[Midnightbsd-cvs] src [10752] trunk/usr.sbin/fstyp: sync with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Jun 9 18:26:45 EDT 2018
Revision: 10752
http://svnweb.midnightbsd.org/src/?rev=10752
Author: laffer1
Date: 2018-06-09 18:26:44 -0400 (Sat, 09 Jun 2018)
Log Message:
-----------
sync with freebsd
Added Paths:
-----------
trunk/usr.sbin/fstyp/
trunk/usr.sbin/fstyp/Makefile
trunk/usr.sbin/fstyp/cd9660.c
trunk/usr.sbin/fstyp/ext2fs.c
trunk/usr.sbin/fstyp/fstyp.8
trunk/usr.sbin/fstyp/fstyp.c
trunk/usr.sbin/fstyp/fstyp.h
trunk/usr.sbin/fstyp/geli.c
trunk/usr.sbin/fstyp/msdosfs.c
trunk/usr.sbin/fstyp/msdosfs.h
trunk/usr.sbin/fstyp/ntfs.c
trunk/usr.sbin/fstyp/tests/
trunk/usr.sbin/fstyp/tests/Makefile
trunk/usr.sbin/fstyp/tests/ext2.img.bz2
trunk/usr.sbin/fstyp/tests/ext3.img.bz2
trunk/usr.sbin/fstyp/tests/ext4.img.bz2
trunk/usr.sbin/fstyp/tests/ext4_with_label.img.bz2
trunk/usr.sbin/fstyp/tests/fstyp_test.sh
trunk/usr.sbin/fstyp/tests/ntfs.img.bz2
trunk/usr.sbin/fstyp/tests/ntfs_with_label.img.bz2
trunk/usr.sbin/fstyp/ufs.c
trunk/usr.sbin/fstyp/zfs.c
Added: trunk/usr.sbin/fstyp/Makefile
===================================================================
--- trunk/usr.sbin/fstyp/Makefile (rev 0)
+++ trunk/usr.sbin/fstyp/Makefile 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,46 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/fstyp/Makefile 293776 2016-01-12 16:38:09Z allanjude $
+
+.include <bsd.own.mk>
+
+PROG= fstyp
+SRCS= cd9660.c ext2fs.c fstyp.c geli.c msdosfs.c ntfs.c ufs.c
+
+.if ${MK_ZFS} != "no"
+SRCS += zfs.c
+.endif
+
+MAN= fstyp.8
+
+WARNS?= 2
+
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
+CFLAGS+=-I${.CURDIR}/../../sys
+
+.if ${MK_ZFS} != "no"
+IGNORE_PRAGMA= YES
+
+CFLAGS+= -DNEED_SOLARIS_BOOLEAN -DHAVE_ZFS
+CFLAGS+= -I${.CURDIR}/../../sys/cddl/compat/opensolaris
+CFLAGS+= -I${.CURDIR}/../../cddl/compat/opensolaris/include
+CFLAGS+= -I${.CURDIR}/../../cddl/compat/opensolaris/lib/libumem
+CFLAGS+= -I${.CURDIR}/../../cddl/contrib/opensolaris/lib/libnvpair
+CFLAGS+= -I${.CURDIR}/../../cddl/contrib/opensolaris/lib/libzpool/common
+CFLAGS+= -I${.CURDIR}/../../sys/cddl/contrib/opensolaris/uts/common/fs/zfs
+CFLAGS+= -I${.CURDIR}/../../sys/cddl/contrib/opensolaris/uts/common
+CFLAGS+= -I${.CURDIR}/../../sys/cddl/contrib/opensolaris/uts/common/sys
+CFLAGS+= -I${.CURDIR}/../../cddl/contrib/opensolaris/head
+.endif
+
+DPADD= ${LIBGEOM} ${LIBMD}
+LDADD= -lgeom -lmd
+
+.if ${MK_ZFS} != "no"
+DPADD += ${LIBNVPAIR} ${LIBZFS}
+LDADD += -lnvpair -lzfs
+.endif
+
+.include <bsd.prog.mk>
Property changes on: trunk/usr.sbin/fstyp/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/cd9660.c
===================================================================
--- trunk/usr.sbin/fstyp/cd9660.c (rev 0)
+++ trunk/usr.sbin/fstyp/cd9660.c 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,63 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2004 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.sbin/fstyp/cd9660.c 286193 2015-08-02 10:08:57Z trasz $");
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "fstyp.h"
+
+#define ISO9660_MAGIC "\x01" "CD001" "\x01\x00"
+#define ISO9660_OFFSET 0x8000
+#define VOLUME_LEN 32
+
+int
+fstyp_cd9660(FILE *fp, char *label, size_t size)
+{
+ char *sector, *volume;
+
+ sector = read_buf(fp, ISO9660_OFFSET, 512);
+ if (sector == NULL)
+ return (1);
+ if (bcmp(sector, ISO9660_MAGIC, sizeof(ISO9660_MAGIC) - 1) != 0) {
+ free(sector);
+ return (1);
+ }
+ volume = sector + 0x28;
+ bzero(label, size);
+ strlcpy(label, volume, MIN(size, VOLUME_LEN));
+ free(sector);
+ rtrim(label, size);
+ return (0);
+}
Property changes on: trunk/usr.sbin/fstyp/cd9660.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/ext2fs.c
===================================================================
--- trunk/usr.sbin/fstyp/ext2fs.c (rev 0)
+++ trunk/usr.sbin/fstyp/ext2fs.c 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,86 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005 Stanislav Sedov
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.sbin/fstyp/ext2fs.c 277437 2015-01-20 20:44:16Z trasz $");
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "fstyp.h"
+
+#define EXT2FS_SB_OFFSET 1024
+#define EXT2_SUPER_MAGIC 0xef53
+#define EXT2_DYNAMIC_REV 1
+
+typedef struct e2sb {
+ uint8_t fake1[56];
+ uint16_t s_magic;
+ uint8_t fake2[18];
+ uint32_t s_rev_level;
+ uint8_t fake3[40];
+ char s_volume_name[16];
+} e2sb_t;
+
+int
+fstyp_ext2fs(FILE *fp, char *label, size_t size)
+{
+ e2sb_t *fs;
+ char *s_volume_name;
+
+ fs = (e2sb_t *)read_buf(fp, EXT2FS_SB_OFFSET, 512);
+ if (fs == NULL)
+ return (1);
+
+ /* Check for magic and versio n*/
+ if (fs->s_magic == EXT2_SUPER_MAGIC &&
+ fs->s_rev_level == EXT2_DYNAMIC_REV) {
+ //G_LABEL_DEBUG(1, "ext2fs file system detected on %s.",
+ // pp->name);
+ } else {
+ free(fs);
+ return (1);
+ }
+
+ s_volume_name = fs->s_volume_name;
+ /* Terminate label */
+ s_volume_name[sizeof(fs->s_volume_name) - 1] = '\0';
+
+ if (s_volume_name[0] == '/')
+ s_volume_name += 1;
+
+ strlcpy(label, s_volume_name, size);
+ free(fs);
+
+ return (0);
+}
Property changes on: trunk/usr.sbin/fstyp/ext2fs.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/fstyp.8
===================================================================
--- trunk/usr.sbin/fstyp/fstyp.8 (rev 0)
+++ trunk/usr.sbin/fstyp/fstyp.8 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,128 @@
+.\" $MidnightBSD$
+.\" Copyright (c) 2014 The FreeBSD Foundation
+.\" All rights reserved.
+.\"
+.\" This software was developed by Edward Tomasz Napierala under sponsorship
+.\" from the FreeBSD Foundation.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.\" $FreeBSD: stable/10/usr.sbin/fstyp/fstyp.8 293776 2016-01-12 16:38:09Z allanjude $
+.\"
+.Dd July 11, 2015
+.Dt FSTYP 8
+.Os
+.Sh NAME
+.Nm fstyp
+.Nd determine filesystem type
+.Sh SYNOPSIS
+.Nm
+.Op Fl l
+.Op Fl s
+.Op Fl u
+.Ar special
+.Sh DESCRIPTION
+The
+.Nm
+utility is used to determine the filesystem type on a given device.
+It can recognize ISO-9660, Ext2, FAT, NTFS, and UFS filesystems.
+When the
+.Fl u
+flag is specified,
+.Nm
+also recognizes certain additional metadata formats that cannot be
+handled using
+.Xr mount 8 ,
+such as ZFS pools and
+.Xr geli 8
+providers.
+.Pp
+The filesystem name is printed to the standard output
+as, respectively:
+.Bl -item -offset indent -compact
+.It
+cd9660
+.It
+ext2fs
+.It
+geli
+.It
+msdosfs
+.It
+ntfs
+.It
+ufs
+.It
+zfs
+.El
+.Pp
+Because
+.Nm
+is built specifically to detect filesystem types, it differs from
+.Xr file 1
+in several ways.
+The output is machine-parsable, filesystem labels are supported,
+the utility runs sandboxed using
+.Xr capsicum 4 ,
+and does not try to recognize any file format other than filesystems.
+.Pp
+These options are available:
+.Bl -tag -width ".Fl l"
+.It Fl l
+In addition to filesystem type, print filesystem label if available.
+.It Fl s
+Ignore file type.
+By default,
+.Nm
+only works on regular files and disk-like device nodes.
+Trying to read other file types might have unexpected consequences or hang
+indefinitely.
+.It Fl u
+Include filesystems and devices that cannot be mounted directly by
+.Xr mount 8 .
+.El
+.Sh EXIT STATUS
+The
+.Nm
+utility exits 0 on success, and >0 if an error occurs or the filesystem
+type is not recognized.
+.Sh SEE ALSO
+.Xr file 1 ,
+.Xr capsicum 4 ,
+.Xr autofs 8 ,
+.Xr geli 8 ,
+.Xr glabel 8 ,
+.Xr mount 8 ,
+.Xr zpool 8
+.Sh HISTORY
+The
+.Nm
+command appeared in
+.Fx 10.2 .
+.Sh AUTHORS
+The
+.Nm
+utility was developed by
+.An Edward Tomasz Napierala Aq Mt trasz at FreeBSD.org
+under sponsorship from the FreeBSD Foundation.
+ZFS and GELI support was added by
+.An Allan Jude Aq Mt allanjude at FreeBSD.org
Property changes on: trunk/usr.sbin/fstyp/fstyp.8
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/fstyp.c
===================================================================
--- trunk/usr.sbin/fstyp/fstyp.c (rev 0)
+++ trunk/usr.sbin/fstyp/fstyp.c 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,236 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.sbin/fstyp/fstyp.c 293776 2016-01-12 16:38:09Z allanjude $");
+
+#include <sys/capability.h>
+#include <sys/disk.h>
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <err.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <vis.h>
+
+#include "fstyp.h"
+
+#define LABEL_LEN 256
+
+typedef int (*fstyp_function)(FILE *, char *, size_t);
+
+static struct {
+ const char *name;
+ fstyp_function function;
+ bool unmountable;
+} fstypes[] = {
+ { "cd9660", &fstyp_cd9660, false },
+ { "ext2fs", &fstyp_ext2fs, false },
+ { "geli", &fstyp_geli, true },
+ { "msdosfs", &fstyp_msdosfs, false },
+ { "ntfs", &fstyp_ntfs, false },
+ { "ufs", &fstyp_ufs, false },
+#ifdef HAVE_ZFS
+ { "zfs", &fstyp_zfs, true },
+#endif
+ { NULL, NULL, NULL }
+};
+
+void *
+read_buf(FILE *fp, off_t off, size_t len)
+{
+ int error;
+ size_t nread;
+ void *buf;
+
+ error = fseek(fp, off, SEEK_SET);
+ if (error != 0) {
+ warn("cannot seek to %jd", (uintmax_t)off);
+ return (NULL);
+ }
+
+ buf = malloc(len);
+ if (buf == 0) {
+ warn("cannot malloc %zd bytes of memory", len);
+ return (NULL);
+ }
+
+ nread = fread(buf, len, 1, fp);
+ if (nread != 1) {
+ free(buf);
+ if (feof(fp) == 0)
+ warn("fread");
+ return (NULL);
+ }
+
+ return (buf);
+}
+
+char *
+checked_strdup(const char *s)
+{
+ char *c;
+
+ c = strdup(s);
+ if (c == NULL)
+ err(1, "strdup");
+ return (c);
+}
+
+void
+rtrim(char *label, size_t size)
+{
+ ptrdiff_t i;
+
+ for (i = size - 1; i >= 0; i--) {
+ if (label[i] == '\0')
+ continue;
+ else if (label[i] == ' ')
+ label[i] = '\0';
+ else
+ break;
+ }
+}
+
+static void
+usage(void)
+{
+
+ fprintf(stderr, "usage: fstyp [-l] [-s] [-u] special\n");
+ exit(1);
+}
+
+static void
+type_check(const char *path, FILE *fp)
+{
+ int error, fd;
+ off_t mediasize;
+ struct stat sb;
+
+ fd = fileno(fp);
+
+ error = fstat(fd, &sb);
+ if (error != 0)
+ err(1, "%s: fstat", path);
+
+ if (S_ISREG(sb.st_mode))
+ return;
+
+ error = ioctl(fd, DIOCGMEDIASIZE, &mediasize);
+ if (error != 0)
+ errx(1, "%s: not a disk", path);
+}
+
+int
+main(int argc, char **argv)
+{
+ int ch, error, i, nbytes;
+ bool ignore_type = false, show_label = false, show_unmountable = false;
+ char label[LABEL_LEN + 1], strvised[LABEL_LEN * 4 + 1];
+ char *path;
+ FILE *fp;
+ fstyp_function fstyp_f;
+
+ while ((ch = getopt(argc, argv, "lsu")) != -1) {
+ switch (ch) {
+ case 'l':
+ show_label = true;
+ break;
+ case 's':
+ ignore_type = true;
+ break;
+ case 'u':
+ show_unmountable = true;
+ break;
+ default:
+ usage();
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+ if (argc != 1)
+ usage();
+
+ path = argv[0];
+
+ fp = fopen(path, "r");
+ if (fp == NULL)
+ err(1, "%s", path);
+
+ error = cap_enter();
+ if (error != 0 && errno != ENOSYS)
+ err(1, "cap_enter");
+
+ if (ignore_type == false)
+ type_check(path, fp);
+
+ memset(label, '\0', sizeof(label));
+
+ for (i = 0;; i++) {
+ if (show_unmountable == false && fstypes[i].unmountable == true)
+ continue;
+ fstyp_f = fstypes[i].function;
+ if (fstyp_f == NULL)
+ break;
+
+ error = fstyp_f(fp, label, sizeof(label));
+ if (error == 0)
+ break;
+ }
+
+ if (fstypes[i].name == NULL) {
+ warnx("%s: filesystem not recognized", path);
+ return (1);
+ }
+
+ if (show_label && label[0] != '\0') {
+ /*
+ * XXX: I'd prefer VIS_HTTPSTYLE, but it unconditionally
+ * encodes spaces.
+ */
+ nbytes = strsnvis(strvised, sizeof(strvised), label,
+ VIS_GLOB | VIS_NL, "\"'$");
+ if (nbytes == -1)
+ err(1, "strsnvis");
+
+ printf("%s %s\n", fstypes[i].name, strvised);
+ } else {
+ printf("%s\n", fstypes[i].name);
+ }
+
+ return (0);
+}
Property changes on: trunk/usr.sbin/fstyp/fstyp.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/fstyp.h
===================================================================
--- trunk/usr.sbin/fstyp/fstyp.h (rev 0)
+++ trunk/usr.sbin/fstyp/fstyp.h 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,52 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/usr.sbin/fstyp/fstyp.h 293776 2016-01-12 16:38:09Z allanjude $
+ */
+
+#ifndef FSTYP_H
+#define FSTYP_H
+
+#define MIN(a,b) (((a)<(b))?(a):(b))
+
+void *read_buf(FILE *fp, off_t off, size_t len);
+char *checked_strdup(const char *s);
+void rtrim(char *label, size_t size);
+
+int fstyp_cd9660(FILE *fp, char *label, size_t size);
+int fstyp_ext2fs(FILE *fp, char *label, size_t size);
+int fstyp_geli(FILE *fp, char *label, size_t size);
+int fstyp_msdosfs(FILE *fp, char *label, size_t size);
+int fstyp_ntfs(FILE *fp, char *label, size_t size);
+int fstyp_ufs(FILE *fp, char *label, size_t size);
+#ifdef HAVE_ZFS
+int fstyp_zfs(FILE *fp, char *label, size_t size);
+#endif
+
+#endif /* !FSTYP_H */
Property changes on: trunk/usr.sbin/fstyp/fstyp.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/geli.c
===================================================================
--- trunk/usr.sbin/fstyp/geli.c (rev 0)
+++ trunk/usr.sbin/fstyp/geli.c 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,72 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2015 Allan Jude <allanjude at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.sbin/fstyp/geli.c 293776 2016-01-12 16:38:09Z allanjude $");
+
+#include <sys/disk.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <geom/eli/g_eli.h>
+
+#include "fstyp.h"
+
+int
+fstyp_geli(FILE *fp, char *label __unused, size_t labelsize __unused)
+{
+ int error;
+ off_t mediasize;
+ u_int sectorsize;
+ struct g_eli_metadata md;
+ u_char *buf;
+
+ error = ioctl(fileno(fp), DIOCGMEDIASIZE, &mediasize);
+ if (error != 0)
+ return (1);
+ error = ioctl(fileno(fp), DIOCGSECTORSIZE, §orsize);
+ if (error != 0)
+ return (1);
+ buf = (u_char *)read_buf(fp, mediasize - sectorsize, sectorsize);
+ if (buf == NULL)
+ goto gelierr;
+ error = eli_metadata_decode(buf, &md);
+ if (error)
+ goto gelierr;
+
+ if (strcmp(md.md_magic, G_ELI_MAGIC) == 0) {
+ free(buf);
+ return (0);
+ }
+
+gelierr:
+ free(buf);
+
+ return (1);
+}
Property changes on: trunk/usr.sbin/fstyp/geli.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/msdosfs.c
===================================================================
--- trunk/usr.sbin/fstyp/msdosfs.c (rev 0)
+++ trunk/usr.sbin/fstyp/msdosfs.c 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,176 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2004 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * Copyright (c) 2006 Tobias Reifenberger
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.sbin/fstyp/msdosfs.c 286193 2015-08-02 10:08:57Z trasz $");
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "fstyp.h"
+#include "msdosfs.h"
+
+#define LABEL_NO_NAME "NO NAME "
+
+int
+fstyp_msdosfs(FILE *fp, char *label, size_t size)
+{
+ FAT_BSBPB *pfat_bsbpb;
+ FAT32_BSBPB *pfat32_bsbpb;
+ FAT_DES *pfat_entry;
+ uint8_t *sector0, *sector;
+
+ sector0 = NULL;
+ sector = NULL;
+
+ /* Load 1st sector with boot sector and boot parameter block. */
+ sector0 = (uint8_t *)read_buf(fp, 0, 512);
+ if (sector0 == NULL)
+ return (1);
+
+ /* Check for the FAT boot sector signature. */
+ if (sector0[510] != 0x55 || sector0[511] != 0xaa) {
+ goto error;
+ }
+
+ /*
+ * Test if this is really a FAT volume and determine the FAT type.
+ */
+
+ pfat_bsbpb = (FAT_BSBPB *)sector0;
+ pfat32_bsbpb = (FAT32_BSBPB *)sector0;
+
+ if (UINT16BYTES(pfat_bsbpb->BPB_FATSz16) != 0) {
+ /*
+ * If the BPB_FATSz16 field is not zero and the string "FAT" is
+ * at the right place, this should be a FAT12 or FAT16 volume.
+ */
+ if (strncmp(pfat_bsbpb->BS_FilSysType, "FAT", 3) != 0) {
+ goto error;
+ }
+
+ /* A volume with no name should have "NO NAME " as label. */
+ if (strncmp(pfat_bsbpb->BS_VolLab, LABEL_NO_NAME,
+ sizeof(pfat_bsbpb->BS_VolLab)) == 0) {
+ goto endofchecks;
+ }
+ strlcpy(label, pfat_bsbpb->BS_VolLab,
+ MIN(size, sizeof(pfat_bsbpb->BS_VolLab) + 1));
+ } else if (UINT32BYTES(pfat32_bsbpb->BPB_FATSz32) != 0) {
+ uint32_t fat_FirstDataSector, fat_BytesPerSector, offset;
+
+ /*
+ * If the BPB_FATSz32 field is not zero and the string "FAT" is
+ * at the right place, this should be a FAT32 volume.
+ */
+ if (strncmp(pfat32_bsbpb->BS_FilSysType, "FAT", 3) != 0) {
+ goto error;
+ }
+
+ /*
+ * If the volume label is not "NO NAME " we're done.
+ */
+ if (strncmp(pfat32_bsbpb->BS_VolLab, LABEL_NO_NAME,
+ sizeof(pfat32_bsbpb->BS_VolLab)) != 0) {
+ strlcpy(label, pfat32_bsbpb->BS_VolLab,
+ MIN(size, sizeof(pfat32_bsbpb->BS_VolLab) + 1));
+ goto endofchecks;
+ }
+
+ /*
+ * If the volume label "NO NAME " is in the boot sector, the
+ * label of FAT32 volumes may be stored as a special entry in
+ * the root directory.
+ */
+ fat_FirstDataSector =
+ UINT16BYTES(pfat32_bsbpb->BPB_RsvdSecCnt) +
+ (pfat32_bsbpb->BPB_NumFATs *
+ UINT32BYTES(pfat32_bsbpb->BPB_FATSz32));
+ fat_BytesPerSector = UINT16BYTES(pfat32_bsbpb->BPB_BytsPerSec);
+
+ // fat_FirstDataSector, fat_BytesPerSector);
+
+ for (offset = fat_BytesPerSector * fat_FirstDataSector;;
+ offset += fat_BytesPerSector) {
+ sector = (uint8_t *)read_buf(fp, offset, fat_BytesPerSector);
+ if (sector == NULL)
+ goto error;
+
+ pfat_entry = (FAT_DES *)sector;
+ do {
+ /* No more entries available. */
+ if (pfat_entry->DIR_Name[0] == 0) {
+ goto endofchecks;
+ }
+
+ /* Skip empty or long name entries. */
+ if (pfat_entry->DIR_Name[0] == 0xe5 ||
+ (pfat_entry->DIR_Attr &
+ FAT_DES_ATTR_LONG_NAME) ==
+ FAT_DES_ATTR_LONG_NAME) {
+ continue;
+ }
+
+ /*
+ * The name of the entry is the volume label if
+ * ATTR_VOLUME_ID is set.
+ */
+ if (pfat_entry->DIR_Attr &
+ FAT_DES_ATTR_VOLUME_ID) {
+ strlcpy(label, pfat_entry->DIR_Name,
+ MIN(size,
+ sizeof(pfat_entry->DIR_Name) + 1));
+ goto endofchecks;
+ }
+ } while((uint8_t *)(++pfat_entry) <
+ (uint8_t *)(sector + fat_BytesPerSector));
+ free(sector);
+ }
+ } else {
+ goto error;
+ }
+
+endofchecks:
+ rtrim(label, size);
+
+ free(sector0);
+ free(sector);
+
+ return (0);
+
+error:
+ free(sector0);
+ free(sector);
+
+ return (1);
+}
Property changes on: trunk/usr.sbin/fstyp/msdosfs.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/msdosfs.h
===================================================================
--- trunk/usr.sbin/fstyp/msdosfs.h (rev 0)
+++ trunk/usr.sbin/fstyp/msdosfs.h 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,141 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2006 Tobias Reifenberger
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/usr.sbin/fstyp/msdosfs.h 275680 2014-12-10 14:14:16Z trasz $
+ */
+
+#include <sys/types.h>
+
+/*
+ * Conversion macros for little endian encoded unsigned integers
+ * in byte streams to the local unsigned integer format.
+ */
+#define UINT16BYTES(p) ((uint32_t)((p)[0] + (256*(p)[1])))
+#define UINT32BYTES(p) ((uint32_t)((p)[0] + (256*(p)[1]) + \
+ (65536*(p)[2]) + (16777216*(p)[3])))
+
+/*
+ * All following structures are according to:
+ *
+ * Microsoft Extensible Firmware Initiative FAT32 File System Specification
+ * FAT: General Overview of On-Disk Format
+ * Version 1.03, December 6, 2000
+ * Microsoft Corporation
+ */
+
+/*
+ * FAT boot sector and boot parameter block for
+ * FAT12 and FAT16 volumes
+ */
+typedef struct fat_bsbpb {
+ /* common fields */
+ uint8_t BS_jmpBoot[3];
+ uint8_t BS_OEMName[8];
+ uint8_t BPB_BytsPerSec[2];
+ uint8_t BPB_SecPerClus;
+ uint8_t BPB_RsvdSecCnt[2];
+ uint8_t BPB_NumFATs;
+ uint8_t BPB_RootEntCnt[2];
+ uint8_t BPB_TotSec16[2];
+ uint8_t BPB_Media;
+ uint8_t BPB_FATSz16[2];
+ uint8_t BPB_SecPerTrack[2];
+ uint8_t BPB_NumHeads[2];
+ uint8_t BPB_HiddSec[4];
+ uint8_t BPB_TotSec32[4];
+ /* FAT12/FAT16 only fields */
+ uint8_t BS_DrvNum;
+ uint8_t BS_Reserved1;
+ uint8_t BS_BootSig;
+ uint8_t BS_VolID[4];
+ uint8_t BS_VolLab[11];
+ uint8_t BS_FilSysType[8];
+} FAT_BSBPB; /* 62 bytes */
+
+/*
+ * FAT boot sector and boot parameter block for
+ * FAT32 volumes
+ */
+typedef struct fat32_bsbpb {
+ /* common fields */
+ uint8_t BS_jmpBoot[3];
+ uint8_t BS_OEMName[8];
+ uint8_t BPB_BytsPerSec[2];
+ uint8_t BPB_SecPerClus;
+ uint8_t BPB_RsvdSecCnt[2];
+ uint8_t BPB_NumFATs;
+ uint8_t BPB_RootEntCnt[2];
+ uint8_t BPB_TotSec16[2];
+ uint8_t BPB_Media;
+ uint8_t BPB_FATSz16[2];
+ uint8_t BPB_SecPerTrack[2];
+ uint8_t BPB_NumHeads[2];
+ uint8_t BPB_HiddSec[4];
+ uint8_t BPB_TotSec32[4];
+ /* FAT32 only fields */
+ uint8_t BPB_FATSz32[4];
+ uint8_t BPB_ExtFlags[2];
+ uint8_t BPB_FSVer[2];
+ uint8_t BPB_RootClus[4];
+ uint8_t BPB_FSInfo[2];
+ uint8_t BPB_BkBootSec[2];
+ uint8_t BPB_Reserved[12];
+ uint8_t BS_DrvNum;
+ uint8_t BS_Reserved1;
+ uint8_t BS_BootSig;
+ uint8_t BS_VolID[4];
+ uint8_t BS_VolLab[11];
+ uint8_t BS_FilSysType[8];
+} FAT32_BSBPB; /* 90 bytes */
+
+/*
+ * FAT directory entry structure
+ */
+#define FAT_DES_ATTR_READ_ONLY 0x01
+#define FAT_DES_ATTR_HIDDEN 0x02
+#define FAT_DES_ATTR_SYSTEM 0x04
+#define FAT_DES_ATTR_VOLUME_ID 0x08
+#define FAT_DES_ATTR_DIRECTORY 0x10
+#define FAT_DES_ATTR_ARCHIVE 0x20
+#define FAT_DES_ATTR_LONG_NAME (FAT_DES_ATTR_READ_ONLY | \
+ FAT_DES_ATTR_HIDDEN | \
+ FAT_DES_ATTR_SYSTEM | \
+ FAT_DES_ATTR_VOLUME_ID)
+
+typedef struct fat_des {
+ uint8_t DIR_Name[11];
+ uint8_t DIR_Attr;
+ uint8_t DIR_NTRes;
+ uint8_t DIR_CrtTimeTenth;
+ uint8_t DIR_CrtTime[2];
+ uint8_t DIR_CrtDate[2];
+ uint8_t DIR_LstAccDate[2];
+ uint8_t DIR_FstClusHI[2];
+ uint8_t DIR_WrtTime[2];
+ uint8_t DIR_WrtDate[2];
+ uint8_t DIR_FstClusLO[2];
+ uint8_t DIR_FileSize[4];
+} FAT_DES;
Property changes on: trunk/usr.sbin/fstyp/msdosfs.h
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/ntfs.c
===================================================================
--- trunk/usr.sbin/fstyp/ntfs.c (rev 0)
+++ trunk/usr.sbin/fstyp/ntfs.c 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,164 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005 Takanori Watanabe
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.sbin/fstyp/ntfs.c 277436 2015-01-20 20:42:55Z trasz $");
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "fstyp.h"
+
+#define NTFS_A_VOLUMENAME 0x60
+#define NTFS_FILEMAGIC ((uint32_t)(0x454C4946))
+#define NTFS_VOLUMEINO 3
+
+struct ntfs_attr {
+ uint32_t a_type;
+ uint32_t reclen;
+ uint8_t a_flag;
+ uint8_t a_namelen;
+ uint8_t a_nameoff;
+ uint8_t reserved1;
+ uint8_t a_compression;
+ uint8_t reserved2;
+ uint16_t a_index;
+ uint16_t a_datalen;
+ uint16_t reserved3;
+ uint16_t a_dataoff;
+ uint16_t a_indexed;
+} __packed;
+
+struct ntfs_filerec {
+ uint32_t fr_hdrmagic;
+ uint16_t fr_hdrfoff;
+ uint16_t fr_hdrfnum;
+ uint8_t reserved[8];
+ uint16_t fr_seqnum;
+ uint16_t fr_nlink;
+ uint16_t fr_attroff;
+ uint16_t fr_flags;
+ uint32_t fr_size;
+ uint32_t fr_allocated;
+ uint64_t fr_mainrec;
+ uint16_t fr_attrnum;
+} __packed;
+
+struct ntfs_bootfile {
+ uint8_t reserved1[3];
+ uint8_t bf_sysid[8];
+ uint16_t bf_bps;
+ uint8_t bf_spc;
+ uint8_t reserved2[7];
+ uint8_t bf_media;
+ uint8_t reserved3[2];
+ uint16_t bf_spt;
+ uint16_t bf_heads;
+ uint8_t reserver4[12];
+ uint64_t bf_spv;
+ uint64_t bf_mftcn;
+ uint64_t bf_mftmirrcn;
+ int8_t bf_mftrecsz;
+ uint32_t bf_ibsz;
+ uint32_t bf_volsn;
+} __packed;
+
+int
+fstyp_ntfs(FILE *fp, char *label, size_t size)
+{
+ struct ntfs_bootfile *bf;
+ struct ntfs_filerec *fr;
+ struct ntfs_attr *atr;
+ off_t voloff;
+ char *filerecp, *ap;
+ int8_t mftrecsz;
+ char vnchar;
+ int recsize, j;
+
+ filerecp = NULL;
+
+ bf = (struct ntfs_bootfile *)read_buf(fp, 0, 512);
+ if (bf == NULL || strncmp(bf->bf_sysid, "NTFS ", 8) != 0)
+ goto fail;
+
+ mftrecsz = bf->bf_mftrecsz;
+ recsize = (mftrecsz > 0) ? (mftrecsz * bf->bf_bps * bf->bf_spc) : (1 << -mftrecsz);
+
+ voloff = bf->bf_mftcn * bf->bf_spc * bf->bf_bps +
+ recsize * NTFS_VOLUMEINO;
+
+ filerecp = read_buf(fp, voloff, recsize);
+ if (filerecp == NULL)
+ goto fail;
+ fr = (struct ntfs_filerec *)filerecp;
+
+ if (fr->fr_hdrmagic != NTFS_FILEMAGIC)
+ goto fail;
+
+ for (ap = filerecp + fr->fr_attroff;
+ atr = (struct ntfs_attr *)ap, (int)atr->a_type != -1;
+ ap += atr->reclen) {
+ if (atr->a_type == NTFS_A_VOLUMENAME) {
+ if(atr->a_datalen >= size *2){
+ goto fail;
+ }
+ /*
+ *UNICODE to ASCII.
+ * Should we need to use iconv(9)?
+ */
+ for (j = 0; j < atr->a_datalen; j++) {
+ vnchar = *(ap + atr->a_dataoff + j);
+ if (j & 1) {
+ if (vnchar) {
+ goto fail;
+ }
+ } else {
+ label[j / 2] = vnchar;
+ }
+ }
+ label[j / 2] = 0;
+ break;
+ }
+ }
+
+ free(bf);
+ free(filerecp);
+
+ return (0);
+
+fail:
+ free(bf);
+ free(filerecp);
+
+ return (1);
+}
Property changes on: trunk/usr.sbin/fstyp/ntfs.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/tests/Makefile
===================================================================
--- trunk/usr.sbin/fstyp/tests/Makefile (rev 0)
+++ trunk/usr.sbin/fstyp/tests/Makefile 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,14 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/fstyp/tests/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+ATF_TESTS_SH= fstyp_test
+
+FILES= ext2.img.bz2
+FILES+= ext3.img.bz2
+FILES+= ext4.img.bz2
+FILES+= ext4_with_label.img.bz2
+FILES+= ntfs.img.bz2
+FILES+= ntfs_with_label.img.bz2
+FILESDIR= ${TESTSDIR}
+
+.include <bsd.test.mk>
Property changes on: trunk/usr.sbin/fstyp/tests/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/tests/ext2.img.bz2
===================================================================
(Binary files differ)
Index: trunk/usr.sbin/fstyp/tests/ext2.img.bz2
===================================================================
--- trunk/usr.sbin/fstyp/tests/ext2.img.bz2 2018-06-09 22:16:16 UTC (rev 10751)
+++ trunk/usr.sbin/fstyp/tests/ext2.img.bz2 2018-06-09 22:26:44 UTC (rev 10752)
Property changes on: trunk/usr.sbin/fstyp/tests/ext2.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/tests/ext3.img.bz2
===================================================================
(Binary files differ)
Index: trunk/usr.sbin/fstyp/tests/ext3.img.bz2
===================================================================
--- trunk/usr.sbin/fstyp/tests/ext3.img.bz2 2018-06-09 22:16:16 UTC (rev 10751)
+++ trunk/usr.sbin/fstyp/tests/ext3.img.bz2 2018-06-09 22:26:44 UTC (rev 10752)
Property changes on: trunk/usr.sbin/fstyp/tests/ext3.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/tests/ext4.img.bz2
===================================================================
(Binary files differ)
Index: trunk/usr.sbin/fstyp/tests/ext4.img.bz2
===================================================================
--- trunk/usr.sbin/fstyp/tests/ext4.img.bz2 2018-06-09 22:16:16 UTC (rev 10751)
+++ trunk/usr.sbin/fstyp/tests/ext4.img.bz2 2018-06-09 22:26:44 UTC (rev 10752)
Property changes on: trunk/usr.sbin/fstyp/tests/ext4.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/tests/ext4_with_label.img.bz2
===================================================================
(Binary files differ)
Index: trunk/usr.sbin/fstyp/tests/ext4_with_label.img.bz2
===================================================================
--- trunk/usr.sbin/fstyp/tests/ext4_with_label.img.bz2 2018-06-09 22:16:16 UTC (rev 10751)
+++ trunk/usr.sbin/fstyp/tests/ext4_with_label.img.bz2 2018-06-09 22:26:44 UTC (rev 10752)
Property changes on: trunk/usr.sbin/fstyp/tests/ext4_with_label.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/tests/fstyp_test.sh
===================================================================
--- trunk/usr.sbin/fstyp/tests/fstyp_test.sh (rev 0)
+++ trunk/usr.sbin/fstyp/tests/fstyp_test.sh 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,260 @@
+#!/bin/sh
+#
+# Copyright (c) 2015 Alan Somers
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/fstyp/tests/fstyp_test.sh 312270 2017-01-16 07:11:37Z ngie $
+
+atf_test_case cd9660
+cd9660_head() {
+ atf_set "descr" "fstyp(8) should detect cd9660 filesystems"
+}
+cd9660_body() {
+ atf_check -s exit:0 mkdir -p dir/emptydir # makefs requires a nonempty directory
+ atf_check -s exit:0 -o ignore makefs -t cd9660 -Z -s 64m cd9660.img dir
+ atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img
+ atf_check -s exit:0 -o inline:"cd9660\n" fstyp -l cd9660.img
+}
+
+atf_test_case cd9660_label
+cd9660_label_head() {
+ atf_set "descr" "fstyp(8) can read the label on a cd9660 filesystem"
+}
+cd9660_label_body() {
+ atf_check -s exit:0 mkdir -p dir/emptydir # makefs requires a nonempty directory
+ atf_check -s exit:0 -o ignore makefs -t cd9660 -o label=Foo -Z -s 64m cd9660.img dir
+ atf_check -s exit:0 -o inline:"cd9660\n" fstyp cd9660.img
+ # Note: cd9660 labels are always upper case
+ atf_check -s exit:0 -o inline:"cd9660 FOO\n" fstyp -l cd9660.img
+}
+
+atf_test_case dir
+dir_head() {
+ atf_set "descr" "fstyp(8) should fail on a directory"
+}
+dir_body() {
+ atf_check -s exit:0 mkdir dir
+ atf_check -s exit:1 -e match:"not a disk" fstyp dir
+}
+
+atf_test_case empty
+empty_head() {
+ atf_set "descr" "fstyp(8) should fail on an empty file"
+}
+empty_body() {
+ atf_check -s exit:0 touch empty
+ atf_check -s exit:1 -e match:"filesystem not recognized" fstyp empty
+}
+
+atf_test_case ext2
+ext2_head() {
+ atf_set "descr" "fstyp(8) can detect ext2 filesystems"
+}
+ext2_body() {
+ bzcat $(atf_get_srcdir)/ext2.img.bz2 > ext2.img
+ atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext2.img
+ atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext2.img
+}
+
+atf_test_case ext3
+ext3_head() {
+ atf_set "descr" "fstyp(8) can detect ext3 filesystems"
+}
+ext3_body() {
+ bzcat $(atf_get_srcdir)/ext3.img.bz2 > ext3.img
+ atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext3.img
+ atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext3.img
+}
+
+atf_test_case ext4
+ext4_head() {
+ atf_set "descr" "fstyp(8) can detect ext4 filesystems"
+}
+ext4_body() {
+ bzcat $(atf_get_srcdir)/ext4.img.bz2 > ext4.img
+ atf_check -s exit:0 -o inline:"ext2fs\n" fstyp ext4.img
+ atf_check -s exit:0 -o inline:"ext2fs\n" fstyp -l ext4.img
+}
+
+atf_test_case ext4_label
+ext4_label_head() {
+ atf_set "descr" "fstyp(8) can read the label on an ext4 filesystem"
+}
+ext4_label_body() {
+ bzcat $(atf_get_srcdir)/ext4_with_label.img.bz2 > ext4_with_label.img
+ atf_check -s exit:0 -o inline:"ext2fs foo\n" fstyp -l ext4_with_label.img
+}
+
+atf_test_case fat12
+fat12_head() {
+ atf_set "descr" "fstyp(8) can detect FAT12 filesystems"
+}
+fat12_body() {
+ atf_check -s exit:0 truncate -s 64m msdos.img
+ atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 12 ./msdos.img
+ atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
+ atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
+}
+
+atf_test_case fat16
+fat16_head() {
+ atf_set "descr" "fstyp(8) can detect FAT16 filesystems"
+}
+fat16_body() {
+ atf_check -s exit:0 truncate -s 64m msdos.img
+ atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 16 ./msdos.img
+ atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
+ atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
+}
+
+atf_test_case fat32
+fat32_head() {
+ atf_set "descr" "fstyp(8) can detect FAT32 filesystems"
+}
+fat32_body() {
+ atf_check -s exit:0 truncate -s 64m msdos.img
+ atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -c 1 \
+ ./msdos.img
+ atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
+ atf_check -s exit:0 -o inline:"msdosfs\n" fstyp -l msdos.img
+}
+
+atf_test_case fat32_label
+fat32_label_head() {
+ atf_set "descr" "fstyp(8) can read the label on an msdos filesystem"
+}
+fat32_label_body() {
+ atf_check -s exit:0 truncate -s 64m msdos.img
+ atf_check -s exit:0 -o ignore -e ignore newfs_msdos -F 32 -L Foo -c 1 \
+ ./msdos.img
+ atf_check -s exit:0 -o inline:"msdosfs\n" fstyp msdos.img
+ # Note: msdos labels are always upper case
+ atf_check -s exit:0 -o inline:"msdosfs FOO\n" fstyp -l msdos.img
+}
+
+atf_test_case ntfs
+ntfs_head() {
+ atf_set "descr" "fstyp(8) can detect ntfs filesystems"
+}
+ntfs_body() {
+ bzcat $(atf_get_srcdir)/ntfs.img.bz2 > ntfs.img
+ atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs.img
+ atf_check -s exit:0 -o inline:"ntfs\n" fstyp -l ntfs.img
+}
+
+atf_test_case ntfs_with_label
+ntfs_with_label_head() {
+ atf_set "descr" "fstyp(8) can read labels on ntfs filesystems"
+}
+ntfs_with_label_body() {
+ bzcat $(atf_get_srcdir)/ntfs_with_label.img.bz2 > ntfs_with_label.img
+ atf_check -s exit:0 -o inline:"ntfs\n" fstyp ntfs_with_label.img
+ atf_check -s exit:0 -o inline:"ntfs Foo\n" fstyp -l ntfs_with_label.img
+}
+
+atf_test_case ufs1
+ufs1_head() {
+ atf_set "descr" "fstyp(8) should detect UFS version 1 filesystems"
+}
+ufs1_body() {
+ atf_check -s exit:0 mkdir dir
+ atf_check -s exit:0 -o ignore makefs -Z -s 64m ufs.img dir
+ atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img
+ atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img
+}
+
+atf_test_case ufs2
+ufs2_head() {
+ atf_set "descr" "fstyp(8) should detect UFS version 2 filesystems"
+}
+ufs2_body() {
+ atf_check -s exit:0 mkdir dir
+ atf_check -s exit:0 -o ignore makefs -o version=2 -Z -s 64m ufs.img dir
+ atf_check -s exit:0 -o inline:"ufs\n" fstyp ufs.img
+ atf_check -s exit:0 -o inline:"ufs\n" fstyp -l ufs.img
+}
+
+atf_test_case ufs2_label
+ufs2_label_head() {
+ atf_set "descr" "fstyp(8) can read the label on a UFS v2 filesystem"
+}
+ufs2_label_body() {
+ atf_check -s exit:0 mkdir dir
+ atf_check -s exit:0 -o ignore makefs -o version=2,label="foo" -Z -s 64m ufs.img dir
+ atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l ufs.img
+}
+
+atf_test_case ufs_on_device cleanup
+ufs_on_device_head() {
+ atf_set "descr" "fstyp(8) should work on device nodes"
+ atf_set "require.user" "root"
+}
+ufs_on_device_body() {
+ mdconfig -a -t swap -s 64m > mdname
+ md=$(cat mdname)
+ if [ -z "$md" ]; then
+ atf_fail "Failed to create md(4) device"
+ fi
+ atf_check -s exit:0 -o ignore newfs -L foo /dev/$md
+ atf_check -s exit:0 -o inline:"ufs\n" fstyp /dev/$md
+ atf_check -s exit:0 -o inline:"ufs foo\n" fstyp -l /dev/$md
+}
+ufs_on_device_cleanup() {
+ md=$(cat mdname)
+ if [ -n "$md" ]; then
+ mdconfig -d -u "$md"
+ fi
+}
+
+atf_test_case zeros
+zeros_head() {
+ atf_set "descr" "fstyp(8) should fail on a zero-filled file"
+}
+zeros_body() {
+ atf_check -s exit:0 truncate -s 256m zeros
+ atf_check -s exit:1 -e match:"filesystem not recognized" fstyp zeros
+}
+
+
+atf_init_test_cases() {
+ atf_add_test_case cd9660
+ atf_add_test_case cd9660_label
+ atf_add_test_case dir
+ atf_add_test_case empty
+ atf_add_test_case ext2
+ atf_add_test_case ext3
+ atf_add_test_case ext4
+ atf_add_test_case ext4_label
+ atf_add_test_case fat12
+ atf_add_test_case fat16
+ atf_add_test_case fat32
+ atf_add_test_case fat32_label
+ atf_add_test_case ntfs
+ atf_add_test_case ntfs_with_label
+ atf_add_test_case ufs1
+ atf_add_test_case ufs2
+ atf_add_test_case ufs2_label
+ atf_add_test_case ufs_on_device
+ atf_add_test_case zeros
+}
Property changes on: trunk/usr.sbin/fstyp/tests/fstyp_test.sh
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/tests/ntfs.img.bz2
===================================================================
(Binary files differ)
Index: trunk/usr.sbin/fstyp/tests/ntfs.img.bz2
===================================================================
--- trunk/usr.sbin/fstyp/tests/ntfs.img.bz2 2018-06-09 22:16:16 UTC (rev 10751)
+++ trunk/usr.sbin/fstyp/tests/ntfs.img.bz2 2018-06-09 22:26:44 UTC (rev 10752)
Property changes on: trunk/usr.sbin/fstyp/tests/ntfs.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/tests/ntfs_with_label.img.bz2
===================================================================
(Binary files differ)
Index: trunk/usr.sbin/fstyp/tests/ntfs_with_label.img.bz2
===================================================================
--- trunk/usr.sbin/fstyp/tests/ntfs_with_label.img.bz2 2018-06-09 22:16:16 UTC (rev 10751)
+++ trunk/usr.sbin/fstyp/tests/ntfs_with_label.img.bz2 2018-06-09 22:26:44 UTC (rev 10752)
Property changes on: trunk/usr.sbin/fstyp/tests/ntfs_with_label.img.bz2
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/x-bzip2
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/ufs.c
===================================================================
--- trunk/usr.sbin/fstyp/ufs.c (rev 0)
+++ trunk/usr.sbin/fstyp/ufs.c 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,110 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2002, 2003 Gordon Tetlow
+ * Copyright (c) 2006 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * This software was developed by Edward Tomasz Napierala under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.sbin/fstyp/ufs.c 275680 2014-12-10 14:14:16Z trasz $");
+
+#include <sys/types.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <ufs/ufs/dinode.h>
+#include <ufs/ffs/fs.h>
+
+#include "fstyp.h"
+
+static const int superblocks[] = SBLOCKSEARCH;
+
+int
+fstyp_ufs(FILE *fp, char *label, size_t labelsize)
+{
+ int sb, superblock;
+ struct fs *fs;
+
+ /*
+ * Walk through the standard places that superblocks hide and look
+ * for UFS magic. If we find magic, then check that the size in the
+ * superblock corresponds to the size of the underlying provider.
+ * Finally, look for a volume label and create an appropriate
+ * provider based on that.
+ */
+ for (sb = 0; (superblock = superblocks[sb]) != -1; sb++) {
+ fs = (struct fs *)read_buf(fp, superblock, SBLOCKSIZE);
+ if (fs == NULL)
+ continue;
+ /*
+ * Check for magic. We also need to check if file system size is equal
+ * to providers size, because sysinstall(8) used to bogusly put first
+ * partition at offset 0 instead of 16, and glabel/ufs would find file
+ * system on slice instead of partition.
+ */
+#ifdef notyet
+ if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_fsize > 0 &&
+ ((pp->mediasize / fs->fs_fsize == fs->fs_old_size) ||
+ (pp->mediasize / fs->fs_fsize == fs->fs_providersize))) {
+ /* Valid UFS1. */
+ } else if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_fsize > 0 &&
+ ((pp->mediasize / fs->fs_fsize == fs->fs_size) ||
+ (pp->mediasize / fs->fs_fsize == fs->fs_providersize))) {
+ /* Valid UFS2. */
+ } else {
+ g_free(fs);
+ continue;
+ }
+#else
+ if (fs->fs_magic == FS_UFS1_MAGIC && fs->fs_fsize > 0) {
+ /* Valid UFS1. */
+ } else if (fs->fs_magic == FS_UFS2_MAGIC && fs->fs_fsize > 0) {
+ /* Valid UFS2. */
+ } else {
+ free(fs);
+ continue;
+ }
+#endif
+
+ if (fs->fs_sblockloc != superblock || fs->fs_ncg < 1 ||
+ fs->fs_bsize < MINBSIZE ||
+ (size_t)fs->fs_bsize < sizeof(struct fs)) {
+ free(fs);
+ continue;
+ }
+
+ strlcpy(label, fs->fs_volname, labelsize);
+
+ free(fs);
+ return (0);
+ }
+
+ return (1);
+}
Property changes on: trunk/usr.sbin/fstyp/ufs.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/usr.sbin/fstyp/zfs.c
===================================================================
--- trunk/usr.sbin/fstyp/zfs.c (rev 0)
+++ trunk/usr.sbin/fstyp/zfs.c 2018-06-09 22:26:44 UTC (rev 10752)
@@ -0,0 +1,79 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2015 Allan Jude <allanjude at FreeBSD.org>
+ * Copyright (c) 2015 Xin LI <delphij at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: stable/10/usr.sbin/fstyp/zfs.c 293776 2016-01-12 16:38:09Z allanjude $");
+
+#include <sys/types.h>
+#include <cddl/compat/opensolaris/sys/types.h>
+#include <sys/time.h>
+#include <cddl/compat/opensolaris/sys/time.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <libnvpair.h>
+#include <sys/vdev_impl.h>
+
+#include "fstyp.h"
+
+int
+fstyp_zfs(FILE *fp, char *label, size_t labelsize)
+{
+ vdev_label_t *vdev_label = NULL;
+ vdev_phys_t *vdev_phys;
+ char *zpool_name = NULL;
+ nvlist_t *config = NULL;
+ int err = 0;
+
+ /*
+ * Read in the first ZFS vdev label ("L0"), located at the beginning
+ * of the vdev and extract the pool name from it.
+ *
+ * TODO: the checksum of label should be validated.
+ */
+ vdev_label = (vdev_label_t *)read_buf(fp, 0, sizeof(*vdev_label));
+ if (vdev_label == NULL)
+ return (1);
+
+ vdev_phys = &(vdev_label->vl_vdev_phys);
+
+ if ((nvlist_unpack(vdev_phys->vp_nvlist, sizeof(vdev_phys->vp_nvlist),
+ &config, 0)) == 0 &&
+ (nvlist_lookup_string(config, "name", &zpool_name) == 0)) {
+ strlcpy(label, zpool_name, labelsize);
+ } else
+ err = 1;
+
+ nvlist_free(config);
+ free(vdev_label);
+
+ return (err);
+}
Property changes on: trunk/usr.sbin/fstyp/zfs.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
More information about the Midnightbsd-cvs
mailing list