add -m flag to override default creation mode for lost+found
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Sat, 18 Feb 1989 09:02:39 +0000 (01:02 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Sat, 18 Feb 1989 09:02:39 +0000 (01:02 -0800)
SCCS-vsn: sbin/fsck/fsck.8 6.5
SCCS-vsn: sbin/fsck/main.c 5.9
SCCS-vsn: sbin/fsck/dir.c 5.5
SCCS-vsn: sbin/fsck/fsck.h 5.8
SCCS-vsn: sbin/fsck/pass2.c 5.4

usr/src/sbin/fsck/dir.c
usr/src/sbin/fsck/fsck.8
usr/src/sbin/fsck/fsck.h
usr/src/sbin/fsck/main.c
usr/src/sbin/fsck/pass2.c

index 56dc498..1e8ce07 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)dir.c      5.4 (Berkeley) %G%";
+static char sccsid[] = "@(#)dir.c      5.5 (Berkeley) %G%";
 #endif not lint
 
 #include <sys/param.h>
 #endif not lint
 
 #include <sys/param.h>
@@ -20,6 +20,7 @@ static char sccsid[] = "@(#)dir.c     5.4 (Berkeley) %G%";
 
 char   *endpathname = &pathname[BUFSIZ - 2];
 char   *lfname = "lost+found";
 
 char   *endpathname = &pathname[BUFSIZ - 2];
 char   *lfname = "lost+found";
+int    lfmode = 01777;
 struct dirtemplate emptydir = { 0, DIRBLKSIZ };
 struct dirtemplate dirhead = { 0, 12, 1, ".", 0, DIRBLKSIZ - 12, 2, ".." };
 
 struct dirtemplate emptydir = { 0, DIRBLKSIZ };
 struct dirtemplate dirhead = { 0, 12, 1, ".", 0, DIRBLKSIZ - 12, 2, ".." };
 
@@ -311,7 +312,7 @@ linkup(orphan, pdir)
                } else {
                        pwarn("NO lost+found DIRECTORY");
                        if (preen || reply("CREATE")) {
                } else {
                        pwarn("NO lost+found DIRECTORY");
                        if (preen || reply("CREATE")) {
-                               lfdir = allocdir(ROOTINO, 0);
+                               lfdir = allocdir(ROOTINO, 0, lfmode);
                                if (lfdir != 0) {
                                        if (makeentry(ROOTINO, lfdir, lfname) != 0) {
                                                if (preen)
                                if (lfdir != 0) {
                                        if (makeentry(ROOTINO, lfdir, lfname) != 0) {
                                                if (preen)
@@ -337,7 +338,7 @@ linkup(orphan, pdir)
                if (reply("REALLOCATE") == 0)
                        return (0);
                oldlfdir = lfdir;
                if (reply("REALLOCATE") == 0)
                        return (0);
                oldlfdir = lfdir;
-               if ((lfdir = allocdir(ROOTINO, 0)) == 0) {
+               if ((lfdir = allocdir(ROOTINO, 0, lfmode)) == 0) {
                        pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n");
                        return (0);
                }
                        pfatal("SORRY. CANNOT CREATE lost+found DIRECTORY\n\n");
                        return (0);
                }
@@ -485,15 +486,16 @@ bad:
 /*
  * allocate a new directory
  */
 /*
  * allocate a new directory
  */
-allocdir(parent, request)
+allocdir(parent, request, mode)
        ino_t parent, request;
        ino_t parent, request;
+       int mode;
 {
        ino_t ino;
        char *cp;
        DINODE *dp;
        register BUFAREA *bp;
 
 {
        ino_t ino;
        char *cp;
        DINODE *dp;
        register BUFAREA *bp;
 
-       ino = allocino(request, IFDIR|0755);
+       ino = allocino(request, IFDIR|mode);
        dirhead.dot_ino = ino;
        dirhead.dotdot_ino = parent;
        dp = ginode(ino);
        dirhead.dot_ino = ino;
        dirhead.dotdot_ino = parent;
        dp = ginode(ino);
index 93d2815..399fd94 100644 (file)
@@ -2,7 +2,7 @@
 .\" All rights reserved.  The Berkeley software License Agreement
 .\" specifies the terms and conditions for redistribution.
 .\"
 .\" All rights reserved.  The Berkeley software License Agreement
 .\" specifies the terms and conditions for redistribution.
 .\"
-.\"    @(#)fsck.8      6.4 (Berkeley) %G%
+.\"    @(#)fsck.8      6.5 (Berkeley) %G%
 .\"
 .TH FSCK 8 ""
 .UC 4
 .\"
 .TH FSCK 8 ""
 .UC 4
@@ -15,6 +15,9 @@ fsck \- file system consistency check and interactive repair
 .B /etc/fsck
 .B \-p
 [
 .B /etc/fsck
 .B \-p
 [
+.B \-m
+mode
+] [
 filesystem ...
 ]
 .br
 filesystem ...
 ]
 .br
@@ -29,6 +32,9 @@ block#
 ] [
 .B \-n
 ] [
 ] [
 .B \-n
 ] [
+.B \-m
+mode
+] [
 filesystem 
 ] ...
 .SH DESCRIPTION
 filesystem 
 ] ...
 .SH DESCRIPTION
@@ -128,6 +134,14 @@ Use the block specified immediately after the flag as
 the super block for the file system.  Block 32 is usually
 an alternate super block.
 .TP 6
 the super block for the file system.  Block 32 is usually
 an alternate super block.
 .TP 6
+.B \-m
+Use the mode specified in octal immediately after the flag as the
+permission bits to use when creating the lost+found directory
+rather than the default 1777.
+In particular, systems that do not wish to have lost files accessible
+by all users on the system should use a more restrictive
+set of permissions such as 700.
+.TP 6
 .B  \-y
 Assume a yes response to all questions asked by 
 .I fsck;
 .B  \-y
 Assume a yes response to all questions asked by 
 .I fsck;
index 14a6499..0a512e5 100644 (file)
@@ -3,7 +3,7 @@
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
  * All rights reserved.  The Berkeley software License Agreement
  * specifies the terms and conditions for redistribution.
  *
- *     @(#)fsck.h      5.7 (Berkeley) %G%
+ *     @(#)fsck.h      5.8 (Berkeley) %G%
  */
 
 #define        MAXDUP          10       /* limit on dup blks (per inode) */
  */
 
 #define        MAXDUP          10       /* limit on dup blks (per inode) */
@@ -160,6 +160,7 @@ ino_t       imax;                   /* number of inodes */
 ino_t  lastino;                /* hiwater mark of inodes */
 ino_t  lfdir;                  /* lost & found directory inode number */
 char   *lfname;                /* lost & found directory name */
 ino_t  lastino;                /* hiwater mark of inodes */
 ino_t  lfdir;                  /* lost & found directory inode number */
 char   *lfname;                /* lost & found directory name */
+int    lfmode;                 /* lost & found directory creation mode */
 
 off_t  maxblk;                 /* largest logical blk in file */
 off_t  bmapsz;                 /* num chars in blockmap */
 
 off_t  maxblk;                 /* largest logical blk in file */
 off_t  bmapsz;                 /* num chars in blockmap */
index 2f8e551..ef5494d 100644 (file)
@@ -11,7 +11,7 @@ char copyright[] =
 #endif not lint
 
 #ifndef lint
 #endif not lint
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.9 (Berkeley) %G%";
 #endif not lint
 
 #include <sys/param.h>
 #endif not lint
 
 #include <sys/param.h>
@@ -21,6 +21,7 @@ static char sccsid[] = "@(#)main.c    5.8 (Berkeley) %G%";
 #include <sys/wait.h>
 #include <fstab.h>
 #include <strings.h>
 #include <sys/wait.h>
 #include <fstab.h>
 #include <strings.h>
+#include <ctype.h>
 #include "fsck.h"
 
 char   *rawname(), *unrawname(), *blockcheck();
 #include "fsck.h"
 
 char   *rawname(), *unrawname(), *blockcheck();
@@ -68,6 +69,16 @@ main(argc, argv)
                        debug++;
                        break;
 
                        debug++;
                        break;
 
+               case 'm':
+                       if (!isdigit(argv[1][0]))
+                               errexit("-m flag requires a mode\n");
+                       sscanf(*++argv, "%o", &lfmode);
+                       if (lfmode &~ 07777)
+                               errexit("bad mode to -m: %o\n", lfmode);
+                       argc--;
+                       printf("** lost+found creation mode %o\n", lfmode);
+                       break;
+
                case 'n':       /* default no answer flag */
                case 'N':
                        nflag++;
                case 'n':       /* default no answer flag */
                case 'N':
                        nflag++;
index adf7b92..8c54a6b 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)pass2.c    5.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)pass2.c    5.4 (Berkeley) %G%";
 #endif not lint
 
 #include <sys/param.h>
 #endif not lint
 
 #include <sys/param.h>
@@ -33,7 +33,7 @@ pass2()
                pfatal("ROOT INODE UNALLOCATED");
                if (reply("ALLOCATE") == 0)
                        errexit("");
                pfatal("ROOT INODE UNALLOCATED");
                if (reply("ALLOCATE") == 0)
                        errexit("");
-               if (allocdir(ROOTINO, ROOTINO) != ROOTINO)
+               if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
                        errexit("CANNOT ALLOCATE ROOT INODE\n");
                descend(&rootdesc, ROOTINO);
                break;
                        errexit("CANNOT ALLOCATE ROOT INODE\n");
                descend(&rootdesc, ROOTINO);
                break;
@@ -42,7 +42,7 @@ pass2()
                pfatal("DUPS/BAD IN ROOT INODE");
                if (reply("REALLOCATE")) {
                        freeino(ROOTINO);
                pfatal("DUPS/BAD IN ROOT INODE");
                if (reply("REALLOCATE")) {
                        freeino(ROOTINO);
-                       if (allocdir(ROOTINO, ROOTINO) != ROOTINO)
+                       if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
                                errexit("CANNOT ALLOCATE ROOT INODE\n");
                        descend(&rootdesc, ROOTINO);
                        break;
                                errexit("CANNOT ALLOCATE ROOT INODE\n");
                        descend(&rootdesc, ROOTINO);
                        break;
@@ -58,7 +58,7 @@ pass2()
                pfatal("ROOT INODE NOT DIRECTORY");
                if (reply("REALLOCATE")) {
                        freeino(ROOTINO);
                pfatal("ROOT INODE NOT DIRECTORY");
                if (reply("REALLOCATE")) {
                        freeino(ROOTINO);
-                       if (allocdir(ROOTINO, ROOTINO) != ROOTINO)
+                       if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
                                errexit("CANNOT ALLOCATE ROOT INODE\n");
                        descend(&rootdesc, ROOTINO);
                        break;
                                errexit("CANNOT ALLOCATE ROOT INODE\n");
                        descend(&rootdesc, ROOTINO);
                        break;