From: Matthew Wilcox <willy@debian.org>
To: Herbert Poetzl <herbert@13thfloor.at>
Cc: linux-fsdevel@vger.kernel.org
Subject: Re: readdir within kernel
Date: Thu, 19 Dec 2002 13:09:52 +0000 [thread overview]
Message-ID: <20021219130952.O9994@parcelfarce.linux.theplanet.co.uk> (raw)
In-Reply-To: <20021219050632.GB16235@www.13thfloor.at>; from herbert@13thfloor.at on Thu, Dec 19, 2002 at 06:06:32AM +0100
On Thu, Dec 19, 2002 at 06:06:32AM +0100, Herbert Poetzl wrote:
> I would like to know if this is the right way to
> read a directory contents for a given directory
> dentry within a kernel module ...
well, you probably _shouldn't_ be anyway... but since you are, this is
how I did it for debugging why my system couldn't find /sbin/init.
diff -u -p -r1.11 main.c
--- init/main.c 10 Dec 2002 22:03:28 -0000 1.11
+++ init/main.c 19 Dec 2002 13:08:45 -0000
@@ -501,6 +501,26 @@ static void do_pre_smp_initcalls(void)
extern void prepare_namespace(void);
+static int kernel_filler(void *buf, const char *name, int namlen, loff_t offset,
+ ino_t ino, unsigned int d_type)
+{
+ printk("%.*s\n", namlen, name);
+}
+
+static void kernel_ls(char *name)
+{
+ struct file *file;
+
+ file = filp_open(name, O_RDONLY, 0);
+ if (!file) {
+ printk("Could not open %s\n", name);
+ return;
+ }
+
+ vfs_readdir(file, kernel_filler, NULL);
+ filp_close(file, current->files);
+}
+
static int init(void * unused)
{
static char * argv_sh[] = { "sh", NULL, };
@@ -540,6 +560,9 @@ static int init(void * unused)
(void) dup(0);
(void) dup(0);
+
+ kernel_ls("/");
+ kernel_ls("/sbin");
/*
* We try each of these until one succeeds.
--
"It's not Hollywood. War is real, war is primarily not about defeat or
victory, it is about death. I've seen thousands and thousands of dead bodies.
Do you think I want to have an academic debate on this subject?" -- Robert Fisk
prev parent reply other threads:[~2002-12-19 13:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-19 5:06 readdir within kernel Herbert Poetzl
2002-12-19 13:09 ` Matthew Wilcox [this message]
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=20021219130952.O9994@parcelfarce.linux.theplanet.co.uk \
--to=willy@debian.org \
--cc=herbert@13thfloor.at \
--cc=linux-fsdevel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.