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

浏览源代码.

函数

int format (const char *dev, int sectors, int option)
 formatting sd card 更多...
 
void set_label (const char *name)
 

变量

char FatLabel [LABEL_LEN]
 

函数说明

◆ format()

int format ( const char *  dev,
int  sectors,
int  option 
)

formatting sd card

Description:
formatting sd card.
注意
  • The prefix of the parameter dev must be "/dev", and the length must be less than the value defined by PATH_MAX. There are four kind of format option: FMT_FAT16, FMT_FAT32, FMT_ANY, FMT_ERASE. If users input anything else, the default format option is FMT_ANY. Format option is decided by the number of clusters. Choosing the wrong option will cause error of format. The detailed information of (FAT16,FAT32) is ff.h.
参数
dev[IN] Type #const char* path of the block device to format, which must be a really existing block device node.
sectors[IN] Type int number of sectors per cluster.
option[IN] Type int option of format.
返回值
#0Format success.
#-1Format failed.
Dependency:
  • unistd.h: the header file that contains the API declaration.
参见

在文件 format.c44 行定义.

45{
46 struct Vnode *device = NULL;
47 INT err;
48 if (dev == NULL) {
49 set_errno(EINVAL);
50 return -1;
51 }
52
53 if (strncmp(dev, "/dev", DEV_NAME_SIZE) != 0) {
54 PRINTK("Usage :\n");
55 PRINTK(" format <dev_vnodename> <sectors> <option> <label>\n");
56 PRINTK(" dev_vnodename : the name of dev\n");
57 PRINTK(" sectors : Size of allocation unit in unit of byte or sector, ");
58 PRINTK("0 instead of default size\n");
59 PRINTK(" options : Index of filesystem. 1 for FAT filesystem, 2 for FAT32 filesystem, ");
60 PRINTK("7 for any, 8 for erase\n");
61 PRINTK(" label : The volume of device. It will be emptyed when this parameter is null\n");
62 PRINTK("Example:\n");
63 PRINTK(" format /dev/mmcblk0 128 2\n");
64
65 set_errno(EINVAL);
66 return -1;
67 }
68 VnodeHold();
69 err = VnodeLookup(dev, &device, 0);
70 if (err == -ENOENT || err == -ENOSYS) {
71 VnodeDrop();
72 set_errno(ENODEV);
73 return -1;
74 } else if (err < 0) {
75 VnodeDrop();
76 set_errno(-err);
77 return -1;
78 }
79 err = fatfs_mkfs(device, sectors, option);
80 if (err < 0) {
81 VnodeDrop();
82 set_errno(-err);
83 return -1;
84 }
85#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
86 else if (err >= VIRERR_BASE) {
87 set_errno(err);
88 }
89#endif
90 VnodeDrop();
91 return 0;
92}
int fatfs_mkfs(struct Vnode *device, int sectors, int option)
Definition: fatfs.c:1885
vnode并不包含文件名,因为 vnode和文件名是 1:N 的关系
Definition: vnode.h:164
int VnodeDrop(void)
归还锁
Definition: vnode.c:292
int VnodeHold(void)
拿锁,封装互斥量
Definition: vnode.c:283
int VnodeLookup(const char *path, struct Vnode **vnode, uint32_t flags)
通过路径查询vnode节点
Definition: vnode.c:491
函数调用图:
这是这个函数的调用关系图:

◆ set_label()

void set_label ( const char *  name)
Description:
The set_label() function shall set the value of a global varible, the value will be used to set the label of SD card in format().
参数
name[IN] label to set, the length must be less than 12
注意
  • The function must be called before format().
返回值
voidNone.
Dependency:
  • fs.h
参见
format

在文件 format.c94 行定义.

95{
96 INT len;
97 INT err;
98
99 (void)memset_s(FatLabel, LABEL_LEN, 0, LABEL_LEN);
100
101 if (name == NULL || *name == '\0') {
102 return;
103 }
104
105 len = strlen(name);
106 if (len >= LABEL_LEN) {
107 len = LABEL_LEN - 1;
108 }
109
110 err = strncpy_s(FatLabel, LABEL_LEN, name, len);
111 if (err != EOK) {
112 PRINT_ERR("Fat set_label error");
113 }
114}
char FatLabel[LABEL_LEN]
Definition: format.c:41
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
这是这个函数的调用关系图:

变量说明

◆ FatLabel

char FatLabel[LABEL_LEN]

在文件 format.c41 行定义.