Package: klibc-utils
Version: 2.0.12-1
Severity: normal
Tags: upstream patch

Hi,

fstype should autodetect bcachefs, not the least because bcachefs filesystems
may require other treatment of UUID mounts (#1060411, #1061525). I've attached
a simple patch.


-- System Information:
Debian Release: 12.4
  APT prefers stable-security
  APT policy: (500, 'stable-security'), (500, 'stable-debug'), (500, 
'proposed-updates'), (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.7.0 (SMP w/56 CPU threads; PREEMPT)
Kernel taint flags: TAINT_WARN
Locale: LANG=en_DK.UTF-8, LC_CTYPE=en_DK.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_NO:en_US:en_GB:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages klibc-utils depends on:
ii  libklibc  2.0.12-1

klibc-utils recommends no packages.

klibc-utils suggests no packages.

-- debconf-show failed
Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 klibc (2.0.13-3) experimental; urgency=medium
 .
   * Install klibc shared library in /usr/lib
Author: Ben Hutchings <b...@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout https://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: (upstream|backport|vendor|other), (<patch-url>|commit:<commit-id>)
Bug: <upstream-bugtracker-url>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: (no|not-needed|<patch-forwarded-url>)
Applied-Upstream: <version>, (<commit-url>|commit:<commid-id>)
Reviewed-By: <name and email of someone who approved/reviewed the patch>
Last-Update: 2024-01-28

Index: klibc-2.0.13/usr/kinit/fstype/bcachefs_fs.h
===================================================================
--- /dev/null
+++ klibc-2.0.13/usr/kinit/fstype/bcachefs_fs.h
@@ -0,0 +1,20 @@
+#ifndef __BCACHEFS_FS_H
+#define __BCACHEFS_FS_H
+
+#define BCACHEFS_MAGIC                             \
+       {0xc6, 0x85, 0x73, 0xf6, 0x66, 0xce, 0x90, 0xa9, \
+        0xd9, 0x6a, 0x60, 0xcf, 0x80, 0x3d, 0xf7, 0xef};
+
+/*
+ * Structure of the superblock
+ */
+struct bch_sb_layout {
+       __u8 magic[16]; /* bcachefs superblock UUID */
+       __u8 layout_type;
+       __u8 sb_max_size_bits; /* base 2 of 512 byte sectors */
+       __u8 nr_superblocks;
+       __u8 pad[5];
+       __le64 sb_offset[61];
+} __attribute__((packed));
+
+#endif /* __BCACHEFS_FS_H */
Index: klibc-2.0.13/usr/kinit/fstype/fstype.c
===================================================================
--- klibc-2.0.13.orig/usr/kinit/fstype/fstype.c
+++ klibc-2.0.13/usr/kinit/fstype/fstype.c
@@ -23,6 +23,7 @@
 
 #define cpu_to_be32(x) __cpu_to_be32(x)        /* Needed by romfs_fs.h */
 
+#include "bcachefs_fs.h"
 #include "btrfs.h"
 #include "cramfs_fs.h"
 #include "ext2_fs.h"
@@ -161,6 +162,24 @@ static int ext2_image(const void *buf, u
        return 0;
 }
 
+static int bcachefs_image(const void *buf, unsigned long long *bytes)
+{
+       static const __u8 BCACHEFS_MAGIC_STRING[16] = BCACHEFS_MAGIC;
+       /* layout superblock starts at sector 7 */
+       const struct bch_sb_layout *sb =
+           (const struct bch_sb_layout *)((const char *)buf + 512);
+
+       if (memcmp(sb->magic, BCACHEFS_MAGIC_STRING,
+                  sizeof(BCACHEFS_MAGIC_STRING)) == 0) {
+               /* Knowing the size of the filesystem can potentially
+                  entail opening multiple devices and looking into their
+                  superblocks */
+               *bytes = 0;
+               return 1;
+       }
+       return 0;
+}
+
 static int reiserfs_image(const void *buf, unsigned long long *bytes)
 {
        const struct reiserfs_super_block *sb =
@@ -389,6 +408,7 @@ static struct imagetype images[] = {
        {1, "minix", minix_image},
        {1, "nilfs2", nilfs2_image},
        {2, "ocfs2", ocfs2_image},
+       {3, "bcachefs", bcachefs_image},
        {8, "reiserfs", reiserfs_image},
        {64, "reiserfs", reiserfs_image},
        {64, "reiser4", reiser4_image},

Reply via email to