Lines Matching refs:fp

235 #define ABORT(fs, res)		{ fp->err = (BYTE)(res); LEAVE_FF(fs, res); }
1646 FIL* fp, /* Pointer to the file object */ in clmt_clust() argument
1652 FATFS *fs = fp->obj.fs; in clmt_clust()
1655 tbl = fp->cltbl + 1; /* Top of CLMT */ in clmt_clust()
3733 FIL* fp, /* Pointer to the blank file object */ argument
3749 if (!fp) return FR_INVALID_OBJECT;
3792 fp->obj.fs = fs;
3793 init_alloc_info(fs, &fp->obj);
3801 if (res == FR_OK && fp->obj.sclust != 0) { /* Remove the cluster chain if exist */
3802 res = remove_chain(&fp->obj, fp->obj.sclust, 0);
3803 fs->last_clst = fp->obj.sclust - 1; /* Reuse the cluster hole */
3841 fp->dir_sect = fs->winsect; /* Pointer to the directory entry */
3842 fp->dir_ptr = dj.dir;
3844 fp->obj.lockid = inc_share(&dj, (mode & ~FA_READ) ? 1 : 0); /* Lock the file for this session */
3845 if (fp->obj.lockid == 0) res = FR_INT_ERR;
3863 fp->obj.c_scl = dj.obj.sclust; /* Get containing directory info */
3864 fp->obj.c_size = ((DWORD)dj.obj.objsize & 0xFFFFFF00) | dj.obj.stat;
3865 fp->obj.c_ofs = dj.blk_ofs;
3866 init_alloc_info(fs, &fp->obj);
3870 fp->obj.sclust = ld_clust(fs, dj.dir); /* Get object allocation info */
3871 fp->obj.objsize = ld_dword(dj.dir + DIR_FileSize);
3874 fp->cltbl = 0; /* Disable fast seek mode */
3876 fp->obj.fs = fs; /* Validate the file object */
3877 fp->obj.id = fs->id;
3878 fp->flag = mode; /* Set file access mode */
3879 fp->err = 0; /* Clear error flag */
3880 fp->sect = 0; /* Invalidate current data sector */
3881 fp->fptr = 0; /* Set file pointer top of the file */
3884 memset(fp->buf, 0, sizeof fp->buf); /* Clear sector buffer */
3886 …if ((mode & FA_SEEKEND) && fp->obj.objsize > 0) { /* Seek to end of file if FA_OPEN_APPEND is spec…
3887 fp->fptr = fp->obj.objsize; /* Offset to seek */
3889 clst = fp->obj.sclust; /* Follow the cluster chain */
3890 for (ofs = fp->obj.objsize; res == FR_OK && ofs > bcs; ofs -= bcs) {
3891 clst = get_fat(&fp->obj, clst);
3895 fp->clust = clst;
3901 fp->sect = sc + (DWORD)(ofs / SS(fs));
3903 if (disk_read(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) res = FR_DISK_ERR;
3908 if (res != FR_OK) dec_share(fp->obj.lockid); /* Decrement file open counter if seek failed */
3917 if (res != FR_OK) fp->obj.fs = 0; /* Invalidate file object on error */
3930 FIL* fp, /* Open file to be read */ argument
3946 res = validate(&fp->obj, &fs); /* Check validity of the file object */
3947 if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res); /* Check validity */
3948 if (!(fp->flag & FA_READ)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */
3949 remain = fp->obj.objsize - fp->fptr;
3952 …for ( ; btr > 0; btr -= rcnt, *br += rcnt, rbuff += rcnt, fp->fptr += rcnt) { /* Repeat until btr …
3953 if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */
3954 csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */
3956 if (fp->fptr == 0) { /* On the top of the file? */
3957 clst = fp->obj.sclust; /* Follow cluster chain from the origin */
3960 if (fp->cltbl) {
3961 clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */
3965 clst = get_fat(&fp->obj, fp->clust); /* Follow cluster chain on the FAT */
3970 fp->clust = clst; /* Update current cluster */
3972 sect = clst2sect(fs, fp->clust); /* Get current sector */
3987 if ((fp->flag & FA_DIRTY) && fp->sect - sect < cc) {
3988 memcpy(rbuff + ((fp->sect - sect) * SS(fs)), fp->buf, SS(fs));
3996 if (fp->sect != sect) { /* Load data sector if not in cache */
3998 if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */
3999 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
4000 fp->flag &= (BYTE)~FA_DIRTY;
4003 …if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Fill sector cache …
4006 fp->sect = sect;
4008 rcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes remains in the sector */
4011 if (move_window(fs, fp->sect) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Move sector window */
4012 memcpy(rbuff, fs->win + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
4014 memcpy(rbuff, fp->buf + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
4030 FIL* fp, /* Open file to be written */ argument
4045 res = validate(&fp->obj, &fs); /* Check validity of the file object */
4046 if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res); /* Check validity */
4047 if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */
4050 if ((!FF_FS_EXFAT || fs->fs_type != FS_EXFAT) && (DWORD)(fp->fptr + btw) < (DWORD)fp->fptr) {
4051 btw = (UINT)(0xFFFFFFFF - (DWORD)fp->fptr);
4054 …= wcnt, *bw += wcnt, wbuff += wcnt, fp->fptr += wcnt, fp->obj.objsize = (fp->fptr > fp->obj.objsiz…
4055 if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */
4056 csect = (UINT)(fp->fptr / SS(fs)) & (fs->csize - 1); /* Sector offset in the cluster */
4058 if (fp->fptr == 0) { /* On the top of the file? */
4059 clst = fp->obj.sclust; /* Follow from the origin */
4061 clst = create_chain(&fp->obj, 0); /* create a new cluster chain */
4065 if (fp->cltbl) {
4066 clst = clmt_clust(fp, fp->fptr); /* Get cluster# from the CLMT */
4070 clst = create_chain(&fp->obj, fp->clust); /* Follow or stretch cluster chain on the FAT */
4076 fp->clust = clst; /* Update current cluster */
4077 if (fp->obj.sclust == 0) fp->obj.sclust = clst; /* Set start cluster if the first write */
4080 …if (fs->winsect == fp->sect && sync_window(fs) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Write-back sec…
4082 if (fp->flag & FA_DIRTY) { /* Write-back sector cache */
4083 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
4084 fp->flag &= (BYTE)~FA_DIRTY;
4087 sect = clst2sect(fs, fp->clust); /* Get current sector */
4103 if (fp->sect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
4104 memcpy(fp->buf, wbuff + ((fp->sect - sect) * SS(fs)), SS(fs));
4105 fp->flag &= (BYTE)~FA_DIRTY;
4113 if (fp->fptr >= fp->obj.objsize) { /* Avoid silly cache filling on the growing edge */
4118 if (fp->sect != sect && /* Fill sector cache with file data */
4119 fp->fptr < fp->obj.objsize &&
4120 disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) {
4124 fp->sect = sect;
4126 wcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes remains in the sector */
4129 if (move_window(fs, fp->sect) != FR_OK) ABORT(fs, FR_DISK_ERR); /* Move sector window */
4130 memcpy(fs->win + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
4133 memcpy(fp->buf + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
4134 fp->flag |= FA_DIRTY;
4138 fp->flag |= FA_MODIFIED; /* Set file change flag */
4151 FIL* fp /* Open file to be synced */ argument
4160 res = validate(&fp->obj, &fs); /* Check validity of the file object */
4162 if (fp->flag & FA_MODIFIED) { /* Is there any change to the file? */
4164 if (fp->flag & FA_DIRTY) { /* Write-back cached data if needed */
4165 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) LEAVE_FF(fs, FR_DISK_ERR);
4166 fp->flag &= (BYTE)~FA_DIRTY;
4173 res = fill_first_frag(&fp->obj); /* Fill first fragment on the FAT if needed */
4175 …res = fill_last_frag(&fp->obj, fp->clust, 0xFFFFFFFF); /* Fill last fragment on the FAT if needed …
4182 res = load_obj_xdir(&dj, &fp->obj); /* Load directory entry block */
4185 fs->dirbuf[XDIR_GenFlags] = fp->obj.stat | 1; /* Update file allocation information */
4186 st_dword(fs->dirbuf + XDIR_FstClus, fp->obj.sclust); /* Update start cluster */
4187 st_qword(fs->dirbuf + XDIR_FileSize, fp->obj.objsize); /* Update file size */
4188 …st_qword(fs->dirbuf + XDIR_ValidFileSize, fp->obj.objsize); /* (FatFs does not support Valid File …
4195 fp->flag &= (BYTE)~FA_MODIFIED;
4203 res = move_window(fs, fp->dir_sect);
4205 dir = fp->dir_ptr;
4207 st_clust(fp->obj.fs, dir, fp->obj.sclust); /* Update file allocation information */
4208 st_dword(dir + DIR_FileSize, (DWORD)fp->obj.objsize); /* Update file size */
4213 fp->flag &= (BYTE)~FA_MODIFIED;
4232 FIL* fp /* Open file to be closed */ argument
4239 res = f_sync(fp); /* Flush cached data */
4243 res = validate(&fp->obj, &fs); /* Lock volume */
4246 res = dec_share(fp->obj.lockid); /* Decrement file open counter */
4247 if (res == FR_OK) fp->obj.fs = 0; /* Invalidate file object */
4249 fp->obj.fs = 0; /* Invalidate file object */
4449 FIL* fp, /* Pointer to the file object */ argument
4464 res = validate(&fp->obj, &fs); /* Check validity of the file object */
4465 if (res == FR_OK) res = (FRESULT)fp->err;
4468 …res = fill_last_frag(&fp->obj, fp->clust, 0xFFFFFFFF); /* Fill last fragment on the FAT if needed …
4474 if (fp->cltbl) { /* Fast seek */
4476 tbl = fp->cltbl;
4478 cl = fp->obj.sclust; /* Origin of the chain */
4485 cl = get_fat(&fp->obj, cl);
4494 *fp->cltbl = ulen; /* Number of items used */
4501 if (ofs > fp->obj.objsize) ofs = fp->obj.objsize; /* Clip offset at the file size */
4502 fp->fptr = ofs; /* Set file pointer */
4504 fp->clust = clmt_clust(fp, ofs - 1);
4505 dsc = clst2sect(fs, fp->clust);
4508 if (fp->fptr % SS(fs) && dsc != fp->sect) { /* Refill sector cache if needed */
4511 if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */
4512 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
4513 fp->flag &= (BYTE)~FA_DIRTY;
4516 …if (disk_read(fs->pdrv, fp->buf, dsc, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Load current sector…
4518 fp->sect = dsc;
4530 …if (ofs > fp->obj.objsize && (FF_FS_READONLY || !(fp->flag & FA_WRITE))) { /* In read-only mode, c…
4531 ofs = fp->obj.objsize;
4533 ifptr = fp->fptr;
4534 fp->fptr = nsect = 0;
4539 fp->fptr = (ifptr - 1) & ~(FSIZE_t)(bcs - 1); /* start from the current cluster */
4540 ofs -= fp->fptr;
4541 clst = fp->clust;
4543 clst = fp->obj.sclust; /* start from the first cluster */
4546 clst = create_chain(&fp->obj, 0);
4549 fp->obj.sclust = clst;
4552 fp->clust = clst;
4556 ofs -= bcs; fp->fptr += bcs;
4558 if (fp->flag & FA_WRITE) { /* Check if in write mode or not */
4559 …if (FF_FS_EXFAT && fp->fptr > fp->obj.objsize) { /* No FAT chain object needs correct objsize to g…
4560 fp->obj.objsize = fp->fptr;
4561 fp->flag |= FA_MODIFIED;
4563 clst = create_chain(&fp->obj, clst); /* Follow chain with forceed stretch */
4570 clst = get_fat(&fp->obj, clst); /* Follow cluster chain if not in write mode */
4574 fp->clust = clst;
4576 fp->fptr += ofs;
4584 …if (!FF_FS_READONLY && fp->fptr > fp->obj.objsize) { /* Set file change flag if the file size is e…
4585 fp->obj.objsize = fp->fptr;
4586 fp->flag |= FA_MODIFIED;
4588 if (fp->fptr % SS(fs) && nsect != fp->sect) { /* Fill sector cache if needed */
4591 if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */
4592 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
4593 fp->flag &= (BYTE)~FA_DIRTY;
4596 …if (disk_read(fs->pdrv, fp->buf, nsect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR); /* Fill sector cache…
4598 fp->sect = nsect;
4928 FIL* fp /* Pointer to the file object */ argument
4936 res = validate(&fp->obj, &fs); /* Check validity of the file object */
4937 if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res);
4938 if (!(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */
4940 if (fp->fptr < fp->obj.objsize) { /* Process when fptr is not on the eof */
4941 if (fp->fptr == 0) { /* When set file size to zero, remove entire cluster chain */
4942 res = remove_chain(&fp->obj, fp->obj.sclust, 0);
4943 fp->obj.sclust = 0;
4945 ncl = get_fat(&fp->obj, fp->clust);
4950 res = remove_chain(&fp->obj, ncl, fp->clust);
4953 fp->obj.objsize = fp->fptr; /* Set file size to current read/write point */
4954 fp->flag |= FA_MODIFIED;
4956 if (res == FR_OK && (fp->flag & FA_DIRTY)) {
4957 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) {
4960 fp->flag &= (BYTE)~FA_DIRTY;
5584 FIL* fp, /* Pointer to the file object */ argument
5594 res = validate(&fp->obj, &fs); /* Check validity of the file object */
5595 if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res);
5596 if (fsz == 0 || fp->obj.objsize != 0 || !(fp->flag & FA_WRITE)) LEAVE_FF(fs, FR_DENIED);
5623 n = get_fat(&fp->obj, clst);
5656 fp->obj.sclust = scl; /* Update object allocation information */
5657 fp->obj.objsize = fsz;
5658 if (FF_FS_EXFAT) fp->obj.stat = 2; /* Set status 'contiguous chain' */
5659 fp->flag |= FA_MODIFIED;
5680 FIL* fp, /* Pointer to the file object */ argument
5696 res = validate(&fp->obj, &fs); /* Check validity of the file object */
5697 if (res != FR_OK || (res = (FRESULT)fp->err) != FR_OK) LEAVE_FF(fs, res);
5698 if (!(fp->flag & FA_READ)) LEAVE_FF(fs, FR_DENIED); /* Check access mode */
5700 remain = fp->obj.objsize - fp->fptr;
5703 …for ( ; btf > 0 && (*func)(0, 0); fp->fptr += rcnt, *bf += rcnt, btf -= rcnt) { /* Repeat until al…
5704 csect = (UINT)(fp->fptr / SS(fs) & (fs->csize - 1)); /* Sector offset in the cluster */
5705 if (fp->fptr % SS(fs) == 0) { /* On the sector boundary? */
5707 clst = (fp->fptr == 0) ? /* On the top of the file? */
5708 fp->obj.sclust : get_fat(&fp->obj, fp->clust);
5711 fp->clust = clst; /* Update current cluster */
5714 sect = clst2sect(fs, fp->clust); /* Get current data sector */
5721 if (fp->sect != sect) { /* Fill sector cache with file data */
5723 if (fp->flag & FA_DIRTY) { /* Write-back dirty sector cache */
5724 if (disk_write(fs->pdrv, fp->buf, fp->sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
5725 fp->flag &= (BYTE)~FA_DIRTY;
5728 if (disk_read(fs->pdrv, fp->buf, sect, 1) != RES_OK) ABORT(fs, FR_DISK_ERR);
5730 dbuf = fp->buf;
5732 fp->sect = sect;
5733 rcnt = SS(fs) - (UINT)fp->fptr % SS(fs); /* Number of bytes remains in the sector */
5735 rcnt = (*func)(dbuf + ((UINT)fp->fptr % SS(fs)), rcnt); /* Forward the file data */
6448 FIL* fp /* Pointer to the file object */ argument
6470 f_read(fp, s, 1, &rc); /* Get a code unit */
6474 f_read(fp, s, 1, &rc); /* Get 2nd byte */
6481 f_read(fp, s, 2, &rc); /* Get a code unit */
6486 f_read(fp, s, 2, &rc); /* Get low surrogate */
6493 f_read(fp, s, 1, &rc); /* Get a code unit */
6508 f_read(fp, s, ct, &rc); /* Get trailing bytes */
6555 f_read(fp, s, 1, &rc); /* Get a byte */
6583 FIL *fp; /* Pointer to the writing file */ member
6718 f_write(pb->fp, pb->buf, (UINT)i, &n);
6733 && f_write(pb->fp, pb->buf, (UINT)pb->idx, &nw) == FR_OK
6743 static void putc_init (putbuff* pb, FIL* fp) argument
6746 pb->fp = fp;
6753 FIL* fp /* Pointer to the file object */ argument
6759 putc_init(&pb, fp);
6773 FIL* fp /* Pointer to the file object */ argument
6779 putc_init(&pb, fp);
6915 FIL* fp, /* Pointer to the file object */ argument
6935 putc_init(&pb, fp);