diff options
Diffstat (limited to 'sbin/fsdb')
-rw-r--r-- | sbin/fsdb/fsdb.c | 54 | ||||
-rw-r--r-- | sbin/fsdb/fsdb.h | 6 | ||||
-rw-r--r-- | sbin/fsdb/fsdbutil.c | 58 |
3 files changed, 68 insertions, 50 deletions
diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c index cd8adb5ba1a..f842fc92548 100644 --- a/sbin/fsdb/fsdb.c +++ b/sbin/fsdb/fsdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsdb.c,v 1.19 2007/02/20 22:23:57 jmc Exp $ */ +/* $OpenBSD: fsdb.c,v 1.20 2007/04/10 17:17:25 millert Exp $ */ /* $NetBSD: fsdb.c,v 1.7 1997/01/11 06:50:53 lukem Exp $ */ /*- @@ -38,7 +38,7 @@ */ #ifndef lint -static const char rcsid[] = "$OpenBSD: fsdb.c,v 1.19 2007/02/20 22:23:57 jmc Exp $"; +static const char rcsid[] = "$OpenBSD: fsdb.c,v 1.20 2007/04/10 17:17:25 millert Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -80,7 +80,7 @@ static int chnamefunc(struct inodesc *); static int dotime(char *, int32_t *, int32_t *); int returntosingle = 0; -struct ufs1_dinode *curinode; +union dinode *curinode; ino_t curinum; static void @@ -328,7 +328,7 @@ CMDFUNCSTART(back) CMDFUNCSTART(zapi) { ino_t inum; - struct ufs1_dinode *dp; + union dinode *dp; char *cp; GETINUM(1,inum); @@ -356,7 +356,8 @@ CMDFUNCSTART(uplink) { if (!checkactive()) return 1; - printf("inode %d link count now %d\n", curinum, ++curinode->di_nlink); + DIP_SET(curinode, di_nlink, DIP(curinode, di_nlink) + 1); + printf("inode %d link count now %d\n", curinum, DIP(curinode, di_nlink)); inodirty(); return 0; } @@ -365,7 +366,8 @@ CMDFUNCSTART(downlink) { if (!checkactive()) return 1; - printf("inode %d link count now %d\n", curinum, --curinode->di_nlink); + DIP_SET(curinode, di_nlink, DIP(curinode, di_nlink) - 1); + printf("inode %d link count now %d\n", curinum, DIP(curinode, di_nlink)); inodirty(); return 0; } @@ -621,7 +623,7 @@ CMDFUNCSTART(newtype) if (!checkactive()) return 1; - type = curinode->di_mode & IFMT; + type = DIP(curinode, di_mode) & IFMT; for (tp = typenamemap; tp < &typenamemap[sizeof(typemap)/sizeof(*typemap)]; tp++) { @@ -636,8 +638,8 @@ CMDFUNCSTART(newtype) warnx("try one of `file', `dir', `socket', `fifo'"); return 1; } - curinode->di_mode &= ~IFMT; - curinode->di_mode |= type; + DIP_SET(curinode, di_mode, DIP(curinode, di_mode) & ~IFMT); + DIP_SET(curinode, di_mode, DIP(curinode, di_mode) | type); inodirty(); printactive(); return 0; @@ -658,8 +660,8 @@ CMDFUNCSTART(chmode) return 1; } - curinode->di_mode &= ~07777; - curinode->di_mode |= modebits; + DIP_SET(curinode, di_mode, DIP(curinode, di_mode) & ~07777); + DIP_SET(curinode, di_mode, DIP(curinode, di_mode) | modebits); inodirty(); printactive(); return rval; @@ -680,7 +682,7 @@ CMDFUNCSTART(chlen) return 1; } - curinode->di_size = len; + DIP_SET(curinode, di_size, len); inodirty(); printactive(); return rval; @@ -705,7 +707,7 @@ CMDFUNCSTART(chaflags) warnx("flags set beyond 32-bit range of field (%lx)", flags); return(1); } - curinode->di_flags = flags; + DIP_SET(curinode, di_flags, flags); inodirty(); printactive(); return rval; @@ -730,7 +732,7 @@ CMDFUNCSTART(chgen) warnx("gen set beyond 32-bit range of field (%lx)", gen); return(1); } - curinode->di_gen = gen; + DIP_SET(curinode, di_gen, gen); inodirty(); printactive(); return rval; @@ -755,7 +757,7 @@ CMDFUNCSTART(linkcount) return 1; } - curinode->di_nlink = lcnt; + DIP_SET(curinode, di_nlink, lcnt); inodirty(); printactive(); return rval; @@ -782,7 +784,7 @@ CMDFUNCSTART(chowner) } } - curinode->di_uid = uid; + DIP_SET(curinode, di_uid, uid); inodirty(); printactive(); return rval; @@ -808,7 +810,7 @@ CMDFUNCSTART(chgroup) } } - curinode->di_gid = gid; + DIP_SET(curinode, di_gid, gid); inodirty(); printactive(); return rval; @@ -873,8 +875,12 @@ badformat: CMDFUNCSTART(chmtime) { - if (dotime(argv[1], &curinode->di_mtime, &curinode->di_mtimensec)) + int32_t rsec, nsec; + + if (dotime(argv[1], &rsec, &nsec)) return 1; + DIP_SET(curinode, di_mtime, rsec); + DIP_SET(curinode, di_mtimensec, nsec); inodirty(); printactive(); return 0; @@ -882,8 +888,12 @@ CMDFUNCSTART(chmtime) CMDFUNCSTART(chatime) { - if (dotime(argv[1], &curinode->di_atime, &curinode->di_atimensec)) + int32_t rsec, nsec; + + if (dotime(argv[1], &rsec, &nsec)) return 1; + DIP_SET(curinode, di_atime, rsec); + DIP_SET(curinode, di_atimensec, nsec); inodirty(); printactive(); return 0; @@ -891,8 +901,12 @@ CMDFUNCSTART(chatime) CMDFUNCSTART(chctime) { - if (dotime(argv[1], &curinode->di_ctime, &curinode->di_ctimensec)) + int32_t rsec, nsec; + + if (dotime(argv[1], &rsec, &nsec)) return 1; + DIP_SET(curinode, di_ctime, rsec); + DIP_SET(curinode, di_ctimensec, nsec); inodirty(); printactive(); return 0; diff --git a/sbin/fsdb/fsdb.h b/sbin/fsdb/fsdb.h index db42e8f9034..ff0f31f08e0 100644 --- a/sbin/fsdb/fsdb.h +++ b/sbin/fsdb/fsdb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fsdb.h,v 1.5 2003/08/25 23:28:15 tedu Exp $ */ +/* $OpenBSD: fsdb.h,v 1.6 2007/04/10 17:17:25 millert Exp $ */ /* $NetBSD: fsdb.h,v 1.4 1996/09/28 19:30:36 christos Exp $ */ /*- @@ -54,12 +54,12 @@ struct cmdtable { unsigned int maxargc; int (*handler)(int argc, char *argv[]); }; -extern struct ufs1_dinode *curinode; +extern union dinode *curinode; extern ino_t curinum; char **crack(char *, int *); int argcount(struct cmdtable *, int, char *[]); -void printstat(const char *, ino_t, struct ufs1_dinode *); +void printstat(const char *, ino_t, union dinode *); int checkactive(void); int checkactivedir(void); int printactive(void); diff --git a/sbin/fsdb/fsdbutil.c b/sbin/fsdb/fsdbutil.c index 7db4aae82f1..610eae92768 100644 --- a/sbin/fsdb/fsdbutil.c +++ b/sbin/fsdb/fsdbutil.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fsdbutil.c,v 1.11 2005/12/19 15:18:01 pedro Exp $ */ +/* $OpenBSD: fsdbutil.c,v 1.12 2007/04/10 17:17:25 millert Exp $ */ /* $NetBSD: fsdbutil.c,v 1.5 1996/09/28 19:30:37 christos Exp $ */ /*- @@ -38,7 +38,7 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: fsdbutil.c,v 1.11 2005/12/19 15:18:01 pedro Exp $"; +static char rcsid[] = "$OpenBSD: fsdbutil.c,v 1.12 2007/04/10 17:17:25 millert Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -94,7 +94,7 @@ argcount(struct cmdtable *cmdp, int argc, char *argv[]) } void -printstat(const char *cp, ino_t inum, struct ufs1_dinode *dp) +printstat(const char *cp, ino_t inum, union dinode *dp) { struct group *grp; struct passwd *pw; @@ -102,7 +102,7 @@ printstat(const char *cp, ino_t inum, struct ufs1_dinode *dp) char *p; printf("%s: ", cp); - switch (dp->di_mode & IFMT) { + switch (DIP(dp, di_mode) & IFMT) { case IFDIR: puts("directory"); break; @@ -111,19 +111,22 @@ printstat(const char *cp, ino_t inum, struct ufs1_dinode *dp) break; case IFBLK: printf("block special (%d,%d)", - major(dp->di_rdev), minor(dp->di_rdev)); + (int)major(DIP(dp, di_rdev)), (int)minor(DIP(dp, di_rdev))); break; case IFCHR: printf("character special (%d,%d)", - major(dp->di_rdev), minor(dp->di_rdev)); + (int)major(DIP(dp, di_rdev)), (int)minor(DIP(dp, di_rdev))); break; case IFLNK: fputs("symlink",stdout); - if (dp->di_size > 0 && dp->di_size < MAXSYMLINKLEN_UFS1 && - dp->di_blocks == 0) - printf(" to `%.*s'\n", (int) dp->di_size, - (char *)dp->di_shortlink); - else + if (DIP(dp, di_size) > 0 && + DIP(dp, di_size) < sblock.fs_maxsymlinklen && + DIP(dp, di_blocks) == 0) { + char *p = sblock.fs_magic == FS_UFS1_MAGIC ? + (char *)dp->dp1.di_shortlink : + (char *)dp->dp2.di_shortlink; + printf(" to `%.*s'\n", (int)DIP(dp, di_size), p); + } else putchar('\n'); break; case IFSOCK: @@ -134,31 +137,31 @@ printstat(const char *cp, ino_t inum, struct ufs1_dinode *dp) break; } - printf("I=%u MODE=%o SIZE=%llu", inum, dp->di_mode, dp->di_size); - t = dp->di_mtime; + printf("I=%u MODE=%o SIZE=%llu", inum, DIP(dp, di_mode), DIP(dp, di_size)); + t = DIP(dp, 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)); + t = DIP(dp, 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)); + t = DIP(dp, 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); + printf("LINKCNT=%hd FLAGS=%#x BLKCNT=%x GEN=%x\n", DIP(dp, di_nlink), + DIP(dp, di_flags), (unsigned)DIP(dp, di_blocks), DIP(dp, di_gen)); } int @@ -178,7 +181,7 @@ checkactivedir(void) warnx("no current inode"); return 0; } - if ((curinode->di_mode & IFMT) != IFDIR) { + if ((DIP(curinode, di_mode) & IFMT) != IFDIR) { warnx("inode %d not a directory", curinum); return 0; } @@ -190,7 +193,7 @@ printactive(void) { if (!checkactive()) return 1; - switch (curinode->di_mode & IFMT) { + switch (DIP(curinode, di_mode) & IFMT) { case IFDIR: case IFREG: case IFBLK: @@ -205,7 +208,8 @@ printactive(void) 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; |