This is a discussion on directory data structure within the Linux General forums, part of the Linux Forums category; On Jun 28, 7:58*pm, Dances With Crows <danceswithcr...@usa.net> wrote: > Maxwell Lol staggered into ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 I wanted to write a small directory browser and at the same time learn about how directories are being stored in the Gnu/Linux system. I don't want myself and my knowledge of linux to be constrained just to the APIs. It is basically a project for learning and not anything more. But I may turn it into something interesting if everything works well. Thanks a lot for your replies. -Sid |
|
|||
|
On Sat, 28 Jun 2008 14:58:40 +0000, Dances With Crows wrote:
>>> 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. He can't explain it better, because he doesn't know how. That's why he's asking for help with his programming homework. Maybe he'll know more by the end of the semester, but I rather doubt it. -- "Bother!" said Pooh, as he harpooned Flipper. |
|
|||
|
On Jun 28, 10:48*pm, Dan C <youmustbejok...@lan.invalid> wrote:
> On Sat, 28 Jun 2008 14:58:40 +0000, Dances With Crows wrote: > >>> 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. > > He can't explain it better, because he doesn't know how. *That's why he's > asking for help with his programming homework. > > Maybe he'll know more by the end of the semester, but I rather doubt it. > > -- > "Bother!" said Pooh, as he harpooned Flipper. well I guess Mr. Dan C can't help much as he doesn't know anything about what we've been talking about. |
|
|||
|
sid <kingsiddharth@gmail.com> writes:
> 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. Well, then why not try to do exactly that, and tell us what your next problem is? But if you want to interpret the binary information, you need to understand the various *.h files. How do you plan to split bits and bytes into something that makes sense without using the *.h files? If you just want the filenames, you can use "strings <." but then "echo *" or "ls" will also work, and be much more accurate. So - again - I don't understand what you are trying to do. If you want to learn the internals, you need to understand the API's and the manual pages. Otherwise you are just guessing. As I said before, perl allows you to write a script to examine the contents of a directory, without compiling a program. See the opendir/readdir functions. |