!848 挑单 fs相关修改同步3.2-beta3

Merge pull request !848 from wangchen/1010_m
This commit is contained in:
openharmony_ci 2022-10-11 02:31:37 +00:00 committed by Gitee
commit c9c8d68f5f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 58 additions and 31 deletions

View File

@ -43,7 +43,6 @@
static pthread_mutex_t g_fsLocalMutex = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t g_fsLocalMutex = PTHREAD_MUTEX_INITIALIZER;
static struct PartitionCfg g_partitionCfg; static struct PartitionCfg g_partitionCfg;
static struct lfs_config g_lfsCfg;
static struct DeviceDesc *g_lfsDevice = NULL; static struct DeviceDesc *g_lfsDevice = NULL;
static uint32_t LfsGetStartAddr(int partition) static uint32_t LfsGetStartAddr(int partition)
@ -177,6 +176,7 @@ int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data)
{ {
int ret; int ret;
lfs_t *mountHdl = NULL; lfs_t *mountHdl = NULL;
struct lfs_config *cfg = NULL;
if ((mp == NULL) || (mp->mPath == NULL) || (data == NULL)) { if ((mp == NULL) || (mp->mPath == NULL) || (data == NULL)) {
errno = EFAULT; errno = EFAULT;
@ -184,22 +184,23 @@ int LfsMount(struct MountPoint *mp, unsigned long mountflags, const void *data)
goto errout; goto errout;
} }
mountHdl = (lfs_t *)malloc(sizeof(lfs_t)); mountHdl = (lfs_t *)malloc(sizeof(lfs_t) + sizeof(struct lfs_config));
if (mountHdl == NULL) { if (mountHdl == NULL) {
errno = ENODEV; errno = ENODEV;
ret = (int)LOS_NOK; ret = (int)LOS_NOK;
goto errout; 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; 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) { if (ret != 0) {
ret = lfs_format((lfs_t *)mp->mData, &g_lfsCfg); ret = lfs_format((lfs_t *)mp->mData, cfg);
if (ret == 0) { if (ret == 0) {
ret = lfs_mount((lfs_t *)mp->mData, &g_lfsCfg); ret = lfs_mount((lfs_t *)mp->mData, cfg);
} }
} }
if (ret != 0) { if (ret != 0) {
@ -655,12 +656,13 @@ int LfsFormat(const char *partName, void *privData)
{ {
int ret; int ret;
lfs_t lfs = {0}; lfs_t lfs = {0};
struct lfs_config cfg = {0};
(void)partName; (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) { if (ret != 0) {
errno = LittlefsErrno(ret); errno = LittlefsErrno(ret);
ret = (int)LOS_NOK; ret = (int)LOS_NOK;

View File

@ -122,14 +122,45 @@ struct MountPoint *VfsMpFind(const char *path, const char **pathInMp)
return bestMp; 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, int LOS_FsMount(const char *source, const char *target,
const char *fsType, unsigned long mountflags, const char *fsType, unsigned long mountflags,
const void *data) const void *data)
{ {
int ret; int ret;
struct MountPoint *mp = NULL; struct MountPoint *mp = NULL;
struct FsMap *mFs = NULL;
const char *pathInMp = NULL;
/* target must begin with '/', for example /system, /data, etc. */ /* target must begin with '/', for example /system, /data, etc. */
if ((target == NULL) || (target[0] != '/')) { if ((target == NULL) || (target[0] != '/')) {
@ -137,29 +168,19 @@ int LOS_FsMount(const char *source, const char *target,
} }
(void)VfsLock(); (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 */ mp = MountPointInit(target, fsType, mountflags);
mFs = VfsFsMapGet(fsType);
if ((mFs == NULL) || (mFs->fsMops == NULL) || (mFs->fsMops->mount == NULL)) {
goto errout;
}
mp = (struct MountPoint *)malloc(sizeof(struct MountPoint));
if (mp == NULL) { if (mp == NULL) {
goto errout; VfsUnlock();
return (int)LOS_NOK;
} }
mp->mFs = mFs;
mp->mDev = NULL;
if (source != NULL) { if (source != NULL) {
mp->mDev = strdup(source); mp->mDev = strdup(source);
if (mp->mDev == NULL) { 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); PRINT_ERR("mount failed, target %s.\n", target);
goto errout; goto errout;
} }
mp->mRefs = 0;
mp->mWriteEnable = (mountflags & MS_RDONLY) ? FALSE : TRUE;
mp->mFs->fsRefs++;
mp->mNext = g_mountPoints;
g_mountPoints = mp; g_mountPoints = mp;
VfsUnlock(); VfsUnlock();
return LOS_OK; return LOS_OK;

View File

@ -240,4 +240,7 @@
#define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS #define LWIP_SOCKET_OFFSET CONFIG_NFILE_DESCRIPTORS
#endif #endif
#define LWIP_SOCKET_IOCTL 0
#define LWIP_SOCKET_FCNTL 0
#endif /* _LWIP_PORTING_LWIPOPTS_H_ */ #endif /* _LWIP_PORTING_LWIPOPTS_H_ */

View File

@ -211,6 +211,7 @@ int close(int fd)
} }
#endif #endif
#if LWIP_SOCKET_IOCTL
#ifdef LWIP_SOCKET_IOCTL_FUNC #ifdef LWIP_SOCKET_IOCTL_FUNC
int ioctl(int fd, int req, ...) int ioctl(int fd, int req, ...)
{ {
@ -222,7 +223,9 @@ int ioctl(int fd, int req, ...)
return lwip_ioctl(fd, (long)req, (void *)arg); return lwip_ioctl(fd, (long)req, (void *)arg);
} }
#endif #endif
#endif
#if LWIP_SOCKET_FCNTL
#ifdef LWIP_SOCKET_FCNTL_FUNC #ifdef LWIP_SOCKET_FCNTL_FUNC
int fcntl(int fd, int cmd, ...) int fcntl(int fd, int cmd, ...)
{ {
@ -234,6 +237,7 @@ int fcntl(int fd, int cmd, ...)
return lwip_fcntl(fd, cmd, val); return lwip_fcntl(fd, cmd, val);
} }
#endif #endif
#endif
#if LWIP_SOCKET_SELECT #if LWIP_SOCKET_SELECT
#ifdef LWIP_SOCKET_SELECT_FUNC #ifdef LWIP_SOCKET_SELECT_FUNC