tmpfs & vfs: pass file's owner and group around
MODIFY
sys/kern/tmpfs.c
sys/kern/tmpfs.c
@@ -47,6 +47,8 @@ typedef struct tmpfs_node {
nlink_t tfn_links; /* number of file hard links */
ino_t tfn_ino; /* node identifier */
size_t tfn_size; /* file size in bytes */
+ uid_t tfn_uid; /* owner of file */
+ gid_t tfn_gid; /* group of file */
/* Data that is only applicable to a particular type. */
union {
@@ -276,6 +278,8 @@ static int tmpfs_vop_getattr(vnode_t *v, vattr_t *va) {
va->va_mode = node->tfn_mode;
va->va_nlink = node->tfn_links;
va->va_ino = node->tfn_ino;
+ va->va_uid = node->tfn_uid;
+ va->va_gid = node->tfn_gid;
va->va_size = node->tfn_size;
return 0;
}
@@ -434,6 +438,8 @@ static tmpfs_node_t *tmpfs_new_node(tmpfs_mount_t *tfm, vattr_t *va,
node->tfn_mode = va->va_mode;
node->tfn_type = ntype;
node->tfn_links = 0;
+ node->tfn_uid = va->va_uid;
+ node->tfn_gid = va->va_gid;
node->tfn_size = 0;
mtx_lock(&tfm->tfm_lock);

MODIFY
sys/kern/vfs_syscalls.c
sys/kern/vfs_syscalls.c
@@ -65,6 +65,8 @@ static int vfs_create(proc_t *p, int fdat, char *pathname, int flags, int mode,
vattr_t va;
vattr_null(&va);
va.va_mode = S_IFREG | (mode & ALLPERMS);
+ va.va_uid = p->p_cred.cr_ruid;
+ va.va_gid = p->p_cred.cr_rgid;
error = VOP_CREATE(vs.vs_dvp, &vs.vs_lastcn, &va, &vs.vs_vp);
vnode_put(vs.vs_dvp);
} else {
@@ -257,6 +259,8 @@ int do_mkdirat(proc_t *p, int fd, char *path, mode_t mode) {
* implementation-defined.
* https://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdir.html */
va.va_mode = S_IFDIR | ((mode & ACCESSPERMS) & ~p->p_cmask);
+ va.va_uid = p->p_cred.cr_ruid;
+ va.va_gid = p->p_cred.cr_rgid;
error = VOP_MKDIR(vs.vs_dvp, &vs.vs_lastcn, &va, &vs.vs_vp);
if (!error)
@@ -458,6 +462,8 @@ int do_symlinkat(proc_t *p, char *target, int newdirfd, char *linkpath) {
memset(&va, 0, sizeof(vattr_t));
va.va_mode = S_IFLNK | (ACCESSPERMS & ~p->p_cmask);
+ va.va_uid = p->p_cred.cr_ruid;
+ va.va_gid = p->p_cred.cr_rgid;
error = VOP_SYMLINK(vs.vs_dvp, &vs.vs_lastcn, &va, target, &vs.vs_vp);
if (!error)

tmpfs & vfs: pass file's owner and group around (#846)