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