Skip to content

Commit

Permalink
lxcfs.c : Added LXCFS_TYPE macro checks to all FUSE filesystem calls
Browse files Browse the repository at this point in the history
Signed-off-by: Devon Schwartz <[email protected]>
  • Loading branch information
DevonSchwartz committed May 5, 2024
1 parent c037ad8 commit 1f64e98
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/lxcfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,9 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
#endif
{
int ret;
enum lxcfs_virt_t type;

type = file_info_type(fi);

if (strcmp(path, "/") == 0) {
if (dir_filler(filler, buf, ".", 0) != 0 ||
Expand All @@ -755,21 +758,21 @@ static int lxcfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
return 0;
}

if (cgroup_is_enabled && strncmp(path, "/cgroup", 7) == 0) {
if (cgroup_is_enabled && LXCFS_TYPE_CGROUP(type)) {
up_users();
ret = do_cg_readdir(path, buf, filler, offset, fi);
down_users();
return ret;
}

if (strcmp(path, "/proc") == 0) {
if (LXCFS_TYPE_PROC(type)) {
up_users();
ret = do_proc_readdir(path, buf, filler, offset, fi);
down_users();
return ret;
}

if (strncmp(path, "/sys", 4) == 0) {
if (LXCFS_TYPE_SYS(type)) {
up_users();
ret = do_sys_readdir(path, buf, filler, offset, fi);
down_users();
Expand Down Expand Up @@ -880,7 +883,7 @@ static int lxcfs_read(const char *path, char *buf, size_t size, off_t offset,

type = file_info_type(fi);

if (cgroup_is_enabled && LXCFS_TYPE_CGROUP(type)) {
if (cgroup_is_enabled && LXCFS_TYPE_CGROUP(type)) {
up_users();
ret = do_cg_read(path, buf, size, offset, fi);
down_users();
Expand Down Expand Up @@ -911,15 +914,18 @@ int lxcfs_write(const char *path, const char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
int ret;
enum lxcfs_virt_t type;

type = file_info_type(fi);

if (cgroup_is_enabled && strncmp(path, "/cgroup", 7) == 0) {
if (cgroup_is_enabled && LXCFS_TYPE_CGROUP(type)) {
up_users();
ret = do_cg_write(path, buf, size, offset, fi);
down_users();
return ret;
}

if (strncmp(path, "/sys", 4) == 0) {
if (LXCFS_TYPE_SYS(type)) {
up_users();
ret = do_sys_write(path, buf, size, offset, fi);
down_users();
Expand Down

0 comments on commit 1f64e98

Please sign in to comment.