Re: directory data structure
- From: Fred Weigel <fred_weigel@xxxxxxxxxxx>
- Date: Fri, 27 Jun 2008 17:45:57 +0200 (CEST)
sid <kingsiddharth@xxxxxxxxx> wrote:
Hi
I want to write a C program that can read directories (say list them
as well).
I found out that we could use an API provided by dirent.h header file,
but I am not too keen on using the API. I want to access it directly
without any API. Any help is welcome.
Thank you.
A couple of ways -- as root, read the disk (raw) and interpret the
filesystem yourself; this doesn't work for networked file systems, so
add in code for NFS, SMB, etc (and code for ext2/ext3, msdos, iso9660
and whatever other filesystems you may encounter).
Execute the "ls" command, and interpret the results. I guess this
qualifies as an "API" of sorts.
Use the calls supplied in dirent.h.
Take your pick. Note that historically, "." could be opened in the
current directory, and could be read. Unfortunately, the record
structure was fixed, and this limited file names. The directory was
simply a file that mapped names to inode numbers. Now, you can still
create a file that isn't in a directory (left as an assignment). But, it
can be difficult to determine the "inode number" these days.
Specifically, multiple drives and networking make this difficult, along
with file systems that do not support the concept (eg. msdos). Since you
can no longer rely on inodes, "." is no longer the directory file, and
the "dirent" routines are used.
I am (reasonably) sure that you don't want to rewrite the various file
systems in user code. You could write a custom driver to expose the
"vfs" layer of the file system (but this would make the code (1) VERY
Linux specific, and (2) untrusted, since it can play directly in the
kernel).
I hope this gives you some ideas and direction.
.
- References:
- directory data structure
- From: sid
- directory data structure
- Prev by Date: Re: Trapping video and audio output
- Next by Date: Re: Clone NTFS drives over network?
- Previous by thread: directory data structure
- Next by thread: Re: directory data structure
- Index(es):
Relevant Pages
|