Return to previous page Return to menu Go to next page

[Example] Simultaneous access to multiple files in different directories

To access a file in a different directory, the target file must be opened while switching the current directory.
An example of accessing two files in two subdirectories directly under the current directory at the same time. Assume that the file identifiers of the two subdirectories that contain the files you want to access are specified by dir_fid1 and dir_fid2, respectively.

#define MAX_DIR 10 / * Maximum number of directory information * / 

GfsDirTbl curdir; / ​​* Current directory at this point * / GfsDirTbl dirtbl1, dirtbl2; / * Directory information management area * / GfsDirId dirid1 [MAX_DIR]; / * Directory information storage area * / GfsDirId dirid2 [MAX_DIR]; / * Directory information storage area * / Sint32 dir_fid1, dir_fid2; / * Contains the directory file identifier * / Sint32 fid1, fid2; / * Contains the identifier of the file to be accessed * / GfsHn gfs1, gfs2; / * File handle of the file to be accessed * /

/ * Read directory information of dir_fid1 of current directory * / GFS_DIRTBL_TYPE (&dirtbl1) = GFS_DIR_ID; GFS_DIRTBL_NDIR (&dirtbl1) = MAX_DIR; GFS_DIRTBL_DIRID(&dirtbl1) = dirid1; GFS_LoadDir(dir_gfs1, &dirtbl1);

/ * Read the directory information of dir_fid2 of the current directory * / GFS_DIRTBL_TYPE (&dirtbl2) = GFS_DIR_ID; GFS_DIRTBL_NDIR (&dirtbl2) = MAX_DIR; GFS_DIRTBL_DIRID(&dirtbl2) = dirid2; GFS_LoadDir(dir_gfs2, &dirtbl2);

/ * Open the file dir_fid1 and fid1 * / GFS_SetDir (&dirtbl1); gfs1 = GFS_Open(fid1);

/ * Open the file dir_fid2 and fid2 * / GFS_SetDir (&dirtbl2); gfs2 = GFS_Open(fid2); /* * File access here */ GFS_Close(gfs1); GFS_Close(gfs2);

3.4 Mutual conversion of file name and file identifier

If directory information including the file name is set in the current directory, the mutual conversion function between the file name and the file identifier can be used.
∙ An error will occur if these functions are called when directory information that does not include a file name is set as the current directory.
∙ An example of defining a function that opens a file with a file name using this function is shown below.
 [Example] / * Open the file specified by the file name * /
GfsHn OpenByName (Uint8 * fname)
{
Sint32 fid = GFS_NameToId (fname); 

If (fid <0) { Return NULL; } Return GFS_Open (fid);



Return to previous page Return to menu Go to next page