Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/fstyp fstyp: Sync HAMMER1/2 with DragonFly BSD
details: https://anonhg.NetBSD.org/src/rev/2e970371b7b8
branches: trunk
changeset: 949348:2e970371b7b8
user: tkusumi <tkusumi%NetBSD.org@localhost>
date: Sun Jan 10 12:38:40 2021 +0000
description:
fstyp: Sync HAMMER1/2 with DragonFly BSD
taken-from: DragonFly BSD
diffstat:
usr.sbin/fstyp/fstyp.h | 4 +-
usr.sbin/fstyp/hammer.c | 112 ++++++++++------
usr.sbin/fstyp/hammer2.c | 276 ++++++++++++++++++++++++++++++++++++-----
usr.sbin/fstyp/hammer2_disk.h | 94 ++++++++++----
4 files changed, 376 insertions(+), 110 deletions(-)
diffs (truncated from 843 to 300 lines):
diff -r e48cf8db104e -r 2e970371b7b8 usr.sbin/fstyp/fstyp.h
--- a/usr.sbin/fstyp/fstyp.h Sun Jan 10 12:34:56 2021 +0000
+++ b/usr.sbin/fstyp/fstyp.h Sun Jan 10 12:38:40 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fstyp.h,v 1.8 2020/01/01 09:08:52 tkusumi Exp $ */
+/* $NetBSD: fstyp.h,v 1.9 2021/01/10 12:38:40 tkusumi Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -74,5 +74,7 @@
int fsvtyp_hammer(const char *, char *, size_t);
int fsvtyp_hammer_partial(const char *, char *, size_t);
+int fsvtyp_hammer2(const char *, char *, size_t);
+int fsvtyp_hammer2_partial(const char *, char *, size_t);
#endif /* !FSTYP_H */
diff -r e48cf8db104e -r 2e970371b7b8 usr.sbin/fstyp/hammer.c
--- a/usr.sbin/fstyp/hammer.c Sun Jan 10 12:34:56 2021 +0000
+++ b/usr.sbin/fstyp/hammer.c Sun Jan 10 12:38:40 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hammer.c,v 1.3 2020/01/15 15:30:46 tkusumi Exp $ */
+/* $NetBSD: hammer.c,v 1.4 2021/01/10 12:38:40 tkusumi Exp $ */
/*-
* Copyright (c) 2016-2019 The DragonFly Project
@@ -27,13 +27,13 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hammer.c,v 1.3 2020/01/15 15:30:46 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hammer.c,v 1.4 2021/01/10 12:38:40 tkusumi Exp $");
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
-#include <assert.h>
+#include <uuid.h>
#include "fstyp.h"
#include "hammer_disk.h"
@@ -41,13 +41,7 @@
static hammer_volume_ondisk_t
read_ondisk(FILE *fp)
{
- hammer_volume_ondisk_t ondisk;
-
- ondisk = read_buf(fp, 0, sizeof(*ondisk));
- if (ondisk == NULL)
- err(1, "failed to read ondisk");
-
- return (ondisk);
+ return (read_buf(fp, 0, sizeof(struct hammer_volume_ondisk)));
}
static int
@@ -61,32 +55,49 @@
ondisk->vol_signature != HAMMER_FSBUF_VOLUME_REV)
return (1);
if (ondisk->vol_rootvol != HAMMER_ROOT_VOLNO)
- return (2);
+ return (1);
if (ondisk->vol_no < 0 || ondisk->vol_no > HAMMER_MAX_VOLUMES - 1)
- return (3);
+ return (1);
if (ondisk->vol_count < 1 || ondisk->vol_count > HAMMER_MAX_VOLUMES)
- return (4);
+ return (1);
if (count == 0) {
count = ondisk->vol_count;
- assert(count != 0);
+ if (count == 0)
+ return (1);
memcpy(&fsid, &ondisk->vol_fsid, sizeof(fsid));
memcpy(&fstype, &ondisk->vol_fstype, sizeof(fstype));
strlcpy(label, ondisk->vol_label, sizeof(label));
} else {
if (ondisk->vol_count != count)
- return (5);
- if (memcmp(&ondisk->vol_fsid, &fsid, sizeof(fsid)))
- return (6);
- if (memcmp(&ondisk->vol_fstype, &fstype, sizeof(fstype)))
- return (7);
+ return (1);
+ if (!uuid_equal(&ondisk->vol_fsid, &fsid, NULL))
+ return (1);
+ if (!uuid_equal(&ondisk->vol_fstype, &fstype, NULL))
+ return (1);
if (strcmp(ondisk->vol_label, label))
- return (8);
+ return (1);
}
return (0);
}
+static const char*
+extract_device_name(const char *devpath)
+{
+ const char *p;
+
+ p = strrchr(devpath, '/');
+ if (p) {
+ p++;
+ if (*p == 0)
+ p = NULL;
+ } else {
+ p = devpath;
+ }
+ return (p);
+}
+
int
fstyp_hammer(FILE *fp, char *label, size_t size)
{
@@ -96,6 +107,8 @@
const char *p;
#endif
ondisk = read_ondisk(fp);
+ if (!ondisk)
+ goto fail;
if (ondisk->vol_no != HAMMER_ROOT_VOLNO)
goto fail;
if (ondisk->vol_count != 1)
@@ -109,15 +122,11 @@
*/
#ifdef HAS_DEVPATH
/* Add device name to help support multiple autofs -media mounts. */
- p = strrchr(devpath, '/');
- if (p) {
- p++;
- if (*p == 0)
- strlcpy(label, ondisk->vol_label, size);
- else
- snprintf(label, size, "%s_%s", ondisk->vol_label, p);
- } else
- snprintf(label, size, "%s_%s", ondisk->vol_label, devpath);
+ p = extract_device_name(devpath);
+ if (p)
+ snprintf(label, size, "%s_%s", ondisk->vol_label, p);
+ else
+ strlcpy(label, ondisk->vol_label, size);
#else
strlcpy(label, ondisk->vol_label, size);
#endif
@@ -130,20 +139,23 @@
static int
test_volume(const char *volpath)
{
- hammer_volume_ondisk_t ondisk;
+ hammer_volume_ondisk_t ondisk = NULL;
FILE *fp;
int volno = -1;
if ((fp = fopen(volpath, "r")) == NULL)
- err(1, "failed to open %s", volpath);
+ goto fail;
ondisk = read_ondisk(fp);
- fclose(fp);
+ if (!ondisk)
+ goto fail;
if (test_ondisk(ondisk))
goto fail;
volno = ondisk->vol_no;
fail:
+ if (fp)
+ fclose(fp);
free(ondisk);
return (volno);
}
@@ -152,8 +164,8 @@
__fsvtyp_hammer(const char *blkdevs, char *label, size_t size, int partial)
{
hammer_volume_ondisk_t ondisk = NULL;
- FILE *fp;
- char *dup, *p, *volpath, x[HAMMER_MAX_VOLUMES];
+ FILE *fp = NULL;
+ char *dup = NULL, *p, *volpath, *rootvolpath, x[HAMMER_MAX_VOLUMES];
int i, volno, error = 1;
if (!blkdevs)
@@ -164,6 +176,7 @@
p = dup;
volpath = NULL;
+ rootvolpath = NULL;
volno = -1;
while (p) {
volpath = p;
@@ -171,19 +184,23 @@
*p++ = '\0';
if ((volno = test_volume(volpath)) == -1)
break;
- assert(volno >= 0);
- assert(volno < HAMMER_MAX_VOLUMES);
+ if (volno < 0 || volno >= HAMMER_MAX_VOLUMES)
+ goto fail;
x[volno]++;
+ if (volno == HAMMER_ROOT_VOLNO)
+ rootvolpath = volpath;
}
- if (!volpath)
- err(1, "invalid path %s", blkdevs);
+ /* If no rootvolpath, proceed only if partial mode with volpath. */
+ if (rootvolpath)
+ volpath = rootvolpath;
+ else if (!partial || !volpath)
+ goto fail;
if ((fp = fopen(volpath, "r")) == NULL)
- err(1, "failed to open %s", volpath);
+ goto fail;
ondisk = read_ondisk(fp);
- fclose(fp);
-
- free(dup);
+ if (!ondisk)
+ goto fail;
if (volno == -1)
goto fail;
@@ -202,11 +219,18 @@
if (x[i] != 0)
goto fail;
success:
- /* XXX autofs -media mount can't handle multiple mounts */
- strlcpy(label, ondisk->vol_label, size);
+ /* Add device name to help support multiple autofs -media mounts. */
+ p = __UNCONST(extract_device_name(volpath));
+ if (p)
+ snprintf(label, size, "%s_%s", ondisk->vol_label, p);
+ else
+ strlcpy(label, ondisk->vol_label, size);
error = 0;
fail:
+ if (fp)
+ fclose(fp);
free(ondisk);
+ free(dup);
return (error);
}
diff -r e48cf8db104e -r 2e970371b7b8 usr.sbin/fstyp/hammer2.c
--- a/usr.sbin/fstyp/hammer2.c Sun Jan 10 12:34:56 2021 +0000
+++ b/usr.sbin/fstyp/hammer2.c Sun Jan 10 12:38:40 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hammer2.c,v 1.6 2020/09/23 14:39:23 tkusumi Exp $ */
+/* $NetBSD: hammer2.c,v 1.7 2021/01/10 12:38:40 tkusumi Exp $ */
/*-
* Copyright (c) 2017-2019 The DragonFly Project
@@ -27,7 +27,7 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hammer2.c,v 1.6 2020/09/23 14:39:23 tkusumi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hammer2.c,v 1.7 2021/01/10 12:38:40 tkusumi Exp $");
#include <stdio.h>
#include <stdlib.h>
@@ -35,28 +35,93 @@
#include <string.h>
#include <err.h>
#include <assert.h>
+#include <uuid.h>
#include "fstyp.h"
#include "hammer2_disk.h"
-static hammer2_volume_data_t*
-read_voldata(FILE *fp)
+static ssize_t
+get_file_size(FILE *fp)
{
- hammer2_volume_data_t *voldata;
+ ssize_t siz;
+
+ if (fseek(fp, 0, SEEK_END) == -1) {
+ warnx("hammer2: failed to seek media end");
+ return (-1);
+ }
- voldata = read_buf(fp, 0, sizeof(*voldata));
- if (voldata == NULL)
- err(1, "failed to read volume data");
+ siz = ftell(fp);
+ if (siz == -1) {
+ warnx("hammer2: failed to tell media end");
+ return (-1);
+ }
+
+ return (siz);
+}
- return (voldata);
+static hammer2_volume_data_t *
Home |
Main Index |
Thread Index |
Old Index