commit
c9c8d68f5f
|
@ -43,7 +43,6 @@
|
|||
static pthread_mutex_t g_fsLocalMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static struct PartitionCfg g_partitionCfg;
|
||||
static struct lfs_config g_lfsCfg;
|
||||
static struct DeviceDesc *g_lfsDevice = NULL;
|
||||
|
||||
static uint32_t LfsGetStartAddr(int partition)
|
||||
|
@ -177,6 +176,7 @@ int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data)
|
|||
{
|
||||
int ret;
|
||||
lfs_t *mountHdl = NULL;
|
||||
struct lfs_config *cfg = NULL;
|
||||
|
||||
if ((mp == NULL) || (mp->mPath == NULL) || (data == NULL)) {
|
||||
errno = EFAULT;
|
||||
|
@ -184,22 +184,23 @@ int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data)
|
|||
goto errout;
|
||||
}
|
||||
|
||||
mountHdl = (lfs_t *)malloc(sizeof(lfs_t));
|
||||
mountHdl = (lfs_t *)malloc(sizeof(lfs_t) + sizeof(struct lfs_config));
|
||||
if (mountHdl == NULL) {
|
||||
errno = ENODEV;
|
||||
ret = (int)LOS_NOK;
|
||||
goto errout;
|
||||
}
|
||||
(void)memset_s(mountHdl, sizeof(lfs_t), 0, sizeof(lfs_t));
|
||||
(void)memset_s(mountHdl, sizeof(lfs_t) + sizeof(struct lfs_config), 0, sizeof(lfs_t) + sizeof(struct lfs_config));
|
||||
mp->mData = (void *)mountHdl;
|
||||
cfg = (void *)((UINTPTR)mountHdl + sizeof(lfs_t));
|
||||
|
||||
LfsConfigAdapter((struct PartitionCfg *)data, &g_lfsCfg);
|
||||
LfsConfigAdapter((struct PartitionCfg *)data, cfg);
|
||||
|
||||
ret = lfs_mount((lfs_t *)mp->mData, &g_lfsCfg);
|
||||
ret = lfs_mount((lfs_t *)mp->mData, cfg);
|
||||
if (ret != 0) {
|
||||
ret = lfs_format((lfs_t *)mp->mData, &g_lfsCfg);
|
||||
ret = lfs_format((lfs_t *)mp->mData, cfg);
|
||||
if (ret == 0) {
|
||||
ret = lfs_mount((lfs_t *)mp->mData, &g_lfsCfg);
|
||||
ret = lfs_mount((lfs_t *)mp->mData, cfg);
|
||||
}
|
||||
}
|
||||
if (ret != 0) {
|
||||
|
@ -655,12 +656,13 @@ int LfsFormat(const char *partName, void *privData)
|
|||
{
|
||||
int ret;
|
||||
lfs_t lfs = {0};
|
||||
struct lfs_config cfg = {0};
|
||||
|
||||
(void)partName;
|
||||
|
||||
LfsConfigAdapter((struct PartitionCfg *)privData, &g_lfsCfg);
|
||||
LfsConfigAdapter((struct PartitionCfg *)privData, &cfg);
|
||||
|
||||
ret = lfs_format(&lfs, &g_lfsCfg);
|
||||
ret = lfs_format(&lfs, &cfg);
|
||||
if (ret != 0) {
|
||||
errno = LittlefsErrno(ret);
|
||||
ret = (int)LOS_NOK;
|
||||
|
|
|
@ -122,14 +122,45 @@ struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
|
|||
return bestMp;
|
||||
}
|
||||
|
||||
STATIC struct MountPoint *MountPointInit(const char *target, const char *fsType, unsigned long mountflags)
|
||||
{
|
||||
struct MountPoint *mp = NULL;
|
||||
const char *pathInMp = NULL;
|
||||
struct FsMap *mFs = NULL;
|
||||
|
||||
/* find mp by target, to see if it was mounted */
|
||||
mp = VfsMpFind(target, &pathInMp);
|
||||
if (mp != NULL && pathInMp != NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Find fsMap coresponding to the fsType */
|
||||
mFs = VfsFsMapGet(fsType);
|
||||
if ((mFs == NULL) || (mFs->fsMops == NULL) || (mFs->fsMops->mount == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mp = (struct MountPoint *)malloc(sizeof(struct MountPoint));
|
||||
if (mp == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mp->mFs = mFs;
|
||||
mp->mDev = NULL;
|
||||
mp->mRefs = 0;
|
||||
mp->mWriteEnable = (mountflags & MS_RDONLY) ? FALSE : TRUE;
|
||||
mp->mFs->fsRefs++;
|
||||
mp->mNext = g_mountPoints;
|
||||
|
||||
return mp;
|
||||
}
|
||||
|
||||
int LOS_FsMount(const char *source, const char *target,
|
||||
const char *fsType, unsigned long mountflags,
|
||||
const void *data)
|
||||
{
|
||||
int ret;
|
||||
struct MountPoint *mp = NULL;
|
||||
struct FsMap *mFs = NULL;
|
||||
const char *pathInMp = NULL;
|
||||
|
||||
/* target must begin with '/', for example /system, /data, etc. */
|
||||
if ((target == NULL) || (target[0] != '/')) {
|
||||
|
@ -137,29 +168,19 @@ int LOS_FsMount(const char *source, const char *target,
|
|||
}
|
||||
|
||||
(void)VfsLock();
|
||||
/* find mp by target, to see if it was mounted */
|
||||
mp = VfsMpFind(target, &pathInMp);
|
||||
if (mp != NULL && pathInMp != NULL) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Find fsMap coresponding to the fsType */
|
||||
mFs = VfsFsMapGet(fsType);
|
||||
if ((mFs == NULL) || (mFs->fsMops == NULL) || (mFs->fsMops->mount == NULL)) {
|
||||
goto errout;
|
||||
}
|
||||
|
||||
mp = (struct MountPoint *)malloc(sizeof(struct MountPoint));
|
||||
mp = MountPointInit(target, fsType, mountflags);
|
||||
if (mp == NULL) {
|
||||
goto errout;
|
||||
VfsUnlock();
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
|
||||
mp->mFs = mFs;
|
||||
mp->mDev = NULL;
|
||||
if (source != NULL) {
|
||||
mp->mDev = strdup(source);
|
||||
if (mp->mDev == NULL) {
|
||||
goto errout;
|
||||
free(mp);
|
||||
VfsUnlock();
|
||||
return (int)LOS_NOK;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,10 +195,7 @@ int LOS_FsMount(const char *source, const char *target,
|
|||
PRINT_ERR("mount failed, target %s.\n", target);
|
||||
goto errout;
|
||||
}
|
||||
mp->mRefs = 0;
|
||||
mp->mWriteEnable = (mountflags & MS_RDONLY) ? FALSE : TRUE;
|
||||
mp->mFs->fsRefs++;
|
||||
mp->mNext = g_mountPoints;
|
||||
|
||||
g_mountPoints = mp;
|
||||
VfsUnlock();
|
||||
return LOS_OK;
|
||||
|
|
|
@ -240,4 +240,7 @@
|
|||
#define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS
|
||||
#endif
|
||||
|
||||
#define LWIP_SOCKET_IOCTL 0
|
||||
#define LWIP_SOCKET_FCNTL 0
|
||||
|
||||
#endif /* _LWIP_PORTING_LWIPOPTS_H_ */
|
||||
|
|
|
@ -211,6 +211,7 @@ int close(int fd)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if LWIP_SOCKET_IOCTL
|
||||
#ifdef LWIP_SOCKET_IOCTL_FUNC
|
||||
int ioctl(int fd, int req, ...)
|
||||
{
|
||||
|
@ -222,7 +223,9 @@ int ioctl(int fd, int req, ...)
|
|||
return lwip_ioctl(fd, (long)req, (void *)arg);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LWIP_SOCKET_FCNTL
|
||||
#ifdef LWIP_SOCKET_FCNTL_FUNC
|
||||
int fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
|
@ -234,6 +237,7 @@ int fcntl(int fd, int cmd, ...)
|
|||
return lwip_fcntl(fd, cmd, val);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if LWIP_SOCKET_SELECT
|
||||
#ifdef LWIP_SOCKET_SELECT_FUNC
|
||||
|
|
Loading…
Reference in New Issue