PROGRAMMER'S GUIDEFile system library
BackForward
File system library

Five. Access method


There are the following two access methods provided by this library.

5.1 Complete return type access

Completion-return access is similar to the standard C library file access function.
The following is an example of a program for return-to-complete access.

[example]
#define BUF_SIZE 2048

GfsHn gfs; / * File handle * / Sint32 fid; / * File identifier * / Sint32 nsct = 1; / * Number of sectors read * / Uint32 buf [BUF_SIZE / 4]; / * Read area * / gfs = GFS_Open (fid); / * File open * / GFS_Fread (gfs, nsct, buf, BUF_SIZE); / * Read nsct sector into buf * / GFS_Close (gfs); / * File close * /

5.2 Immediate return access

Immediate return access is performed using the request function and the server function. The request function executes only the request acceptance process and returns immediately. The actual access processing is performed by repeatedly calling the server function while monitoring the input completion status. You can also process your application in a server function call loop. For a file handle that has issued a request once, the request cannot be issued until the access process is completed.

(1) Immediate return type access to a single file
For singular file access, GFS_NwExecOne is the server function.
The following is an example of a program that accesses one file with the immediate return type. In this example, GFS_NwFread is the request function.

example]
#define BUF_SIZE 2048 * 2

GfsHn gfs; / * File handle * /
Sint32 nsct = 2; / * Number of sectors read * /
Sint32 stat; / * Server status * /
Uint32 buf [BUF_SIZE / 4]; / * Read area * /

gfs = GFS_Open (fid); / * File open * /
/ * Request function * /
GFS_NwFread (gfs, nsct, buf, BUF_SIZE); / * Read nsct sector into buf * /
                                        / * Immediate return * /

for (;;) {
     / * Server function * /
     stat = GFS_NwExecOne (gfs); / * Perform read * /
     if (stat == GFS_SVR_COMPLETED) {/ * Is reading completed? * /
          break;
     }
     user (); / * Arbitrary user processing * /
}

GFS_Close (gfs); / * File close * /

(2) Immediate return access to multiple files
For continuous access to multiple files, GFS_NwExecSerer is the server function.
The request function is common to accessing a single file.
The application issues access processing requests to multiple files. After that, access processing is executed sequentially by passing control to the server on a regular basis. Access processing is performed one by one in the order in which they are requested.
The following is an example of a program that performs user processing while reading three files.

[example]
/ * Number of sectors read from each file * /
#define NSCT1 1
# define NSCT2 2
# define NSCT3 3

/ * The size of the data storage area of each file (unit is bytes) * /
# define BSIZE1 2048 * NSCT1
# define BSIZE2 2048 * NSCT2
# define BSIZE3 2048 * NSCT3

Sint32 fid1, fid2, fid3; / * File identifier of each file * / GfsHn gfs1, gfs2, gfs3; / * File handle for each file * / Uint32 buf1 [BSIZE1 / 4]; / * Data storage area for each file * / Uint32 buf2 [BSIZE2 / 4]; Uint32 buf3 [BSIZE3 / 4]; GfsHn now_gfs; / * File handle being accessed * / Sint32 stat; / * Server status * / gfs1 = GFS_Open (fid1); / * File open * / gfs2 = GFS_Open (fid2); gfs3 = GFS_Open (fid3); GFS_NwFread (gfs1, NSCT1, buf1, BSIZE1); / * Start read operation * / GFS_NwFread (gfs2, NSCT2, buf2, BSIZE2); GFS_NwFread (gfs3, NSCT3, buf3, BSIZE3); for (;;) { stat = GFS_NwExecServer (& now_gfs); / * Perform read * / if (stat == GFS_SVR_COMPLETED) {/ * Do you have any work to do? * / break; } user (); / * Arbitrary user processing * / } GFS_Close (gfs1); GFS_Close (gfs2); GFS_Close (gfs3);

(3) Look ahead to the CD buffer
When reading large files in quick succession, you can use GFS_NwCdRead to specify read-ahead to the CD buffer to maximize the read speed of the CD.
In the following program example, a 1000-sector file is read continuously by 10 sectors. Since GFS_NwCdRead is specified to read ahead 1000 sectors, the target file is played back 1000 sectors continuously and stored in the buffer. Since the data is being fetched from the CD buffer in parallel with this process, the buffer will not be full and playback will not be interrupted.
If the processing performed in this example is performed without using look-ahead, CD playback will be interrupted every 10 sectors, resulting in wasted time.

[example]
#define SECT_SIZE 2048
#define FILE_SECT 1000
#define FILE_SIZE (FILE_SECT * SECT_SIZE)
#define RD_UNIT 10

Uint8 * rd_bp, * proc_bp; / * Read buffer and processing buffer * /
Uint32 buf1 [RD_UNIT * SECT_SIZE / 4]; / * Data storage area 1 * /
Uint32 buf2 [RD_UNIT * SECT_SIZE / 4]; / * Data storage area 2 * /
GfsHn gfs;
Sint32 i, stat, nbyte;

gfs = GFS_Open (fid); GFS_NwCdRead (gfs, FILE_SECT); / * Read-ahead instruction to CD buffer * / GFS_SetTransPara (gfs, RD_UNIT); / * Extract maximum RD_UNIT sector at once * / for (i = 0; i <FILE_SECT / RD_UNIT; ++ i) { / * Read, set processing buffer * / if (i & 1) { rd_bp = buf1; proc_bp = buf2; } else { rd_bp = buf2; proc_bp = buf1; } / * Eject from CD buffer * / GFS_NwFread (gfs, RD_UNIT, rd_bp, RD_UNIT * SECT_SIZE); do { if (i & 0) { user_process (proc_bp); / * Processing for read data * / } else { user_process0 (); / * Processing before data is read * / } GFS_NwExecOne (gfs); GFS_NwGetStat (gfs, & stat, & nbyte); } While (nbyte <RD_UNIT * SECT_SIZE); }


BackForward
PROGRAMMER'S GUIDEFile system library
Copyright SEGA ENTERPRISES, LTD., 1997