summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-01-16 04:04:22 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-01-16 04:04:22 +0000
commitabd2051d67a709d535a48746b4ff8bea263fabdb (patch)
tree91834a084e84616703c2d9040986a40d57ed06d9
parent9666f8e7d3c4edd8ed71187697db6e67a3ec54e5 (diff)
Update from NetBSD: adds chlen command and makes -Wall happy.
-rw-r--r--sbin/fsdb/fsdb.88
-rw-r--r--sbin/fsdb/fsdb.c106
-rw-r--r--sbin/fsdb/fsdb.h12
-rw-r--r--sbin/fsdb/fsdbutil.c13
4 files changed, 85 insertions, 54 deletions
diff --git a/sbin/fsdb/fsdb.8 b/sbin/fsdb/fsdb.8
index 8754a89569c..256e7826cd4 100644
--- a/sbin/fsdb/fsdb.8
+++ b/sbin/fsdb/fsdb.8
@@ -1,5 +1,5 @@
-.\" $OpenBSD: fsdb.8,v 1.4 1996/10/08 01:20:24 michaels Exp $
-.\" $NetBSD: fsdb.8,v 1.4 1996/02/27 22:28:09 jtc Exp $
+.\" $OpenBSD: fsdb.8,v 1.5 1997/01/16 04:04:18 millert Exp $
+.\" $NetBSD: fsdb.8,v 1.5 1997/01/11 05:51:40 lukem Exp $
.\"
.\" Copyright (c) 1996 The NetBSD Foundation, Inc.
.\" All rights reserved.
@@ -176,6 +176,10 @@ Change the file flags of the current inode to
Change the owner of the current inode to
.Ar uid .
.Pp
+.It Cm chlen Ar length
+Change length of current inode to
+.Ar length .
+.Pp
.It Cm chgrp Ar gid
Change the group of the current inode to
.Ar gid .
diff --git a/sbin/fsdb/fsdb.c b/sbin/fsdb/fsdb.c
index cf7f0b6dc9e..98e010ac328 100644
--- a/sbin/fsdb/fsdb.c
+++ b/sbin/fsdb/fsdb.c
@@ -1,5 +1,5 @@
-/* $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.
@@ -47,6 +47,7 @@ static char rcsid[] = "$NetBSD: fsdb.c,v 1.4 1996/03/21 17:56:15 jtc Exp $";
#include <sys/time.h>
#include <sys/mount.h>
#include <ctype.h>
+#include <err.h>
#include <fcntl.h>
#include <grp.h>
#include <histedit.h>
@@ -63,20 +64,31 @@ static char rcsid[] = "$NetBSD: fsdb.c,v 1.4 1996/03/21 17:56:15 jtc Exp $";
#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.
*
@@ -90,7 +102,6 @@ main(argc, argv)
{
int ch, rval;
char *fsys = NULL;
- struct stat stb;
while (-1 != (ch = getopt(argc, argv, "f:d"))) {
switch (ch) {
@@ -120,8 +131,8 @@ main(argc, argv)
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[];
@@ -139,6 +150,7 @@ CMDFUNC(rm); /* remove name */
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 */
@@ -150,7 +162,7 @@ CMDFUNC(chatime); /* Change atime */
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 },
@@ -172,6 +184,7 @@ struct cmdtable cmds[] = {
{ "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 },
@@ -184,7 +197,7 @@ struct cmdtable cmds[] = {
{ NULL, 0, 0, 0 },
};
-int
+static int
helpfn(argc, argv)
int argc;
char *argv[];
@@ -200,7 +213,7 @@ helpfn(argc, argv)
return 0;
}
-char *
+static char *
prompt(el)
EditLine *el;
{
@@ -210,10 +223,10 @@ prompt(el)
}
-int
+static int
cmdloop()
{
- char *line;
+ char *line = NULL;
const char *elline;
int cmd_argc, rval = 0, known;
#define scratch known
@@ -243,13 +256,13 @@ cmdloop()
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])) {
@@ -277,8 +290,7 @@ cmdloop()
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' ) { \
@@ -356,7 +368,7 @@ CMDFUNCSTART(downlink)
return 0;
}
-const char *typename[] = {
+static const char *typename[] = {
"unknown",
"fifo",
"char special",
@@ -374,9 +386,9 @@ const char *typename[] = {
"whiteout",
};
-int slot;
+static int slot;
-int
+static int
scannames(idesc)
struct inodesc *idesc;
{
@@ -404,9 +416,6 @@ CMDFUNCSTART(ls)
return 0;
}
-int findino __P((struct inodesc *idesc)); /* from fsck */
-static int dolookup __P((char *name));
-
static int
dolookup(name)
char *name;
@@ -464,7 +473,6 @@ CMDFUNCSTART(focusname)
CMDFUNCSTART(ln)
{
ino_t inum;
- struct dinode *dp;
int rval;
char *cp;
@@ -497,9 +505,9 @@ CMDFUNCSTART(rm)
}
}
-long slotcount, desired;
+static long slotcount, desired;
-int
+static int
chinumfunc(idesc)
struct inodesc *idesc;
{
@@ -514,7 +522,6 @@ chinumfunc(idesc)
CMDFUNCSTART(chinum)
{
- int rval;
char *cp;
ino_t inum;
struct inodesc idesc;
@@ -544,7 +551,7 @@ CMDFUNCSTART(chinum)
}
}
-int
+static int
chnamefunc(idesc)
struct inodesc *idesc;
{
@@ -568,7 +575,6 @@ CMDFUNCSTART(chname)
{
int rval;
char *cp;
- ino_t inum;
struct inodesc idesc;
slotcount = 0;
@@ -599,7 +605,7 @@ CMDFUNCSTART(chname)
}
}
-struct typemap {
+static struct typemap {
const char *typename;
int typebits;
} typenamemap[] = {
@@ -611,7 +617,6 @@ struct typemap {
CMDFUNCSTART(newtype)
{
- int rval = 1;
int type;
struct typemap *tp;
@@ -661,6 +666,27 @@ CMDFUNCSTART(chmode)
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;
@@ -749,7 +775,7 @@ CMDFUNCSTART(chowner)
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]);
@@ -775,7 +801,7 @@ CMDFUNCSTART(chgroup)
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]);
@@ -789,7 +815,7 @@ CMDFUNCSTART(chgroup)
return rval;
}
-int
+static int
dotime(name, rsec, rnsec)
char *name;
int32_t *rsec, *rnsec;
diff --git a/sbin/fsdb/fsdb.h b/sbin/fsdb/fsdb.h
index 16c0b762be2..63a2e2f0db7 100644
--- a/sbin/fsdb/fsdb.h
+++ b/sbin/fsdb/fsdb.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: fsdb.h,v 1.2 1996/03/21 00:15:48 niklas Exp $ */
-/* $NetBSD: fsdb.h,v 1.3 1996/02/27 22:28:13 jtc Exp $ */
+/* $OpenBSD: fsdb.h,v 1.3 1997/01/16 04:04:20 millert Exp $ */
+/* $NetBSD: fsdb.h,v 1.4 1996/09/28 19:30:36 christos Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -57,9 +57,9 @@ struct cmdtable {
extern struct dinode *curinode;
extern ino_t curinum;
-int argcount __P((struct cmdtable *cmdp, int argc, char *argv[]));
-char **crack __P((char *line, int *argc));
-void printstat __P((const char *cp, ino_t inum, struct dinode *dp));
-int printactive __P((void));
+char **crack __P((char *, int *));
+int argcount __P((struct cmdtable *, int, char *[]));
+void printstat __P((const char *, ino_t, struct dinode *));
int checkactive __P((void));
int checkactivedir __P((void));
+int printactive __P((void));
diff --git a/sbin/fsdb/fsdbutil.c b/sbin/fsdb/fsdbutil.c
index 82e73562bd3..4dd13cea046 100644
--- a/sbin/fsdb/fsdbutil.c
+++ b/sbin/fsdb/fsdbutil.c
@@ -1,5 +1,5 @@
-/* $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.
@@ -38,7 +38,7 @@
*/
#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>
@@ -47,6 +47,7 @@ static char rcsid[] = "$NetBSD: fsdbutil.c,v 1.4 1996/02/27 22:28:16 jtc Exp $";
#include <sys/time.h>
#include <sys/mount.h>
#include <ctype.h>
+#include <err.h>
#include <fcntl.h>
#include <grp.h>
#include <pwd.h>
@@ -139,7 +140,7 @@ printstat(cp, inum, dp)
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],
@@ -153,11 +154,11 @@ printstat(cp, inum, dp)
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);