From: Edward Falk <efalk@google.com>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] add path-oriented proc_mkdir_path() function to /proc
Date: Mon, 10 May 2004 15:09:08 -0700 [thread overview]
Message-ID: <E1BNIxQ-00013R-Fo@peregrine.corp.google.com> (raw)
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@google.com
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,
next reply other threads:[~2004-05-10 22:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-10 22:09 Edward Falk [this message]
2004-05-10 22:39 ` Valdis.Kletnieks
2004-05-10 22:57 ` Paul Jackson
2004-05-10 23:14 Edward Falk
2004-05-10 23:22 Edward Falk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1BNIxQ-00013R-Fo@peregrine.corp.google.com \
--to=efalk@google.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®