forked from freebsd/freebsd-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fstyp: sync HAMMER1/2 detection support with DragonFly BSD.
Submitted by: Tomohiro Kusumi PR: 243929
- Loading branch information
Showing
2 changed files
with
210 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/*- | ||
* Copyright (c) 2016 The DragonFly Project | ||
* Copyright (c) 2016-2019 The DragonFly Project | ||
* Copyright (c) 2016-2019 Tomohiro Kusumi <[email protected]> | ||
* All rights reserved. | ||
* | ||
* This software was developed by Edward Tomasz Napierala under sponsorship | ||
|
@@ -43,7 +44,7 @@ __FBSDID("$FreeBSD$"); | |
#include "fstyp.h" | ||
|
||
static hammer_volume_ondisk_t | ||
__read_ondisk(FILE *fp) | ||
read_ondisk(FILE *fp) | ||
{ | ||
hammer_volume_ondisk_t ondisk; | ||
|
||
|
@@ -55,7 +56,7 @@ __read_ondisk(FILE *fp) | |
} | ||
|
||
static int | ||
__test_ondisk(const hammer_volume_ondisk_t ondisk) | ||
test_ondisk(const hammer_volume_ondisk_t ondisk) | ||
{ | ||
static int count = 0; | ||
static hammer_uuid_t fsid, fstype; | ||
|
@@ -97,23 +98,23 @@ fstyp_hammer(FILE *fp, char *label, size_t size) | |
hammer_volume_ondisk_t ondisk; | ||
int error = 1; | ||
|
||
ondisk = __read_ondisk(fp); | ||
ondisk = read_ondisk(fp); | ||
if (ondisk->vol_no != HAMMER_ROOT_VOLNO) | ||
goto done; | ||
goto fail; | ||
if (ondisk->vol_count != 1) | ||
goto done; | ||
if (__test_ondisk(ondisk)) | ||
goto done; | ||
goto fail; | ||
if (test_ondisk(ondisk)) | ||
goto fail; | ||
|
||
strlcpy(label, ondisk->vol_label, size); | ||
error = 0; | ||
done: | ||
fail: | ||
free(ondisk); | ||
return (error); | ||
} | ||
|
||
static int | ||
__test_volume(const char *volpath) | ||
test_volume(const char *volpath) | ||
{ | ||
hammer_volume_ondisk_t ondisk; | ||
FILE *fp; | ||
|
@@ -122,65 +123,74 @@ __test_volume(const char *volpath) | |
if ((fp = fopen(volpath, "r")) == NULL) | ||
err(1, "failed to open %s", volpath); | ||
|
||
ondisk = __read_ondisk(fp); | ||
ondisk = read_ondisk(fp); | ||
fclose(fp); | ||
if (__test_ondisk(ondisk)) | ||
goto done; | ||
if (test_ondisk(ondisk)) | ||
goto fail; | ||
|
||
volno = ondisk->vol_no; | ||
done: | ||
fail: | ||
free(ondisk); | ||
return (volno); | ||
} | ||
|
||
static int | ||
__fsvtyp_hammer(const char *blkdevs, char *label, size_t size, int partial) | ||
{ | ||
hammer_volume_ondisk_t ondisk; | ||
hammer_volume_ondisk_t ondisk = NULL; | ||
FILE *fp; | ||
char *dup, *p, *volpath, x[HAMMER_MAX_VOLUMES]; | ||
int i, volno, error = 1; | ||
|
||
if (!blkdevs) | ||
goto fail; | ||
|
||
memset(x, 0, sizeof(x)); | ||
dup = strdup(blkdevs); | ||
p = dup; | ||
|
||
volpath = NULL; | ||
volno = -1; | ||
while (p) { | ||
volpath = p; | ||
if ((p = strchr(p, ':')) != NULL) | ||
*p++ = '\0'; | ||
if ((volno = __test_volume(volpath)) == -1) | ||
if ((volno = test_volume(volpath)) == -1) | ||
break; | ||
assert(volno >= 0); | ||
assert(volno < HAMMER_MAX_VOLUMES); | ||
x[volno]++; | ||
} | ||
|
||
if (!volpath) | ||
err(1, "invalid path %s", blkdevs); | ||
if ((fp = fopen(volpath, "r")) == NULL) | ||
err(1, "failed to open %s", volpath); | ||
ondisk = __read_ondisk(fp); | ||
ondisk = read_ondisk(fp); | ||
fclose(fp); | ||
|
||
free(dup); | ||
|
||
if (volno == -1) | ||
goto done; | ||
goto fail; | ||
if (partial) | ||
goto success; | ||
|
||
for (i = 0; i < HAMMER_MAX_VOLUMES; i++) | ||
if (x[i] > 1) | ||
goto done; | ||
goto fail; | ||
for (i = 0; i < HAMMER_MAX_VOLUMES; i++) | ||
if (x[i] == 0) | ||
break; | ||
if (ondisk->vol_count != i) | ||
goto done; | ||
goto fail; | ||
for (; i < HAMMER_MAX_VOLUMES; i++) | ||
if (x[i] != 0) | ||
goto done; | ||
goto fail; | ||
success: | ||
strlcpy(label, ondisk->vol_label, size); | ||
error = 0; | ||
done: | ||
fail: | ||
free(ondisk); | ||
return (error); | ||
} | ||
|
Oops, something went wrong.