2008-04-29 00:22:51 +04:00
|
|
|
/* $NetBSD: fsdb.c,v 1.37 2008/04/28 20:23:08 martin Exp $ */
|
1995-10-09 02:18:08 +03:00
|
|
|
|
1996-02-28 01:28:09 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by John T. Kohl.
|
|
|
|
*
|
|
|
|
* 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
|
1997-07-31 04:21:53 +04:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1996-02-28 01:28:09 +03:00
|
|
|
* 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
|
1995-10-09 02:08:36 +03:00
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
#include <sys/cdefs.h>
|
1995-10-09 02:08:36 +03:00
|
|
|
#ifndef lint
|
2008-04-29 00:22:51 +04:00
|
|
|
__RCSID("$NetBSD: fsdb.c,v 1.37 2008/04/28 20:23:08 martin Exp $");
|
1995-10-09 02:08:36 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/mount.h>
|
1995-10-09 02:18:08 +03:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <histedit.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
1998-04-01 20:04:21 +04:00
|
|
|
#include <time.h>
|
1995-10-09 02:18:08 +03:00
|
|
|
#include <unistd.h>
|
1996-09-28 23:30:35 +04:00
|
|
|
#include <err.h>
|
1995-10-09 02:18:08 +03:00
|
|
|
|
1995-10-09 02:08:36 +03:00
|
|
|
#include <ufs/ufs/dinode.h>
|
|
|
|
#include <ufs/ufs/dir.h>
|
|
|
|
#include <ufs/ffs/fs.h>
|
1998-03-18 20:03:15 +03:00
|
|
|
#include <ufs/ffs/ffs_extern.h>
|
1995-10-09 02:08:36 +03:00
|
|
|
|
|
|
|
#include "fsdb.h"
|
|
|
|
#include "fsck.h"
|
1996-09-28 23:30:35 +04:00
|
|
|
#include "extern.h"
|
1995-10-09 02:08:36 +03:00
|
|
|
|
2005-01-19 23:19:04 +03:00
|
|
|
static void usage(void);
|
|
|
|
static int cmdloop(void);
|
|
|
|
static char *prompt(EditLine *);
|
|
|
|
static int scannames(struct inodesc *);
|
|
|
|
static int dolookup(char *);
|
|
|
|
static int chinumfunc(struct inodesc *);
|
|
|
|
static int chnamefunc(struct inodesc *);
|
|
|
|
static int dotime(char *, int32_t *, int32_t *);
|
|
|
|
static void print_blks32(int32_t *buf, int size, uint64_t *blknum);
|
|
|
|
static void print_blks64(int64_t *buf, int size, uint64_t *blknum);
|
|
|
|
static void print_indirblks32(uint32_t blk, int ind_level,
|
|
|
|
uint64_t *blknum);
|
|
|
|
static void print_indirblks64(uint64_t blk, int ind_level,
|
|
|
|
uint64_t *blknum);
|
|
|
|
static int compare_blk32(uint32_t *, uint32_t);
|
|
|
|
static int compare_blk64(uint64_t *, uint64_t);
|
|
|
|
static int founddatablk(uint64_t);
|
|
|
|
static int find_blks32(uint32_t *buf, int size, uint32_t *blknum);
|
|
|
|
static int find_blks64(uint64_t *buf, int size, uint64_t *blknum);
|
|
|
|
static int find_indirblks32(uint32_t blk, int ind_level,
|
|
|
|
uint32_t *blknum);
|
|
|
|
static int find_indirblks64(uint64_t blk, int ind_level,
|
|
|
|
uint64_t *blknum);
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
int returntosingle = 0;
|
2003-04-02 14:39:19 +04:00
|
|
|
union dinode *curinode;
|
1997-09-14 18:56:57 +04:00
|
|
|
ino_t curinum;
|
1996-09-28 23:30:35 +04:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
static void
|
2005-01-19 23:19:04 +03:00
|
|
|
usage(void)
|
1995-10-09 02:08:36 +03:00
|
|
|
{
|
2004-01-04 03:13:00 +03:00
|
|
|
errx(1, "usage: %s [-dFn] -f <fsname>", getprogname());
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* We suck in lots of fsck code, and just pick & choose the stuff we want.
|
|
|
|
*
|
|
|
|
* fsreadfd is set up to read from the file system, fswritefd to write to
|
|
|
|
* the file system.
|
|
|
|
*/
|
1996-03-21 20:56:15 +03:00
|
|
|
int
|
2005-01-19 23:19:04 +03:00
|
|
|
main(int argc, char *argv[])
|
1995-10-09 02:08:36 +03:00
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
int ch, rval;
|
|
|
|
char *fsys = NULL;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
2004-01-03 22:57:42 +03:00
|
|
|
forceimage = 0;
|
|
|
|
debug = 0;
|
|
|
|
isappleufs = 0;
|
|
|
|
while ((ch = getopt(argc, argv, "dFf:n")) != -1) {
|
1995-10-09 02:08:36 +03:00
|
|
|
switch (ch) {
|
|
|
|
case 'd':
|
|
|
|
debug++;
|
|
|
|
break;
|
2004-01-03 22:57:42 +03:00
|
|
|
case 'F':
|
|
|
|
forceimage = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
fsys = optarg;
|
|
|
|
break;
|
1999-03-09 19:11:47 +03:00
|
|
|
case 'n':
|
|
|
|
nflag++;
|
|
|
|
break;
|
1995-10-09 02:08:36 +03:00
|
|
|
default:
|
1995-10-09 02:18:08 +03:00
|
|
|
usage();
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (fsys == NULL)
|
1995-10-09 02:18:08 +03:00
|
|
|
usage();
|
1998-03-18 20:03:15 +03:00
|
|
|
endian = 0;
|
2004-01-03 22:57:42 +03:00
|
|
|
if (setup(fsys) <= 0)
|
1995-10-09 02:08:36 +03:00
|
|
|
errx(1, "cannot set up file system `%s'", fsys);
|
|
|
|
printf("Editing file system `%s'\nLast Mounted on %s\n", fsys,
|
1998-03-18 20:03:15 +03:00
|
|
|
sblock->fs_fsmnt);
|
1995-10-09 02:18:08 +03:00
|
|
|
rval = cmdloop();
|
1999-03-09 19:11:47 +03:00
|
|
|
if (nflag)
|
|
|
|
exit(rval);
|
1998-03-18 20:03:15 +03:00
|
|
|
sblock->fs_clean = 0; /* mark it dirty */
|
1995-10-09 02:08:36 +03:00
|
|
|
sbdirty();
|
1998-03-18 20:03:15 +03:00
|
|
|
markclean = 0;
|
|
|
|
ckfini();
|
1995-10-09 02:08:36 +03:00
|
|
|
printf("*** FILE SYSTEM MARKED DIRTY\n");
|
|
|
|
printf("*** BE SURE TO RUN FSCK TO CLEAN UP ANY DAMAGE\n");
|
|
|
|
printf("*** IF IT WAS MOUNTED, RE-MOUNT WITH -u -o reload\n");
|
|
|
|
exit(rval);
|
|
|
|
}
|
|
|
|
|
2005-02-05 17:26:05 +03:00
|
|
|
#define CMDFUNC(func) static int func (int argc, char *argv[])
|
1996-09-28 23:30:35 +04:00
|
|
|
#define CMDFUNCSTART(func) static int func(argc, argv) \
|
|
|
|
int argc; \
|
1995-10-09 02:18:08 +03:00
|
|
|
char *argv[];
|
1995-10-09 02:08:36 +03:00
|
|
|
|
|
|
|
CMDFUNC(helpfn);
|
1997-09-14 18:56:57 +04:00
|
|
|
CMDFUNC(focus); /* focus on inode */
|
|
|
|
CMDFUNC(active); /* print active inode */
|
|
|
|
CMDFUNC(focusname); /* focus by name */
|
|
|
|
CMDFUNC(zapi); /* clear inode */
|
|
|
|
CMDFUNC(uplink); /* incr link */
|
|
|
|
CMDFUNC(downlink); /* decr link */
|
|
|
|
CMDFUNC(linkcount); /* set link count */
|
|
|
|
CMDFUNC(quit); /* quit */
|
|
|
|
CMDFUNC(ls); /* list directory */
|
1999-03-09 19:11:47 +03:00
|
|
|
CMDFUNC(blks); /* list blocks */
|
2003-04-26 12:42:49 +04:00
|
|
|
CMDFUNC(findblk); /* find block */
|
1997-09-14 18:56:57 +04:00
|
|
|
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 */
|
|
|
|
CMDFUNC(chgroup); /* Change group */
|
|
|
|
CMDFUNC(back); /* pop back to last ino */
|
|
|
|
CMDFUNC(chmtime); /* Change mtime */
|
|
|
|
CMDFUNC(chctime); /* Change ctime */
|
|
|
|
CMDFUNC(chatime); /* Change atime */
|
|
|
|
CMDFUNC(chinum); /* Change inode # of dirent */
|
|
|
|
CMDFUNC(chname); /* Change dirname of dirent */
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static struct cmdtable cmds[] = {
|
1997-09-14 18:56:57 +04:00
|
|
|
{"help", "Print out help", 1, 1, helpfn},
|
|
|
|
{"?", "Print out help", 1, 1, helpfn},
|
|
|
|
{"inode", "Set active inode to INUM", 2, 2, focus},
|
|
|
|
{"clri", "Clear inode INUM", 2, 2, zapi},
|
|
|
|
{"lookup", "Set active inode by looking up NAME", 2, 2, focusname},
|
|
|
|
{"cd", "Set active inode by looking up NAME", 2, 2, focusname},
|
|
|
|
{"back", "Go to previous active inode", 1, 1, back},
|
|
|
|
{"active", "Print active inode", 1, 1, active},
|
|
|
|
{"print", "Print active inode", 1, 1, active},
|
|
|
|
{"uplink", "Increment link count", 1, 1, uplink},
|
|
|
|
{"downlink", "Decrement link count", 1, 1, downlink},
|
|
|
|
{"linkcount", "Set link count to COUNT", 2, 2, linkcount},
|
|
|
|
{"ls", "List current inode as directory", 1, 1, ls},
|
1999-03-09 19:11:47 +03:00
|
|
|
{"blks", "List current inode's data blocks", 1, 1, blks},
|
2003-04-26 12:42:49 +04:00
|
|
|
{"findblk", "Find inode owning disk block(s)", 2, 33, findblk},
|
1997-09-14 18:56:57 +04:00
|
|
|
{"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},
|
|
|
|
{"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},
|
|
|
|
{"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},
|
|
|
|
{"quit", "Exit", 1, 1, quit},
|
|
|
|
{"q", "Exit", 1, 1, quit},
|
|
|
|
{"exit", "Exit", 1, 1, quit},
|
2006-10-16 07:10:59 +04:00
|
|
|
{ .cmd = NULL},
|
1995-10-09 02:08:36 +03:00
|
|
|
};
|
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
helpfn(int argc, char *argv[])
|
1995-10-09 02:08:36 +03:00
|
|
|
{
|
1997-09-15 05:45:36 +04:00
|
|
|
struct cmdtable *cmdtp;
|
1997-09-14 18:56:57 +04:00
|
|
|
|
|
|
|
printf("Commands are:\n%-10s %5s %5s %s\n",
|
|
|
|
"command", "min argc", "max argc", "what");
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
for (cmdtp = cmds; cmdtp->cmd; cmdtp++)
|
|
|
|
printf("%-10s %5u %5u %s\n",
|
|
|
|
cmdtp->cmd, cmdtp->minargc, cmdtp->maxargc, cmdtp->helptxt);
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static char *
|
2005-01-19 23:19:04 +03:00
|
|
|
prompt(EditLine *el)
|
1995-10-09 02:08:36 +03:00
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
static char pstring[64];
|
2005-08-19 06:07:18 +04:00
|
|
|
snprintf(pstring, sizeof(pstring), "fsdb (inum: %llu)> ",
|
|
|
|
(unsigned long long)curinum);
|
1997-09-14 18:56:57 +04:00
|
|
|
return pstring;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
cmdloop(void)
|
1995-10-09 02:08:36 +03:00
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
char *line;
|
|
|
|
const char *elline;
|
|
|
|
int cmd_argc, rval = 0, known;
|
1995-10-09 02:08:36 +03:00
|
|
|
#define scratch known
|
1997-09-14 18:56:57 +04:00
|
|
|
char **cmd_argv;
|
|
|
|
struct cmdtable *cmdp;
|
|
|
|
History *hist;
|
1997-10-14 19:06:42 +04:00
|
|
|
HistEvent he;
|
1997-09-14 18:56:57 +04:00
|
|
|
EditLine *elptr;
|
|
|
|
|
|
|
|
curinode = ginode(ROOTINO);
|
|
|
|
curinum = ROOTINO;
|
|
|
|
printactive();
|
|
|
|
|
|
|
|
hist = history_init();
|
1998-05-20 14:01:11 +04:00
|
|
|
history(hist, &he, H_SETSIZE, 100); /* 100 elt history buffer */
|
1997-09-14 18:56:57 +04:00
|
|
|
|
2001-02-20 01:48:57 +03:00
|
|
|
elptr = el_init(getprogname(), stdin, stdout, stderr);
|
1997-09-14 18:56:57 +04:00
|
|
|
el_set(elptr, EL_EDITOR, "emacs");
|
|
|
|
el_set(elptr, EL_PROMPT, prompt);
|
|
|
|
el_set(elptr, EL_HIST, history, hist);
|
|
|
|
el_source(elptr, NULL);
|
|
|
|
|
|
|
|
while ((elline = el_gets(elptr, &scratch)) != NULL && scratch != 0) {
|
|
|
|
if (debug)
|
|
|
|
printf("command `%s'\n", elline);
|
|
|
|
|
1997-10-14 19:06:42 +04:00
|
|
|
history(hist, &he, H_ENTER, elline);
|
1997-09-14 18:56:57 +04:00
|
|
|
|
|
|
|
line = strdup(elline);
|
|
|
|
cmd_argv = crack(line, &cmd_argc);
|
|
|
|
if (cmd_argc) {
|
|
|
|
/*
|
|
|
|
* el_parse returns -1 to signal that it's not been
|
|
|
|
* handled internally.
|
|
|
|
*/
|
2002-03-18 23:04:49 +03:00
|
|
|
if (el_parse(elptr, cmd_argc,
|
|
|
|
(const char **)cmd_argv) != -1)
|
1997-09-14 18:56:57 +04:00
|
|
|
continue;
|
|
|
|
known = 0;
|
|
|
|
for (cmdp = cmds; cmdp->cmd; cmdp++) {
|
|
|
|
if (!strcmp(cmdp->cmd, cmd_argv[0])) {
|
|
|
|
if (cmd_argc >= cmdp->minargc &&
|
|
|
|
cmd_argc <= cmdp->maxargc)
|
|
|
|
rval =
|
|
|
|
(*cmdp->handler)(cmd_argc,
|
|
|
|
cmd_argv);
|
|
|
|
else
|
|
|
|
rval = argcount(cmdp, cmd_argc,
|
|
|
|
cmd_argv);
|
|
|
|
known = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!known)
|
|
|
|
warnx("unknown command `%s'", cmd_argv[0]),
|
|
|
|
rval = 1;
|
|
|
|
} else
|
|
|
|
rval = 0;
|
|
|
|
free(line);
|
|
|
|
if (rval < 0)
|
|
|
|
return rval;
|
|
|
|
if (rval)
|
|
|
|
warnx("rval was %d", rval);
|
|
|
|
}
|
|
|
|
el_end(elptr);
|
|
|
|
history_end(hist);
|
|
|
|
return rval;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static ino_t ocurrent;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
2005-08-19 06:07:18 +04:00
|
|
|
#define GETINUM(ac,inum) inum = strtoull(argv[ac], &cp, 0); \
|
2003-04-26 12:42:49 +04:00
|
|
|
if (inum < ROOTINO || inum >= maxino || cp == argv[ac] || *cp != '\0' ) { \
|
2005-08-19 06:07:18 +04:00
|
|
|
printf("inode %llu out of range; range is [%llu,%llu]\n", \
|
|
|
|
(unsigned long long)inum, (unsigned long long)ROOTINO, \
|
|
|
|
(unsigned long long)maxino); \
|
1995-10-09 02:08:36 +03:00
|
|
|
return 1; \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Focus on given inode number
|
|
|
|
*/
|
|
|
|
CMDFUNCSTART(focus)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
ino_t inum;
|
|
|
|
char *cp;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
GETINUM(1, inum);
|
|
|
|
curinode = ginode(inum);
|
|
|
|
ocurrent = curinum;
|
|
|
|
curinum = inum;
|
|
|
|
printactive();
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(back)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
curinum = ocurrent;
|
|
|
|
curinode = ginode(curinum);
|
|
|
|
printactive();
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(zapi)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
ino_t inum;
|
2003-04-02 14:39:19 +04:00
|
|
|
union dinode *dp;
|
1997-09-14 18:56:57 +04:00
|
|
|
char *cp;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
GETINUM(1, inum);
|
|
|
|
dp = ginode(inum);
|
|
|
|
clearinode(dp);
|
|
|
|
inodirty();
|
|
|
|
if (curinode) /* re-set after potential change */
|
|
|
|
curinode = ginode(curinum);
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(active)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
printactive();
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(quit)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
return -1;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(uplink)
|
|
|
|
{
|
2003-04-02 14:39:19 +04:00
|
|
|
int16_t nlink;
|
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
2003-04-02 14:39:19 +04:00
|
|
|
nlink = iswap16(DIP(curinode, nlink));
|
|
|
|
nlink++;
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, nlink, iswap16(nlink));
|
2005-08-19 06:07:18 +04:00
|
|
|
printf("inode %llu link count now %d\n", (unsigned long long)curinum,
|
|
|
|
nlink);
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(downlink)
|
|
|
|
{
|
2003-04-02 14:39:19 +04:00
|
|
|
int16_t nlink;
|
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
2003-04-02 14:39:19 +04:00
|
|
|
nlink = iswap16(DIP(curinode, nlink));
|
|
|
|
nlink--;
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, nlink, iswap16(nlink));
|
2005-08-19 06:07:18 +04:00
|
|
|
printf("inode %llu link count now %d\n", (unsigned long long)curinum,
|
|
|
|
nlink);
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static const char *typename[] = {
|
1997-09-14 18:56:57 +04:00
|
|
|
"unknown",
|
|
|
|
"fifo",
|
|
|
|
"char special",
|
|
|
|
"unregistered #3",
|
|
|
|
"directory",
|
|
|
|
"unregistered #5",
|
|
|
|
"blk special",
|
|
|
|
"unregistered #7",
|
|
|
|
"regular",
|
|
|
|
"unregistered #9",
|
|
|
|
"symlink",
|
|
|
|
"unregistered #11",
|
|
|
|
"socket",
|
|
|
|
"unregistered #13",
|
|
|
|
"whiteout",
|
1995-10-09 02:08:36 +03:00
|
|
|
};
|
1997-09-14 18:56:57 +04:00
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static int slot;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
scannames(struct inodesc *idesc)
|
1995-10-09 02:08:36 +03:00
|
|
|
{
|
1997-09-15 05:45:36 +04:00
|
|
|
struct direct *dirp = idesc->id_dirp;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
|
|
|
printf("slot %d ino %d reclen %d: %s, `%.*s'\n",
|
1998-03-18 20:03:15 +03:00
|
|
|
slot++, iswap32(dirp->d_ino), iswap16(dirp->d_reclen),
|
|
|
|
typename[dirp->d_type],
|
1997-09-14 18:56:57 +04:00
|
|
|
dirp->d_namlen, dirp->d_name);
|
1995-10-09 02:08:36 +03:00
|
|
|
return (KEEPON);
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(ls)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
struct inodesc idesc;
|
|
|
|
checkactivedir(); /* let it go on anyway */
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
slot = 0;
|
|
|
|
idesc.id_number = curinum;
|
|
|
|
idesc.id_func = scannames;
|
|
|
|
idesc.id_type = DATA;
|
|
|
|
idesc.id_fix = IGNORE;
|
|
|
|
ckinode(curinode, &idesc);
|
|
|
|
curinode = ginode(curinum);
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
1999-03-09 19:11:47 +03:00
|
|
|
CMDFUNCSTART(blks)
|
|
|
|
{
|
2004-09-17 16:18:55 +04:00
|
|
|
uint64_t blkno = 0;
|
1999-03-09 19:11:47 +03:00
|
|
|
int i, type;
|
|
|
|
if (!curinode) {
|
2002-07-20 12:36:17 +04:00
|
|
|
warnx("no current inode");
|
1999-03-09 19:11:47 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
type = iswap16(DIP(curinode, mode)) & IFMT;
|
1999-03-09 19:11:47 +03:00
|
|
|
if (type != IFDIR && type != IFREG) {
|
2005-08-19 06:07:18 +04:00
|
|
|
warnx("inode %llu not a file or directory",
|
|
|
|
(unsigned long long)curinum);
|
1999-03-09 19:11:47 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
if (is_ufs2) {
|
2005-08-19 06:07:18 +04:00
|
|
|
printf("I=%llu %lld blocks\n", (unsigned long long)curinum,
|
2003-04-02 14:39:19 +04:00
|
|
|
(long long)(iswap64(curinode->dp2.di_blocks)));
|
|
|
|
} else {
|
2005-08-19 06:07:18 +04:00
|
|
|
printf("I=%llu %d blocks\n", (unsigned long long)curinum,
|
2003-04-02 14:39:19 +04:00
|
|
|
iswap32(curinode->dp1.di_blocks));
|
|
|
|
}
|
1999-03-09 19:11:47 +03:00
|
|
|
printf("Direct blocks:\n");
|
2003-04-02 14:39:19 +04:00
|
|
|
if (is_ufs2)
|
|
|
|
print_blks64(curinode->dp2.di_db, NDADDR, &blkno);
|
2003-04-08 18:46:21 +04:00
|
|
|
else
|
|
|
|
print_blks32(curinode->dp1.di_db, NDADDR, &blkno);
|
2003-04-02 14:39:19 +04:00
|
|
|
|
|
|
|
if (is_ufs2) {
|
2004-09-17 16:18:55 +04:00
|
|
|
for (i = 0; i < NIADDR; i++)
|
|
|
|
print_indirblks64(iswap64(curinode->dp2.di_ib[i]), i,
|
|
|
|
&blkno);
|
2003-04-02 14:39:19 +04:00
|
|
|
} else {
|
2004-09-17 16:18:55 +04:00
|
|
|
for (i = 0; i < NIADDR; i++)
|
|
|
|
print_indirblks32(iswap32(curinode->dp1.di_ib[i]), i,
|
|
|
|
&blkno);
|
1999-03-09 19:11:47 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-26 12:42:49 +04:00
|
|
|
static int findblk_numtofind;
|
|
|
|
static int wantedblksize;
|
|
|
|
CMDFUNCSTART(findblk)
|
|
|
|
{
|
|
|
|
ino_t inum, inosused;
|
2005-06-02 04:38:41 +04:00
|
|
|
uint32_t *wantedblk32 = NULL;
|
|
|
|
uint64_t *wantedblk64 = NULL;
|
2003-04-26 12:42:49 +04:00
|
|
|
struct cg *cgp = cgrp;
|
|
|
|
int i, c;
|
|
|
|
|
|
|
|
ocurrent = curinum;
|
|
|
|
wantedblksize = (argc - 1);
|
|
|
|
if (is_ufs2) {
|
|
|
|
wantedblk64 = malloc(sizeof(uint64_t) * wantedblksize);
|
|
|
|
if (wantedblk64 == NULL) {
|
|
|
|
perror("malloc");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
memset(wantedblk64, 0, sizeof(uint64_t) * wantedblksize);
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
wantedblk64[i - 1] =
|
|
|
|
dbtofsb(sblock, strtoull(argv[i], NULL, 0));
|
|
|
|
} else {
|
|
|
|
wantedblk32 = malloc(sizeof(uint32_t) * wantedblksize);
|
|
|
|
if (wantedblk32 == NULL) {
|
|
|
|
perror("malloc");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
memset(wantedblk32, 0, sizeof(uint32_t) * wantedblksize);
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
wantedblk32[i - 1] =
|
|
|
|
dbtofsb(sblock, strtoull(argv[i], NULL, 0));
|
|
|
|
}
|
|
|
|
findblk_numtofind = wantedblksize;
|
|
|
|
for (c = 0; c < sblock->fs_ncg; c++) {
|
|
|
|
inum = c * sblock->fs_ipg;
|
|
|
|
getblk(&cgblk, cgtod(sblock, c), sblock->fs_cgsize);
|
|
|
|
memcpy(cgp, cgblk.b_un.b_cg, sblock->fs_cgsize);
|
|
|
|
if (needswap)
|
|
|
|
ffs_cg_swap(cgblk.b_un.b_cg, cgp, sblock);
|
|
|
|
if (is_ufs2)
|
|
|
|
inosused = cgp->cg_initediblk;
|
|
|
|
else
|
|
|
|
inosused = sblock->fs_ipg;
|
|
|
|
for (; inosused > 0; inum++, inosused--) {
|
|
|
|
if (inum < ROOTINO)
|
|
|
|
continue;
|
|
|
|
if (is_ufs2 ? compare_blk64(wantedblk64,
|
|
|
|
ino_to_fsba(sblock, inum)) :
|
|
|
|
compare_blk32(wantedblk32,
|
|
|
|
ino_to_fsba(sblock, inum))) {
|
2005-08-19 06:07:18 +04:00
|
|
|
printf("block %llu: inode block (%llu-%llu)\n",
|
2003-04-26 12:42:49 +04:00
|
|
|
(unsigned long long)fsbtodb(sblock,
|
|
|
|
ino_to_fsba(sblock, inum)),
|
2005-08-19 06:07:18 +04:00
|
|
|
(unsigned long long)
|
2003-04-26 12:42:49 +04:00
|
|
|
(inum / INOPB(sblock)) * INOPB(sblock),
|
2005-08-19 06:07:18 +04:00
|
|
|
(unsigned long long)
|
2003-04-26 12:42:49 +04:00
|
|
|
(inum / INOPB(sblock) + 1) * INOPB(sblock));
|
|
|
|
findblk_numtofind--;
|
|
|
|
if (findblk_numtofind == 0)
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
curinum = inum;
|
|
|
|
curinode = ginode(inum);
|
|
|
|
switch (iswap16(DIP(curinode, mode)) & IFMT) {
|
|
|
|
case IFDIR:
|
|
|
|
case IFREG:
|
|
|
|
if (DIP(curinode, blocks) == 0)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
case IFLNK:
|
|
|
|
{
|
|
|
|
uint64_t size = iswap64(DIP(curinode, size));
|
|
|
|
if (size > 0 &&
|
|
|
|
size < sblock->fs_maxsymlinklen &&
|
|
|
|
DIP(curinode, blocks) == 0)
|
|
|
|
continue;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (is_ufs2 ?
|
|
|
|
find_blks64(curinode->dp2.di_db, NDADDR,
|
|
|
|
wantedblk64) :
|
|
|
|
find_blks32(curinode->dp1.di_db, NDADDR,
|
|
|
|
wantedblk32))
|
|
|
|
goto end;
|
|
|
|
for (i = 0; i < NIADDR; i++) {
|
|
|
|
if (is_ufs2 ?
|
|
|
|
compare_blk64(wantedblk64,
|
|
|
|
iswap64(curinode->dp2.di_ib[i])) :
|
|
|
|
compare_blk32(wantedblk32,
|
|
|
|
iswap32(curinode->dp1.di_ib[i])))
|
|
|
|
if (founddatablk(is_ufs2 ?
|
|
|
|
iswap64(curinode->dp2.di_ib[i]) :
|
|
|
|
iswap32(curinode->dp1.di_ib[i])))
|
|
|
|
goto end;
|
|
|
|
if (is_ufs2 ? (curinode->dp2.di_ib[i] != 0) :
|
|
|
|
(curinode->dp1.di_ib[i] != 0))
|
|
|
|
if (is_ufs2 ?
|
|
|
|
find_indirblks64(
|
|
|
|
iswap64(curinode->dp2.di_ib[i]),
|
|
|
|
i, wantedblk64) :
|
|
|
|
find_indirblks32(
|
|
|
|
iswap32(curinode->dp1.di_ib[i]),
|
|
|
|
i, wantedblk32))
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end:
|
2006-05-19 18:50:32 +04:00
|
|
|
if (wantedblk32)
|
|
|
|
free(wantedblk32);
|
|
|
|
if (wantedblk64)
|
|
|
|
free(wantedblk64);
|
2003-04-26 12:42:49 +04:00
|
|
|
curinum = ocurrent;
|
|
|
|
curinode = ginode(curinum);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
compare_blk32(uint32_t *wantedblk, uint32_t curblk)
|
2003-04-26 12:42:49 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < wantedblksize; i++) {
|
|
|
|
if (wantedblk[i] != 0 && wantedblk[i] == curblk) {
|
|
|
|
wantedblk[i] = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
compare_blk64(uint64_t *wantedblk, uint64_t curblk)
|
2003-04-26 12:42:49 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < wantedblksize; i++) {
|
|
|
|
if (wantedblk[i] != 0 && wantedblk[i] == curblk) {
|
|
|
|
wantedblk[i] = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
founddatablk(uint64_t blk)
|
2003-04-26 12:42:49 +04:00
|
|
|
{
|
2005-08-19 06:07:18 +04:00
|
|
|
printf("%llu: data block of inode %llu\n",
|
|
|
|
(unsigned long long)fsbtodb(sblock, blk),
|
|
|
|
(unsigned long long)curinum);
|
2003-04-26 12:42:49 +04:00
|
|
|
findblk_numtofind--;
|
|
|
|
if (findblk_numtofind == 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
find_blks32(uint32_t *buf, int size, uint32_t *wantedblk)
|
2003-04-26 12:42:49 +04:00
|
|
|
{
|
|
|
|
int blk;
|
|
|
|
for(blk = 0; blk < size; blk++) {
|
|
|
|
if (buf[blk] == 0)
|
|
|
|
continue;
|
|
|
|
if (compare_blk32(wantedblk, iswap32(buf[blk]))) {
|
|
|
|
if (founddatablk(iswap32(buf[blk])))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
find_indirblks32(uint32_t blk, int ind_level, uint32_t *wantedblk)
|
2003-04-26 12:42:49 +04:00
|
|
|
{
|
|
|
|
#define MAXNINDIR (MAXBSIZE / sizeof(uint32_t))
|
|
|
|
uint32_t idblk[MAXNINDIR];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
bread(fsreadfd, (char *)idblk, fsbtodb(sblock, blk),
|
|
|
|
(int)sblock->fs_bsize);
|
|
|
|
if (ind_level <= 0) {
|
|
|
|
if (find_blks32(idblk,
|
|
|
|
sblock->fs_bsize / sizeof(uint32_t), wantedblk))
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
ind_level--;
|
|
|
|
for (i = 0; i < sblock->fs_bsize / sizeof(uint32_t); i++) {
|
|
|
|
if (compare_blk32(wantedblk, iswap32(idblk[i]))) {
|
|
|
|
if (founddatablk(iswap32(idblk[i])))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if(idblk[i] != 0)
|
|
|
|
if (find_indirblks32(iswap32(idblk[i]),
|
|
|
|
ind_level, wantedblk))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef MAXNINDIR
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
find_blks64(uint64_t *buf, int size, uint64_t *wantedblk)
|
2003-04-26 12:42:49 +04:00
|
|
|
{
|
|
|
|
int blk;
|
|
|
|
for(blk = 0; blk < size; blk++) {
|
|
|
|
if (buf[blk] == 0)
|
|
|
|
continue;
|
|
|
|
if (compare_blk64(wantedblk, iswap64(buf[blk]))) {
|
|
|
|
if (founddatablk(iswap64(buf[blk])))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
find_indirblks64(uint64_t blk, int ind_level, uint64_t *wantedblk)
|
2003-04-26 12:42:49 +04:00
|
|
|
{
|
|
|
|
#define MAXNINDIR (MAXBSIZE / sizeof(uint64_t))
|
|
|
|
uint64_t idblk[MAXNINDIR];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
bread(fsreadfd, (char *)idblk, fsbtodb(sblock, blk),
|
|
|
|
(int)sblock->fs_bsize);
|
|
|
|
if (ind_level <= 0) {
|
|
|
|
if (find_blks64(idblk,
|
|
|
|
sblock->fs_bsize / sizeof(uint64_t), wantedblk))
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
ind_level--;
|
|
|
|
for (i = 0; i < sblock->fs_bsize / sizeof(uint64_t); i++) {
|
|
|
|
if (compare_blk64(wantedblk, iswap64(idblk[i]))) {
|
|
|
|
if (founddatablk(iswap64(idblk[i])))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if(idblk[i] != 0)
|
|
|
|
if (find_indirblks64(iswap64(idblk[i]),
|
|
|
|
ind_level, wantedblk))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef MAXNINDIR
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-02 14:39:19 +04:00
|
|
|
#define CHARS_PER_LINES 70
|
|
|
|
|
1999-03-09 19:11:47 +03:00
|
|
|
static void
|
2005-01-19 23:19:04 +03:00
|
|
|
print_blks32(int32_t *buf, int size, uint64_t *blknum)
|
1999-03-09 19:11:47 +03:00
|
|
|
{
|
|
|
|
int chars;
|
|
|
|
char prbuf[CHARS_PER_LINES+1];
|
|
|
|
int blk;
|
|
|
|
|
|
|
|
chars = 0;
|
|
|
|
for(blk = 0; blk < size; blk++, (*blknum)++) {
|
|
|
|
if (buf[blk] == 0)
|
|
|
|
continue;
|
|
|
|
snprintf(prbuf, CHARS_PER_LINES, "%d ", iswap32(buf[blk]));
|
|
|
|
if ((chars + strlen(prbuf)) > CHARS_PER_LINES) {
|
|
|
|
printf("\n");
|
|
|
|
chars = 0;
|
|
|
|
}
|
|
|
|
if (chars == 0)
|
2004-09-17 16:18:55 +04:00
|
|
|
printf("%" PRIu64 ": ", *blknum);
|
2000-10-11 00:24:49 +04:00
|
|
|
printf("%s", prbuf);
|
1999-03-09 19:11:47 +03:00
|
|
|
chars += strlen(prbuf);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-01-19 23:19:04 +03:00
|
|
|
print_blks64(int64_t *buf, int size, uint64_t *blknum)
|
2003-04-02 14:39:19 +04:00
|
|
|
{
|
|
|
|
int chars;
|
|
|
|
char prbuf[CHARS_PER_LINES+1];
|
|
|
|
int blk;
|
|
|
|
|
|
|
|
chars = 0;
|
|
|
|
for(blk = 0; blk < size; blk++, (*blknum)++) {
|
|
|
|
if (buf[blk] == 0)
|
|
|
|
continue;
|
|
|
|
snprintf(prbuf, CHARS_PER_LINES, "%lld ",
|
|
|
|
(long long)iswap64(buf[blk]));
|
|
|
|
if ((chars + strlen(prbuf)) > CHARS_PER_LINES) {
|
|
|
|
printf("\n");
|
|
|
|
chars = 0;
|
|
|
|
}
|
|
|
|
if (chars == 0)
|
2004-09-17 16:18:55 +04:00
|
|
|
printf("%" PRIu64 ": ", *blknum);
|
2003-04-02 14:39:19 +04:00
|
|
|
printf("%s", prbuf);
|
|
|
|
chars += strlen(prbuf);
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef CHARS_PER_LINES
|
|
|
|
|
|
|
|
static void
|
2005-01-19 23:19:04 +03:00
|
|
|
print_indirblks32(uint32_t blk, int ind_level, uint64_t *blknum)
|
1999-03-09 19:11:47 +03:00
|
|
|
{
|
2003-01-25 00:55:02 +03:00
|
|
|
#define MAXNINDIR (MAXBSIZE / sizeof(int32_t))
|
2004-09-17 16:18:55 +04:00
|
|
|
const int ptrperblk_shift = sblock->fs_bshift - 2;
|
|
|
|
const int ptrperblk = 1 << ptrperblk_shift;
|
2003-01-25 00:55:02 +03:00
|
|
|
int32_t idblk[MAXNINDIR];
|
1999-03-09 19:11:47 +03:00
|
|
|
int i;
|
2004-09-17 16:18:55 +04:00
|
|
|
|
|
|
|
if (blk == 0) {
|
|
|
|
*blknum += (uint64_t)ptrperblk << (ptrperblk_shift * ind_level);
|
|
|
|
return;
|
|
|
|
}
|
1999-03-09 19:11:47 +03:00
|
|
|
|
2003-01-25 00:55:02 +03:00
|
|
|
printf("Indirect block %lld (level %d):\n", (long long)blk,
|
|
|
|
ind_level+1);
|
1999-03-09 19:11:47 +03:00
|
|
|
bread(fsreadfd, (char *)idblk, fsbtodb(sblock, blk),
|
|
|
|
(int)sblock->fs_bsize);
|
|
|
|
if (ind_level <= 0) {
|
2004-09-17 16:18:55 +04:00
|
|
|
print_blks32(idblk, ptrperblk, blknum);
|
1999-03-09 19:11:47 +03:00
|
|
|
} else {
|
|
|
|
ind_level--;
|
2004-09-17 16:18:55 +04:00
|
|
|
for (i = 0; i < ptrperblk; i++)
|
|
|
|
print_indirblks32(iswap32(idblk[i]), ind_level, blknum);
|
2003-04-02 14:39:19 +04:00
|
|
|
}
|
|
|
|
#undef MAXNINDIR
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2005-01-19 23:19:04 +03:00
|
|
|
print_indirblks64(uint64_t blk, int ind_level, uint64_t *blknum)
|
2003-04-02 14:39:19 +04:00
|
|
|
{
|
|
|
|
#define MAXNINDIR (MAXBSIZE / sizeof(int64_t))
|
2004-09-17 16:18:55 +04:00
|
|
|
const int ptrperblk_shift = sblock->fs_bshift - 3;
|
|
|
|
const int ptrperblk = 1 << ptrperblk_shift;
|
2003-04-02 14:39:19 +04:00
|
|
|
int64_t idblk[MAXNINDIR];
|
|
|
|
int i;
|
2004-09-17 16:18:55 +04:00
|
|
|
|
|
|
|
if (blk == 0) {
|
|
|
|
*blknum += (uint64_t)ptrperblk << (ptrperblk_shift * ind_level);
|
|
|
|
return;
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
|
|
|
|
printf("Indirect block %lld (level %d):\n", (long long)blk,
|
|
|
|
ind_level+1);
|
|
|
|
bread(fsreadfd, (char *)idblk, fsbtodb(sblock, blk),
|
|
|
|
(int)sblock->fs_bsize);
|
|
|
|
if (ind_level <= 0) {
|
2004-09-17 16:18:55 +04:00
|
|
|
print_blks64(idblk, ptrperblk, blknum);
|
2003-04-02 14:39:19 +04:00
|
|
|
} else {
|
|
|
|
ind_level--;
|
2004-09-17 16:18:55 +04:00
|
|
|
for (i = 0; i < ptrperblk; i++)
|
|
|
|
print_indirblks64(iswap64(idblk[i]), ind_level, blknum);
|
1999-03-09 19:11:47 +03:00
|
|
|
}
|
|
|
|
#undef MAXNINDIR
|
|
|
|
}
|
|
|
|
|
1995-10-09 02:08:36 +03:00
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
dolookup(char *name)
|
1997-09-14 18:56:57 +04:00
|
|
|
{
|
|
|
|
struct inodesc idesc;
|
|
|
|
|
|
|
|
if (!checkactivedir())
|
|
|
|
return 0;
|
|
|
|
idesc.id_number = curinum;
|
|
|
|
idesc.id_func = findino;
|
|
|
|
idesc.id_name = name;
|
|
|
|
idesc.id_type = DATA;
|
|
|
|
idesc.id_fix = IGNORE;
|
|
|
|
if (ckinode(curinode, &idesc) & FOUND) {
|
|
|
|
curinum = idesc.id_parent;
|
|
|
|
curinode = ginode(curinum);
|
|
|
|
printactive();
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
warnx("name `%s' not found in current inode directory", name);
|
|
|
|
return 0;
|
|
|
|
}
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(focusname)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
char *p, *val;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
ocurrent = curinum;
|
|
|
|
|
|
|
|
if (argv[1][0] == '/') {
|
|
|
|
curinum = ROOTINO;
|
|
|
|
curinode = ginode(ROOTINO);
|
|
|
|
} else {
|
|
|
|
if (!checkactivedir())
|
|
|
|
return 1;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
1997-09-14 18:56:57 +04:00
|
|
|
for (p = argv[1]; p != NULL;) {
|
|
|
|
while ((val = strsep(&p, "/")) != NULL && *val == '\0');
|
|
|
|
if (val) {
|
|
|
|
printf("component `%s': ", val);
|
|
|
|
fflush(stdout);
|
|
|
|
if (!dolookup(val)) {
|
|
|
|
curinode = ginode(curinum);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(ln)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
ino_t inum;
|
|
|
|
int rval;
|
|
|
|
char *cp;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
GETINUM(1, inum);
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
if (!checkactivedir())
|
|
|
|
return 1;
|
|
|
|
rval = makeentry(curinum, inum, argv[2]);
|
|
|
|
if (rval)
|
2005-08-19 06:07:18 +04:00
|
|
|
printf("Ino %llu entered as `%s'\n", (unsigned long long)inum,
|
|
|
|
argv[2]);
|
1997-09-14 18:56:57 +04:00
|
|
|
else
|
|
|
|
printf("could not enter name? weird.\n");
|
|
|
|
curinode = ginode(curinum);
|
|
|
|
return rval;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(rm)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
int rval;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
if (!checkactivedir())
|
|
|
|
return 1;
|
|
|
|
rval = changeino(curinum, argv[1], 0);
|
|
|
|
if (rval & ALTERED) {
|
|
|
|
printf("Name `%s' removed\n", argv[1]);
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
printf("could not remove name? weird.\n");
|
|
|
|
return 1;
|
|
|
|
}
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static long slotcount, desired;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
chinumfunc(struct inodesc *idesc)
|
1995-10-09 02:08:36 +03:00
|
|
|
{
|
1997-09-15 05:45:36 +04:00
|
|
|
struct direct *dirp = idesc->id_dirp;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
|
|
|
if (slotcount++ == desired) {
|
1998-03-18 20:03:15 +03:00
|
|
|
dirp->d_ino = iswap32(idesc->id_parent);
|
1997-09-14 18:56:57 +04:00
|
|
|
return STOP | ALTERED | FOUND;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
return KEEPON;
|
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chinum)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
char *cp;
|
|
|
|
ino_t inum;
|
|
|
|
struct inodesc idesc;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
slotcount = 0;
|
|
|
|
if (!checkactivedir())
|
|
|
|
return 1;
|
|
|
|
GETINUM(2, inum);
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
desired = strtol(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0' || desired < 0) {
|
|
|
|
printf("invalid slot number `%s'\n", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
idesc.id_number = curinum;
|
|
|
|
idesc.id_func = chinumfunc;
|
|
|
|
idesc.id_fix = IGNORE;
|
|
|
|
idesc.id_type = DATA;
|
|
|
|
idesc.id_parent = inum; /* XXX convenient hiding place */
|
|
|
|
|
|
|
|
if (ckinode(curinode, &idesc) & FOUND)
|
|
|
|
return 0;
|
|
|
|
else {
|
|
|
|
warnx("no %sth slot in current directory", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
chnamefunc(struct inodesc *idesc)
|
1995-10-09 02:08:36 +03:00
|
|
|
{
|
1997-09-15 05:45:36 +04:00
|
|
|
struct direct *dirp = idesc->id_dirp;
|
1997-09-14 18:56:57 +04:00
|
|
|
struct direct testdir;
|
1996-09-28 23:30:35 +04:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
if (slotcount++ == desired) {
|
|
|
|
/* will name fit? */
|
|
|
|
testdir.d_namlen = strlen(idesc->id_name);
|
1998-03-18 20:03:15 +03:00
|
|
|
if (DIRSIZ(NEWDIRFMT, &testdir, 0) <= iswap16(dirp->d_reclen)) {
|
1997-09-14 18:56:57 +04:00
|
|
|
dirp->d_namlen = testdir.d_namlen;
|
2003-07-13 12:16:15 +04:00
|
|
|
strlcpy(dirp->d_name, idesc->id_name,
|
|
|
|
sizeof(dirp->d_name));
|
1997-09-14 18:56:57 +04:00
|
|
|
return STOP | ALTERED | FOUND;
|
|
|
|
} else
|
|
|
|
return STOP | FOUND; /* won't fit, so give up */
|
|
|
|
}
|
|
|
|
return KEEPON;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chname)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
int rval;
|
|
|
|
char *cp;
|
|
|
|
struct inodesc idesc;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
slotcount = 0;
|
|
|
|
if (!checkactivedir())
|
|
|
|
return 1;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
desired = strtoul(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0') {
|
|
|
|
printf("invalid slot number `%s'\n", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
idesc.id_number = curinum;
|
|
|
|
idesc.id_func = chnamefunc;
|
|
|
|
idesc.id_fix = IGNORE;
|
|
|
|
idesc.id_type = DATA;
|
|
|
|
idesc.id_name = argv[2];
|
|
|
|
|
|
|
|
rval = ckinode(curinode, &idesc);
|
|
|
|
if ((rval & (FOUND | ALTERED)) == (FOUND | ALTERED))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
if (rval & FOUND) {
|
2002-07-20 12:36:17 +04:00
|
|
|
warnx("new name `%s' does not fit in slot %s",
|
1997-09-14 18:56:57 +04:00
|
|
|
argv[2], argv[1]);
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
warnx("no %sth slot in current directory", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static struct typemap {
|
1997-09-14 18:56:57 +04:00
|
|
|
const char *typename;
|
|
|
|
int typebits;
|
|
|
|
} typenamemap[] = {
|
|
|
|
{ "file", IFREG },
|
|
|
|
{ "dir", IFDIR },
|
|
|
|
{ "socket", IFSOCK },
|
|
|
|
{ "fifo", IFIFO },
|
1995-10-09 02:08:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
CMDFUNCSTART(newtype)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
int type;
|
2003-04-02 14:39:19 +04:00
|
|
|
uint16_t mode;
|
1997-09-14 18:56:57 +04:00
|
|
|
struct typemap *tp;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
2003-04-02 14:39:19 +04:00
|
|
|
mode = iswap16(DIP(curinode, mode));
|
|
|
|
type = mode & IFMT;
|
1997-09-14 18:56:57 +04:00
|
|
|
for (tp = typenamemap;
|
2003-04-02 14:39:19 +04:00
|
|
|
tp < &typenamemap[sizeof(typenamemap) / sizeof(*typenamemap)];
|
1997-09-14 18:56:57 +04:00
|
|
|
tp++) {
|
|
|
|
if (!strcmp(argv[1], tp->typename)) {
|
|
|
|
printf("setting type to %s\n", tp->typename);
|
|
|
|
type = tp->typebits;
|
|
|
|
break;
|
|
|
|
}
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
if (tp == &typenamemap[sizeof(typenamemap) / sizeof(*typenamemap)]) {
|
1997-09-14 18:56:57 +04:00
|
|
|
warnx("type `%s' not known", argv[1]);
|
|
|
|
warnx("try one of `file', `dir', `socket', `fifo'");
|
|
|
|
return 1;
|
|
|
|
}
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, mode, iswap16((mode & ~IFMT) | type));
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
printactive();
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chmode)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
long modebits;
|
|
|
|
char *cp;
|
2003-04-02 14:39:19 +04:00
|
|
|
uint16_t mode;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
modebits = strtol(argv[1], &cp, 8);
|
|
|
|
if (cp == argv[1] || *cp != '\0') {
|
|
|
|
warnx("bad modebits `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
2003-04-02 14:39:19 +04:00
|
|
|
mode = iswap16(DIP(curinode, mode));
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, mode, iswap16((mode & ~07777) | modebits));
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
printactive();
|
1998-03-18 20:03:15 +03:00
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
1996-10-12 00:22:43 +04:00
|
|
|
CMDFUNCSTART(chlen)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
long len;
|
|
|
|
char *cp;
|
1996-10-12 00:22:43 +04:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
1996-10-12 00:22:43 +04:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
len = strtol(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0' || len < 0) {
|
|
|
|
warnx("bad length '%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, size, iswap64(len));
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
printactive();
|
1998-03-18 20:03:15 +03:00
|
|
|
return 0;
|
1996-10-12 00:22:43 +04:00
|
|
|
}
|
|
|
|
|
1995-10-09 02:08:36 +03:00
|
|
|
CMDFUNCSTART(chaflags)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
u_long flags;
|
|
|
|
char *cp;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
flags = strtoul(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0') {
|
|
|
|
warnx("bad flags `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (flags > UINT_MAX) {
|
2002-07-20 12:36:17 +04:00
|
|
|
warnx("flags set beyond 32-bit range of field (0x%lx)",
|
1997-09-14 18:56:57 +04:00
|
|
|
flags);
|
|
|
|
return (1);
|
|
|
|
}
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, flags, iswap32(flags));
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
printactive();
|
1998-03-18 20:03:15 +03:00
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chgen)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
long gen;
|
|
|
|
char *cp;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
gen = strtol(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0') {
|
|
|
|
warnx("bad gen `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (gen > INT_MAX || gen < INT_MIN) {
|
2002-07-20 12:36:17 +04:00
|
|
|
warnx("gen set beyond 32-bit range of field (0x%lx)", gen);
|
1997-09-14 18:56:57 +04:00
|
|
|
return (1);
|
|
|
|
}
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, gen, iswap32(gen));
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
printactive();
|
1998-03-18 20:03:15 +03:00
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(linkcount)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
int lcnt;
|
|
|
|
char *cp;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
lcnt = strtol(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0') {
|
|
|
|
warnx("bad link count `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (lcnt > USHRT_MAX || lcnt < 0) {
|
2002-07-20 12:36:17 +04:00
|
|
|
warnx("max link count is %d", USHRT_MAX);
|
1997-09-14 18:56:57 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, nlink, iswap16(lcnt));
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
printactive();
|
1998-03-18 20:03:15 +03:00
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chowner)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
unsigned long uid;
|
|
|
|
char *cp;
|
|
|
|
struct passwd *pwd;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
uid = strtoul(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0') {
|
|
|
|
/* try looking up name */
|
|
|
|
if ((pwd = getpwnam(argv[1])) != 0) {
|
|
|
|
uid = pwd->pw_uid;
|
|
|
|
} else {
|
|
|
|
warnx("bad uid `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
2004-01-03 22:57:42 +03:00
|
|
|
if (!is_ufs2 && sblock->fs_old_inodefmt < FS_44INODEFMT)
|
|
|
|
curinode->dp1.di_ouid = iswap32(uid);
|
|
|
|
else
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, uid, iswap32(uid));
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
printactive();
|
1998-03-18 20:03:15 +03:00
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chgroup)
|
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
unsigned long gid;
|
|
|
|
char *cp;
|
|
|
|
struct group *grp;
|
|
|
|
|
|
|
|
if (!checkactive())
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
gid = strtoul(argv[1], &cp, 0);
|
|
|
|
if (cp == argv[1] || *cp != '\0') {
|
|
|
|
if ((grp = getgrnam(argv[1])) != 0) {
|
|
|
|
gid = grp->gr_gid;
|
|
|
|
} else {
|
|
|
|
warnx("bad gid `%s'", argv[1]);
|
|
|
|
return 1;
|
|
|
|
}
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
2004-01-03 22:57:42 +03:00
|
|
|
if (sblock->fs_old_inodefmt < FS_44INODEFMT)
|
|
|
|
curinode->dp1.di_ogid = iswap32(gid);
|
|
|
|
else
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, gid, iswap32(gid));
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
printactive();
|
1998-03-18 20:03:15 +03:00
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
1996-09-28 23:30:35 +04:00
|
|
|
static int
|
2005-01-19 23:19:04 +03:00
|
|
|
dotime(char *name, int32_t *rsec, int32_t *rnsec)
|
1995-10-09 02:08:36 +03:00
|
|
|
{
|
1997-09-14 18:56:57 +04:00
|
|
|
char *p, *val;
|
|
|
|
struct tm t;
|
|
|
|
int32_t sec;
|
|
|
|
int32_t nsec;
|
|
|
|
p = strchr(name, '.');
|
|
|
|
if (p) {
|
|
|
|
*p = '\0';
|
|
|
|
nsec = strtoul(++p, &val, 0);
|
|
|
|
if (val == p || *val != '\0' || nsec >= 1000000000 || nsec < 0) {
|
|
|
|
warnx("invalid nanoseconds");
|
|
|
|
goto badformat;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
nsec = 0;
|
|
|
|
if (strlen(name) != 14) {
|
1995-10-09 02:08:36 +03:00
|
|
|
badformat:
|
1997-09-14 18:56:57 +04:00
|
|
|
warnx("date format: YYYYMMDDHHMMSS[.nsec]");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
for (p = name; *p; p++)
|
|
|
|
if (*p < '0' || *p > '9')
|
|
|
|
goto badformat;
|
1995-10-09 02:08:36 +03:00
|
|
|
|
1997-09-14 18:56:57 +04:00
|
|
|
p = name;
|
1995-10-09 02:08:36 +03:00
|
|
|
#define VAL() ((*p++) - '0')
|
1997-09-14 18:56:57 +04:00
|
|
|
t.tm_year = VAL();
|
|
|
|
t.tm_year = VAL() + t.tm_year * 10;
|
|
|
|
t.tm_year = VAL() + t.tm_year * 10;
|
|
|
|
t.tm_year = VAL() + t.tm_year * 10 - 1900;
|
|
|
|
t.tm_mon = VAL();
|
|
|
|
t.tm_mon = VAL() + t.tm_mon * 10 - 1;
|
|
|
|
t.tm_mday = VAL();
|
|
|
|
t.tm_mday = VAL() + t.tm_mday * 10;
|
|
|
|
t.tm_hour = VAL();
|
|
|
|
t.tm_hour = VAL() + t.tm_hour * 10;
|
|
|
|
t.tm_min = VAL();
|
|
|
|
t.tm_min = VAL() + t.tm_min * 10;
|
|
|
|
t.tm_sec = VAL();
|
|
|
|
t.tm_sec = VAL() + t.tm_sec * 10;
|
|
|
|
t.tm_isdst = -1;
|
|
|
|
|
|
|
|
sec = mktime(&t);
|
|
|
|
if (sec == -1) {
|
|
|
|
warnx("date/time out of range");
|
|
|
|
return 1;
|
|
|
|
}
|
1998-03-18 20:03:15 +03:00
|
|
|
*rsec = iswap32(sec);
|
|
|
|
*rnsec = iswap32(nsec);
|
1997-09-14 18:56:57 +04:00
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chmtime)
|
|
|
|
{
|
2003-04-02 14:39:19 +04:00
|
|
|
int32_t rsec, nsec;
|
|
|
|
|
|
|
|
if (dotime(argv[1], &rsec, &nsec))
|
1997-09-14 18:56:57 +04:00
|
|
|
return 1;
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, mtime, rsec);
|
|
|
|
DIP_SET(curinode, mtimensec, nsec);
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
printactive();
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chatime)
|
|
|
|
{
|
2003-04-02 14:39:19 +04:00
|
|
|
int32_t rsec, nsec;
|
|
|
|
|
|
|
|
if (dotime(argv[1], &rsec, &nsec))
|
1997-09-14 18:56:57 +04:00
|
|
|
return 1;
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, atime, rsec);
|
|
|
|
DIP_SET(curinode, atimensec, nsec);
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
printactive();
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CMDFUNCSTART(chctime)
|
|
|
|
{
|
2003-04-02 14:39:19 +04:00
|
|
|
int32_t rsec, nsec;
|
|
|
|
|
|
|
|
if (dotime(argv[1], &rsec, &nsec))
|
1997-09-14 18:56:57 +04:00
|
|
|
return 1;
|
2006-04-21 19:00:49 +04:00
|
|
|
DIP_SET(curinode, ctime, rsec);
|
|
|
|
DIP_SET(curinode, ctimensec, nsec);
|
1997-09-14 18:56:57 +04:00
|
|
|
inodirty();
|
|
|
|
printactive();
|
|
|
|
return 0;
|
1995-10-09 02:08:36 +03:00
|
|
|
}
|