Unix Programming - File creation time

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > December 2007 > File creation time





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author File creation time
Generic Usenet Account

2007-12-28, 7:23 pm

Hi,

As per my man pages, the stat structure contains the following fields:
struct stat {
dev_t st_dev; /* device */
ino_t st_ino; /* inode */
mode_t st_mode; /* protection */
nlink_t st_nlink; /* number of hard links
*/
uid_t st_uid; /* user ID of owner */
gid_t st_gid; /* group ID of owner */
dev_t st_rdev; /* device type (if inode
device) */
off_t st_size; /* total size, in bytes
*/
blksize_t st_blksize; /* blocksize for
filesystem I/O */
blkcnt_t st_blocks; /* number of blocks
allocated */
time_t st_atime; /* time of last access */
time_t st_mtime; /* time of last
modification */
time_t st_ctime; /* time of last change */
};

I am interested in the file creation time. What field should I use?
Should I go with some other system call? Also, what is the difference
between the time of last modification and the time of last change?

Thanks,
Gus
fjblurt@yahoo.com

2007-12-28, 7:23 pm

On Dec 28, 4:21 pm, Generic Usenet Account <use...@sta.samsung.com>
wrote:
> Hi,
>
> As per my man pages, the stat structure contains the following fields:
> struct stat {
> dev_t st_dev; /* device */
> ino_t st_ino; /* inode */
> mode_t st_mode; /* protection */
> nlink_t st_nlink; /* number of hard links
> */
> uid_t st_uid; /* user ID of owner */
> gid_t st_gid; /* group ID of owner */
> dev_t st_rdev; /* device type (if inode
> device) */
> off_t st_size; /* total size, in bytes
> */
> blksize_t st_blksize; /* blocksize for
> filesystem I/O */
> blkcnt_t st_blocks; /* number of blocks
> allocated */
> time_t st_atime; /* time of last access */
> time_t st_mtime; /* time of last
> modification */
> time_t st_ctime; /* time of last change */
> };
>
> I am interested in the file creation time. What field should I use?


None of these tell you the file creation time. That information is
only kept for a few filesystems. For example, ufs2 on FreeBSD fills
in an st_birthtime field. But in general it's not available via
stat(2) or any other system call.

> Should I go with some other system call? Also, what is the difference
> between the time of last modification and the time of last change?


The FreeBSD man page describes them as follows:

st_atime Time when file data last accessed. Changed by the
mknod(2), utimes(2), read(2) and readv(2) system
calls.

st_mtime Time when file data last modified. Changed by the
mkdir(2), mkfifo(2), mknod(2), utimes(2), write(2)
and
writev(2) system calls.

st_ctime Time when file status was last changed (inode data
modifi-
cation). Changed by the chflags(2), chmod(2),
chown(2),
creat(2), link(2), mkdir(2), mkfifo(2), mknod(2),
rename(2), rmdir(2), symlink(2), truncate(2),
unlink(2),
utimes(2), write(2) and writev(2) system calls.

st_birthtime Time when the inode was created.

Hope this helps.
Gordon Burditt

2007-12-31, 7:23 pm

> struct stat {
....
> time_t st_atime; /* time of last access */
> time_t st_mtime; /* time of last
>modification */
> time_t st_ctime; /* time of last change */
>
>I am interested in the file creation time.


There is no file creation time here. I don't even think there is a
coherent definition of "file creation time". For example, should the
shell command:
echo foo > file
update the so-called "creation time" if file "file" existed before
running this command?

>What field should I use?


st_mtime is probably pretty close for files which are written once
and not modified later. For write-frequently database files, you're
out of luck.

>Should I go with some other system call?


What makes you think a file creation time is stored anywhere?

>Also, what is the difference
>between the time of last modification and the time of last change?


Operations such as chown and chmod change st_ctime but not st_mtime.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com