!832 LOS_FsMount 接口存在多处功能问题

Merge pull request !832 from wangchen/0923_m
This commit is contained in:
openharmony_ci 2022-09-26 13:02:50 +00:00 committed by Gitee
commit 816d03f5c1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 40 additions and 22 deletions

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;