1 /*-----------------------------------------------------------------------*/
 2 /* Synchronize the File Object                                           */
 3 /*-----------------------------------------------------------------------*/
 4 
 5 FRESULT f_sync (
 6     FIL *fp        /* Pointer to the file object */
 7 )
 8 {
 9     FRESULT res;
10     DWORD tim;
11     BYTE *dir;
12 
13 
14     res = validate(fp->fs, fp->id);        /* Check validity of the object */
15     if (res == FR_OK) {
16         if (fp->flag & FA__WRITTEN) {    /* Has the file been written? */
17 #if !_FS_TINY    /* Write-back dirty buffer */
18             if (fp->flag & FA__DIRTY) {
19                 if (disk_write(fp->fs->drv, fp->buf, fp->dsect, 1) != RES_OK)
20                     LEAVE_FF(fp->fs, FR_DISK_ERR);
21                 fp->flag &= ~FA__DIRTY;
22             }
23 #endif
24             /* Update the directory entry */
25             res = move_window(fp->fs, fp->dir_sect);
26             if (res == FR_OK) {
27                 dir = fp->dir_ptr;
28                 dir[DIR_Attr] |= AM_ARC;                    /* Set archive bit */
29                 ST_DWORD(dir+DIR_FileSize, fp->fsize);        /* Update file size */
30                 ST_CLUST(dir, fp->sclust);                    /* Update start cluster */
31                 tim = get_fattime();                        /* Update updated time */
32                 ST_DWORD(dir+DIR_WrtTime, tim);
33                 fp->flag &= ~FA__WRITTEN;
34                 fp->fs->wflag = 1;
35                 res = sync(fp->fs);
36             }
37         }
38     }
39 
40     LEAVE_FF(fp->fs, res);
41 }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2022-12-23
  • 2022-01-21
  • 2021-04-27
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案