From f2e6a0328a0ae958023cf01b4ce4995444e69f91 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sun, 18 Aug 2013 18:02:25 +0200 Subject: [PATCH] Uses STAT_NSEC_INVALID in the portable interface instead of FILE_MTIME_NSEC_INVALID. --- elem.h | 8 +------- handle.c | 6 +++--- mingw.h | 6 ++++++ scan.c | 8 ++++---- state.c | 8 ++++---- unix.h | 13 +++++++------ 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/elem.h b/elem.h index fa8e892d..9b949029 100644 --- a/elem.h +++ b/elem.h @@ -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. */ diff --git a/handle.c b/handle.c index 2a8b8391..bf41f34c 100644 --- a/handle.c +++ b/handle.c @@ -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; diff --git a/mingw.h b/mingw.h index bd0c16fa..7d477534 100644 --- a/mingw.h +++ b/mingw.h @@ -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 diff --git a/scan.c b/scan.c index 70f25624..d5c10f7e 100644 --- a/scan.c +++ b/scan.c @@ -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); diff --git a/state.c b/state.c index 6e28a1cb..926e7218 100644 --- a/state.c +++ b/state.c @@ -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) { diff --git a/unix.h b/unix.h index 47b95084..210ea384 100644 --- a/unix.h +++ b/unix.h @@ -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 /**