scan_ffs minimal ufs2

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

scan_ffs minimal ufs2

gwes-2

Fixed 2 bugs:
   size output was in bytes not DEV_BSIZE blocks
   would not find fs with fs_frag == 4096
Added:
   recognize UFS2

Index: scan_ffs.c
===================================================================
RCS file: /cvs/src/sbin/scan_ffs/scan_ffs.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 scan_ffs.c
--- scan_ffs.c 23 Nov 2015 19:19:30 -0000 1.21
+++ scan_ffs.c 18 Feb 2019 02:02:37 -0000
@@ -45,6 +45,7 @@
 #define FLAG_LABELS 4
 
 static void usage(void);
+static void ffs1_compat_read(struct fs *);
 
 static int
 ufsscan(int fd, daddr_t beg, daddr_t end, int flags)
@@ -66,39 +67,49 @@ ufsscan(int fd, daddr_t beg, daddr_t end
  err(1, "read");
 
  for (n = 0; n < (SBSIZE * SBCOUNT); n += 512){
+ long long sboff;
  sb = (struct fs*)(&buf[n]);
- if (sb->fs_magic == FS_MAGIC) {
+ if (sb->fs_magic == FS_UFS1_MAGIC ||
+    sb->fs_magic == FS_UFS2_MAGIC) {
+ ffs1_compat_read(sb);
  if (flags & FLAG_VERBOSE)
- printf("block %lld id %x,%x size %d\n",
+ printf("block %lld id %x,%x size %lld\n",
     (long long)(blk + (n/512)),
     sb->fs_id[0], sb->fs_id[1],
-    sb->fs_ffs1_size);
+    sb->fs_size * sb->fs_fsize / 512);
 
- if (((blk+(n/512)) - lastblk) == (SBSIZE/512)) {
+ if (sb->fs_magic == FS_UFS1_MAGIC)
+ sboff = SBLOCK_UFS1;
+ else
+ sboff = SBLOCK_UFS2;
+ if ((blk+(n/512) - lastblk) ==
+    (fsbtodb(sb, cgsblock(sb, 0)) -
+    sboff / 512)) {
  if (flags & FLAG_LABELS ) {
  printf("X: %lld %lld 4.2BSD %d %d %d # %s\n",
-    ((off_t)sb->fs_ffs1_size *
+    ((off_t)sb->fs_size *
     sb->fs_fsize / 512),
     (long long)(blk + (n/512) -
-    (2*SBSIZE/512)),
+    fsbtodb(sb, cgsblock(sb, 0))),
     sb->fs_fsize, sb->fs_bsize,
     sb->fs_cpg, lastmount);
  } else {
  /* XXX 2038 */
- time_t t = sb->fs_ffs1_time;
+ time_t t = sb->fs_time;
 
  printf("ffs at %lld size %lld "
     "mount %s time %s",
     (long long)(blk+(n/512) -
-    (2*SBSIZE/512)),
-    (long long)(off_t)sb->fs_ffs1_size *
-    sb->fs_fsize,
+    fsbtodb(sb, cgsblock(sb, 0))),
+    (long long)(off_t)sb->fs_size *
+    sb->fs_fsize / 512,
     lastmount, ctime(&t));
  }
 
  if (flags & FLAG_SMART) {
- off_t size = (off_t)sb->fs_ffs1_size *
-    sb->fs_fsize;
+ off_t size = (off_t)sb->fs_size *
+    sb->fs_fsize -
+    fsbtodb(sb, cgsblock(sb, 0)) * 512;
 
  if ((n + size) < (SBSIZE * SBCOUNT))
  n += size;
@@ -181,3 +192,22 @@ main(int argc, char *argv[])
 
  return (ufsscan(fd, beg, end, flags));
 }
+
+static void
+ffs1_compat_read(struct fs *fs)
+{
+ if (fs->fs_magic == FS_UFS2_MAGIC)
+ return; /* UFS2 */
+ if (fs->fs_sblockloc == 0)
+ fs->fs_sblockloc = SBLOCK_UFS1;
+ fs->fs_flags = fs->fs_ffs1_flags;
+ fs->fs_maxbsize = fs->fs_bsize;
+ fs->fs_time = fs->fs_ffs1_time;
+ fs->fs_size = fs->fs_ffs1_size;
+ fs->fs_dsize = fs->fs_ffs1_dsize;
+ fs->fs_csaddr = fs->fs_ffs1_csaddr;
+ fs->fs_cstotal.cs_ndir = fs->fs_ffs1_cstotal.cs_ndir;
+ fs->fs_cstotal.cs_nbfree = fs->fs_ffs1_cstotal.cs_nbfree;
+ fs->fs_cstotal.cs_nifree = fs->fs_ffs1_cstotal.cs_nifree;
+ fs->fs_cstotal.cs_nffree = fs->fs_ffs1_cstotal.cs_nffree;
+}