I'm writing backup software. I want to programmatically determine if a file has been modified since last time. Is a flag or something like that on files under the EXT3 filesystem?
Asked
Active
Viewed 546 times
0
-
1Note that this has nothing to do with ext3. All filesystems that come anywhere close to POSIX compliance support mtime, as it's a standard part of Unix. – Phil Miller Nov 12 '09 at 13:43
2 Answers
1
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
- 391,730
- 64
- 469
- 606
-
`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 Nov 13 '09 at 01:36