Use geom attribute "PART::type" to determine partition type and choose
relevant fsck_xxx utility. MFC after: 1 week
This commit is contained in:
parent
224914b7da
commit
681a5b28a4
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=274750
@ -41,8 +41,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <sys/queue.h>
|
#include <sys/queue.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#define FSTYPENAMES
|
#include <sys/disk.h>
|
||||||
#include <sys/disklabel.h>
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -81,10 +80,21 @@ static void addentry(struct fstypelist *, const char *, const char *);
|
|||||||
static void maketypelist(char *);
|
static void maketypelist(char *);
|
||||||
static void catopt(char **, const char *);
|
static void catopt(char **, const char *);
|
||||||
static void mangle(char *, int *, const char ** volatile *, int *);
|
static void mangle(char *, int *, const char ** volatile *, int *);
|
||||||
static const char *getfslab(const char *);
|
static const char *getfstype(const char *);
|
||||||
static void usage(void) __dead2;
|
static void usage(void) __dead2;
|
||||||
static int isok(struct fstab *);
|
static int isok(struct fstab *);
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
const char *ptype;
|
||||||
|
const char *name;
|
||||||
|
} ptype_map[] = {
|
||||||
|
{ "ufs", "ffs" },
|
||||||
|
{ "ffs", "ffs" },
|
||||||
|
{ "fat", "msdosfs" },
|
||||||
|
{ "efi", "msdosfs" },
|
||||||
|
{ NULL, NULL },
|
||||||
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -203,7 +213,7 @@ main(int argc, char *argv[])
|
|||||||
if ((fs = getfsfile(spec)) == NULL &&
|
if ((fs = getfsfile(spec)) == NULL &&
|
||||||
(fs = getfsspec(spec)) == NULL) {
|
(fs = getfsspec(spec)) == NULL) {
|
||||||
if (vfstype == NULL)
|
if (vfstype == NULL)
|
||||||
vfstype = getfslab(spec);
|
vfstype = getfstype(spec);
|
||||||
if (vfstype == NULL)
|
if (vfstype == NULL)
|
||||||
errx(1, "Could not determine filesystem type");
|
errx(1, "Could not determine filesystem type");
|
||||||
type = vfstype;
|
type = vfstype;
|
||||||
@ -535,41 +545,27 @@ mangle(char *opts, int *argcp, const char ** volatile *argvp, int *maxargcp)
|
|||||||
*maxargcp = maxargc;
|
*maxargcp = maxargc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
getfslab(const char *str)
|
getfstype(const char *str)
|
||||||
{
|
{
|
||||||
struct disklabel dl;
|
struct diocgattr_arg attr;
|
||||||
int fd;
|
int fd, i;
|
||||||
char p;
|
|
||||||
const char *vfstype;
|
|
||||||
u_char t;
|
|
||||||
|
|
||||||
/* deduce the file system type from the disk label */
|
|
||||||
if ((fd = open(str, O_RDONLY)) == -1)
|
if ((fd = open(str, O_RDONLY)) == -1)
|
||||||
err(1, "cannot open `%s'", str);
|
err(1, "cannot open `%s'", str);
|
||||||
|
|
||||||
if (ioctl(fd, DIOCGDINFO, &dl) == -1) {
|
strncpy(attr.name, "PART::type", sizeof(attr.name));
|
||||||
|
memset(&attr.value, 0, sizeof(attr.value));
|
||||||
|
attr.len = sizeof(attr.value);
|
||||||
|
if (ioctl(fd, DIOCGATTR, &attr) == -1) {
|
||||||
(void) close(fd);
|
(void) close(fd);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
(void) close(fd);
|
(void) close(fd);
|
||||||
|
for (i = 0; ptype_map[i].ptype != NULL; i++)
|
||||||
p = str[strlen(str) - 1];
|
if (strstr(attr.value.str, ptype_map[i].ptype) != NULL)
|
||||||
|
return (ptype_map[i].name);
|
||||||
if ((p - 'a') >= dl.d_npartitions)
|
return (NULL);
|
||||||
errx(1, "partition `%s' is not defined on disk", str);
|
|
||||||
|
|
||||||
if ((t = dl.d_partitions[p - 'a'].p_fstype) >= FSMAXTYPES)
|
|
||||||
errx(1, "partition `%s' is not of a legal vfstype",
|
|
||||||
str);
|
|
||||||
|
|
||||||
if ((vfstype = fstypenames[t]) == NULL)
|
|
||||||
errx(1, "vfstype `%s' on partition `%s' is not supported",
|
|
||||||
fstypenames[t], str);
|
|
||||||
|
|
||||||
return vfstype;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user