* readdir within kernel
@ 2002-12-19 5:06 Herbert Poetzl
2002-12-19 13:09 ` Matthew Wilcox
0 siblings, 1 reply; 2+ messages in thread
From: Herbert Poetzl @ 2002-12-19 5:06 UTC (permalink / raw)
To: linux-fsdevel
hi all!
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 ...
suggestions and/or hints are very welcome ...
extern filldir_t xxx_filler;
void xxx_dump_dir(struct dentry *de)
{
struct file pf;
struct inode *in = de->d_inode;
int ret;
ret = init_private_file(&pf, de, FMODE_READ);
if (!pf.f_op->readdir)
goto out_close;
ret = vfs_readdir(&pf, xxx_filler, (void *)0);
out_close:
if (pf.f_op->release)
pf.f_op->release(in, &pf);
return;
}
many thanks,
Herbert
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: readdir within kernel
2002-12-19 5:06 readdir within kernel Herbert Poetzl
@ 2002-12-19 13:09 ` Matthew Wilcox
0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2002-12-19 13:09 UTC (permalink / raw)
To: Herbert Poetzl; +Cc: linux-fsdevel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-12-19 13:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-19 5:06 readdir within kernel Herbert Poetzl
2002-12-19 13:09 ` Matthew Wilcox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).