[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC] First batch of changes for ls to support GNU extensions.
From: |
Alfred M. Szmidt |
Subject: |
[RFC] First batch of changes for ls to support GNU extensions. |
Date: |
Thu, 28 Mar 2002 10:31:20 +0100 |
User-agent: |
Gnus/5.090004 (Oort Gnus v0.04) Emacs/21.2.50 |
Hi,
This is the first public patch for `ls' to support those nice and joyful
GNU extensions.
Please submit any comments, etc.
diff -urp fileutils-4.1.7.orig/ChangeLog fileutils-4.1.7/ChangeLog
--- fileutils-4.1.7.orig/ChangeLog Sun Mar 10 23:23:19 2002
+++ fileutils-4.1.7/ChangeLog Wed Mar 27 23:44:21 2002
@@ -1,3 +1,22 @@
+2002-03-25 Alfred M. Szmidt <ams@kemisten.nu>
+
+ Add new --gnu-hurd-extensions/-e and --author options for GNU/Hurd.
+
+ The following changes have only an affect if HAVE_GNU_HURD_EXTENSIONS
+ is set.
+ * src/ls.c: (<hurd.h>): New include.
+ (struct fileinfo): New members trans_name, trans_fsid, trans_mode.
+ (print_author, print_gnu_hurd_extensions): New variables.
+ (enum): Define AUTHOR_OPTION.
+ (long_options, decode_switches): Add --gnu-hurd-extentions and
+ --author support.
+ (print_long_format, usage): Implement new changes.
+ * NEWS: Document this.
+ * doc/coreutils.texi: Likewise.
+ * configure.ac: Check for <hurd.h>, define HAVE_GNU_HURD_EXTENTIONS
+ if found.
+
+
2002-03-10 Jim Meyering <meyering@lucent.com>
* Version 4.1.7.
diff -urp fileutils-4.1.7.orig/NEWS fileutils-4.1.7/NEWS
--- fileutils-4.1.7.orig/NEWS Sat Mar 9 21:44:22 2002
+++ fileutils-4.1.7/NEWS Mon Mar 25 20:43:50 2002
@@ -1,3 +1,5 @@
+[4.1.8]
+* New ls option: --gnu-hurd-extensions/-e and --author (GNU/Hurd extension)
[4.1.7]
* rm: close a hole that would allow a running rm process to be subverted
[4.1.6]
diff -urp fileutils-4.1.7.orig/configure.ac fileutils-4.1.7/configure.ac
--- fileutils-4.1.7.orig/configure.ac Sun Mar 10 19:38:26 2002
+++ fileutils-4.1.7/configure.ac Mon Mar 25 18:25:42 2002
@@ -45,6 +45,10 @@ if test $fu_cv_sys_truncating_statfs = y
fi
AC_MSG_RESULT($fu_cv_sys_truncating_statfs)
+AC_CHECK_HEADER(hurd.h,
+ [AC_DEFINE(HAVE_GNU_HURD_EXTENSIONS, 1,
+ [Define to 1 if we have GNU/Hurd extentions.])])
+
jm_LIB_CHECK
AM_GNU_GETTEXT
diff -urp fileutils-4.1.7.orig/doc/coreutils.texi
fileutils-4.1.7/doc/coreutils.texi
--- fileutils-4.1.7.orig/doc/coreutils.texi Wed Mar 6 09:57:17 2002
+++ fileutils-4.1.7/doc/coreutils.texi Mon Mar 25 20:43:19 2002
@@ -4847,6 +4847,11 @@ List all files in directories, including
@opindex --almost-all
List all files in directories except for @file{.} and @file{..}.
+@item --author
+@opindex --author
+@cindex hurd, author, printing
+Display the author field of a file. (This is an GNU/Hurd extention)
+
@item -B
@itemx --ignore-backups
@opindex -B
@@ -4944,6 +4949,15 @@ Finally, output a line of the form:
//DIRED-OPTIONS// --quoting-style=@var{word}
@end example
where @var{word} is the quoting style (@pxref{Formatting the file names}).
+
+@item -e
+@itemx --gnu-hurd-extentions
+@opindex -e
+@opindex --gnu-hurd-extentions
+@cindex hurd, translator, unknown user, printing
+Display information about translators and the permission bits for unknown
+users.
+(This is an GNU/Hurd extention)
@item --full-time
@opindex --full-time
diff -urp fileutils-4.1.7.orig/src/ls.c fileutils-4.1.7/src/ls.c
--- fileutils-4.1.7.orig/src/ls.c Thu Feb 28 09:34:00 2002
+++ fileutils-4.1.7/src/ls.c Wed Mar 27 19:38:36 2002
@@ -66,6 +66,9 @@
#include <grp.h>
#include <pwd.h>
#include <getopt.h>
+#if HAVE_GNU_HURD_EXTENSIONS
+# include <hurd.h>
+#endif
/* Get MB_CUR_MAX. */
#if HAVE_STDLIB_H
@@ -219,6 +222,18 @@ struct fileinfo
struct stat stat;
+#if HAVE_GNU_HURD_EXTENSIONS
+ /* The translator that is attached to the node. */
+ char *trans_name;
+
+ /* The fsid for the active translator. */
+ int trans_fsid;
+
+ /* If 1 then we have a translator attached and/or running on the node,
+ otherwise 0. */
+ int trans_mode;
+#endif
+
/* For symbolic link, name of the file linked to, otherwise zero. */
char *linkname;
@@ -465,6 +480,14 @@ static int print_owner = 1;
static int print_group = 1;
+#if HAVE_GNU_HURD_EXTENSIONS
+/* Nonzero means to display author information.*/
+static int print_author = 0;
+
+/* Nonzero means to display unknown user bits and translator information. */
+static int print_gnu_hurd_extensions = 0;
+#endif
+
/* Nonzero means print the user and group id's as numbers rather
than as names. -n */
@@ -698,6 +721,9 @@ static int exit_status;
enum
{
BLOCK_SIZE_OPTION = CHAR_MAX + 1,
+#if HAVE_GNU_HURD_EXTENSIONS
+ AUTHOR_OPTION,
+#endif
COLOR_OPTION,
FORMAT_OPTION,
FULL_TIME_OPTION,
@@ -747,6 +773,10 @@ static struct option const long_options[
{"time-style", required_argument, 0, TIME_STYLE_OPTION},
{"color", optional_argument, 0, COLOR_OPTION},
{"block-size", required_argument, 0, BLOCK_SIZE_OPTION},
+#if HAVE_GNU_HURD_EXTENSIONS
+ {"author", no_argument, 0, AUTHOR_OPTION},
+ {"gnu-hurd-extentions", no_argument, 0, 'e'},
+#endif
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
@@ -1294,7 +1324,11 @@ decode_switches (int argc, char **argv)
}
while ((c = getopt_long (argc, argv,
- "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UX1",
+ "abcd"
+#if HAVE_GNU_HURD_EXTENSIONS
+ "e"
+#endif
+ "fghiklmnopqrstuvw:xABCDFGHI:LNQRST:UX1",
long_options, NULL)) != -1)
{
switch (c)
@@ -1315,6 +1349,13 @@ decode_switches (int argc, char **argv)
time_type = time_ctime;
break;
+#if HAVE_GNU_HURD_EXTENSIONS
+ case 'e':
+ format = long_format;
+ print_gnu_hurd_extensions = 1;
+ break;
+#endif
+
case 'd':
immediate_dirs = 1;
break;
@@ -1494,6 +1535,13 @@ decode_switches (int argc, char **argv)
format = one_per_line;
break;
+#if HAVE_GNU_HURD_EXTENSIONS
+ case AUTHOR_OPTION:
+ format = long_format;
+ print_author = 1;
+ break;
+#endif
+
case SORT_OPTION:
sort_type = XARGMATCH ("--sort", optarg, sort_args, sort_types);
sort_type_specified = 1;
@@ -2287,6 +2335,60 @@ gobble_file (const char *name, enum file
free (linkpath);
}
+#if HAVE_GNU_HURD_EXTENSIONS
+ if ((files[files_index].stat.st_mode & S_IROOT)
+ && print_gnu_hurd_extensions)
+ {
+ file_t trans_port;
+ int trans_fd;
+ struct stat trans_stat;
+
+ /* Get the underlying node */
+ trans_port = file_name_lookup (path, O_NOTRANS, 0);
+ if (trans_port == MACH_PORT_NULL)
+ {
+ error (0, errno, "%s", quotearg_colon (path));
+ exit_status = 1;
+ return 0;
+ }
+
+ trans_fd = open (path, O_NOTRANS);
+ if (trans_fd == -1)
+ {
+ error (0, errno, "%s", quotearg_colon (path));
+ exit_status = 1;
+ return 0;
+ }
+
+ fstat (trans_fd, &trans_stat);
+ if (trans_stat.st_mode & S_IPTRANS)
+ {
+ char buf[1024], *trans = buf;
+ int trans_len = sizeof (buf);
+
+ file_get_translator (trans_port, &trans, &trans_len);
+ argz_stringify (trans, trans_len, ' ');
+
+ files[files_index].trans_name = strdup(trans);
+ files[files_index].trans_mode = 1;
+ }
+
+ /* Get the top node. */
+ trans_fd = open (path, O_NORW);
+ if (trans_fd == -1)
+ {
+ error (0, errno, "%s", quotearg_colon (path));
+ exit_status = 1;
+ return 0;
+ }
+
+ fstat (trans_fd, &trans_stat);
+ files[files_index].trans_fsid = trans_stat.st_fsid;
+
+ mach_port_deallocate (mach_task_self(), trans_port);
+ }
+#endif /* HAVE_GNU_HURD_EXTENSIONS */
+
if (S_ISLNK (files[files_index].stat.st_mode))
files[files_index].filetype = symbolic_link;
else if (S_ISDIR (files[files_index].stat.st_mode))
@@ -2744,15 +2846,19 @@ get_current_time (void)
static void
print_long_format (const struct fileinfo *f)
{
- char modebuf[12];
-
+ char modebuf[15];
+
/* 7 fields that may require LONGEST_HUMAN_READABLE bytes,
- 1 10-byte mode string,
+ 1 10-byte mode string (13-bytes on GNU/Hurd)
1 35-byte time string (may be longer in some locales -- see below)
or LONGEST_HUMAN_READABLE integer,
9 spaces, one following each of these fields, and
1 trailing NUL byte. */
char init_bigbuf[7 * LONGEST_HUMAN_READABLE + 10
+#if HAVE_GNU_HURD_EXTENSIONS
+ + 3
+#endif
+ + 1
+ MAX (35, LONGEST_HUMAN_READABLE)
+ 9 + 1];
char *buf = init_bigbuf;
@@ -2770,8 +2876,39 @@ print_long_format (const struct fileinfo
mode_string (f->stat.st_mode, modebuf);
#endif
- modebuf[10] = (FILE_HAS_ACL (f) ? '+' : ' ');
- modebuf[11] = '\0';
+#if HAVE_GNU_HURD_EXTENSIONS
+#define S_IRUNK (S_IRUSR << S_IUNKSHIFT)
+#define S_IWUNK (S_IWUSR << S_IUNKSHIFT)
+#define S_IXUNK (S_IXUSR << S_IUNKSHIFT)
+
+ if (print_gnu_hurd_extensions)
+ {
+ /* If S_IUSEUNK is not set then default to showing group member
+ permission bits. */
+ if (f->stat.st_mode & S_IUSEUNK)
+ {
+ modebuf[10] = f->stat.st_mode & S_IRUNK ? 'r' : '-';
+ modebuf[11] = f->stat.st_mode & S_IWUNK ? 'w' : '-';
+ modebuf[12] = f->stat.st_mode & S_IXUNK ? 'x' : '-';
+ }
+ else
+ {
+ modebuf[10] = f->stat.st_mode & S_IROTH ? 'r' : '-';
+ modebuf[11] = f->stat.st_mode & S_IWOTH ? 'w' : '-';
+ modebuf[12] = f->stat.st_mode & S_IXOTH ? 'x' : '-';
+ }
+
+ modebuf[13] = (FILE_HAS_ACL (f) ? '+' : ' ');
+ modebuf[14] = '\0';
+ }
+ else
+ {
+#endif
+ modebuf[10] = (FILE_HAS_ACL (f) ? '+' : ' ');
+ modebuf[11] = '\0';
+#if HAVE_GNU_HURD_EXTENSIONS
+ }
+#endif
switch (time_type)
{
@@ -2834,6 +2971,19 @@ print_long_format (const struct fileinfo
p += strlen (p);
}
+#if HAVE_GNU_HURD_EXTENSIONS
+ if (print_author)
+ {
+ char const *author_name =
+ (numeric_ids ? NULL : getuser (f->stat.st_author));
+ if (author_name)
+ sprintf (p, "%-8s ", author_name);
+ else
+ sprintf (p, "%-8lu ", (unsigned long) f->stat.st_author);
+ p += strlen (p);
+ }
+#endif
+
if (S_ISCHR (f->stat.st_mode) || S_ISBLK (f->stat.st_mode))
sprintf (p, "%3lu, %3lu ",
(unsigned long) major (f->stat.st_rdev),
@@ -2940,6 +3090,19 @@ print_long_format (const struct fileinfo
print_type_indicator (f->linkmode);
}
}
+#if HAVE_GNU_HURD_EXTENSIONS
+ else if ((f->stat.st_mode & S_IROOT)
+ && print_gnu_hurd_extensions)
+ {
+ DIRED_FPUTS_LITERAL (" => ", stdout);
+ if (f->trans_name)
+ printf ("%s", f->trans_name);
+ else
+ printf ("unknown");
+
+ printf (" (%d)", f->trans_fsid);
+ }
+#endif /* HAVE_GNU_HURD_EXTENSIONS */
else if (indicator_style != none)
print_type_indicator (f->stat.st_mode);
}
@@ -3584,9 +3747,14 @@ Mandatory arguments to long options are
fputs (_("\
-a, --all do not hide entries starting with .\n\
-A, --almost-all do not list implied . and ..\n\
- -b, --escape print octal escapes for nongraphic characters\n\
"), stdout);
+#if HAVE_GNU_HURD_EXTENSIONS
fputs (_("\
+ --author print the author of each file\n\
+"), stdout);
+#endif
+ fputs (_("\
+ -b, --escape print octal escapes for nongraphic characters\n\
--block-size=SIZE use SIZE-byte blocks\n\
-B, --ignore-backups do not list implied entries ending with ~\n\
-c with -lt: sort by, and show, ctime (time of
last\n\
@@ -3601,6 +3769,12 @@ Mandatory arguments to long options are
-d, --directory list directory entries instead of contents\n\
-D, --dired generate output designed for Emacs' dired mode\n\
"), stdout);
+#if HAVE_GNU_HURD_EXTENSIONS
+ fputs (_("\
+ -e, --gnu-hurd-extentions print translator information and unknown\n\
+ user bits\n\
+"), stdout);
+#endif
fputs (_("\
-f do not sort, enable -aU, disable -lst\n\
-F, --classify append indicator (one of */=@|) to entries\n\
--
Alfred M. Szmidt
- [RFC] First batch of changes for ls to support GNU extensions.,
Alfred M. Szmidt <=