【u-boot】u-boot支持的文件系统
一、概览
u-boot支持的文件系统如下:
二、源码剖析
(1)strcut fstype_info
文件系统相关的操作代码实现在对应名称的名录中,对于u-boot来说,实现了一个上层接口:fs.c
。在该文件中使用strcut fstype_info
描述一个文件系统的实例和操作接口:
struct fstype_info {int fstype;char *name;/** Is it legal to pass NULL as .probe()'s fs_dev_desc parameter? This* should be false in most cases. For "virtual" filesystems which* aren't based on a U-Boot block device (e.g. sandbox), this can be* set to true. This should also be true for the dumm entry at the end* of fstypes[], since that is essentially a "virtual" (non-existent)* filesystem.*/bool null_dev_desc_ok;int (*probe)(struct blk_desc *fs_dev_desc,disk_partition_t *fs_partition);int (*ls)(const char *dirname);int (*exists)(const char *filename);int (*size)(const char *filename, loff_t *size);int (*read)(const char *filename, void *buf, loff_t offset,loff_t len, loff_t *actread);int (*write)(const char *filename, void *buf, loff_t offset,loff_t len, loff_t *actwrite);void (*close)(void);int (*uuid)(char *uuid_str);/** Open a directory stream. On success return 0 and directory* stream pointer via 'dirsp'. On error, return -errno. See* fs_opendir().*/int (*opendir)(const char *filename, struct fs_dir_stream **dirsp);/** Read next entry from directory stream. On success return 0* and directory entry pointer via 'dentp'. On error return* -errno. See fs_readdir().*/int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp);/* see fs_closedir() */void (*closedir)(struct fs_dir_stream *dirs);
};
上述结构体各字段含义如下:
(1)int fstype;
:整数ID,用来识别文件系统类型(例如FS_TYPE_FAT
/FS_TYPE_EXT
等)。fstypes[]
中按此字段匹配/查找。
(2)char *name;
:可读字符串名(通常是静态字符串字面量)。建议驱动把常量字符串指针放在这里(不要在注册后free),因为fstypes[]
是静态表,名字应有静态生命周期。
(3)bool null_dev_desc_ok;
:指示当fs_dev_desc
(struct blk_desc *
)为NULL
时,probe()
是否仍然可以被调用并执行。对于基于块设备的真实文件系统(sd/mmc/usb),通常不允许设置为NULL。对于“虚拟”文件系统(例如sandbox /hostfs/某些内存/虚拟后端),可以设为true
,允许无块设备上下文。源码里对这个字段有注释说明。
(4)probe()
:用来“识别 / 打开 / 初始化”指定设备上的该种文件系统。文件系统层会遍历fstypes[]
,并调用每个info->probe()
来检测是否为该文件系统。如果probe()
返回“0 表示识别成功”时,fs
层将接受该类型并把它标记为当前文件系统。->probe()
的调用发生在两个函数中:fs_set_blk_dev()
和fs_set_blk_dev_with_part()
。
(4-1)fs_set_blk_dev()
根据指定的设备和分区信息,自动探测可用的文件系统类型,并准备好全局文件系统环境(fs_type
, fs_dev_desc
, fs_partition
)以供后续读写操作使用。换句话说,这是文件系统层在调用fs_read()
、fs_ls()
之前必须执行的“挂载”动作。
int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
{struct fstype_info *info;int part, i;
#ifdef CONFIG_NEEDS_MANUAL_RELOCstatic int relocated;if (!relocated) {for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes);i++, info++) {info->name += gd->reloc_off;info->probe += gd->reloc_off;info->close += gd->reloc_off;info->ls += gd->reloc_off;info->read += gd->reloc_off;info->