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: Add exFAT support
details: https://anonhg.NetBSD.org/src/rev/112c59e803de
branches: trunk
changeset: 465364:112c59e803de
user: tkusumi <tkusumi%NetBSD.org@localhost>
date: Mon Nov 18 14:53:34 2019 +0000
description:
fstyp: Add exFAT support
Taken-from: FreeBSD and DragonFlyBSD
diffstat:
usr.sbin/fstyp/Makefile | 4 +-
usr.sbin/fstyp/exfat.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++
usr.sbin/fstyp/fstyp.8 | 8 +++-
usr.sbin/fstyp/fstyp.c | 5 +-
usr.sbin/fstyp/fstyp.h | 3 +-
5 files changed, 90 insertions(+), 8 deletions(-)
diffs (176 lines):
diff -r 07e2dc1daa2b -r 112c59e803de usr.sbin/fstyp/Makefile
--- a/usr.sbin/fstyp/Makefile Mon Nov 18 12:06:26 2019 +0000
+++ b/usr.sbin/fstyp/Makefile Mon Nov 18 14:53:34 2019 +0000
@@ -1,9 +1,9 @@
-# $NetBSD: Makefile,v 1.5 2019/06/24 08:27:21 hannken Exp $
+# $NetBSD: Makefile,v 1.6 2019/11/18 14:53:34 tkusumi Exp $
.include <bsd.own.mk>
PROG= fstyp
-SRCS= cd9660.c ext2fs.c fstyp.c msdosfs.c ntfs.c ufs.c
+SRCS= cd9660.c exfat.c ext2fs.c fstyp.c msdosfs.c ntfs.c ufs.c
.if (${MKZFS} != "no")
SRCS+= zfs.c
diff -r 07e2dc1daa2b -r 112c59e803de usr.sbin/fstyp/exfat.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/fstyp/exfat.c Mon Nov 18 14:53:34 2019 +0000
@@ -0,0 +1,78 @@
+/* $NetBSD: exfat.c,v 1.1 2019/11/18 14:53:34 tkusumi Exp $ */
+
+/*
+ * Copyright (c) 2017 Conrad Meyer <cem%FreeBSD.org@localhost>
+ * 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: exfat.c,v 1.1 2019/11/18 14:53:34 tkusumi Exp $");
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "fstyp.h"
+
+struct exfat_vbr {
+ char ev_jmp[3];
+ char ev_fsname[8];
+ char ev_zeros[53];
+ uint64_t ev_part_offset;
+ uint64_t ev_vol_length;
+ uint32_t ev_fat_offset;
+ uint32_t ev_fat_length;
+ uint32_t ev_cluster_offset;
+ uint32_t ev_cluster_count;
+ uint32_t ev_rootdir_cluster;
+ uint32_t ev_vol_serial;
+ uint16_t ev_fs_revision;
+ uint16_t ev_vol_flags;
+ uint8_t ev_log_bytes_per_sect;
+ uint8_t ev_log_sect_per_clust;
+ uint8_t ev_num_fats;
+ uint8_t ev_drive_sel;
+ uint8_t ev_percent_used;
+} __packed;
+
+int
+fstyp_exfat(FILE *fp, char *label, size_t size)
+{
+ struct exfat_vbr *ev;
+
+ ev = (struct exfat_vbr *)read_buf(fp, 0, 512);
+ if (ev == NULL || strncmp(ev->ev_fsname, "EXFAT ", 8) != 0)
+ goto fail;
+
+ /*
+ * Reading the volume label requires walking the root directory to look
+ * for a special label file. Left as an exercise for the reader.
+ */
+ free(ev);
+ return (0);
+
+fail:
+ free(ev);
+ return (1);
+}
diff -r 07e2dc1daa2b -r 112c59e803de usr.sbin/fstyp/fstyp.8
--- a/usr.sbin/fstyp/fstyp.8 Mon Nov 18 12:06:26 2019 +0000
+++ b/usr.sbin/fstyp/fstyp.8 Mon Nov 18 14:53:34 2019 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: fstyp.8,v 1.2 2018/01/09 09:41:29 wiz Exp $
+.\" $NetBSD: fstyp.8,v 1.3 2019/11/18 14:53:34 tkusumi Exp $
.\"
.\" Copyright (c) 2017 The NetBSD Foundation, Inc.
.\" Copyright (c) 2016 The DragonFly Project
@@ -34,7 +34,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd November 25, 2017
+.Dd November 19, 2019
.Dt FSTYP 8
.Os
.Sh NAME
@@ -48,7 +48,7 @@
The
.Nm
utility is used to determine the file system type on a given device.
-It can recognize ISO-9660, Ext2, FAT, NTFS, and UFS file systems.
+It can recognize ISO-9660, exFAT, Ext2, FAT, NTFS, and UFS file systems.
When the
.Fl u
flag is specified,
@@ -64,6 +64,8 @@
.It
cd9660
.It
+exfat
+.It
ext2fs
.It
msdosfs
diff -r 07e2dc1daa2b -r 112c59e803de usr.sbin/fstyp/fstyp.c
--- a/usr.sbin/fstyp/fstyp.c Mon Nov 18 12:06:26 2019 +0000
+++ b/usr.sbin/fstyp/fstyp.c Mon Nov 18 14:53:34 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fstyp.c,v 1.2 2018/01/09 10:47:57 martin Exp $ */
+/* $NetBSD: fstyp.c,v 1.3 2019/11/18 14:53:34 tkusumi Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
*
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: fstyp.c,v 1.2 2018/01/09 10:47:57 martin Exp $");
+__RCSID("$NetBSD: fstyp.c,v 1.3 2019/11/18 14:53:34 tkusumi Exp $");
#include <sys/disklabel.h>
#include <sys/dkio.h>
@@ -64,6 +64,7 @@
bool unmountable;
} fstypes[] = {
{ "cd9660", &fstyp_cd9660, false },
+ { "exfat", &fstyp_exfat, false },
{ "ext2fs", &fstyp_ext2fs, false },
{ "msdosfs", &fstyp_msdosfs, false },
{ "ntfs", &fstyp_ntfs, false },
diff -r 07e2dc1daa2b -r 112c59e803de usr.sbin/fstyp/fstyp.h
--- a/usr.sbin/fstyp/fstyp.h Mon Nov 18 12:06:26 2019 +0000
+++ b/usr.sbin/fstyp/fstyp.h Mon Nov 18 14:53:34 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fstyp.h,v 1.1 2018/01/09 03:31:15 christos Exp $ */
+/* $NetBSD: fstyp.h,v 1.2 2019/11/18 14:53:34 tkusumi Exp $ */
/*-
* Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -44,6 +44,7 @@
void rtrim(char *, size_t);
int fstyp_cd9660(FILE *, char *, size_t);
+int fstyp_exfat(FILE *fp, char *label, size_t size);
int fstyp_ext2fs(FILE *, char *, size_t);
int fstyp_msdosfs(FILE *, char *, size_t);
int fstyp_ntfs(FILE *, char *, size_t);
Home |
Main Index |
Thread Index |
Old Index