Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 04-23-2005, 08:39 AM   #1
LQ Newbie
Registered: Oct 2004
Posts: 22

Rep: Reputation: 15

I know that inodes are a special data structure that holds a pointer to where the file resides in a particular filesystem. I have also read that an inode contains other information BUT it does not contain the filename and the actual data itself. So when a particular user creates a file in a particular directory, does the kernel checks all the inodes in that particular directory, access the actual file and check its name in order to verifty that the new name of the file is unique?
Old 04-23-2005, 01:28 PM   #2
Registered: Mar 2003
Location: Belgium
Distribution: Hardened gentoo
Posts: 323

Rep: Reputation: 30
No, because the name of the file is actually stored in the directory node, not in the file's data area.
So, a directory in unix can be seen as a sort of file (with a format the kernel understands) containing a table of the names of the regular files (and also pipes, sockets, ...) in that directory, and their inode numbers.
This means we can get a list of all files in a directory without reading from any of those files (we only read the directory "file").

When a user creates or opens a file, the kernel traverses this table to see if a file with that name already exists. If it does, it gets the inode number from this table, and through the inode it knows where on disk the data are.
If the file didn't exist, a new inode is created for it, and a new (name, inode#) entry in the table of that directory is created.

So to see if a file exists, it's not neccessary to look inside its inode.

Hope this kind of answers your question!

Last edited by nukkel; 04-23-2005 at 02:00 PM.
Old 04-23-2005, 10:53 PM   #3
Senior Member
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 52
nukkel is of course 100% correct in his/her explanation

just in case you are a bit more curious and for me right now it's fun to look this up
(i know i'm sick)
there are two syscall choices creat() and open().
originally just creat but then later open was modified to do creation with certain arguments
and creat became just a handoff to open

if you use open but use the O_CREAT and the file exists the function return a error (-1) as the file descriptor. and that's about it -- it just simply checks the path to see if it exists. if it does it stops.
in the kernel code below PTR_ERR returns either a dentry (directory entry) pointer for whatever filesystem is in use or an error code

asmlinkage long sys_open(const char __user * filename, int flags, int mode)
	char * tmp;
	int fd, error;

#if BITS_PER_LONG != 32
	flags |= O_LARGEFILE;
	tmp = getname(filename);
	fd = PTR_ERR(tmp);
	if (!IS_ERR(tmp)) {
		fd = get_unused_fd();
		if (fd >= 0) {
			struct file *f = filp_open(tmp, flags, mode);
			error = PTR_ERR(f);
			if (IS_ERR(f))
				goto out_error;
			fd_install(fd, f);
	return fd;

	fd = error;
	goto out;
Old 04-24-2005, 02:17 PM   #4
Registered: Mar 2003
Location: Belgium
Distribution: Hardened gentoo
Posts: 323

Rep: Reputation: 30

If you like to program check out the manpages of readdir(), scandir(), opendir(), telldir() etc. which are nice to explore directory entries: they allow one to traverse a directory table, returning a struct containing a (name, inode#) pair.
Then stat() each file to get the info INSIDE the inode, and you have your own little version of "ls" !


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
what is inodes? Paxmaster Linux - General 4 06-20-2005 05:53 AM
Out of Inodes tmiles Linux - Newbie 4 02-06-2005 08:35 PM
Inodes used up wolferd1 Linux - General 2 02-04-2005 04:22 PM
What is inodes? ionian2k Linux - Newbie 1 12-15-2002 10:29 AM
Inodes milena1 Linux - General 0 02-05-2002 07:55 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:19 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration