coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/4] stat: support statx DONT_SYNC and FORCE_SYNC flags


From: Jeff Layton
Subject: [PATCH 4/4] stat: support statx DONT_SYNC and FORCE_SYNC flags
Date: Fri, 12 Apr 2019 16:53:06 -0400

Add two new command-line options that change how the statx call that
set the appropriate flags in the statx call, to modify its behavior
vs. network filesystems. These options are only implemented when
built with HAVE_STATX.

* NEWS: mention the enhancements
* src/stat.c: add new options to control synchronization with server
---
 NEWS       |  8 ++++++++
 src/stat.c | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/NEWS b/NEWS
index 6844228bef9f..f8de29a397ab 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,14 @@ GNU coreutils NEWS                                    -*- 
outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** New Features
+
+   stat now uses the statx() system call to do its bidding when it is
+   available. It will craft a statx mask with only the needed attributes.
+   When built with statx support, it also supports new command line
+   options to control synchronization with the server on network
+   filesytems.
+
 ** Bug fixes
 
   factor again outputs immediately when stdout is a tty but stdin is not.
diff --git a/src/stat.c b/src/stat.c
index fab257701ddd..9f9c1ecbaf3d 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -201,6 +201,10 @@ static struct option const long_options[] =
   {"format", required_argument, NULL, 'c'},
   {"printf", required_argument, NULL, PRINTF_OPTION},
   {"terse", no_argument, NULL, 't'},
+#if HAVE_STATX && defined STATX_INO
+  {"dont-sync", no_argument, NULL, 'D' },
+  {"force-sync", no_argument, NULL, 'F' },
+#endif
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -1200,6 +1204,12 @@ do_statfs (char const *filename, char const *format)
 }
 
 #if HAVE_STATX && defined STATX_INO
+/* Ask statx to avoid syncing? */
+static bool dont_sync;
+
+/* Ask statx to force sync? */
+static bool force_sync;
+
 /* Much of the format printing requires a struct stat or timespec */
 static struct timespec
 statx_timestamp_to_timespec(struct statx_timestamp tsx)
@@ -1472,6 +1482,11 @@ do_stat (char const *filename, char const *format, char 
const *format2)
       flags = AT_SYMLINK_NOFOLLOW;
     }
 
+  if (dont_sync)
+    flags |= AT_STATX_DONT_SYNC;
+  else if (force_sync)
+    flags |= AT_STATX_FORCE_SYNC;
+
   fd = statx(fd, filename, flags, format_to_mask(format), &stx);
   if (fd < 0)
     {
@@ -1797,6 +1812,12 @@ Display file or file system status.\n\
   -L, --dereference     follow links\n\
   -f, --file-system     display file system status instead of file status\n\
 "), stdout);
+#if HAVE_STATX && defined STATX_INO
+      fputs (_("\
+  -D, --dont-sync      don't synchronize with server (for network fs')\n\
+  -F, --force-sync     force synchronization with server (for network fs')\n\
+"), stdout);
+#endif
       fputs (_("\
   -c  --format=FORMAT   use the specified FORMAT instead of the default;\n\
                           output a newline after each use of FORMAT\n\
@@ -1929,6 +1950,26 @@ main (int argc, char *argv[])
           trailing_delim = "\n";
           break;
 
+#if HAVE_STATX && defined STATX_INO
+       case 'D':
+         if (force_sync)
+            {
+              error (0, 0, _("--dont-sync and --force-sync are mutually 
exclusive"));
+              usage (EXIT_FAILURE);
+            }
+         dont_sync = true;
+         break;
+
+       case 'F':
+         if (dont_sync)
+            {
+              error (0, 0, _("--dont-sync and --force-sync are mutually 
exclusive"));
+              usage (EXIT_FAILURE);
+            }
+         force_sync = true;
+         break;
+#endif
+
         case 'L':
           follow_links = true;
           break;
-- 
2.20.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]