

1 /*-----------------------------------------------------------------------*/ 2 /* Seek File R/W Pointer */ 3 /*-----------------------------------------------------------------------*/ 4 5 FRESULT f_lseek ( 6 FIL *fp, /* Pointer to the file object */ 7 DWORD ofs /* File pointer from top of file */ 8 ) 9 { 10 FRESULT res; 11 12 13 res = validate(fp->fs, fp->id); /* Check validity of the object */ 14 if (res != FR_OK) LEAVE_FF(fp->fs, res); 15 if (fp->flag & FA__ERROR) /* Check abort flag */ 16 LEAVE_FF(fp->fs, FR_INT_ERR); 17 18 #if _USE_FASTSEEK 19 if (fp->cltbl) { /* Fast seek */ 20 DWORD cl, pcl, ncl, tcl, dsc, tlen, ulen, *tbl; 21 22 if (ofs == CREATE_LINKMAP) { /* Create CLMT */ 23 tbl = fp->cltbl; 24 tlen = *tbl++; ulen = 2; /* Given table size and required table size */ 25 cl = fp->sclust; /* Top of the chain */ 26 if (cl) { 27 do { 28 /* Get a fragment */ 29 tcl = cl; ncl = 0; ulen += 2; /* Top, length and used items */ 30 do { 31 pcl = cl; ncl++; 32 cl = get_fat(fp->fs, cl); 33 if (cl <= 1) ABORT(fp->fs, FR_INT_ERR); 34 if (cl == 0xFFFFFFFF) ABORT(fp->