Index: src/UPDATING =================================================================== RCS file: /home/chs/netbsd/cvs/src/UPDATING,v retrieving revision 1.334 diff -u -p -r1.334 UPDATING --- src/UPDATING 12 Nov 2022 02:20:15 -0000 1.334 +++ src/UPDATING 15 Nov 2022 01:45:13 -0000 @@ -19,6 +19,33 @@ See also: BUILDING, build.sh, Makefile. Recent changes: ^^^^^^^^^^^^^^^ +20221116: + + The addition to NetBSD's version of UFS2 of support for extended + attributes broke backward compatibility with previous releases + of NetBSD, so UFS2 has been restored to being compatible with + previous NetBSD releases by disabling extended attributes. + (Note that ACLs are implemented as extended attributes, so + this changes disables ACLs as well.) + + Support for UFS2 with extended attributes is now available in a new + UFS variant called UFS2ea. If you have created extended attributes + in an original UFS2 file system then "fsck -p" will now fail due to + the unexpected presence of extended attributes and "fsck -y" will + remove all extended attributes. If you wish to preserve extended + attributes rather than delete them, there is a utility to convert + a UFS2 file system to UFS2ea and leave extended attributes in place, + but this should be used with caution since it will preserve any + extended attributes that have been corrupted by the backward + incompatibility too. + + If you wish to use a UFS2ea file system as your root file system, + then you will need to update your boot loader to a version that + supports UFS2ea. + + For more information, see: + https://wiki.netbsd.org/features/UFS2ea + 20221111: The new libdrm import worsened the conflict issues for the kdump/ktruss ioctl, and i915 now conflicts with base, and has Index: src/distrib/sets/lists/tests/mi =================================================================== RCS file: /home/chs/netbsd/cvs/src/distrib/sets/lists/tests/mi,v retrieving revision 1.1230 diff -u -p -r1.1230 mi --- src/distrib/sets/lists/tests/mi 10 Nov 2022 06:13:58 -0000 1.1230 +++ src/distrib/sets/lists/tests/mi 15 Nov 2022 01:41:40 -0000 @@ -4354,6 +4354,7 @@ ./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_quotas tests-sbin-tests compattestfile,atf +./usr/tests/sbin/fsck_ffs/t_extattr tests-sbin-tests compattestfile,atf ./usr/tests/sbin/gpt tests-sbin-tests compattestfile,atf ./usr/tests/sbin/gpt/Atffile tests-sbin-tests compattestfile,atf ./usr/tests/sbin/gpt/Kyuafile tests-sbin-tests compattestfile,atf,kyua 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 15 Nov 2022 01:41:40 -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.60 diff -u -p -r1.60 cgdconfig.c --- src/sbin/cgdconfig/cgdconfig.c 13 Sep 2022 10:14:32 -0000 1.60 +++ src/sbin/cgdconfig/cgdconfig.c 15 Nov 2022 01:41:40 -0000 @@ -1207,8 +1207,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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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/extern.h =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsck_ffs/extern.h,v retrieving revision 1.27 diff -u -p -r1.27 extern.h --- src/sbin/fsck_ffs/extern.h 9 Jun 2011 19:57:52 -0000 1.27 +++ src/sbin/fsck_ffs/extern.h 15 Nov 2022 01:41:40 -0000 @@ -42,6 +42,7 @@ void clri(struct inodesc *, const char int cmpsblks(const struct fs *, struct fs *); int cmpsblks42(const struct fs *, struct fs *); int cmpsblks44(const struct fs *, struct fs *); +void cvt_magic(struct fs *); union dinode * getnextinode(ino_t); void direrror(ino_t, const char *); int dirscan(struct inodesc *); 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 15 Nov 2022 01:41:40 -0000 @@ -166,6 +166,7 @@ extern struct fs *sblocksave; sb_oldfscompat_write(sblk.b_un.b_fs, sblocksave); \ if (needswap) \ ffs_sb_swap(sblk.b_un.b_fs, sblk.b_un.b_fs); \ + cvt_magic(sblk.b_un.b_fs); \ sblk.b_dirty = 1; \ } while (0) #define cgdirty() do {copyback_cg(&cgblk); cgblk.b_dirty = 1;} while (0) @@ -280,12 +281,15 @@ extern int zflag; /* zero unused direct extern int cvtlevel; /* convert to newer file system format */ 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 doing2noea; /* converting UFS2ea to UFS2 */ extern int newinofmt; /* filesystem has new inode format */ extern char usedsoftdep; /* just fix soft dependency inconsistencies */ extern int preen; /* just fix normal inconsistencies */ extern int quiet; /* Don't print anything if clean */ extern int forceimage; /* file system is an image file */ extern int is_ufs2; /* we're dealing with an UFS2 filesystem */ +extern int is_ufs2ea; /* is the variant that supports exattrs */ extern int markclean; /* mark file system clean when done */ extern char havesb; /* superblock has been read */ extern char skipclean; /* skip clean file systems if preening */ 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 15 Nov 2022 01:41:40 -0000 @@ -205,7 +205,23 @@ 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 +Convert the file system to the format which supports extended attributes +(and access control lists). +After this conversion is performed, the file system will no longer be +recognized at all by releases prior to +.Nx 10.0 . +.It no-ea +Convert the file system to the format which does not support extended attributes +(or access control lists). +This will remove any existing extended attributes, and the file system +will become recognizable to releases prior to +.Nx 10.0 . +.El .Pp In interactive mode, .Nm @@ -227,6 +243,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 15 Nov 2022 01:41:40 -0000 @@ -102,11 +102,14 @@ int zflag; int cvtlevel; int doinglevel1; int doinglevel2; +int doing2ea; +int doing2noea; int newinofmt; char usedsoftdep; int preen; int forceimage; int is_ufs2; +int is_ufs2ea; int markclean; char havesb; char skipclean; @@ -194,6 +197,14 @@ main(int argc, char *argv[]) case 'c': skipclean = 0; + if (strcmp(optarg, "ea") == 0) { + doing2ea = 1; + break; + } + if (strcmp(optarg, "no-ea") == 0) { + doing2noea = 1; + break; + } cvtlevel = argtoi('c', "conversion level", optarg, 10); if (cvtlevel > 4) { cvtlevel = 4; @@ -201,7 +212,7 @@ main(int argc, char *argv[]) cvtlevel); } break; - + case 'd': debug++; break; 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 15 Nov 2022 01:41:40 -0000 @@ -423,7 +423,23 @@ 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 && (!is_ufs2ea || doing2noea) && + (iswap32(dp->dp2.di_extsize) != 0 || + iswap64(dp->dp2.di_extb[0]) != 0 || + iswap64(dp->dp2.di_extb[1]) != 0)) { + pfatal("NON-ZERO EXTATTR FIELDS"); + if (!reply("CLEAR EXTATTR FIELDS AND 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 &= ~07777; + inodirty(); + } + if (is_ufs2ea && iswap32(dp->dp2.di_extsize) > 0) { int ret, offset; idesc->id_type = ADDR; ndb = howmany(iswap32(dp->dp2.di_extsize), sblock->fs_bsize); 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 15 Nov 2022 01:41:40 -0000 @@ -223,11 +223,13 @@ pass5(void) * write back the superblock to the spare at this * cylinder group. */ - if ((cvtlevel && sblk.b_dirty) || doswap) { + if ((cvtlevel && sblk.b_dirty) || doswap || doing2ea || doing2noea) { bwrite(fswritefd, sblk.b_un.b_buf, FFS_FSBTODB(sblock, cgsblock(sblock, c)), sblock->fs_sbsize); } else { + int alt_ufs2ea = 0; + /* * Read in the current alternate superblock, * and compare it to the master. If it's @@ -242,10 +244,15 @@ pass5(void) sblock->fs_sbsize); if (needswap) ffs_sb_swap(asblk.b_un.b_fs, altsblock); + if (altsblock->fs_magic == FS_UFS2EA_MAGIC) { + altsblock->fs_magic = FS_UFS2_MAGIC; + alt_ufs2ea = 1; + } } sb_oldfscompat_write(sblock, sblocksave); - if ((asblk.b_errs || cmpsblks(sblock, altsblock)) && - dofix(&idesc[3], + if ((asblk.b_errs || cmpsblks(sblock, altsblock) || + is_ufs2ea != alt_ufs2ea) && + dofix(&idesc[3], "ALTERNATE SUPERBLK(S) ARE INCORRECT")) { bwrite(fswritefd, sblk.b_un.b_buf, FFS_FSBTODB(sblock, cgsblock(sblock, c)), 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 15 Nov 2022 01:41:40 -0000 @@ -718,7 +718,8 @@ 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_UFS1_MAGIC || fs->fs_magic == FS_UFS2_MAGIC) { + if (fs->fs_magic == FS_UFS1_MAGIC || fs->fs_magic == FS_UFS2_MAGIC || + fs->fs_magic == FS_UFS2EA_MAGIC) { #ifndef NO_FFS_EI if (endian == 0 || BYTE_ORDER == endian) { needswap = 0; @@ -732,7 +733,8 @@ detect_byteorder(struct fs *fs, int sblo } #ifndef NO_FFS_EI else if (fs->fs_magic == FS_UFS1_MAGIC_SWAPPED || - fs->fs_magic == FS_UFS2_MAGIC_SWAPPED) { + fs->fs_magic == FS_UFS2_MAGIC_SWAPPED || + fs->fs_magic == FS_UFS2EA_MAGIC_SWAPPED) { if (endian == 0 || BYTE_ORDER != endian) { needswap = 1; doswap = do_blkswap = do_dirswap = 0; @@ -746,6 +748,29 @@ detect_byteorder(struct fs *fs, int sblo return -1; } +/* Update on-disk fs->fs_magic if we are converting */ +void +cvt_magic(struct fs *fs) +{ + + if (is_ufs2ea || doing2ea) { + if (fs->fs_magic == FS_UFS2_MAGIC) { + fs->fs_magic = FS_UFS2EA_MAGIC; + } + if (fs->fs_magic == FS_UFS2_MAGIC_SWAPPED) { + fs->fs_magic = FS_UFS2EA_MAGIC_SWAPPED; + } + } + if (doing2noea) { + if (fs->fs_magic == FS_UFS2EA_MAGIC) { + fs->fs_magic = FS_UFS2_MAGIC; + } + if (fs->fs_magic == FS_UFS2EA_MAGIC_SWAPPED) { + fs->fs_magic = FS_UFS2_MAGIC_SWAPPED; + } + } +} + /* * Possible superblock locations ordered from most to least likely. */ @@ -811,9 +836,15 @@ readsb(int listerr) memmove(sblock, sblk.b_un.b_fs, SBLOCKSIZE); if (needswap) ffs_sb_swap(sblk.b_un.b_fs, sblock); - + if (sblock->fs_magic == FS_UFS2EA_MAGIC) { + is_ufs2ea = 1; + sblock->fs_magic = FS_UFS2_MAGIC; + } is_ufs2 = sblock->fs_magic == FS_UFS2_MAGIC; + /* change on-disk magic if asked */ + cvt_magic(fs); + /* * run a few consistency checks of the super block */ @@ -845,6 +876,11 @@ readsb(int listerr) memmove(altsblock, asblk.b_un.b_fs, sblock->fs_sbsize); if (needswap) ffs_sb_swap(asblk.b_un.b_fs, altsblock); + if (altsblock->fs_magic == FS_UFS2EA_MAGIC) { + altsblock->fs_magic = FS_UFS2_MAGIC; + } + /* change on-disk magic if asked */ + cvt_magic(asblk.b_un.b_fs); if (cmpsblks(sblock, altsblock)) { if (debug) { uint32_t *nlp, *olp, *endlp; @@ -873,7 +909,7 @@ out: sb_oldfscompat_read(sblock, &sblocksave); /* Now we know the SB is valid, we can write it back if needed */ - if (doswap) { + if (doswap || doing2ea || doing2noea) { sbdirty(); dirty(&asblk); } 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 15 Nov 2022 01:41:40 -0000 @@ -324,6 +324,18 @@ ckfini(int noint) "\n***** FILE SYSTEM MARKED CLEAN *****\n"); } } + if (doing2ea) { + printf("ENABLING EXTATTR SUPPORT\n"); + is_ufs2ea = 1; + sbdirty(); + flush(fswritefd, &sblk); + } + if (doing2noea) { + printf("DISABLING EXTATTR SUPPORT\n"); + is_ufs2ea = 0; + 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.8 =================================================================== RCS file: /home/chs/netbsd/cvs/src/sbin/fsdb/fsdb.8,v retrieving revision 1.27 diff -u -p -r1.27 fsdb.8 --- src/sbin/fsdb/fsdb.8 29 May 2021 16:51:25 -0000 1.27 +++ src/sbin/fsdb/fsdb.8 15 Nov 2022 01:41:40 -0000 @@ -35,7 +35,7 @@ .Nd FFS debugging/editing tool .Sh SYNOPSIS .Nm -.Op Fl dFn +.Op Fl dFnN .Fl f Ar fsname .Sh DESCRIPTION .Nm @@ -74,6 +74,12 @@ The .Fl n option disables writing to the device, preventing any changes from being made to the filesystem. +.Pp +The +.Fl N +option causes the superblock not to be marked dirty when +.Nm +exits. .Sh COMMANDS Besides the built-in .Xr editline 3 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 15 Nov 2022 01:41:40 -0000 @@ -51,6 +51,7 @@ __RCSID("$NetBSD: fsdb.c,v 1.52 2021/05/ #include #include #include +#include #include #include @@ -91,13 +92,17 @@ int bflag; int debug; int zflag; int cvtlevel; +int eaflag; int doinglevel1; int doinglevel2; +int doing2ea; +int doing2noea; int newinofmt; char usedsoftdep; int preen; int forceimage; int is_ufs2; +int is_ufs2ea; int markclean; char havesb; char skipclean; @@ -137,6 +142,7 @@ static int scannames(struct inodesc *); static int dolookup(char *); static int chinumfunc(struct inodesc *); static int chnamefunc(struct inodesc *); +static int chreclenfunc(struct inodesc *); static int dotime(char *, int64_t *, int32_t *); static void print_blks32(int32_t *buf, int size, uint64_t *blknum, struct wrinfo *wrp); static void print_blks64(int64_t *buf, int size, uint64_t *blknum, struct wrinfo *wrp); @@ -160,7 +166,7 @@ ino_t curinum; static void usage(void) { - errx(1, "usage: %s [-dFn] -f ", getprogname()); + errx(1, "usage: %s [-dFfNn] ", getprogname()); } /* * We suck in lots of fsck code, and just pick & choose the stuff we want. @@ -173,11 +179,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++; @@ -188,6 +195,9 @@ main(int argc, char *argv[]) case 'f': fsys = optarg; break; + case 'N': + makedirty = false; + break; case 'n': nflag++; break; @@ -195,6 +205,10 @@ main(int argc, char *argv[]) usage(); } } + argc -= optind; + argv += optind; + if (fsys == NULL) + fsys = argv[0]; if (fsys == NULL) usage(); endian = 0; @@ -205,6 +219,10 @@ main(int argc, char *argv[]) rval = cmdloop(); if (nflag) exit(rval); + if (!makedirty) { + ckfini(1); + exit(rval); + } sblock->fs_clean = 0; /* mark it dirty */ sbdirty(); markclean = 0; @@ -245,6 +263,15 @@ CMDFUNC(chatime); /* Change atime */ CMDFUNC(chbirthtime); /* Change birthtime */ CMDFUNC(chinum); /* Change inode # of dirent */ CMDFUNC(chname); /* Change dirname of dirent */ +CMDFUNC(chreclen); /* Change reclen 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,13 +288,14 @@ 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}, {"ln", "Hardlink INO into current inode directory as NAME", 3, 3, ln}, {"chinum", "Change dir entry number INDEX to INUM", 3, 3, chinum}, {"chname", "Change dir entry number INDEX to NAME", 3, 3, chname}, + {"chreclen", "Change dir entry number INDEX to RECLEN", 3, 3, chreclen}, {"chtype", "Change type of current inode to TYPE", 2, 2, newtype}, {"chmod", "Change mode of current inode to MODE", 2, 2, chmode}, {"chown", "Change owner of current inode to OWNER", 2, 2, chowner}, @@ -276,11 +304,19 @@ 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}, @@ -491,6 +527,7 @@ static const char *typename[] = { "whiteout", }; +static int diroff; static int slot; static int @@ -498,10 +535,11 @@ scannames(struct inodesc *idesc) { struct direct *dirp = idesc->id_dirp; - printf("slot %d ino %d reclen %d: %s, `%.*s'\n", - slot++, iswap32(dirp->d_ino), iswap16(dirp->d_reclen), - typename[dirp->d_type], + printf("slot %d off %d ino %d reclen %d: %s, `%.*s'\n", + slot++, diroff, iswap32(dirp->d_ino), iswap16(dirp->d_reclen), + typename[dirp->d_type], dirp->d_namlen, dirp->d_name); + diroff += dirp->d_reclen; return (KEEPON); } @@ -511,6 +549,7 @@ CMDFUNC(ls) checkactivedir(); /* let it go on anyway */ slot = 0; + diroff = 0; idesc.id_number = curinum; idesc.id_func = scannames; idesc.id_type = DATA; @@ -524,16 +563,18 @@ CMDFUNC(ls) CMDFUNC(blks) { uint64_t blkno = 0; - int i, type; + 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); + wrinfo.size = iswap64(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))); @@ -564,6 +599,11 @@ CMDFUNC(blks) 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, @@ -827,7 +867,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 +877,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; @@ -1154,6 +1195,53 @@ CMDFUNC(chname) } } +static int +chreclenfunc(struct inodesc *idesc) +{ + struct direct *dirp = idesc->id_dirp; + + if (slotcount++ == desired) { + dirp->d_reclen = iswap16(idesc->id_parent); + return STOP | ALTERED | FOUND; + } + return KEEPON; +} + +CMDFUNC(chreclen) +{ + char *cp; + uint32_t reclen; + struct inodesc idesc; + + slotcount = 0; + if (!checkactivedir()) + return 1; + + desired = strtoul(argv[1], &cp, 0); + if (cp == argv[1] || *cp != '\0') { + printf("invalid slot number `%s'\n", argv[1]); + return 1; + } + reclen = strtoul(argv[2], &cp, 0); + if (reclen >= UINT16_MAX) { + printf("invalid reclen `%s'\n", argv[2]); + return 1; + } + + idesc.id_number = curinum; + idesc.id_func = chreclenfunc; + idesc.id_fix = IGNORE; + idesc.id_type = DATA; + idesc.id_parent = reclen; /* XXX convenient hiding place */ + + if (ckinode(curinode, &idesc) & FOUND) + return 0; + else { + warnx("no %sth slot in current directory", argv[1]); + return 1; + } +} + static struct typemap { const char *typename; int typebits; @@ -1162,6 +1250,9 @@ static struct typemap { { "dir", IFDIR }, { "socket", IFSOCK }, { "fifo", IFIFO }, + {"link", IFLNK}, + {"chr", IFCHR}, + {"blk", IFBLK}, }; CMDFUNC(newtype) @@ -1217,13 +1308,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 +1372,160 @@ CMDFUNC(chgen) return 0; } +CMDFUNC(chextsize) +{ + 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 0; +} + +CMDFUNC(chblocks) +{ + 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 0; +} + +CMDFUNC(chdb) +{ + 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 0; +} + +CMDFUNC(chib) +{ + 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 0; +} + +CMDFUNC(chextb) +{ + 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 0; +} + +CMDFUNC(chfreelink) +{ +#if 0 + 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; + } + + DIP_SET(curinode, freelink, freelink); + inodirty(); + printactive(); +#endif + return 0; +} + CMDFUNC(linkcount) { int lcnt; @@ -1418,6 +1663,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 +1679,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 +1695,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 +1715,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 +1726,43 @@ CMDFUNC(chbirthtime) printactive(); return 0; } + +CMDFUNC(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 15 Nov 2022 01:41:40 -0000 @@ -95,11 +95,13 @@ printstat(const char *cp, ino_t inum, un time_t t; char *p; uint64_t size, blocks; + uint32_t extsize; 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 +141,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=%u", (unsigned long long)inum, + mode, (unsigned long long)size, 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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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_vfsops.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/sys/ufs/ffs/ffs_vfsops.c,v retrieving revision 1.377 diff -u -p -r1.377 ffs_vfsops.c --- src/sys/ufs/ffs/ffs_vfsops.c 10 Nov 2022 10:53:29 -0000 1.377 +++ src/sys/ufs/ffs/ffs_vfsops.c 15 Nov 2022 01:41:40 -0000 @@ -845,6 +845,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); @@ -1217,6 +1226,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; @@ -2375,6 +2391,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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -0000 @@ -9,4 +9,6 @@ TESTS_SH+= ${name} TESTS_SH_SRC_${name}= quotas_common.sh ${name}.sh .endfor +TESTS_SH+= t_extattr + .include Index: src/tests/sbin/fsck_ffs/t_extattr.sh =================================================================== RCS file: src/tests/sbin/fsck_ffs/t_extattr.sh diff -N src/tests/sbin/fsck_ffs/t_extattr.sh --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/tests/sbin/fsck_ffs/t_extattr.sh 15 Nov 2022 01:41:40 -0000 @@ -0,0 +1,197 @@ +# $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_extattr_enable cleanup +atf_test_case fsck_extattr_enable_corrupted cleanup +atf_test_case fsck_extattr_disable cleanup + +cleanup() +{ + echo in cleanup + umount -f ${MNT} > /dev/null 2>&1 || true + vnconfig -u ${VND} > /dev/null 2>&1 || true +} + +fsck_extattr_enable_head() +{ + atf_set "descr" "Checks fsck_ffs enabling extattrs" +} + +fsck_extattr_enable_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_extattr_enable_cleanup() +{ + cleanup +} + +fsck_extattr_enable_corrupted_head() +{ + atf_set "descr" "Checks fsck_ffs enabling extattrs with corruption" +} + +fsck_extattr_enable_corrupted_body() +{ + atf_check mkdir -p ${MNT} + + # Create an fs with extattrs enabled and set an extattr 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 + + # Convert to 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 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_extattr_enable_corrupted_cleanup() +{ + cleanup +} + +fsck_extattr_disable_head() +{ + atf_set "descr" "Checks fsck_ffs disabling extattrs" +} + +fsck_extattr_disable_body() +{ + atf_check mkdir -p ${MNT} + + # Create an fs with extattrs enabled and set an extattr 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} + + # Convert to disable extattrs. + atf_check -o 'match:CLEAR EXTATTR FIELDS' \ + -o 'match:DISABLING EXTATTR SUPPORT' \ + fsck_ffs -y -c no-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:getextattr: mnt/file: failed: Operation not supported' \ + getextattr user testname ${MNT}/file + atf_check umount ${MNT} + + # Convert to enable extattrs again. + atf_check -o 'match:ENABLING EXTATTR SUPPORT' \ + fsck_ffs -y -c ea ${CDEV} + + # Verify that the test extattr is still gone. + 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_extattr_disable_cleanup() +{ + cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case fsck_extattr_enable + atf_add_test_case fsck_extattr_enable_corrupted + atf_add_test_case fsck_extattr_disable +} 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 15 Nov 2022 01:41:40 -0000 @@ -192,11 +192,13 @@ dumpfs(const char *name) if (read(fd, &afs, SBLOCKSIZE) != SBLOCKSIZE) continue; switch(afs.fs_magic) { + case FS_UFS2EA_MAGIC: case FS_UFS2_MAGIC: is_ufs2 = 1; break; case FS_UFS1_MAGIC: break; + case FS_UFS2EA_MAGIC_SWAPPED: case FS_UFS2_MAGIC_SWAPPED: is_ufs2 = 1; needswap = 1; @@ -294,7 +296,8 @@ 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, + fs->fs_magic == FS_UFS2EA_MAGIC ? "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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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/ffs_balloc.c =================================================================== RCS file: /home/chs/netbsd/cvs/src/usr.sbin/makefs/ffs/ffs_balloc.c,v retrieving revision 1.21 diff -u -p -r1.21 ffs_balloc.c --- src/usr.sbin/makefs/ffs/ffs_balloc.c 29 Mar 2015 05:52:59 -0000 1.21 +++ src/usr.sbin/makefs/ffs/ffs_balloc.c 15 Nov 2022 01:41:40 -0000 @@ -74,7 +74,8 @@ static int ffs_balloc_ufs2(struct inode int ffs_balloc(struct inode *ip, off_t offset, int bufsize, struct buf **bpp) { - if (ip->i_fs->fs_magic == FS_UFS2_MAGIC) + if (ip->i_fs->fs_magic == FS_UFS2_MAGIC || + ip->i_fs->fs_magic == FS_UFS2EA_MAGIC) return ffs_balloc_ufs2(ip, offset, bufsize, bpp); else return ffs_balloc_ufs1(ip, offset, bufsize, bpp); 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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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 15 Nov 2022 01:41:40 -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.41 diff -u -p -r1.41 label.c --- src/usr.sbin/sysinst/label.c 21 Jun 2022 15:46:10 -0000 1.41 +++ src/usr.sbin/sysinst/label.c 15 Nov 2022 01:41:40 -0000 @@ -2023,7 +2023,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;