add -o option to list file flags
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 13 Dec 1991 08:36:56 +0000 (00:36 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 13 Dec 1991 08:36:56 +0000 (00:36 -0800)
SCCS-vsn: bin/ls/ls.h 5.13
SCCS-vsn: bin/ls/print.c 5.26
SCCS-vsn: bin/ls/ls.1 6.19
SCCS-vsn: bin/ls/ls.c 5.52

usr/src/bin/ls/ls.1
usr/src/bin/ls/ls.c
usr/src/bin/ls/ls.h
usr/src/bin/ls/print.c

index c1b17a8..341e83f 100644 (file)
@@ -6,7 +6,7 @@
 .\"
 .\" %sccs.include.redist.roff%
 .\"
 .\"
 .\" %sccs.include.redist.roff%
 .\"
-.\"     @(#)ls.1       6.18 (Berkeley) %G%
+.\"     @(#)ls.1       6.19 (Berkeley) %G%
 .\"
 .Dd 
 .Dt LS 1
 .\"
 .Dd 
 .Dt LS 1
@@ -93,6 +93,10 @@ option, causing the sizes to be reported in kilobytes.
 (The lowercase letter ``ell.'')  List in long format. (See below.)
 If the output is to a terminal, a total sum for all the file
 sizes is output on a line before the long listing.
 (The lowercase letter ``ell.'')  List in long format. (See below.)
 If the output is to a terminal, a total sum for all the file
 sizes is output on a line before the long listing.
+.It Fl g
+Include the file flags in a long
+.Pq Fl l
+output
 .It Fl q
 Force printing of non-graphic characters in file names as
 the character `?'; this is the default when output is to a terminal.
 .It Fl q
 Force printing of non-graphic characters in file names as
 the character `?'; this is the default when output is to a terminal.
index a7edde0..cf2b820 100644 (file)
@@ -15,7 +15,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)ls.c       5.51 (Berkeley) %G%";
+static char sccsid[] = "@(#)ls.c       5.52 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -41,6 +41,7 @@ int termwidth = 80;           /* default terminal width */
 int f_accesstime;              /* use time of last access */
 int f_column;                  /* columnated format */
 int f_group;                   /* show group ownership of a file */
 int f_accesstime;              /* use time of last access */
 int f_column;                  /* columnated format */
 int f_group;                   /* show group ownership of a file */
+int f_flags;                   /* show flags associated with a file */
 int f_ignorelink;              /* indirect through symbolic link operands */
 int f_inode;                   /* print inode */
 int f_kblocks;                 /* print size in kilobytes */
 int f_ignorelink;              /* indirect through symbolic link operands */
 int f_inode;                   /* print inode */
 int f_kblocks;                 /* print size in kilobytes */
@@ -91,7 +92,7 @@ main(argc, argv)
        if (!getuid())
                f_listdot = 1;
 
        if (!getuid())
                f_listdot = 1;
 
-       while ((ch = getopt(argc, argv, "1ACFLRTacdfgiklqrstu")) != EOF) {
+       while ((ch = getopt(argc, argv, "1ACFLRTacdfgikloqrstu")) != EOF) {
                switch (ch) {
                /*
                 * -1, -C and -l all override each other
                switch (ch) {
                /*
                 * -1, -C and -l all override each other
@@ -150,6 +151,9 @@ main(argc, argv)
                case 'k':
                        f_kblocks = 1;
                        break;
                case 'k':
                        f_kblocks = 1;
                        break;
+               case 'o':
+                       f_flags = 1;
+                       break;
                case 'q':
                        f_nonprint = 1;
                        break;
                case 'q':
                        f_nonprint = 1;
                        break;
index 1600a80..3178837 100644 (file)
@@ -7,7 +7,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ls.h        5.12 (Berkeley) %G%
+ *     @(#)ls.h        5.13 (Berkeley) %G%
  */
 
 typedef struct _lsstruct {
  */
 
 typedef struct _lsstruct {
@@ -16,19 +16,26 @@ typedef struct _lsstruct {
        struct stat lstat;              /* lstat(2) for file */
 } LS;
 
        struct stat lstat;              /* lstat(2) for file */
 } LS;
 
+/*
+ * Specify maximum width of flags output. Determined from flags_from_fid
+ * routine in print.c
+ */
+#define FLAGSWIDTH 10
+
 /*
  * overload -- we probably have to save blocks and/or maxlen with the lstat
  * array, so tabdir() stuffs it into unused fields in the first stat structure.
  * If there's ever a type larger than u_long, fix this.  Any calls to qsort
  * must save and restore the values.
  */
 /*
  * overload -- we probably have to save blocks and/or maxlen with the lstat
  * array, so tabdir() stuffs it into unused fields in the first stat structure.
  * If there's ever a type larger than u_long, fix this.  Any calls to qsort
  * must save and restore the values.
  */
-#define        st_btotal       st_flags
-#define        st_maxlen       st_gen
+#define        st_btotal       st_spare1
+#define        st_maxlen       st_spare2
 
 extern int errno;
 
 extern int f_accesstime;       /* use time of last access */
 extern int f_group;            /* show group ownership of a file */
 
 extern int errno;
 
 extern int f_accesstime;       /* use time of last access */
 extern int f_group;            /* show group ownership of a file */
+extern int f_flags;            /* show flags associated with a file */
 extern int f_inode;            /* print inode */
 extern int f_kblocks;          /* print size in kilobytes */
 extern int f_longform;         /* long listing format */
 extern int f_inode;            /* print inode */
 extern int f_kblocks;          /* print size in kilobytes */
 extern int f_longform;         /* long listing format */
index ddb41c8..a6d17ec 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)print.c    5.25 (Berkeley) %G%";
+static char sccsid[] = "@(#)print.c    5.26 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -28,6 +28,7 @@ static int    printaname __P((LS *));
 static void    printlink __P((char *));
 static void    printtime __P((time_t));
 static int     printtype __P((u_int));
 static void    printlink __P((char *));
 static void    printtime __P((time_t));
 static int     printtype __P((u_int));
+static char    *flags_from_fid __P((long));
 
 void
 printscol(stats, num)
 
 void
 printscol(stats, num)
@@ -64,6 +65,9 @@ printlong(stats, num)
                if (f_group)
                        (void)printf("%-*s ", UT_NAMESIZE,
                            group_from_gid(stats->lstat.st_gid, 0));
                if (f_group)
                        (void)printf("%-*s ", UT_NAMESIZE,
                            group_from_gid(stats->lstat.st_gid, 0));
+               if (f_flags)
+                       (void)printf("%-*s ", FLAGSWIDTH,
+                           flags_from_fid(stats->lstat.st_flags));
                if (S_ISCHR(stats->lstat.st_mode) ||
                    S_ISBLK(stats->lstat.st_mode))
                        (void)printf("%3d, %3d ", major(stats->lstat.st_rdev),
                if (S_ISCHR(stats->lstat.st_mode) ||
                    S_ISBLK(stats->lstat.st_mode))
                        (void)printf("%3d, %3d ", major(stats->lstat.st_rdev),
@@ -219,3 +223,30 @@ printlink(name)
        path[lnklen] = '\0';
        (void)printf(" -> %s", path);
 }
        path[lnklen] = '\0';
        (void)printf(" -> %s", path);
 }
+
+char *
+flags_from_fid(flags)
+       long flags;
+{
+       static char buf[FLAGSWIDTH + 1];
+       int size;
+
+       size = FLAGSWIDTH;
+       buf[0] = '\0';
+       if (size && (flags & NODUMP)) {
+               strncat(buf, "nodump", size);
+               size -= 6;
+       } else {
+               strncat(buf, "dump", size);
+               size -= 4;
+       }
+       if (size && (flags & IMMUTABLE)) {
+               strncat(buf, ",nochg", size);
+               size -= 6;
+       }
+       if (size && (flags & ARCHIVED)) {
+               strncat(buf, ",arch", size);
+               size -= 5;
+       }
+       return (buf);
+}