mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] add path-oriented proc_mkdir_path() function to /proc
@ 2004-05-10 22:09 Edward Falk
  2004-05-10 22:39 ` Valdis.Kletnieks
  2004-05-10 22:57 ` Paul Jackson
  0 siblings, 2 replies; 5+ messages in thread
From: Edward Falk @ 2004-05-10 22:09 UTC (permalink / raw)
  To: linux-kernel

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, 

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [PATCH] add path-oriented proc_mkdir_path() function to /proc
@ 2004-05-10 23:14 Edward Falk
  0 siblings, 0 replies; 5+ messages in thread
From: Edward Falk @ 2004-05-10 23:14 UTC (permalink / raw)
  To: linux-kernel

[patch to allow creation of e.g. /proc/foo/bar/ with one function call.]

> Hmm.. Looks like a useful utility function (there's certainly enough deep
> trees in my /proc/sys tree), but I wonder...
> 
> 1) Do we have cases where code should be implementing "it had *better* exist"
> checks?  This may be important if an intermediate directory "should have" been
> created by sysctl or something, and has special permission needs..
> 
> 2) Alternatively, does using this open up accidental collisions where we should
> have checked something *doesnt* exist already, and complain if it does?
> 
> (Feel free to address either one by adding a "Dont do that then" comment ;)

Don't do that, then.  :)

OK, long answer:

1 & 2) are beyond the scope of my patch, but it seems to me that
additional functionality could be added -- perhaps in the form of O_CREAT,
O_EXCL flags -- if demand warranted it.  Perhaps this could be done in
a later patch?

	-ed falk, efalk@google.com

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [PATCH] add path-oriented proc_mkdir_path() function to /proc
@ 2004-05-10 23:22 Edward Falk
  0 siblings, 0 replies; 5+ messages in thread
From: Edward Falk @ 2004-05-10 23:22 UTC (permalink / raw)
  To: linux-kernel

>> ... adds the function proc_mkdir_path() ...
>
>Who uses this?

Well, almost nobody yet :)

I'm very shortly going to submit a diagnostic utility that creates
nested entries in /proc.

I originally wrote proc_mkdir_path() to make the nested entries, and
someone suggested that it be submitted as a seperate patch since it's
of general usefulness.

	-ed falk, falk@google.com

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-05-10 23:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-10 22:09 [PATCH] add path-oriented proc_mkdir_path() function to /proc Edward Falk
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

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®