Sun Apr 24 06:48:15 2022 UTC ()
Ask driver about sector size to support reading superblocks from fixed
byte offsets.


(mlelstv)
diff -r1.30 -r1.31 src/sys/lib/libsa/ext2fs.c
diff -r1.9 -r1.10 src/sys/lib/libsa/minixfs3.c
diff -r1.4 -r1.5 src/sys/lib/libsa/saioctl.h
diff -r1.81 -r1.82 src/sys/lib/libsa/ufs.c

cvs diff -r1.30 -r1.31 src/sys/lib/libsa/ext2fs.c (expand / switch to unified diff)

--- src/sys/lib/libsa/ext2fs.c 2022/04/19 09:25:38 1.30
+++ src/sys/lib/libsa/ext2fs.c 2022/04/24 06:48:15 1.31
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ext2fs.c,v 1.30 2022/04/19 09:25:38 skrll Exp $ */ 1/* $NetBSD: ext2fs.c,v 1.31 2022/04/24 06:48:15 mlelstv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Manuel Bouyer. 4 * Copyright (c) 1997 Manuel Bouyer.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -405,29 +405,35 @@ search_directory(const char *name, int l @@ -405,29 +405,35 @@ search_directory(const char *name, int l
405 } 405 }
406 fp->f_seekp += buf_size; 406 fp->f_seekp += buf_size;
407 } 407 }
408 return ENOENT; 408 return ENOENT;
409} 409}
410 410
411int 411int
412read_sblock(struct open_file *f, struct m_ext2fs *fs) 412read_sblock(struct open_file *f, struct m_ext2fs *fs)
413{ 413{
414 static uint8_t sbbuf[SBSIZE]; 414 static uint8_t sbbuf[SBSIZE];
415 struct ext2fs ext2fs; 415 struct ext2fs ext2fs;
416 size_t buf_size; 416 size_t buf_size;
417 int rc; 417 int rc;
 418 u_int secsize;
 419
 420 secsize = 0;
 421 rc = DEV_IOCTL(f->f_dev)(f, SAIOSECSIZE, &secsize);
 422 if (rc != 0 || secsize == 0)
 423 secsize = DEV_BSIZE;
418 424
419 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, 425 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
420 SBOFF / DEV_BSIZE, SBSIZE, sbbuf, &buf_size); 426 SBOFF / secsize, SBSIZE, sbbuf, &buf_size);
421 if (rc) 427 if (rc)
422 return rc; 428 return rc;
423 429
424 if (buf_size != SBSIZE) 430 if (buf_size != SBSIZE)
425 return EIO; 431 return EIO;
426 432
427 e2fs_sbload((void *)sbbuf, &ext2fs); 433 e2fs_sbload((void *)sbbuf, &ext2fs);
428 if (ext2fs.e2fs_magic != E2FS_MAGIC) 434 if (ext2fs.e2fs_magic != E2FS_MAGIC)
429 return EINVAL; 435 return EINVAL;
430 if (ext2fs.e2fs_rev > E2FS_REV1 || 436 if (ext2fs.e2fs_rev > E2FS_REV1 ||
431 (ext2fs.e2fs_rev == E2FS_REV1 && 437 (ext2fs.e2fs_rev == E2FS_REV1 &&
432 (ext2fs.e2fs_first_ino != EXT2_FIRSTINO || 438 (ext2fs.e2fs_first_ino != EXT2_FIRSTINO ||
433 (ext2fs.e2fs_inode_size != 128 && ext2fs.e2fs_inode_size != 256) || 439 (ext2fs.e2fs_inode_size != 128 && ext2fs.e2fs_inode_size != 256) ||

cvs diff -r1.9 -r1.10 src/sys/lib/libsa/minixfs3.c (expand / switch to unified diff)

--- src/sys/lib/libsa/minixfs3.c 2022/04/19 09:25:38 1.9
+++ src/sys/lib/libsa/minixfs3.c 2022/04/24 06:48:15 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: minixfs3.c,v 1.9 2022/04/19 09:25:38 skrll Exp $ */ 1/* $NetBSD: minixfs3.c,v 1.10 2022/04/24 06:48:15 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2012 4 * Copyright (c) 2012
5 * Vrije Universiteit, Amsterdam, The Netherlands. All rights reserved. 5 * Vrije Universiteit, Amsterdam, The Netherlands. All rights reserved.
6 * 6 *
7 * Author: Evgeniy Ivanov (based on libsa/ext2fs.c). 7 * Author: Evgeniy Ivanov (based on libsa/ext2fs.c).
8 * 8 *
9 * This code is derived from src/sys/lib/libsa/ext2fs.c contributed to  9 * This code is derived from src/sys/lib/libsa/ext2fs.c contributed to
10 * The NetBSD Foundation, see copyrights below. 10 * The NetBSD Foundation, see copyrights below.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -439,35 +439,41 @@ search_directory(const char *name, int l @@ -439,35 +439,41 @@ search_directory(const char *name, int l
439 } 439 }
440 } 440 }
441 fp->f_seekp += buf_size; 441 fp->f_seekp += buf_size;
442 } 442 }
443 return ENOENT; 443 return ENOENT;
444} 444}
445 445
446int 446int
447read_sblock(struct open_file *f, struct mfs_sblock *fs) 447read_sblock(struct open_file *f, struct mfs_sblock *fs)
448{ 448{
449 static uint8_t sbbuf[MINBSIZE]; 449 static uint8_t sbbuf[MINBSIZE];
450 size_t buf_size; 450 size_t buf_size;
451 int rc; 451 int rc;
 452 u_int secsize;
452 453
453 /* We must read amount multiple of sector size, hence we can't 454 /* We must read amount multiple of sector size, hence we can't
454 * read SBSIZE and read MINBSIZE. 455 * read SBSIZE and read MINBSIZE.
455 */ 456 */
456 if (SBSIZE > MINBSIZE) 457 if (SBSIZE > MINBSIZE)
457 return EINVAL; 458 return EINVAL;
458 459
 460 secsize = 0;
 461 rc = DEV_IOCTL(f->f_dev)(f, SAIOSECSIZE, &secsize);
 462 if (rc != 0 || secsize == 0)
 463 secsize = DEV_BSIZE;
 464
459 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, 465 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
460 SUPER_BLOCK_OFF / DEV_BSIZE, MINBSIZE, sbbuf, &buf_size); 466 SUPER_BLOCK_OFF / secsize, MINBSIZE, sbbuf, &buf_size);
461 if (rc) 467 if (rc)
462 return rc; 468 return rc;
463 469
464 if (buf_size != MINBSIZE) 470 if (buf_size != MINBSIZE)
465 return EIO; 471 return EIO;
466 472
467 mfs_sbload((void *)sbbuf, fs); 473 mfs_sbload((void *)sbbuf, fs);
468 474
469 if (fs->mfs_magic != SUPER_MAGIC) 475 if (fs->mfs_magic != SUPER_MAGIC)
470 return EINVAL; 476 return EINVAL;
471 if (fs->mfs_block_size < MINBSIZE) 477 if (fs->mfs_block_size < MINBSIZE)
472 return EINVAL; 478 return EINVAL;
473 if ((fs->mfs_block_size % 512) != 0) 479 if ((fs->mfs_block_size % 512) != 0)

cvs diff -r1.4 -r1.5 src/sys/lib/libsa/saioctl.h (expand / switch to unified diff)

--- src/sys/lib/libsa/saioctl.h 2005/12/11 12:24:46 1.4
+++ src/sys/lib/libsa/saioctl.h 2022/04/24 06:48:15 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: saioctl.h,v 1.4 2005/12/11 12:24:46 christos Exp $ */ 1/* $NetBSD: saioctl.h,v 1.5 2022/04/24 06:48:15 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1993 4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -36,13 +36,15 @@ @@ -36,13 +36,15 @@
36#define SAIOCHECK (('d'<<8)|2) /* next i/o checks data */ 36#define SAIOCHECK (('d'<<8)|2) /* next i/o checks data */
37#define SAIOHCHECK (('d'<<8)|3) /* next i/o checks header & data */ 37#define SAIOHCHECK (('d'<<8)|3) /* next i/o checks header & data */
38#define SAIONOBAD (('d'<<8)|4) /* inhibit bad sector forwarding */ 38#define SAIONOBAD (('d'<<8)|4) /* inhibit bad sector forwarding */
39#define SAIODOBAD (('d'<<8)|5) /* enable bad sector forwarding */ 39#define SAIODOBAD (('d'<<8)|5) /* enable bad sector forwarding */
40#define SAIOECCLIM (('d'<<8)|6) /* set limit to ecc correction, bits */ 40#define SAIOECCLIM (('d'<<8)|6) /* set limit to ecc correction, bits */
41#define SAIOECCUNL (('d'<<8)|7) /* use standard ecc procedures */ 41#define SAIOECCUNL (('d'<<8)|7) /* use standard ecc procedures */
42#define SAIORETRIES (('d'<<8)|8) /* set retry count for unit */ 42#define SAIORETRIES (('d'<<8)|8) /* set retry count for unit */
43#define SAIODEVDATA (('d'<<8)|9) /* get pointer to pack label */ 43#define SAIODEVDATA (('d'<<8)|9) /* get pointer to pack label */
44#define SAIOSSI (('d'<<8)|10) /* set skip sector inhibit */ 44#define SAIOSSI (('d'<<8)|10) /* set skip sector inhibit */
45#define SAIONOSSI (('d'<<8)|11) /* inhibit skip sector handling */ 45#define SAIONOSSI (('d'<<8)|11) /* inhibit skip sector handling */
46#define SAIOSSDEV (('d'<<8)|12) /* is device skip sector type? */ 46#define SAIOSSDEV (('d'<<8)|12) /* is device skip sector type? */
47#define SAIODEBUG (('d'<<8)|13) /* enable/disable debugging */ 47#define SAIODEBUG (('d'<<8)|13) /* enable/disable debugging */
48#define SAIOGBADINFO (('d'<<8)|14) /* get bad-sector table */ 48#define SAIOGBADINFO (('d'<<8)|14) /* get bad-sector table */
 49
 50#define SAIOSECSIZE (('d'<<8)|15) /* get sector size */

cvs diff -r1.81 -r1.82 src/sys/lib/libsa/ufs.c (expand / switch to unified diff)

--- src/sys/lib/libsa/ufs.c 2022/04/19 09:25:38 1.81
+++ src/sys/lib/libsa/ufs.c 2022/04/24 06:48:15 1.82
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ufs.c,v 1.81 2022/04/19 09:25:38 skrll Exp $ */ 1/* $NetBSD: ufs.c,v 1.82 2022/04/24 06:48:15 mlelstv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1993 4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * The Mach Operating System project at Carnegie-Mellon University. 8 * The Mach Operating System project at Carnegie-Mellon University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -584,48 +584,56 @@ search_directory(const char *name, int l @@ -584,48 +584,56 @@ search_directory(const char *name, int l
584 } 584 }
585 } 585 }
586 fp->f_seekp += buf_size; 586 fp->f_seekp += buf_size;
587 } 587 }
588 return ENOENT; 588 return ENOENT;
589} 589}
590 590
591static __inline__ int 591static __inline__ int
592ffs_find_superblock(struct open_file *f, FS *fs) 592ffs_find_superblock(struct open_file *f, FS *fs)
593{ 593{
594 struct file *fp = (struct file *)f->f_fsdata; 594 struct file *fp = (struct file *)f->f_fsdata;
595 int rc; 595 int rc;
596 size_t buf_size; 596 size_t buf_size;
 597 u_int secsize;
597#ifdef LIBSA_FFSv2 598#ifdef LIBSA_FFSv2
598 static daddr_t sblock_try[] = SBLOCKSEARCH; 599 static daddr_t sblock_try[] = SBLOCKSEARCH;
599 int i; 600 int i;
 601#endif
 602
 603 secsize = 0;
 604 rc = DEV_IOCTL(f->f_dev)(f, SAIOSECSIZE, &secsize);
 605 if (rc != 0 || secsize == 0)
 606 secsize = DEV_BSIZE;
600 607
 608#ifdef LIBSA_FFSv2
601 for (i = 0; sblock_try[i] != -1; i++) { 609 for (i = 0; sblock_try[i] != -1; i++) {
602 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, 610 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
603 sblock_try[i] / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size); 611 sblock_try[i] / secsize, SBLOCKSIZE, fs, &buf_size);
604 if (rc) 612 if (rc)
605 return rc; 613 return rc;
606 if (buf_size != SBLOCKSIZE) 614 if (buf_size != SBLOCKSIZE)
607 return EINVAL; 615 return EINVAL;
608 ffs_fix_magic_swapped(fp, fs); 616 ffs_fix_magic_swapped(fp, fs);
609 if (fs->fs_sblockloc != sblock_try[i]) 617 if (fs->fs_sblockloc != sblock_try[i])
610 /* an alternate superblock - try again */ 618 /* an alternate superblock - try again */
611 continue; 619 continue;
612 if (ffs_is_magic(fs)) 620 if (ffs_is_magic(fs))
613 return 0; 621 return 0;
614 } 622 }
615 return EINVAL; 623 return EINVAL;
616#else /* LIBSA_FFSv2 */ 624#else /* LIBSA_FFSv2 */
617 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, 625 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
618 SBLOCKOFFSET / DEV_BSIZE, SBLOCKSIZE, fs, &buf_size); 626 SBLOCKOFFSET / secsize, SBLOCKSIZE, fs, &buf_size);
619 if (rc) 627 if (rc)
620 return rc; 628 return rc;
621 if (buf_size != SBLOCKSIZE) 629 if (buf_size != SBLOCKSIZE)
622 return EINVAL; 630 return EINVAL;
623 ffs_fix_magic_swapped(fp, fs); 631 ffs_fix_magic_swapped(fp, fs);
624 632
625#ifdef LIBSA_LFS 633#ifdef LIBSA_LFS
626 if (fs->lfs_version != REQUIRED_LFS_VERSION) 634 if (fs->lfs_version != REQUIRED_LFS_VERSION)
627 return EINVAL; 635 return EINVAL;
628#endif 636#endif
629 if (!ffs_is_magic(fs)) 637 if (!ffs_is_magic(fs))
630 return EINVAL; 638 return EINVAL;
631 639