From nobody Mon Jul 25 01:12:57 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4LrhqY513Mz4Wtyv; Mon, 25 Jul 2022 01:12:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LrhqY4SXcz3MBr; Mon, 25 Jul 2022 01:12:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658711577; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VEXUWgaL/xs6A/e10Isa0+3MBFRwvU3WVDurYxBTLMk=; b=NBrnnwNpQIliY/ndjS/lPXnTfKQ1x09aW9KZAS7nOfQJsdeNSEnfwgk7PDoh8PL1/Hws0S WAjZkQPA1CHWDyKj/zZTQS45xV/doiqrDobNOep49kPwHyrNzh4DHbFZxKRA5wUg+ZQ7sG eMwWRp8xW2nBvfwXFsd2HSehcKdi/Ec5Hdv3p/0h0DAhpiBMZ7443f2Kt4yyBRkoUCyc07 1Pn7vQ+t1eAoCY67lUYJ7AwOuS2Em0V2Rjw0HJLSfo0ViZus0VdtK8D2gdQWcWyZd1ccx8 XZeaoEMbz/ZTk+6FVx18Ou6IGhktw2f2diO7VqCTUNhU4U5iWRzo7k3Ps92UMA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4LrhqY3WvpzfVd; Mon, 25 Jul 2022 01:12:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 26P1CvFt093635; Mon, 25 Jul 2022 01:12:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26P1Cvrv093634; Mon, 25 Jul 2022 01:12:57 GMT (envelope-from git) Date: Mon, 25 Jul 2022 01:12:57 GMT Message-Id: <202207250112.26P1Cvrv093634@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kirk McKusick Subject: git: 82e72f1d12fa - main - Add d_sblockloc to libufs(3) disk structure to allow options to be added. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mckusick X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 82e72f1d12fa8a3baaefe46509d9aa33406cbf4d Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1658711577; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=VEXUWgaL/xs6A/e10Isa0+3MBFRwvU3WVDurYxBTLMk=; b=TRyEb9+nnI9yNtr9P6W1mg876CeMzcj0JffZVaCKe3vV/m8yCm/8VNCZTwxTkgaIpVG9/j D836TuZAhGytPEQdFi3N9dphMVMG3yjUnYG9OK4dtR+Ltf0/E3IbOm/t26KR1dtc/cz3vy R5apwXF2PmHy+xYlFZ9dMjko53UkfMADCS97z4bkh4Yksmv/rp1nqmnxJGCV2hX4SHrCoz KFHJKM5kI5XKHJ7zJ2tD1b+ZYIkBkZ9/jxbAhRVWiCyNLFIHtYgrbEUm0H2IgzFzlZnQcI i2f3l1131nBlulPJzbdKpdCP19uSiZIqyw3eViArbeKUlcxrnJ/DX92UxPfD/A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1658711577; a=rsa-sha256; cv=none; b=UKlS2V9qnTRo7kkNHqB3vQ7aNXKDs+vJJGUi3kTUm0DfNLsDd8+NunTkXwLDgUM6jt4RZ+ uMHDy+wjfIVHn2ubyuP+D+PvOc4ZwOfY5OGkTpsBvQgPDEWNXcgBHn++IYpbyZHsnlLIg9 s1s1zYlXXKtWuFUIvIlIqHDRNyO7xrFm9FiakmbHYHzIj4TzKqO6AxrO6FlO9IT2T8OP+1 oIAn+0LoGkQ2p6lyq3ZXHrtxcExREkb8FgnhOKvhparw0Cr5zWQgisel5YnUNXlJUY9IwC gEPnb52uoa42It9KHOpCp+VTGht7lcd5N8zWl0/Gyd1QzmjgabZLrQvXKf+6Ug== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mckusick: URL: https://cgit.FreeBSD.org/src/commit/?id=82e72f1d12fa8a3baaefe46509d9aa33406cbf4d commit 82e72f1d12fa8a3baaefe46509d9aa33406cbf4d Author: Kirk McKusick AuthorDate: 2022-07-25 01:10:39 +0000 Commit: Kirk McKusick CommitDate: 2022-07-25 01:12:25 +0000 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. --- lib/libufs/libufs.h | 1 + lib/libufs/sblock.c | 22 +++++++++++++++++++--- lib/libufs/type.c | 1 + 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/libufs/libufs.h b/lib/libufs/libufs.h index 63a8dc170997..5045117b5d7d 100644 --- a/lib/libufs/libufs.h +++ b/lib/libufs/libufs.h @@ -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 diff --git a/lib/libufs/sblock.c b/lib/libufs/sblock.c index 3b65e79b02b5..9ba012400f1d 100644 --- a/lib/libufs/sblock.c +++ b/lib/libufs/sblock.c @@ -49,21 +49,37 @@ __FBSDID("$FreeBSD$"); #include +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(disk, NULL); + error = sbget(disk->d_fd, &fs, disk->d_sblockloc); + return (handle_disk_read(disk, fs, error)); +} - if ((errno = sbget(disk->d_fd, &fs, STDSB)) != 0) { - switch (errno) { +static int +handle_disk_read(struct uufsd *disk, struct fs *fs, int error) +{ + + ERROR(disk, NULL); + 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"); diff --git a/lib/libufs/type.c b/lib/libufs/type.c index a060f8ec5abf..ac5b8d17e84c 100644 --- a/lib/libufs/type.c +++ b/lib/libufs/type.c @@ -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);