Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


File System

Posted on 1999-07-01
Medium Priority
Last Modified: 2013-12-06
In unix file system there is a block called "Directory block" which points to the list of objects containing inode and the file name. How can i get the contents in the directory block ?
Question by:jituj
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 51

Expert Comment

ID: 2011327
opendir() ?
LVL 14

Accepted Solution

chris_calabrese earned 60 total points
ID: 2011328
A "Directory" in the Unix filesystem is a mapping between names and corresponding inode-numbers.  It's not any kind of fixed block, but actually pretty similar to a regular file.  As an aside, because the directories only reference the inodes, not contain them, it is therefore possible that the same file (inode) can be pointed at by different directories under different names.

Directory information can be read with the opendir() and readdir() C-language functions.  Here's an example from the HP-UX man page for opendir():
     The following code searches the current directory for an entry name:

           DIR *dirp;
           struct dirent *dp;

           dirp = opendir(".");
           while ((dp = readdir(dirp)) != NULL) {
                if (strcmp(dp->d_name, name) == 0) {
                     (void) closedir(dirp);
                     return FOUND;
           (void) closedir(dirp);
           return NOT_FOUND;

You can get information about the file itself with the stat() system call.

Author Comment

ID: 2011329
i also found the same solution for the problem but this is not very efficient bec. everytime u have to check whether the name u are getting from readdir is a directory or some other file , i want handle to the list of directories which again points to the list of objects having inode number and the filename associated with the inode number.
LVL 14

Expert Comment

ID: 2011330
The Unix filesystem semantics are structured in such a way that you _must_ read the directory with readdir() and then stat() the entries to tell if they, in turn, are directories.  Sorry, there is no way around this.  Meanwhile, it actually is pretty efficient because the kernel keeps caches for the name/inode translations and the inode contents, so you're usually looking in the cache and not going repeatedly to the disk.

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question