Uses STAT_NSEC_INVALID in the portable interface instead of FILE_MTIME_NSEC_INVALID.

This commit is contained in:
Andrea Mazzoleni 2013-08-18 18:02:25 +02:00
parent 147b905495
commit f2e6a0328a
6 changed files with 25 additions and 24 deletions

8
elem.h
View file

@ -189,12 +189,6 @@ struct snapraid_block {
#define FILE_IS_JUNCTION 0x800 /**< If it's a junction for Windows. Not yet supported. */
#define FILE_IS_LINK_MASK 0xF00 /**< Mask for link type. */
/**
* Value used to mark files without the nanoseconds value.
* Note that this value is never reported by stat().
*/
#define FILE_MTIME_NSEC_INVALID -1
/**
* File.
*/
@ -204,7 +198,7 @@ struct snapraid_file {
uint64_t physical; /**< Physical offset of the file. */
data_off_t size; /**< Size of the file. */
struct snapraid_block* blockvec; /**< All the blocks of the file. */
int mtime_nsec; /**< Modification time nanoseconds. In the range 0 <= x < 1,000,000,000, or FILE_MTIME_NSEC_INVALID. */
int mtime_nsec; /**< Modification time nanoseconds. In the range 0 <= x < 1,000,000,000, or STAT_NSEC_INVALID if not present. */
block_off_t blockmax; /**< Number of blocks. */
unsigned flag; /**< FILE_IS_* flags. */
char* sub; /**< Sub path of the file. Without the disk dir. The disk is implicit. */

View file

@ -333,7 +333,7 @@ int handle_utime(struct snapraid_handle* handle)
#if HAVE_FUTIMENS /* futimens() is preferred because it gives nanosecond precision */
tv[0].tv_sec = handle->file->mtime_sec;
if (handle->file->mtime_nsec != FILE_MTIME_NSEC_INVALID)
if (handle->file->mtime_nsec != STAT_NSEC_INVALID)
tv[0].tv_nsec = handle->file->mtime_nsec;
else
tv[0].tv_nsec = 0;
@ -343,7 +343,7 @@ int handle_utime(struct snapraid_handle* handle)
ret = futimens(handle->f, tv);
#elif HAVE_FUTIMES /* fallback to futimes() if nanosecond precision is not available */
tv[0].tv_sec = handle->file->mtime_sec;
if (handle->file->mtime_nsec != FILE_MTIME_NSEC_INVALID)
if (handle->file->mtime_nsec != STAT_NSEC_INVALID)
tv[0].tv_usec = handle->file->mtime_nsec / 1000;
else
tv[0].tv_usec = 0;
@ -353,7 +353,7 @@ int handle_utime(struct snapraid_handle* handle)
ret = futimes(handle->f, tv);
#elif HAVE_FUTIMESAT /* fallback to futimesat() for Solaris, it only has futimesat() */
tv[0].tv_sec = handle->file->mtime_sec;
if (handle->file->mtime_nsec != FILE_MTIME_NSEC_INVALID)
if (handle->file->mtime_nsec != STAT_NSEC_INVALID)
tv[0].tv_usec = handle->file->mtime_nsec / 1000;
else
tv[0].tv_usec = 0;

View file

@ -104,6 +104,12 @@
#undef pwrite
#define pwrite windows_pwrite
/**
* If nanoseconds are not supported, we report the special STAT_NSEC_INVALID value,
* to mark that it's undefined.
*/
#define STAT_NSEC_INVALID -1
/* We have nano second support */
#define STAT_NSEC(st) (st)->st_mtimensec

8
scan.c
View file

@ -299,16 +299,16 @@ static void scan_file(struct snapraid_scan* scan, struct snapraid_state* state,
/* check if the file is not changed */
if (file->size == st->st_size
&& file->mtime_sec == st->st_mtime
/* always accept the value if it's FILE_MTIME_NSEC_INVALID */
/* always accept the value if it's STAT_NSEC_INVALID */
/* it happens when upgrading from an old version of SnapRAID */
&& (file->mtime_nsec == STAT_NSEC(st) || file->mtime_nsec == FILE_MTIME_NSEC_INVALID)
&& (file->mtime_nsec == STAT_NSEC(st) || file->mtime_nsec == STAT_NSEC_INVALID)
) {
/* mark as present */
file_flag_set(file, FILE_IS_PRESENT);
/* update the nano seconds mtime if required */
if (file->mtime_nsec == FILE_MTIME_NSEC_INVALID
&& STAT_NSEC(st) != FILE_MTIME_NSEC_INVALID
if (file->mtime_nsec == STAT_NSEC_INVALID
&& STAT_NSEC(st) != STAT_NSEC_INVALID
) {
file->mtime_nsec = STAT_NSEC(st);

View file

@ -1181,12 +1181,12 @@ static void state_read_text(struct snapraid_state* state, const char* path, STRE
/* ignore nanoseconds if asked to find by name */
if (state->opt.force_by_name)
v_mtime_nsec = FILE_MTIME_NSEC_INVALID;
v_mtime_nsec = STAT_NSEC_INVALID;
c = sgetc(f);
} else {
/* use a special value, meaning that we don't have this information */
v_mtime_nsec = FILE_MTIME_NSEC_INVALID;
v_mtime_nsec = STAT_NSEC_INVALID;
}
if (c != ' ') {
@ -1822,7 +1822,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f)
sputc(' ', f);
sputu64(mtime_sec, f);
hash = oathash64(hash, mtime_sec);
if (mtime_nsec != FILE_MTIME_NSEC_INVALID) {
if (mtime_nsec != STAT_NSEC_INVALID) {
sputc('.', f);
sputu32(mtime_nsec, f);
hash = oathash32(hash, mtime_nsec);
@ -2188,7 +2188,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST
/* ignore nanoseconds if asked to find by name */
if (state->opt.force_by_name)
v_mtime_nsec = FILE_MTIME_NSEC_INVALID;
v_mtime_nsec = STAT_NSEC_INVALID;
ret = sgetb64(f, &v_inode);
if (ret < 0) {

13
unix.h
View file

@ -21,6 +21,12 @@
#define O_BINARY 0 /**< Not used in Unix. */
#define O_SEQUENTIAL 0 /**< In Unix posix_fadvise() shall be used. */
/**
* If nanoseconds are not supported, we report the special STAT_NSEC_INVALID value,
* to mark that it's undefined.
*/
#define STAT_NSEC_INVALID -1
/* Check if we have nanoseconds support */
#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
#define STAT_NSEC(st) (st)->st_mtim.tv_nsec /* Linux */
@ -29,12 +35,7 @@
#elif HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
#define STAT_NSEC(st) (st)->st_mtimespec.tv_nsec /* FreeBSD, Mac OS X */
#else
/**
* If nanoseconds are not supported, we report the special FILE_MTIME_NSEC_INVALID value,
* to mark that it's undefined.
* This result in not having it saved into the content file as a dummy 0.
*/
#define STAT_NSEC(st) -1
#define STAT_NSEC(st) STAT_NSEC_INVALID
#endif
/**