home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / utils / bug / 2318 < prev    next >
Encoding:
Text File  |  1993-01-03  |  15.6 KB  |  508 lines

  1. Newsgroups: gnu.utils.bug
  2. Path: sparky!uunet!cis.ohio-state.edu!clsi.UUCP!mitch
  3. From: mitch@clsi.UUCP (Mitchell Perilstein)
  4. Subject: suggestion for ls
  5. Message-ID: <9301032211.AA26134@clsi.clsi.COM>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Sun, 3 Jan 1993 22:11:58 GMT
  10. Approved: bug-gnu-utils@prep.ai.mit.edu
  11. Lines: 495
  12.  
  13. The following patches to fileutils-3.4 adds Yet Another Switch to ls:
  14.  
  15.      -M, --mountpoints
  16.           Indicate directories which are mountpoints by appending
  17.           a  `^'  character to their filename. If the long format
  18.           is also specified, indicates which device is mounted on
  19.           the mountpoint and the host, if remote.
  20.  
  21. Here is some sample output:
  22.  
  23. $ ls -M /
  24. backup          export          pcfs            var^
  25. bin             home^           sbin            vmunix
  26. boot            kadb            sys             vmunix.GENERIC
  27. clsi^           lib             tmp             vmunix.old
  28. dev             lost+found      tmp_rex
  29. etc             mnt             usr^
  30.  
  31. $ ls -lM /
  32. total 4820
  33. drwxrwxrwx   3 root     users         512 Jan  2 14:32 backup
  34. lrwxrwxrwx   1 root     wheel           7 May  1  1992 bin -> usr/bin
  35. -r--r--r--   1 root     bin        140904 May  1  1992 boot
  36. drwxr-xr-x   8 root     wheel         512 Jan  1 22:58 clsi <- /dev/sd0e
  37. drwxr-sr-x   2 bin      staff       11264 Dec 21 14:16 dev
  38. drwxr-sr-x   9 bin      staff        3072 Jan  3 12:20 etc
  39. drwxr-sr-x   4 root     wheel         512 May  1  1992 export
  40. drwxr-xr-x  11 root     wheel         512 Jan  1 23:04 home <- /dev/sd0h
  41. -rwxr-xr-x   1 root     wheel      311163 May  1  1992 kadb
  42. lrwxrwxrwx   1 root     wheel           7 May  1  1992 lib -> usr/lib
  43. ..
  44.  
  45. $ ls -lM /home/dev
  46. total 6
  47. drwxrws---  13 markb    rvcg          512 Dec 11 12:50 codegen <- dubhe:/dubhe/codegen
  48. drwxrws---   8 hank     users         512 Nov 11 14:22 internal <- unuk:/unuk/internal
  49. drwxrwsr-x   7 daniel   third         512 Jan  3 16:55 openhdl <- pollux:/pollux/openhdl
  50. drwxrws---  22 glenn    synth         512 Dec 18 15:49 synthesis <- capella:/capella/synthesis
  51. ..
  52.  
  53. --> NOTE
  54. --> Tested only on Sun4 SunOS 4.1 and RISC Ultrix V4.2A. There are
  55. --> some platform-dependent things in mountlist.c which I could not
  56. --> test; they might even produce syntax errors.
  57.  
  58. Recursive context diffs follow.  Thanks for such a nice and easily
  59. maintainable product!
  60.  
  61. Respectfully,
  62. ---
  63.  Mitchell N. Perilstein   CAD Language Systems, Inc.   410-992-5700 x225 
  64.  Member, League for Programming Freedom.  Mail lpf@uunet.uu.net for info.
  65.  
  66.  
  67. diff -cr fileutils-3.4.orig/ChangeLog fileutils-3.4/ChangeLog
  68. *** fileutils-3.4.orig/ChangeLog    Thu Oct 29 15:23:14 1992
  69. --- fileutils-3.4/ChangeLog    Fri Jan  1 17:41:26 1993
  70. ***************
  71. *** 1,3 ****
  72. --- 1,10 ----
  73. + Fri Jan  1 17:31:54 1993  Mitchell Perilstein  (mitch@clsi.com)
  74. +     * mountlist.{c,h}: read_filesystem_list records inode of mountdir.
  75. +     * Makefile.in, ls.1, ls.c: Add -M,--mountpoint option. ls calls
  76. +     read_filesystem_list; uses dev and inode to compare mountponts.
  77.   Thu Oct 29 14:57:21 1992  David J. MacKenzie  (djm@kropotkin.gnu.ai.mit.edu)
  78.   
  79.       * Version 3.4.
  80. Common subdirectories: fileutils-3.4.orig/lib and fileutils-3.4/lib
  81. Common subdirectories: fileutils-3.4.orig/man and fileutils-3.4/man
  82. Common subdirectories: fileutils-3.4.orig/src and fileutils-3.4/src
  83. diff -cr fileutils-3.4.orig/lib/mountlist.c fileutils-3.4/lib/mountlist.c
  84. *** fileutils-3.4.orig/lib/mountlist.c    Sat Apr 18 15:33:08 1992
  85. --- fileutils-3.4/lib/mountlist.c    Fri Jan  1 17:39:27 1993
  86. ***************
  87. *** 17,22 ****
  88. --- 17,23 ----
  89.   
  90.   #include <stdio.h>
  91.   #include <sys/types.h>
  92. + #include <sys/stat.h>
  93.   #include "mountlist.h"
  94.   
  95.   #ifdef STDC_HEADERS
  96. ***************
  97. *** 169,174 ****
  98. --- 170,176 ----
  99.     struct mount_entry *mount_list;
  100.     struct mount_entry *me;
  101.     struct mount_entry *mtail;
  102. +   struct stat statbuf;  
  103.   
  104.     /* Start the list off with a dummy entry. */
  105.     me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
  106. ***************
  107. *** 195,200 ****
  108. --- 197,206 ----
  109.       me = (struct mount_entry *) xmalloc (sizeof (struct mount_entry));
  110.       me->me_devname = xstrdup (mnt->mnt_fsname);
  111.       me->me_mountdir = xstrdup (mnt->mnt_dir);
  112. +     if (stat (mnt->mnt_dir, &statbuf) >= 0)
  113. +         me->me_ino = statbuf.st_ino;
  114. +     else
  115. +         me->me_ino = 0;
  116.       me->me_type = xstrdup (mnt->mnt_type);
  117.       devopt = strstr (mnt->mnt_opts, "dev=");
  118.       if (devopt)
  119. ***************
  120. *** 233,238 ****
  121. --- 239,248 ----
  122.       me->me_mountdir = xstrdup (fsp->f_mntonname);
  123.       me->me_type = fstype_to_string (fsp->f_type);
  124.       me->me_dev = -1;    /* Magic; means not known yet. */
  125. +     if (stat (mnt->mnt_dir, &statbuf) >= 0)
  126. +         me->me_ino = statbuf.st_ino;
  127. +     else
  128. +         me->me_ino = 0;
  129.       me->me_next = NULL;
  130.   
  131.       /* Add to the linked list. */
  132. ***************
  133. *** 257,262 ****
  134. --- 267,276 ----
  135.       me->me_mountdir = xstrdup (fsd.fd_req.path);
  136.       me->me_type = gt_names[fsd.fd_req.fstype];
  137.       me->me_dev = fsd.fd_req.dev;
  138. +     if (stat (fsd.fd_req.path, &statbuf) >= 0)
  139. +         me->me_ino = statbuf.st_ino;
  140. +     else
  141. +         me->me_ino = 0;
  142.       me->me_next = NULL;
  143.   
  144.       /* Add to the linked list. */
  145. ***************
  146. *** 290,295 ****
  147. --- 304,313 ----
  148.   #endif
  149.       me->me_mountdir = xstrdup (mnt.mt_filsys);
  150.       me->me_dev = -1;    /* Magic; means not known yet. */
  151. +     if (stat (mnt.mt_filsys, &statbuf) >= 0)
  152. +         me->me_ino = statbuf.st_ino;
  153. +     else
  154. +         me->me_ino = 0;
  155.       me->me_type = "";
  156.   #ifdef GETFSTYP            /* SVR3.  */
  157.       if (need_fs_type)
  158. ***************
  159. *** 332,337 ****
  160. --- 350,359 ----
  161.       me->me_mountdir = xstrdup (mnt.mnt_mountp);
  162.       me->me_type = xstrdup (mnt.mnt_fstype);
  163.       me->me_dev = -1;    /* Magic; means not known yet. */
  164. +     if (stat (mnt.mnt_mountp, &statbuf) >= 0)
  165. +         me->me_ino = statbuf.st_ino;
  166. +     else
  167. +         me->me_ino = 0;
  168.       me->me_next = NULL;
  169.   
  170.       /* Add to the linked list. */
  171. ***************
  172. *** 384,389 ****
  173. --- 406,415 ----
  174.       me->me_mountdir = xstrdup (thisent + vmp->vmt_data[VMT_STUB].vmt_off);
  175.       me->me_type = xstrdup (fstype_to_string (vmp->vmt_gfstype));
  176.       me->me_dev = -1;    /* vmt_fsid might be the info we want.  */
  177. +     if (stat (me->me_mountdir, &statbuf) >= 0)
  178. +         me->me_ino = statbuf.st_ino;
  179. +     else
  180. +         me->me_ino = 0;
  181.       me->me_next = NULL;
  182.   
  183.       /* Add to the linked list. */
  184. diff -cr fileutils-3.4.orig/lib/mountlist.h fileutils-3.4/lib/mountlist.h
  185. *** fileutils-3.4.orig/lib/mountlist.h    Wed Mar 25 12:33:05 1992
  186. --- fileutils-3.4/lib/mountlist.h    Thu Dec 31 15:27:47 1992
  187. ***************
  188. *** 22,27 ****
  189. --- 22,28 ----
  190.     char *me_mountdir;        /* Mount point directory pathname. */
  191.     char *me_type;        /* "nfs", "4.2", etc. */
  192.     dev_t me_dev;            /* Device number of me_mountdir. */
  193. +   ino_t me_ino;            /* Inode of me_mountdir. */
  194.     struct mount_entry *me_next;
  195.   };
  196.   
  197. diff -cr fileutils-3.4.orig/man/ls.1 fileutils-3.4/man/ls.1
  198. *** fileutils-3.4.orig/man/ls.1    Wed Oct 14 23:17:11 1992
  199. --- fileutils-3.4/man/ls.1    Fri Jan  1 17:44:03 1993
  200. ***************
  201. *** 3,14 ****
  202.   ls, dir, vdir \- list contents of directories
  203.   .SH SYNOPSIS
  204.   .B ls
  205. ! [\-abcdgiklmnpqrstuxABCFLNQRSUX1] [\-w cols] [\-T cols] [\-I pattern]
  206.   [\-\-all] [\-\-escape] [\-\-directory] [\-\-inode] [\-\-kilobytes]
  207.   [\-\-numeric-uid-gid] [\-\-hide-control-chars] [\-\-reverse] [\-\-size]
  208.   [\-\-width=cols] [\-\-tabsize=cols] [\-\-almost-all] [\-\-ignore-backups]
  209.   [\-\-classify] [\-\-file-type] [\-\-ignore=pattern] [\-\-dereference]
  210. ! [\-\-literal] [\-\-quote-name] [\-\-recursive]
  211.   [\-\-sort={none,time,size,extension}]
  212.   [\-\-format={long,verbose,commas,across,vertical,single-column}]
  213.   [\-\-time={atime,access,use,ctime,status}] [path...]
  214. --- 3,14 ----
  215.   ls, dir, vdir \- list contents of directories
  216.   .SH SYNOPSIS
  217.   .B ls
  218. ! [\-abcdgiklmnpqrstuxABCFLMNQRSUX1] [\-w cols] [\-T cols] [\-I pattern]
  219.   [\-\-all] [\-\-escape] [\-\-directory] [\-\-inode] [\-\-kilobytes]
  220.   [\-\-numeric-uid-gid] [\-\-hide-control-chars] [\-\-reverse] [\-\-size]
  221.   [\-\-width=cols] [\-\-tabsize=cols] [\-\-almost-all] [\-\-ignore-backups]
  222.   [\-\-classify] [\-\-file-type] [\-\-ignore=pattern] [\-\-dereference]
  223. ! [\-\-literal] [\-\-mountpoints] [\-\-quote-name] [\-\-recursive]
  224.   [\-\-sort={none,time,size,extension}]
  225.   [\-\-format={long,verbose,commas,across,vertical,single-column}]
  226.   [\-\-time={atime,access,use,ctime,status}] [path...]
  227. ***************
  228. *** 119,124 ****
  229. --- 119,129 ----
  230.   .I "\-L, \-\-dereference"
  231.   List the files linked to by symbolic links instead of listing the
  232.   contents of the links.
  233. + .TP
  234. + .I "\-M, \-\-mountpoints"
  235. + Indicate directories which are mountpoints by appending a `^' character
  236. + to their filename. If the long format is also specified, indicates which
  237. + device is mounted on the mountpoint and the host, if remote.
  238.   .TP
  239.   .I "\-N, \-\-literal"
  240.   Do not quote file names.
  241. diff -cr fileutils-3.4.orig/src/ls.c fileutils-3.4/src/ls.c
  242. *** fileutils-3.4.orig/src/ls.c    Wed Oct 14 23:08:47 1992
  243. --- fileutils-3.4/src/ls.c    Fri Jan  1 18:18:52 1993
  244. ***************
  245. *** 45,50 ****
  246. --- 45,51 ----
  247.   #include <getopt.h>
  248.   #include <fnmatch.h>
  249.   #include "system.h"
  250. + #include "mountlist.h"
  251.   
  252.   #ifndef S_IEXEC
  253.   #define S_IEXEC S_IXUSR
  254. ***************
  255. *** 180,185 ****
  256. --- 181,191 ----
  257.   
  258.   /* The name the program was run with, stripped of any leading path. */
  259.   char *program_name;
  260. + /* List of mountpoints. Used only when show_mountpoints (-M) is nonzero. */
  261. + struct mount_entry *mountpoint_list;
  262.   
  263.   /* Option flags */
  264.   
  265. ***************
  266. *** 263,268 ****
  267. --- 269,280 ----
  268.   
  269.   enum indicator_style indicator_style;
  270.   
  271. + /* Nonzero means show when a directory is a mountpoint; `^' is an 
  272. +    displayed unless -l; `filename <- host:dir' when -l. Controlled 
  273. +    by -M. */
  274. + int show_mountpoints;
  275.   /* Nonzero means mention the inode number of each file.  -i  */
  276.   
  277.   int print_inode;
  278. ***************
  279. *** 367,373 ****
  280.     format_needs_stat = sort_type == sort_time || sort_type == sort_size
  281.       || format == long_format
  282.       || trace_links || trace_dirs || indicator_style != none
  283. !     || print_block_size || print_inode;
  284.   
  285.     nfiles = 100;
  286.     files = (struct file *) xmalloc (sizeof (struct file) * nfiles);
  287. --- 379,386 ----
  288.     format_needs_stat = sort_type == sort_time || sort_type == sort_size
  289.       || format == long_format
  290.       || trace_links || trace_dirs || indicator_style != none
  291. !     || print_block_size || print_inode 
  292. !     || show_mountpoints;
  293.   
  294.     nfiles = 100;
  295.     files = (struct file *) xmalloc (sizeof (struct file) * nfiles);
  296. ***************
  297. *** 437,442 ****
  298. --- 450,456 ----
  299.     {"file-type", 0, 0, 'F'},
  300.     {"ignore", 1, 0, 'I'},
  301.     {"dereference", 0, 0, 'L'},
  302. +   {"mountpoints", 0, 0, 'M'},
  303.     {"literal", 0, 0, 'N'},
  304.     {"quote-name", 0, 0, 'Q'},
  305.     {"recursive", 0, 0, 'R'},
  306. ***************
  307. *** 535,540 ****
  308. --- 549,555 ----
  309.     really_all_files = 0;
  310.     ignore_patterns = 0;
  311.     quote_as_string = 0;
  312. +   show_mountpoints = 0;
  313.   
  314.     p = getenv ("COLUMNS");
  315.     line_length = p ? atoi (p) : 80;
  316. ***************
  317. *** 551,557 ****
  318.     p = getenv ("TABSIZE");
  319.     tabsize = p ? atoi (p) : 8;
  320.   
  321. !   while ((c = getopt_long (argc, argv, "abcdgiklmnpqrstuw:xABCFI:LNQRST:UX1",
  322.                  long_options, (int *) 0)) != EOF)
  323.       {
  324.         switch (c)
  325. --- 566,572 ----
  326.     p = getenv ("TABSIZE");
  327.     tabsize = p ? atoi (p) : 8;
  328.   
  329. !   while ((c = getopt_long (argc, argv, "abcdgiklmnpqrstuw:xABCFI:LMNQRST:UX1",
  330.                  long_options, (int *) 0)) != EOF)
  331.       {
  332.         switch (c)
  333. ***************
  334. *** 663,668 ****
  335. --- 678,688 ----
  336.         qmark_funny_chars = 0;
  337.         break;
  338.         
  339. +     case 'M':
  340. +       show_mountpoints = 1;
  341. +       mountpoint_list = 0;
  342. +       break;
  343. +       
  344.       case 'Q':
  345.         quote_as_string = 1;
  346.         quote_funny_chars = 1;
  347. ***************
  348. *** 1141,1146 ****
  349. --- 1161,1218 ----
  350.   
  351.     return 1;
  352.   }
  353. + /* Based on cwd and pending list, calculate whole path to a file. 
  354. +    Returns allocated string. */
  355. + char *
  356. + get_whole_path(file)
  357. +      char *file;
  358. + {
  359. +   char *xgetcwd();
  360. +   char *result;
  361. +   
  362. +   if (dir_defaulted)
  363. +     {
  364. +       char *cwd = xgetcwd();    /* should error check this call?? */
  365. +       int cwdlen = strlen(cwd);
  366. +       
  367. +       result = (char *)xrealloc (cwd, cwdlen + strlen(file) + 2);
  368. +       result[cwdlen] = '\\';
  369. +       strcat(&result[cwdlen + 1], file) ;
  370. +     } 
  371. +   else 
  372. +     { 
  373. +       ;
  374. +       
  375. +     }    
  376. +   return result;
  377. + }
  378. + /* Returns char pointer to name of device if DIR is a mountpoint, otherwise
  379. +    returns NULL. */
  380. + char *
  381. + is_mountpoint(dir)
  382. +     struct file *dir;
  383. + {
  384. +     struct mount_entry *me;
  385. +     /* Init the mount list. Only do this first time it's needed. */
  386. +     if (!mountpoint_list)
  387. +       {
  388. +          mountpoint_list = read_filesystem_list(1, 1);
  389. +      if (!mountpoint_list)
  390. +        return (char *)NULL; /* Nonfatal error, just keep going. */
  391. +                   /* At worst, the listing will be wrong. */
  392. +       }    
  393. +     /* Compare directory against every mountpoint. Compare device 
  394. +        numbers and then inode numbers. */
  395. +     for (me = mountpoint_list; NULL != me; me = me->me_next)
  396. +     if (me->me_dev == dir->stat.st_dev && me->me_ino == dir->stat.st_ino) 
  397. +         return me->me_devname;
  398. +     return (char *)NULL;
  399. + }
  400.   
  401.   /* Sort the files now in the table.  */
  402.   
  403. ***************
  404. *** 1416,1422 ****
  405.           print_type_indicator (f->linkmode);
  406.       }
  407.       }
  408. !   else if (indicator_style != none)
  409.       print_type_indicator (f->stat.st_mode);
  410.   }
  411.   
  412. --- 1488,1504 ----
  413.           print_type_indicator (f->linkmode);
  414.       }
  415.       }
  416. !   else if ((f->filetype == directory || f->filetype == arg_directory)
  417. !        && show_mountpoints)
  418. !     {
  419. !       char *devname = is_mountpoint (f);
  420. !     
  421. !       if (NULL != devname)
  422. !     printf (" <- %s", devname);
  423. !       else if (indicator_style != none)
  424. !     print_type_indicator (f->stat.st_mode);
  425. !     }
  426. !  else if (indicator_style != none)
  427.       print_type_indicator (f->stat.st_mode);
  428.   }
  429.   
  430. ***************
  431. *** 1506,1513 ****
  432.   
  433.     print_name_with_quoting (f->name);
  434.   
  435. !   if (indicator_style != none)
  436. !     print_type_indicator (f->stat.st_mode);
  437.   }
  438.   
  439.   void
  440. --- 1588,1604 ----
  441.   
  442.     print_name_with_quoting (f->name);
  443.   
  444. !   if ((f->filetype == directory || f->filetype == arg_directory)
  445. !       && show_mountpoints)
  446. !     {
  447. !       if (NULL != is_mountpoint (f))    
  448. !     putchar ('^');
  449. !       else if (indicator_style != none)
  450. !       print_type_indicator (f->stat.st_mode);
  451. !     }
  452. !   else
  453. !     if (indicator_style != none)
  454. !       print_type_indicator (f->stat.st_mode);
  455.   }
  456.   
  457.   void
  458. ***************
  459. *** 1799,1805 ****
  460.   usage ()
  461.   {
  462.     fprintf (stderr, "\
  463. ! Usage: %s [-abcdgiklmnpqrstuxABCFLNQRSUX1] [-w cols] [-T cols] [-I pattern]\n\
  464.          [--all] [--escape] [--directory] [--inode] [--kilobytes] [--literal]\n\
  465.          [--numeric-uid-gid] [--hide-control-chars] [--reverse] [--size]\n\
  466.          [--width=cols] [--tabsize=cols] [--almost-all] [--ignore-backups]\n",
  467. --- 1890,1896 ----
  468.   usage ()
  469.   {
  470.     fprintf (stderr, "\
  471. ! Usage: %s [-abcdgiklmnpqrstuxABCFLMNQRSUX1] [-w cols] [-T cols] [-I pattern]\n\
  472.          [--all] [--escape] [--directory] [--inode] [--kilobytes] [--literal]\n\
  473.          [--numeric-uid-gid] [--hide-control-chars] [--reverse] [--size]\n\
  474.          [--width=cols] [--tabsize=cols] [--almost-all] [--ignore-backups]\n",
  475. ***************
  476. *** 1806,1812 ****
  477.          program_name);
  478.     fprintf (stderr, "\
  479.          [--classify] [--file-type] [--ignore=pattern] [--dereference]\n\
  480. !        [--quote-name] [--recursive] [--sort={none,time,size,extension}]\n\
  481.          [--format={long,verbose,commas,across,vertical,single-column}]\n\
  482.          [--time={atime,access,use,ctime,status}] [path...]\n");
  483.     exit (1);
  484. --- 1897,1904 ----
  485.          program_name);
  486.     fprintf (stderr, "\
  487.          [--classify] [--file-type] [--ignore=pattern] [--dereference]\n\
  488. !        [--mountpoints] [--quote-name] [--recursive]\n\
  489. !        [--sort={none,time,size,extension}]\n\
  490.          [--format={long,verbose,commas,across,vertical,single-column}]\n\
  491.          [--time={atime,access,use,ctime,status}] [path...]\n");
  492.     exit (1);
  493.  
  494.  
  495.