2018-04-08 06:52:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1998, 2003, 2013, 2018 Marshall Kirk McKusick.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* 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 MARSHALL KIRK MCKUSICK ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL MARSHALL KIRK MCKUSICK BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 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 POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ufs/ffs/fs.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2018-04-18 23:08:10 +00:00
|
|
|
#include <sys/stat.h>
|
2018-04-08 06:52:58 +00:00
|
|
|
#include <libufs.h>
|
|
|
|
|
|
|
|
union dinode {
|
|
|
|
struct ufs1_dinode *dp1;
|
|
|
|
struct ufs2_dinode *dp2;
|
|
|
|
};
|
|
|
|
|
2020-09-19 20:06:12 +00:00
|
|
|
void prtblknos(struct fs *fs, union dinode *dp);
|
|
|
|
|
|
|
|
struct uufsd disk;
|
2018-04-08 06:52:58 +00:00
|
|
|
|
|
|
|
int
|
2023-03-22 22:57:26 +00:00
|
|
|
main(int argc, char *argv[])
|
2018-04-08 06:52:58 +00:00
|
|
|
{
|
2018-11-13 21:40:56 +00:00
|
|
|
union dinodep dp;
|
2018-04-08 06:52:58 +00:00
|
|
|
struct fs *fs;
|
2018-04-18 23:08:10 +00:00
|
|
|
struct stat sb;
|
|
|
|
struct statfs sfb;
|
|
|
|
char *xargv[4];
|
|
|
|
char ibuf[64];
|
2018-04-19 22:43:55 +00:00
|
|
|
char *fsname, *filename;
|
|
|
|
ino_t inonum;
|
2018-04-08 06:52:58 +00:00
|
|
|
|
2018-04-19 22:43:55 +00:00
|
|
|
filename = NULL;
|
2018-04-18 23:08:10 +00:00
|
|
|
if (argc == 2) {
|
2018-04-19 22:43:55 +00:00
|
|
|
filename = argv[1];
|
|
|
|
if (lstat(filename, &sb) != 0)
|
|
|
|
err(1, "stat(%s)", filename);
|
|
|
|
if (statfs(filename, &sfb) != 0)
|
|
|
|
err(1, "statfs(%s)", filename);
|
2018-04-18 23:08:10 +00:00
|
|
|
xargv[0] = argv[0];
|
|
|
|
xargv[1] = sfb.f_mntfromname;
|
|
|
|
sprintf(ibuf, "%jd", (intmax_t)sb.st_ino);
|
|
|
|
xargv[2] = ibuf;
|
|
|
|
xargv[3] = NULL;
|
|
|
|
argv = xargv;
|
|
|
|
argc = 3;
|
|
|
|
}
|
2018-04-08 06:52:58 +00:00
|
|
|
if (argc < 3) {
|
2018-04-18 23:08:10 +00:00
|
|
|
(void)fprintf(stderr, "%s\n%s\n",
|
|
|
|
"usage: prtblknos filename",
|
|
|
|
" prtblknos filesystem inode ...");
|
2018-04-08 06:52:58 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fsname = *++argv;
|
|
|
|
|
|
|
|
/* get the superblock. */
|
Move the ability to search for alternate UFS superblocks from fsck_ffs(8)
into ffs_sbsearch() to allow use by other parts of the system.
Historically only fsck_ffs(8), the UFS filesystem checker, had code
to track down and use alternate UFS superblocks. Since fsdb(8) used
much of the fsck_ffs(8) implementation it had some ability to track
down alternate superblocks.
This change extracts the code to track down alternate superblocks
from fsck_ffs(8) and puts it into a new function ffs_sbsearch() in
sys/ufs/ffs/ffs_subr.c. Like ffs_sbget() and ffs_sbput() also found
in ffs_subr.c, these functions can be used directly by the kernel
subsystems. Additionally they are exported to the UFS library,
libufs(8) so that they can be used by user-level programs. The new
functions added to libufs(8) are sbfind(3) that is an alternative
to sbread(3) and sbsearch(3) that is an alternative to sbget(3).
See their manual pages for further details.
The utilities that have been changed to search for superblocks are
dumpfs(8), fsdb(8), ffsinfo(8), and fsck_ffs(8). Also, the prtblknos(8)
tool found in tools/diag/prtblknos searches for superblocks.
The UFS specific mount code uses the superblock search interface
when mounting the root filesystem and when the administrator doing
a mount(8) command specifies the force flag (-f). The standalone UFS
boot code (found in stand/libsa/ufs.c) uses the superblock search
code in the hope of being able to get the system up and running so
that fsck_ffs(8) can be used to get the filesystem cleaned up.
The following utilities have not been changed to search for
superblocks: clri(8), tunefs(8), snapinfo(8), fstyp(8), quot(8),
dump(8), fsirand(8), growfs(8), quotacheck(8), gjournal(8), and
glabel(8). When these utilities fail, they do report the cause of
the failure. The one exception is the tasting code used to try and
figure what a given disk contains. The tasting code will remain
silent so as not to put out a slew of messages as it trying to taste
every new mass storage device that shows up.
Reviewed by: kib
Reviewed by: Warner Losh
Tested by: Peter Holm
Differential Revision: https://reviews.freebsd.org/D36053
Sponsored by: The FreeBSD Foundation
2022-08-13 19:41:53 +00:00
|
|
|
if (ufs_disk_fillout_blank(&disk, fsname) == -1 ||
|
|
|
|
sbfind(&disk, 0) == -1)
|
2018-04-18 23:08:10 +00:00
|
|
|
err(1, "Cannot access file system superblock on %s", fsname);
|
2018-04-08 06:52:58 +00:00
|
|
|
fs = (struct fs *)&disk.d_sb;
|
|
|
|
|
|
|
|
/* remaining arguments are inode numbers. */
|
|
|
|
while (*++argv) {
|
|
|
|
/* get the inode number. */
|
|
|
|
if ((inonum = atoi(*argv)) <= 0 ||
|
2018-04-19 22:43:55 +00:00
|
|
|
inonum >= (ino_t)fs->fs_ipg * fs->fs_ncg)
|
2018-04-18 23:08:10 +00:00
|
|
|
warnx("%s is not a valid inode number", *argv);
|
2018-04-19 22:43:55 +00:00
|
|
|
if (filename == NULL)
|
|
|
|
(void)printf("inode #%jd: ", (intmax_t)inonum);
|
|
|
|
else
|
|
|
|
(void)printf("%s (inode #%jd): ", filename,
|
|
|
|
(intmax_t)inonum);
|
2018-04-08 06:52:58 +00:00
|
|
|
|
Move the ability to search for alternate UFS superblocks from fsck_ffs(8)
into ffs_sbsearch() to allow use by other parts of the system.
Historically only fsck_ffs(8), the UFS filesystem checker, had code
to track down and use alternate UFS superblocks. Since fsdb(8) used
much of the fsck_ffs(8) implementation it had some ability to track
down alternate superblocks.
This change extracts the code to track down alternate superblocks
from fsck_ffs(8) and puts it into a new function ffs_sbsearch() in
sys/ufs/ffs/ffs_subr.c. Like ffs_sbget() and ffs_sbput() also found
in ffs_subr.c, these functions can be used directly by the kernel
subsystems. Additionally they are exported to the UFS library,
libufs(8) so that they can be used by user-level programs. The new
functions added to libufs(8) are sbfind(3) that is an alternative
to sbread(3) and sbsearch(3) that is an alternative to sbget(3).
See their manual pages for further details.
The utilities that have been changed to search for superblocks are
dumpfs(8), fsdb(8), ffsinfo(8), and fsck_ffs(8). Also, the prtblknos(8)
tool found in tools/diag/prtblknos searches for superblocks.
The UFS specific mount code uses the superblock search interface
when mounting the root filesystem and when the administrator doing
a mount(8) command specifies the force flag (-f). The standalone UFS
boot code (found in stand/libsa/ufs.c) uses the superblock search
code in the hope of being able to get the system up and running so
that fsck_ffs(8) can be used to get the filesystem cleaned up.
The following utilities have not been changed to search for
superblocks: clri(8), tunefs(8), snapinfo(8), fstyp(8), quot(8),
dump(8), fsirand(8), growfs(8), quotacheck(8), gjournal(8), and
glabel(8). When these utilities fail, they do report the cause of
the failure. The one exception is the tasting code used to try and
figure what a given disk contains. The tasting code will remain
silent so as not to put out a slew of messages as it trying to taste
every new mass storage device that shows up.
Reviewed by: kib
Reviewed by: Warner Losh
Tested by: Peter Holm
Differential Revision: https://reviews.freebsd.org/D36053
Sponsored by: The FreeBSD Foundation
2022-08-13 19:41:53 +00:00
|
|
|
if (getinode(&disk, &dp, inonum) < 0)
|
2018-11-13 21:40:56 +00:00
|
|
|
warn("Read of inode %jd on %s failed: %s",
|
|
|
|
(intmax_t)inonum, fsname, disk.d_error);
|
2018-04-08 06:52:58 +00:00
|
|
|
|
2020-09-19 20:06:12 +00:00
|
|
|
prtblknos(fs, (union dinode *)dp.dp1);
|
2018-04-08 06:52:58 +00:00
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|