summaryrefslogtreecommitdiffstats
path: root/sbin/fsdb
diff options
context:
space:
mode:
authormckusick <mckusick@FreeBSD.org>2002-06-21 06:18:05 +0000
committermckusick <mckusick@FreeBSD.org>2002-06-21 06:18:05 +0000
commit88d85c15ef183c06524d6ca695f62c0c0672b00c (patch)
treef1364dbfb9835934a3879b5904f7ff9a1495744c /sbin/fsdb
parenteacb69b0197a8553d5004aa99532cabad8778e36 (diff)
downloadFreeBSD-src-88d85c15ef183c06524d6ca695f62c0c0672b00c.zip
FreeBSD-src-88d85c15ef183c06524d6ca695f62c0c0672b00c.tar.gz
This commit adds basic support for the UFS2 filesystem. The UFS2
filesystem expands the inode to 256 bytes to make space for 64-bit block pointers. It also adds a file-creation time field, an ability to use jumbo blocks per inode to allow extent like pointer density, and space for extended attributes (up to twice the filesystem block size worth of attributes, e.g., on a 16K filesystem, there is space for 32K of attributes). UFS2 fully supports and runs existing UFS1 filesystems. New filesystems built using newfs can be built in either UFS1 or UFS2 format using the -O option. In this commit UFS1 is the default format, so if you want to build UFS2 format filesystems, you must specify -O 2. This default will be changed to UFS2 when UFS2 proves itself to be stable. In this commit the boot code for reading UFS2 filesystems is not compiled (see /sys/boot/common/ufsread.c) as there is insufficient space in the boot block. Once the size of the boot block is increased, this code can be defined. Things to note: the definition of SBSIZE has changed to SBLOCKSIZE. The header file <ufs/ufs/dinode.h> must be included before <ufs/ffs/fs.h> so as to get the definitions of ufs2_daddr_t and ufs_lbn_t. Still TODO: Verify that the first level bootstraps work for all the architectures. Convert the utility ffsinfo to understand UFS2 and test growfs. Add support for the extended attribute storage. Update soft updates to ensure integrity of extended attribute storage. Switch the current extended attribute interfaces to use the extended attribute storage. Add the extent like functionality (framework is there, but is currently never used). Sponsored by: DARPA & NAI Labs. Reviewed by: Poul-Henning Kamp <phk@freebsd.org>
Diffstat (limited to 'sbin/fsdb')
-rw-r--r--sbin/fsdb/fsdb.c72
-rw-r--r--sbin/fsdb/fsdb.h10
-rw-r--r--sbin/fsdb/fsdbutil.c103
3 files changed, 117 insertions, 68 deletions
diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c
index 0f32762..9971b7c 100644
--- a/sbin/fsdb/fsdb.c
+++ b/sbin/fsdb/fsdb.c
@@ -280,7 +280,7 @@ cmdloop(void)
return rval;
}
-struct dinode *curinode;
+union dinode *curinode;
ino_t curinum, ocurrent;
#define GETINUM(ac,inum) inum = strtoul(argv[ac], &cp, 0); \
@@ -317,7 +317,7 @@ CMDFUNCSTART(back)
CMDFUNCSTART(zapi)
{
ino_t inum;
- struct dinode *dp;
+ union dinode *dp;
char *cp;
GETINUM(1,inum);
@@ -350,7 +350,8 @@ CMDFUNCSTART(uplink)
{
if (!checkactive())
return 1;
- printf("inode %d link count now %d\n", curinum, ++curinode->di_nlink);
+ DIP(curinode, di_nlink) += 1;
+ printf("inode %d link count now %d\n", curinum, DIP(curinode, di_nlink));
inodirty();
return 0;
}
@@ -359,7 +360,8 @@ CMDFUNCSTART(downlink)
{
if (!checkactive())
return 1;
- printf("inode %d link count now %d\n", curinum, --curinode->di_nlink);
+ DIP(curinode, di_nlink) -= 1;
+ printf("inode %d link count now %d\n", curinum, DIP(curinode, di_nlink));
inodirty();
return 0;
}
@@ -617,7 +619,7 @@ CMDFUNCSTART(newtype)
if (!checkactive())
return 1;
- type = curinode->di_mode & IFMT;
+ type = DIP(curinode, di_mode) & IFMT;
for (tp = typenamemap;
tp < &typenamemap[sizeof(typenamemap)/sizeof(*typenamemap)];
tp++) {
@@ -632,8 +634,8 @@ CMDFUNCSTART(newtype)
warnx("try one of `file', `dir', `socket', `fifo'");
return 1;
}
- curinode->di_mode &= ~IFMT;
- curinode->di_mode |= type;
+ DIP(curinode, di_mode) &= ~IFMT;
+ DIP(curinode, di_mode) |= type;
inodirty();
printactive(0);
return 0;
@@ -654,7 +656,7 @@ CMDFUNCSTART(chlen)
return 1;
}
- curinode->di_size = len;
+ DIP(curinode, di_size) = len;
inodirty();
printactive(0);
return rval;
@@ -675,8 +677,8 @@ CMDFUNCSTART(chmode)
return 1;
}
- curinode->di_mode &= ~07777;
- curinode->di_mode |= modebits;
+ DIP(curinode, di_mode) &= ~07777;
+ DIP(curinode, di_mode) |= modebits;
inodirty();
printactive(0);
return rval;
@@ -701,7 +703,7 @@ CMDFUNCSTART(chaflags)
warnx("flags set beyond 32-bit range of field (%lx)\n", flags);
return(1);
}
- curinode->di_flags = flags;
+ DIP(curinode, di_flags) = flags;
inodirty();
printactive(0);
return rval;
@@ -726,7 +728,7 @@ CMDFUNCSTART(chgen)
warnx("gen set beyond 32-bit range of field (%lx)\n", gen);
return(1);
}
- curinode->di_gen = gen;
+ DIP(curinode, di_gen) = gen;
inodirty();
printactive(0);
return rval;
@@ -751,7 +753,7 @@ CMDFUNCSTART(linkcount)
return 1;
}
- curinode->di_nlink = lcnt;
+ DIP(curinode, di_nlink) = lcnt;
inodirty();
printactive(0);
return rval;
@@ -778,7 +780,7 @@ CMDFUNCSTART(chowner)
}
}
- curinode->di_uid = uid;
+ DIP(curinode, di_uid) = uid;
inodirty();
printactive(0);
return rval;
@@ -804,18 +806,17 @@ CMDFUNCSTART(chgroup)
}
}
- curinode->di_gid = gid;
+ DIP(curinode, di_gid) = gid;
inodirty();
printactive(0);
return rval;
}
int
-dotime(char *name, struct timespec *rts)
+dotime(char *name, time_t *secp, int32_t *nsecp)
{
char *p, *val;
struct tm t;
- int32_t sec;
int32_t nsec;
p = strchr(name, '.');
if (p) {
@@ -832,6 +833,7 @@ badformat:
warnx("date format: YYYYMMDDHHMMSS[.nsec]");
return 1;
}
+ *nsecp = nsec;
for (p = name; *p; p++)
if (*p < '0' || *p > '9')
@@ -855,20 +857,26 @@ badformat:
t.tm_sec = VAL() + t.tm_sec * 10;
t.tm_isdst = -1;
- sec = mktime(&t);
- if (sec == -1) {
+ *secp = mktime(&t);
+ if (*secp == -1) {
warnx("date/time out of range");
return 1;
}
- rts->tv_sec = sec;
- rts->tv_nsec = nsec;
return 0;
}
CMDFUNCSTART(chmtime)
{
- if (dotime(argv[1], &curinode->di_ctime))
+ time_t secs;
+ int32_t nsecs;
+
+ if (dotime(argv[1], &secs, &nsecs))
return 1;
+ if (sblock.fs_magic == FS_UFS1_MAGIC)
+ curinode->dp1.di_mtime = _time_to_time32(secs);
+ else
+ curinode->dp2.di_mtime = _time_to_time64(secs);
+ DIP(curinode, di_mtimensec) = nsecs;
inodirty();
printactive(0);
return 0;
@@ -876,8 +884,16 @@ CMDFUNCSTART(chmtime)
CMDFUNCSTART(chatime)
{
- if (dotime(argv[1], &curinode->di_ctime))
+ time_t secs;
+ int32_t nsecs;
+
+ if (dotime(argv[1], &secs, &nsecs))
return 1;
+ if (sblock.fs_magic == FS_UFS1_MAGIC)
+ curinode->dp1.di_atime = _time_to_time32(secs);
+ else
+ curinode->dp2.di_atime = _time_to_time64(secs);
+ DIP(curinode, di_atimensec) = nsecs;
inodirty();
printactive(0);
return 0;
@@ -885,8 +901,16 @@ CMDFUNCSTART(chatime)
CMDFUNCSTART(chctime)
{
- if (dotime(argv[1], &curinode->di_ctime))
+ time_t secs;
+ int32_t nsecs;
+
+ if (dotime(argv[1], &secs, &nsecs))
return 1;
+ if (sblock.fs_magic == FS_UFS1_MAGIC)
+ curinode->dp1.di_ctime = _time_to_time32(secs);
+ else
+ curinode->dp2.di_ctime = _time_to_time64(secs);
+ DIP(curinode, di_ctimensec) = nsecs;
inodirty();
printactive(0);
return 0;
diff --git a/sbin/fsdb/fsdb.h b/sbin/fsdb/fsdb.h
index be16016..442ae12 100644
--- a/sbin/fsdb/fsdb.h
+++ b/sbin/fsdb/fsdb.h
@@ -30,9 +30,9 @@
* $FreeBSD$
*/
-extern int bread(int fd, char *buf, ufs_daddr_t blk, long size);
-extern void bwrite(int fd, char *buf, ufs_daddr_t blk, long size);
-extern void rwerror(char *mesg, ufs_daddr_t blk);
+extern int bread(int fd, char *buf, ufs2_daddr_t blk, long size);
+extern void bwrite(int fd, char *buf, ufs2_daddr_t blk, long size);
+extern void rwerror(char *mesg, ufs2_daddr_t blk);
extern int reply(char *question);
extern long dev_bsize;
@@ -50,13 +50,13 @@ struct cmdtable {
#define FL_WR 0x0001 /* wants to write */
int (*handler)(int argc, char *argv[]);
};
-extern struct dinode *curinode;
+extern union dinode *curinode;
extern ino_t curinum;
int argcount(struct cmdtable *cmdp, int argc, char *argv[]);
char **crack(char *line, int *argc);
char **recrack(char *line, int *argc, int argc_max);
-void printstat(const char *cp, ino_t inum, struct dinode *dp);
+void printstat(const char *cp, ino_t inum, union dinode *dp);
int printactive(int doblocks);
int checkactive(void);
int checkactivedir(void);
diff --git a/sbin/fsdb/fsdbutil.c b/sbin/fsdb/fsdbutil.c
index 96c48b0..b0d4c12 100644
--- a/sbin/fsdb/fsdbutil.c
+++ b/sbin/fsdb/fsdbutil.c
@@ -50,8 +50,8 @@ static const char rcsid[] =
#include "fsck.h"
static int charsperline(void);
-static int printindir(ufs_daddr_t blk, int level, char *bufp);
-static void printblocks(ino_t inum, struct dinode *dp);
+static int printindir(ufs2_daddr_t blk, int level, char *bufp);
+static void printblocks(ino_t inum, union dinode *dp);
char **
crack(char *line, int *argc)
@@ -106,15 +106,17 @@ argcount(struct cmdtable *cmdp, int argc, char *argv[])
}
void
-printstat(const char *cp, ino_t inum, struct dinode *dp)
+printstat(const char *cp, ino_t inum, union dinode *dp)
{
struct group *grp;
struct passwd *pw;
+ ufs2_daddr_t blocks;
+ int64_t gen;
char *p;
time_t t;
printf("%s: ", cp);
- switch (dp->di_mode & IFMT) {
+ switch (DIP(dp, di_mode) & IFMT) {
case IFDIR:
puts("directory");
break;
@@ -123,19 +125,25 @@ printstat(const char *cp, ino_t inum, struct dinode *dp)
break;
case IFBLK:
printf("block special (%d,%d)",
- major(dp->di_rdev), minor(dp->di_rdev));
+ major(DIP(dp, di_rdev)), minor(DIP(dp, di_rdev)));
break;
case IFCHR:
printf("character special (%d,%d)",
- major(dp->di_rdev), minor(dp->di_rdev));
+ major(DIP(dp, di_rdev)), minor(DIP(dp, di_rdev)));
break;
case IFLNK:
fputs("symlink",stdout);
- if (dp->di_size > 0 && dp->di_size < MAXSYMLINKLEN &&
- dp->di_blocks == 0)
- printf(" to `%.*s'\n", (int) dp->di_size, (char *)dp->di_shortlink);
- else
- putchar('\n');
+ if (DIP(dp, di_size) > 0 &&
+ DIP(dp, di_size) < sblock.fs_maxsymlinklen &&
+ DIP(dp, di_blocks) == 0) {
+ if (sblock.fs_magic == FS_UFS1_MAGIC)
+ p = (caddr_t)dp->dp1.di_db;
+ else
+ p = (caddr_t)dp->dp2.di_db;
+ printf(" to `%.*s'\n", (int) DIP(dp, di_size), p);
+ } else {
+ putchar('\n');
+ }
break;
case IFSOCK:
puts("socket");
@@ -144,31 +152,43 @@ printstat(const char *cp, ino_t inum, struct dinode *dp)
puts("fifo");
break;
}
- printf("I=%lu MODE=%o SIZE=%qu", (u_long)inum, dp->di_mode, dp->di_size);
- t = dp->di_mtime;
+ printf("I=%lu MODE=%o SIZE=%qu", (u_long)inum, DIP(dp, di_mode),
+ DIP(dp, di_size));
+ if (sblock.fs_magic == FS_UFS1_MAGIC)
+ t = _time32_to_time(dp->dp1.di_mtime);
+ else
+ t = _time64_to_time(dp->dp2.di_mtime);
p = ctime(&t);
printf("\n\tMTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20],
- dp->di_mtimensec);
- t = dp->di_ctime;
+ DIP(dp, di_mtimensec));
+ if (sblock.fs_magic == FS_UFS1_MAGIC)
+ t = _time32_to_time(dp->dp1.di_ctime);
+ else
+ t = _time64_to_time(dp->dp2.di_ctime);
p = ctime(&t);
printf("\n\tCTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20],
- dp->di_ctimensec);
- t = dp->di_atime;
+ DIP(dp, di_ctimensec));
+ if (sblock.fs_magic == FS_UFS1_MAGIC)
+ t = _time32_to_time(dp->dp1.di_atime);
+ else
+ t = _time64_to_time(dp->dp2.di_atime);
p = ctime(&t);
printf("\n\tATIME=%15.15s %4.4s [%d nsec]\n", &p[4], &p[20],
- dp->di_atimensec);
+ DIP(dp, di_atimensec));
- if ((pw = getpwuid(dp->di_uid)))
+ if ((pw = getpwuid(DIP(dp, di_uid))))
printf("OWNER=%s ", pw->pw_name);
else
- printf("OWNUID=%u ", dp->di_uid);
- if ((grp = getgrgid(dp->di_gid)))
+ printf("OWNUID=%u ", DIP(dp, di_uid));
+ if ((grp = getgrgid(DIP(dp, di_gid))))
printf("GRP=%s ", grp->gr_name);
else
- printf("GID=%u ", dp->di_gid);
+ printf("GID=%u ", DIP(dp, di_gid));
- printf("LINKCNT=%hd FLAGS=%#x BLKCNT=%x GEN=%x\n", dp->di_nlink, dp->di_flags,
- dp->di_blocks, dp->di_gen);
+ blocks = DIP(dp, di_blocks);
+ gen = DIP(dp, di_gen);
+ printf("LINKCNT=%hd FLAGS=%#x BLKCNT=%qx GEN=%qx\n", DIP(dp, di_nlink),
+ DIP(dp, di_flags), blocks, gen);
}
@@ -199,12 +219,12 @@ charsperline(void)
* Recursively print a list of indirect blocks.
*/
static int
-printindir(ufs_daddr_t blk, int level, char *bufp)
+printindir(ufs2_daddr_t blk, int level, char *bufp)
{
struct bufarea buf, *bp;
- char tempbuf[32]; /* enough to print an ufs_daddr_t */
+ char tempbuf[32]; /* enough to print an ufs2_daddr_t */
int i, j, cpl, charssofar;
- ufs_daddr_t blkno;
+ ufs2_daddr_t blkno;
if (level == 0) {
/* for the final indirect level, don't use the cache */
@@ -219,13 +239,16 @@ printindir(ufs_daddr_t blk, int level, char *bufp)
cpl = charsperline();
for (i = charssofar = 0; i < NINDIR(&sblock); i++) {
- blkno = bp->b_un.b_indir[i];
+ if (sblock.fs_magic == FS_UFS1_MAGIC)
+ blkno = bp->b_un.b_indir1[i];
+ else
+ blkno = bp->b_un.b_indir2[i];
if (blkno == 0) {
if (level == 0)
putchar('\n');
return 0;
}
- j = sprintf(tempbuf, "%d", blkno);
+ j = sprintf(tempbuf, "%qd", blkno);
if (level == 0) {
charssofar += j;
if (charssofar >= cpl - 2) {
@@ -253,30 +276,32 @@ printindir(ufs_daddr_t blk, int level, char *bufp)
* Print the block pointers for one inode.
*/
static void
-printblocks(ino_t inum, struct dinode *dp)
+printblocks(ino_t inum, union dinode *dp)
{
char *bufp;
int i, j, nfrags;
long ndb, offset;
+ ufs2_daddr_t blkno;
printf("Blocks for inode %d:\n", inum);
printf("Direct blocks:\n");
- ndb = howmany(dp->di_size, sblock.fs_bsize);
+ ndb = howmany(DIP(dp, di_size), sblock.fs_bsize);
for (i = 0; i < NDADDR; i++) {
- if (dp->di_db[i] == 0) {
+ if (DIP(dp, di_db[i]) == 0) {
putchar('\n');
return;
}
if (i > 0)
printf(", ");
- printf("%d", dp->di_db[i]);
- if (--ndb == 0 && (offset = blkoff(&sblock, dp->di_size)) != 0) {
+ blkno = DIP(dp, di_db[i]);
+ printf("%qd", blkno);
+ if (--ndb == 0 && (offset = blkoff(&sblock, DIP(dp, di_size))) != 0) {
nfrags = numfrags(&sblock, fragroundup(&sblock, offset));
printf(" (%d frag%s)", nfrags, nfrags > 1? "s": "");
}
}
putchar('\n');
- if (dp->di_ib[0] == 0)
+ if (DIP(dp, di_ib[0]) == 0)
return;
bufp = malloc((unsigned int)sblock.fs_bsize);
@@ -284,7 +309,7 @@ printblocks(ino_t inum, struct dinode *dp)
errx(EEXIT, "cannot allocate indirect block buffer");
printf("Indirect blocks:\n");
for (i = 0; i < NIADDR; i++)
- if (printindir(dp->di_ib[i], i, bufp) == 0)
+ if (printindir(DIP(dp, di_ib[i]), i, bufp) == 0)
break;
free(bufp);
}
@@ -307,7 +332,7 @@ checkactivedir(void)
warnx("no current inode\n");
return 0;
}
- if ((curinode->di_mode & IFMT) != IFDIR) {
+ if ((DIP(curinode, di_mode) & IFMT) != IFDIR) {
warnx("inode %d not a directory", curinum);
return 0;
}
@@ -319,7 +344,7 @@ printactive(int doblocks)
{
if (!checkactive())
return 1;
- switch (curinode->di_mode & IFMT) {
+ switch (DIP(curinode, di_mode) & IFMT) {
case IFDIR:
case IFREG:
case IFBLK:
@@ -337,7 +362,7 @@ printactive(int doblocks)
break;
default:
printf("current inode %d: screwy itype 0%o (mode 0%o)?\n",
- curinum, curinode->di_mode & IFMT, curinode->di_mode);
+ curinum, DIP(curinode, di_mode) & IFMT, DIP(curinode, di_mode));
break;
}
return 0;
OpenPOWER on IntegriCloud