📄 tff.lst
字号:
941
942 #ifndef _FS_READONLY
943
944 #if 0
FRESULT f_unlink (
const char *path /* Pointer to the file or directory path */
)
{
FRESULT res;
BYTE *dir, *sdir;
DWORD dsect;
WORD dclust;
DIR dirscan;
char fn[8+3+1];
FATFS *fs = FatFs;
if ((res = check_mounted()) != FR_OK) return res;
if (disk_status() & STA_PROTECT) return FR_WRITE_PROTECTED;
res = trace_path(&dirscan, fn, path, &dir); /* Trace the file path */
if (res != FR_OK) return res; /* Trace failed */
if (dir == NULL) return FR_NO_FILE; /* It is a root directory */
if (*(dir+11) & AM_RDO) return FR_DENIED; /* It is a R/O item */
dsect = fs->winsect;
dclust = LD_WORD(dir+26);
if (*(dir+11) & AM_DIR) { /* It is a sub-directory */
dirscan.clust = dclust; /* Check if the sub-dir is empty or not */
dirscan.sect = clust2sect(dclust);
dirscan.index = 0;
do {
if (!move_window(dirscan.sect)) return FR_RW_ERROR;
sdir = &(fs->win[(dirscan.index & 15) * 32]);
if (*sdir == 0) break;
if (!((*sdir == 0xE5) || (*sdir == '.')) && !(*(sdir+11) & AM_VOL))
return FR_DENIED; /* The directory is not empty */
} while (next_dir_entry(&dirscan));
}
if (!move_window(dsect)) return FR_RW_ERROR; /* Mark the directory entry 'deleted' */
*dir = 0xE5; fs->winflag = 1;
C51 COMPILER V7.02b TFF 03/24/2008 15:52:29 PAGE 17
if (!remove_chain(dclust)) return FR_RW_ERROR; /* Remove the cluster chain */
if (!move_window(0)) return FR_RW_ERROR;
return FR_OK;
}
#endif
991 #endif /* _FS_READONLY */
992
993
994
995
996 /*--------------------*/
997 /* Create a Directory */
998
999 #ifndef _FS_READONLY
1000 FRESULT f_mkdir (
1001 const char *path /* Pointer to the directory path */
1002 )
1003 {
1004 1 FRESULT res;
1005 1 BYTE *dir, *w, n;
1006 1 DWORD sect, dsect, tim;
1007 1 WORD dclust;
1008 1 DIR dirscan;
1009 1 char fn[8+3+1];
1010 1 FATFS *fs = FatFs;
1011 1
1012 1
1013 1 if ((res = check_mounted()) != FR_OK) return res;
1014 1 if (disk_status() & STA_PROTECT) return FR_WRITE_PROTECTED;
1015 1
1016 1 res = trace_path(&dirscan, fn, path, &dir); /* Trace the file path */
1017 1
1018 1 if (res == FR_OK) return FR_DENIED; /* Any file or directory is already existing */
1019 1 if (res != FR_NO_FILE) return res;
1020 1
1021 1 dir = reserve_direntry(&dirscan); /* Reserve a directory entry */
1022 1 if (dir == NULL) return FR_DENIED;
1023 1 sect = fs->winsect;
1024 1 dsect = clust2sect(dclust = create_chain(0)); /* Get a new cluster for new directory */
1025 1 if (!dsect) return FR_DENIED;
1026 1 if (!move_window(0)) return 0;
1027 1
1028 1 w = fs->win;
1029 1 memset(w, 0, 512); /* Initialize the directory table */
1030 1 for (n = fs->sects_clust - 1; n; n--) {
1031 2 if (disk_write(w, dsect+n, 1) != RES_OK) return FR_RW_ERROR;
1032 2 }
1033 1
1034 1 fs->winsect = dsect; /* Create dot directories */
1035 1 memset(w, ' ', 8+3);
1036 1 *w = '.';
1037 1 *(w+11) = AM_DIR;
1038 1 // tim = get_fattime();
1039 1 // ST_DWORD(w+22, tim);
1040 1 memcpy(w+32, w, 32); *(w+33) = '.';
1041 1 ST_WORD(w+26, dclust);
1042 1 ST_WORD(w+32+26, dirscan.sclust);
1043 1 fs->winflag = 1;
1044 1
1045 1 if (!move_window(sect)) return FR_RW_ERROR;
1046 1 memcpy(dir, fn, 8+3); /* Initialize the new entry */
C51 COMPILER V7.02b TFF 03/24/2008 15:52:29 PAGE 18
1047 1 *(dir+11) = AM_DIR;
1048 1 *(dir+12) = fn[11];
1049 1 memset(dir+13, 0, 32-13);
1050 1 ST_DWORD(dir+22, tim); /* Crated time */
1051 1 ST_WORD(dir+26, dclust); /* Table start cluster */
1052 1 fs->winflag = 1;
1053 1
1054 1 if (!move_window(0)) return FR_RW_ERROR;
1055 1
1056 1 return FR_OK;
1057 1 }
1058 #if 0
#endif
1060 #endif /* _FS_READONLY */
1061
1062
1063
1064 /*---------------------------*/
1065 /* Initialize directroy scan */
1066
1067 FRESULT f_opendir (
1068 DIR *scan, /* Pointer to directory object to initialize */
1069 const char *path /* Pointer to the directory path, null str means the root */
1070 )
1071 {
1072 1 FRESULT res;
1073 1 BYTE *dir;
1074 1 char fn[8+3+1];
1075 1
1076 1
1077 1 if ((res = check_mounted()) != FR_OK) return res;
1078 1
1079 1 res = trace_path(scan, fn, path, &dir); /* Trace the directory path */
1080 1
1081 1 if (res == FR_OK) { /* Trace completed */
1082 2 if (dir != NULL) { /* It is not a root dir */
1083 3 if (*(dir+11) & AM_DIR) { /* The entry is a directory */
1084 4 scan->clust = LD_WORD(dir+26);
1085 4 scan->sect = clust2sect(scan->clust);
1086 4 scan->index = 0;
1087 4 } else { /* The entry is a file */
1088 4 res = FR_NO_PATH;
1089 4 }
1090 3 }
1091 2 }
1092 1 return res;
1093 1 }
1094
1095
1096
1097 /*----------------------------------*/
1098 /* Read Directory Entry in Sequense */
1099
1100 FRESULT f_readdir (
1101 DIR *scan, /* Pointer to the directory object */
1102 FILINFO *finfo /* Pointer to file information to return */
1103 )
1104 {
1105 1 BYTE *dir, c;
1106 1 FATFS *fs = FatFs;
1107 1
1108 1
C51 COMPILER V7.02b TFF 03/24/2008 15:52:29 PAGE 19
1109 1 if (!fs) return FR_NOT_ENABLED;
1110 1 finfo->fname[0] = 0;
1111 1 if ((disk_status() & STA_NOINIT) || !fs->fs_type) return FR_NOT_READY;
1112 1
1113 1 while (scan->sect) {
1114 2 if (!move_window(scan->sect)) return FR_RW_ERROR;
1115 2 dir = &(fs->win[(scan->index & 15) * 32]); /* pointer to the directory entry */
1116 2 c = *dir;
1117 2 if (c == 0) break; /* Has it reached to end of dir? */
1118 2 if ((c != 0xE5) && (c != '.') && !(*(dir+11) & AM_VOL)) /* Is it a valid entry? */
1119 2 get_fileinfo(finfo, dir);
1120 2 if (!next_dir_entry(scan)) scan->sect = 0; /* Next entry */
1121 2 if (finfo->fname[0]) break; /* Found valid entry */
1122 2 }
1123 1
1124 1 return FR_OK;
1125 1 }
1126
1127
1128 #if 0
/*-----------------*/
/* Get File Status */
FRESULT f_stat (
const char *path, /* Pointer to the file path */
FILINFO *finfo /* Pointer to file information to return */
)
{
FRESULT res;
BYTE *dir;
DIR dirscan;
char fn[8+3+1];
if ((res = check_mounted()) != FR_OK) return res;
res = trace_path(&dirscan, fn, path, &dir); /* Trace the file path */
if (res == FR_OK) /* Trace completed */
get_fileinfo(finfo, dir);
return res;
}
#endif
1153
1154
1155 /*-----------------------*/
1156 /* Change File Attribute */
1157
1158 #ifndef _FS_READONLY
1159 #if 0
FRESULT f_chmod (
const char *path, /* Pointer to the file path */
BYTE value, /* Attribute bits */
BYTE mask /* Attribute mask to change */
)
{
FRESULT res;
BYTE *dir;
DIR dirscan;
char fn[8+3+1];
FATFS *fs = FatFs;
C51 COMPILER V7.02b TFF 03/24/2008 15:52:29 PAGE 20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -