FATFS 初学之 f_chmod/ f_utime

f_chmod:

 1 /*-----------------------------------------------------------------------*/
 2 /* Change Attribute                                                      */
 3 /*-----------------------------------------------------------------------*/
 4
 5 FRESULT f_chmod (
 6     const TCHAR *path,    /* Pointer to the file path */
 7     BYTE value,            /* Attribute bits */
 8     BYTE mask            /* Attribute mask to change */
 9 )
10 {
11     FRESULT res;
12     DIR dj;
13     BYTE *dir;
14     DEF_NAMEBUF;
15
16
17     res = chk_mounted(&path, &dj.fs, 1);
18     if (res == FR_OK) {
19         INIT_BUF(dj);
20         res = follow_path(&dj, path);        /* Follow the file path */
21         FREE_BUF();
22         if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT))
23             res = FR_INVALID_NAME;
24         if (res == FR_OK) {
25             dir = dj.dir;
26             if (!dir) {                        /* Is it a root directory? */
27                 res = FR_INVALID_NAME;
28             } else {                        /* File or sub directory */
29                 mask &= AM_RDO|AM_HID|AM_SYS|AM_ARC;    /* Valid attribute mask */
30                 dir[DIR_Attr] = (value & mask) | (dir[DIR_Attr] & (BYTE)~mask);    /* Apply attribute change */
31                 dj.fs->wflag = 1;
32                 res = sync(dj.fs);
33             }
34         }
35     }
36
37     LEAVE_FF(dj.fs, res);
38 }

函数功能:修改一个文件或目录的属性。

描述:

f_chmod函数当_FS_READONLY == 0并且_FS_MINIMIZE == 0时可用。
f_chmod函数修改一个文件或目录的属性。

f_utime:

 1 /*-----------------------------------------------------------------------*/
 2 /* Change Timestamp                                                      */
 3 /*-----------------------------------------------------------------------*/
 4
 5 FRESULT f_utime (
 6     const TCHAR *path,    /* Pointer to the file/directory name */
 7     const FILINFO *fno    /* Pointer to the time stamp to be set */
 8 )
 9 {
10     FRESULT res;
11     DIR dj;
12     BYTE *dir;
13     DEF_NAMEBUF;
14
15
16     res = chk_mounted(&path, &dj.fs, 1);
17     if (res == FR_OK) {
18         INIT_BUF(dj);
19         res = follow_path(&dj, path);    /* Follow the file path */
20         FREE_BUF();
21         if (_FS_RPATH && res == FR_OK && (dj.fn[NS] & NS_DOT))
22             res = FR_INVALID_NAME;
23         if (res == FR_OK) {
24             dir = dj.dir;
25             if (!dir) {                    /* Root directory */
26                 res = FR_INVALID_NAME;
27             } else {                    /* File or sub-directory */
28                 ST_WORD(dir+DIR_WrtTime, fno->ftime);
29                 ST_WORD(dir+DIR_WrtDate, fno->fdate);
30                 dj.fs->wflag = 1;
31                 res = sync(dj.fs);
32             }
33         }
34     }
35
36     LEAVE_FF(dj.fs, res);
37 }

函数功能:f_utime函数修改一个文件或目录的时间戳。

描述:

f_utime函数当_FS_READONLY == 0并且_FS_MINIMIZE == 0时可用。
f_utime函数修改一个文件或目录的时间戳(即文件属性里的创建、修改、访问时间)。

例:

1 // 设置只读标志,清除存档标志,其他不变
2 f_chmod("file.txt", AR_RDO, AR_RDO | AR_ARC);

FATFS 初学之 f_chmod/ f_utime

时间: 2024-10-31 16:26:12

FATFS 初学之 f_chmod/ f_utime的相关文章

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_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_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); /*

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