2 * This program, created 2002-10-03 by Garrett A. Wollman
3 * <wollman@FreeBSD.org>, is in the public domain. Use at your own risk.
11 #include <ufs/ufs/dinode.h>
12 #include <ufs/ffs/fs.h>
31 main(int argc, char **argv)
33 off_t end, last1, last2;
42 while ((c = getopt(argc, argv, "o:")) != -1) {
45 if (optarg[0] == '\0')
47 offset = strtoimax(optarg, &ch, 10);
48 if (*ch != '\0' || offset < 0)
50 offset -= offset % DEV_BSIZE;
63 fd = open(argv[0], O_RDONLY, 0);
65 err(1, "%s", argv[0]);
68 end = lseek(fd, offset, SEEK_SET);
70 err(1, "%s", argv[0]);
78 justread = read(fd, &u.buf[len], DEV_BSIZE);
79 if (justread != DEV_BSIZE) {
81 printf("reached end-of-file at %jd\n",
87 errx(1, "short read %jd (wanted %d) at %jd",
88 (intmax_t)justread, DEV_BSIZE, (intmax_t)end);
92 if (len >= sizeof(struct fs)) {
95 if (u.sblock.fs_magic == FS_UFS1_MAGIC) {
96 intmax_t fsbegin = offset - SBLOCK_UFS1;
97 printf("Found UFS1 superblock at offset %jd, "
98 "block %jd\n", offset,
100 printf("Filesystem might begin at offset %jd, "
101 "block %jd\n", fsbegin,
102 fsbegin / DEV_BSIZE);
104 printf("%jd blocks from last guess\n",
105 fsbegin / DEV_BSIZE - last1);
107 last1 = fsbegin / DEV_BSIZE;
109 memmove(u.buf, &u.buf[DEV_BSIZE], len);
110 } else if (u.sblock.fs_magic == FS_UFS2_MAGIC) {
111 intmax_t fsbegin = offset - SBLOCK_UFS2;
112 printf("Found UFS2 superblock at offset %jd, "
113 "block %jd\n", offset,
115 printf("Filesystem might begin at offset %jd, "
116 "block %jd\n", fsbegin,
117 fsbegin / DEV_BSIZE);
119 printf("%jd blocks from last guess\n",
120 fsbegin / DEV_BSIZE - last2);
122 last2 = fsbegin / DEV_BSIZE;
124 memmove(u.buf, &u.buf[DEV_BSIZE], len);
127 if (len >= SBLOCKSIZE) {
128 memmove(u.buf, &u.buf[DEV_BSIZE],
129 SBLOCKSIZE - DEV_BSIZE);