Page MenuHomeFreeBSD

D29917.id87936.diff
No OneTemporary

D29917.id87936.diff

Index: usr.sbin/fstyp/Makefile
===================================================================
--- usr.sbin/fstyp/Makefile
+++ usr.sbin/fstyp/Makefile
@@ -4,7 +4,7 @@
PROG= fstyp
SRCS= apfs.c cd9660.c exfat.c ext2fs.c fstyp.c geli.c hammer.c \
- hammer2.c hfsplus.c msdosfs.c ntfs.c ufs.c
+ hammer2.c hfsplus.c msdosfs.c ntfs.c ufs.c bfs.c
.if ${MK_ZFS} != "no"
SRCS += zfs.c
Index: usr.sbin/fstyp/bfs.c
===================================================================
--- /dev/null
+++ usr.sbin/fstyp/bfs.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2021 Miguel Gocobachi <miguel@gocobachi.dev>. 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>
+__FBSDID("$FreeBSD$");
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "fstyp.h"
+
+#define BFS_OS_NAME_LENGTH 32
+#define BFS_SUPER_BLOCK_MAGIC1 0x42465331
+
+struct bfs_disk_superblock {
+ char name[BFS_OS_NAME_LENGTH];
+ int32_t magic1;
+};
+
+int fstyp_bfs(FILE *fp, char *label, size_t size)
+{
+ struct bfs_disk_superblock *volume;
+
+ volume = read_buf(fp, 512, sizeof(*volume));
+
+ if (volume == NULL) {
+ free(volume);
+
+ return 1;
+ }
+
+ if (volume->magic1 != BFS_SUPER_BLOCK_MAGIC1) {
+ free(volume);
+
+ return 1;
+ }
+
+ bzero(label, size);
+ strlcpy(label, volume->name, MIN(size, BFS_OS_NAME_LENGTH));
+ rtrim(label, size);
+
+ free(volume);
+
+ return 0;
+}
Index: usr.sbin/fstyp/fstyp.h
===================================================================
--- usr.sbin/fstyp/fstyp.h
+++ usr.sbin/fstyp/fstyp.h
@@ -60,6 +60,7 @@
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);
+int fstyp_bfs(FILE *fp, char *label, size_t size);
#ifdef HAVE_ZFS
int fstyp_zfs(FILE *fp, char *label, size_t size);
#endif
Index: usr.sbin/fstyp/fstyp.c
===================================================================
--- usr.sbin/fstyp/fstyp.c
+++ usr.sbin/fstyp/fstyp.c
@@ -74,6 +74,7 @@
{ "msdosfs", &fstyp_msdosfs, false, NULL },
{ "ntfs", &fstyp_ntfs, false, NTFS_ENC },
{ "ufs", &fstyp_ufs, false, NULL },
+ { "bfs", &fstyp_bfs, false, NULL },
#ifdef HAVE_ZFS
{ "zfs", &fstyp_zfs, true, NULL },
#endif
Index: usr.sbin/fstyp/tests/Makefile
===================================================================
--- usr.sbin/fstyp/tests/Makefile
+++ usr.sbin/fstyp/tests/Makefile
@@ -11,5 +11,6 @@
${PACKAGE}FILES+= ext4_with_label.img.bz2
${PACKAGE}FILES+= ntfs.img.bz2
${PACKAGE}FILES+= ntfs_with_label.img.bz2
+${PACKAGE}FILES+= bfs.img.bz2
.include <bsd.test.mk>
Index: usr.sbin/fstyp/tests/fstyp_test.sh
===================================================================
--- usr.sbin/fstyp/tests/fstyp_test.sh
+++ usr.sbin/fstyp/tests/fstyp_test.sh
@@ -255,6 +255,15 @@
atf_check -s exit:1 -e match:"filesystem not recognized" fstyp zeros
}
+atf_test_case bfs
+bfs_head() {
+ atf_set "descr" "fstyp(8) can detect bfs and label filesystems"
+}
+bfs_body() {
+ bzcat $(atf_get_srcdir)/bfs.img.bz2 > bfs.img
+ atf_check -s exit:0 -o inline:"bfs\n" fstyp bfs.img
+ atf_check -s exit:0 -o inline:"bfs BeFS\n" fstyp -l bfs.img
+}
atf_init_test_cases() {
atf_add_test_case cd9660
@@ -277,5 +286,6 @@
atf_add_test_case ufs2
atf_add_test_case ufs2_label
atf_add_test_case ufs_on_device
+ atf_add_test_case bfs
atf_add_test_case zeros
}

File Metadata

Mime Type
text/plain
Expires
Thu, Jun 25, 5:15 PM (2 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34325772
Default Alt Text
D29917.id87936.diff (4 KB)

Event Timeline