/*1* Copyright (c) 1998, 2003, 2013, 2018 Marshall Kirk McKusick.2* All Rights Reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY MARSHALL KIRK MCKUSICK ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL MARSHALL KIRK MCKUSICK BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#include <ufs/ffs/fs.h>2728#include <err.h>29#include <stdlib.h>30#include <stdio.h>31#include <sys/stat.h>32#include <libufs.h>3334void prtblknos(struct fs *fs, union dinode *dp);3536struct uufsd disk;3738int39main(int argc, char *argv[])40{41union dinodep dp;42struct fs *fs;43struct stat sb;44struct statfs sfb;45char *xargv[4];46char ibuf[64];47char *fsname, *filename;48ino_t inonum;4950filename = NULL;51if (argc == 2) {52filename = argv[1];53if (lstat(filename, &sb) != 0)54err(1, "stat(%s)", filename);55if (statfs(filename, &sfb) != 0)56err(1, "statfs(%s)", filename);57xargv[0] = argv[0];58xargv[1] = sfb.f_mntfromname;59sprintf(ibuf, "%jd", (intmax_t)sb.st_ino);60xargv[2] = ibuf;61xargv[3] = NULL;62argv = xargv;63argc = 3;64}65if (argc < 3) {66(void)fprintf(stderr, "%s\n%s\n",67"usage: prtblknos filename",68" prtblknos filesystem inode ...");69exit(1);70}7172fsname = *++argv;7374/* get the superblock. */75if (ufs_disk_fillout_blank(&disk, fsname) == -1 ||76sbfind(&disk, 0) == -1)77err(1, "Cannot access file system superblock on %s", fsname);78fs = (struct fs *)&disk.d_sbunion.d_sb;7980/* remaining arguments are inode numbers. */81while (*++argv) {82/* get the inode number. */83if ((inonum = atoi(*argv)) <= 0 ||84inonum >= (ino_t)fs->fs_ipg * fs->fs_ncg)85warnx("%s is not a valid inode number", *argv);86if (filename == NULL)87(void)printf("inode #%jd: ", (intmax_t)inonum);88else89(void)printf("%s (inode #%jd): ", filename,90(intmax_t)inonum);9192if (getinode(&disk, &dp, inonum) < 0)93warn("Read of inode %jd on %s failed: %s",94(intmax_t)inonum, fsname, disk.d_error);9596prtblknos(fs, (union dinode *)dp.dp1);97}98exit(0);99}100101102