summaryrefslogtreecommitdiff
path: root/src/extract-magic
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2011-12-22 23:23:02 +0100
committerJim Meyering <meyering@redhat.com>2011-12-23 22:39:14 +0100
commit9c54c0a1d04ec243f9d118d679f31cd17b35ce6b (patch)
tree25bfac7d970d951301e05e15e3f12b6a2fa46db5 /src/extract-magic
parent6e3299fcdb783b19552dbb2ceb0d012ce51a3501 (diff)
downloadcoreutils-9c54c0a1d04ec243f9d118d679f31cd17b35ce6b.tar.xz
tail: with -f, use polling when a file is on an FS of unknown type
Before, we would use inotify in that case, which would work as long as updates were taking place locally, but not at all when remote. Move hard-coded list of known remote FS types into a more maintainable table in stat.c, alongside the list of FS names and magic numbers. Generate a new is_local_fs_type function. * src/Makefile.am (fs-is-local.h): New rule, generated file. * src/extract-magic: Revamp to parse local/remote keyword after each magic number in src/stat.c's case statements. Accept new --local option. * src/.gitignore: Ignore the generated fs-is-local.h. * src/tail.c [HAVE_INOTIFY]: Include fs-is-local.h. (fremote) [HAVE_INOTIFY]: Use the new function in place of the switch stmt with hard-coded list of FS types. Emit a warning when processing a file on a file system of unknown type. * NEWS (Changes in behavior): Mention it. Suggested by Sven Breuner.
Diffstat (limited to 'src/extract-magic')
-rw-r--r--src/extract-magic48
1 files changed, 38 insertions, 10 deletions
diff --git a/src/extract-magic b/src/extract-magic
index 6bc054f50..57d3681ae 100644
--- a/src/extract-magic
+++ b/src/extract-magic
@@ -65,10 +65,15 @@ FIXME: describe
OPTIONS:
- Derive #define directives from specially formatted `case ...:' statements.
+ There are two modes of operation, the default, which is to emit
+ #define directives derived from specially formatted `case' statements,
+ and that with --local, which is to emit a static inline function
+ mapping S_MAGIC_* values to 1, 0, -1, corresponding to known-local,
+ known-remote/distributed/network and unknown, respectively.
- --help display this help and exit
- --version output version information and exit
+ --local emit an is_local_fs_type function
+ --help display this help and exit
+ --version output version information and exit
EOF
}
@@ -76,8 +81,12 @@ EOF
}
{
+ # The default is to print S_MAGIC_* definitions.
+ my $emit_magic = 1;
+
GetOptions
(
+ local => sub { $emit_magic = 0 },
help => sub { usage 0 },
version => sub { print "$ME version $VERSION\n"; exit },
) or usage 1;
@@ -103,31 +112,50 @@ EOF
# Fail if there is a `case S_MAGIC_.*' line without
# a properly formed comment.
- print <<EOF;
+ my $map_comment = <<EOF;
+/* Map each S_MAGIC_* value to 1, 0 or -1.
+ 1 if it is known to be a remote file system type,
+ 0 if it is known to be a local file system type, or -1 otherwise. */
+EOF
+ my $magic_comment = <<EOF;
/* Define the magic numbers as given by statfs(2).
Please send additions to bug-coreutils\@gnu.org and meskes\@debian.org.
This file is generated automatically from $file. */
-
-#if defined __linux__
EOF
+ print $emit_magic ? $magic_comment : $map_comment;
+
+ $emit_magic
+ and print "\n#if defined __linux__\n";
+ $emit_magic
+ or print "static inline int\n"
+ . "is_local_fs_type (unsigned long int magic)\n"
+ . "{\n switch (magic)\n {\n";
while (defined (my $line = <FH>))
{
$line =~ /^[ \t]+case S_MAGIC_/
or next;
- $line =~ m!^[ \t]+case (S_MAGIC_\w+): /\* (0x[0-9A-Fa-f]+) \*/$!
+ $line =~
+ m!^[ \t]+case (S_MAGIC_\w+): /\* (0x[0-9A-Fa-f]+) (local|remote) \*/!
or (warn "$ME:$file:$.: malformed case S_MAGIC_... line"),
$fail = 1, next;
my $name = $1;
- my $value = $2;
- print "# define $name $value\n";
+ my $magic = $2;
+ my $local = $3 eq 'local' ? 1 : 0;
+ print $emit_magic
+ ? "# define $name $magic\n"
+ : " case $name: return $local;\n";
}
- print <<\EOF;
+ $emit_magic
+ and print <<\EOF;
#elif defined __GNU__
# include <hurd/hurd_types.h>
#endif
EOF
+ $emit_magic
+ or printf " default: return -1;\n }\n}\n";
+
close FH;
exit $fail;