commit
0469e5b849
|
@ -1776,6 +1776,45 @@ static int fatfs_set_part_info(los_part *part)
|
||||||
return 0;
|
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)
|
int fatfs_mkfs (struct Vnode *device, int sectors, int option)
|
||||||
{
|
{
|
||||||
BYTE *work_buff = NULL;
|
BYTE *work_buff = NULL;
|
||||||
|
@ -1811,19 +1850,22 @@ int fatfs_mkfs (struct Vnode *device, int sectors, int option)
|
||||||
return -fatfs_2_vfs(result);
|
return -fatfs_2_vfs(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
result = fatfs_setlabel(part);
|
||||||
|
if (result == FR_OK) {
|
||||||
#ifdef LOSCFG_FS_FAT_CACHE
|
#ifdef LOSCFG_FS_FAT_CACHE
|
||||||
ret = OsSdSync(part->disk_id);
|
ret = OsSdSync(part->disk_id);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
ret = fatfs_set_part_info(part);
|
ret = fatfs_set_part_info(part);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return -fatfs_2_vfs(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fatfs_mkdir(struct Vnode *parent, const char *name, mode_t mode, struct Vnode **vpp)
|
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_ANY 0x07
|
||||||
#define FMT_ERASE 0x08
|
#define FMT_ERASE 0x08
|
||||||
|
|
||||||
|
extern char FatLabel[LABEL_LEN];
|
||||||
|
|
||||||
int fatfs_2_vfs(int result);
|
int fatfs_2_vfs(int result);
|
||||||
int fatfs_lookup(struct Vnode *parent, const char *name, int len, struct Vnode **vpp);
|
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);
|
int fatfs_create(struct Vnode *parent, const char *name, int mode, struct Vnode **vpp);
|
||||||
|
|
Loading…
Reference in New Issue