Date: Fri, 7 Dec 2001 18:40:23 +0100 From: Roman Neuhauser <neuhauser@mobil.cz> To: Anthony Atkielski <anthony@freebie.atkielski.com> Cc: FreeBSD Questions <freebsd-questions@freebsd.org> Subject: Re: Modifying only certain bits with chmod Message-ID: <20011207184023.E19927@roman.mobil.cz> In-Reply-To: <004a01c17eb2$43d07d20$0a00000a@atkielski.com> References: <001601c17e7c$9a391040$0a00000a@atkielski.com> <20011206200848.A12197@roman.mobil.cz> <004a01c17eb2$43d07d20$0a00000a@atkielski.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--dc+cDN39EJAMEtIO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline > From: "Anthony Atkielski" <anthony@freebie.atkielski.com> > To: "Roman Neuhauser" <neuhauser@mobil.cz> > Cc: "FreeBSD Questions" <freebsd-questions@freebsd.org> > Subject: Re: Modifying only certain bits with chmod > Date: Fri, 7 Dec 2001 01:01:04 +0100 > > ----- Original Message ----- > From: "Roman Neuhauser" <neuhauser@mobil.cz> > To: "Anthony Atkielski" <anthony@freebie.atkielski.com> > Cc: "FreeBSD Questions" <freebsd-questions@freebsd.org> > Sent: Thursday, December 06, 2001 20:08 > Subject: Re: Modifying only certain bits with chmod > > > > > From: "Anthony Atkielski" <anthony@freebie.atkielski.com> > > > To: "FreeBSD Questions" <freebsd-questions@freebsd.org> > > > Subject: Re: Modifying only certain bits with chmod > > > Date: Thu, 6 Dec 2001 18:36:56 +0100 > > > > > > Roman writes: > > > > > > > I'm not that old, have been using FreeBSD for a couple of months > > > > only, and yet I terribly miss an option that would make ls(1) > > > > display perms in octal. > > > > > > Done. Shall I send you the modified source? I added a -p option (one > of > > > the few letters available!) which prints the file modes in octal instead > of > > > as the usual -rw-r--r-- strings if you also specify the long format for > > > output (-l). I've not exhaustively tested it but it seems to work okay > > > (it's a simple change). > > > > I prefer unified diffs (diff -u), but anything will do. > > > > And thanks! > > Hmm ... I'm not sure how to make unified diffs (?). I did manage to create > a tarball, I think. You can find the ls and chmod tweaks in > > ftp://ftp.atkielski.com/pub/custom Unified diffs are (as I suggested in my previous email) created with "diff -u". I extracted the tarball into /usr/src/bin and did (after some tweaks) roman@roman ...src/bin > diff -u ls/ nls/ >~/ls-octal.diff See the result (this is FreeBSD 4.4-STABLE #0: Tue Oct 9 15:41:28 CEST 2001) attached. My changes: Makefile, and the (name of) the man page. -- FreeBSD 4.4-STABLE 6:30PM up 45 days, 5:13, 13 users, load averages: 0.10, 0.10, 0.08 --dc+cDN39EJAMEtIO Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ls-octal.diff" diff -u ls/Makefile nls/Makefile --- ls/Makefile Tue Jul 4 20:45:27 2000 +++ nls/Makefile Fri Dec 7 18:12:28 2001 @@ -2,7 +2,7 @@ # $FreeBSD: src/bin/ls/Makefile,v 1.9.2.2 2000/07/04 18:45:27 ache Exp $ -PROG= ls +PROG= nls SRCS= cmp.c ls.c print.c util.c .if !defined(RELEASE_BUILD_FIXIT) Only in ls: ls.1 diff -u ls/ls.c nls/ls.c --- ls/ls.c Wed Aug 16 21:57:11 2000 +++ nls/ls.c Thu Dec 6 18:10:23 2001 @@ -113,6 +113,7 @@ int f_timesort; /* sort by time vice name */ int f_type; /* add type character for non-regular files */ int f_whiteout; /* show whiteout entries */ +int f_octperms; /* display permissions in octal, too */ #ifdef COLORLS int f_color; /* add type in color for non-regular files */ @@ -163,7 +164,7 @@ f_listdot = 1; fts_options = FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "1ABCFGHLPRTWabcdfgiklnoqrstu")) != -1) { + while ((ch = getopt(argc, argv, "1ABCFGHLPRTWabcdfgiklnopqrstu")) != -1) { switch (ch) { /* * The -1, -C and -l options all override each other so shell @@ -243,6 +244,9 @@ break; case 'o': f_flags = 1; + break; + case 'p': + f_octperms = 1; break; case 'q': f_nonprint = 1; diff -u ls/ls.h nls/ls.h --- ls/ls.h Wed Jul 12 08:19:14 2000 +++ nls/ls.h Thu Dec 6 18:10:23 2001 @@ -54,6 +54,7 @@ extern int f_statustime; /* use time of last mode change */ extern int f_notabs; /* don't use tab-separated multi-col output */ extern int f_type; /* add type character for non-regular files */ +extern int f_octperms; /* flag to show perms in octal */ #ifdef COLORLS extern int f_color; /* add type in color for non-regular files */ #endif Only in nls: nls.1 diff -u ls/print.c nls/print.c --- ls/print.c Wed Jul 12 08:19:14 2000 +++ nls/print.c Thu Dec 6 18:24:02 2001 @@ -75,6 +75,7 @@ #endif #define IS_NOPRINT(p) ((p)->fts_number == NO_PRINT) +#define MODEBUFSIZ 20 /* size of buffer to hold mode field */ #ifdef COLORLS /* Most of these are taken from <sys/stat.h> */ @@ -127,6 +128,27 @@ return printf("%s", name); } +/* convert mode field to octal */ +/* code below assumes buffer is at least 5 characters long, and that mode does not exceed 12 bits in size */ + +void +modeoct(inmode,buf) + mode_t inmode; + char *buf; +{ + mode_t workmode; + int scount; + char *wp; + + wp = buf+4; + *wp-- = '\0'; /* flag end of this string */ + for (workmode = inmode, scount=4; scount>0; scount--, wp--) + { + *wp = '0'+(workmode & 7); + workmode >>=3; + } +} + void printlong(dp) DISPLAY *dp; @@ -134,7 +156,7 @@ struct stat *sp; FTSENT *p; NAMES *np; - char buf[20]; + char buf[MODEBUFSIZ]; #ifdef COLORLS int color_printed = 0; #endif @@ -151,7 +173,10 @@ if (f_size) (void)printf("%*qd ", dp->s_block, howmany(sp->st_blocks, blocksize)); - (void)strmode(sp->st_mode, buf); + if (!f_octperms) + (void)strmode(sp->st_mode, buf); + else + modeoct(sp->st_mode, buf); np = p->fts_pointer; (void)printf("%s %*u %-*s %-*s ", buf, dp->s_nlink, sp->st_nlink, dp->s_user, np->user, dp->s_group, diff -u ls/util.c nls/util.c --- ls/util.c Mon Aug 7 10:05:08 2000 +++ nls/util.c Thu Dec 6 18:10:23 2001 @@ -162,9 +162,9 @@ { (void)fprintf(stderr, #ifdef COLORLS - "usage: ls [-ABCFGHLPRTWabcdfgiklnoqrstu1]" + "usage: ls [-ABCFGHLPRTWabcdfgiklnopqrstu1]" #else - "usage: ls [-ABCFHLPRTWabcdfgiklnoqrstu1]" + "usage: ls [-ABCFHLPRTWabcdfgiklnopqrstu1]" #endif " [file ...]\n"); exit(1); --dc+cDN39EJAMEtIO-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011207184023.E19927>
