coreutils
[Top][All Lists]
Advanced

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

[PATCH] stat: add --list-fstypes option for listing known file system ty


From: Bernhard Voelker
Subject: [PATCH] stat: add --list-fstypes option for listing known file system types
Date: Wed, 07 Aug 2013 22:17:29 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130329 Thunderbird/17.0.5

Hi *,

WDYT about a new option for stat(1) to list all known file system types?

The output looks like the following:

  $ src/stat --list-fstypes | head -n4
  FsType                  Magic           Treated by tail(1): local/remote?
  ADFS                    0xADF5          local
  AFFS                    0xADFF          local
  AFS                     0x5346414F      remote
  ...


I didn't include a test yet but would add one
if someone thinks it would be worthwhile.

Have a nice day,
Berny


>From 537b402bdffdbac07f85b3ef251cee812c7e489e Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <address@hidden>
Date: Wed, 7 Aug 2013 22:08:52 +0200
Subject: [PATCH] stat: add --list-fstypes option for listing known file system
 types

* src/extract-magic: Generate the function list_known_fstypes()
into the file "fs.h", i.e., in the $emit_magic case.
While at it, add a recurse-inclusion guard for that file.
* src/stat.c (LIST_FSTYPES_OPTION): Add new enum, used ...
(long_options): ... here to identify the new --list-fstypes option.
(usage): Add the new option.
(main): Handle the new option.
* doc/coreutils.texi (stat invocation): Document the new option.
* NEWS: Mention the new option.
---
 NEWS               |  3 +++
 doc/coreutils.texi |  7 +++++++
 src/extract-magic  | 21 ++++++++++++++++++++-
 src/stat.c         | 11 ++++++++++-
 4 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 4a78617..dffef23 100644
--- a/NEWS
+++ b/NEWS
@@ -53,6 +53,9 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   csplit accepts a new option: --suppressed-matched, to elide the lines
   used to identify the split points.

+  stat accepts a new option: --list-fstypes to list all file system types
+  known by stat(1) and tail(1).
+
   shuf accepts a new option: --repetitions (-r), to allow repetitions
   of input items in the permuted output.

diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index aef5cc9..d451ed7 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -11671,6 +11671,13 @@ also give information about the files the links point 
to.

 @table @samp

address@hidden --list-fstypes
address@hidden --list-fstypes
address@hidden file systems
+List all file system types known by @command{stat} and exit immediately.
+The list includes the names of the file system, the magic numbers and
+whether @command{tail} treats them as a local or a remote file system.
+
 @item -L
 @itemx --dereference
 @opindex -L
diff --git a/src/extract-magic b/src/extract-magic
index 98e9d87..f984c1a 100644
--- a/src/extract-magic
+++ b/src/extract-magic
@@ -125,7 +125,18 @@ EOF
   print $emit_magic ? $magic_comment : $map_comment;

   $emit_magic
-    and print "\n#if defined __linux__\n";
+    and print "\n#ifndef FS_H\n"
+              . "# define FS_H\n\n"
+              . "static inline void\n"
+              . "list_known_fstypes (void)\n"
+              . "{\n"
+              . "  const char *fmt = \"%-20s\\t%-10s\\t\%s\\n\";\n"
+              . "  const char *strLocal   = _(\"local\");\n"
+              . "  const char *strRemote  = _(\"remote\");\n"
+              . "  printf(fmt, \n"
+              . "         _(\"FsType\"), _(\"Magic\"), \n"
+              . "         _(\"Treated by tail(1): local/remote?\"));\n"
+              . "#if defined __linux__\n";
   $emit_magic
     or print "static inline int\n"
       . "is_local_fs_type (unsigned long int magic)\n"
@@ -144,14 +155,22 @@ EOF
       my $local = $3 eq 'local' ? 1 : 0;
       print $emit_magic
         ? "# define $name $magic\n"
+          . "  printf(fmt, "
+          .          "\"" . substr ($name, 8) . "\", "  # strip off "S_MAGIC_"
+          .          "\"$magic\","
+          .          ($local ? "strLocal" : "strRemote")
+          . ");\n"
         : "      case $name: return $local;\n";
     }

   $emit_magic
     and print <<\EOF;
 #elif defined __GNU__
+  printf("%s\n", _("Sorry, not implemented on GNU/Hurd"));
 # include <hurd/hurd_types.h>
 #endif
+}
+#endif
 EOF
   $emit_magic
     or printf "      default: return -1;\n    }\n}\n";
diff --git a/src/stat.c b/src/stat.c
index ce0aec8..b4255af 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -174,7 +174,8 @@ static char const printf_flags[] = "'-+ #0I";

 enum
 {
-  PRINTF_OPTION = CHAR_MAX + 1
+  PRINTF_OPTION = CHAR_MAX + 1,
+  LIST_FSTYPES_OPTION
 };

 static struct option const long_options[] =
@@ -182,6 +183,7 @@ static struct option const long_options[] =
   {"dereference", no_argument, NULL, 'L'},
   {"file-system", no_argument, NULL, 'f'},
   {"format", required_argument, NULL, 'c'},
+  {"list-fstypes", no_argument, NULL, LIST_FSTYPES_OPTION},
   {"printf", required_argument, NULL, PRINTF_OPTION},
   {"terse", no_argument, NULL, 't'},
   {GETOPT_HELP_OPTION_DECL},
@@ -1361,6 +1363,9 @@ Display file or file system status.\n\
       emit_mandatory_arg_note ();

       fputs (_("\
+      --list-fstypes    list known file system types (and exit)\n\
+"), stdout);
+      fputs (_("\
   -L, --dereference     follow links\n\
   -f, --file-system     display file system status instead of file status\n\
 "), stdout);
@@ -1492,6 +1497,10 @@ main (int argc, char *argv[])
           terse = true;
           break;

+        case LIST_FSTYPES_OPTION:
+          list_known_fstypes ();
+          exit (EXIT_SUCCESS);
+
         case_GETOPT_HELP_CHAR;

         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
-- 
1.8.3.1




reply via email to

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