diff --git a/doc/rst/dwalk.1.rst b/doc/rst/dwalk.1.rst index 0e54f931..9d3f6dbe 100644 --- a/doc/rst/dwalk.1.rst +++ b/doc/rst/dwalk.1.rst @@ -70,6 +70,10 @@ OPTIONS Print files to the screen. +.. option:: --no-atime + + Must bu used with --lite option. Do not update last file access time. + .. option:: -L, --dereference Dereference symbolic links and walk the target file or directory diff --git a/man/dwalk.1 b/man/dwalk.1 index 3f58d2d5..fd36bed0 100644 --- a/man/dwalk.1 +++ b/man/dwalk.1 @@ -103,6 +103,11 @@ Print files to the screen. .UNINDENT .INDENT 0.0 .TP +.B \-\-no\-atime +Must be used with the \-\-lite option. Do not update the file last access time. +.UNINDENT +.INDENT 0.0 +.TP .B \-L, \-\-dereference Dereference symbolic links and walk the target file or directory that each symbolic link refers to. diff --git a/src/common/mfu_flist.c b/src/common/mfu_flist.c index a0071f1e..9b13a3a5 100644 --- a/src/common/mfu_flist.c +++ b/src/common/mfu_flist.c @@ -67,6 +67,9 @@ mfu_walk_opts_t* mfu_walk_opts_new(void) /* Don't dereference symbolic links by default */ opts->dereference = 0; + /* Don't update the file last access time */ + opts->no_atime = 0; + return opts; } diff --git a/src/common/mfu_flist_walk.c b/src/common/mfu_flist_walk.c index 120976e4..ce660a1f 100644 --- a/src/common/mfu_flist_walk.c +++ b/src/common/mfu_flist_walk.c @@ -51,6 +51,7 @@ static flist_t* CURRENT_LIST; static int SET_DIR_PERMS; static int REMOVE_FILES; static int DEREFERENCE; +static int NO_ATIME; static mfu_file_t** CURRENT_PFILE; /**************************************** @@ -180,11 +181,15 @@ struct linux_dirent { static void walk_getdents_process_dir(const char* dir, CIRCLE_handle* handle) { + int flags = O_RDONLY | O_DIRECTORY; char buf[BUF_SIZE]; + if (NO_ATIME) + flags |= O_NOATIME; + /* TODO: may need to try these functions multiple times */ mfu_file_t* mfu_file = *CURRENT_PFILE; - mfu_file_open(dir, O_RDONLY | O_DIRECTORY, mfu_file); + mfu_file_open(dir, flags, mfu_file); if (mfu_file->fd == -1) { /* print error */ MFU_LOG(MFU_LOG_ERR, "Failed to open directory for reading: `%s' (errno=%d %s)", dir, errno, strerror(errno)); @@ -605,6 +610,12 @@ void mfu_flist_walk_paths(uint64_t num_paths, const char** paths, DEREFERENCE = 1; } + /* if no_atime is set to 1 then set global variable */ + NO_ATIME = 0; + if (walk_opts->no_atime) { + NO_ATIME = 1; + } + /* convert handle to flist_t */ flist_t* flist = (flist_t*) bflist; @@ -657,11 +668,15 @@ void mfu_flist_walk_paths(uint64_t num_paths, const char** paths, CIRCLE_cb_process(&walk_stat_process); } else { - /* walk directories using file types in readdir */ - CIRCLE_cb_create(&walk_readdir_create); - CIRCLE_cb_process(&walk_readdir_process); - // CIRCLE_cb_create(&walk_getdents_create); - // CIRCLE_cb_process(&walk_getdents_process); + if (walk_opts->no_atime) { + /* walk directories without updating the file last access time */ + CIRCLE_cb_create(&walk_getdents_create); + CIRCLE_cb_process(&walk_getdents_process); + } else { + /* walk directories using file types in readdir */ + CIRCLE_cb_create(&walk_readdir_create); + CIRCLE_cb_process(&walk_readdir_process); + } } /* prepare callbacks and initialize variables for reductions */ diff --git a/src/common/mfu_param_path.h b/src/common/mfu_param_path.h index 04b2d51e..f6600463 100644 --- a/src/common/mfu_param_path.h +++ b/src/common/mfu_param_path.h @@ -113,6 +113,7 @@ typedef struct { int remove; /* flag option to remove files during walk */ int use_stat; /* flag option on whether or not to stat files during walk */ int dereference; /* flag option to dereference symbolic links */ + int no_atime; /* flag option to not update the file last acess time */ } mfu_walk_opts_t; typedef enum { diff --git a/src/dwalk/dwalk.c b/src/dwalk/dwalk.c index 3676c625..44852b5d 100644 --- a/src/dwalk/dwalk.c +++ b/src/dwalk/dwalk.c @@ -319,6 +319,7 @@ static void print_usage(void) printf(" -d, --distribution : \n - print distribution by field\n"); printf(" -f, --file_histogram - print default size distribution of items\n"); printf(" -p, --print - print files to screen\n"); + printf(" --no-atime - use with -l; do not update the file last access time\n"); printf(" -L, --dereference - follow symbolic links\n"); printf(" --progress - print progress every N seconds\n"); printf(" -v, --verbose - verbose output\n"); @@ -390,6 +391,7 @@ int main(int argc, char** argv) {"distribution", 1, 0, 'd'}, {"file_histogram", 0, 0, 'f'}, {"print", 0, 0, 'p'}, + {"no-atime", 0, 0, 'n'}, {"dereference", 0, 0, 'L'}, {"progress", 1, 0, 'R'}, {"verbose", 0, 0, 'v'}, @@ -401,7 +403,7 @@ int main(int argc, char** argv) int usage = 0; while (1) { int c = getopt_long( - argc, argv, "i:o:tls:d:fpLvqh", + argc, argv, "i:o:tls:d:fpLvqhn", long_options, &option_index ); @@ -432,6 +434,9 @@ int main(int argc, char** argv) case 'p': print = 1; break; + case 'n': + walk_opts->no_atime = 1; + break; case 'L': walk_opts->dereference = 1; break;