提交 0469e5b8 编写于 作者: O openharmony_ci 提交者: Gitee

!378 修复了FATFS设置卷标的功能

Merge pull request !378 from Far/master
......@@ -1776,6 +1776,45 @@ static int fatfs_set_part_info(los_part *part)
return 0;
}
static FRESULT fatfs_setlabel(los_part *part)
{
QWORD start_sector = 0;
BYTE fmt = 0;
FATFS fs;
FRESULT result;
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
fs.vir_flag = FS_PARENT;
fs.parent_fs = &fs;
fs.vir_amount = DISK_ERROR;
fs.vir_avail = FS_VIRDISABLE;
#endif
if (disk_ioctl(fs.pdrv, GET_SECTOR_SIZE, &(fs.ssize)) != RES_OK) {
return -EIO;
}
fs.win = (BYTE *)ff_memalloc(fs.ssize);
if (fs.win == NULL) {
return -ENOMEM;
}
result = find_fat_partition(&fs, part, &fmt, &start_sector);
if (result != FR_OK) {
free(fs.win);
return -fatfs_2_vfs(result);
}
result = init_fatobj(&fs, fmt, start_sector);
if (result != FR_OK) {
free(fs.win);
return -fatfs_2_vfs(result);
}
result = set_volumn_label(&fs, FatLabel);
free(fs.win);
return result;
}
int fatfs_mkfs (struct Vnode *device, int sectors, int option)
{
BYTE *work_buff = NULL;
......@@ -1811,19 +1850,22 @@ int fatfs_mkfs (struct Vnode *device, int sectors, int option)
return -fatfs_2_vfs(result);
}
result = fatfs_setlabel(part);
if (result == FR_OK) {
#ifdef LOSCFG_FS_FAT_CACHE
ret = OsSdSync(part->disk_id);
if (ret != 0) {
return -EIO;
}
ret = OsSdSync(part->disk_id);
if (ret != 0) {
return -EIO;
}
#endif
}
ret = fatfs_set_part_info(part);
if (ret != 0) {
return -EIO;
}
return 0;
return -fatfs_2_vfs(result);
}
int fatfs_mkdir(struct Vnode *parent, const char *name, mode_t mode, struct Vnode **vpp)
......
......@@ -113,6 +113,8 @@ extern "C" {
#define FMT_ANY 0x07
#define FMT_ERASE 0x08
extern char FatLabel[LABEL_LEN];
int fatfs_2_vfs(int result);
int fatfs_lookup(struct Vnode *parent, const char *name, int len, struct Vnode **vpp);
int fatfs_create(struct Vnode *parent, const char *name, int mode, struct Vnode **vpp);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册