Add d_sblockloc to libufs(3) disk structure to allow options to be added.

By making the disk block parameter used by the libufs(3) sbread(3)
function visible, applications using sbread(3) can set their own
addition options such as using the STDSB_NOHASHFAIL request to
say that they want the superblock read to succeed even when
the superblock checkhash is incorrect.

While here also add an error message when a check-hash failure
is detected.
This commit is contained in:
Kirk McKusick 2022-07-24 18:10:39 -07:00
parent bf24d17fda
commit 82e72f1d12
3 changed files with 21 additions and 3 deletions

View file

@ -65,6 +65,7 @@ struct uufsd {
int d_ccg; /* current cylinder group */
int d_lcg; /* last cylinder group (in d_cg) */
const char *d_error; /* human readable disk error */
off_t d_sblockloc; /* where to look for the superblock */
int d_mine; /* internal flags */
#define d_fs d_sbunion.d_fs
#define d_sb d_sbunion.d_sb

View file

@ -49,21 +49,37 @@ __FBSDID("$FreeBSD$");
#include <libufs.h>
static int handle_disk_read(struct uufsd *, struct fs *, int);
/*
* Read the standard superblock.
*/
int
sbread(struct uufsd *disk)
{
struct fs *fs;
int error;
error = sbget(disk->d_fd, &fs, disk->d_sblockloc);
return (handle_disk_read(disk, fs, error));
}
static int
handle_disk_read(struct uufsd *disk, struct fs *fs, int error)
{
ERROR(disk, NULL);
if ((errno = sbget(disk->d_fd, &fs, STDSB)) != 0) {
switch (errno) {
if (error != 0) {
switch (error) {
case EIO:
ERROR(disk, "non-existent or truncated superblock");
break;
case ENOENT:
ERROR(disk, "no usable known superblock found");
break;
case EINTEGRITY:
ERROR(disk, "superblock check-hash failure");
break;
case ENOSPC:
ERROR(disk, "failed to allocate space for superblock "
"information");

View file

@ -168,6 +168,7 @@ again: if ((ret = stat(name, &st)) < 0) {
disk->d_ufs = 0;
disk->d_error = NULL;
disk->d_si = NULL;
disk->d_sblockloc = STDSB;
if (oname != name) {
name = strdup(name);