[PATCH] add path-oriented proc_mkdir_path() function to /proc
From: Edward Falk
Date: Mon May 10 2004 - 17:12:07 EST
Hi all; apologies if there's a maintainer I should be sending this to
as well; couldn't find one in the maintainers list or in the source code.
This patch adds the function proc_mkdir_path() to fs/proc/generic.c.
This allows kernel code to create e.g. "/proc/foo/bar/baz" without needing
to check the hard way if /proc/foo/ and /proc/foo/bar/ already exist.
This patch works with both 2.6.6-rc3 and 2.6.6
-ed falk, efalk@xxxxxxxxxx
diff -urN linux-2.6.6-rc3/fs/proc/generic.c linux/fs/proc/generic.c
--- linux-2.6.6-rc3/fs/proc/generic.c 2004-05-08 15:24:03.000000000 -0700
+++ linux/fs/proc/generic.c 2004-05-08 15:47:04.000000000 -0700
@@ -612,6 +612,40 @@
return proc_mkdir_mode(name, S_IRUGO | S_IXUGO, parent);
}
+
+struct proc_dir_entry *proc_mkdir_path(const char *name,
+ struct proc_dir_entry *parent)
+{
+ const char *next;
+ int len;
+ struct proc_dir_entry *de;
+
+ /* Search top level for first component of name. If not found,
+ * create it. Keep doing this until we run out of name components.
+ */
+
+ for(;;) {
+ next = strchr(name, '/');
+ len = next != NULL ? next - name : strlen(name);
+ for (de = parent->subdir; de != NULL; de = de->next) {
+ if (proc_match(len, name, de))
+ break;
+ }
+ if (de == NULL) {
+ char fname[NAME_MAX+1];
+ memcpy(fname, name, len); fname[len] = '\0';
+ de = proc_mkdir(fname, parent);
+ }
+ if (next == NULL)
+ break;
+ parent = de;
+ name = next + 1;
+ }
+ return de;
+}
+
+
+
struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
struct proc_dir_entry *parent)
{
diff -urN linux-2.6.6-rc3/include/linux/proc_fs.h linux/include/linux/proc_fs.h
--- linux-2.6.6-rc3/include/linux/proc_fs.h 2004-05-08 15:24:07.000000000 -0700
+++ linux/include/linux/proc_fs.h 2004-05-08 15:46:06.000000000 -0700
@@ -142,6 +142,8 @@
extern struct proc_dir_entry *proc_mkdir(const char *,struct proc_dir_entry *);
extern struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
struct proc_dir_entry *parent);
+extern struct proc_dir_entry *proc_mkdir_path(const char *path,
+ struct proc_dir_entry *parent);
static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
mode_t mode, struct proc_dir_entry *base,
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/