📄 tff.lst
字号:
case FS_FAT12 :
bc = (WORD)clust * 3 / 2;
if (!move_window(fatsect + bc / 512U)) return FALSE;
p = &fs->win[bc % 512U];
*p = (clust & 1) ? ((*p & 0x0F) | ((BYTE)val << 4)) : (BYTE)val;
bc++;
fs->winflag = 1;
if (!move_window(fatsect + bc / 512U)) return FALSE;
p = &fs->win[bc % 512U];
*p = (clust & 1) ? (BYTE)(val >> 4) : ((*p & 0xF0) | ((BYTE)(val >> 8) & 0x0F));
break;
case FS_FAT16 :
if (!move_window(fatsect + clust / 256)) return FALSE;
ST_WORD(&fs->win[((WORD)clust * 2) % 512U], (WORD)val);
break;
#if _FAT32
case FS_FAT32 :
if (!move_window(fatsect + clust / 128)) return FALSE;
ST_DWORD(&fs->win[((WORD)clust * 4) % 512U], val);
break;
#endif
default :
return FALSE;
}
fs->winflag = 1;
return TRUE;
}
#endif /* !_FS_READONLY */
239
240
241
C51 COMPILER V8.08 TFF 10/31/2008 14:44:16 PAGE 5
242
243 /*-----------------------------------------------------------------------*/
244 /* Remove a cluster chain */
245 /*-----------------------------------------------------------------------*/
246
247 #if !_FS_READONLY
static
BOOL remove_chain ( /* TRUE: successful, FALSE: failed */
CLUST clust /* Cluster# to remove chain from */
)
{
CLUST nxt;
FATFS *fs = FatFs;
while (clust >= 2 && clust < fs->max_clust) {
nxt = get_cluster(clust);
if (nxt == 1) return FALSE;
if (!put_cluster(clust, 0)) return FALSE;
if (fs->free_clust != (CLUST)0xFFFFFFFF) {
fs->free_clust++;
#if _USE_FSINFO
fs->fsi_flag = 1;
#endif
}
clust = nxt;
}
return TRUE;
}
#endif
272
273
274
275
276 /*-----------------------------------------------------------------------*/
277 /* Stretch or create a cluster chain */
278 /*-----------------------------------------------------------------------*/
279
280 #if !_FS_READONLY
static
CLUST create_chain ( /* 0: No free cluster, 1: Error, >=2: New cluster number */
CLUST clust /* Cluster# to stretch, 0 means create new */
)
{
CLUST cstat, ncl, scl, mcl;
FATFS *fs = FatFs;
mcl = fs->max_clust;
if (clust == 0) { /* Create new chain */
scl = fs->last_clust; /* Get last allocated cluster */
if (scl < 2 || scl >= mcl) scl = 1;
}
else { /* Stretch existing chain */
cstat = get_cluster(clust); /* Check the cluster status */
if (cstat < 2) return 1; /* It is an invalid cluster */
if (cstat < mcl) return cstat; /* It is already followed by next cluster */
scl = clust;
}
ncl = scl; /* Start cluster */
for (;;) {
C51 COMPILER V8.08 TFF 10/31/2008 14:44:16 PAGE 6
ncl++; /* Next cluster */
if (ncl >= mcl) { /* Wrap around */
ncl = 2;
if (ncl > scl) return 0; /* No free custer */
}
cstat = get_cluster(ncl); /* Get the cluster status */
if (cstat == 0) break; /* Found a free cluster */
if (cstat == 1) return 1; /* Any error occured */
if (ncl == scl) return 0; /* No free custer */
}
if (!put_cluster(ncl, (CLUST)0x0FFFFFFF)) return 1; /* Mark the new cluster "in use" */
if (clust != 0 && !put_cluster(clust, ncl)) return 1; /* Link it to previous one if needed */
fs->last_clust = ncl; /* Update fsinfo */
if (fs->free_clust != (CLUST)0xFFFFFFFF) {
fs->free_clust--;
#if _USE_FSINFO
fs->fsi_flag = 1;
#endif
}
return ncl; /* Return new cluster number */
}
#endif /* !_FS_READONLY */
329
330
331
332
333 /*-----------------------------------------------------------------------*/
334 /* Get sector# from cluster# */
335 /*-----------------------------------------------------------------------*/
336
337 static
338 DWORD clust2sect ( /* !=0: sector number, 0: failed - invalid cluster# */
339 CLUST clust /* Cluster# to be converted */
340 )
341 {
342 1 FATFS *fs = FatFs;
343 1
344 1
345 1 clust -= 2;
346 1 if (clust >= (fs->max_clust - 2)) return 0; /* Invalid cluster# */
347 1 return (DWORD)clust * fs->csize + fs->database;
348 1 }
349
350
351
352
353 /*-----------------------------------------------------------------------*/
354 /* Move directory pointer to next */
355 /*-----------------------------------------------------------------------*/
356
357 static
358 BOOL next_dir_entry ( /* TRUE: successful, FALSE: could not move next */
359 DIR *dj /* Pointer to directory object */
360 )
361 {
362 1 CLUST clust;
363 1 WORD idx;
364 1
365 1
C51 COMPILER V8.08 TFF 10/31/2008 14:44:16 PAGE 7
366 1 idx = dj->index + 1;
367 1 if ((idx & 15) == 0) { /* Table sector changed? */
368 2 dj->sect++; /* Next sector */
369 2 if (dj->clust == 0) { /* In static table */
370 3 if (idx >= dj->fs->n_rootdir) return FALSE; /* Reached to end of table */
371 3 } else { /* In dynamic table */
372 3 if (((idx / 16) & (dj->fs->csize - 1)) == 0) { /* Cluster changed? */
373 4 clust = get_cluster(dj->clust); /* Get next cluster */
374 4 if (clust < 2 || clust >= dj->fs->max_clust) /* Reached to end of table */
375 4 return FALSE;
376 4 dj->clust = clust; /* Initialize for new cluster */
377 4 dj->sect = clust2sect(clust);
378 4 }
379 3 }
380 2 }
381 1 dj->index = idx; /* Lower 4 bit of dj->index indicates offset in dj->sect */
382 1 return TRUE;
383 1 }
384
385
386
387
388 /*-----------------------------------------------------------------------*/
389 /* Get file status from directory entry */
390 /*-----------------------------------------------------------------------*/
391
392 #if _FS_MINIMIZE <= 1
393 static
394 void get_fileinfo ( /* No return code */
395 FILINFO *finfo, /* Ptr to store the File Information */
396 const BYTE *dir /* Ptr to the directory entry */
397 )
398 {
399 1 BYTE n, c, a;
400 1 char *p;
401 1
402 1
403 1 p = &finfo->fname[0];
404 1 a = _USE_NTFLAG ? dir[DIR_NTres] : 0; /* NT flag */
405 1 for (n = 0; n < 8; n++) { /* Convert file name (body) */
406 2 c = dir[n];
407 2 if (c == ' ') break;
408 2 if (c == 0x05) c = 0xE5;
409 2 if (a & 0x08 && c >= 'A' && c <= 'Z') c += 0x20;
410 2 *p++ = c;
411 2 }
412 1 if (dir[8] != ' ') { /* Convert file name (extension) */
413 2 *p++ = '.';
414 2 for (n = 8; n < 11; n++) {
415 3 c = dir[n];
416 3 if (c == ' ') break;
417 3 if (a & 0x10 && c >= 'A' && c <= 'Z') c += 0x20;
418 3 *p++ = c;
419 3 }
420 2 }
421 1 *p = '\0';
422 1
423 1 finfo->fattrib = dir[DIR_Attr]; /* Attribute */
424 1 finfo->fsize = LD_DWORD(&dir[DIR_FileSize]); /* Size */
425 1 finfo->fdate = LD_WORD(&dir[DIR_WrtDate]); /* Date */
426 1 finfo->ftime = LD_WORD(&dir[DIR_WrtTime]); /* Time */
427 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -