LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-03-2010, 10:38 AM   #1
tranduyhung
LQ Newbie
 
Registered: Sep 2010
Location: Vietnam
Distribution: Debian, Lubuntu
Posts: 10

Rep: Reputation: 0
Linux File Structure - inode


Hi,

I'm reading "Beginning Linux Programming (4th Edition)", published in 2007.

In chapter 3 - "Working with files", page 94, they said:

"When you delete a file all that happens is that the directory entry for the file is removed and the number of links to the file goes down by one. The data for the file is possibly still available through other links to the same file. When the number of links to a file (the number after the permissions in ls -l) reaches zero, the inode and the data blocks it references are then no longer in use and are marked as free."

I still don't understand this even after searching Google for more information. So when we delete a file, its data is still available if there is something's linked to it?

Anyone could explain more for me, or give me a example please.

Thank you so much!

Regards,
Hung

Last edited by tranduyhung; 11-03-2010 at 10:40 AM.
 
Old 11-03-2010, 10:42 AM   #2
mlangdn
Senior Member
 
Registered: Mar 2005
Location: Kentucky
Distribution: Slackware64-current
Posts: 1,844

Rep: Reputation: 452Reputation: 452Reputation: 452Reputation: 452Reputation: 452
Try this link for more info:

http://www.linux.com/archive/feature/58142

I'm reading this one now.
 
Old 11-03-2010, 11:31 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
I figure it's something like this ...

A file is a base inode plus none or more indirectly linked inodes plus none or more data blocks as explained here. Its name(s) are contained in directory entries which point to the base inode; the base inode has a count of the number of such links. When a directory entry is removed the link count is decremented and the kernel checks the new number of links. If it is zero the kernel checks if any processes have the file open (this information is in kernel memory) and if it is zero the kernel deletes the file otherwise it waits for the process(es) to close the file and each time that happens it checks again to see if any processes have the file open (described here). Presumably actually deleting the file means marking all its inodes as free.

What happens if there is a power failure while a file has no directory entries but is held open by one or more processes? There is no opportunity to delete it (as described above) but it is not accessible either. Presumably that is why it is good practice to run fsck after a power failure so this can be rectified.

Last edited by catkin; 11-03-2010 at 11:33 AM. Reason: "no no" to "no"
 
Old 11-08-2010, 12:54 PM   #4
martinkunev
LQ Newbie
 
Registered: Oct 2007
Location: Sofia, Bulgaria
Distribution: Debian, Gentoo
Posts: 6

Rep: Reputation: 1
Quote:
Originally Posted by catkin View Post
I figure it's something like this ...

A file is a base inode plus none or more indirectly linked inodes plus none or more data blocks as explained here.
There is no such thing as base inode or indirectly linked inodes. The file can have many names and many blocks associated with it but it always has exactly one inode. For regular files the inode contains file permissions, number of hard links (this is the same as the number of names of the file) etc.
 
1 members found this post helpful.
Old 11-09-2010, 06:01 AM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by martinkunev View Post
There is no such thing as base inode or indirectly linked inodes. The file can have many names and many blocks associated with it but it always has exactly one inode. For regular files the inode contains file permissions, number of hard links (this is the same as the number of names of the file) etc.
Thank you for the correction
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to access Inode structure of file Pratik dhamdhere Linux - Kernel 3 11-18-2010 11:50 PM
To lock inode structure saranraj Linux - Newbie 1 03-02-2010 11:04 PM
Convert directory structure from long file names in Linux to DOS 8.3 structure? manorina Linux - Software 5 09-12-2009 09:18 AM
Symbolic linking and inode structure tintintin Linux - General 0 01-21-2008 04:32 PM
Inode file_lock structure sid18 Linux - Kernel 0 09-09-2007 12:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:10 AM.

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