提交 2360f111 编写于 作者: E evanscjv

Description: FatFs liteos_m adapt

Reviewed-by: shenwei
上级 072f2531
......@@ -6,16 +6,25 @@
/* This is an example of glue functions to attach various exsisting */
/* storage control modules to the FatFs module with a defined API. */
/*-----------------------------------------------------------------------*/
#include "diskio.h" /* Declarations of disk functions */
#include "diskio.h"
#ifndef __LITEOS_M__
#include "fs/fs.h"
#include "string.h"
#include "disk.h"
#else
#include "ff_gen_drv.h"
#if defined ( __GNUC__ )
#ifndef __weak
#define __weak __attribute__((weak))
#endif
#endif
#endif
/*-----------------------------------------------------------------------*/
/* Get Drive Status */
/*-----------------------------------------------------------------------*/
#ifndef __LITEOS_M__
#define CARD_UNPLUGED 1
extern int get_cardstatus(int pdrv);
#define GET_CARD_STATUS \
......@@ -24,12 +33,20 @@ extern int get_cardstatus(int pdrv);
return STA_NOINIT; \
} while (0)
extern struct tm tm;
#endif
DSTATUS disk_status (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
#ifndef __LITEOS_M__
return 0;
#else
DSTATUS stat;
stat = g_diskDrv.drv[pdrv]->disk_status(g_diskDrv.lun[pdrv]);
return stat;
#endif
}
......@@ -42,7 +59,17 @@ DSTATUS disk_initialize (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
#ifndef __LITEOS_M__
return 0;
#else
DSTATUS stat = RES_OK;
if(g_diskDrv.initialized[pdrv] == 0)
{
stat = g_diskDrv.drv[pdrv]->disk_initialize(g_diskDrv.lun[pdrv]);
}
return stat;
#endif
}
......@@ -58,6 +85,7 @@ DRESULT disk_read (
UINT count /* Number of sectors to read */
)
{
#ifndef __LITEOS_M__
int result;
result = los_part_read((int)pdrv, (void *)buff, sector, (UINT32)count);
......@@ -66,8 +94,15 @@ DRESULT disk_read (
return RES_OK;
else
return RES_ERROR;
#else
DRESULT res;
res = g_diskDrv.drv[pdrv]->disk_read(g_diskDrv.lun[pdrv], buff, sector, count);
return res;
#endif
}
#ifndef __LITEOS_M__
DRESULT disk_raw_read (int id, void *buff, QWORD sector, UINT32 count)
{
int result;
......@@ -79,12 +114,16 @@ DRESULT disk_raw_read (int id, void *buff, QWORD sector, UINT32 count)
else
return RES_ERROR;
}
#endif
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
/*-----------------------------------------------------------------------*/
#if FF_FS_READONLY == 0
DRESULT disk_write (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */
......@@ -92,6 +131,7 @@ DRESULT disk_write (
UINT count /* Number of sectors to write */
)
{
#ifndef __LITEOS_M__
int result;
result = los_part_write((int)pdrv, (void *)buff, sector, (UINT32)count);
......@@ -100,8 +140,16 @@ DRESULT disk_write (
return RES_OK;
else
return RES_ERROR;
#else
DRESULT res;
res = g_diskDrv.drv[pdrv]->disk_write(g_diskDrv.lun[pdrv], buff, sector, count);
return res;
#endif
}
#ifndef __LITEOS_M__
DRESULT disk_raw_write(int id, void *buff, QWORD sector, UINT32 count){
int result;
void *uwBuff = buff;
......@@ -113,6 +161,10 @@ DRESULT disk_raw_write(int id, void *buff, QWORD sector, UINT32 count){
else
return RES_ERROR;
}
#endif
#endif /* FF_FS_READONLY == 0 */
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions */
......@@ -124,6 +176,7 @@ DRESULT disk_ioctl (
void *buff /* Buffer to send/receive control data */
)
{
#ifndef __LITEOS_M__
int result;
result = los_part_ioctl((int)pdrv, (int)cmd, buff);
......@@ -132,8 +185,21 @@ DRESULT disk_ioctl (
return RES_OK;
else
return RES_ERROR;
#else
DRESULT res;
res = g_diskDrv.drv[pdrv]->disk_ioctl(g_diskDrv.lun[pdrv], cmd, buff);
return res;
#endif
}
/*
* @brief Gets Time from RTC
* @param None
* @retval Time in DWORD
*/
#ifndef __LITEOS_M__
DWORD get_fattime (void)
{
time_t seconds = 0;
......@@ -155,5 +221,10 @@ DWORD get_fattime (void)
((DWORD)local_time.tm_min << 5) |
((DWORD)local_time.tm_sec >> 1);
}
#else
__weak DWORD get_fattime (void)
{
return 0;
}
#endif
......@@ -11,8 +11,12 @@ extern "C" {
#endif /*__cplusplus */
#endif /*__cplusplus */
#ifndef __LITEOS_M__
#include "integer.h"
#include "ffconf.h"
#else
#include "ff.h"
#endif
/* Status of Disk Functions */
typedef BYTE DSTATUS;
......@@ -32,10 +36,15 @@ typedef enum {
DSTATUS disk_initialize (BYTE pdrv);
DSTATUS disk_status (BYTE pdrv);
DRESULT disk_read (BYTE pdrv, BYTE* buff, QWORD sector, UINT count);
DRESULT disk_raw_read (int id, void* buff, QWORD sector, UINT32 count);
DRESULT disk_write (BYTE pdrv, const BYTE* buff, QWORD sector, UINT count);
#ifndef __LITEOS_M__
DRESULT disk_raw_read (int id, void* buff, QWORD sector, UINT32 count);
DRESULT disk_raw_write (int id, void* buff, QWORD sector, UINT32 count);
#endif
DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
#ifdef __LITEOS_M__
DWORD get_fattime (void);
#endif
/* Disk Status Bits (DSTATUS) */
......@@ -64,6 +73,11 @@ DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff);
#define MMC_GET_CID 12 /* Get CID */
#define MMC_GET_OCR 13 /* Get OCR */
#define MMC_GET_SDSTAT 14 /* Get SD status */
#ifdef __LITEOS_M__
#define ISDIO_READ 55 /* Read data form SD iSDIO register */
#define ISDIO_WRITE 56 /* Write data to SD iSDIO register */
#define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */
#endif
/* ATA/CF specific ioctl command */
#define ATA_GET_REV 20 /* Get F/W revision */
......
......@@ -19,7 +19,12 @@
#include "ff.h" /* Declarations of FatFs API */
#ifndef __LITEOS_M__
#include <user_copy.h>
#else
#include "os_feature.h"
#include "cmsis_os.h"
#endif
#include "diskio.h" /* Declarations of device I/O functions */
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
......@@ -2710,7 +2715,7 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */
bsect = 0;
fmt = check_fs(fs, bsect); /* Load sector 0 and check if it is an FAT-VBR as SFD */
if (fmt == 2 || (fmt < 2 && LD2PT(vol) != 0)) { /* Not an FAT-VBR or forced partition number */
if (fs->win[MBR_Table + 4] != 0xEE) { /* The partition type is GPT, not MBR */
if (fs->win[MBR_Table + 4] != 0xEE) { /* The partition type is MBR, not GPT */
/* Read MBR and EBR to get right boot sector. */
extended_br = LD2PT(vol) - 4;
if (extended_br > 0) {
......@@ -2722,14 +2727,25 @@ FRESULT find_volume ( /* FR_OK(0): successful, !=0: an error occurred */
bsect = ld_dword(&pt[8]);
do {
mem_set(fs->win, 0, SS(fs));
#ifndef __LITEOS_M__
if (disk_raw_read(LD2DI(vol), fs->win, bsect + offset, 1) != RES_OK) return FR_DISK_ERR;
#else
if (disk_read(LD2PD(vol), fs->win, bsect + offset, 1) != RES_OK) return FR_DISK_ERR;
#endif
pt = fs->win + MBR_Table;
offset = ld_dword(&pt[SZ_PTE + 8]);
} while (--extended_br);
}
i = LD2PT(vol); /* Partition number: 0:auto, 1-4:primary, >4:logical */
if (i) { /* Find an FAT volume */
#ifndef __LITEOS_M__
bsect = LD2PS(vol);
#else
i = LD2PT(vol); /* Partition number: 0:auto, 1-4:forced */
if (i != 0) i--;
pt = fs->win + (MBR_Table + i * SZ_PTE);
bsect = pt[PTE_System] ? ld_dword(pt + PTE_StLba) : 0;
#endif
} else {
pt = fs->win + MBR_Table;
bsect = pt[4] ? ld_dword(&pt[8]) : 0;
......@@ -2970,7 +2986,9 @@ FRESULT f_open (
FRESULT res;
DIR dj;
FATFS *fs;
#if FF_FS_REENTRANT
FATFS *fs_bak;
#endif
#if !FF_FS_READONLY
DWORD clst, cl, bcs;
QWORD sc, dw;
......@@ -2984,15 +3002,25 @@ FRESULT f_open (
/* Get logical drive number */
mode &= FF_FS_READONLY ? FA_READ : FA_READ | FA_WRITE | FA_CREATE_ALWAYS | FA_CREATE_NEW | FA_OPEN_ALWAYS | FA_OPEN_APPEND | FA_SEEKEND;
res = find_volume(&path, &fs, mode);
#if FF_FS_REENTRANT
fs_bak = fs;
#endif
if (res == FR_OK) {
dj.obj.fs = fs;
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
#if FF_FS_REENTRANT
if (ISCHILD(fs)) LEAVE_FF(fs_bak,FR_INVAILD_FATFS);
#else
if (ISCHILD(fs)) LEAVE_FF(fs,FR_INVAILD_FATFS);
#endif
if (ISVIRPART(fs)) {
/* Check the virtual partition top directory, and match the virtual fs */
res = follow_virentry(&dj.obj,path);
#if FF_FS_REENTRANT
if (res == FR_INT_ERR) LEAVE_FF(fs_bak,res);
#else
if (res == FR_INT_ERR) LEAVE_FF(fs,res);
#endif
if (res == FR_OK)
fs = dj.obj.fs;
}
......@@ -3189,8 +3217,11 @@ FRESULT f_open (
}
if (res != FR_OK) fp->obj.fs = 0; /* Invalidate file object on error */
#if FF_FS_REENTRANT
LEAVE_FF(fs_bak, res);
#else
LEAVE_FF(fs, res);
#endif
}
......@@ -3214,7 +3245,9 @@ FRESULT f_read (
FSIZE_t remain;
UINT rcnt, cc, csect;
BYTE *rbuff = (BYTE*)buff;
#ifndef __LITEOS_M__
UINT copy_ret;
#endif
*br = 0; /* Clear read byte counter */
res = validate(&fp->obj, &fs); /* Check validity of the file object */
......@@ -3256,13 +3289,21 @@ FRESULT f_read (
#if !FF_FS_READONLY && FF_FS_MINIMIZE <= 2 /* Replace one of the read sectors with cached data if it contains a dirty sector */
#if FF_FS_TINY
if (fs->wflag && fs->winsect - sect < cc) {
#ifndef __LITEOS_M__
copy_ret = LOS_CopyFromKernel(rbuff + ((fs->winsect - sect) * SS(fs)), SS(fs), fs->win, SS(fs));
if (copy_ret != EOK) ABORT(fs, FR_INVALID_PARAMETER);
#else
mem_cpy(rbuff + ((fs->winsect - sect) * SS(fs)), fs->win, SS(fs));
#endif
}
#else
if ((fp->flag & FA_DIRTY) && fp->sect - sect < cc) {
#ifndef __LITEOS_M__
copy_ret = LOS_CopyFromKernel(rbuff + ((fp->sect - sect) * SS(fs)), SS(fs), fp->buf, SS(fs));
if (copy_ret != EOK) ABORT(fs, FR_INVALID_PARAMETER);
#else
mem_cpy(rbuff + ((fp->sect - sect) * SS(fs)), fp->buf, SS(fs));
#endif
}
#endif
#endif
......@@ -3291,8 +3332,12 @@ FRESULT f_read (
if (copy_ret != EOK) ABORT(fs, FR_INVALID_PARAMETER);
#else
/* Extract partial sector */
#ifndef __LITEOS_M__
copy_ret = LOS_CopyFromKernel(rbuff, rcnt, fp->buf + fp->fptr % SS(fs), rcnt);
if (copy_ret != EOK) ABORT(fs, FR_INVALID_PARAMETER);
#else
mem_cpy(rbuff, fp->buf + fp->fptr % SS(fs), rcnt); /* Extract partial sector */
#endif
#endif
}
......@@ -3317,7 +3362,9 @@ FRESULT f_write (
DWORD clst;
UINT wcnt, cc, csect;
const BYTE *wbuff = (const BYTE*)buff;
#ifndef __LITEOS_M__
UINT copy_ret;
#endif
*bw = 0; /* Clear write byte counter */
res = validate(&fp->obj, &fs); /* Check validity of the file object */
......@@ -3381,8 +3428,12 @@ FRESULT f_write (
}
#else
if (fp->sect - sect < cc) { /* Refill sector cache if it gets invalidated by the direct write */
#ifndef __LITEOS_M__
copy_ret = LOS_CopyToKernel(fp->buf, SS(fs), wbuff + ((fp->sect - sect) * SS(fs)), SS(fs));
if (copy_ret != EOK) ABORT(fs, FR_INVALID_PARAMETER);
#else
mem_cpy(fp->buf, wbuff + ((fp->sect - sect) * SS(fs)), SS(fs));
#endif
fp->flag &= (BYTE)~FA_DIRTY;
}
#endif
......@@ -3413,8 +3464,12 @@ FRESULT f_write (
if (copy_ret != EOK) ABORT(fs, FR_INVALID_PARAMETER);
fs->wflag = 1;
#else
#ifndef __LITEOS_M__
copy_ret = LOS_CopyToKernel(fp->buf + fp->fptr % SS(fs), wcnt, wbuff, wcnt);
if (copy_ret != EOK) ABORT(fs, FR_INVALID_PARAMETER);
#else
mem_cpy(fp->buf + fp->fptr % SS(fs), wbuff, wcnt); /* Fit data to the sector */
#endif
fp->flag |= FA_DIRTY;
#endif
......@@ -4215,7 +4270,9 @@ FRESULT f_unlink (
DIR dj, sdj;
DWORD dclst = 0;
FATFS *fs;
#if FF_FS_REENTRANT
FATFS *fs_bak;
#endif
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
DWORD rtclst = 0;
DWORD st_bak = 0;
......@@ -4226,14 +4283,24 @@ FRESULT f_unlink (
/* Get logical drive */
res = find_volume(&path, &fs, FA_WRITE);
dj.obj.fs = fs;
#if FF_FS_REENTRANT
fs_bak = fs;
#endif
if (res == FR_OK) {
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
#if FF_FS_REENTRANT
if (ISCHILD(fs)) LEAVE_FF(fs_bak,FR_INVAILD_FATFS);
#else
if (ISCHILD(fs)) LEAVE_FF(fs,FR_INVAILD_FATFS);
#endif
if (ISVIRPART(fs)) {
/* Check the virtual partition top directory, and match the virtual fs */
res = follow_virentry(&dj.obj,path);
#if FF_FS_REENTRANT
if (res == FR_INT_ERR) LEAVE_FF(fs_bak,res);
#else
if (res == FR_INT_ERR) LEAVE_FF(fs,res);
#endif
if (res == FR_OK)
fs = dj.obj.fs;
}
......@@ -4249,10 +4316,19 @@ FRESULT f_unlink (
st_bak = PARENTFS(dj.obj.fs)->winsect;
/* Follow the root directory cluster chain */
for (;;) {
#if FF_FS_REENTRANT
if (rtclst == 0xFFFFFFFF) LEAVE_FF(fs_bak,FR_DISK_ERR);
#else
if (rtclst == 0xFFFFFFFF) LEAVE_FF(fs,FR_DISK_ERR);
#endif
if (rtclst == 0x0FFFFFFF) break;
#if FF_FS_REENTRANT
if (rtclst < 2 || rtclst >= fs->n_fatent) LEAVE_FF(fs_bak,FR_INT_ERR);
if (rtclst == 0 || rtclst == 1) LEAVE_FF(fs_bak,FR_INT_ERR);
#else
if (rtclst < 2 || rtclst >= fs->n_fatent) LEAVE_FF(fs,FR_INT_ERR);
if (rtclst == 0 || rtclst == 1) LEAVE_FF(fs,FR_INT_ERR);
#endif
/* If current dirent is on rootdir clust chain */
if (dj.clust == rtclst) {
/* Set a flag */
......@@ -4265,7 +4341,11 @@ FRESULT f_unlink (
if (dj.atrootdir == 1) {
if (ISCHILD(fs)) {
/* The FATFS is child object already, that means the operation is trying to delete the virtual partition directory */
#if FF_FS_REENTRANT
LEAVE_FF(fs_bak,FR_DENIED);
#else
LEAVE_FF(fs,FR_DENIED);
#endif
}
}
res = move_window(dj.obj.fs,st_bak);
......@@ -4313,8 +4393,11 @@ FRESULT f_unlink (
}
FREE_NAMBUF();
}
#if FF_FS_REENTRANT
LEAVE_FF(fs_bak, res);
#else
LEAVE_FF(fs, res);
#endif
}
......@@ -4331,7 +4414,9 @@ FRESULT f_mkdir (
FRESULT res;
DIR dj;
FATFS *fs;
#if FF_FS_REENTRANT
FATFS *fs_bak;
#endif
BYTE *dir;
UINT n;
DWORD dcl, pcl, tm;
......@@ -4342,16 +4427,26 @@ FRESULT f_mkdir (
/* Get logical drive */
res = find_volume(&path, &fs, FA_WRITE);
fs_bak = fs;
dj.obj.fs = fs;
#if FF_FS_REENTRANT
fs_bak = fs;
#endif
dj.obj.sclust = 0;
if (res == FR_OK) {
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
#if FF_FS_REENTRANT
if (ISCHILD(fs)) LEAVE_FF(fs_bak,FR_INVAILD_FATFS);
#else
if (ISCHILD(fs)) LEAVE_FF(fs,FR_INVAILD_FATFS);
#endif
if (ISVIRPART(fs)) {
/* Check the virtual partition top directory, and match the virtual fs */
res = follow_virentry(&dj.obj,path);
#if FF_FS_REENTRANT
if (res == FR_INT_ERR) LEAVE_FF(fs_bak,res);
#else
if (res == FR_INT_ERR) LEAVE_FF(fs,res);
#endif
if (res == FR_OK)
fs = dj.obj.fs;
}
......@@ -4437,7 +4532,11 @@ FRESULT f_mkdir (
}
FREE_NAMBUF();
}
#if FF_FS_REENTRANT
LEAVE_FF(fs_bak, res);
#else
LEAVE_FF(fs, res);
#endif
}
/*-----------------------------------------------------------------------*/
......@@ -4452,7 +4551,9 @@ FRESULT f_rename (
FRESULT res;
DIR djo, djn;
FATFS *fs;
#if FF_FS_REENTRANT
FATFS *fs_bak;
#endif
BYTE buf[SZDIRE], *dir;
QWORD dw;
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
......@@ -4464,7 +4565,9 @@ FRESULT f_rename (
get_ldnumber(&path_new); /* Snip the drive number of new name off */
res = find_volume(&path_old, &fs, FA_WRITE); /* Get logical drive of the old object */
#if FF_FS_REENTRANT
fs_bak = fs;
#endif
if (res == FR_OK) {
djo.obj.fs = fs;
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
......@@ -4472,7 +4575,11 @@ FRESULT f_rename (
if (ISVIRPART(fs)) {
/* Check the virtual partition top directory, and match the virtual fs */
res = follow_virentry(&djo.obj,path_old);
#if FF_FS_REENTRANT
if (res == FR_INT_ERR) LEAVE_FF(fs_bak,res);
#else
if (res == FR_INT_ERR) LEAVE_FF(fs,res);
#endif
if (res == FR_OK)
fs = djo.obj.fs;
}
......@@ -4491,10 +4598,17 @@ FRESULT f_rename (
st_bak = PARENTFS(djo.obj.fs)->winsect;
/* Follow the root directory cluster chain */
for (;;) {
#if FF_FS_REENTRANT
if (rtclst == 0xFFFFFFFF) LEAVE_FF(fs_bak,FR_DISK_ERR);
if (rtclst == 0x0FFFFFFF) break;
if (rtclst < 2 || rtclst >= fs->n_fatent) LEAVE_FF(fs_bak,FR_INT_ERR);
if (rtclst == 0 || rtclst == 1) LEAVE_FF(fs_bak,FR_INT_ERR);
#else
if (rtclst == 0xFFFFFFFF) LEAVE_FF(fs,FR_DISK_ERR);
if (rtclst == 0x0FFFFFFF) break;
if (rtclst < 2 || rtclst >= fs->n_fatent) LEAVE_FF(fs,FR_INT_ERR);
if (rtclst == 0 || rtclst == 1) LEAVE_FF(fs,FR_INT_ERR);
#endif
/* If current dirent is on rootdir clust chain */
if (djo.clust == rtclst) {
/* Set a flag */
......@@ -4506,7 +4620,11 @@ FRESULT f_rename (
if (djo.atrootdir == 1) {
if (ISCHILD(fs)) {
/* The FATFS is child object already, that means the operation is trying to delete the virtual partition directory */
#if FF_FS_REENTRANT
LEAVE_FF(fs_bak,FR_DENIED);
#else
LEAVE_FF(fs,FR_DENIED);
#endif
}
}
res = move_window(djo.obj.fs,st_bak);
......@@ -4566,8 +4684,11 @@ FRESULT f_rename (
}
FREE_NAMBUF();
}
#if FF_FS_REENTRANT
LEAVE_FF(fs_bak, res);
#else
LEAVE_FF(fs, res);
#endif
}
#endif /* !FF_FS_READONLY */
......@@ -4591,20 +4712,32 @@ FRESULT f_chmod (
FRESULT res;
DIR dj;
FATFS *fs;
#if FF_FS_REENTRANT
FATFS *fs_bak;
#endif
DEF_NAMBUF
res = find_volume(&path, &fs, FA_WRITE); /* Get logical drive */
dj.obj.fs = fs;
#if FF_FS_REENTRANT
fs_bak = fs;
#endif
if (res == FR_OK) {
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
#if FF_FS_REENTRANT
if (ISCHILD(fs)) LEAVE_FF(fs_bak,FR_INVAILD_FATFS);
#else
if (ISCHILD(fs)) LEAVE_FF(fs,FR_INVAILD_FATFS);
#endif
if (ISVIRPART(fs)) {
/* Check the virtual partition top directory, and match the virtual fs */
res = follow_virentry(&dj.obj,path);
#if FF_FS_REENTRANT
if (res == FR_INT_ERR) LEAVE_FF(fs_bak,res);
#else
if (res == FR_INT_ERR) LEAVE_FF(fs,res);
#endif
if (res == FR_OK)
fs = dj.obj.fs;
}
......@@ -4626,8 +4759,11 @@ FRESULT f_chmod (
}
FREE_NAMBUF();
}
#if FF_FS_REENTRANT
LEAVE_FF(fs_bak, res);
#else
LEAVE_FF(fs, res);
#endif
}
......@@ -5080,7 +5216,11 @@ FRESULT f_mkfs (
static const WORD cst[] = {1, 4, 16, 64, 256, 512, 0}; /* Cluster size boundary for FAT volume (4Ks unit) */
static const WORD cst32[] = {1, 2, 4, 8, 16, 32, 0}; /* Cluster size boundary for FAT32 volume (128Ks unit) */
BYTE fmt, sys, *buf, *pte, pdrv, part;
#ifndef __LITEOS_M__
size_t ss;
#else
WORD ss;
#endif
DWORD au;
QWORD szb_buf, sz_buf, sz_blk, n_clst, pau, sect, nsect, n;
QWORD b_vol, b_fat, b_data; /* Base LBA for volume, fat, data */
......@@ -5147,19 +5287,35 @@ FRESULT f_mkfs (
}
pte = &buf[MBR_Table + extended_pos * SZ_PTE];
extended_base = ld_dword(pte + 8);
#ifndef __LITEOS_M__
if (disk_raw_read(LD2DI(vol), buf, extended_base, 1) != RES_OK) return FR_DISK_ERR;
#else
if (disk_read(LD2PD(vol), buf, extended_base, 1) != RES_OK) return FR_DISK_ERR;
#endif
pte = &buf[MBR_Table];
for (; extended_br > 1; --extended_br) {
pte = &buf[MBR_Table];
extended_offset = ld_dword(pte + SZ_PTE + 8);
mem_set(buf, 0, len);
#ifndef __LITEOS_M__
if (disk_raw_read(LD2DI(vol), buf, extended_base + extended_offset, 1) != RES_OK) return FR_DISK_ERR;
#else
if (disk_read(LD2PD(vol), buf, extended_base + extended_offset, 1) != RES_OK) return FR_DISK_ERR;
#endif
}
}
if (!pte[4]) return FR_MKFS_ABORTED; /* No partition? */
#ifdef __LITEOS_M__
b_vol = ld_dword(pte + PTE_StLba); /* Get volume start sector */
sz_vol = ld_dword(pte + PTE_SizLba); /* Get volume size */
#else
b_vol = LD2PS(vol); /* Volume start sector */
sz_vol = LD2PC(vol); /* Volume size */
#endif
} else {
gpt_part = 1;
b_vol = LD2PS(vol); /* Volume start sector */
sz_vol = LD2PC(vol); /* Volume size */
if (disk_read(pdrv, buf, b_vol, 1) != RES_OK) return FR_DISK_ERR; /* Load GPT partition info */
if (ld_word(buf + BS_55AA) != 0xAA55) return FR_MKFS_ABORTED; /* Check if GPT partition is valid */
}
......@@ -5171,9 +5327,6 @@ FRESULT f_mkfs (
mem_cpy(multi_buf, buf, ss);
if (!gpt_part)
if (!pte[4]) {res = FR_MKFS_ABORTED; goto EXIT;} /* No partition? */
b_vol = LD2PS(vol); /* Volume start sector */
sz_vol = LD2PC(vol); /* Volume size */
} else
#endif
{
......@@ -5384,13 +5537,25 @@ FRESULT f_mkfs (
}
n = (part > 4) ? extended_base + extended_offset : 0;
pte[4] = sys;
#ifndef __LITEOS_M__
if (disk_raw_write(LD2DI(vol), multi_buf, n, 1) != RES_OK) { res = FR_DISK_ERR; goto EXIT; } /* Write it to teh MBR */
#else
if (disk_write(LD2PD(vol), multi_buf, n, 1) != RES_OK) { res = FR_DISK_ERR; goto EXIT; } /* Write it to teh MBR */
#endif
} else {
b_vol = LD2PS(vol); /* Volume start sector */
#ifndef __LITEOS_M__
if (disk_raw_read(LD2DI(vol), multi_buf, b_vol, 1) != RES_OK) { res = FR_DISK_ERR; goto EXIT; }
#else
if (disk_read(LD2PD(vol), multi_buf, b_vol, 1) != RES_OK) { res = FR_DISK_ERR; goto EXIT; }
#endif
pte = &multi_buf[MBR_Table];
pte[4] = sys;
#ifndef __LITEOS_M__
if (disk_raw_write(LD2DI(vol), multi_buf, b_vol, 1) != RES_OK) { res = FR_DISK_ERR; goto EXIT; } /* Write it to the MBR */
#else
if (disk_write(LD2PD(vol), multi_buf, b_vol, 1) != RES_OK) { res = FR_DISK_ERR; goto EXIT; } /* Write it to the MBR */
#endif
}
} else
#endif
......@@ -5415,7 +5580,7 @@ FRESULT f_mkfs (
}
if (disk_ioctl(pdrv, CTRL_SYNC, 0) != RES_OK) { res = FR_DISK_ERR; goto EXIT; }
#ifndef __LITEOS_M__
switch(fmt) {
case FS_FAT12:
PRINTK("format to FAT12, %lld sectors per cluster.\n", pau);
......@@ -5426,7 +5591,7 @@ FRESULT f_mkfs (
case FS_FAT32:
PRINTK("Format to FAT32, %lld sectors per cluster.\n", pau);
}
#endif
EXIT:
#if FF_MULTI_PARTITION
ff_memfree(multi_buf);
......
......@@ -26,14 +26,13 @@ extern "C" {
#include "integer.h" /* Basic integer types */
#include "ffconf.h" /* FatFs configuration options */
#include "dirent.h"
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
#include "fs/fs.h"
#endif
#if FF_DEFINED != FFCONF_DEF
#error Wrong configuration file (ffconf.h).
#endif
#include "dirent.h"
/* Definitions of volume management */
......@@ -165,8 +164,10 @@ typedef struct {
CHAR namelabel[_MAX_ENTRYLENGTH + 1]; /* The name label point to the each virtual Fatfs object ,only available in virtual Fatfs obj */
VOID** child_fs; /* Point to the child Fatfs object ,only available in reality Fatfs object */
#endif
#ifndef __LITEOS_M__
uid_t fs_uid;
gid_t fs_gid;
#endif
unsigned short fs_dmask;
unsigned short fs_fmask;
} FATFS;
......@@ -214,7 +215,7 @@ typedef struct {
/* Directory object structure (DIR) */
struct DIR {
struct __dirstream {
FFOBJID obj; /* Object identifier */
DWORD dptr; /* Current read/write offset */
DWORD clust; /* Current cluster */
......@@ -232,8 +233,6 @@ struct DIR {
#endif
};
/* File information structure (FILINFO) */
typedef struct {
......@@ -394,7 +393,9 @@ DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */
void* ff_memalloc (UINT msize); /* Allocate memory block */
void ff_memfree (void* mblock); /* Free memory block */
#ifndef __LITEOS_M__
int ff_strnlen(const void *str, size_t maxlen);
#endif
/* Sync functions */
#if FF_FS_REENTRANT
......
......@@ -5,8 +5,12 @@
/ FatFs Functional Configurations
/---------------------------------------------------------------------------*/
#ifndef __LITEOS_M__
#include "los_mux.h"
#include "los_config.h"
#else
#include "fs_config.h"
#endif
#ifdef __cplusplus
#if __cplusplus
......@@ -57,17 +61,28 @@ extern "C" {
#define FF_USE_FASTSEEK 0
/* This option switches fast seek function. (0:Disable or 1:Enable) */
#ifndef __LITEOS_M__
#define FF_USE_EXPAND 1
#else
#define FF_USE_EXPAND 0
#endif
/* This option switches f_expand function. (0:Disable or 1:Enable) */
#ifndef __LITEOS_M__
#define FF_USE_CHMOD 1
#else
#define FF_USE_CHMOD 0
#endif
/* This option switches attribute manipulation functions, f_chmod() and f_utime().
/ (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */
#ifndef __LITEOS_M__
#define FF_USE_LABEL 1
#else
#define FF_USE_LABEL 0
#endif
/* This option switches volume label functions, f_getlabel() and f_setlabel().
/ (0:Disable or 1:Enable) */
......@@ -113,6 +128,7 @@ extern "C" {
/ 0 - Include all code pages above and configured by f_setcp()
*/
#ifndef __LITEOS_M__
#define MMC0_DEVNAME "mmcblk0"
#define MMC1_DEVNAME "mmcblk1"
#define USB_DEVNAME "sda"
......@@ -121,6 +137,7 @@ enum STORAGE {
MMC0,
MMC1,
};
#endif
#define FF_USE_LFN 2
#define FF_MAX_LFN 255
......@@ -139,8 +156,11 @@ enum STORAGE {
/ memory for the working buffer, memory management functions, ff_memalloc() and
/ ff_memfree(), must be added to the project. */
#ifndef __LITEOS_M__
#define FF_LFN_UNICODE 0
#else
#define FF_LFN_UNICODE 2
#endif
/* This option switches the character encoding on the API when LFN is enabled.
/
/ 0: ANSI/OEM in current CP (TCHAR = char)
......@@ -172,8 +192,11 @@ enum STORAGE {
/ 3: Unicode in UTF-8
*/
#ifndef __LITEOS_M__
#define FF_FS_RPATH 0
#else
#define FF_FS_RPATH 1
#endif
/* This option configures support for relative path.
/
/ 0: Disable relative path and remove related functions.
......@@ -186,7 +209,11 @@ enum STORAGE {
/ Drive/Volume Configurations
/---------------------------------------------------------------------------*/
#ifndef __LITEOS_M__
#define FF_VOLUMES LOSCFG_FS_FAT_VOLUMES
#else
#define FF_VOLUMES 4
#endif
/* Number of volumes (logical drives) to be used. (1-10) */
#ifdef LOSCFG_FS_FAT_VIRTUAL_PARTITION
......@@ -195,8 +222,12 @@ enum STORAGE {
#define _FLOAT_ACC 0.00000001
#endif
#ifndef __LITEOS_M__
#define FF_STR_VOLUME_ID 0
#define FF_VOLUME_STRS "RAM","NAND","CF","SD","SD2","USB","USB2","USB3"
#else
#define FF_STR_VOLUME_ID 2
#endif
/* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings.
/ When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive
/ number in the path name. FF_VOLUME_STRS defines the volume ID strings for each
......@@ -219,7 +250,11 @@ enum STORAGE {
#define FF_MIN_SS 512
#ifndef __LITEOS_M__
#define FF_MAX_SS 4096
#else
#define FF_MAX_SS FS_MAX_SS
#endif
/* This set of options configures the range of sector size to be supported. (512,
/ 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and
/ harddisk. But a larger value may be required for on-board flash memory and some
......@@ -228,7 +263,11 @@ enum STORAGE {
/ GET_SECTOR_SIZE command. */
#ifndef __LITEOS_M__
#define FF_USE_TRIM 0
#else
#define FF_USE_TRIM 1
#endif
/* This option switches support for ATA-TRIM. (0:Disable or 1:Enable)
/ To enable Trim function, also CTRL_TRIM command should be implemented to the
/ disk_ioctl() function. */
......@@ -271,8 +310,11 @@ enum STORAGE {
/ FF_NORTC_MDAY and FF_NORTC_YEAR have no effect.
/ These options have no effect at read-only configuration (FF_FS_READONLY = 1). */
#ifndef __LITEOS_M__
#define FF_FS_LOCK CONFIG_NFILE_DESCRIPTORS
#else
#define FF_FS_LOCK FAT_MAX_OPEN_FILES
#endif
/* The option FF_FS_LOCK switches file lock function to control duplicated file open
/ and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
/ is 1.
......@@ -284,9 +326,15 @@ enum STORAGE {
/ lock control is independent of re-entrancy. */
#ifndef __LITEOS_M__
#define FF_FS_REENTRANT 1
#define FF_FS_TIMEOUT 6000
#define FF_SYNC_t LosMux
#else
#define FF_FS_REENTRANT 0
#define FF_FS_TIMEOUT 1000
#define FF_SYNC_t HANDLE
#endif
/* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs
/ module itself. Note that regardless of this option, file access to different
/ volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
......
......@@ -5,7 +5,10 @@
#include "ff.h"
#ifdef __LITEOS_M__
#include "ffconf.h"
#include "los_memory.h"
#endif
void ff_memset (void* dst,
int val,
......@@ -19,7 +22,7 @@ void ff_memset (void* dst,
} while (--cnt);
}
#ifndef __LITEOS_M__
int ff_strnlen(const void *str,
size_t maxlen
)
......@@ -30,6 +33,7 @@ int ff_strnlen(const void *str,
return p - c;
}
#endif
/*------------------------------------------------------------------------*/
/* Allocate a memory block */
......@@ -87,6 +91,7 @@ int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object
FF_SYNC_t* sobj /* Pointer to return the created sync object */
)
{
#ifndef __LITEOS_M__
int ret;
......@@ -95,6 +100,9 @@ int ff_cre_syncobj ( /* 1:Function succeeded, 0:Could not create the sync object
return TRUE;
} else
return FALSE;
#else
return TRUE;
#endif
}
......@@ -110,6 +118,7 @@ int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error
FF_SYNC_t* sobj /* Sync object tied to the logical drive to be deleted */
)
{
#ifndef __LITEOS_M__
int ret;
ret = LOS_MuxDestroy(sobj);
if(ret == LOS_OK) {
......@@ -117,6 +126,9 @@ int ff_del_syncobj ( /* 1:Function succeeded, 0:Could not delete due to an error
} else {
return FALSE;
}
#else
return TRUE;
#endif
}
......@@ -131,11 +143,15 @@ int ff_req_grant ( /* 1:Got a grant to access the volume, 0:Could not get a gran
FF_SYNC_t* sobj /* Sync object to wait */
)
{
#ifndef __LITEOS_M__
if (LOS_MuxLock(sobj, FF_FS_TIMEOUT) == LOS_OK) {
return TRUE;
}
return FALSE;
#else
return TRUE;
#endif
}
......@@ -149,7 +165,9 @@ void ff_rel_grant (
FF_SYNC_t* sobj /* Sync object to be signaled */
)
{
#ifndef __LITEOS_M__
(void)LOS_MuxUnlock(sobj);
#endif
}
#endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册