F_chmod/f_utime for beginners of fatfs

Source: Internet
Author: User

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 }
View code

Function: modifies the attributes of a file or directory.

Description:

The f_chmod function is available when _ fs_readonly = 0 and _ fs_minimize = 0.
The f_chmod function modifies the attributes of a file or directory.

 

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 }
View code

Function: The f_utime function modifies the timestamp of a file or directory.

Description:

The f_utime function is available when _ fs_readonly = 0 and _ fs_minimize = 0.
The f_utime function modifies the timestamp of a file or directory (that is, the creation, modification, and access time in the file attribute ).

 

Example:

1 // set the read-only flag to clear the archive flag. Other flags remain unchanged. 2 f_chmod ("file.txt", ar_rdo, ar_rdo | ar_arc );
View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.