Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions components/dfs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,16 @@ if RT_USING_DFS_V1
default n
endif

config RT_USING_DFS_ROMFS
menuconfig RT_USING_DFS_ROMFS
bool "Enable ReadOnly file system on flash"
default n

config RT_USING_DFS_ROMFS_USER_ROOT
bool "Use user's romfs root"
depends on RT_USING_DFS_ROMFS
default n
if RT_USING_DFS_ROMFS
config RT_USING_DFS_ROMFS_USER_ROOT
bool "Use user's romfs root"
depends on RT_USING_DFS_V1
default n
endif

if RT_USING_SMART
config RT_USING_DFS_PTYFS
Expand Down
33 changes: 33 additions & 0 deletions components/dfs/dfs_v2/include/dfs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,38 @@ extern "C"
{
#endif

#define MS_RDONLY 1
#define MS_NOSUID 2
#define MS_NODEV 4
#define MS_NOEXEC 8
#define MS_SYNCHRONOUS 16
#define MS_REMOUNT 32
#define MS_MANDLOCK 64
#define MS_DIRSYNC 128
#define MS_NOATIME 1024
#define MS_NODIRATIME 2048
#define MS_BIND 4096
#define MS_MOVE 8192
#define MS_REC 16384
#define MS_SILENT 32768
#define MS_POSIXACL (1<<16)
#define MS_UNBINDABLE (1<<17)
#define MS_PRIVATE (1<<18)
#define MS_SLAVE (1<<19)
#define MS_SHARED (1<<20)
#define MS_RELATIME (1<<21)
#define MS_KERNMOUNT (1<<22)
#define MS_I_VERSION (1<<23)
#define MS_STRICTATIME (1<<24)
#define MS_LAZYTIME (1<<25)
#define MS_NOREMOTELOCK (1<<27)
#define MS_NOSEC (1<<28)
#define MS_BORN (1<<29)
#define MS_ACTIVE (1<<30)
#define MS_NOUSER (1U<<31)

#define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME)

/* file system partition table */
struct dfs_partition
{
Expand Down Expand Up @@ -87,6 +119,7 @@ int dfs_unregister(struct dfs_filesystem_type *fs);
int dfs_register(struct dfs_filesystem_type *fs);
const char *dfs_filesystem_get_mounted_path(struct rt_device *device);

int dfs_remount(const char *path, rt_ubase_t flags, void *data);
int dfs_mount(const char *device_name,
const char *path,
const char *filesystemtype,
Expand Down
9 changes: 9 additions & 0 deletions components/dfs/dfs_v2/include/dfs_mnt.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct dfs_mnt
#define MNT_IS_UMOUNT 0x8 /* the mnt is unmount */
#define MNT_IS_LOCKED 0x10 /* the mnt is locked */
#define MNT_FORCE 0x20 /* the mnt force unmount */
#define MNT_LAZY_UMNT 0x40 /* the mnt has pending umount */
#define MNT_RDONLY 0x80 /* the mnt is read only */

rt_atomic_t ref_count; /* reference count */

Expand All @@ -60,9 +62,16 @@ const char *dfs_mnt_get_mounted_path(struct rt_device *device);
struct dfs_mnt* dfs_mnt_ref(struct dfs_mnt* mnt);
int dfs_mnt_unref(struct dfs_mnt* mnt);

int dfs_mnt_umount(struct dfs_mnt *mnt, int flags);
int dfs_mnt_setflags(struct dfs_mnt *mnt, int flags);

rt_bool_t dfs_mnt_has_child_mnt(struct dfs_mnt *mnt, const char* fullpath);

int dfs_mnt_foreach(struct dfs_mnt* (*func)(struct dfs_mnt *mnt, void *parameter), void *parameter);
int dfs_mnt_umount_iter(rt_bool_t (*filter)(struct dfs_mnt *mnt, void *parameter), void *parameter);

typedef void (*dfs_mnt_umnt_cb_t)(struct dfs_mnt *mnt);
RT_OBJECT_HOOKLIST_DECLARE(dfs_mnt_umnt_cb_t, dfs_mnt_umnt);

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions components/dfs/dfs_v2/include/dfs_pcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ int dfs_aspace_mmap_write(struct dfs_file *file, struct rt_varea *varea, void *d

void dfs_pcache_release(size_t count);
void dfs_pcache_unmount(struct dfs_mnt *mnt);
void dfs_pcache_clean(struct dfs_mnt *mnt);

#ifdef __cplusplus
}
Expand Down
58 changes: 53 additions & 5 deletions components/dfs/dfs_v2/src/dfs_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,52 @@ int dfs_unregister(struct dfs_filesystem_type *fs)
return ret;
}

#define REMNT_UNSUPP_FLAGS (~(MS_REMOUNT | MS_RMT_MASK))
int dfs_remount(const char *path, rt_ubase_t flags, void *data)
{
int rc = 0;
char *fullpath = RT_NULL;
struct dfs_mnt *mnt = RT_NULL;

if (flags & REMNT_UNSUPP_FLAGS)
{
return -EINVAL;
}

fullpath = dfs_normalize_path(RT_NULL, path);
if (!fullpath)
{
rc = -ENOENT;
}
else
{
DLOG(msg, "dfs", "mnt", DLOG_MSG, "mnt = dfs_mnt_lookup(%s)", fullpath);
mnt = dfs_mnt_lookup(fullpath);
if (mnt)
{
dfs_lock();
dfs_mnt_setflags(mnt, flags);
dfs_unlock();
}
else
{
struct stat buf = {0};
if (dfs_file_stat(fullpath, &buf) == 0 && S_ISBLK(buf.st_mode))
{
/* path was not already mounted on target */
rc = -EINVAL;
}
else
{
/* path is not a directory */
rc = -ENOTDIR;
}
}
}

return rc;
}

/*
* parent(mount path)
* mnt_parent <- - - - - - - +
Expand Down Expand Up @@ -300,7 +346,7 @@ int dfs_mount(const char *device_name,

int dfs_umount(const char *specialfile, int flags)
{
int ret = -RT_ERROR;
int ret = -1;
char *fullpath = RT_NULL;
struct dfs_mnt *mnt = RT_NULL;

Expand All @@ -314,7 +360,7 @@ int dfs_umount(const char *specialfile, int flags)
if (strcmp(mnt->fullpath, fullpath) == 0)
{
/* is the mount point */
rt_atomic_t ref_count = rt_atomic_load(&(mnt->ref_count));
rt_base_t ref_count = rt_atomic_load(&(mnt->ref_count));

if (!(mnt->flags & MNT_IS_LOCKED) && rt_list_isempty(&mnt->child) && (ref_count == 1 || (flags & MNT_FORCE)))
{
Expand All @@ -327,17 +373,19 @@ int dfs_umount(const char *specialfile, int flags)
}
else
{
LOG_E("the file system is busy!");
LOG_I("the file system is busy!");
ret = -EBUSY;
}
}
else
{
LOG_E("the path:%s is not a mountpoint!", fullpath);
LOG_I("the path:%s is not a mountpoint!", fullpath);
ret = -EINVAL;
}
}
else
{
LOG_E("no filesystem found.");
LOG_I("no filesystem found.");
}
rt_free(fullpath);
}
Expand Down
35 changes: 29 additions & 6 deletions components/dfs/dfs_v2/src/dfs_mnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@

#include <rtthread.h>

#include "dfs.h"
#include "dfs_mnt.h"
#include "dfs_dentry.h"
#include "dfs_private.h"

#include <dfs.h>
#include <dfs_dentry.h>
#include <dfs_mnt.h>
#include <dfs_pcache.h>

#define DBG_TAG "DFS.mnt"
#define DBG_LVL DBG_WARNING
#include <rtdbg.h>

static struct dfs_mnt *_root_mnt = RT_NULL;

RT_OBJECT_HOOKLIST_DEFINE(dfs_mnt_umnt);

/*
* mnt tree structure
*
Expand Down Expand Up @@ -75,6 +79,7 @@ int dfs_mnt_insert(struct dfs_mnt* mnt, struct dfs_mnt* child)
child = _root_mnt;
rt_atomic_sub(&(_root_mnt->parent->ref_count), 1);
rt_atomic_sub(&(_root_mnt->ref_count), 1);
_root_mnt->flags &= ~MNT_IS_LOCKED;

_root_mnt = dfs_mnt_ref(mnt);
mnt->parent = dfs_mnt_ref(mnt);
Expand Down Expand Up @@ -242,21 +247,24 @@ struct dfs_mnt* dfs_mnt_ref(struct dfs_mnt* mnt)
return mnt;
}

int dfs_mnt_unref(struct dfs_mnt* mnt)
int dfs_mnt_unref(struct dfs_mnt *mnt)
{
rt_err_t ret = RT_EOK;
rt_base_t ref_count;

if (mnt)
{
rt_atomic_sub(&(mnt->ref_count), 1);
ref_count = rt_atomic_sub(&(mnt->ref_count), 1) - 1;

if (rt_atomic_load(&(mnt->ref_count)) == 0)
if (ref_count == 0)
{
dfs_lock();

if (mnt->flags & MNT_IS_UMOUNT)
{
mnt->fs_ops->umount(mnt);

RT_OBJECT_HOOKLIST_CALL(dfs_mnt_umnt, (mnt));
}

/* free full path */
Expand All @@ -278,6 +286,21 @@ int dfs_mnt_unref(struct dfs_mnt* mnt)
return ret;
}

int dfs_mnt_setflags(struct dfs_mnt *mnt, int flags)
{
int error = 0;

if (flags & MS_RDONLY)
{
mnt->flags |= MNT_RDONLY;
#ifdef RT_USING_PAGECACHE
dfs_pcache_clean(mnt);
#endif
}

return error;
}

int dfs_mnt_destroy(struct dfs_mnt* mnt)
{
rt_err_t ret = RT_EOK;
Expand Down
32 changes: 27 additions & 5 deletions components/dfs/dfs_v2/src/dfs_pcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void dfs_pcache_release(size_t count)
dfs_pcache_unlock();
}

void dfs_pcache_unmount(struct dfs_mnt *mnt)
static void _pcache_clean(struct dfs_mnt *mnt, int (*cb)(struct dfs_aspace *aspace))
{
rt_list_t *node = RT_NULL;
struct dfs_aspace *aspace = RT_NULL;
Expand All @@ -176,7 +176,7 @@ void dfs_pcache_unmount(struct dfs_mnt *mnt)
if (aspace && aspace->mnt == mnt)
{
dfs_aspace_clean(aspace);
dfs_aspace_release(aspace);
cb(aspace);
}
}

Expand All @@ -188,13 +188,28 @@ void dfs_pcache_unmount(struct dfs_mnt *mnt)
if (aspace && aspace->mnt == mnt)
{
dfs_aspace_clean(aspace);
dfs_aspace_release(aspace);
cb(aspace);
}
}

dfs_pcache_unlock();
}

void dfs_pcache_unmount(struct dfs_mnt *mnt)
{
_pcache_clean(mnt, dfs_aspace_release);
}

static int _dummy_cb(struct dfs_aspace *mnt)
{
return 0;
}

void dfs_pcache_clean(struct dfs_mnt *mnt)
{
_pcache_clean(mnt, _dummy_cb);
}

static int dfs_pcache_limit_check(void)
{
int index = 4;
Expand Down Expand Up @@ -1139,14 +1154,21 @@ int dfs_aspace_write(struct dfs_file *file, const void *buf, size_t count, off_t

if (file && file->vnode && file->vnode->aspace)
{
if (!(file->vnode->aspace->ops->write))
return ret;
struct dfs_vnode *vnode = file->vnode;
struct dfs_aspace *aspace = vnode->aspace;

struct dfs_page *page;
char *ptr = (char *)buf;

if (!(aspace->ops->write))
{
return ret;
}
else if (aspace->mnt && (aspace->mnt->flags & MNT_RDONLY))
{
return -EROFS;
}

ret = 0;

while (count)
Expand Down
10 changes: 9 additions & 1 deletion components/lwp/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ if RT_USING_LWP
config LWP_DEBUG_INIT
select RT_USING_HOOKLIST
bool "Enable debug mode of init process"
default n
depends on LWP_USING_RUNTIME
default y
endif

config LWP_USING_RUNTIME
bool "Using processes runtime environment (INIT process)"
default y
help
Runtime environment provide by init process including boot scripts,
poweroff, shutdown, reboot, etc.

config RT_LWP_MAX_NR
int "The max number of light-weight process"
default 30
Expand Down
4 changes: 4 additions & 0 deletions components/lwp/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ for item in termios_path:
src += Glob(item + '*.c')
CPPPATH += ['./terminal/']

# Remove optional sources
if not GetDepend(['LWP_USING_RUNTIME']):
SrcRemove(src, 'lwp_runtime.c')

group = DefineGroup('lwP', src, depend = ['RT_USING_SMART'], CPPPATH = CPPPATH)

group = group + SConscript(os.path.join('vdso', 'SConscript'))
Expand Down
9 changes: 9 additions & 0 deletions components/lwp/libc_musl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@
#ifndef __LIBC_MUSL_H__
#define __LIBC_MUSL_H__

/* from reboot.h */
#define RB_AUTOBOOT 0x01234567
#define RB_HALT_SYSTEM 0xcdef0123
#define RB_ENABLE_CAD 0x89abcdef
#define RB_DISABLE_CAD 0
#define RB_POWER_OFF 0x4321fedc
#define RB_SW_SUSPEND 0xd000fce2
#define RB_KEXEC 0x45584543

/* from internal/futex.h */

#define FUTEX_WAIT 0
Expand Down
Loading
Loading