directory data structure

This is a discussion on directory data structure within the Linux General forums, part of the Linux Forums category; Hi I want to write a C program that can read directories (say list them as well). I found out ...


Go Back   Usenet Forums > Linux Forums > Linux General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-27-2008
sid
 
Posts: n/a
Default directory data structure

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.
Reply With Quote
  #2 (permalink)  
Old 06-27-2008
Fred Weigel
 
Posts: n/a
Default Re: directory data structure

sid <kingsiddharth@gmail.com> 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.


Reply With Quote
  #3 (permalink)  
Old 06-27-2008
Dan C
 
Posts: n/a
Default Re: directory data structure

On Fri, 27 Jun 2008 01:55:56 -0700, sid 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.


Do your own homework, chump.


--
"Bother!" said Pooh, as Piglet stepped on the land mine.

Reply With Quote
  #4 (permalink)  
Old 06-27-2008
sid
 
Posts: n/a
Default Re: directory data structure

On Jun 27, 9:14*pm, Dan C <youmustbejok...@lan.invalid> wrote:
> On Fri, 27 Jun 2008 01:55:56 -0700, sid 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.

>
> Do your own homework, chump.
>
> --
> "Bother!" said Pooh, as Piglet stepped on the land mine.


I am really sorry for you as you feel this is my homework. If you
don't know the answer to my question please don't waste time to write
such rude things.
If I don't know anything I just read it and let it pass and I would
advice you to do the same..
Reply With Quote
  #5 (permalink)  
Old 06-28-2008
Dan C
 
Posts: n/a
Default Re: directory data structure

On Fri, 27 Jun 2008 14:22:05 -0700, sid wrote:

>> > 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.


>> Do your own homework, chump.


> I am really sorry for you as you feel this is my homework. If you
> don't know the answer to my question please don't waste time to write
> such rude things.


Yes, you are sorry.

> If I don't know anything I just read it and let it pass and I would
> advice you to do the same..


You'd "advice" me, eh?

Stay in school, and finish studying your English before you worry about
getting help with your programming homework, boy.


--
"Bother!" said Pooh, as he tried to learn COBOL.

Reply With Quote
  #6 (permalink)  
Old 06-28-2008
sid
 
Posts: n/a
Default Re: directory data structure

On Jun 28, 4:37*am, Dan C <youmustbejok...@lan.invalid> wrote:
> On Fri, 27 Jun 2008 14:22:05 -0700, sid wrote:
> >> > 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.
> >> Do your own homework, chump.

> > I am really sorry for you as you feel this is my homework. If you
> > don't know the answer to my question please don't waste time to write
> > such rude things.

>

That's what people like you can say when they get frustrated. I really
enjoy to see frustrated people like you, and frustrating them even
more. :)

> Yes, you are sorry.
>
> > If I don't know anything I just read it and let it pass and I would
> > advice you to do the same..

>
> You'd "advice" me, eh?
>
> Stay in school, and finish studying your English before you worry about
> getting help with your programming homework, boy.
>
> --
> "Bother!" said Pooh, as he tried to learn COBOL.


Reply With Quote
  #7 (permalink)  
Old 06-28-2008
Maxwell Lol
 
Posts: n/a
Default Re: directory data structure

sid <kingsiddharth@gmail.com> writes:

> 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.


This doesn't make any sense.
If you don't want an API, then why use C?
You could use the API built into perl. But that's another API.
If you truly want to NOT use an API, use shell commands, not C.

Use dd(1) to read raw data from the disk and enjoy parsing binary
information, where you need the info in the *.h files.

Or use ls(1), find(1) and other shell commands.




Reply With Quote
  #8 (permalink)  
Old 06-28-2008
Dances With Crows
 
Posts: n/a
Default Re: directory data structure

Maxwell Lol staggered into the Black Sun and said:
> sid <kingsiddharth@gmail.com> writes:
>> 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.


? opendir() and readdir() are how this is done in C. They are not
insanely complex and there's a large amount of sample code that uses
those functions out there. Read some of that sample code and understand
it, then use the concepts you learn.

>> I want to access it directly without any API.

> This doesn't make any sense. If you don't want an API, then why use
> C?


It is not clear what the OP wants. Maybe the OP should explain better.
The other thing that he could be thinking about is open()ing the
directory itself. This is not a good idea, because some programmers who
are more paranoid and dedicated than you have already written opendir()
and its friends, and Laziness is one of the virtues of a programmer.

> Use dd(1) to read raw data from the disk and enjoy parsing binary
> information, where you need the info in the *.h files. Or use ls(1),
> find(1) and other shell commands.


dd is probably the wrong tool for the job as well, since it refuses to
dump data if you do "dd if=somedir/ ..." .

--
"Assembly of God". Haven't you ever wondered what goes on in a place
like that? What kinds of parts does God need? --Slacquer
My blog and resume: http://crow202.dyndns.org/wordpress/
Matt G|There is no Darkness in Eternity/But only Light too dim for us to see
Reply With Quote
  #9 (permalink)  
Old 06-28-2008
sid
 
Posts: n/a
Default Re: directory data structure

On Jun 28, 7:15*pm, Maxwell Lol <nos...@com.invalid> wrote:
> sid <kingsiddha...@gmail.com> writes:
> > 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.

>
> This doesn't make any sense.
> If you don't want an API, then why use C?
> You could use the API built into perl. But that's another API.
> If you truly want to NOT use an API, use shell commands, not C.
>
> Use dd(1) to read raw data from the disk and enjoy parsing binary
> information, where you need the info in the *.h files.
>
> Or use ls(1), find(1) and other shell commands.


Actually what I was thinking of was that since everything is a file
in
a Linux kernel/system, I would just read the directory files and
interpret them... and I know that we could do so in the older
versions
of Linux as well as UNIX. Say, if you wanted to read the current
directory, you could just do "od -bc ." and this would octal dump the
contents the of current directory. Also, even now you could read the
contents of the directory file using VI ( vi <directory name> ). So I
planned to do something similar and was thinking that you guys might
help me with it.

Thanks


Reply With Quote
  #10 (permalink)  
Old 06-28-2008
sid
 
Posts: n/a
Default Re: directory data structure

On Jun 28, 7:58*pm, Dances With Crows <danceswithcr...@usa.net> wrote:
> Maxwell Lol staggered into the Black Sun and said:
>
> > sid <kingsiddha...@gmail.com> writes:
> >> 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.

>
> ? *opendir() and readdir() are how this is done in C. *They are not
> insanely complex and there's a large amount of sample code that uses
> those functions out there. *Read some of that sample code and understand
> it, then use the concepts you learn.
>
> >> I want to access it directly without any API.

> > This doesn't make any sense. *If you don't want an API, then why use
> > C?

>
> It is not clear what the OP wants. *Maybe the OP should explain better.
> The other thing that he could be thinking about is open()ing the
> directory itself. *This is not a good idea, because some programmers who
> are more paranoid and dedicated than you have already written opendir()
> and its friends, and Laziness is one of the virtues of a programmer.
>
> > Use dd(1) to read raw data from the disk and enjoy parsing binary
> > information, where you need the info in the *.h files. *Or use ls(1),
> > find(1) and other shell commands.

>
> dd is probably the wrong tool for the job as well, since it refuses to
> dump data if you do "dd if=somedir/ ..." .
>
> --
> * *"Assembly of God". Haven't you ever wondered what goes on in a place
> * *like that? *What kinds of parts does God need? *--Slacquer
> * My blog and resume:http://crow202.dyndns.org/wordpress/
> Matt G|There is no Darkness in Eternity/But only Light too dim for us to see


Actually what I was thinking of was that since everything is a file
in
a Linux kernel/system, I would just read the directory files and
interpret them... and I know that we could do so in the older
versions
of Linux as well as UNIX. Say, if you wanted to read the current
directory, you could just do "od -bc ." and this would octal dump the
contents the of current directory. Also, even now you could read the
contents of the directory file using VI ( vi <directory name> ). So I
planned to do something similar and was thinking that you guys might
help me with it.

Thanks


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:26 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0