Re: directory data structure



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.


.



Relevant Pages

  • Re: Kernel SCM saga..
    ... On filesystems that don't have a stable inode number, I use the md5sum ... Since these same file systems lack hard links as ... It works with smb, fat, vfat, ...
    (Linux-Kernel)
  • Re: [UNIONFS] 00/42 Unionfs and related patches review
    ... When stackable file systems were first proposed in the early 90s, ... data changes will happen on a lower inode all within one second and not be ... What you propose violates the clean layer separation in a way that I'm not ...
    (Linux-Kernel)
  • Re: kern/85503: panic: wrong dirclust using msdosfs in RELENG_6
    ... Tricks to map to the API's inode number space are unavoidable due to ... representing offsets within file systems. ... I think I said that the inode number in msdosfs should be the cluster ...
    (freebsd-arch)
  • A question on modules, caching and file systems - probably.
    ... have a back-of-a-napkin design for a storage API, ... ideas to simply layer my solution on top of the file-system. ... I've looked at various file systems (and file-system ... While user-land ISAM libraries and their ilk offer many of the ...
    (comp.os.linux.questions)
  • A question on modules, caching and file systems - probably.
    ... have a back-of-a-napkin design for a storage API, ... ideas to simply layer my solution on top of the file-system. ... I've looked at various file systems (and file-system ... While user-land ISAM libraries and their ilk offer many of the ...
    (comp.os.linux.development.system)