Operating System - HP-UX
1833757 Members
2855 Online
110063 Solutions
New Discussion

Directory Modification Time

 
SOLVED
Go to solution
Sundar_7
Honored Contributor

Directory Modification Time


I was trying to figure out how the Directory modification time is handled. So, wanted to see if anyone can help me understand this better

Directory modification time is

a) NOT updated if an exisiting file within that directory is modified

b) updated if a new file is created.

c) updated if an existing file is removed.

d) updated if an existing file is renamed

Given that directory contains nothing more than map of inode to file names, the above mentioned behavior makes sense to me. But was wondering how do you guys interpret this ?

Also what determines a directory size ?

Any useful input will be appreciated with points :-)

-- Sundar.
Learn What to do ,How to do and more importantly When to do ?
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor

Re: Directory Modification Time

Stop thinking of the directory as a directory and think of of as simply a regular file and your observations will make sense. A directory is really metadata - data that describe other data. Nothing in the directory's contents change if a file within a directory is modified because none of those involve a change of the metadata -- any of the other changes you mentioned directly affect the metadata so that the directory has to be rewritten and thus the modification time is changed.
If it ain't broke, I can fix that.
Sundar_7
Honored Contributor

Re: Directory Modification Time

Thanks Clay. I kind of figured that is the case - What about the directory size ? what determines the size of a directory ?
Learn What to do ,How to do and more importantly When to do ?
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Directory Modification Time

Use a text editor to examine /usr/include/sys/dirent.h. A directory is essentially a file that consists of a bunch of struct dirent's plus a little bit of additional header data. Essentially the size of a directory is determined by the number of dirent's. A few things should be noted. First, if a file is unlinked (rm'ed), the dirent is not actually removed but is rather marked available so that the dirent can be used for new files. Thus removing a file does not shrink a directory. If there are no available dirents in a directory and a file needs to be created, the directory is rewritten with the larger size. The other thing to note is that a file might have more than one directory entry --- hard linked files share a common inode but each link has its own directory entry.
If it ain't broke, I can fix that.
Sundar_7
Honored Contributor

Re: Directory Modification Time

Thanks Clay - As always, you are second to none! - Be right there, I will catch you up in some 10 years :-)
Learn What to do ,How to do and more importantly When to do ?
RAC_1
Honored Contributor

Re: Directory Modification Time

I agree with Sundar.

There is only one A. Clay Stephenson.
In my spare time, I just browse through his postings/replies. Rather his replies.

Anil
There is no substitute to HARDWORK