FATFS 初学之 f_chdir/ f_chdrive

 1 FRESULT f_chdir (
 2     const TCHAR *path    /* Pointer to the directory path */
 3 )
 4 {
 5     FRESULT res;
 6     DIR dj;
 7     DEF_NAMEBUF;
 8
 9
10     res = chk_mounted(&path, &dj.fs, 0);
11     if (res == FR_OK) {
12         INIT_BUF(dj);
13         res = follow_path(&dj, path);        /* Follow the path */
14         FREE_BUF();
15         if (res == FR_OK) {                    /* Follow completed */
16             if (!dj.dir) {
17                 dj.fs->cdir = dj.sclust;    /* Start directory itself */
18             } else {
19                 if (dj.dir[DIR_Attr] & AM_DIR)    /* Reached to the directory */
20                     dj.fs->cdir = LD_CLUST(dj.dir);
21                 else
22                     res = FR_NO_PATH;        /* Reached but a file */
23             }
24         }
25         if (res == FR_NO_FILE) res = FR_NO_PATH;
26     }
27
28     LEAVE_FF(dj.fs, res);
29 }

函数功能:f_chdir函数改变一个驱动器的当前目录。

描述:

f_chdir函数当_FS_RPATH == 1时可用。
f_chdir函数改变一个逻辑驱动器的当前目录。当一个逻辑驱动器被自动挂载时,它的当前目录被初始化为根目录。注意:当前目录被保存在每个文件系统对象中,因此它也影响使用同一逻辑驱动器的其它任务。

f_chdrive:

 1 FRESULT f_chdrive (
 2     BYTE drv        /* Drive number */
 3 )
 4 {
 5     if (drv >= _VOLUMES) return FR_INVALID_DRIVE;
 6
 7     CurrVol = drv;
 8
 9     return FR_OK;
10 }

函数功能:f_chdrive函数改变当前驱动器。

描述:

f_chdrive函数当_FS_RPATH == 1时可用。
f_chdrive函数改变当前驱动器。当前驱动器号初始值为0,注意:当前驱动器被保存为一个静态变量,因此它也影响使用文件函数的其它任务。

例:

1   // 改变当前驱动器的当前目录(根目录下的dir1)
2     f_chdir("/dir1");
3
4     // 改变驱动器2的当前目录(父目录)
5     f_chdir("2:..");

PS:还是不知道有什么作用....

FATFS 初学之 f_chdir/ f_chdrive

时间: 2024-10-01 21:34:53

FATFS 初学之 f_chdir/ f_chdrive的相关文章

FATFS 初学之 f_mkdir/ unlink

f_mkdir: 1 /*-----------------------------------------------------------------------*/ 2 /* Create a Directory */ 3 /*-----------------------------------------------------------------------*/ 4 5 FRESULT f_mkdir ( 6 const TCHAR *path /* Pointer to th

FATFS 初学之 f_forward

1 /*-----------------------------------------------------------------------*/ 2 /* Forward data to the stream directly (available on only tiny cfg) */ 3 /*-----------------------------------------------------------------------*/ 4 5 FRESULT f_forward

FATFS 初学之 f_rename

1 /*-----------------------------------------------------------------------*/ 2 /* Rename File/Directory */ 3 /*-----------------------------------------------------------------------*/ 4 5 FRESULT f_rename ( 6 const TCHAR *path_old, /* Pointer to th

FATFS 初学之 f_mkfs

1 /*-----------------------------------------------------------------------*/ 2 /* Create File System on the Drive */ 3 /*-----------------------------------------------------------------------*/ 4 5 FRESULT f_mkfs ( 6 BYTE drv, /* Logical drive numb

FATFS 初学之 f_getfree

1 /*-----------------------------------------------------------------------*/ 2 /* Get Number of Free Clusters */ 3 /*-----------------------------------------------------------------------*/ 4 5 FRESULT f_getfree ( 6 const TCHAR *path, /* Pointer to

FATFS 初学之 f_chmod/ f_utime

f_chmod: 1 /*-----------------------------------------------------------------------*/ 2 /* Change Attribute */ 3 /*-----------------------------------------------------------------------*/ 4 5 FRESULT f_chmod ( 6 const TCHAR *path, /* Pointer to the

FATFS 初学之 f_open/ f_close

f_open: 1 /*-----------------------------------------------------------------------*/ 2 /* Open or Create a File */ 3 /*-----------------------------------------------------------------------*/ 4 5 FRESULT f_open ( 6 FIL *fp, /* Pointer to the blank

FATFS 初学之 f_opendir/ f_readdir

f_opendir: 1 /*-----------------------------------------------------------------------*/ 2 /* Create a Directroy Object */ 3 /*-----------------------------------------------------------------------*/ 4 5 FRESULT f_opendir ( 6 DIR *dj, /* Pointer to

FATFS 初学之 f_gets/ f_putc/ f_puts/ f_printf

详见:嵌入式大讲堂 f_gets: 1 /*-----------------------------------------------------------------------*/ 2 /* Get a string from the file */ 3 /*-----------------------------------------------------------------------*/ 4 TCHAR* f_gets ( 5 TCHAR* buff, /* Point