Index: src/distrib/sets/lists/tests/mi =================================================================== RCS file: /home/chs/netbsd/cvs/src/distrib/sets/lists/tests/mi,v retrieving revision 1.1207 diff -u -p -r1.1207 mi --- src/distrib/sets/lists/tests/mi 23 May 2022 22:33:56 -0000 1.1207 +++ src/distrib/sets/lists/tests/mi 24 May 2022 02:21:34 -0000 @@ -4338,6 +4338,7 @@ ./usr/tests/sbin/fsck_ffs/Atffile tests-sbin-tests compattestfile,atf ./usr/tests/sbin/fsck_ffs/Kyuafile tests-sbin-tests compattestfile,atf,kyua ./usr/tests/sbin/fsck_ffs/t_check_quotas tests-sbin-tests compattestfile,atf +./usr/tests/sbin/fsck_ffs/t_enable_extattr tests-sbin-tests compattestfile,atf ./usr/tests/sbin/fsck_ffs/t_enable_quotas tests-sbin-tests compattestfile,atf ./usr/tests/sbin/gpt tests-sbin-tests compattestfile,atf ./usr/tests/sbin/gpt/Atffile tests-sbin-tests compattestfile,atf Index: src/sbin/badsect/badsect.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/badsect/badsect.c,v retrieving revision 1.34 diff -u -p -r1.34 badsect.c --- src/sbin/badsect/badsect.c 5 Sep 2016 01:09:57 -0000 1.34 +++ src/sbin/badsect/badsect.c 24 May 2022 02:21:34 -0000 @@ -151,11 +151,13 @@ main(int argc, char *argv[]) rdfs(sblock_try[i], SBLOCKSIZE, fs); switch (fs->fs_magic) { case FS_UFS2_MAGIC: + case FS_UFS2EA_MAGIC: is_ufs2 = 1; /* FALLTHROUGH */ case FS_UFS1_MAGIC: break; case FS_UFS2_MAGIC_SWAPPED: + case FS_UFS2EA_MAGIC_SWAPPED: is_ufs2 = 1; /* FALLTHROUGH */ case FS_UFS1_MAGIC_SWAPPED: Index: src/sbin/cgdconfig/cgdconfig.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/cgdconfig/cgdconfig.c,v retrieving revision 1.53 diff -u -p -r1.53 cgdconfig.c --- src/sbin/cgdconfig/cgdconfig.c 22 Nov 2021 14:34:35 -0000 1.53 +++ src/sbin/cgdconfig/cgdconfig.c 24 May 2022 02:21:34 -0000 @@ -1015,8 +1015,10 @@ verify_ffs(int fd) switch (u.fs.fs_magic) { case FS_UFS1_MAGIC: case FS_UFS2_MAGIC: + case FS_UFS2EA_MAGIC: case FS_UFS1_MAGIC_SWAPPED: case FS_UFS2_MAGIC_SWAPPED: + case FS_UFS2EA_MAGIC_SWAPPED: return 0; default: continue; Index: src/sbin/clri/clri.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/clri/clri.c,v retrieving revision 1.24 diff -u -p -r1.24 clri.c --- src/sbin/clri/clri.c 30 Aug 2015 05:23:17 -0000 1.24 +++ src/sbin/clri/clri.c 24 May 2022 02:21:34 -0000 @@ -107,11 +107,13 @@ main(int argc, char *argv[]) sbp = (struct fs *)sblock; switch(sbp->fs_magic) { case FS_UFS2_MAGIC: + case FS_UFS2EA_MAGIC: is_ufs2 = 1; /*FALLTHROUGH*/ case FS_UFS1_MAGIC: break; case FS_UFS2_MAGIC_SWAPPED: + case FS_UFS2EA_MAGIC_SWAPPED: is_ufs2 = 1; /*FALLTHROUGH*/ case FS_UFS1_MAGIC_SWAPPED: Index: src/sbin/dump/ffs_inode.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/dump/ffs_inode.c,v retrieving revision 1.23 diff -u -p -r1.23 ffs_inode.c --- src/sbin/dump/ffs_inode.c 1 Mar 2019 16:42:11 -0000 1.23 +++ src/sbin/dump/ffs_inode.c 24 May 2022 02:21:34 -0000 @@ -83,11 +83,17 @@ fs_read_sblock(char *superblock) rawread(sblock_try[i], (char *)superblock, MAXBSIZE); switch(sblock->fs_magic) { + case FS_UFS2EA_MAGIC: + sblock->fs_magic = FS_UFS2_MAGIC; + /*FALLTHROUGH*/ case FS_UFS2_MAGIC: is_ufs2 = 1; /*FALLTHROUGH*/ case FS_UFS1_MAGIC: break; + case FS_UFS2EA_MAGIC_SWAPPED: + sblock->fs_magic = FS_UFS2_MAGIC_SWAPPED; + /*FALLTHROUGH*/ case FS_UFS2_MAGIC_SWAPPED: is_ufs2 = 1; /*FALLTHROUGH*/ Index: src/sbin/fsck_ffs/fsck.h =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsck_ffs/fsck.h,v retrieving revision 1.55 diff -u -p -r1.55 fsck.h --- src/sbin/fsck_ffs/fsck.h 18 Apr 2020 12:54:38 -0000 1.55 +++ src/sbin/fsck_ffs/fsck.h 24 May 2022 02:21:34 -0000 @@ -278,8 +278,10 @@ extern int bflag; /* location of altern extern int debug; /* output debugging info */ extern int zflag; /* zero unused directory space */ extern int cvtlevel; /* convert to newer file system format */ +extern int eaflag; /* fs is UFS2ea */ extern int doinglevel1; /* converting to new cylinder group format */ extern int doinglevel2; /* converting to new inode format */ +extern int doing2ea; /* converting UFS2 to UFS2ea */ extern int newinofmt; /* filesystem has new inode format */ extern char usedsoftdep; /* just fix soft dependency inconsistencies */ extern int preen; /* just fix normal inconsistencies */ @@ -294,6 +296,7 @@ extern int fsreadfd; /* file descriptor extern int fswritefd; /* file descriptor for writing file system */ extern int rerun; /* rerun fsck. Only used in non-preen mode */ extern char resolved; /* cleared if unresolved changes => not clean */ +extern int extattr_supported; /* file system image supports extattrs */ #ifndef NO_FFS_EI extern int endian; /* endian coversion */ Index: src/sbin/fsck_ffs/fsck_ffs.8 =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsck_ffs/fsck_ffs.8,v retrieving revision 1.51 diff -u -p -r1.51 fsck_ffs.8 --- src/sbin/fsck_ffs/fsck_ffs.8 5 May 2019 14:59:06 -0000 1.51 +++ src/sbin/fsck_ffs/fsck_ffs.8 24 May 2022 02:21:34 -0000 @@ -205,7 +205,13 @@ option to .Xr newfs 8 . .El .Pp -Note that FFSv2 file systems are always level 4. +Note that FFSv2 file systems always have the features of FFSv1 level 4. +.Pp +FFSv2 file systems have separate conversion options: +.Bl -tag -width 3n -offset indent +.It ea +Enable support for extended attributes (and access control lists). +.El .Pp In interactive mode, .Nm @@ -227,6 +233,7 @@ in the second line) and the file system level .Dq ( fslevel in the sixth line). +.Pp .It Fl d Print debugging output. .It Fl F Index: src/sbin/fsck_ffs/main.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsck_ffs/main.c,v retrieving revision 1.89 diff -u -p -r1.89 main.c --- src/sbin/fsck_ffs/main.c 6 Apr 2020 09:54:24 -0000 1.89 +++ src/sbin/fsck_ffs/main.c 24 May 2022 02:21:34 -0000 @@ -100,8 +100,10 @@ int bflag; int debug; int zflag; int cvtlevel; +int eaflag; int doinglevel1; int doinglevel2; +int doing2ea; int newinofmt; char usedsoftdep; int preen; @@ -115,6 +117,7 @@ int fsreadfd; int fswritefd; int rerun; char resolved; +int extattr_supported; #ifndef NO_FFS_EI int endian; int doswap; @@ -194,6 +197,10 @@ main(int argc, char *argv[]) case 'c': skipclean = 0; + if (strcmp(optarg, "ea") == 0) { + doing2ea = 1; + break; + } cvtlevel = argtoi('c', "conversion level", optarg, 10); if (cvtlevel > 4) { cvtlevel = 4; Index: src/sbin/fsck_ffs/pass1.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsck_ffs/pass1.c,v retrieving revision 1.59 diff -u -p -r1.59 pass1.c --- src/sbin/fsck_ffs/pass1.c 19 Apr 2020 19:37:06 -0000 1.59 +++ src/sbin/fsck_ffs/pass1.c 24 May 2022 02:21:34 -0000 @@ -423,7 +423,7 @@ checkinode(ino_t inumber, struct inodesc else idesc->id_type = ADDR; (void)ckinode(dp, idesc); - if (is_ufs2 && iswap32(dp->dp2.di_extsize) > 0) { + if (is_ufs2 && extattr_supported && iswap32(dp->dp2.di_extsize) > 0) { int ret, offset; idesc->id_type = ADDR; ndb = howmany(iswap32(dp->dp2.di_extsize), sblock->fs_bsize); @@ -441,7 +441,24 @@ checkinode(ino_t inumber, struct inodesc if (ret & STOP) break; } + } else if (is_ufs2 && doing2ea && + (iswap32(dp->dp2.di_extsize) != 0 || + iswap64(dp->dp2.di_extb[0]) != 0 || + iswap64(dp->dp2.di_extb[1]) != 0)) { + if (preen) + pwarn("CLEARING EXTATTR FIELDS, SETTING PERMS TO 0\n"); + else if (!reply("CLEAR EXTATTR FIELDS, SET PERMS TO 0")) { + markclean = 0; + return; + } + dp = ginode(inumber); + dp->dp2.di_extsize = iswap32(0); + dp->dp2.di_extb[0] = iswap64(0); + dp->dp2.di_extb[1] = iswap64(0); + dp->dp2.di_mode &= ~0777; + inodirty(); } + idesc->id_entryno *= btodb(sblock->fs_fsize); if (is_ufs2) blocks = iswap64(dp->dp2.di_blocks); Index: src/sbin/fsck_ffs/pass5.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsck_ffs/pass5.c,v retrieving revision 1.54 diff -u -p -r1.54 pass5.c --- src/sbin/fsck_ffs/pass5.c 23 Jun 2013 22:03:34 -0000 1.54 +++ src/sbin/fsck_ffs/pass5.c 24 May 2022 02:21:34 -0000 @@ -242,6 +242,14 @@ pass5(void) sblock->fs_sbsize); if (needswap) ffs_sb_swap(asblk.b_un.b_fs, altsblock); + switch (altsblock->fs_magic) { + case FS_UFS2EA_MAGIC: + altsblock->fs_magic = FS_UFS2_MAGIC; + break; + case FS_UFS2EA_MAGIC_SWAPPED: + altsblock->fs_magic = FS_UFS2_MAGIC_SWAPPED; + break; + } } sb_oldfscompat_write(sblock, sblocksave); if ((asblk.b_errs || cmpsblks(sblock, altsblock)) && Index: src/sbin/fsck_ffs/setup.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsck_ffs/setup.c,v retrieving revision 1.103 diff -u -p -r1.103 setup.c --- src/sbin/fsck_ffs/setup.c 17 Apr 2020 09:42:27 -0000 1.103 +++ src/sbin/fsck_ffs/setup.c 24 May 2022 02:21:34 -0000 @@ -718,6 +718,16 @@ detect_byteorder(struct fs *fs, int sblo fs->fs_magic == FS_UFS1_MAGIC_SWAPPED)) /* Likely to be the first alternate of a fs with 64k blocks */ return -1; + if (fs->fs_magic == FS_UFS2EA_MAGIC) { + eaflag = 1; + extattr_supported = 1; + fs->fs_magic = FS_UFS2_MAGIC; + } + if (fs->fs_magic == FS_UFS2EA_MAGIC_SWAPPED) { + eaflag = 1; + extattr_supported = 1; + fs->fs_magic = FS_UFS2_MAGIC_SWAPPED; + } if (fs->fs_magic == FS_UFS1_MAGIC || fs->fs_magic == FS_UFS2_MAGIC) { #ifndef NO_FFS_EI if (endian == 0 || BYTE_ORDER == endian) { @@ -845,6 +855,14 @@ readsb(int listerr) memmove(altsblock, asblk.b_un.b_fs, sblock->fs_sbsize); if (needswap) ffs_sb_swap(asblk.b_un.b_fs, altsblock); + switch (altsblock->fs_magic) { + case FS_UFS2EA_MAGIC: + altsblock->fs_magic = FS_UFS2_MAGIC; + break; + case FS_UFS2EA_MAGIC_SWAPPED: + altsblock->fs_magic = FS_UFS2_MAGIC_SWAPPED; + break; + } if (cmpsblks(sblock, altsblock)) { if (debug) { uint32_t *nlp, *olp, *endlp; Index: src/sbin/fsck_ffs/utilities.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsck_ffs/utilities.c,v retrieving revision 1.66 diff -u -p -r1.66 utilities.c --- src/sbin/fsck_ffs/utilities.c 17 Apr 2020 09:42:27 -0000 1.66 +++ src/sbin/fsck_ffs/utilities.c 24 May 2022 02:21:34 -0000 @@ -224,6 +224,9 @@ flush(int fd, struct bufarea *bp) { int i, j; struct csum *ccsp; + struct fs *fs; + uint32_t savemagic; + daddr_t bno; if (!bp->b_dirty) return; @@ -233,9 +236,21 @@ flush(int fd, struct bufarea *bp) (long long)bp->b_bno); bp->b_dirty = 0; bp->b_errs = 0; + fs = (struct fs *)bp->b_un.b_buf; + savemagic = fs->fs_magic; + if (bp == &sblk && (eaflag || doing2ea)) { + fs->fs_magic = needswap ? FS_UFS2EA_MAGIC_SWAPPED : FS_UFS2EA_MAGIC; + if (doing2ea) { + for (i = 0; i < fs->fs_ncg; i++) { + bno = FFS_FSBTODB(fs, cgsblock(fs, i)); + bwrite(fd, bp->b_un.b_buf, bno, (long)bp->b_size); + } + } + } bwrite(fd, bp->b_un.b_buf, bp->b_bno, (long)bp->b_size); if (bp != &sblk) return; + fs->fs_magic = savemagic; for (i = 0, j = 0; i < sblock->fs_cssize; i += sblock->fs_bsize, j++) { int size = sblock->fs_cssize - i < sblock->fs_bsize ? sblock->fs_cssize - i : sblock->fs_bsize; @@ -324,6 +339,12 @@ ckfini(int noint) "\n***** FILE SYSTEM MARKED CLEAN *****\n"); } } + if (doing2ea) { + printf("ENABLING EXTATTR SUPPORT\n"); + eaflag = 1; + sbdirty(); + flush(fswritefd, &sblk); + } if (debug) printf("cache missed %ld of %ld (%d%%)\n", diskreads, totalreads, (int)(diskreads * 100 / totalreads)); Index: src/sbin/fsdb/fsdb.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsdb/fsdb.c,v retrieving revision 1.52 diff -u -p -r1.52 fsdb.c --- src/sbin/fsdb/fsdb.c 29 May 2021 16:51:25 -0000 1.52 +++ src/sbin/fsdb/fsdb.c 24 May 2022 02:21:34 -0000 @@ -51,6 +51,7 @@ __RCSID("$NetBSD: fsdb.c,v 1.52 2021/05/ #include #include #include +#include #include #include @@ -91,8 +92,10 @@ int bflag; int debug; int zflag; int cvtlevel; +int eaflag; int doinglevel1; int doinglevel2; +int doing2ea; int newinofmt; char usedsoftdep; int preen; @@ -106,6 +109,8 @@ int fsreadfd; int fswritefd; int rerun; char resolved; +int extattr_supported; + int endian; int doswap; int needswap; @@ -160,7 +165,7 @@ ino_t curinum; static void usage(void) { - errx(1, "usage: %s [-dFn] -f ", getprogname()); + errx(1, "usage: %s [-dfFn] ", getprogname()); } /* * We suck in lots of fsck code, and just pick & choose the stuff we want. @@ -173,11 +178,12 @@ main(int argc, char *argv[]) { int ch, rval; char *fsys = NULL; + bool makedirty = true; forceimage = 0; debug = 0; isappleufs = 0; - while ((ch = getopt(argc, argv, "dFf:n")) != -1) { + while ((ch = getopt(argc, argv, "dFf:nN")) != -1) { switch (ch) { case 'd': debug++; @@ -186,37 +192,48 @@ main(int argc, char *argv[]) forceimage = 1; break; case 'f': - fsys = optarg; break; case 'n': nflag++; break; + case 'N': + makedirty = false; + break; default: usage(); } } - if (fsys == NULL) + argc -= optind; + argv += optind; + if (argc != 1) usage(); + else + fsys = argv[0]; + endian = 0; if (setup(fsys, fsys) <= 0) errx(1, "cannot set up file system `%s'", fsys); printf("Editing file system `%s'\nLast Mounted on %s\n", fsys, sblock->fs_fsmnt); rval = cmdloop(); - if (nflag) - exit(rval); - sblock->fs_clean = 0; /* mark it dirty */ - sbdirty(); - markclean = 0; - ckfini(1); - printf("*** FILE SYSTEM MARKED DIRTY\n"); - printf("*** BE SURE TO RUN FSCK TO CLEAN UP ANY DAMAGE\n"); - printf("*** IF IT WAS MOUNTED, RE-MOUNT WITH -u -o reload\n"); + if (!nflag && makedirty) { + sblock->fs_clean = 0; /* mark it dirty */ + sbdirty(); + markclean = 0; + ckfini(1); + printf("*** FILE SYSTEM MARKED DIRTY\n"); + printf("*** BE SURE TO RUN FSCK TO CLEAN UP ANY DAMAGE\n"); + printf("*** IF IT WAS MOUNTED, RE-MOUNT WITH -u -o reload\n"); + } else if (!nflag) { + ckfini(1); + } exit(rval); } #define CMDFUNC(func) static int func (int argc, char *argv[]) +#define CMDFUNCSTART(x) CMDFUNC(x) + CMDFUNC(helpfn); CMDFUNC(focus); /* focus on inode */ CMDFUNC(active); /* print active inode */ @@ -245,6 +262,14 @@ CMDFUNC(chatime); /* Change atime */ CMDFUNC(chbirthtime); /* Change birthtime */ CMDFUNC(chinum); /* Change inode # of dirent */ CMDFUNC(chname); /* Change dirname of dirent */ +CMDFUNC(chextsize); /* Change extsize */ +CMDFUNC(chblocks); /* Change blocks */ +CMDFUNC(chdb); /* Change direct block pointer */ +CMDFUNC(chib); /* Change indirect block pointer */ +CMDFUNC(chextb); /* Change extattr block pointer */ +CMDFUNC(chfreelink); /* Change freelink pointer */ +CMDFUNC(iptrs); /* print raw block pointers for active inode */ +CMDFUNC(saveea); /* Save extattrs */ static struct cmdtable cmds[] = { {"help", "Print out help", 1, 1, helpfn}, @@ -261,7 +286,7 @@ static struct cmdtable cmds[] = { {"linkcount", "Set link count to COUNT", 2, 2, linkcount}, {"ls", "List current inode as directory", 1, 1, ls}, {"blks", "List current inode's data blocks", 1, 1, blks}, - {"saveblks", "Save current inode's data blocks", 2, 2, blks}, + {"saveblks", "Save current inode's data blocks to FILE", 2, 2, blks}, {"findblk", "Find inode owning disk block(s)", 2, 33, findblk}, {"rm", "Remove NAME from current inode directory", 2, 2, rm}, {"del", "Remove NAME from current inode directory", 2, 2, rm}, @@ -276,11 +301,21 @@ static struct cmdtable cmds[] = { {"chflags", "Change flags of current inode to FLAGS", 2, 2, chaflags}, {"chgen", "Change generation number of current inode to GEN", 2, 2, chgen}, + + { "chextsize", "Change extsize of current inode to EXTSIZE", 2, 2, chextsize }, + { "chblocks", "Change blocks of current inode to BLOCKS", 2, 2, chblocks }, + { "chdb", "Change db pointer N of current inode to BLKNO", 3, 3, chdb }, + { "chib", "Change ib pointer N of current inode to BLKNO", 3, 3, chib }, + { "chextb", "Change extb pointer N of current inode to BLKNO", 3, 3, chextb }, + { "chfreelink", "Change freelink of current inode to FREELINK", 2, 2, chfreelink }, + { "iptrs", "Print raw block pointers of current inode", 1, 1, iptrs }, + {"mtime", "Change mtime of current inode to MTIME", 2, 2, chmtime}, {"ctime", "Change ctime of current inode to CTIME", 2, 2, chctime}, {"atime", "Change atime of current inode to ATIME", 2, 2, chatime}, {"birthtime", "Change atime of current inode to BIRTHTIME", 2, 2, chbirthtime}, + {"saveea", "Save current inode's extattr blocks to FILE", 2, 2, saveea}, {"quit", "Exit", 1, 1, quit}, {"q", "Exit", 1, 1, quit}, {"exit", "Exit", 1, 1, quit}, @@ -524,16 +559,22 @@ CMDFUNC(ls) CMDFUNC(blks) { uint64_t blkno = 0; - int i, type; + uint64_t size; + int i; struct wrinfo wrinfo, *wrp = NULL; + bool saveblks; - if (strcmp(argv[0], "saveblks") == 0) { + saveblks = strcmp(argv[0], "saveblks") == 0; + if (saveblks) { wrinfo.fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0644); if (wrinfo.fd == -1) { warn("unable to create file %s", argv[1]); return 0; } - wrinfo.size = DIP(curinode, size); + if (is_ufs2) + wrinfo.size = iswap64(DIP(curinode, size)); + else + wrinfo.size = iswap32(DIP(curinode, size)); wrinfo.written_size = 0; wrp = &wrinfo; } @@ -541,12 +582,6 @@ CMDFUNC(blks) warnx("no current inode"); return 0; } - type = iswap16(DIP(curinode, mode)) & IFMT; - if (type != IFDIR && type != IFREG) { - warnx("inode %llu not a file or directory", - (unsigned long long)curinum); - return 0; - } if (is_ufs2) { printf("I=%llu %lld blocks\n", (unsigned long long)curinum, (long long)(iswap64(curinode->dp2.di_blocks))); @@ -555,15 +590,24 @@ CMDFUNC(blks) iswap32(curinode->dp1.di_blocks)); } printf("Direct blocks:\n"); - if (is_ufs2) - print_blks64(curinode->dp2.di_db, UFS_NDADDR, &blkno, wrp); - else - print_blks32(curinode->dp1.di_db, UFS_NDADDR, &blkno, wrp); - + if (is_ufs2) { + size = iswap64(DIP(curinode, size)); + if (size > sizeof(int64_t) * UFS_NDADDR) + print_blks64(curinode->dp2.di_db, UFS_NDADDR, &blkno, wrp); + } else { + size = iswap32(DIP(curinode, size)); + if (size > sizeof(int32_t) * UFS_NDADDR) + print_blks32(curinode->dp1.di_db, UFS_NDADDR, &blkno, wrp); + } if (is_ufs2) { for (i = 0; i < UFS_NIADDR; i++) print_indirblks64(iswap64(curinode->dp2.di_ib[i]), i, &blkno, wrp); + printf("Extattr blocks:\n"); + blkno = 0; + if (saveblks) + wrinfo.size += iswap32(curinode->dp2.di_extsize); + print_blks64(curinode->dp2.di_extb, UFS_NXADDR, &blkno, wrp); } else { for (i = 0; i < UFS_NIADDR; i++) print_indirblks32(iswap32(curinode->dp1.di_ib[i]), i, @@ -644,7 +688,9 @@ CMDFUNC(findblk) break; case IFLNK: { - uint64_t size = iswap64(DIP(curinode, size)); + uint64_t size = is_ufs2 ? + iswap64(DIP(curinode, size)) : + iswap32(DIP(curinode, size)); if (size > 0 && size < (uint64_t)sblock->fs_maxsymlinklen && DIP(curinode, blocks) == 0) @@ -827,7 +873,7 @@ static int writefileblk(struct wrinfo *wrp, uint64_t blk) { char buf[MAXBSIZE]; - long long size; + long long size, rsize; size = wrp->size - wrp->written_size; if (size > sblock->fs_bsize) @@ -837,7 +883,8 @@ writefileblk(struct wrinfo *wrp, uint64_ return -1; } - if (bread(fsreadfd, buf, FFS_FSBTODB(sblock, blk), size) != 0) + rsize = roundup(size, DEV_BSIZE); + if (bread(fsreadfd, buf, FFS_FSBTODB(sblock, blk), rsize) != 0) return -1; if (write(wrp->fd, buf, size) != size) return -1; @@ -1162,6 +1209,9 @@ static struct typemap { { "dir", IFDIR }, { "socket", IFSOCK }, { "fifo", IFIFO }, + {"link", IFLNK}, + {"chr", IFCHR}, + {"blk", IFBLK}, }; CMDFUNC(newtype) @@ -1217,13 +1267,13 @@ CMDFUNC(chmode) CMDFUNC(chlen) { - long len; + off_t len; char *cp; if (!checkactive()) return 1; - len = strtol(argv[1], &cp, 0); + len = strtoull(argv[1], &cp, 0); if (cp == argv[1] || *cp != '\0' || len < 0) { warnx("bad length '%s'", argv[1]); return 1; @@ -1281,6 +1331,167 @@ CMDFUNC(chgen) return 0; } +CMDFUNCSTART(chextsize) +{ + int rval = 1; + uint32_t extsize; + char *cp; + + if (!is_ufs2) + return 1; + if (!checkactive()) + return 1; + + extsize = strtol(argv[1], &cp, 0); + if (cp == argv[1] || *cp != '\0') { + warnx("bad extsize `%s'", argv[1]); + return 1; + } + + curinode->dp2.di_extsize = extsize; + inodirty(); + printactive(); + return rval; +} + +CMDFUNCSTART(chblocks) +{ + int rval = 1; + uint64_t blocks; + char *cp; + + if (!checkactive()) + return 1; + + blocks = strtoll(argv[1], &cp, 0); + if (cp == argv[1] || *cp != '\0') { + warnx("bad blocks `%s'", argv[1]); + return 1; + } + + DIP_SET(curinode, blocks, blocks); + inodirty(); + printactive(); + return rval; +} + +CMDFUNCSTART(chdb) +{ + int rval = 1; + unsigned int idx; + daddr_t bno; + char *cp; + + if (!checkactive()) + return 1; + + idx = strtoull(argv[1], &cp, 0); + if (cp == argv[1] || *cp != '\0') { + warnx("bad pointer idx `%s'", argv[1]); + return 1; + } + bno = strtoll(argv[2], &cp, 0); + if (cp == argv[2] || *cp != '\0') { + warnx("bad block number `%s'", argv[2]); + return 1; + } + if (idx >= UFS_NDADDR) { + warnx("pointer index %d is out of range", idx); + return 1; + } + + DIP_SET(curinode, db[idx], bno); + inodirty(); + printactive(); + return rval; +} + +CMDFUNCSTART(chib) +{ + int rval = 1; + unsigned int idx; + daddr_t bno; + char *cp; + + if (!checkactive()) + return 1; + + idx = strtoull(argv[1], &cp, 0); + if (cp == argv[1] || *cp != '\0') { + warnx("bad pointer idx `%s'", argv[1]); + return 1; + } + bno = strtoll(argv[2], &cp, 0); + if (cp == argv[2] || *cp != '\0') { + warnx("bad block number `%s'", argv[2]); + return 1; + } + if (idx >= UFS_NIADDR) { + warnx("pointer index %d is out of range", idx); + return 1; + } + + DIP_SET(curinode, ib[idx], bno); + inodirty(); + printactive(); + return rval; +} + +CMDFUNCSTART(chextb) +{ + int rval = 1; + unsigned int idx; + daddr_t bno; + char *cp; + + if (!checkactive()) + return 1; + + idx = strtoull(argv[1], &cp, 0); + if (cp == argv[1] || *cp != '\0') { + warnx("bad pointer idx `%s'", argv[1]); + return 1; + } + bno = strtoll(argv[2], &cp, 0); + if (cp == argv[2] || *cp != '\0') { + warnx("bad block number `%s'", argv[2]); + return 1; + } + if (idx >= UFS_NXADDR) { + warnx("pointer index %d is out of range", idx); + return 1; + } + + curinode->dp2.di_extb[idx] = bno; + inodirty(); + printactive(); + return rval; +} + +CMDFUNCSTART(chfreelink) +{ + int rval = 1; + ino_t freelink; + char *cp; + + if (!checkactive()) + return 1; + + freelink = strtoll(argv[1], &cp, 0); + if (cp == argv[1] || *cp != '\0') { + warnx("bad freelink `%s'", argv[1]); + return 1; + } + + (void)&freelink; +#if 0 + DIP_SET(curinode, freelink, freelink); +#endif + inodirty(); + printactive(); + return rval; +} + CMDFUNC(linkcount) { int lcnt; @@ -1418,6 +1629,8 @@ CMDFUNC(chmtime) int64_t rsec; int32_t nsec; + if (!checkactive()) + return 1; if (dotime(argv[1], &rsec, &nsec)) return 1; DIP_SET(curinode, mtime, rsec); @@ -1432,6 +1645,8 @@ CMDFUNC(chatime) int64_t rsec; int32_t nsec; + if (!checkactive()) + return 1; if (dotime(argv[1], &rsec, &nsec)) return 1; DIP_SET(curinode, atime, rsec); @@ -1446,6 +1661,8 @@ CMDFUNC(chctime) int64_t rsec; int32_t nsec; + if (!checkactive()) + return 1; if (dotime(argv[1], &rsec, &nsec)) return 1; DIP_SET(curinode, ctime, rsec); @@ -1464,6 +1681,8 @@ CMDFUNC(chbirthtime) warnx("birthtime can only be set in ufs2"); return 1; } + if (!checkactive()) + return 1; if (dotime(argv[1], &rsec, &nsec)) return 1; @@ -1473,3 +1692,43 @@ CMDFUNC(chbirthtime) printactive(); return 0; } + +CMDFUNCSTART(iptrs) +{ + int i; + + if (!checkactive()) + return 1; + for (i = 0; i < UFS_NDADDR; i++) + printf("di_db %d %ju\n", i, DIP(curinode, db[i])); + for (i = 0; i < UFS_NIADDR; i++) + printf("di_ib %d %ju\n", i, DIP(curinode, ib[i])); + if (is_ufs2) + for (i = 0; i < UFS_NXADDR; i++) + printf("di_extb %d %ju\n", i, curinode->dp2.di_extb[i]); + return 0; +} + +CMDFUNC(saveea) +{ + struct wrinfo wrinfo; + uint64_t blkno = 0; + + if (!is_ufs2) { + warnx("dumping extattrs is only supported for ufs2"); + return 1; + } + if (!checkactive()) + return 1; + + wrinfo.fd = open(argv[1], O_WRONLY | O_TRUNC | O_CREAT, 0644); + if (wrinfo.fd == -1) { + warn("unable to create file %s", argv[1]); + return 0; + } + + wrinfo.size = iswap32(curinode->dp2.di_extsize); + wrinfo.written_size = 0; + print_blks64(curinode->dp2.di_extb, UFS_NXADDR, &blkno, &wrinfo); + return 0; +} Index: src/sbin/fsdb/fsdbutil.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsdb/fsdbutil.c,v retrieving revision 1.23 diff -u -p -r1.23 fsdbutil.c --- src/sbin/fsdb/fsdbutil.c 29 May 2021 16:51:25 -0000 1.23 +++ src/sbin/fsdb/fsdbutil.c 24 May 2022 02:21:34 -0000 @@ -94,12 +94,13 @@ printstat(const char *cp, ino_t inum, un struct passwd *pw; time_t t; char *p; - uint64_t size, blocks; + uint64_t size, extsize, blocks; uint16_t mode; uint32_t rdev; uint32_t uid, gid; size = iswap64(DIP(dp, size)); + extsize = is_ufs2 ? iswap32(dp->dp2.di_extsize) : 0; blocks = is_ufs2 ? iswap64(DIP(dp, blocks)) : iswap32(DIP(dp, blocks)); mode = iswap16(DIP(dp, mode)); rdev = iswap32(DIP(dp, rdev)); @@ -139,8 +140,8 @@ printstat(const char *cp, ino_t inum, un puts("fifo"); break; } - printf("I=%llu MODE=%o SIZE=%llu", (unsigned long long)inum, mode, - (unsigned long long)size); + printf("I=%llu MODE=%o SIZE=%llu EXTSIZE=%llu", (unsigned long long)inum, + mode, (unsigned long long)size, (unsigned long long)extsize); t = is_ufs2 ? iswap64(dp->dp2.di_mtime) : iswap32(dp->dp1.di_mtime); p = ctime(&t); printf("\n\t MTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20], Index: src/sbin/fsirand/fsirand.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsirand/fsirand.c,v retrieving revision 1.32 diff -u -p -r1.32 fsirand.c --- src/sbin/fsirand/fsirand.c 19 Oct 2013 01:09:58 -0000 1.32 +++ src/sbin/fsirand/fsirand.c 24 May 2022 02:21:34 -0000 @@ -95,11 +95,13 @@ getsblock(int fd, const char *name, stru switch(fs->fs_magic) { case FS_UFS2_MAGIC: + case FS_UFS2EA_MAGIC: is_ufs2 = 1; /* FALLTHROUGH */ case FS_UFS1_MAGIC: break; case FS_UFS2_MAGIC_SWAPPED: + case FS_UFS2EA_MAGIC_SWAPPED: is_ufs2 = 1; /* FALLTHROUGH */ case FS_UFS1_MAGIC_SWAPPED: Index: src/sbin/newfs/extern.h =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/newfs/extern.h,v retrieving revision 1.19 diff -u -p -r1.19 extern.h --- src/sbin/newfs/extern.h 18 Apr 2020 12:54:38 -0000 1.19 +++ src/sbin/newfs/extern.h 24 May 2022 02:21:34 -0000 @@ -31,6 +31,7 @@ void mkfs(const char *, int, int, mode_t extern int mfs; /* run as the memory based filesystem */ extern int Nflag; /* run mkfs without writing file system */ extern int Oflag; /* format as an 4.3BSD file system */ +extern int eaflag; /* use UFS2ea fs_magic */ extern int verbosity; /* amount of printf() output */ extern int64_t fssize; /* file system size */ extern int sectorsize; /* bytes/sector */ Index: src/sbin/newfs/mkfs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/newfs/mkfs.c,v retrieving revision 1.131 diff -u -p -r1.131 mkfs.c --- src/sbin/newfs/mkfs.c 1 Jan 2022 10:32:28 -0000 1.131 +++ src/sbin/newfs/mkfs.c 24 May 2022 02:21:34 -0000 @@ -745,6 +745,8 @@ mkfs(const char *fsys, int fi, int fo, memset(iobuf + sizeof(sblock), 0, i - sizeof(sblock)); if (needswap) ffs_sb_swap(&sblock, (struct fs *)iobuf); + if (eaflag) + ((struct fs *)iobuf)->fs_magic = FS_UFS2EA_MAGIC; if ((sblock.fs_old_flags & FS_FLAGS_UPDATED) == 0) memset(iobuf + offsetof(struct fs, fs_old_postbl_start), 0xff, 256); Index: src/sbin/newfs/newfs.8 =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/newfs/newfs.8,v retrieving revision 1.85 diff -u -p -r1.85 newfs.8 --- src/sbin/newfs/newfs.8 13 Apr 2019 19:29:27 -0000 1.85 +++ src/sbin/newfs/newfs.8 24 May 2022 02:21:34 -0000 @@ -229,9 +229,10 @@ or This is the default. .It 2 FFSv2; enhanced Fast File System, suited for more than 1 Terabyte capacity. -.\" Supports access control lists. This is also known as .Sq UFS2 . +.It 2ea +FFSv2 plus support for extended attributes and access control lists. .El See .Xr fsck_ffs 8 Index: src/sbin/newfs/newfs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/newfs/newfs.c,v retrieving revision 1.117 diff -u -p -r1.117 newfs.c --- src/sbin/newfs/newfs.c 16 Apr 2022 18:15:20 -0000 1.117 +++ src/sbin/newfs/newfs.c 24 May 2022 02:21:34 -0000 @@ -207,6 +207,7 @@ int mfs; /* run as the memory based fi int Gflag; /* allow garbage parameters (for testing) */ int Nflag; /* run without writing file system */ int Oflag = 1; /* format as an 4.3BSD file system */ +int eaflag; /* use UFS2ea fs_magic */ int verbosity; /* amount of printf() output */ #define DEFAULT_VERBOSITY 3 /* 4 is traditional behavior */ int64_t fssize; /* file system size */ @@ -315,6 +316,10 @@ main(int argc, char *argv[]) verbosity = DEFAULT_VERBOSITY; break; case 'O': + if (strcmp(optarg, "2ea") == 0) { + eaflag = 1; + optarg[1] = 0; + } Oflag = strsuftoi64("format", optarg, 0, 2, NULL); break; case 'S': @@ -862,7 +867,7 @@ struct help_strings { { NEWFS, "-I \t\tdo not check that the file system type is '4.2BSD'" }, { BOTH, "-N \t\tdo not create file system, just print out " "parameters" }, - { NEWFS, "-O N\t\tfilesystem format: 0 => 4.3BSD, 1 => FFSv1, 2 => FFSv2" }, + { NEWFS, "-O N\t\tfilesystem format: 0 => 4.3BSD, 1 => FFSv1, 2 => FFSv2, 2ea => FFSv2 with extattrs" }, { NEWFS, "-S secsize\tsector size" }, #ifdef COMPAT { NEWFS, "-T disktype\tdisk type" }, Index: src/sbin/resize_ffs/resize_ffs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/resize_ffs/resize_ffs.c,v retrieving revision 1.56 diff -u -p -r1.56 resize_ffs.c --- src/sbin/resize_ffs/resize_ffs.c 8 Apr 2022 10:17:53 -0000 1.56 +++ src/sbin/resize_ffs/resize_ffs.c 24 May 2022 02:21:34 -0000 @@ -2227,12 +2227,14 @@ main(int argc, char **argv) readat(where / DEV_BSIZE, oldsb, SBLOCKSIZE); switch (oldsb->fs_magic) { case FS_UFS2_MAGIC: + case FS_UFS2EA_MAGIC: is_ufs2 = 1; /* FALLTHROUGH */ case FS_UFS1_MAGIC: needswap = 0; break; case FS_UFS2_MAGIC_SWAPPED: + case FS_UFS2EA_MAGIC_SWAPPED: is_ufs2 = 1; /* FALLTHROUGH */ case FS_UFS1_MAGIC_SWAPPED: Index: src/sbin/scan_ffs/scan_ffs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/scan_ffs/scan_ffs.c,v retrieving revision 1.35 diff -u -p -r1.35 scan_ffs.c --- src/sbin/scan_ffs/scan_ffs.c 20 Jan 2022 14:45:14 -0000 1.35 +++ src/sbin/scan_ffs/scan_ffs.c 24 May 2022 02:21:34 -0000 @@ -128,7 +128,9 @@ ffs_checkver(struct sblockinfo *sbi) sbi->ffs->fs_size = sbi->ffs->fs_old_size; return FSTYPE_FFSV1; case FS_UFS2_MAGIC: + case FS_UFS2EA_MAGIC: case FS_UFS2_MAGIC_SWAPPED: + case FS_UFS2EA_MAGIC_SWAPPED: return FSTYPE_FFSV2; default: return FSTYPE_NONE; Index: src/sbin/tunefs/tunefs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/tunefs/tunefs.c,v retrieving revision 1.55 diff -u -p -r1.55 tunefs.c --- src/sbin/tunefs/tunefs.c 18 Sep 2021 03:05:20 -0000 1.55 +++ src/sbin/tunefs/tunefs.c 24 May 2022 02:21:34 -0000 @@ -81,6 +81,7 @@ int fi; long dev_bsize = 512; int needswap = 0; int is_ufs2 = 0; +int extattr = 0; off_t sblockloc; int userquota = 0; int groupquota = 0; @@ -361,7 +362,9 @@ main(int argc, char *argv[]) if (aflag) { name = "ACLs"; if (strcmp(avalue, "enable") == 0) { - if (sblock.fs_flags & FS_NFS4ACLS) { + if (is_ufs2 && !extattr) { + warnx("%s not supported by this fs", name); + } else if (sblock.fs_flags & FS_NFS4ACLS) { warnx("%s remains unchanged as enabled", name); } else if (sblock.fs_flags & FS_POSIX1EACLS) { warnx("%s and POSIX.1e ACLs are mutually " @@ -384,7 +387,9 @@ main(int argc, char *argv[]) if (pflag) { name = "POSIX1e ACLs"; if (strcmp(pvalue, "enable") == 0) { - if (sblock.fs_flags & FS_POSIX1EACLS) { + if (is_ufs2 && !extattr) { + warnx("%s not supported by this fs", name); + } else if (sblock.fs_flags & FS_POSIX1EACLS) { warnx("%s remains unchanged as enabled", name); } else if (sblock.fs_flags & FS_NFS4ACLS) { warnx("%s and ACLs are mutually " @@ -657,11 +662,17 @@ getsb(struct fs *fs, const char *file) errx(5, "cannot find filesystem superblock"); bread(sblock_try[i] / dev_bsize, (char *)fs, SBLOCKSIZE, file); switch(fs->fs_magic) { + case FS_UFS2EA_MAGIC: + extattr = 1; + /*FALLTHROUGH*/ case FS_UFS2_MAGIC: is_ufs2 = 1; /*FALLTHROUGH*/ case FS_UFS1_MAGIC: break; + case FS_UFS2EA_MAGIC_SWAPPED: + extattr = 1; + /*FALLTHROUGH*/ case FS_UFS2_MAGIC_SWAPPED: is_ufs2 = 1; /*FALLTHROUGH*/ Index: src/sys/arch/hppa/stand/xxboot/readufs_ffs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/arch/hppa/stand/xxboot/readufs_ffs.c,v retrieving revision 1.1 diff -u -p -r1.1 readufs_ffs.c --- src/sys/arch/hppa/stand/xxboot/readufs_ffs.c 24 Feb 2014 07:23:43 -0000 1.1 +++ src/sys/arch/hppa/stand/xxboot/readufs_ffs.c 24 May 2022 02:21:34 -0000 @@ -66,7 +66,7 @@ try_ffs(void) break; #endif #ifdef USE_UFS2 - if (magic == FS_UFS2_MAGIC) { + if (magic == FS_UFS2_MAGIC || magic == FS_UFS2EA_MAGIC) { #ifdef USE_UFS1 fsi.ufstype = UFSTYPE_UFS2; #endif @@ -81,7 +81,8 @@ try_ffs(void) */ fsi_ffs.magic = magic; #ifdef DEBUG_WITH_STDIO - printf("FFS: detected UFS%d format\n", (magic == FS_UFS2_MAGIC) + 1); + printf("FFS: detected UFS%d format\n", + (magic == FS_UFS2_MAGIC || magic == FS_UFS2EA_MAGIC) + 1); #endif /* This partition looks like an FFS. */ Index: src/sys/arch/sparc/stand/bootblk/bootblk.fth =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/arch/sparc/stand/bootblk/bootblk.fth,v retrieving revision 1.16 diff -u -p -r1.16 bootblk.fth --- src/sys/arch/sparc/stand/bootblk/bootblk.fth 24 Jul 2021 21:31:36 -0000 1.16 +++ src/sys/arch/sparc/stand/bootblk/bootblk.fth 24 May 2022 02:21:34 -0000 @@ -624,6 +624,7 @@ create cur-blockno -1 l, -1 l, \ Curren fs_magic l@ case fs1_magic_value of init-ffs-v1 true endof fs2_magic_value of init-ffs-v2 true endof + fs2ea_magic_value of init-ffs-v2 true endof false swap \ Return false endcase ; Index: src/sys/arch/sparc/stand/bootblk/genfth.cf =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/arch/sparc/stand/bootblk/genfth.cf,v retrieving revision 1.9 diff -u -p -r1.9 genfth.cf --- src/sys/arch/sparc/stand/bootblk/genfth.cf 10 Jun 2013 10:26:22 -0000 1.9 +++ src/sys/arch/sparc/stand/bootblk/genfth.cf 24 May 2022 02:21:34 -0000 @@ -158,6 +158,7 @@ member d_name define fs1_magic_value FS_UFS1_MAGIC define fs2_magic_value FS_UFS2_MAGIC +define fs2ea_magic_value FS_UFS2EA_MAGIC define fs_42postblfmt FS_42POSTBLFMT define fs_44inodefmt FS_44INODEFMT define ndaddr UFS_NDADDR Index: src/sys/arch/x68k/stand/boot_ufs/readufs_ffs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/arch/x68k/stand/boot_ufs/readufs_ffs.c,v retrieving revision 1.14 diff -u -p -r1.14 readufs_ffs.c --- src/sys/arch/x68k/stand/boot_ufs/readufs_ffs.c 23 Jun 2013 02:06:05 -0000 1.14 +++ src/sys/arch/x68k/stand/boot_ufs/readufs_ffs.c 24 May 2022 02:21:34 -0000 @@ -69,7 +69,7 @@ try_ffs(void) } #endif #ifdef USE_UFS2 - if (magic == FS_UFS2_MAGIC) { + if (magic == FS_UFS2_MAGIC || magic == FS_UFS2EA_MAGIC) { #ifdef USE_UFS1 fsi.ufstype = UFSTYPE_UFS2; #endif @@ -84,7 +84,8 @@ try_ffs(void) */ fsi_ffs.magic = magic; #ifdef DEBUG_WITH_STDIO - printf("FFS: detected UFS%d format\n", (magic == FS_UFS2_MAGIC) + 1); + printf("FFS: detected UFS%d format\n", + (magic == FS_UFS2_MAGIC || magic == FS_UFS2EA_MAGIC) + 1); #endif /* This partition looks like an FFS. */ Index: src/sys/lib/libsa/ffsv1.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/lib/libsa/ffsv1.c,v retrieving revision 1.9 diff -u -p -r1.9 ffsv1.c --- src/sys/lib/libsa/ffsv1.c 24 Apr 2022 06:52:59 -0000 1.9 +++ src/sys/lib/libsa/ffsv1.c 24 May 2022 02:52:37 -0000 @@ -17,9 +17,4 @@ #define ufs_indp_swap bswap32 #define indp_t int32_t -#define FS_MAGIC FS_UFS1_MAGIC - -/* #define FSMOD "wapbl/ufs/ffs" */ -#define FSMOD NULL - #include "ufs.c" Index: src/sys/lib/libsa/ffsv2.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/lib/libsa/ffsv2.c,v retrieving revision 1.9 diff -u -p -r1.9 ffsv2.c --- src/sys/lib/libsa/ffsv2.c 24 Apr 2022 06:52:59 -0000 1.9 +++ src/sys/lib/libsa/ffsv2.c 24 May 2022 02:29:10 -0000 @@ -17,9 +17,4 @@ #define ufs_indp_swap bswap64 #define indp_t int64_t -#define FS_MAGIC FS_UFS2_MAGIC - -/* #define FSMOD "wapbl/ufs/ffs" */ -#define FSMOD NULL - #include "ufs.c" Index: src/sys/lib/libsa/lfsv1.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/lib/libsa/lfsv1.c,v retrieving revision 1.15 diff -u -p -r1.15 lfsv1.c --- src/sys/lib/libsa/lfsv1.c 27 May 2021 06:54:44 -0000 1.15 +++ src/sys/lib/libsa/lfsv1.c 24 May 2022 02:21:34 -0000 @@ -25,8 +25,6 @@ #define dblksize(a, b, c) lfs_dblksize((a), (b), (c)) #define FSBTODB(fs, daddr) (daddr) /* LFSv1 uses sectors for addresses */ -#define FS_MAGIC LFS_MAGIC - #define FSMOD "lfs" #include "lib/libsa/ufs.c" Index: src/sys/lib/libsa/lfsv2.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/lib/libsa/lfsv2.c,v retrieving revision 1.15 diff -u -p -r1.15 lfsv2.c --- src/sys/lib/libsa/lfsv2.c 27 May 2021 06:54:44 -0000 1.15 +++ src/sys/lib/libsa/lfsv2.c 24 May 2022 02:21:34 -0000 @@ -29,8 +29,6 @@ #define dblksize(a, b, c) lfs_dblksize((a), (b), (c)) #define FSBTODB(a, b) LFS_FSBTODB((a), (b)) -#define FS_MAGIC LFS_MAGIC - #define FSMOD "lfs" #include "lib/libsa/ufs.c" Index: src/sys/lib/libsa/ufs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/lib/libsa/ufs.c,v retrieving revision 1.86 diff -u -p -r1.86 ufs.c --- src/sys/lib/libsa/ufs.c 29 Apr 2022 07:42:07 -0000 1.86 +++ src/sys/lib/libsa/ufs.c 24 May 2022 02:21:34 -0000 @@ -156,9 +156,6 @@ typedef uint32_t ino32_t; #ifndef FSBTODB #define FSBTODB(fs, indp) FFS_FSBTODB(fs, indp) #endif -#ifndef FS_MAGIC -#define FS_MAGIC FS_UFS1_MAGIC -#endif #ifndef UFS_NINDIR #define UFS_NINDIR FFS_NINDIR #endif @@ -214,17 +211,54 @@ static int search_directory(const char * static void ffs_oldfscompat(FS *); #endif +#ifdef LIBSA_FFSv1 static __inline__ bool ffs_is_magic(FS *fs) { - return fs->fs_magic == FS_MAGIC; + return fs->fs_magic == FS_UFS1_MAGIC; +} + +static __inline__ bool +ffs_is_magic_swapped(FS *fs) +{ + return fs->fs_magic == bswap32(FS_UFS1_MAGIC); } +#endif + +#ifdef LIBSA_FFSv2 +static __inline__ bool +ffs_is_magic(FS *fs) +{ + return fs->fs_magic == FS_UFS2_MAGIC || fs->fs_magic == FS_UFS2EA_MAGIC; +} + +static __inline__ bool +ffs_is_magic_swapped(FS *fs) +{ + return fs->fs_magic == bswap32(FS_UFS2_MAGIC) || + fs->fs_magic == bswap32(FS_UFS2EA_MAGIC); +} +#endif + +#ifdef LIBSA_LFS +static __inline__ bool +ffs_is_magic(FS *fs) +{ + return fs->fs_magic == LFS_MAGIC; +} + +static __inline__ bool +ffs_is_magic_swapped(FS *fs) +{ + return fs->fs_magic == bswap32(LFS_MAGIC); +} +#endif static __inline__ void ffs_fix_magic_swapped(struct file *fp, FS *fs) { #ifdef LIBSA_FFS_EI - fp->f_swapped = fs->fs_magic == bswap32(FS_MAGIC); + fp->f_swapped = ffs_is_magic_swapped(fs); if (fp->f_swapped) { ffs_sb_swap(fs, fs); Index: src/sys/ufs/ffs/ffs_balloc.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/ufs/ffs/ffs_balloc.c,v retrieving revision 1.65 diff -u -p -r1.65 ffs_balloc.c --- src/sys/ufs/ffs/ffs_balloc.c 5 Sep 2020 16:30:13 -0000 1.65 +++ src/sys/ufs/ffs/ffs_balloc.c 24 May 2022 02:21:34 -0000 @@ -543,6 +543,8 @@ ffs_balloc_ufs2(struct vnode *vp, off_t const int needswap = UFS_FSNEEDSWAP(fs); UVMHIST_FUNC("ffs_balloc"); UVMHIST_CALLED(ubchist); + KASSERT((ump->um_flags & UFS_EA) != 0 || (flags & IO_EXT) == 0); + lbn = ffs_lblkno(fs, off); size = ffs_blkoff(fs, off) + size; if (size > fs->fs_bsize) Index: src/sys/ufs/ffs/ffs_extattr.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/ufs/ffs/ffs_extattr.c,v retrieving revision 1.8 diff -u -p -r1.8 ffs_extattr.c --- src/sys/ufs/ffs/ffs_extattr.c 14 Dec 2021 11:06:50 -0000 1.8 +++ src/sys/ufs/ffs/ffs_extattr.c 24 May 2022 02:21:34 -0000 @@ -464,6 +464,9 @@ ffs_open_ea(struct vnode *vp, kauth_cred int error; ip = VTOI(vp); + if ((ip->i_ump->um_flags & UFS_EA) == 0) { + return EOPNOTSUPP; + } ffs_lock_ea(vp); if (ip->i_ea_area != NULL) { @@ -497,6 +500,7 @@ ffs_close_ea(struct vnode *vp, int commi struct ufs2_dinode *dp; ip = VTOI(vp); + KASSERT((ip->i_ump->um_flags & UFS_EA) != 0); if (commit) KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE); Index: src/sys/ufs/ffs/ffs_inode.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/ufs/ffs/ffs_inode.c,v retrieving revision 1.131 diff -u -p -r1.131 ffs_inode.c --- src/sys/ufs/ffs/ffs_inode.c 31 Jul 2020 04:07:30 -0000 1.131 +++ src/sys/ufs/ffs/ffs_inode.c 24 May 2022 02:21:34 -0000 @@ -243,6 +243,9 @@ ffs_truncate(struct vnode *ovp, off_t le if ((ioflag & (IO_EXT | IO_NORMAL)) == 0) ioflag |= IO_NORMAL; + if ((ump->um_flags & UFS_EA) == 0) + ioflag &= ~IO_EXT; + fs = oip->i_fs; #define i_din2 i_din.ffs2_din extblocks = 0; Index: src/sys/ufs/ffs/ffs_vfsops.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/ufs/ffs/ffs_vfsops.c,v retrieving revision 1.376 diff -u -p -r1.376 ffs_vfsops.c --- src/sys/ufs/ffs/ffs_vfsops.c 16 Apr 2022 08:00:55 -0000 1.376 +++ src/sys/ufs/ffs/ffs_vfsops.c 24 May 2022 02:21:34 -0000 @@ -842,6 +842,15 @@ ffs_reload(struct mount *mp, kauth_cred_ brelse(bp, 0); + /* Allow converting from UFS2 to UFS2EA but not vice versa. */ + if (newfs->fs_magic == FS_UFS2EA_MAGIC) { + ump->um_flags |= UFS_EA; + newfs->fs_magic = FS_UFS2_MAGIC; + } else { + if ((ump->um_flags & UFS_EA) != 0) + return EINVAL; + } + if ((newfs->fs_magic != FS_UFS1_MAGIC) && (newfs->fs_magic != FS_UFS2_MAGIC)) { kmem_free(newfs, fs_sbsize); @@ -1214,6 +1223,13 @@ ffs_mountfs(struct vnode *devvp, struct * size to read the superblock. Once read, we swap the whole * superblock structure. */ + if (fs->fs_magic == FS_UFS2EA_MAGIC) { + ump->um_flags |= UFS_EA; + fs->fs_magic = FS_UFS2_MAGIC; + } else if (fs->fs_magic == FS_UFS2EA_MAGIC_SWAPPED) { + ump->um_flags |= UFS_EA; + fs->fs_magic = FS_UFS2_MAGIC_SWAPPED; + } if (fs->fs_magic == FS_UFS1_MAGIC) { fs_sbsize = fs->fs_sbsize; fstype = UFS1; @@ -2370,6 +2386,11 @@ ffs_sbupdate(struct ufsmount *mp, int wa memcpy(bp->b_data, fs, fs->fs_sbsize); ffs_oldfscompat_write((struct fs *)bp->b_data, mp); + if (mp->um_flags & UFS_EA) { + struct fs *bfs = (struct fs *)bp->b_data; + KASSERT(bfs->fs_magic == FS_UFS2_MAGIC); + bfs->fs_magic = FS_UFS2EA_MAGIC; + } #ifdef FFS_EI if (mp->um_flags & UFS_NEEDSWAP) ffs_sb_swap((struct fs *)bp->b_data, (struct fs *)bp->b_data); Index: src/sys/ufs/ffs/fs.h =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/ufs/ffs/fs.h,v retrieving revision 1.69 diff -u -p -r1.69 fs.h --- src/sys/ufs/ffs/fs.h 18 Sep 2021 03:05:20 -0000 1.69 +++ src/sys/ufs/ffs/fs.h 24 May 2022 02:21:34 -0000 @@ -398,8 +398,10 @@ struct fs { */ #define FS_UFS1_MAGIC 0x011954 /* UFS1 fast file system magic number */ #define FS_UFS2_MAGIC 0x19540119 /* UFS2 fast file system magic number */ +#define FS_UFS2EA_MAGIC 0x19012038 /* UFS2 with extattrs */ #define FS_UFS1_MAGIC_SWAPPED 0x54190100 #define FS_UFS2_MAGIC_SWAPPED 0x19015419 +#define FS_UFS2EA_MAGIC_SWAPPED 0x38200119 #define FS_OKAY 0x7c269d38 /* superblock checksum */ #define FS_42INODEFMT -1 /* 4.2BSD inode format */ #define FS_44INODEFMT 2 /* 4.4BSD inode format */ Index: src/sys/ufs/ufs/ufs_bmap.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/ufs/ufs/ufs_bmap.c,v retrieving revision 1.53 diff -u -p -r1.53 ufs_bmap.c --- src/sys/ufs/ufs/ufs_bmap.c 20 Apr 2020 03:57:02 -0000 1.53 +++ src/sys/ufs/ufs/ufs_bmap.c 24 May 2022 02:21:34 -0000 @@ -191,7 +191,7 @@ ufs_bmaparray(struct vnode *vp, daddr_t } return (0); } else if (bn < 0 && bn >= -UFS_NXADDR) { - KASSERT(ump->um_fstype == UFS2); + KASSERT(ump->um_fstype == UFS2 && (ump->um_flags & UFS_EA) != 0); daddr = ufs_rw64(ip->i_ffs2_extb[-1 - bn], UFS_MPNEEDSWAP(ump)); *bnp = blkptrtodb(ump, daddr); if (*bnp == 0) Index: src/sys/ufs/ufs/ufsmount.h =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/ufs/ufs/ufsmount.h,v retrieving revision 1.43 diff -u -p -r1.43 ufsmount.h --- src/sys/ufs/ufs/ufsmount.h 27 Mar 2015 17:27:56 -0000 1.43 +++ src/sys/ufs/ufs/ufsmount.h 24 May 2022 02:21:34 -0000 @@ -163,6 +163,7 @@ struct ufs_ops { #define UFS_ISAPPLEUFS 0x02 /* filesystem is Apple UFS */ #define UFS_QUOTA 0x04 /* filesystem has QUOTA (v1) */ #define UFS_QUOTA2 0x08 /* filesystem has QUOTA2 */ +#define UFS_EA 0x10 /* UFS2 with extattrs */ /* * Filesystem types Index: src/tests/fs/ffs/t_extattr.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/tests/fs/ffs/t_extattr.c,v retrieving revision 1.2 diff -u -p -r1.2 t_extattr.c --- src/tests/fs/ffs/t_extattr.c 12 Apr 2020 23:52:20 -0000 1.2 +++ src/tests/fs/ffs/t_extattr.c 24 May 2022 02:21:34 -0000 @@ -78,8 +78,8 @@ check_list(const char *buf, ssize_t nr) } } -// Make it ffsv2 -const char *newfs = "newfs -O 2 -F -s 10000 " IMGNAME; +// Make it ffsv2 with extattrs +const char *newfs = "newfs -O 2ea -F -s 10000 " IMGNAME; #define FAKEBLK "/dev/formula1" static void Index: src/tests/sbin/fsck_ffs/Makefile =================================================================== RCS file: /home/chs/netbsd/cvs/src/tests/sbin/fsck_ffs/Makefile,v retrieving revision 1.2 diff -u -p -r1.2 Makefile --- src/tests/sbin/fsck_ffs/Makefile 6 Mar 2011 17:08:41 -0000 1.2 +++ src/tests/sbin/fsck_ffs/Makefile 24 May 2022 02:21:34 -0000 @@ -9,4 +9,6 @@ TESTS_SH+= ${name} TESTS_SH_SRC_${name}= quotas_common.sh ${name}.sh .endfor +TESTS_SH+= t_enable_extattr + .include Index: src/tests/sbin/fsck_ffs/t_enable_extattr.sh =================================================================== RCS file: src/tests/sbin/fsck_ffs/t_enable_extattr.sh diff -N src/tests/sbin/fsck_ffs/t_enable_extattr.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/tests/sbin/fsck_ffs/t_enable_extattr.sh 3 Jan 2022 09:44:37 -0000 @@ -0,0 +1,144 @@ +# $NetBSD$ +# +# Copyright (c) 2021 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +VND=vnd0 +BDEV=/dev/${VND}a +CDEV=/dev/r${VND}a +IMG=fsimage +MNT=mnt + +atf_test_case fsck_enable_extattr cleanup +atf_test_case fsck_enable_extattr_corrupted cleanup + +cleanup() +{ + umount -f ${MNT} > /dev/null 2>&1 || true + vnconfig -u ${VND} > /dev/null 2>&1 || true +} + +fsck_enable_extattr_head() +{ + atf_set "descr" "Checks fsck_ffs enabling extattrs" +} + +fsck_enable_extattr_body() +{ + atf_check mkdir -p ${MNT} + + atf_check -o ignore newfs -O2 -s 4m -F ${IMG} + atf_check vnconfig ${VND} ${IMG} + + # Verify that extattrs are disabled. + atf_check -o ignore -e 'match:POSIX1e ACLs not supported by this fs' \ + tunefs -p enable ${CDEV} + atf_check mount -t ffs ${BDEV} ${MNT} + atf_check touch ${MNT}/file + atf_check -s exit:1 -e ignore setextattr user name1 value1 ${MNT}/file + atf_check umount ${MNT} + + # Enable extattrs. + atf_check -o 'match:ENABLING EXTATTR SUPPORT' \ + fsck_ffs -c ea ${CDEV} + + # Verify that extattrs are now enabled. + atf_check -o 'match:POSIX1e ACLs set' -e ignore \ + tunefs -p enable ${CDEV} + atf_check mount -t ffs ${BDEV} ${MNT} + atf_check touch ${MNT}/file + atf_check setextattr user testname testvalue ${MNT}/file + atf_check -o 'match:testvalue' getextattr user testname ${MNT}/file + atf_check umount ${MNT} + atf_check vnconfig -u ${VND} +} + +fsck_enable_extattr_cleanup() +{ + cleanup +} + +fsck_enable_extattr_corrupted_head() +{ + atf_set "descr" "Checks fsck_ffs enabling extattrs with corruption" +} + +fsck_enable_extattr_corrupted_body() +{ + atf_check mkdir -p ${MNT} + + # Create an fs with extattrs enabled and set one on the test file. + atf_check -o ignore newfs -O2ea -b 8k -f 1k -s 4m -F ${IMG} + atf_check vnconfig ${VND} ${IMG} + + atf_check mount -t ffs ${BDEV} ${MNT} + atf_check touch ${MNT}/file + atf_check setextattr user testname testvalue ${MNT}/file + atf_check -o 'match:testvalue' getextattr user testname ${MNT}/file + atf_check umount ${MNT} + + # Find the location and size of the extattr block. + extb0=$(printf 'cd file\niptrs\n' | fsdb -n $CDEV | grep 'di_extb 0' | + awk '{print $3}') + extsize=$(printf 'cd file\n' | fsdb -n $CDEV | grep EXTSIZE | tail -1 | + awk '{print $4}' | sed 's,.*=,,') + atf_check [ $extb0 != 0 ] + atf_check [ $extsize != 0 ] + + # Recreate the fs with extattrs disabled and set the extattr block + # size/location of the new test file to the same values as the old + # test file. This simulates extattrs having been created in a + # UFS2-non-ea file system before UFS2ea was invented. + atf_check -o ignore newfs -O2 -b 8k -f 1k -s 4m -F ${IMG} + atf_check mount -t ffs ${BDEV} ${MNT} + atf_check touch ${MNT}/file + atf_check umount ${MNT} + printf "cd file\nchextb 0 $extb0\n" | fsdb -N $CDEV + printf "cd file\nchextsize $extsize\n" | fsdb -N $CDEV + + # Enable extattrs. + atf_check -o 'match:CLEAR EXTATTR FIELDS' \ + -o 'match:ENABLING EXTATTR SUPPORT' \ + fsck_ffs -y -c ea ${CDEV} + + # Verify that the test file does not have the test extattr. + atf_check -o ignore fsck -n ${CDEV} + atf_check mount -t ffs ${BDEV} ${MNT} + atf_check -s exit:1 -e 'match:Attribute not found' \ + getextattr user testname ${MNT}/file + atf_check umount ${MNT} + atf_check vnconfig -u ${VND} +} + +fsck_enable_extattr_corrupted_cleanup() +{ + cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case fsck_enable_extattr + atf_add_test_case fsck_enable_extattr_corrupted +} Index: src/usr.sbin/dumpfs/dumpfs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/usr.sbin/dumpfs/dumpfs.c,v retrieving revision 1.65 diff -u -p -r1.65 dumpfs.c --- src/usr.sbin/dumpfs/dumpfs.c 18 Sep 2021 03:05:20 -0000 1.65 +++ src/usr.sbin/dumpfs/dumpfs.c 24 May 2022 02:21:34 -0000 @@ -103,7 +103,7 @@ static union { #define DFLT_OPTS (opt_superblock | opt_cg_summary | opt_cg_info | opt_verbose) static long dev_bsize = 512; -static int needswap, printold, is_ufs2; +static int needswap, printold, is_ufs2, is_ufs2ea; static int Fflag; static uint opt_flags; @@ -192,11 +192,17 @@ dumpfs(const char *name) if (read(fd, &afs, SBLOCKSIZE) != SBLOCKSIZE) continue; switch(afs.fs_magic) { + case FS_UFS2EA_MAGIC: + is_ufs2ea = 1; + /* FALLTHROUGH */ case FS_UFS2_MAGIC: is_ufs2 = 1; break; case FS_UFS1_MAGIC: break; + case FS_UFS2EA_MAGIC_SWAPPED: + is_ufs2ea = 1; + /* FALLTHROUGH */ case FS_UFS2_MAGIC_SWAPPED: is_ufs2 = 1; needswap = 1; @@ -294,7 +300,7 @@ print_superblock(struct fs *fs, uint16_t time_t t; int32_t fsflags; - printf("format\tFFSv%d\n", is_ufs2+1); + printf("format\tFFSv%d%s\n", is_ufs2+1, is_ufs2ea ? "ea" : ""); #if BYTE_ORDER == LITTLE_ENDIAN if (needswap) #else Index: src/usr.sbin/fstyp/ufs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/usr.sbin/fstyp/ufs.c,v retrieving revision 1.1 diff -u -p -r1.1 ufs.c --- src/usr.sbin/fstyp/ufs.c 9 Jan 2018 03:31:15 -0000 1.1 +++ src/usr.sbin/fstyp/ufs.c 24 May 2022 02:21:34 -0000 @@ -67,6 +67,12 @@ fstyp_ufs(FILE *fp, char *label, size_t fs = (struct fs *)read_buf(fp, superblock, SBLOCKSIZE); if (fs == NULL) continue; + + if (fs->fs_magic == FS_UFS2EA_MAGIC) + fs->fs_magic = FS_UFS2_MAGIC; + else if (fs->fs_magic == FS_UFS2EA_MAGIC_SWAPPED) + fs->fs_magic = FS_UFS2_MAGIC_SWAPPED; + /* * Check for magic. We also need to check if file system size * is equal to providers size, because sysinstall(8) used to Index: src/usr.sbin/installboot/ffs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/usr.sbin/installboot/ffs.c,v retrieving revision 1.32 diff -u -p -r1.32 ffs.c --- src/usr.sbin/installboot/ffs.c 23 Jun 2013 02:06:06 -0000 1.32 +++ src/usr.sbin/installboot/ffs.c 24 May 2022 02:21:34 -0000 @@ -502,6 +502,7 @@ ffs_match_common(ib_params *params, off_ continue; switch (fs->fs_magic) { case FS_UFS2_MAGIC: + case FS_UFS2EA_MAGIC: is_ufs2 = 1; /* FALLTHROUGH */ case FS_UFS1_MAGIC: @@ -512,6 +513,7 @@ ffs_match_common(ib_params *params, off_ break; #ifndef FFS_NO_SWAP case FS_UFS2_MAGIC_SWAPPED: + case FS_UFS2EA_MAGIC_SWAPPED: is_ufs2 = 1; /* FALLTHROUGH */ case FS_UFS1_MAGIC_SWAPPED: Index: src/usr.sbin/makefs/ffs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/usr.sbin/makefs/ffs.c,v retrieving revision 1.72 diff -u -p -r1.72 ffs.c --- src/usr.sbin/makefs/ffs.c 9 Apr 2022 10:05:35 -0000 1.72 +++ src/usr.sbin/makefs/ffs.c 24 May 2022 02:21:34 -0000 @@ -180,6 +180,8 @@ ffs_prep_opts(fsinfo_t *fsopts) 0, 0, "Optimization (time|space)" }, { 'l', "label", ffs_opts->label, OPT_STRARRAY, 1, sizeof(ffs_opts->label), "UFS label" }, + { 'e', "extattr", &ffs_opts->extattr, OPT_INT32, + 0, 1, "extattr support" }, { .name = NULL } }; @@ -194,6 +196,7 @@ ffs_prep_opts(fsinfo_t *fsopts) ffs_opts->avgfilesize= -1; ffs_opts->avgfpdir= -1; ffs_opts->version = 1; + ffs_opts->extattr = 1; fsopts->fs_specific = ffs_opts; fsopts->fs_options = copy_opts(ffs_options); Index: src/usr.sbin/makefs/ffs.h =================================================================== RCS file: /home/chs/netbsd/cvs/src/usr.sbin/makefs/ffs.h,v retrieving revision 1.2 diff -u -p -r1.2 ffs.h --- src/usr.sbin/makefs/ffs.h 9 Oct 2011 21:33:43 -0000 1.2 +++ src/usr.sbin/makefs/ffs.h 24 May 2022 02:21:34 -0000 @@ -60,6 +60,7 @@ typedef struct { int avgfilesize; /* expected average file size */ int avgfpdir; /* expected # of files per directory */ int version; /* filesystem version (1 = FFS, 2 = UFS2) */ + int extattr; /* use UFS2ea magic */ int maxbsize; /* maximum extent size */ int maxblkspercg; /* max # of blocks per cylinder group */ /* XXX: support `old' file systems ? */ Index: src/usr.sbin/makefs/makefs.8 =================================================================== RCS file: /home/chs/netbsd/cvs/src/usr.sbin/makefs/makefs.8,v retrieving revision 1.70 diff -u -p -r1.70 makefs.8 --- src/usr.sbin/makefs/makefs.8 6 Apr 2022 13:39:06 -0000 1.70 +++ src/usr.sbin/makefs/makefs.8 24 May 2022 02:21:34 -0000 @@ -304,6 +304,8 @@ Expected number of files per directory. Block size. .It Sy density Bytes per inode. +.It Sy extattr +UFS2 with extended attributes. .It Sy extent Maximum extent size. .It Sy fsize Index: src/usr.sbin/makefs/ffs/mkfs.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/usr.sbin/makefs/ffs/mkfs.c,v retrieving revision 1.40 diff -u -p -r1.40 mkfs.c --- src/usr.sbin/makefs/ffs/mkfs.c 2 Apr 2022 19:16:49 -0000 1.40 +++ src/usr.sbin/makefs/ffs/mkfs.c 24 May 2022 02:21:34 -0000 @@ -109,6 +109,7 @@ union { #define writebuf wb.pad static int Oflag; /* format as an 4.3BSD file system */ +static int extattr; /* use UFS2ea magic */ static int64_t fssize; /* file system size */ static int sectorsize; /* bytes/sector */ static int fsize; /* fragment size */ @@ -148,6 +149,7 @@ ffs_mkfs(const char *fsys, const fsinfo_ ffs_opt_t *ffs_opts = fsopts->fs_specific; Oflag = ffs_opts->version; + extattr = ffs_opts->extattr; fssize = fsopts->size / fsopts->sectorsize; sectorsize = fsopts->sectorsize; fsize = ffs_opts->fsize; @@ -296,7 +298,10 @@ ffs_mkfs(const char *fsys, const fsinfo_ sblock.fs_old_postblformat = 1; sblock.fs_old_nrpos = 1; } else { - sblock.fs_magic = FS_UFS2_MAGIC; + if (extattr) + sblock.fs_magic = FS_UFS2EA_MAGIC; + else + sblock.fs_magic = FS_UFS2_MAGIC; #if 0 /* XXX makefs is used for small filesystems. */ sblock.fs_sblockloc = SBLOCK_UFS2; #else Index: src/usr.sbin/quot/quot.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/usr.sbin/quot/quot.c,v retrieving revision 1.34 diff -u -p -r1.34 quot.c --- src/usr.sbin/quot/quot.c 28 Jul 2016 08:24:58 -0000 1.34 +++ src/usr.sbin/quot/quot.c 24 May 2022 02:21:34 -0000 @@ -569,10 +569,12 @@ quot(const char *name, const char *mp) fs = (struct fs *)superblock; if (fs->fs_magic != FS_UFS1_MAGIC && - fs->fs_magic != FS_UFS2_MAGIC) + fs->fs_magic != FS_UFS2_MAGIC && + fs->fs_magic != FS_UFS2EA_MAGIC) continue; if (fs->fs_magic == FS_UFS2_MAGIC + || fs->fs_magic == FS_UFS2EA_MAGIC || fs->fs_old_flags & FS_FLAGS_UPDATED) { /* Not the main superblock */ if (fs->fs_sblockloc != sbloc) Index: src/usr.sbin/quotacheck/quotacheck.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/usr.sbin/quotacheck/quotacheck.c,v retrieving revision 1.49 diff -u -p -r1.49 quotacheck.c --- src/usr.sbin/quotacheck/quotacheck.c 16 Jun 2015 23:04:14 -0000 1.49 +++ src/usr.sbin/quotacheck/quotacheck.c 24 May 2022 02:21:34 -0000 @@ -367,6 +367,9 @@ chkquota(const char *type, const char *f bread(sblock_try[i], (char *)&sblock, SBLOCKSIZE); switch (sblock.fs_magic) { #ifdef HAVE_UFSv2 + case FS_UFS2EA_MAGIC: + sblock.fs_magic = FS_UFS2_MAGIC; + /*FALLTHROUGH*/ case FS_UFS2_MAGIC: is_ufs2 = 1; /*FALLTHROUGH*/ @@ -374,6 +377,9 @@ chkquota(const char *type, const char *f case FS_UFS1_MAGIC: break; #ifdef HAVE_UFSv2 + case FS_UFS2EA_MAGIC_SWAPPED: + sblock.fs_magic = FS_UFS2_MAGIC_SWAPPED; + /*FALLTHROUGH*/ case FS_UFS2_MAGIC_SWAPPED: is_ufs2 = 1; /*FALLTHROUGH*/ Index: src/usr.sbin/sysinst/label.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/usr.sbin/sysinst/label.c,v retrieving revision 1.33 diff -u -p -r1.33 label.c --- src/usr.sbin/sysinst/label.c 9 May 2021 11:06:20 -0000 1.33 +++ src/usr.sbin/sysinst/label.c 24 May 2022 02:21:34 -0000 @@ -1989,7 +1989,9 @@ get_last_mounted(int fd, daddr_t partsta *fs_sub_type = 1; continue; case FS_UFS2_MAGIC: + case FS_UFS2EA_MAGIC: case FS_UFS2_MAGIC_SWAPPED: + case FS_UFS2EA_MAGIC_SWAPPED: /* Check we have the main superblock */ if (SB->fs_sblockloc == *sbp) { mnt = (const char *)SB->fs_fsmnt;