tags:

views:

137

answers:

2

Hi everyone. I wanna proramatically determine if a file has been modified since last time. I wonder if there is a flag or somthing like that on files under EXT3 filesystem. I'm writing a backup software.

+1  A: 

Sure. Just call stat() on the file, and inspect the st_mtime member:

struct stat {
    /* ... snip ... */
    time_t    st_atime;   /* time of last access */
    time_t    st_mtime;   /* time of last modification */
    time_t    st_ctime;   /* time of last status change */
};

If you have in the application a timestamp when the last backup was made, you can compare directly.

Note though that not all filesystems really update the modified time, as doing so is kind of expensive. You seem to be aware of this risk.

unwind
Thanks my friend.
Alex James
`mtime` is usually updated (since it only happens when the file data is being modified anyway, it's not much of an incremental expense). It's `atime` that isn't always updated. Note that backup software should inspect both `mtime` and `ctime`, to ensure that changes to permissions cause an incremental backup.
caf
+1  A: 

I think you are looking for stat()

dsm
Thanks Dear friend.
Alex James