From 75f53efdc66be8c6ffac31bd17a309f9065e273c Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Sat, 21 Aug 2010 11:21:59 +0000 Subject: Encapsulate access to node->nn_stat * procfs.c, procfs.h (procfs_node_chown, procfs_node_chmod, procfs_node_chtype): New functions, encapsulate access to some nn_stat fields. * process.c (process_lookup_pid): Use procfs_node_chown instead of direct access. --- process.c | 2 +- procfs.c | 19 +++++++++++++++++++ procfs.h | 13 +++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/process.c b/process.c index a1cc0f6..779a2e1 100644 --- a/process.c +++ b/process.c @@ -224,6 +224,6 @@ process_lookup_pid (struct ps_context *pc, pid_t pid, struct node **np) if (! *np) return ENOMEM; - (*np)->nn_stat.st_uid = proc_stat_owner_uid (ps); + procfs_node_chown (*np, proc_stat_owner_uid (ps)); return 0; } diff --git a/procfs.c b/procfs.c index 0a235a7..5396ecf 100644 --- a/procfs.c +++ b/procfs.c @@ -67,6 +67,25 @@ fail: return NULL; } +void procfs_node_chown (struct node *np, uid_t owner) +{ + np->nn_stat.st_uid = owner; +} + +void procfs_node_chmod (struct node *np, mode_t mode) +{ + np->nn_stat.st_mode = (np->nn_stat.st_mode & S_IFMT) | mode; + np->nn_translated = np->nn_stat.st_mode; +} + +void procfs_node_chtype (struct node *np, mode_t type) +{ + np->nn_stat.st_mode = (np->nn_stat.st_mode & ~S_IFMT) | type; + np->nn_translated = np->nn_stat.st_mode; + if (type == S_IFLNK) + procfs_node_chmod (np, 0777); +} + /* FIXME: possibly not the fastest hash function... */ ino64_t procfs_make_ino (struct node *np, const char *filename) diff --git a/procfs.h b/procfs.h index 4c9d828..4ab3b56 100644 --- a/procfs.h +++ b/procfs.h @@ -48,6 +48,19 @@ void procfs_cleanup_contents_with_vm_deallocate (void *, void *, size_t); enough memory. In this case, ops->cleanup will be invoked. */ struct node *procfs_make_node (const struct procfs_node_ops *ops, void *hook); +/* Set the owner of the node NP. Must be called right after the node + has been created. */ +void procfs_node_chown (struct node *np, uid_t owner); + +/* Set the permission bits of the node NP. Must be called right after + the node has been created. */ +void procfs_node_chmod (struct node *np, mode_t mode); + +/* Set the type of the node NP. If type is S_IFLNK, appropriate + permission bits will be set as well. Must be called right after the + node has been created. */ +void procfs_node_chtype (struct node *np, mode_t type); + /* Interface for the libnetfs side. */ -- cgit v1.2.3