更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
fatfs.h 文件参考

浏览源代码.

函数

int fatfs_2_vfs (int result)
 
int fatfs_lookup (struct Vnode *parent, const char *name, int len, struct Vnode **vpp)
 fat文件系统对 Lookup 接口的实现 更多...
 
int fatfs_create (struct Vnode *parent, const char *name, int mode, struct Vnode **vpp)
 创建 fat vnode 节点 更多...
 
int fatfs_read (struct file *filep, char *buff, size_t count)
 
off_t fatfs_lseek64 (struct file *filep, off64_t offset, int whence)
 
off64_t fatfs_lseek (struct file *filep, off_t offset, int whence)
 
int fatfs_write (struct file *filep, const char *buff, size_t count)
 
int fatfs_fsync (struct file *filep)
 
int fatfs_fallocate64 (struct file *filep, int mode, off64_t offset, off64_t len)
 
int fatfs_fallocate (struct file *filep, int mode, off_t offset, off_t len)
 
int fatfs_truncate64 (struct Vnode *vnode, off64_t len)
 
int fatfs_truncate (struct Vnode *vnode, off_t len)
 
int fatfs_mount (struct Mount *mount, struct Vnode *device, const void *data)
 fat将分区文件系统挂载 举例: mount /dev/mmcblk0p0 /bin1/vs/sd vfat 更多...
 
int fatfs_umount (struct Mount *mount, struct Vnode **device)
 
int fatfs_statfs (struct Mount *mount, struct statfs *info)
 
int fatfs_stat (struct Vnode *vnode, struct stat *buff)
 
int fatfs_chattr (struct Vnode *vnode, struct IATTR *attr)
 
int fatfs_opendir (struct Vnode *vnode, struct fs_dirent_s *idir)
 
int fatfs_readdir (struct Vnode *vnode, struct fs_dirent_s *idir)
 
int fatfs_rewinddir (struct Vnode *vnode, struct fs_dirent_s *dir)
 
int fatfs_closedir (struct Vnode *vnode, struct fs_dirent_s *dir)
 
int fatfs_rename (struct Vnode *oldvnode, struct Vnode *newparent, const char *oldname, const char *newname)
 
int fatfs_mkfs (struct Vnode *device, int sectors, int option)
 
int fatfs_mkdir (struct Vnode *parent, const char *name, mode_t mode, struct Vnode **vpp)
 
int fatfs_rmdir (struct Vnode *parent, struct Vnode *vp, const char *name)
 
int fatfs_unlink (struct Vnode *parent, struct Vnode *vp, const char *name)
 
int fatfs_ioctl (struct file *filep, int req, unsigned long arg)
 
int fatfs_fscheck (struct Vnode *vnode, struct fs_dirent_s *dir)
 
FRESULT find_fat_partition (FATFS *fs, los_part *part, BYTE *format, QWORD *start_sector)
 
FRESULT init_fatobj (FATFS *fs, BYTE fmt, QWORD start_sector)
 
FRESULT _mkfs (los_part *partition, const MKFS_PARM *opt, BYTE *work, UINT len)
 

变量

char FatLabel [LABEL_LEN]
 

函数说明

◆ _mkfs()

FRESULT _mkfs ( los_part partition,
const MKFS_PARM *  opt,
BYTE *  work,
UINT  len 
)
这是这个函数的调用关系图:

◆ fatfs_2_vfs()

int fatfs_2_vfs ( int  result)

在文件 fatfs.c96 行定义.

97{
98 int status = ENOERR;
99
100#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
101 if (result < 0 || result >= VIRERR_BASE) {
102 return result;
103 }
104#else
105 if (result < 0) {
106 return result;
107 }
108#endif
109
110 /* FatFs errno to Libc errno */
111 switch (result) {
112 case FR_OK:
113 break;
114
115 case FR_NO_FILE:
116 case FR_NO_PATH:
117 status = ENOENT;
118 break;
119
120 case FR_NO_FILESYSTEM:
121 status = ENOTSUP;
122 break;
123
124 case FR_INVALID_NAME:
125 status = EINVAL;
126 break;
127
128 case FR_EXIST:
129 case FR_INVALID_OBJECT:
130 status = EEXIST;
131 break;
132
133 case FR_DISK_ERR:
134 case FR_NOT_READY:
135 case FR_INT_ERR:
136 status = EIO;
137 break;
138
139 case FR_WRITE_PROTECTED:
140 status = EROFS;
141 break;
142 case FR_MKFS_ABORTED:
143 case FR_INVALID_PARAMETER:
144 status = EINVAL;
145 break;
146
147 case FR_NO_SPACE_LEFT:
148 status = ENOSPC;
149 break;
150 case FR_NO_DIRENTRY:
151 status = ENFILE;
152 break;
153 case FR_NO_EMPTY_DIR:
154 status = ENOTEMPTY;
155 break;
156 case FR_IS_DIR:
157 status = EISDIR;
158 break;
159 case FR_NO_DIR:
160 status = ENOTDIR;
161 break;
162 case FR_NO_EPERM:
163 case FR_DENIED:
164 status = EPERM;
165 break;
166 case FR_LOCKED:
167 case FR_TIMEOUT:
168 status = EBUSY;
169 break;
170#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
171 case FR_MODIFIED:
172 status = -VIRERR_MODIFIED;
173 break;
174 case FR_CHAIN_ERR:
175 status = -VIRERR_CHAIN_ERR;
176 break;
177 case FR_OCCUPIED:
178 status = -VIRERR_OCCUPIED;
179 break;
180 case FR_NOTCLEAR:
181 status = -VIRERR_NOTCLEAR;
182 break;
183 case FR_NOTFIT:
184 status = -VIRERR_NOTFIT;
185 break;
186 case FR_INVAILD_FATFS:
187 status = -VIRERR_INTER_ERR;
188 break;
189#endif
190 default:
191 status = -FAT_ERROR;
192 break;
193 }
194
195 return status;
196}
这是这个函数的调用关系图:

◆ fatfs_chattr()

int fatfs_chattr ( struct Vnode vnode,
struct IATTR attr 
)

在文件 fatfs.c1494 行定义.

1495{
1496 FATFS *fs = (FATFS *)vp->originMount->data;
1497 DIR_FILE *dfp = (DIR_FILE *)vp->data;
1498 DIR *dp = &(dfp->f_dir);
1499 FILINFO *finfo = &(dfp->fno);
1500 BYTE *dir = dp->dir;
1501 DWORD ftime;
1502 FRESULT result;
1503 int ret;
1504
1505 if (finfo->fname[0] == '/') { /* Is root dir of fatfs ? */
1506 return 0;
1507 }
1508
1509 ret = lock_fs(fs);
1510 if (ret == FALSE) {
1511 result = FR_TIMEOUT;
1512 goto ERROR_OUT;
1513 }
1514
1515 result = move_window(fs, dp->sect);
1516 if (result != FR_OK) {
1517 goto ERROR_UNLOCK;
1518 }
1519
1520 if (attr->attr_chg_valid & CHG_MODE) {
1521 /* FAT only support readonly flag */
1522 if ((attr->attr_chg_mode & S_IWUSR) == 0 && (finfo->fattrib & AM_RDO) == 0) {
1523 dir[DIR_Attr] |= AM_RDO;
1524 finfo->fattrib |= AM_RDO;
1525 fs->wflag = 1;
1526 } else if ((attr->attr_chg_mode & S_IWUSR) != 0 && (finfo->fattrib & AM_RDO) != 0) {
1527 dir[DIR_Attr] &= ~AM_RDO;
1528 finfo->fattrib &= ~AM_RDO;
1529 fs->wflag = 1;
1530 }
1531 vp->mode = fatfs_get_mode(finfo->fattrib, fs->fs_mode);
1532 }
1533
1534 if (attr->attr_chg_valid & (CHG_ATIME | CHG_CTIME | CHG_MTIME)) {
1535 fatfs_chtime(dp, attr);
1536 ftime = ld_dword(dp->dir + DIR_ModTime);
1537 finfo->fdate = (WORD)(ftime >> FTIME_DATE_OFFSET);
1538 finfo->ftime = (WORD)ftime;
1539 }
1540
1541 result = sync_window(fs);
1542 if (result != FR_OK) {
1543 goto ERROR_UNLOCK;
1544 }
1545
1546 unlock_fs(fs, FR_OK);
1547 return fatfs_sync(vp->originMount->mountFlags, fs);
1548ERROR_UNLOCK:
1549 unlock_fs(fs, result);
1550ERROR_OUT:
1551 return -fatfs_2_vfs(result);
1552}
void fatfs_chtime(DIR *dp, struct IATTR *attr)
Definition: fatfs.c:1474
int fatfs_2_vfs(int result)
Definition: fatfs.c:96
static int fatfs_sync(unsigned long mountflags, FATFS *fs)
Definition: fatfs.c:211
static mode_t fatfs_get_mode(BYTE attribute, mode_t fs_mode)
Definition: fatfs.c:248
unsigned attr_chg_mode
确定了文件的类型,以及它的所有者、它的group、其它用户访问此文件的权限 (S_IWUSR | ...)
Definition: vnode.h:85
unsigned int attr_chg_valid
节点改变有效性 (CHG_MODE | CHG_UID | ... )
Definition: vnode.h:83
函数调用图:

◆ fatfs_closedir()

int fatfs_closedir ( struct Vnode vnode,
struct fs_dirent_s *  dir 
)

在文件 fatfs.c1662 行定义.

1663{
1664 DIR *dp = (DIR *)dir->u.fs_dir;
1665 free(dp);
1666 dir->u.fs_dir = NULL;
1667 return 0;
1668}
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
函数调用图:
这是这个函数的调用关系图:

◆ fatfs_create()

int fatfs_create ( struct Vnode parent,
const char *  name,
int  mode,
struct Vnode **  vpp 
)

创建 fat vnode 节点

在文件 fatfs.c614 行定义.

615{
616 return fatfs_create_obj(parent, name, mode, vpp, AM_ARC, NULL);
617}
static int fatfs_create_obj(struct Vnode *parent, const char *name, int mode, struct Vnode **vpp, BYTE type, const char *target)
Definition: fatfs.c:366
函数调用图:

◆ fatfs_fallocate()

int fatfs_fallocate ( struct file filep,
int  mode,
off_t  offset,
off_t  len 
)

在文件 fatfs.c1010 行定义.

1011{
1012 return fatfs_fallocate64(filep, mode, offset, len);
1013}
int fatfs_fallocate64(struct file *filep, int mode, off64_t offset, off64_t len)
Definition: fatfs.c:913
函数调用图:

◆ fatfs_fallocate64()

int fatfs_fallocate64 ( struct file filep,
int  mode,
off64_t  offset,
off64_t  len 
)

在文件 fatfs.c913 行定义.

914{
915 FIL *fp = (FIL *)filep->f_priv;
916 FATFS *fs = fp->obj.fs;
917 struct Vnode *vp = filep->f_vnode;
918 FILINFO *finfo = &((DIR_FILE *)(vp->data))->fno;
919 FRESULT result;
920 int ret;
921
922 if (offset < 0 || len <= 0) {
923 return -EINVAL;
924 }
925
926 if (len >= FAT32_MAXSIZE || offset >= FAT32_MAXSIZE ||
927 len + offset >= FAT32_MAXSIZE) {
928 return -EINVAL;
929 }
930
931 if (mode != FALLOC_FL_KEEP_SIZE) {
932 return -EINVAL;
933 }
934
935 ret = lock_fs(fs);
936 if (ret == FALSE) {
937 return -EBUSY;
938 }
939 result = f_expand(fp, (FSIZE_t)offset, (FSIZE_t)len, 1);
940 if (result == FR_OK) {
941 if (finfo->sclst == 0) {
942 finfo->sclst = fp->obj.sclust;
943 }
944 result = f_sync(fp);
945 }
946 unlock_fs(fs, result);
947
948 return -fatfs_2_vfs(result);
949}
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
Definition: vnode.h:164
void * f_priv
函数调用图:
这是这个函数的调用关系图:

◆ fatfs_fscheck()

int fatfs_fscheck ( struct Vnode vnode,
struct fs_dirent_s *  dir 
)

在文件 fatfs.c2122 行定义.

2123{
2124 FATFS *fs = (FATFS *)vp->originMount->data;
2125 DIR *dp = NULL;
2126 FILINFO *finfo = &(((DIR_FILE *)(vp->data))->fno);
2127#ifdef LOSCFG_FS_FAT_CACHE
2128 los_part *part = NULL;
2129#endif
2130 FRESULT result;
2131 int ret;
2132
2133 if (fs->fs_type != FS_FAT32) {
2134 return -EINVAL;
2135 }
2136
2137 if ((finfo->fattrib & AM_DIR) == 0) {
2138 return -ENOTDIR;
2139 }
2140
2141 ret = fatfs_opendir(vp, dir);
2142 if (ret < 0) {
2143 return ret;
2144 }
2145
2146 ret = lock_fs(fs);
2147 if (ret == FALSE) {
2148 result = FR_TIMEOUT;
2149 goto ERROR_WITH_DIR;
2150 }
2151
2152 dp = (DIR *)dir->u.fs_dir;
2153 dp->obj.id = fs->id;
2154 result = fscheck(dp);
2155 if (result != FR_OK) {
2156 goto ERROR_UNLOCK;
2157 }
2158
2159 unlock_fs(fs, FR_OK);
2160
2161 ret = fatfs_closedir(vp, dir);
2162 if (ret < 0) {
2163 return ret;
2164 }
2165
2166#ifdef LOSCFG_FS_FAT_CACHE
2167 part = get_part((INT)fs->pdrv);
2168 if (part != NULL) {
2169 (void)OsSdSync(part->disk_id);
2170 }
2171#endif
2172
2173 return 0;
2174
2175ERROR_UNLOCK:
2176 unlock_fs(fs, result);
2177ERROR_WITH_DIR:
2178 fatfs_closedir(vp, dir);
2179 return -fatfs_2_vfs(result);
2180}
INT32 OsSdSync(INT32 id)
Definition: bcache.c:956
static FRESULT fscheck(DIR *dp)
Definition: fatfs.c:2077
int fatfs_opendir(struct Vnode *vp, struct fs_dirent_s *idir)
Definition: fatfs.c:1554
int fatfs_closedir(struct Vnode *vp, struct fs_dirent_s *dir)
Definition: fatfs.c:1662
los_part * get_part(INT32 id)
Find disk partition.
Definition: disk.c:272
UINT32 disk_id
Definition: disk.h:198
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void
函数调用图:

◆ fatfs_fsync()

int fatfs_fsync ( struct file filep)

在文件 fatfs.c896 行定义.

897{
898 FIL *fp = filep->f_priv;
899 FATFS *fs = fp->obj.fs;
900 FRESULT result;
901 int ret;
902
903 ret = lock_fs(fs);
904 if (ret == FALSE) {
905 return -EBUSY;
906 }
907
908 result = f_sync(fp);
909 unlock_fs(fs, result);
910 return -fatfs_2_vfs(result);
911}
函数调用图:

◆ fatfs_ioctl()

int fatfs_ioctl ( struct file filep,
int  req,
unsigned long  arg 
)

在文件 fatfs.c2049 行定义.

2050{
2051 return -ENOSYS;
2052}

◆ fatfs_lookup()

int fatfs_lookup ( struct Vnode parent,
const char *  name,
int  len,
struct Vnode **  vpp 
)

fat文件系统对 Lookup 接口的实现

在文件 fatfs.c516 行定义.

517{
518 struct Vnode *vp = NULL;
519 FATFS *fs = (FATFS *)(parent->originMount->data);
520 DIR_FILE *dfp;
521 DIR *dp = NULL;
522 FILINFO *finfo = NULL;
523 DWORD hash;
524 FRESULT result;
525 int ret;
526
527 dfp = (DIR_FILE *)zalloc(sizeof(DIR_FILE));
528 if (dfp == NULL) {
529 ret = ENOMEM;
530 goto ERROR_EXIT;
531 }
532
533 ret = lock_fs(fs);
534 if (ret == FALSE) {
535 ret = EBUSY;
536 goto ERROR_FREE;
537 }
538 finfo = &(dfp->fno);
539 LOS_ListInit(&finfo->fp_list);
540 dp = &(dfp->f_dir);
541 dp->obj.fs = fs;
542 dp->obj.sclust = ((DIR_FILE *)(parent->data))->fno.sclst;
543
544 DEF_NAMBUF;
545 INIT_NAMBUF(fs);
546 result = create_name(dp, &path);
547 if (result != FR_OK) {
548 ret = fatfs_2_vfs(result);
549 goto ERROR_UNLOCK;
550 }
551
552 result = dir_find(dp);
553 if (result != FR_OK) {
554 ret = fatfs_2_vfs(result);
555 goto ERROR_UNLOCK;
556 }
557
558 if (dp->fn[NSFLAG] & NS_NONAME) {
559 result = FR_INVALID_NAME;
560 ret = fatfs_2_vfs(result);
561 goto ERROR_UNLOCK;
562 }
563
564 get_fileinfo(dp, finfo);
565 dp->obj.objsize = 0;
566
567 hash = fatfs_hash(dp->sect, dp->dptr, finfo->sclst);
568 ret = VfsHashGet(parent->originMount, hash, &vp, fatfs_hash_cmp, dfp);
569 if (ret != 0) {
570 ret = VnodeAlloc(&fatfs_vops, &vp);
571 if (ret != 0) {
572 ret = ENOMEM;
573 result = FR_NOT_ENOUGH_CORE;
574 goto ERROR_UNLOCK;
575 }
576 vp->parent = parent;
577 vp->fop = &fatfs_fops;
578 vp->data = dfp;
580 vp->uid = fs->fs_uid;
581 vp->gid = fs->fs_gid;
582 vp->mode = fatfs_get_mode(finfo->fattrib, fs->fs_mode);
583 if (finfo->fattrib & AM_DIR) {
584 vp->type = VNODE_TYPE_DIR;
585 finfo->fsize = fs->csize * SS(fs);
586 } else {
587 vp->type = VNODE_TYPE_REG;
588 }
589
590 ret = VfsHashInsert(vp, hash);
591 if (ret != 0) {
592 result = FR_INVALID_PARAMETER;
593 goto ERROR_UNLOCK;
594 }
595 } else {
596 vp->parent = parent;
597 free(dfp); /* hash hit dfp is no needed */
598 }
599
600 unlock_fs(fs, FR_OK);
601 FREE_NAMBUF();
602 *vpp = vp;
603 return 0;
604
605ERROR_UNLOCK:
606 unlock_fs(fs, result);
607 FREE_NAMBUF();
608ERROR_FREE:
609 free(dfp);
610ERROR_EXIT:
611 return -ret;
612}
struct VnodeOps fatfs_vops
fat 文件系统 vnode实现
Definition: fatfs.c:81
int fatfs_hash_cmp(struct Vnode *vp, void *arg)
哈希值比较函数,返回int
Definition: fatfs.c:228
struct file_operations_vfs fatfs_fops
Definition: fatfs.c:82
static DWORD fatfs_hash(QWORD sect, DWORD dptr, DWORD sclst)
生成hash值的过程
Definition: fatfs.c:238
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
Definition: los_list.h:104
void * zalloc(size_t size)
Definition: malloc.c:91
void * data
Definition: mount.h:78
uint32_t hash
Definition: vnode.h:167
uint gid
Definition: vnode.h:169
enum VnodeType type
Definition: vnode.h:165
mode_t mode
Definition: vnode.h:170
void * data
Definition: vnode.h:176
struct file_operations_vfs * fop
Definition: vnode.h:175
struct Mount * originMount
Definition: vnode.h:180
uint uid
Definition: vnode.h:168
struct Vnode * parent
Definition: vnode.h:173
@ VNODE_TYPE_DIR
Definition: vnode.h:137
@ VNODE_TYPE_REG
Definition: vnode.h:136
int VfsHashGet(const struct Mount *mount, uint32_t hash, struct Vnode **vnode, VfsHashCmp *fun, void *arg)
通过哈希值获取节点信息
Definition: vnode_hash.c:89
int VfsHashInsert(struct Vnode *vnode, uint32_t hash)
插入哈希表
Definition: vnode_hash.c:128
int VnodeAlloc(struct VnodeOps *vop, struct Vnode **vnode)
申请分配一个 vnode 节点,vop为操作节点的驱动程序
Definition: vnode.c:166
函数调用图:

◆ fatfs_lseek()

off64_t fatfs_lseek ( struct file filep,
off_t  offset,
int  whence 
)

在文件 fatfs.c832 行定义.

833{
834 return (off_t)fatfs_lseek64(filep, offset, whence);
835}
off64_t fatfs_lseek64(struct file *filep, off64_t offset, int whence)
Definition: fatfs.c:753
函数调用图:

◆ fatfs_lseek64()

off_t fatfs_lseek64 ( struct file filep,
off64_t  offset,
int  whence 
)

在文件 fatfs.c753 行定义.

754{
755 FIL *fp = (FIL *)filep->f_priv;
756 FATFS *fs = fp->obj.fs;
757 struct Vnode *vp = filep->f_vnode;
758 DIR_FILE *dfp = (DIR_FILE *)vp->data;
759 FILINFO *finfo = &(dfp->fno);
760 struct Mount *mount = vp->originMount;
761 FSIZE_t fpos;
762 FRESULT result;
763 int ret;
764
765 switch (whence) {
766 case SEEK_CUR:
767 offset = filep->f_pos + offset;
768 if (offset < 0) {
769 return -EINVAL;
770 }
771 fpos = offset;
772 break;
773 case SEEK_SET:
774 if (offset < 0) {
775 return -EINVAL;
776 }
777 fpos = offset;
778 break;
779 case SEEK_END:
780 offset = (off_t)((long long)finfo->fsize + offset);
781 if (offset < 0) {
782 return -EINVAL;
783 }
784 fpos = offset;
785 break;
786 default:
787 return -EINVAL;
788 }
789
790 if (offset >= FAT32_MAXSIZE) {
791 return -EINVAL;
792 }
793
794 ret = lock_fs(fs);
795 if (ret == FALSE) {
796 return -EBUSY;
797 }
798
799 if (fpos > finfo->fsize) {
800 if ((filep->f_oflags & O_ACCMODE) == O_RDONLY) {
801 result = FR_DENIED;
802 goto ERROR_EXIT;
803 }
804 if (mount->mountFlags & MS_RDONLY) {
805 result = FR_WRITE_PROTECTED;
806 goto ERROR_EXIT;
807 }
808 }
809 fp->obj.sclust = finfo->sclst;
810 fp->obj.objsize = finfo->fsize;
811
812 result = f_lseek(fp, fpos);
813 finfo->fsize = fp->obj.objsize;
814 finfo->sclst = fp->obj.sclust;
815 if (result != FR_OK) {
816 goto ERROR_EXIT;
817 }
818
819 result = f_sync(fp);
820 if (result != FR_OK) {
821 goto ERROR_EXIT;
822 }
823 filep->f_pos = fpos;
824
825 unlock_fs(fs, FR_OK);
826 return fpos;
827ERROR_EXIT:
828 unlock_fs(fs, result);
829 return -fatfs_2_vfs(result);
830}
举例: mount /dev/mmcblk0p0 /bin1/vs/sd vfat 将/dev/mmcblk0p0 挂载到/bin1/vs/sd目录
Definition: mount.h:68
unsigned long mountFlags
Definition: mount.h:80
loff_t f_pos
int f_oflags
函数调用图:
这是这个函数的调用关系图:

◆ fatfs_mkdir()

int fatfs_mkdir ( struct Vnode parent,
const char *  name,
mode_t  mode,
struct Vnode **  vpp 
)

在文件 fatfs.c1941 行定义.

1942{
1943 return fatfs_create_obj(parent, name, mode, vpp, AM_DIR, NULL);
1944}
函数调用图:

◆ fatfs_mkfs()

int fatfs_mkfs ( struct Vnode device,
int  sectors,
int  option 
)

在文件 fatfs.c1885 行定义.

1886{
1887 BYTE *work_buff = NULL;
1888 los_part *part = NULL;
1889 FRESULT result;
1890 MKFS_PARM opt = {0};
1891 int ret;
1892
1893 part = los_part_find(device);
1894 if (part == NULL || device->data == NULL) {
1895 return -ENODEV;
1896 }
1897
1898 if (sectors < 0 || sectors > FAT32_MAX_CLUSTER_SIZE || ((DWORD)sectors & ((DWORD)sectors - 1))) {
1899 return -EINVAL;
1900 }
1901
1902 if (option != FMT_FAT && option != FMT_FAT32 && option != FMT_ANY && option != FMT_ERASE) {
1903 return -EINVAL;
1904 }
1905
1906 if (part->part_name != NULL) { /* The part is mounted */
1907 return -EBUSY;
1908 }
1909 option = fatfs_erase(part, option);
1910 work_buff = (BYTE *)zalloc(FF_MAX_SS);
1911 if (work_buff == NULL) {
1912 return -ENOMEM;
1913 }
1914
1915 opt.n_sect = sectors;
1916 opt.fmt = (BYTE)option;
1917 result = _mkfs(part, &opt, work_buff, FF_MAX_SS);
1918 free(work_buff);
1919 if (result != FR_OK) {
1920 return -fatfs_2_vfs(result);
1921 }
1922
1923 result = fatfs_setlabel(part);
1924 if (result == FR_OK) {
1925#ifdef LOSCFG_FS_FAT_CACHE
1926 ret = OsSdSync(part->disk_id);
1927 if (ret != 0) {
1928 return -EIO;
1929 }
1930#endif
1931 }
1932
1933 ret = fatfs_set_part_info(part);
1934 if (ret != 0) {
1935 return -EIO;
1936 }
1937
1938 return -fatfs_2_vfs(result);
1939}
static FRESULT fatfs_setlabel(los_part *part)
Definition: fatfs.c:1846
static int fatfs_set_part_info(los_part *part)
设置FAT分区信息
Definition: fatfs.c:1814
static int fatfs_erase(los_part *part, int option)
Definition: fatfs.c:1796
FRESULT _mkfs(los_part *partition, const MKFS_PARM *opt, BYTE *work, UINT len)
los_part * los_part_find(struct Vnode *blkDriver)
Find disk partition.
Definition: disk.c:1682
CHAR * part_name
Definition: disk.h:206
函数调用图:
这是这个函数的调用关系图:

◆ fatfs_mount()

int fatfs_mount ( struct Mount mount,
struct Vnode device,
const void data 
)

fat将分区文件系统挂载 举例: mount /dev/mmcblk0p0 /bin1/vs/sd vfat

在文件 fatfs.c1103 行定义.

1104{
1105 struct Vnode *vp = NULL;
1106 FATFS *fs = NULL;
1107 DIR_FILE *dfp = NULL;
1108 los_part *part = NULL;
1109 QWORD start_sector;
1110 BYTE fmt;
1111 DWORD hash;
1112 FRESULT result;
1113 int ret;
1114
1115 ret = fat_bind_check(blk_device, &part);//通过节点获取分区信息
1116 if (ret != 0) {
1117 goto ERROR_EXIT;
1118 }
1119
1120 ret = SetDiskPartName(part, "vfat");
1121 if (ret != 0) {
1122 ret = EIO;
1123 goto ERROR_EXIT;
1124 }
1125
1126 fs = (FATFS *)zalloc(sizeof(FATFS));
1127 if (fs == NULL) {
1128 ret = ENOMEM;
1129 goto ERROR_PARTNAME;
1130 }
1131
1132#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
1133 fs->vir_flag = FS_PARENT;
1134 fs->parent_fs = fs;
1135 fs->vir_amount = DISK_ERROR;
1136 fs->vir_avail = FS_VIRDISABLE;
1137#endif
1138
1139 ret = ff_cre_syncobj(0, &fs->sobj);
1140 if (ret == 0) { /* create sync object failed */
1141 ret = EINVAL;
1142 goto ERROR_WITH_FS;
1143 }
1144
1145 ret = lock_fs(fs);
1146 if (ret == FALSE) {
1147 ret = EBUSY;
1148 goto ERROR_WITH_MUX;
1149 }
1150
1151 fs->fs_type = 0;
1152 fs->pdrv = part->part_id;
1153
1154#if FF_MAX_SS != FF_MIN_SS /* Get sector size (multiple sector size cfg only) */
1155 if (disk_ioctl(fs->pdrv, GET_SECTOR_SIZE, &(fs->ssize)) != RES_OK) {
1156 ret = EIO;
1157 goto ERROR_WITH_LOCK;
1158 }
1159 if (fs->ssize > FF_MAX_SS || fs->ssize < FF_MIN_SS || (fs->ssize & (fs->ssize - 1))) {
1160 ret = EIO;
1161 goto ERROR_WITH_LOCK;
1162 }
1163#endif
1164
1165 fs->win = (BYTE *)ff_memalloc(SS(fs));
1166 if (fs->win == NULL) {
1167 ret = ENOMEM;
1168 goto ERROR_WITH_LOCK;
1169 }
1170
1171 result = find_fat_partition(fs, part, &fmt, &start_sector);
1172 if (result != FR_OK) {
1173 ret = fatfs_2_vfs(result);
1174 goto ERROR_WITH_FSWIN;
1175 }
1176
1177 result = init_fatobj(fs, fmt, start_sector);
1178 if (result != FR_OK) {
1179 ret = fatfs_2_vfs(result);
1180 goto ERROR_WITH_FSWIN;
1181 }
1182
1183 fs->fs_uid = mnt->vnodeBeCovered->uid;
1184 fs->fs_gid = mnt->vnodeBeCovered->gid;
1185 fs->fs_dmask = GetUmask();
1186 fs->fs_fmask = GetUmask();
1187 fs->fs_mode = mnt->vnodeBeCovered->mode & (S_IRWXU | S_IRWXG | S_IRWXO);
1188
1189 dfp = (DIR_FILE *)zalloc(sizeof(DIR_FILE));
1190 if (dfp == NULL) {
1191 ret = ENOMEM;
1192 goto ERROR_WITH_FSWIN;
1193 }
1194
1195 dfp->f_dir.obj.fs = fs;
1196 dfp->f_dir.obj.sclust = 0; /* set start clust 0, root */
1197 dfp->f_dir.obj.attr = AM_DIR;
1198 dfp->f_dir.obj.objsize = 0; /* dir size is 0 */
1199 dfp->fno.fsize = 0;
1200 dfp->fno.fdate = 0;
1201 dfp->fno.ftime = 0;
1202 dfp->fno.fattrib = AM_DIR;
1203 dfp->fno.sclst = 0;
1204 dfp->fno.fsize = fs->csize * SS(fs);
1205 dfp->fno.fname[0] = '/'; /* Mark as root dir */
1206 dfp->fno.fname[1] = '\0';
1207 LOS_ListInit(&(dfp->fno.fp_list));
1208
1209 ret = VnodeAlloc(&fatfs_vops, &vp);
1210 if (ret != 0) {
1211 ret = ENOMEM;
1212 goto ERROR_WITH_FSWIN;
1213 }
1214
1215 mnt->data = fs;
1216 mnt->vnodeCovered = vp;
1217
1218 vp->parent = mnt->vnodeBeCovered;
1219 vp->fop = &fatfs_fops;
1220 vp->data = dfp;
1221 vp->originMount = mnt;
1222 vp->uid = fs->fs_uid;
1223 vp->gid = fs->fs_gid;
1224 vp->mode = mnt->vnodeBeCovered->mode;
1225 vp->type = VNODE_TYPE_DIR;
1226
1227 hash = fatfs_hash(0, 0, 0);
1228 ret = VfsHashInsert(vp, hash);
1229 if (ret != 0) {
1230 ret = -ret;
1231 goto ERROR_WITH_LOCK;
1232 }
1233 unlock_fs(fs, FR_OK);
1234
1235 return 0;
1236
1237ERROR_WITH_FSWIN:
1238 ff_memfree(fs->win);
1239ERROR_WITH_LOCK:
1240 unlock_fs(fs, FR_OK);
1241ERROR_WITH_MUX:
1242 ff_del_syncobj(&fs->sobj);
1243ERROR_WITH_FS:
1244 free(fs);
1245ERROR_PARTNAME:
1246 if (part->part_name) {
1247 free(part->part_name);
1248 part->part_name = NULL;
1249 }
1250ERROR_EXIT:
1251 return -ret;
1252}
INT32 SetDiskPartName(los_part *part, const CHAR *src)
设置分区名称
Definition: disk.c:1726
static int fat_bind_check(struct Vnode *blk_driver, los_part **partition)
Definition: fatfs.c:1063
FRESULT find_fat_partition(FATFS *fs, los_part *part, BYTE *format, QWORD *start_sector)
FRESULT init_fatobj(FATFS *fs, BYTE fmt, QWORD start_sector)
UINT32 part_id
Definition: disk.h:199
mode_t GetUmask(void)
获取用户创建文件掩码
Definition: vfs_other.c:715
函数调用图:

◆ fatfs_opendir()

int fatfs_opendir ( struct Vnode vnode,
struct fs_dirent_s *  idir 
)

在文件 fatfs.c1554 行定义.

1555{
1556 FATFS *fs = vp->originMount->data;
1557 DIR_FILE *dfp = (DIR_FILE *)vp->data;
1558 FILINFO *finfo = &(dfp->fno);
1559 DIR *dp;
1560 DWORD clst;
1561 FRESULT result;
1562 int ret;
1563
1564 dp = (DIR*)zalloc(sizeof(DIR));
1565 if (dp == NULL) {
1566 return -ENOMEM;
1567 }
1568
1569 ret = lock_fs(fs);
1570 if (ret == FALSE) {
1571 return -EBUSY;
1572 }
1573 clst = finfo->sclst;
1574 dp->obj.fs = fs;
1575 dp->obj.sclust = clst;
1576
1577 result = dir_sdi(dp, 0);
1578 if (result != FR_OK) {
1579 free(dp);
1580 unlock_fs(fs, result);
1581 return -fatfs_2_vfs(result);
1582 }
1583 unlock_fs(fs, result);
1584 idir->u.fs_dir = dp;
1585
1586 return 0;
1587}
函数调用图:
这是这个函数的调用关系图:

◆ fatfs_read()

int fatfs_read ( struct file filep,
char *  buff,
size_t  count 
)

在文件 fatfs.c697 行定义.

698{
699 FIL *fp = (FIL *)filep->f_priv;
700 FATFS *fs = fp->obj.fs;
701 struct Vnode *vp = filep->f_vnode;
702 FILINFO *finfo = &((DIR_FILE *)(vp->data))->fno;
703 size_t rcount;
704 FRESULT result;
705 int ret;
706
707 ret = lock_fs(fs);
708 if (ret == FALSE) {
709 return -EBUSY;
710 }
711 fp->obj.objsize = finfo->fsize;
712 fp->obj.sclust = finfo->sclst;
713 result = f_read(fp, buff, count, &rcount);
714 if (result != FR_OK) {
715 goto EXIT;
716 }
717 filep->f_pos = fp->fptr;
718EXIT:
719 unlock_fs(fs, result);
720 return rcount;
721}

◆ fatfs_readdir()

int fatfs_readdir ( struct Vnode vnode,
struct fs_dirent_s *  idir 
)

在文件 fatfs.c1589 行定义.

1590{
1591 FATFS *fs = vp->originMount->data;
1592 FILINFO fno;
1593 DIR* dp = (DIR*)idir->u.fs_dir;
1594 struct dirent *dirp = NULL;
1595 FRESULT result;
1596 int ret, i;
1597
1598 ret = lock_fs(fs);
1599 if (ret == FALSE) { /* Lock fs failed */
1600 return -EBUSY;
1601 }
1602 DEF_NAMBUF;
1603 INIT_NAMBUF(fs);
1604 for (i = 0; i < idir->read_cnt; i++) {
1605 /* using dir_read_massive to promote performance */
1606 result = dir_read_massive(dp, 0);
1607 if (result == FR_NO_FILE) {
1608 break;
1609 } else if (result != FR_OK) {
1610 goto ERROR_UNLOCK;
1611 }
1612 get_fileinfo(dp, &fno);
1613 /* 0x00 for end of directory and 0xFF for directory is empty */
1614 if (fno.fname[0] == 0x00 || fno.fname[0] == (TCHAR)0xFF) {
1615 break;
1616 }
1617
1618 dirp = &(idir->fd_dir[i]);
1619 if (fno.fattrib & AM_DIR) { /* is dir */
1620 dirp->d_type = DT_DIR;
1621 } else {
1622 dirp->d_type = DT_REG;
1623 }
1624 if (strncpy_s(dirp->d_name, sizeof(dirp->d_name), fno.fname, strlen(fno.fname)) != EOK) {
1625 result = FR_NOT_ENOUGH_CORE;
1626 goto ERROR_UNLOCK;
1627 }
1628 result = dir_next(dp, 0);
1629 if (result != FR_OK && result != FR_NO_FILE) {
1630 goto ERROR_UNLOCK;
1631 }
1632 idir->fd_position++;
1633 idir->fd_dir[i].d_off = idir->fd_position;
1634 idir->fd_dir[i].d_reclen = (uint16_t)sizeof(struct dirent);
1635 }
1636 unlock_fs(fs, FR_OK);
1637 FREE_NAMBUF();
1638 return i;
1639ERROR_UNLOCK:
1640 unlock_fs(fs, result);
1641 FREE_NAMBUF();
1642 return -fatfs_2_vfs(result);
1643}
函数调用图:

◆ fatfs_rename()

int fatfs_rename ( struct Vnode oldvnode,
struct Vnode newparent,
const char *  oldname,
const char *  newname 
)

在文件 fatfs.c1698 行定义.

1699{
1700 FATFS *fs = (FATFS *)(old_vnode->originMount->data);
1701 DIR_FILE *dfp_old = (DIR_FILE *)old_vnode->data;
1702 DIR *dp_old = &(dfp_old->f_dir);
1703 FILINFO *finfo_old = &(dfp_old->fno);
1704 DIR_FILE *dfp_new = NULL;
1705 DIR* dp_new = NULL;
1706 FILINFO* finfo_new = NULL;
1707 DWORD clust;
1708 FRESULT result;
1709 int ret;
1710
1711 ret = lock_fs(fs);
1712 if (ret == FALSE) { /* Lock fs failed */
1713 return -EBUSY;
1714 }
1715
1716 dfp_new = (DIR_FILE *)zalloc(sizeof(DIR_FILE));
1717 if (dfp_new == NULL) {
1718 result = FR_NOT_ENOUGH_CORE;
1719 goto ERROR_UNLOCK;
1720 }
1721 dp_new = &(dfp_new->f_dir);
1722 finfo_new = &(dfp_new->fno);
1723
1724 dp_new->obj.sclust = ((DIR_FILE *)(new_parent->data))->fno.sclst;
1725 dp_new->obj.fs = fs;
1726
1727 /* Find new path */
1728 DEF_NAMBUF;
1729 INIT_NAMBUF(fs);
1730 result = create_name(dp_new, &newname);
1731 if (result != FR_OK) {
1732 goto ERROR_FREE;
1733 }
1734 result = dir_find(dp_new);
1735 if (result == FR_OK) { /* new path name exist */
1736 get_fileinfo(dp_new, finfo_new);
1737 result = rename_check(dp_new, finfo_new, dp_old, finfo_old);
1738 if (result != FR_OK) {
1739 goto ERROR_FREE;
1740 }
1741 result = dir_remove(dp_old);
1742 if (result != FR_OK) {
1743 goto ERROR_FREE;
1744 }
1745 clust = finfo_new->sclst;
1746 if (clust != 0) { /* remove the new path cluster chain if exists */
1747 result = remove_chain(&(dp_new->obj), clust, 0);
1748 if (result != FR_OK) {
1749 goto ERROR_FREE;
1750 }
1751 }
1752 } else { /* new path name not exist */
1753 result = dir_remove(dp_old);
1754 if (result != FR_OK) {
1755 goto ERROR_FREE;
1756 }
1757 result = dir_register(dp_new);
1758 if (result != FR_OK) {
1759 goto ERROR_FREE;
1760 }
1761 }
1762
1763 /* update new dir entry with old info */
1764 result = update_dir(dp_new, finfo_old);
1765 if (result != FR_OK) {
1766 goto ERROR_FREE;
1767 }
1768 result = dir_read(dp_new, 0);
1769 if (result != FR_OK) {
1770 goto ERROR_FREE;
1771 }
1772 dp_new->blk_ofs = dir_ofs(dp_new);
1773 get_fileinfo(dp_new, finfo_new);
1774
1775 dfp_new->fno.fp_list.pstNext = dfp_old->fno.fp_list.pstNext;
1776 dfp_new->fno.fp_list.pstPrev = dfp_old->fno.fp_list.pstPrev;
1777 ret = memcpy_s(dfp_old, sizeof(DIR_FILE), dfp_new, sizeof(DIR_FILE));
1778 if (ret != 0) {
1779 result = FR_NOT_ENOUGH_CORE;
1780 goto ERROR_FREE;
1781 }
1782 free(dfp_new);
1783 unlock_fs(fs, FR_OK);
1784 FREE_NAMBUF();
1785 return fatfs_sync(old_vnode->originMount->mountFlags, fs);
1786
1787ERROR_FREE:
1788 free(dfp_new);
1789ERROR_UNLOCK:
1790 unlock_fs(fs, result);
1791 FREE_NAMBUF();
1792 return -fatfs_2_vfs(result);
1793}
static FRESULT update_dir(DIR *dp, FILINFO *finfo)
Definition: fatfs.c:723
static FRESULT rename_check(DIR *dp_new, FILINFO *finfo_new, DIR *dp_old, FILINFO *finfo_old)
Definition: fatfs.c:1670
函数调用图:

◆ fatfs_rewinddir()

int fatfs_rewinddir ( struct Vnode vnode,
struct fs_dirent_s *  dir 
)

在文件 fatfs.c1645 行定义.

1646{
1647 DIR *dp = (DIR *)dir->u.fs_dir;
1648 FATFS *fs = dp->obj.fs;
1649 FRESULT result;
1650 int ret;
1651
1652 ret = lock_fs(fs);
1653 if (ret == FALSE) {
1654 return -EBUSY;
1655 }
1656
1657 result = dir_sdi(dp, 0);
1658 unlock_fs(fs, result);
1659 return -fatfs_2_vfs(result);
1660}
函数调用图:

◆ fatfs_rmdir()

int fatfs_rmdir ( struct Vnode parent,
struct Vnode vp,
const char *  name 
)

在文件 fatfs.c1946 行定义.

1947{
1948 FATFS *fs = (FATFS *)vp->originMount->data;
1949 DIR_FILE *dfp = (DIR_FILE *)vp->data;
1950 FILINFO *finfo = &(dfp->fno);
1951 DIR *dp = &(dfp->f_dir);
1952 DIR dir_sub;
1953 FRESULT result = FR_OK;
1954 int ret;
1955
1956 if (finfo->fattrib & AM_ARC) {
1957 result = FR_NO_DIR;
1958 goto ERROR_OUT;
1959 }
1960
1961 DEF_NAMBUF;
1962 INIT_NAMBUF(fs);
1963
1964 ret = lock_fs(fs);
1965 if (ret == FALSE) {
1966 result = FR_TIMEOUT;
1967 goto ERROR_OUT;
1968 }
1969 dir_sub.obj.fs = fs;
1970 dir_sub.obj.sclust = finfo->sclst;
1971 result = dir_sdi(&dir_sub, 0);
1972 if (result != FR_OK) {
1973 goto ERROR_UNLOCK;
1974 }
1975 result = dir_read(&dir_sub, 0);
1976 if (result == FR_OK) {
1977 result = FR_NO_EMPTY_DIR;
1978 goto ERROR_UNLOCK;
1979 }
1980 result = dir_remove(dp); /* remove directory entry */
1981 if (result != FR_OK) {
1982 goto ERROR_UNLOCK;
1983 }
1984 /* Directory entry contains at least one cluster */
1985 result = remove_chain(&(dp->obj), finfo->sclst, 0);
1986 if (result != FR_OK) {
1987 goto ERROR_UNLOCK;
1988 }
1989
1990 unlock_fs(fs, FR_OK);
1991 FREE_NAMBUF();
1992 return fatfs_sync(vp->originMount->mountFlags, fs);
1993
1994ERROR_UNLOCK:
1995 unlock_fs(fs, result);
1996 FREE_NAMBUF();
1997ERROR_OUT:
1998 return -fatfs_2_vfs(result);
1999}
函数调用图:

◆ fatfs_stat()

int fatfs_stat ( struct Vnode vnode,
struct stat *  buff 
)

在文件 fatfs.c1439 行定义.

1440{
1441 FATFS *fs = (FATFS *)vp->originMount->data;
1442 DIR_FILE *dfp = (DIR_FILE *)vp->data;
1443 FILINFO *finfo = &(dfp->fno);
1444 time_t time;
1445 int ret;
1446
1447 ret = lock_fs(fs);
1448 if (ret == FALSE) {
1449 return EBUSY;
1450 }
1451
1452 sp->st_dev = fs->pdrv;
1453 sp->st_mode = vp->mode;
1454 sp->st_nlink = 1;
1455 sp->st_uid = fs->fs_uid;
1456 sp->st_gid = fs->fs_gid;
1457 sp->st_size = finfo->fsize;
1458 sp->st_blksize = fs->csize * SS(fs);
1459 if (finfo->fattrib & AM_ARC) {
1460 sp->st_blocks = finfo->fsize ? ((finfo->fsize - 1) / SS(fs) / fs->csize + 1) : 0;
1461 } else {
1462 sp->st_blocks = fs->csize;
1463 }
1464 time = fattime_transfer(finfo->fdate, finfo->ftime);
1465 sp->st_mtime = time;
1466
1467 /* Adapt to kstat member "long tv_sec" */
1468 sp->__st_mtim32.tv_sec = (long)time;
1469
1470 unlock_fs(fs, FR_OK);
1471 return 0;
1472}
macro EXC_SP_SET reg1 mrc 获取CPU信息 and mov mul reg0 计算当前CPU栈的偏移位置 ldr reg1 相减得到栈顶 mov sp
Definition: asm.h:57
static time_t fattime_transfer(WORD fdate, WORD ftime)
Definition: fatfs.c:1407
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 ARG_NUM_3 void ARG_NUM_1 ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_5 ARG_NUM_3 ARG_NUM_3 ARG_NUM_4 ARG_NUM_1 ARG_NUM_1 ARG_NUM_3 ARG_NUM_2 ARG_NUM_1 ARG_NUM_4 ARG_NUM_4 ARG_NUM_5 ARG_NUM_3 ARG_NUM_2 void ARG_NUM_6 unsigned ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_3 ARG_NUM_3 ARG_NUM_2 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_1 char ARG_NUM_0 ARG_NUM_4 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_2 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_6 ARG_NUM_6 ARG_NUM_5 ARG_NUM_3 void ARG_NUM_3 ARG_NUM_3 ARG_NUM_5 ARG_NUM_1 unsigned ARG_NUM_3 long
time_t time(time_t *t)
Definition: time.c:1224
函数调用图:

◆ fatfs_statfs()

int fatfs_statfs ( struct Mount mount,
struct statfs *  info 
)

在文件 fatfs.c1339 行定义.

1340{
1341 FATFS *fs = (FATFS *)mnt->data;
1342 DWORD nclst = 0;
1343 FRESULT result = FR_OK;
1344 int ret;
1345
1346 info->f_type = MSDOS_SUPER_MAGIC;
1347#if FF_MAX_SS != FF_MIN_SS
1348 info->f_bsize = fs->ssize * fs->csize;
1349#else
1350 info->f_bsize = FF_MIN_SS * fs->csize;
1351#endif
1352 info->f_blocks = fs->n_fatent;
1353 ret = lock_fs(fs);
1354 if (ret == FALSE) {
1355 return -EBUSY;
1356 }
1357 /* free cluster is unavailable, update it */
1358 if (fs->free_clst == DISK_ERROR) {
1359 result = fat_count_free_entries(&nclst, fs);
1360 }
1361 info->f_bfree = fs->free_clst;
1362 info->f_bavail = fs->free_clst;
1363 unlock_fs(fs, result);
1364
1365#if FF_USE_LFN
1366 /* Maximum length of filenames */
1367 info->f_namelen = FF_MAX_LFN;
1368#else
1369 /* Maximum length of filenames: 8 is the basename length, 1 is the dot, 3 is the extension length */
1370 info->f_namelen = (8 + 1 + 3);
1371#endif
1372 info->f_fsid.__val[0] = MSDOS_SUPER_MAGIC;
1373 info->f_fsid.__val[1] = 1;
1374 info->f_frsize = SS(fs) * fs->csize;
1375 info->f_files = 0;
1376 info->f_ffree = 0;
1377 info->f_flags = mnt->mountFlags;
1378
1379 return -fatfs_2_vfs(result);
1380}
函数调用图:

◆ fatfs_truncate()

int fatfs_truncate ( struct Vnode vnode,
off_t  len 
)

在文件 fatfs.c1058 行定义.

1059{
1060 return fatfs_truncate64(vp, len);
1061}
int fatfs_truncate64(struct Vnode *vp, off64_t len)
Definition: fatfs.c:1015
函数调用图:

◆ fatfs_truncate64()

int fatfs_truncate64 ( struct Vnode vnode,
off64_t  len 
)

在文件 fatfs.c1015 行定义.

1016{
1017 FATFS *fs = (FATFS *)vp->originMount->data;
1018 DIR_FILE *dfp = (DIR_FILE *)vp->data;
1019 DIR *dp = &(dfp->f_dir);
1020 FILINFO *finfo = &(dfp->fno);
1021 FFOBJID object;
1022 FRESULT result = FR_OK;
1023 int ret;
1024
1025 if (len < 0 || len >= FAT32_MAXSIZE) {
1026 return -EINVAL;
1027 }
1028
1029 ret = lock_fs(fs);
1030 if (ret == FALSE) {
1031 result = FR_TIMEOUT;
1032 goto ERROR_OUT;
1033 }
1034 if (len == finfo->fsize) {
1035 unlock_fs(fs, FR_OK);
1036 return 0;
1037 }
1038
1039 object.fs = fs;
1040 result = realloc_cluster(finfo, &object, (FSIZE_t)len);
1041 if (result != FR_OK) {
1042 goto ERROR_UNLOCK;
1043 }
1044 finfo->fsize = (FSIZE_t)len;
1045
1046 result = update_dir(dp, finfo);
1047 if (result != FR_OK) {
1048 goto ERROR_UNLOCK;
1049 }
1050 unlock_fs(fs, FR_OK);
1051 return fatfs_sync(vp->originMount->mountFlags, fs);
1052ERROR_UNLOCK:
1053 unlock_fs(fs, result);
1054ERROR_OUT:
1055 return -fatfs_2_vfs(result);
1056}
static FRESULT realloc_cluster(FILINFO *finfo, FFOBJID *obj, FSIZE_t size)
Definition: fatfs.c:951
函数调用图:
这是这个函数的调用关系图:

◆ fatfs_umount()

int fatfs_umount ( struct Mount mount,
struct Vnode **  device 
)

在文件 fatfs.c1254 行定义.

1255{
1256 struct Vnode *device;
1257 FATFS *fs = (FATFS *)mnt->data;
1258 los_part *part;
1259 int ret;
1260
1261 ret = lock_fs(fs);
1262 if (ret == FALSE) {
1263 return -EBUSY;
1264 }
1265
1266 part = get_part(fs->pdrv);
1267 if (part == NULL) {
1268 unlock_fs(fs, FR_OK);
1269 return -ENODEV;
1270 }
1271 device = part->dev;
1272 if (device == NULL) {
1273 unlock_fs(fs, FR_OK);
1274 return -ENODEV;
1275 }
1276#ifdef LOSCFG_FS_FAT_CACHE
1277 ret = OsSdSync(part->disk_id);
1278 if (ret != 0) {
1279 unlock_fs(fs, FR_DISK_ERR);
1280 return -EIO;
1281 }
1282#endif
1283 if (part->part_name != NULL) {
1284 free(part->part_name);
1285 part->part_name = NULL;
1286 }
1287
1288 struct drv_data *dd = device->data;
1289 if (dd->ops == NULL) {
1290 unlock_fs(fs, FR_OK);
1291 return ENODEV;
1292 }
1293
1294 const struct block_operations *bops = dd->ops;
1295 if (bops != NULL && bops->close != NULL) {
1296 bops->close(*blkdriver);
1297 }
1298
1299 if (fs->win != NULL) {
1300 ff_memfree(fs->win);
1301 }
1302
1303 unlock_fs(fs, FR_OK);
1304
1305 ret = ff_del_syncobj(&fs->sobj);
1306 if (ret == FALSE) {
1307 return -EINVAL;
1308 }
1309 free(fs);
1310
1311 *blkdriver = device;
1312
1313 return 0;
1314}
函数调用图:

◆ fatfs_unlink()

int fatfs_unlink ( struct Vnode parent,
struct Vnode vp,
const char *  name 
)

在文件 fatfs.c2008 行定义.

2009{
2010 FATFS *fs = (FATFS *)vp->originMount->data;
2011 DIR_FILE *dfp = (DIR_FILE *)vp->data;
2012 FILINFO *finfo = &(dfp->fno);
2013 DIR *dp = &(dfp->f_dir);
2014 FRESULT result = FR_OK;
2015 int ret;
2016
2017 if (finfo->fattrib & AM_DIR) {
2018 result = FR_IS_DIR;
2019 goto ERROR_OUT;
2020 }
2021 ret = lock_fs(fs);
2022 if (ret == FALSE) {
2023 result = FR_TIMEOUT;
2024 goto ERROR_OUT;
2025 }
2026 result = dir_remove(dp); /* remove directory entry */
2027 if (result != FR_OK) {
2028 goto ERROR_UNLOCK;
2029 }
2030 if (finfo->sclst != 0) { /* if cluster chain exists */
2031 result = remove_chain(&(dp->obj), finfo->sclst, 0);
2032 if (result != FR_OK) {
2033 goto ERROR_UNLOCK;
2034 }
2035 }
2036 result = sync_fs(fs);
2037 if (result != FR_OK) {
2038 goto ERROR_UNLOCK;
2039 }
2040 unlock_fs(fs, FR_OK);
2041 return fatfs_sync(vp->originMount->mountFlags, fs);
2042
2043ERROR_UNLOCK:
2044 unlock_fs(fs, result);
2045ERROR_OUT:
2046 return -fatfs_2_vfs(result);
2047}
函数调用图:

◆ fatfs_write()

int fatfs_write ( struct file filep,
const char *  buff,
size_t  count 
)

在文件 fatfs.c858 行定义.

859{
860 FIL *fp = (FIL *)filep->f_priv;
861 FATFS *fs = fp->obj.fs;
862 struct Vnode *vp = filep->f_vnode;
863 FILINFO *finfo = &(((DIR_FILE *)vp->data)->fno);
864 size_t wcount;
865 FRESULT result;
866 int ret;
867
868 ret = lock_fs(fs);
869 if (ret == FALSE) {
870 return -EBUSY;
871 }
872 fp->obj.objsize = finfo->fsize;
873 fp->obj.sclust = finfo->sclst;
874 result = f_write(fp, buff, count, &wcount);
875 if (result != FR_OK) {
876 goto ERROR_EXIT;
877 }
878
879 finfo->fsize = fp->obj.objsize;
880 finfo->sclst = fp->obj.sclust;
881 result = f_sync(fp);
882 if (result != FR_OK) {
883 goto ERROR_EXIT;
884 }
885 update_filbuff(finfo, fp, buff);
886
887 filep->f_pos = fp->fptr;
888
889 unlock_fs(fs, FR_OK);
890 return wcount;
891ERROR_EXIT:
892 unlock_fs(fs, result);
893 return -fatfs_2_vfs(result);
894}
static int update_filbuff(FILINFO *finfo, FIL *wfp, const char *data)
Definition: fatfs.c:837
函数调用图:

◆ find_fat_partition()

FRESULT find_fat_partition ( FATFS *  fs,
los_part part,
BYTE *  format,
QWORD *  start_sector 
)
这是这个函数的调用关系图:

◆ init_fatobj()

FRESULT init_fatobj ( FATFS *  fs,
BYTE  fmt,
QWORD  start_sector 
)
这是这个函数的调用关系图:

变量说明

◆ FatLabel

char FatLabel[LABEL_LEN]
extern

在文件 format.c41 行定义.