LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 02-21-2017, 01:04 PM   #1
rushirg
LQ Newbie
 
Registered: Feb 2017
Posts: 3

Rep: Reputation: Disabled
Unhappy Scenario for file's Inode update


while reading Maurice Bach's "The Design Of The Unix Operating System", i came across inode.
As file gets updated inode also changes but are there any scenarios like,
- file is same and new inode is assigned
- file is changed and previous(old) inode is still there

Are these situations may happen? if yes how? and why?
 
Old 02-21-2017, 01:25 PM   #2
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,362

Rep: Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001Reputation: 2001
Quote:
Originally Posted by rushirg View Post
while reading Maurice Bach's "The Design Of The Unix Operating System", i came across inode.
As file gets updated inode also changes but are there any scenarios like,
- file is same and new inode is assigned
- file is changed and previous(old) inode is still there

Are these situations may happen? if yes how? and why?
If it's a new inode, it's a new file, perhaps created as a copy of the old file and then renamed to replace the old one, but it's still a new file.

A file can be read and rewritten in place (opened for reading and writing) and would keep the same inode. Note that most editors will, for safety, save the new version under a temporary name and then, once the new version has been written successfully, rename it over the old. The file would thus have a different inode. Cases where this can't be done, and the file is thus rewritten in-place, include (a) a directory that is not writable and thus no file creation or renaming can be done there, and (b) files with multiple hard links, since the new file would not share the hard links.
 
Old 02-21-2017, 01:43 PM   #3
rushirg
LQ Newbie
 
Registered: Feb 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
Yes, i got the concept of how the new inode is assigned to same file.
But i am still not clear about 2nd scenario that, file is changed and old inode remains same. is this case possible?
 
Old 02-21-2017, 01:46 PM   #4
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653
Sure. Changing a file directly, the file keeps its inode number.

Code:
touch some_file
ls -alhi some_file
echo "some data" > some_file
ls -alhi some_file
mv some_file /tmp
ls -alhi /tmp/some_file
Code:
# touch some_file
# ls -alhi some_file
3362 -rw-r--r-- 1 root root 0 Feb 21 18:47 some_file
# echo "some data" > some_file
# ls -alhi some_file
3362 -rw-r--r-- 1 root root 10 Feb 21 18:47 some_file
# mv some_file /tmp
# ls -alhi /tmp/some_file
3362 -rw-r--r-- 1 root root 10 Feb 21 18:47 /tmp/some_file

Last edited by szboardstretcher; 02-21-2017 at 01:47 PM.
 
Old 02-21-2017, 01:56 PM   #5
rushirg
LQ Newbie
 
Registered: Feb 2017
Posts: 3

Original Poster
Rep: Reputation: Disabled
OK, it remains same. But as i read in the book, it says, as the file gets updated the inode also get changed. do they mean the content of the inode changes like access/modify time?
 
Old 02-21-2017, 02:57 PM   #6
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 4,237

Rep: Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653Reputation: 1653
I see. Ok, this is the thing.

An "Inode" is an object with a numeric key. The term "Inode" is sometimes simplified and meant as the "inode number" when it really should refer to the record as a whole. For example, an Inode Record contains these fields:
  • Inode number
  • Access Control List (ACL)
  • Extended attribute
  • Direct/indirect disk blocks
  • Number of blocks
  • File access, change and modification time
  • File deletion time
  • File generation number
  • File size
  • File type
  • Group
  • Number of links
  • Owner
  • Permissions
  • Status flags

Notice that the "Inode Record" contains a field called "Inode Number"? That is the source of your confusion. The "Inode Number" does not change with every operation. But other fields in the record itself may.

Last edited by szboardstretcher; 02-21-2017 at 02:59 PM.
 
  


Reply


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
using scenario file to run vbf_example tcl file Alkindi Linux - Wireless Networking 8 06-18-2016 03:31 PM
using scenario file to run tcl file Faiza Al-Salti Linux - Networking 5 06-09-2016 01:04 PM
giving scenario file at terminal in ns2.35 rc49 Linux - Newbie 0 10-11-2015 11:48 AM
how to bind a value from scenario file to the .cc code? farfattou Programming 0 09-06-2013 01:45 PM
Can you write a script to display file name, Inode, and size of any file? JaxsunApex Linux - Newbie 3 01-30-2007 09:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:46 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration