fs: add umask to vfs_ioctx

This commit is contained in:
Mark 2020-09-01 18:07:19 +03:00
parent 074862b9ee
commit d83b93075c
5 changed files with 8 additions and 6 deletions

View File

@ -302,7 +302,7 @@ int vfs_mkdirat(struct vfs_ioctx *ctx, struct vnode *rel, const char *path, mode
return -EROFS;
}
return at->op->mkdir(at, filename, ctx->uid, ctx->gid, mode);
return at->op->mkdir(at, filename, ctx->uid, ctx->gid, mode & ~ctx->umask);
}
int vfs_unlinkat(struct vfs_ioctx *ctx, struct vnode *at, const char *pathname, int flags) {
@ -392,7 +392,7 @@ int vfs_mknod(struct vfs_ioctx *ctx, const char *path, mode_t mode, struct vnode
panic("mknod: unsupported node type\n");
}
struct vnode *nod = vnode_create(type, filename);
nod->mode = mode & VFS_MODE_MASK;
nod->mode = mode & VFS_MODE_MASK & ~ctx->umask;
nod->uid = ctx->uid;
nod->gid = ctx->gid;
@ -439,7 +439,7 @@ int vfs_creatat(struct vfs_ioctx *ctx,
return -EROFS;
}
return at->op->creat(at, filename, ctx->uid, ctx->gid, mode);
return at->op->creat(at, filename, ctx->uid, ctx->gid, mode & ~ctx->umask);
}
int vfs_openat(struct vfs_ioctx *ctx,

View File

@ -20,6 +20,7 @@ struct stat;
struct vfs_ioctx {
// Process' current working directory
struct vnode *cwd_vnode;
mode_t umask;
uid_t uid;
gid_t gid;
};

View File

@ -15,7 +15,6 @@ static const struct __kernel_cmdline_pair {
} kernel_cmdline_pairs[] = {
{ "root", CFG_ROOT, VALUE_STRING },
{ "init", CFG_INIT, VALUE_STRING },
{ "rdinit", CFG_RDINIT, VALUE_STRING },
{ "console", CFG_CONSOLE, VALUE_STRING },
{ "debug", CFG_DEBUG, VALUE_NUMBER },
};
@ -26,7 +25,6 @@ uintptr_t kernel_config[__CFG_SIZE] = {
0,
[CFG_ROOT] = (uintptr_t) "ram0",
[CFG_INIT] = (uintptr_t) "/init",
[CFG_RDINIT] = (uintptr_t) "/init",
[CFG_CONSOLE] = (uintptr_t) "tty0",
[CFG_DEBUG] = DEBUG_ALL_SERIAL |
DEBUG_DISP(DEBUG_INFO) |

View File

@ -5,6 +5,7 @@
#include "sys/thread.h"
#include "sys/assert.h"
#include "fs/vfs.h"
#include "sys/config.h"
#include "sys/debug.h"
#include "sys/sched.h"
#include "sys/heap.h"
@ -59,7 +60,7 @@ static void user_init_func(void *arg) {
thread_self->proc->ctty = tty_dev;
const char *argp[] = {
"/init", NULL
(const char *) kernel_config[CFG_INIT], NULL
};
// &argp[1] - just an empty envp
sys_execve(argp[0], argp, &argp[1]);

View File

@ -130,6 +130,7 @@ pid_t process_alloc_pid(int is_user) {
static void process_ioctx_empty(struct process *proc) {
memset(&proc->ioctx, 0, sizeof(struct vfs_ioctx));
memset(proc->fds, 0, sizeof(proc->fds));
proc->ioctx.umask = 0022;
}
void process_ioctx_fork(struct process *dst, struct process *src) {
@ -138,6 +139,7 @@ void process_ioctx_fork(struct process *dst, struct process *src) {
dst->ioctx.cwd_vnode = src->ioctx.cwd_vnode;
dst->ioctx.gid = src->ioctx.gid;
dst->ioctx.uid = src->ioctx.uid;
dst->ioctx.umask = src->ioctx.umask;
for (int i = 0; i < THREAD_MAX_FDS; ++i) {
if (src->fds[i]) {