-/* $OpenBSD: fsdb.c,v 1.3 1996/04/21 23:46:22 deraadt Exp $ */
-/* $NetBSD: fsdb.c,v 1.4 1996/03/21 17:56:15 jtc Exp $ */
+/* $OpenBSD: fsdb.c,v 1.4 1997/01/16 04:04:19 millert Exp $ */
+/* $NetBSD: fsdb.c,v 1.7 1997/01/11 06:50:53 lukem Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
#include <sys/time.h>
#include <sys/mount.h>
#include <ctype.h>
+#include <err.h>
#include <fcntl.h>
#include <grp.h>
#include <histedit.h>
#include "fsdb.h"
#include "fsck.h"
+#include "extern.h"
extern char *__progname; /* from crt0.o */
-void usage __P((void));
-int cmdloop __P((void));
+int main __P((int, char *[]));
+static void usage __P((void));
+static int cmdloop __P((void));
+static int helpfn __P((int, char *[]));
+static char *prompt __P((EditLine *));
+static int scannames __P((struct inodesc *));
+static int dolookup __P((char *));
+static int chinumfunc __P((struct inodesc *));
+static int chnamefunc __P((struct inodesc *));
+static int dotime __P((char *, int32_t *, int32_t *));
-void
+int returntosingle = 0;
+struct dinode *curinode;
+ino_t curinum;
+
+static void
usage()
{
errx(1, "usage: %s [-d] -f <fsname>", __progname);
}
-int returntosingle = 0;
-
/*
* We suck in lots of fsck code, and just pick & choose the stuff we want.
*
{
int ch, rval;
char *fsys = NULL;
- struct stat stb;
while (-1 != (ch = getopt(argc, argv, "f:d"))) {
switch (ch) {
exit(rval);
}
-#define CMDFUNC(func) int func __P((int argc, char *argv[]))
-#define CMDFUNCSTART(func) int func(argc, argv) \
+#define CMDFUNC(func) static int func __P((int argc, char *argv[]))
+#define CMDFUNCSTART(func) static int func(argc, argv) \
int argc; \
char *argv[];
CMDFUNC(ln); /* add name */
CMDFUNC(newtype); /* change type */
CMDFUNC(chmode); /* change mode */
+CMDFUNC(chlen); /* change length */
CMDFUNC(chaflags); /* change flags */
CMDFUNC(chgen); /* change generation */
CMDFUNC(chowner); /* change owner */
CMDFUNC(chinum); /* Change inode # of dirent */
CMDFUNC(chname); /* Change dirname of dirent */
-struct cmdtable cmds[] = {
+static struct cmdtable cmds[] = {
{ "help", "Print out help", 1, 1, helpfn },
{ "?", "Print out help", 1, 1, helpfn },
{ "inode", "Set active inode to INUM", 2, 2, focus },
{ "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 },
+ { "chlen", "Change length of current inode to LENGTH", 2, 2, chlen },
{ "chgrp", "Change group of current inode to GROUP", 2, 2, chgroup },
{ "chflags", "Change flags of current inode to FLAGS", 2, 2, chaflags },
{ "chgen", "Change generation number of current inode to GEN", 2, 2, chgen },
{ NULL, 0, 0, 0 },
};
-int
+static int
helpfn(argc, argv)
int argc;
char *argv[];
return 0;
}
-char *
+static char *
prompt(el)
EditLine *el;
{
}
-int
+static int
cmdloop()
{
- char *line;
+ char *line = NULL;
const char *elline;
int cmd_argc, rval = 0, known;
#define scratch known
line = strdup(elline);
cmd_argv = crack(line, &cmd_argc);
- /*
- * el_parse returns -1 to signal that it's not been handled
- * internally.
- */
- if (el_parse(elptr, cmd_argc, cmd_argv) != -1)
- continue;
if (cmd_argc) {
+ /*
+ * el_parse returns -1 to signal that it's not been handled
+ * internally.
+ */
+ if (el_parse(elptr, cmd_argc, cmd_argv) != -1)
+ continue;
known = 0;
for (cmdp = cmds; cmdp->cmd; cmdp++) {
if (!strcmp(cmdp->cmd, cmd_argv[0])) {
return rval;
}
-struct dinode *curinode;
-ino_t curinum, ocurrent;
+static ino_t ocurrent;
#define GETINUM(ac,inum) inum = strtoul(argv[ac], &cp, 0); \
if (inum < ROOTINO || inum > maxino || cp == argv[ac] || *cp != '\0' ) { \
return 0;
}
-const char *typename[] = {
+static const char *typename[] = {
"unknown",
"fifo",
"char special",
"whiteout",
};
-int slot;
+static int slot;
-int
+static int
scannames(idesc)
struct inodesc *idesc;
{
return 0;
}
-int findino __P((struct inodesc *idesc)); /* from fsck */
-static int dolookup __P((char *name));
-
static int
dolookup(name)
char *name;
CMDFUNCSTART(ln)
{
ino_t inum;
- struct dinode *dp;
int rval;
char *cp;
}
}
-long slotcount, desired;
+static long slotcount, desired;
-int
+static int
chinumfunc(idesc)
struct inodesc *idesc;
{
CMDFUNCSTART(chinum)
{
- int rval;
char *cp;
ino_t inum;
struct inodesc idesc;
}
}
-int
+static int
chnamefunc(idesc)
struct inodesc *idesc;
{
{
int rval;
char *cp;
- ino_t inum;
struct inodesc idesc;
slotcount = 0;
}
}
-struct typemap {
+static struct typemap {
const char *typename;
int typebits;
} typenamemap[] = {
CMDFUNCSTART(newtype)
{
- int rval = 1;
int type;
struct typemap *tp;
return rval;
}
+CMDFUNCSTART(chlen)
+{
+ int rval = 1;
+ long len;
+ char *cp;
+
+ if (!checkactive())
+ return 1;
+
+ len = strtol(argv[1], &cp, 0);
+ if (cp == argv[1] || *cp != '\0' || len < 0) {
+ warnx("bad length '%s'", argv[1]);
+ return 1;
+ }
+
+ curinode->di_size = len;
+ inodirty();
+ printactive();
+ return rval;
+}
+
CMDFUNCSTART(chaflags)
{
int rval = 1;
uid = strtoul(argv[1], &cp, 0);
if (cp == argv[1] || *cp != '\0' ) {
/* try looking up name */
- if (pwd = getpwnam(argv[1])) {
+ if ((pwd = getpwnam(argv[1]))) {
uid = pwd->pw_uid;
} else {
warnx("bad uid `%s'", argv[1]);
gid = strtoul(argv[1], &cp, 0);
if (cp == argv[1] || *cp != '\0' ) {
- if (grp = getgrnam(argv[1])) {
+ if ((grp = getgrnam(argv[1]))) {
gid = grp->gr_gid;
} else {
warnx("bad gid `%s'", argv[1]);
return rval;
}
-int
+static int
dotime(name, rsec, rnsec)
char *name;
int32_t *rsec, *rnsec;
-/* $OpenBSD: fsdbutil.c,v 1.4 1996/03/21 00:15:50 niklas Exp $ */
-/* $NetBSD: fsdbutil.c,v 1.4 1996/02/27 22:28:16 jtc Exp $ */
+/* $OpenBSD: fsdbutil.c,v 1.5 1997/01/16 04:04:21 millert Exp $ */
+/* $NetBSD: fsdbutil.c,v 1.5 1996/09/28 19:30:37 christos Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
*/
#ifndef lint
-static char rcsid[] = "$NetBSD: fsdbutil.c,v 1.4 1996/02/27 22:28:16 jtc Exp $";
+static char rcsid[] = "$OpenBSD: fsdbutil.c,v 1.5 1997/01/16 04:04:21 millert Exp $";
#endif /* not lint */
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mount.h>
#include <ctype.h>
+#include <err.h>
#include <fcntl.h>
#include <grp.h>
#include <pwd.h>
puts("fifo");
break;
}
- printf("I=%lu MODE=%o SIZE=%qu", inum, dp->di_mode, dp->di_size);
+ printf("I=%u MODE=%o SIZE=%qu", inum, dp->di_mode, dp->di_size);
t = dp->di_mtime;
p = ctime(&t);
printf("\n\tMTIME=%15.15s %4.4s [%d nsec]", &p[4], &p[20],
printf("\n\tATIME=%15.15s %4.4s [%d nsec]\n", &p[4], &p[20],
dp->di_atimensec);
- if (pw = getpwuid(dp->di_uid))
+ if ((pw = getpwuid(dp->di_uid)))
printf("OWNER=%s ", pw->pw_name);
else
printf("OWNUID=%u ", dp->di_uid);
- if (grp = getgrgid(dp->di_gid))
+ if ((grp = getgrgid(dp->di_gid)))
printf("GRP=%s ", grp->gr_name);
else
printf("GID=%u ", dp->di_gid);