Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/fstyp/fstyp.c
Show First 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
#define LABEL_LEN 256 | #define LABEL_LEN 256 | ||||
typedef int (*fstyp_function)(FILE *, char *, size_t); | typedef int (*fstyp_function)(FILE *, char *, size_t); | ||||
static struct { | static struct { | ||||
const char *name; | const char *name; | ||||
fstyp_function function; | fstyp_function function; | ||||
bool unmountable; | |||||
} fstypes[] = { | } fstypes[] = { | ||||
{ "cd9660", &fstyp_cd9660 }, | { "cd9660", &fstyp_cd9660, false }, | ||||
{ "ext2fs", &fstyp_ext2fs }, | { "ext2fs", &fstyp_ext2fs, false }, | ||||
{ "msdosfs", &fstyp_msdosfs }, | { "geli", &fstyp_geli, true }, | ||||
{ "ntfs", &fstyp_ntfs }, | { "msdosfs", &fstyp_msdosfs, false }, | ||||
{ "ufs", &fstyp_ufs }, | { "ntfs", &fstyp_ntfs, false }, | ||||
{ NULL, NULL } | { "ufs", &fstyp_ufs, false }, | ||||
#ifdef HAVE_CDDL | |||||
imp: so what makes zfs mountable, and ufs not mountable?
| |||||
Not Done Inline ActionsOther way around. When a new device is attached, it will be auto-mounted, unless "unmountable" is true (for ZFS and GELI), since they can't be mounted with just 'mount -t <type> <device> <mountpoint>'. ZFS requires 'zpool import' and GELI needs a passphrase. So fstyp -u <device> can detect these types, but when run without -u (by autofs etc), zfs and geli will be detected as unknown, and skipped. allanjude: Other way around. When a new device is attached, it will be auto-mounted, unless "unmountable"… | |||||
{ "zfs", &fstyp_zfs, true }, | |||||
#endif | |||||
{ NULL, NULL, NULL } | |||||
}; | }; | ||||
void * | void * | ||||
read_buf(FILE *fp, off_t off, size_t len) | read_buf(FILE *fp, off_t off, size_t len) | ||||
{ | { | ||||
int error; | int error; | ||||
size_t nread; | size_t nread; | ||||
void *buf; | void *buf; | ||||
Show All 31 Lines | if (c == NULL) | ||||
err(1, "strdup"); | err(1, "strdup"); | ||||
return (c); | return (c); | ||||
} | } | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
fprintf(stderr, "usage: fstyp [-l][-s] special\n"); | fprintf(stderr, "usage: fstyp [-l][-s][-u] special\n"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
static void | static void | ||||
type_check(const char *path, FILE *fp) | type_check(const char *path, FILE *fp) | ||||
{ | { | ||||
int error, fd; | int error, fd; | ||||
off_t mediasize; | off_t mediasize; | ||||
Show All 12 Lines | type_check(const char *path, FILE *fp) | ||||
if (error != 0) | if (error != 0) | ||||
errx(1, "%s: not a disk", path); | errx(1, "%s: not a disk", path); | ||||
} | } | ||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
int ch, error, i, nbytes; | int ch, error, i, nbytes; | ||||
bool ignore_type = false, show_label = false; | bool ignore_type = false, show_label = false, show_unmountable = false; | ||||
Done Inline Actionsthis is technically against style(9) but I actually prefer this style. flags should be named "uflag", "iflag", etc. and initialized after declarations are finished. the way it is above is far better though eadler: this is technically against style(9) but I actually prefer this style.
flags should be named… | |||||
char label[LABEL_LEN + 1], strvised[LABEL_LEN * 4 + 1]; | char label[LABEL_LEN + 1], strvised[LABEL_LEN * 4 + 1]; | ||||
char *path; | char *path; | ||||
FILE *fp; | FILE *fp; | ||||
fstyp_function fstyp_f; | fstyp_function fstyp_f; | ||||
while ((ch = getopt(argc, argv, "ls")) != -1) { | while ((ch = getopt(argc, argv, "lsu")) != -1) { | ||||
switch (ch) { | switch (ch) { | ||||
case 'l': | case 'l': | ||||
show_label = true; | show_label = true; | ||||
break; | break; | ||||
case 's': | case 's': | ||||
ignore_type = true; | ignore_type = true; | ||||
break; | break; | ||||
case 'u': | |||||
show_unmountable = true; | |||||
break; | |||||
default: | default: | ||||
usage(); | usage(); | ||||
} | } | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
if (argc != 1) | if (argc != 1) | ||||
Show All 10 Lines | if (error != 0 && errno != ENOSYS) | ||||
err(1, "cap_enter"); | err(1, "cap_enter"); | ||||
if (ignore_type == false) | if (ignore_type == false) | ||||
type_check(path, fp); | type_check(path, fp); | ||||
memset(label, '\0', sizeof(label)); | memset(label, '\0', sizeof(label)); | ||||
for (i = 0;; i++) { | for (i = 0;; i++) { | ||||
if (show_unmountable == false && fstypes[i].unmountable == true) | |||||
continue; | |||||
fstyp_f = fstypes[i].function; | fstyp_f = fstypes[i].function; | ||||
if (fstyp_f == NULL) | if (fstyp_f == NULL) | ||||
break; | break; | ||||
error = fstyp_f(fp, label, sizeof(label)); | error = fstyp_f(fp, label, sizeof(label)); | ||||
if (error == 0) | if (error == 0) | ||||
break; | break; | ||||
} | } | ||||
Show All 23 Lines |
so what makes zfs mountable, and ufs not mountable?