Date: Sun, 6 Dec 1998 12:54:16 -0500 (EST) From: Dave Chapeskie <dchapes@ddm.on.ca> To: FreeBSD-gnats-submit@FreeBSD.ORG Subject: bin/8989: (patch) chflags support for mtree(8) Message-ID: <199812061754.MAA03308@squigy.ddm.on.ca>
next in thread | raw e-mail | index | archive | help
>Number: 8989 >Category: bin >Synopsis: (patch) chflags support for mtree(8) >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sun Dec 6 10:00:00 PST 1998 >Last-Modified: >Originator: Dave Chapeskie >Organization: DDM Consulting >Release: FreeBSD 2.2.8-RELEASE i386 >Environment: >Description: Two things: 1) The mtree(8) command does not handle file flags. 2) If you use mtree(8) to generate specifications for a directory hierarchy which does not use common permissions the multiple "/set" directives can make the output difficult to look at and spot changes. For example if you are cvs(1)ing the resultant specification the diffs can be confusing and cluttered with changes unreleated to the actual permission changes. >How-To-Repeat: >Fix: The following patch adds "flags" to the list of keywords mtree(8) understands. It also adds a "-S" option which causes mtree to only output a single "/set" directive. The patch also includes appropriate changes to the man page. This patch is relative to FreeBSD-current Dec/98. But should apply cleanly to FreeBSD-stable as well. Index: Makefile =================================================================== RCS file: /cvs/FreeBSD/src/usr.sbin/mtree/Makefile,v retrieving revision 1.6 diff -u -t -r1.6 Makefile --- Makefile 1997/02/22 16:07:51 1.6 +++ Makefile 1998/12/06 17:04:37 @@ -2,9 +2,10 @@ # $Id: Makefile,v 1.6 1997/02/22 16:07:51 peter Exp $ PROG= mtree -SRCS= compare.c crc.c create.c misc.c mtree.c spec.c verify.c +SRCS= compare.c crc.c create.c misc.c mtree.c spec.c stat_flags.c verify.c MAN8= mtree.8 -.PATH: ${.CURDIR}/../../usr.bin/cksum +.PATH: ${.CURDIR}/../../usr.bin/cksum \ + ${.CURDIR}/../../bin/ls DPADD+= ${LIBMD} LDADD+= -lmd Index: compare.c =================================================================== RCS file: /cvs/FreeBSD/src/usr.sbin/mtree/compare.c,v retrieving revision 1.10 diff -u -t -r1.10 compare.c --- compare.c 1998/08/02 14:41:34 1.10 +++ compare.c 1998/12/06 17:09:26 @@ -159,6 +159,21 @@ (void)printf(")\n"); tab = "\t"; } + if (s->flags & F_FLAGS && s->st_flags != p->fts_statp->st_flags) { + LABEL; + (void)printf("%sflags (%s; ", tab, + flags_to_string(s->st_flags,"-")); + (void)printf(flags_to_string(p->fts_statp->st_flags,"-")); + if (uflag) + if (chflags(p->fts_accpath, s->st_flags)) + (void)printf(", not modified: %s)\n", + strerror(errno)); + else + (void)printf(", modified)\n"); + else + (void)printf(")\n"); + tab = "\t"; + } if (s->flags & F_NLINK && s->type != F_DIR && s->st_nlink != p->fts_statp->st_nlink) { LABEL; Index: create.c =================================================================== RCS file: /cvs/FreeBSD/src/usr.sbin/mtree/create.c,v retrieving revision 1.11 diff -u -t -r1.11 create.c --- create.c 1998/08/02 14:41:34 1.11 +++ create.c 1998/12/06 17:11:49 @@ -60,7 +60,7 @@ extern long int crc_total; extern int ftsoptions; -extern int dflag, iflag, nflag, sflag; +extern int dflag, iflag, nflag, sflag, Sflag; extern u_int keys; extern char fullpath[MAXPATHLEN]; extern int lineno; @@ -179,6 +179,9 @@ } if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode) output(indent, &offset, "mode=%#o", p->fts_statp->st_mode & MBITS); + if (keys & F_FLAGS && p->fts_statp->st_flags) + output(indent, &offset, "flags=%s", + flags_to_string(p->fts_statp->st_flags,"-")); if (keys & F_NLINK && p->fts_statp->st_nlink != 1) output(indent, &offset, "nlink=%u", p->fts_statp->st_nlink); if (keys & F_SIZE) @@ -233,6 +236,10 @@ mode_t savemode = *pmode; u_short maxgid, maxuid, maxmode, g[MAXGID], u[MAXUID], m[MAXMODE]; static int first = 1; + + /* With the S flag we only output the first /set record */ + if (Sflag && !first) + return 0; if ((p = fts_children(t, 0)) == NULL) { if (errno) Index: extern.h =================================================================== RCS file: /cvs/FreeBSD/src/usr.sbin/mtree/extern.h,v retrieving revision 1.2 diff -u -t -r1.2 extern.h --- extern.h 1997/10/01 06:30:00 1.2 +++ extern.h 1998/12/06 17:13:01 @@ -41,3 +41,6 @@ char *rlink __P((char *)); NODE *spec __P((void)); int verify __P((void)); +/* from ../../bin/ls */ +char *flags_to_string __P((u_long, char *)); +int string_to_flags __P((char **, u_long *, u_long *)); Index: misc.c =================================================================== RCS file: /cvs/FreeBSD/src/usr.sbin/mtree/misc.c,v retrieving revision 1.5 diff -u -t -r1.5 misc.c --- misc.c 1998/06/05 14:43:40 1.5 +++ misc.c 1998/12/06 17:13:28 @@ -60,6 +60,7 @@ /* NB: the following table must be sorted lexically. */ static KEY keylist[] = { {"cksum", F_CKSUM, NEEDVALUE}, + {"flags", F_FLAGS, NEEDVALUE}, {"gid", F_GID, NEEDVALUE}, {"gname", F_GNAME, NEEDVALUE}, {"ignore", F_IGN, 0}, Index: mtree.8 =================================================================== RCS file: /cvs/FreeBSD/src/usr.sbin/mtree/mtree.8,v retrieving revision 1.13 diff -u -t -r1.13 mtree.8 --- mtree.8 1998/06/10 06:45:08 1.13 +++ mtree.8 1998/12/06 17:15:34 @@ -40,7 +40,7 @@ .Nd map a directory hierarchy .Sh SYNOPSIS .Nm mtree -.Op Fl cdeinrUux +.Op Fl cdeinrSUux .Op Fl f Ar spec .Op Fl K Ar keywords .Op Fl k Ar keywords @@ -97,6 +97,8 @@ .It Fl r Remove any files in the file hierarchy that are not described in the specification. +.It Fl S +Only emit a single initial /set statement. .It Fl s Ar seed Display a single checksum to the standard error output that represents all of the files for which the keyword @@ -104,7 +106,7 @@ was specified. The checksum is seeded with the specified value. .It Fl U -Modify the owner, group, and permissions of existing files to match +Modify the owner, group, permissions, and flags of existing files to match the specification and create any missing directories. User, group, and permissions must all be specified for missing directories to be created. @@ -133,6 +135,8 @@ utility. .It Cm ignore Ignore any file hierarchy below this file. +.It Cm flags +The current file's flags as a symbolic value. .It Cm gid The file group as a numeric value. .It Cm gname @@ -274,6 +278,7 @@ .Sh SEE ALSO .Xr chgrp 1 , .Xr chmod 1 , +.Xr chflags 1 , .Xr cksum 1 , .Xr md5 1 , .Xr stat 2 , Index: mtree.c =================================================================== RCS file: /cvs/FreeBSD/src/usr.sbin/mtree/mtree.c,v retrieving revision 1.7 diff -u -t -r1.7 mtree.c --- mtree.c 1998/06/05 14:43:41 1.7 +++ mtree.c 1998/12/06 17:16:36 @@ -58,7 +58,7 @@ extern long int crc_total; int ftsoptions = FTS_LOGICAL; -int cflag, dflag, eflag, iflag, nflag, rflag, sflag, uflag, Uflag; +int cflag, dflag, eflag, iflag, nflag, rflag, sflag, Sflag, uflag, Uflag; u_int keys; char fullpath[MAXPATHLEN]; @@ -75,7 +75,7 @@ dir = NULL; keys = KEYDEFAULT; - while ((ch = getopt(argc, argv, "cdef:iK:k:np:rs:Uux")) != -1) + while ((ch = getopt(argc, argv, "cdef:iK:k:np:rSs:Uux")) != -1) switch((char)ch) { case 'c': cflag = 1; @@ -112,6 +112,9 @@ break; case 'r': rflag = 1; + break; + case 'S': + Sflag = 1; break; case 's': sflag = 1; Index: mtree.h =================================================================== RCS file: /cvs/FreeBSD/src/usr.sbin/mtree/mtree.h,v retrieving revision 1.3 diff -u -t -r1.3 mtree.h --- mtree.h 1998/06/05 14:43:42 1.3 +++ mtree.h 1998/12/06 17:17:33 @@ -53,6 +53,7 @@ gid_t st_gid; /* gid */ #define MBITS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) mode_t st_mode; /* mode */ + u_long st_flags; /* flags */ nlink_t st_nlink; /* link count */ #define F_CKSUM 0x0001 /* check sum */ @@ -62,6 +63,7 @@ #define F_IGN 0x0010 /* ignore */ #define F_MAGIC 0x0020 /* name has magic chars */ #define F_MODE 0x0040 /* mode */ +#define F_FLAGS 0x20000 /* flags */ #define F_NLINK 0x0080 /* number of links */ #define F_SIZE 0x0100 /* size */ #define F_SLINK 0x0200 /* link count */ Index: spec.c =================================================================== RCS file: /cvs/FreeBSD/src/usr.sbin/mtree/spec.c,v retrieving revision 1.7 diff -u -t -r1.7 spec.c --- spec.c 1997/10/01 06:30:02 1.7 +++ spec.c 1998/12/06 17:20:31 @@ -174,6 +174,8 @@ struct group *gr; struct passwd *pw; mode_t *m; + char *flags; + u_long set_flags, clr_flags; int value; char *ep; @@ -212,6 +214,17 @@ errx(1, "line %d: invalid file mode %s", lineno, val); ip->st_mode = getmode(m, 0); + break; + case F_FLAGS: + flags = val; + if (flags[0]=='-' && flags[1]=='\0') { + ip->st_flags = 0; + break; + } + if (string_to_flags(&flags, &set_flags, &clr_flags)) + errx(1, "line %d: invalid file flag %s", + lineno, flags); + ip->st_flags = set_flags & (~clr_flags); break; case F_NLINK: ip->st_nlink = strtoul(val, &ep, 10); >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199812061754.MAA03308>