Build mkfs.xfs using rules_cc

This drops the old big genrule for mkfs.xfs and replaces it with a nice rules_cc build system
with the help of bazel_cc_fix generated patches and our musl-based toolchain.
While we're at it I bumped the versions of all related dependencies to their latest stable release.
This also means pulling in ini.h which is a dependency of the new xfstools version.

Instructions to regenerate the patches are included in the spec files.

Toolchain selection is done by the existing transition in our rootfs rule so we automatically get a musl-built
static binary when building for the rootfs.

Test Plan: Tested with E2E tests, should fail fairly catastrophically if something were wrong.

X-Origin-Diff: phab/D708
GitOrigin-RevId: 648a05cdd08cfa84a8a9f4c057c52446e7005631
diff --git a/third_party/xfsprogs/external/BUILD b/third_party/inih/BUILD
similarity index 100%
copy from third_party/xfsprogs/external/BUILD
copy to third_party/inih/BUILD
diff --git a/third_party/inih/inih.bzl b/third_party/inih/inih.bzl
new file mode 100644
index 0000000..0752c12
--- /dev/null
+++ b/third_party/inih/inih.bzl
@@ -0,0 +1,24 @@
+#  Copyright 2020 The Monogon Project Authors.
+#
+#  SPDX-License-Identifier: Apache-2.0
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+cc_library(
+    name = "inih",
+    srcs = ["ini.c"],
+    hdrs = ["ini.h"],
+    visibility = ["//visibility:public"],
+)
diff --git a/third_party/util-linux/cc_fix_spec.prototxt b/third_party/util-linux/cc_fix_spec.prototxt
new file mode 100644
index 0000000..fed612f
--- /dev/null
+++ b/third_party/util-linux/cc_fix_spec.prototxt
@@ -0,0 +1,22 @@
+# proto-file: build/bazel_cc_fix/ccfixspec/ccfixspec.proto
+# proto-message: CCFixSpec
+
+# To regenerate the patch, run the following in the checked-out util-linux repo
+# ./autogen.sh
+# ./configure --without-util --without-udev --without-ncursesw --without-tinfo --without-readline --without-cap-ng --without-libz --without-libmagic --without-user --without-btrfs --without-systemd --without-python
+# intercept-build make -j24 uuidgen blkid
+
+# And the following in the monorepo root
+# bazel run //build/bazel_cc_fix -- -workspace $path_to_repo -compilation_db $path_to_repo/compile_commands.json -spec third_party/util-linux/cc_fix_spec.prototxt
+
+# Templated file (original path, later rewritten)
+generated_file {
+  path: "libblkid/src/blkid.h",
+}
+
+# Rewrite blkid.h to root for ease of use and easier codegen
+replace {
+  type: WORKSPACE,
+  from: "libblkid/src/blkid.h",
+  to: "blkid.h",
+}
diff --git a/third_party/util-linux/external.bzl b/third_party/util-linux/external.bzl
index 84b17ec..d764b4d 100644
--- a/third_party/util-linux/external.bzl
+++ b/third_party/util-linux/external.bzl
@@ -18,15 +18,16 @@
 
 def util_linux_external(name, version):
     sums = {
-        "2.34": "1d0c1a38f8c14a2c251681907203cccc78704f5702f2ef4b438bed08344242f7"
+        "2.34": "1d0c1a38f8c14a2c251681907203cccc78704f5702f2ef4b438bed08344242f7",
+        "2.36.2": "084bc6f9bd479bfd78e8924e63f85bb17953681bf1dad240e4d8601a21294d0b",
     }
-    all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""
 
     http_archive(
         name = name,
-        build_file_content = all_content,
         sha256 = sums[version],
         strip_prefix = "util-linux-" + version,
+        build_file = "@//third_party/util-linux:util-linux.bzl",
+        patch_args = ["-p1"],
+        patches = ["//third_party/util-linux/patches:bazel_cc_fix.patch"],
         urls = ["https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/snapshot/util-linux-%s.tar.gz" % version],
     )
-
diff --git a/third_party/xfsprogs/external/BUILD b/third_party/util-linux/patches/BUILD
similarity index 100%
copy from third_party/xfsprogs/external/BUILD
copy to third_party/util-linux/patches/BUILD
diff --git a/third_party/util-linux/patches/bazel_cc_fix.patch b/third_party/util-linux/patches/bazel_cc_fix.patch
new file mode 100644
index 0000000..cd69f5f
--- /dev/null
+++ b/third_party/util-linux/patches/bazel_cc_fix.patch
@@ -0,0 +1,1146 @@
+Copyright 2020 The Monogon Project Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+
+From 0f851156fc72247f8a6ad27dc5d98c1f18a11390 Mon Sep 17 00:00:00 2001
+From: Lorenz Brun <lorenz@nexantic.com>
+Date: Thu, 4 Mar 2021 14:42:52 +0100
+Subject: [PATCH] bazel_cc_fix patch
+
+---
+ lib/blkdev.c                           | 10 +++++-----
+ lib/canonicalize.c                     |  6 +++---
+ lib/color-names.c                      |  4 ++--
+ lib/cpuset.c                           |  4 ++--
+ lib/crc32.c                            |  2 +-
+ lib/crc32c.c                           |  2 +-
+ lib/encode.c                           |  4 ++--
+ lib/env.c                              |  2 +-
+ lib/fileutils.c                        |  6 +++---
+ lib/idcache.c                          |  4 ++--
+ lib/ismounted.c                        | 10 +++++-----
+ lib/linux_version.c                    |  4 ++--
+ lib/loopdev.c                          | 20 ++++++++++----------
+ lib/mangle.c                           |  4 ++--
+ lib/match.c                            |  2 +-
+ lib/mbsalign.c                         |  8 ++++----
+ lib/mbsedit.c                          |  4 ++--
+ lib/md5.c                              |  2 +-
+ lib/pager.c                            | 10 +++++-----
+ lib/path.c                             | 14 +++++++-------
+ lib/procutils.c                        | 10 +++++-----
+ lib/pwdutils.c                         |  6 +++---
+ lib/randutils.c                        |  6 +++---
+ lib/setproctitle.c                     |  2 +-
+ lib/sha1.c                             |  2 +-
+ lib/signames.c                         |  6 +++---
+ lib/strutils.c                         | 10 +++++-----
+ lib/strv.c                             |  4 ++--
+ lib/sysfs.c                            | 16 ++++++++--------
+ lib/timeutils.c                        |  8 ++++----
+ lib/ttyutils.c                         |  4 ++--
+ libblkid/src/blkidP.h                  | 14 +++++++-------
+ libblkid/src/cache.c                   |  2 +-
+ libblkid/src/config.c                  |  2 +-
+ libblkid/src/devname.c                 |  6 +++---
+ libblkid/src/devno.c                   |  4 ++--
+ libblkid/src/evaluate.c                |  6 +++---
+ libblkid/src/partitions/bsd.c          |  2 +-
+ libblkid/src/partitions/dos.c          |  2 +-
+ libblkid/src/partitions/gpt.c          |  2 +-
+ libblkid/src/partitions/minix.c        |  2 +-
+ libblkid/src/partitions/partitions.c   |  4 ++--
+ libblkid/src/partitions/partitions.h   |  4 ++--
+ libblkid/src/partitions/sgi.c          |  2 +-
+ libblkid/src/partitions/sun.c          |  2 +-
+ libblkid/src/probe.c                   |  8 ++++----
+ libblkid/src/save.c                    |  4 ++--
+ libblkid/src/superblocks/bluestore.c   |  2 +-
+ libblkid/src/superblocks/drbdmanage.c  |  2 +-
+ libblkid/src/superblocks/hfs.c         |  2 +-
+ libblkid/src/superblocks/minix.c       |  2 +-
+ libblkid/src/superblocks/mpool.c       |  2 +-
+ libblkid/src/superblocks/nilfs.c       |  2 +-
+ libblkid/src/superblocks/squashfs.c    |  2 +-
+ libblkid/src/superblocks/stratis.c     |  2 +-
+ libblkid/src/superblocks/superblocks.h |  2 +-
+ libblkid/src/superblocks/vfat.c        |  2 +-
+ libblkid/src/topology/sysfs.c          |  2 +-
+ libblkid/src/topology/topology.h       |  2 +-
+ libblkid/src/verify.c                  |  2 +-
+ libuuid/src/gen_uuid.c                 | 12 ++++++------
+ misc-utils/blkid.c                     | 16 ++++++++--------
+ misc-utils/uuidgen.c                   |  8 ++++----
+ 63 files changed, 162 insertions(+), 162 deletions(-)
+
+diff --git a/lib/blkdev.c b/lib/blkdev.c
+index c22853ddc..852c3bcfb 100644
+--- a/lib/blkdev.c
++++ b/lib/blkdev.c
+@@ -27,11 +27,11 @@
+ # define EBADFD 77		/* File descriptor in bad state */
+ #endif
+ 
+-#include "blkdev.h"
+-#include "c.h"
+-#include "linux_version.h"
+-#include "fileutils.h"
+-#include "nls.h"
++#include "include/blkdev.h"
++#include "include/c.h"
++#include "include/linux_version.h"
++#include "include/fileutils.h"
++#include "include/nls.h"
+ 
+ static long
+ blkdev_valid_offset (int fd, off_t offset) {
+diff --git a/lib/canonicalize.c b/lib/canonicalize.c
+index e101c5b7a..05ad92660 100644
+--- a/lib/canonicalize.c
++++ b/lib/canonicalize.c
+@@ -16,9 +16,9 @@
+ #include <sys/stat.h>
+ #include <sys/wait.h>
+ 
+-#include "canonicalize.h"
+-#include "pathnames.h"
+-#include "all-io.h"
++#include "include/canonicalize.h"
++#include "include/pathnames.h"
++#include "include/all-io.h"
+ 
+ /*
+  * Converts private "dm-N" names to "/dev/mapper/<name>"
+diff --git a/lib/color-names.c b/lib/color-names.c
+index 9b1505e4b..3e956312e 100644
+--- a/lib/color-names.c
++++ b/lib/color-names.c
+@@ -4,8 +4,8 @@
+  *
+  * Written by Karel Zak <kzak@redhat.com>
+  */
+-#include "c.h"
+-#include "color-names.h"
++#include "include/c.h"
++#include "include/color-names.h"
+ 
+ struct ul_color_name {
+ 	const char *name;
+diff --git a/lib/cpuset.c b/lib/cpuset.c
+index 2847db853..e8fd4a6d4 100644
+--- a/lib/cpuset.c
++++ b/lib/cpuset.c
+@@ -22,8 +22,8 @@
+ #include <ctype.h>
+ #include <sys/syscall.h>
+ 
+-#include "cpuset.h"
+-#include "c.h"
++#include "include/cpuset.h"
++#include "include/c.h"
+ 
+ static inline int val_to_char(int v)
+ {
+diff --git a/lib/crc32.c b/lib/crc32.c
+index 824693d01..2a213c431 100644
+--- a/lib/crc32.c
++++ b/lib/crc32.c
+@@ -40,7 +40,7 @@
+ 
+ #include <stdio.h>
+ 
+-#include "crc32.h"
++#include "include/crc32.h"
+ 
+ 
+ static const uint32_t crc32_tab[] = {
+diff --git a/lib/crc32c.c b/lib/crc32c.c
+index 49e7543f6..afcd4321b 100644
+--- a/lib/crc32c.c
++++ b/lib/crc32c.c
+@@ -10,7 +10,7 @@
+  *  code or tables extracted from it, as desired without restriction.
+  */
+ 
+-#include "crc32c.h"
++#include "include/crc32c.h"
+ 
+ static const uint32_t crc32Table[256] = {
+ 	0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L,
+diff --git a/lib/encode.c b/lib/encode.c
+index 10b5971c5..2367dab40 100644
+--- a/lib/encode.c
++++ b/lib/encode.c
+@@ -8,8 +8,8 @@
+  * This file may be redistributed under the terms of the
+  * GNU Lesser General Public License.
+  */
+-#include "c.h"
+-#include "encode.h"
++#include "include/c.h"
++#include "include/encode.h"
+ 
+ size_t ul_encode_to_utf8(int enc, unsigned char *dest, size_t len,
+ 			const unsigned char *src, size_t count)
+diff --git a/lib/env.c b/lib/env.c
+index 91c935cf6..02a1b6f0d 100644
+--- a/lib/env.c
++++ b/lib/env.c
+@@ -18,7 +18,7 @@
+ #include <unistd.h>
+ #include <sys/types.h>
+ 
+-#include "env.h"
++#include "include/env.h"
+ 
+ #ifndef HAVE_ENVIRON_DECL
+ extern char **environ;
+diff --git a/lib/fileutils.c b/lib/fileutils.c
+index 003f890f9..511a849e0 100644
+--- a/lib/fileutils.c
++++ b/lib/fileutils.c
+@@ -11,9 +11,9 @@
+ #include <sys/time.h>
+ #include <sys/resource.h>
+ 
+-#include "c.h"
+-#include "fileutils.h"
+-#include "pathnames.h"
++#include "include/c.h"
++#include "include/fileutils.h"
++#include "include/pathnames.h"
+ 
+ int mkstemp_cloexec(char *template)
+ {
+diff --git a/lib/idcache.c b/lib/idcache.c
+index 55502238d..625121178 100644
+--- a/lib/idcache.c
++++ b/lib/idcache.c
+@@ -9,8 +9,8 @@
+ #include <grp.h>
+ #include <sys/types.h>
+ 
+-#include "c.h"
+-#include "idcache.h"
++#include "include/c.h"
++#include "include/idcache.h"
+ 
+ struct identry *get_id(struct idcache *ic, unsigned long int id)
+ {
+diff --git a/lib/ismounted.c b/lib/ismounted.c
+index 9a20b2367..ec29d64f5 100644
+--- a/lib/ismounted.c
++++ b/lib/ismounted.c
+@@ -28,12 +28,12 @@
+ # endif
+ #endif
+ 
+-#include "pathnames.h"
+-#include "strutils.h"
+-#include "ismounted.h"
+-#include "c.h"
++#include "include/pathnames.h"
++#include "include/strutils.h"
++#include "include/ismounted.h"
++#include "include/c.h"
+ #ifdef __linux__
+-# include "loopdev.h"
++#include "include/loopdev.h"
+ #endif
+ 
+ 
+diff --git a/lib/linux_version.c b/lib/linux_version.c
+index 119869e5e..bea8bcf86 100644
+--- a/lib/linux_version.c
++++ b/lib/linux_version.c
+@@ -5,8 +5,8 @@
+ #include <stdio.h>
+ #include <sys/utsname.h>
+ 
+-#include "c.h"
+-#include "linux_version.h"
++#include "include/c.h"
++#include "include/linux_version.h"
+ 
+ int get_linux_version (void)
+ {
+diff --git a/lib/loopdev.c b/lib/loopdev.c
+index 7f299ebf3..ca2e35014 100644
+--- a/lib/loopdev.c
++++ b/lib/loopdev.c
+@@ -33,15 +33,15 @@
+ #include <inttypes.h>
+ #include <dirent.h>
+ 
+-#include "linux_version.h"
+-#include "c.h"
+-#include "sysfs.h"
+-#include "pathnames.h"
+-#include "loopdev.h"
+-#include "canonicalize.h"
+-#include "blkdev.h"
+-#include "debug.h"
+-#include "fileutils.h"
++#include "include/linux_version.h"
++#include "include/c.h"
++#include "include/sysfs.h"
++#include "include/pathnames.h"
++#include "include/loopdev.h"
++#include "include/canonicalize.h"
++#include "include/blkdev.h"
++#include "include/debug.h"
++#include "include/fileutils.h"
+ 
+ /*
+  * Debug stuff (based on include/debug.h)
+@@ -58,7 +58,7 @@ UL_DEBUG_DEFINE_MASKNAMES(loopdev) = UL_DEBUG_EMPTY_MASKNAMES;
+ #define ON_DBG(m, x)    __UL_DBG_CALL(loopdev, LOOPDEV_DEBUG_, m, x)
+ 
+ #define UL_DEBUG_CURRENT_MASK	UL_DEBUG_MASK(loopdev)
+-#include "debugobj.h"
++#include "include/debugobj.h"
+ 
+ static void loopdev_init_debug(void)
+ {
+diff --git a/lib/mangle.c b/lib/mangle.c
+index 1a3b89ae4..ebd9af5ac 100644
+--- a/lib/mangle.c
++++ b/lib/mangle.c
+@@ -11,8 +11,8 @@
+ #include <string.h>
+ #include <ctype.h>
+ 
+-#include "mangle.h"
+-#include "c.h"
++#include "include/mangle.h"
++#include "include/c.h"
+ 
+ #define isoctal(a)		(((a) & ~7) == '0')
+ 
+diff --git a/lib/match.c b/lib/match.c
+index a286a190c..b35302df2 100644
+--- a/lib/match.c
++++ b/lib/match.c
+@@ -7,7 +7,7 @@
+ 
+ #include <string.h>
+ 
+-#include "match.h"
++#include "include/match.h"
+ 
+ /*
+  * match_fstype:
+diff --git a/lib/mbsalign.c b/lib/mbsalign.c
+index e251202af..305bf8f83 100644
+--- a/lib/mbsalign.c
++++ b/lib/mbsalign.c
+@@ -23,10 +23,10 @@
+ #include <limits.h>
+ #include <ctype.h>
+ 
+-#include "c.h"
+-#include "mbsalign.h"
+-#include "strutils.h"
+-#include "widechar.h"
++#include "include/c.h"
++#include "include/mbsalign.h"
++#include "include/strutils.h"
++#include "include/widechar.h"
+ 
+ /*
+  * Counts number of cells in multibyte string. All control and
+diff --git a/lib/mbsedit.c b/lib/mbsedit.c
+index 8ce59016f..9d69e0820 100644
+--- a/lib/mbsedit.c
++++ b/lib/mbsedit.c
+@@ -12,8 +12,8 @@
+ #include <errno.h>
+ #include <stdio.h>
+ 
+-#include "mbsalign.h"
+-#include "mbsedit.h"
++#include "include/mbsalign.h"
++#include "include/mbsedit.h"
+ 
+ struct mbs_editor *mbs_new_edit(char *buf, size_t bufsz, size_t ncells)
+ {
+diff --git a/lib/md5.c b/lib/md5.c
+index 3765ab93e..5b1b3ccbb 100644
+--- a/lib/md5.c
++++ b/lib/md5.c
+@@ -16,7 +16,7 @@
+  */
+ #include <string.h>		/* for memcpy() */
+ 
+-#include "md5.h"
++#include "include/md5.h"
+ 
+ #if !defined(WORDS_BIGENDIAN)
+ # define byteReverse(buf, len)	/* Nothing */
+diff --git a/lib/pager.c b/lib/pager.c
+index 747521e13..3a3a9411c 100644
+--- a/lib/pager.c
++++ b/lib/pager.c
+@@ -14,11 +14,11 @@
+ #include <sys/wait.h>
+ #include <signal.h>
+ 
+-#include "c.h"
+-#include "xalloc.h"
+-#include "nls.h"
+-#include "ttyutils.h"
+-#include "pager.h"
++#include "include/c.h"
++#include "include/xalloc.h"
++#include "include/nls.h"
++#include "include/ttyutils.h"
++#include "include/pager.h"
+ 
+ #define NULL_DEVICE	"/dev/null"
+ 
+diff --git a/lib/path.c b/lib/path.c
+index 75fa85305..7b60be431 100644
+--- a/lib/path.c
++++ b/lib/path.c
+@@ -20,12 +20,12 @@
+ #include <inttypes.h>
+ #include <errno.h>
+ 
+-#include "c.h"
+-#include "fileutils.h"
+-#include "all-io.h"
+-#include "path.h"
+-#include "debug.h"
+-#include "strutils.h"
++#include "include/c.h"
++#include "include/fileutils.h"
++#include "include/all-io.h"
++#include "include/path.h"
++#include "include/debug.h"
++#include "include/strutils.h"
+ 
+ /*
+  * Debug stuff (based on include/debug.h)
+@@ -40,7 +40,7 @@ UL_DEBUG_DEFINE_MASKNAMES(ulpath) = UL_DEBUG_EMPTY_MASKNAMES;
+ #define ON_DBG(m, x)    __UL_DBG_CALL(ulpath, ULPATH_DEBUG_, m, x)
+ 
+ #define UL_DEBUG_CURRENT_MASK	UL_DEBUG_MASK(ulpath)
+-#include "debugobj.h"
++#include "include/debugobj.h"
+ 
+ void ul_path_init_debug(void)
+ {
+diff --git a/lib/procutils.c b/lib/procutils.c
+index bf689ab63..e97de926f 100644
+--- a/lib/procutils.c
++++ b/lib/procutils.c
+@@ -18,11 +18,11 @@
+ #include <dirent.h>
+ #include <ctype.h>
+ 
+-#include "procutils.h"
+-#include "statfs_magic.h"
+-#include "fileutils.h"
+-#include "all-io.h"
+-#include "c.h"
++#include "include/procutils.h"
++#include "include/statfs_magic.h"
++#include "include/fileutils.h"
++#include "include/all-io.h"
++#include "include/c.h"
+ 
+ /*
+  * @pid: process ID for which we want to obtain the threads group
+diff --git a/lib/pwdutils.c b/lib/pwdutils.c
+index d97020cb9..20750acc7 100644
+--- a/lib/pwdutils.c
++++ b/lib/pwdutils.c
+@@ -4,9 +4,9 @@
+  */
+ #include <stdlib.h>
+ 
+-#include "c.h"
+-#include "pwdutils.h"
+-#include "xalloc.h"
++#include "include/c.h"
++#include "include/pwdutils.h"
++#include "include/xalloc.h"
+ 
+ /* Returns allocated passwd and allocated pwdbuf to store passwd strings
+  * fields. In case of error returns NULL and set errno, for unknown user set
+diff --git a/lib/randutils.c b/lib/randutils.c
+index bf8193338..2f262b480 100644
+--- a/lib/randutils.c
++++ b/lib/randutils.c
+@@ -16,9 +16,9 @@
+ #ifdef __linux__
+ #include <sys/syscall.h>
+ #endif
+-#include "c.h"
+-#include "randutils.h"
+-#include "nls.h"
++#include "include/c.h"
++#include "include/randutils.h"
++#include "include/nls.h"
+ 
+ #ifdef HAVE_TLS
+ #define THREAD_LOCAL static __thread
+diff --git a/lib/setproctitle.c b/lib/setproctitle.c
+index 7168e4658..464c0ebde 100644
+--- a/lib/setproctitle.c
++++ b/lib/setproctitle.c
+@@ -8,7 +8,7 @@
+ #include <string.h>
+ #include <stdarg.h>
+ 
+-#include "setproctitle.h"
++#include "include/setproctitle.h"
+ 
+ #ifndef SPT_BUFSIZE
+ # define SPT_BUFSIZE     2048
+diff --git a/lib/sha1.c b/lib/sha1.c
+index 22d33b315..9abcb3c64 100644
+--- a/lib/sha1.c
++++ b/lib/sha1.c
+@@ -14,7 +14,7 @@
+ #include <string.h>
+ #include <stdint.h>
+ 
+-#include "sha1.h"
++#include "include/sha1.h"
+ 
+ #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
+ 
+diff --git a/lib/signames.c b/lib/signames.c
+index 064776a44..c47cdb8ea 100644
+--- a/lib/signames.c
++++ b/lib/signames.c
+@@ -14,9 +14,9 @@
+ #include <string.h>
+ #include <errno.h>
+ 
+-#include "c.h"
+-#include "strutils.h"
+-#include "signames.h"
++#include "include/c.h"
++#include "include/strutils.h"
++#include "include/signames.h"
+ 
+ static const struct ul_signal_name {
+ 	const char *name;
+diff --git a/lib/strutils.c b/lib/strutils.c
+index 304f31407..9761b5b7b 100644
+--- a/lib/strutils.c
++++ b/lib/strutils.c
+@@ -14,11 +14,11 @@
+ #include <string.h>
+ #include <assert.h>
+ 
+-#include "c.h"
+-#include "nls.h"
+-#include "strutils.h"
+-#include "bitops.h"
+-#include "pathnames.h"
++#include "include/c.h"
++#include "include/nls.h"
++#include "include/strutils.h"
++#include "include/bitops.h"
++#include "include/pathnames.h"
+ 
+ static int STRTOXX_EXIT_CODE = EXIT_FAILURE;
+ 
+diff --git a/lib/strv.c b/lib/strv.c
+index ddc2a0c5d..13b2e7875 100644
+--- a/lib/strv.c
++++ b/lib/strv.c
+@@ -19,8 +19,8 @@
+ #include <stdbool.h>
+ #include <assert.h>
+ 
+-#include "strutils.h"
+-#include "strv.h"
++#include "include/strutils.h"
++#include "include/strv.h"
+ 
+ void strv_clear(char **l) {
+         char **k;
+diff --git a/lib/sysfs.c b/lib/sysfs.c
+index 221b49083..ef19baf06 100644
+--- a/lib/sysfs.c
++++ b/lib/sysfs.c
+@@ -10,13 +10,13 @@
+ #include <sys/stat.h>
+ #include <unistd.h>
+ 
+-#include "c.h"
+-#include "pathnames.h"
+-#include "sysfs.h"
+-#include "fileutils.h"
+-#include "all-io.h"
+-#include "debug.h"
+-#include "strutils.h"
++#include "include/c.h"
++#include "include/pathnames.h"
++#include "include/sysfs.h"
++#include "include/fileutils.h"
++#include "include/all-io.h"
++#include "include/debug.h"
++#include "include/strutils.h"
+ 
+ static void sysfs_blkdev_deinit_path(struct path_cxt *pc);
+ static int  sysfs_blkdev_enoent_redirect(struct path_cxt *pc, const char *path, int *dirfd);
+@@ -34,7 +34,7 @@ UL_DEBUG_DEFINE_MASKNAMES(ulsysfs) = UL_DEBUG_EMPTY_MASKNAMES;
+ #define ON_DBG(m, x)    __UL_DBG_CALL(ulsysfs, ULSYSFS_DEBUG_, m, x)
+ 
+ #define UL_DEBUG_CURRENT_MASK	UL_DEBUG_MASK(ulsysfs)
+-#include "debugobj.h"
++#include "include/debugobj.h"
+ 
+ void ul_sysfs_init_debug(void)
+ {
+diff --git a/lib/timeutils.c b/lib/timeutils.c
+index 8b443cdfb..94d9f7070 100644
+--- a/lib/timeutils.c
++++ b/lib/timeutils.c
+@@ -25,10 +25,10 @@
+ #include <time.h>
+ #include <sys/time.h>
+ 
+-#include "c.h"
+-#include "nls.h"
+-#include "strutils.h"
+-#include "timeutils.h"
++#include "include/c.h"
++#include "include/nls.h"
++#include "include/strutils.h"
++#include "include/timeutils.h"
+ 
+ #define WHITESPACE " \t\n\r"
+ 
+diff --git a/lib/ttyutils.c b/lib/ttyutils.c
+index 706456503..8f39a54d0 100644
+--- a/lib/ttyutils.c
++++ b/lib/ttyutils.c
+@@ -7,8 +7,8 @@
+ #include <ctype.h>
+ #include <unistd.h>
+ 
+-#include "c.h"
+-#include "ttyutils.h"
++#include "include/c.h"
++#include "include/ttyutils.h"
+ 
+ 
+ static int get_env_int(const char *name)
+diff --git a/libblkid/src/blkidP.h b/libblkid/src/blkidP.h
+index 802a1b3a6..3ae4bd1dc 100644
+--- a/libblkid/src/blkidP.h
++++ b/libblkid/src/blkidP.h
+@@ -27,14 +27,14 @@
+ # define UUID_STR_LEN   37
+ #endif
+ 
+-#include "c.h"
+-#include "bitops.h"	/* $(top_srcdir)/include/ */
+-#include "blkdev.h"
++#include "include/c.h"
++#include "include/bitops.h"	/* $(top_srcdir)/include/ */
++#include "include/blkdev.h"
+ 
+-#include "debug.h"
++#include "include/debug.h"
+ #include "blkid.h"
+-#include "list.h"
+-#include "encode.h"
++#include "include/list.h"
++#include "include/encode.h"
+ 
+ /*
+  * This describes the attributes of a specific device.
+@@ -338,7 +338,7 @@ UL_DEBUG_DECLARE_MASK(libblkid);
+ #define ON_DBG(m, x)    __UL_DBG_CALL(libblkid, BLKID_DEBUG_, m, x)
+ 
+ #define UL_DEBUG_CURRENT_MASK	UL_DEBUG_MASK(libblkid)
+-#include "debugobj.h"
++#include "include/debugobj.h"
+ 
+ extern void blkid_debug_dump_dev(blkid_dev dev);
+ 
+diff --git a/libblkid/src/cache.c b/libblkid/src/cache.c
+index c199b919e..85d08a5be 100644
+--- a/libblkid/src/cache.c
++++ b/libblkid/src/cache.c
+@@ -22,7 +22,7 @@
+ #include <sys/stat.h>
+ #endif
+ #include "blkidP.h"
+-#include "env.h"
++#include "include/env.h"
+ 
+ /**
+  * SECTION:cache
+diff --git a/libblkid/src/config.c b/libblkid/src/config.c
+index f229b3e63..985f6bdec 100644
+--- a/libblkid/src/config.c
++++ b/libblkid/src/config.c
+@@ -24,7 +24,7 @@
+ #include <stdarg.h>
+ 
+ #include "blkidP.h"
+-#include "env.h"
++#include "include/env.h"
+ 
+ static int parse_evaluate(struct blkid_config *conf, char *s)
+ {
+diff --git a/libblkid/src/devname.c b/libblkid/src/devname.c
+index c58b784cc..42b34dca7 100644
+--- a/libblkid/src/devname.c
++++ b/libblkid/src/devname.c
+@@ -36,9 +36,9 @@
+ 
+ #include "blkidP.h"
+ 
+-#include "canonicalize.h"		/* $(top_srcdir)/include */
+-#include "pathnames.h"
+-#include "sysfs.h"
++#include "include/canonicalize.h"		/* $(top_srcdir)/include */
++#include "include/pathnames.h"
++#include "include/sysfs.h"
+ 
+ /*
+  * Find a dev struct in the cache by device name, if available.
+diff --git a/libblkid/src/devno.c b/libblkid/src/devno.c
+index 74a0d982e..53e54a34f 100644
+--- a/libblkid/src/devno.c
++++ b/libblkid/src/devno.c
+@@ -33,8 +33,8 @@
+ #include <inttypes.h>
+ 
+ #include "blkidP.h"
+-#include "pathnames.h"
+-#include "sysfs.h"
++#include "include/pathnames.h"
++#include "include/sysfs.h"
+ 
+ static char *blkid_strconcat(const char *a, const char *b, const char *c)
+ {
+diff --git a/libblkid/src/evaluate.c b/libblkid/src/evaluate.c
+index 710eac956..08a5f8b0b 100644
+--- a/libblkid/src/evaluate.c
++++ b/libblkid/src/evaluate.c
+@@ -22,9 +22,9 @@
+ #include <stdint.h>
+ #include <stdarg.h>
+ 
+-#include "pathnames.h"
+-#include "canonicalize.h"
+-#include "closestream.h"
++#include "include/pathnames.h"
++#include "include/canonicalize.h"
++#include "include/closestream.h"
+ 
+ #include "blkidP.h"
+ 
+diff --git a/libblkid/src/partitions/bsd.c b/libblkid/src/partitions/bsd.c
+index c74517334..73fe3a8bf 100644
+--- a/libblkid/src/partitions/bsd.c
++++ b/libblkid/src/partitions/bsd.c
+@@ -14,7 +14,7 @@
+ #include <stdint.h>
+ 
+ #include "partitions.h"
+-#include "pt-bsd.h"
++#include "include/pt-bsd.h"
+ 
+ /* Returns 'blkid_idmag' in 512-sectors */
+ #define BLKID_MAG_SECTOR(_mag)  (((_mag)->kboff / 2)  + ((_mag)->sboff >> 9))
+diff --git a/libblkid/src/partitions/dos.c b/libblkid/src/partitions/dos.c
+index 6e758ecaa..1c48cf6be 100644
+--- a/libblkid/src/partitions/dos.c
++++ b/libblkid/src/partitions/dos.c
+@@ -14,7 +14,7 @@
+ #include <stdint.h>
+ 
+ #include "partitions.h"
+-#include "superblocks/superblocks.h"
++#include "libblkid/src/superblocks/superblocks.h"
+ #include "aix.h"
+ 
+ /* see superblocks/vfat.c */
+diff --git a/libblkid/src/partitions/gpt.c b/libblkid/src/partitions/gpt.c
+index 889ff772c..a792e1d1b 100644
+--- a/libblkid/src/partitions/gpt.c
++++ b/libblkid/src/partitions/gpt.c
+@@ -21,7 +21,7 @@
+ #include <inttypes.h>
+ 
+ #include "partitions.h"
+-#include "crc32.h"
++#include "include/crc32.h"
+ 
+ #define GPT_PRIMARY_LBA	1
+ 
+diff --git a/libblkid/src/partitions/minix.c b/libblkid/src/partitions/minix.c
+index 43c9d9af1..c5f37011f 100644
+--- a/libblkid/src/partitions/minix.c
++++ b/libblkid/src/partitions/minix.c
+@@ -12,7 +12,7 @@
+ #include <stdint.h>
+ 
+ #include "partitions.h"
+-#include "minix.h"
++#include "include/minix.h"
+ 
+ static int probe_minix_pt(blkid_probe pr,
+ 		const struct blkid_idmag *mag __attribute__((__unused__)))
+diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c
+index e0a1ee170..4aa51164a 100644
+--- a/libblkid/src/partitions/partitions.c
++++ b/libblkid/src/partitions/partitions.c
+@@ -21,8 +21,8 @@
+ #include <stdarg.h>
+ 
+ #include "partitions.h"
+-#include "sysfs.h"
+-#include "strutils.h"
++#include "include/sysfs.h"
++#include "include/strutils.h"
+ 
+ /**
+  * SECTION: partitions
+diff --git a/libblkid/src/partitions/partitions.h b/libblkid/src/partitions/partitions.h
+index 4a718f4ea..6b8ec40cb 100644
+--- a/libblkid/src/partitions/partitions.h
++++ b/libblkid/src/partitions/partitions.h
+@@ -1,8 +1,8 @@
+ #ifndef BLKID_PARTITIONS_H
+ #define BLKID_PARTITIONS_H
+ 
+-#include "blkidP.h"
+-#include "pt-mbr.h"
++#include "libblkid/src/blkidP.h"
++#include "include/pt-mbr.h"
+ 
+ extern int blkid_partitions_get_flags(blkid_probe pr);
+ 
+diff --git a/libblkid/src/partitions/sgi.c b/libblkid/src/partitions/sgi.c
+index 99c0bf1c7..801ff368a 100644
+--- a/libblkid/src/partitions/sgi.c
++++ b/libblkid/src/partitions/sgi.c
+@@ -13,7 +13,7 @@
+ #include <stdint.h>
+ 
+ #include "partitions.h"
+-#include "pt-sgi.h"
++#include "include/pt-sgi.h"
+ 
+ static int probe_sgi_pt(blkid_probe pr,
+ 		const struct blkid_idmag *mag __attribute__((__unused__)))
+diff --git a/libblkid/src/partitions/sun.c b/libblkid/src/partitions/sun.c
+index 058a66372..24e6df011 100644
+--- a/libblkid/src/partitions/sun.c
++++ b/libblkid/src/partitions/sun.c
+@@ -12,7 +12,7 @@
+ #include <stdint.h>
+ #include <stddef.h>
+ 
+-#include "pt-sun.h"
++#include "include/pt-sun.h"
+ #include "partitions.h"
+ 
+ static int probe_sun_pt(blkid_probe pr,
+diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c
+index 8f5f59da3..3d63c6e79 100644
+--- a/libblkid/src/probe.c
++++ b/libblkid/src/probe.c
+@@ -106,10 +106,10 @@
+ #include <limits.h>
+ 
+ #include "blkidP.h"
+-#include "all-io.h"
+-#include "sysfs.h"
+-#include "strutils.h"
+-#include "list.h"
++#include "include/all-io.h"
++#include "include/sysfs.h"
++#include "include/strutils.h"
++#include "include/list.h"
+ 
+ /*
+  * All supported chains
+diff --git a/libblkid/src/save.c b/libblkid/src/save.c
+index bceaa1139..cae87bf21 100644
+--- a/libblkid/src/save.c
++++ b/libblkid/src/save.c
+@@ -22,8 +22,8 @@
+ #include <errno.h>
+ #endif
+ 
+-#include "closestream.h"
+-#include "fileutils.h"
++#include "include/closestream.h"
++#include "include/fileutils.h"
+ 
+ #include "blkidP.h"
+ 
+diff --git a/libblkid/src/superblocks/bluestore.c b/libblkid/src/superblocks/bluestore.c
+index 2ff1f3518..a516ba8d0 100644
+--- a/libblkid/src/superblocks/bluestore.c
++++ b/libblkid/src/superblocks/bluestore.c
+@@ -20,7 +20,7 @@
+ #include <inttypes.h>
+ #include <stddef.h>
+ 
+-#include "bitops.h"
++#include "include/bitops.h"
+ #include "superblocks.h"
+ 
+ #define BLUESTORE_MAGIC_L		22
+diff --git a/libblkid/src/superblocks/drbdmanage.c b/libblkid/src/superblocks/drbdmanage.c
+index d56c414c9..43537920e 100644
+--- a/libblkid/src/superblocks/drbdmanage.c
++++ b/libblkid/src/superblocks/drbdmanage.c
+@@ -20,7 +20,7 @@
+ #include <inttypes.h>
+ #include <stddef.h>
+ 
+-#include "bitops.h"
++#include "include/bitops.h"
+ #include "superblocks.h"
+ 
+ struct drbdmanage_hdr {
+diff --git a/libblkid/src/superblocks/hfs.c b/libblkid/src/superblocks/hfs.c
+index ebf90e49e..c507c7c02 100644
+--- a/libblkid/src/superblocks/hfs.c
++++ b/libblkid/src/superblocks/hfs.c
+@@ -12,7 +12,7 @@
+ #include <inttypes.h>
+ 
+ #include "superblocks.h"
+-#include "md5.h"
++#include "include/md5.h"
+ 
+ /* HFS / HFS+ */
+ struct hfs_finder_info {
+diff --git a/libblkid/src/superblocks/minix.c b/libblkid/src/superblocks/minix.c
+index b521efb2b..d1fb293cb 100644
+--- a/libblkid/src/superblocks/minix.c
++++ b/libblkid/src/superblocks/minix.c
+@@ -11,7 +11,7 @@
+ 
+ #include <string.h>
+ #include "superblocks.h"
+-#include "minix.h"
++#include "include/minix.h"
+ 
+ #define minix_swab16(doit, num)	((uint16_t) (doit ? swab16(num) : num))
+ #define minix_swab32(doit, num)	((uint32_t) (doit ? swab32(num) : num))
+diff --git a/libblkid/src/superblocks/mpool.c b/libblkid/src/superblocks/mpool.c
+index b27569ef3..702d86897 100644
+--- a/libblkid/src/superblocks/mpool.c
++++ b/libblkid/src/superblocks/mpool.c
+@@ -10,7 +10,7 @@
+ #include <unistd.h>
+ #include <string.h>
+ #include <stdint.h>
+-#include "crc32c.h"
++#include "include/crc32c.h"
+ #include "superblocks.h"
+ 
+ #define MAX_MPOOL_NAME_LEN 32
+diff --git a/libblkid/src/superblocks/nilfs.c b/libblkid/src/superblocks/nilfs.c
+index 423bd1ac4..8fa7200fa 100644
+--- a/libblkid/src/superblocks/nilfs.c
++++ b/libblkid/src/superblocks/nilfs.c
+@@ -8,7 +8,7 @@
+ #include <string.h>
+ 
+ #include "superblocks.h"
+-#include "crc32.h"
++#include "include/crc32.h"
+ 
+ struct nilfs_super_block {
+ 	uint32_t	s_rev_level;
+diff --git a/libblkid/src/superblocks/squashfs.c b/libblkid/src/superblocks/squashfs.c
+index 4db842493..b3171b45f 100644
+--- a/libblkid/src/superblocks/squashfs.c
++++ b/libblkid/src/superblocks/squashfs.c
+@@ -13,7 +13,7 @@
+ #include <string.h>
+ #include <stdint.h>
+ 
+-#include "bitops.h"	/* swab16() */
++#include "include/bitops.h"	/* swab16() */
+ #include "superblocks.h"
+ 
+ struct sqsh_super_block {
+diff --git a/libblkid/src/superblocks/stratis.c b/libblkid/src/superblocks/stratis.c
+index 7a889b2d4..b7b13817d 100644
+--- a/libblkid/src/superblocks/stratis.c
++++ b/libblkid/src/superblocks/stratis.c
+@@ -17,7 +17,7 @@
+ #include <inttypes.h>
+ 
+ #include "superblocks.h"
+-#include "crc32c.h"
++#include "include/crc32c.h"
+ 
+ struct stratis_sb {
+ 	uint32_t crc32;
+diff --git a/libblkid/src/superblocks/superblocks.h b/libblkid/src/superblocks/superblocks.h
+index 5ebe6bc43..867ede21f 100644
+--- a/libblkid/src/superblocks/superblocks.h
++++ b/libblkid/src/superblocks/superblocks.h
+@@ -7,7 +7,7 @@
+ #ifndef _BLKID_SUPERBLOCKS_H
+ #define _BLKID_SUPERBLOCKS_H
+ 
+-#include "blkidP.h"
++#include "libblkid/src/blkidP.h"
+ 
+ extern const struct blkid_idinfo cramfs_idinfo;
+ extern const struct blkid_idinfo swap_idinfo;
+diff --git a/libblkid/src/superblocks/vfat.c b/libblkid/src/superblocks/vfat.c
+index c7a3d080c..ffde68492 100644
+--- a/libblkid/src/superblocks/vfat.c
++++ b/libblkid/src/superblocks/vfat.c
+@@ -17,7 +17,7 @@
+ #include <stdint.h>
+ #include <inttypes.h>
+ 
+-#include "pt-mbr.h"
++#include "include/pt-mbr.h"
+ #include "superblocks.h"
+ 
+ /* Yucky misaligned values */
+diff --git a/libblkid/src/topology/sysfs.c b/libblkid/src/topology/sysfs.c
+index 745cd115a..ac02389c2 100644
+--- a/libblkid/src/topology/sysfs.c
++++ b/libblkid/src/topology/sysfs.c
+@@ -17,7 +17,7 @@
+ #include <unistd.h>
+ #include <errno.h>
+ 
+-#include "sysfs.h"
++#include "include/sysfs.h"
+ #include "topology.h"
+ 
+ /*
+diff --git a/libblkid/src/topology/topology.h b/libblkid/src/topology/topology.h
+index 3e46af9ac..cf0231119 100644
+--- a/libblkid/src/topology/topology.h
++++ b/libblkid/src/topology/topology.h
+@@ -1,7 +1,7 @@
+ #ifndef BLKID_TOPOLOGY_H
+ #define BLKID_TOPOLOGY_H
+ 
+-#include "blkidP.h"
++#include "libblkid/src/blkidP.h"
+ 
+ extern int blkid_topology_set_alignment_offset(blkid_probe pr, int val);
+ extern int blkid_topology_set_minimum_io_size(blkid_probe pr, unsigned long val);
+diff --git a/libblkid/src/verify.c b/libblkid/src/verify.c
+index 4bda3fd40..9f2e0ac8a 100644
+--- a/libblkid/src/verify.c
++++ b/libblkid/src/verify.c
+@@ -21,7 +21,7 @@
+ #endif
+ 
+ #include "blkidP.h"
+-#include "sysfs.h"
++#include "include/sysfs.h"
+ 
+ static void blkid_probe_to_tags(blkid_probe pr, blkid_dev dev)
+ {
+diff --git a/libuuid/src/gen_uuid.c b/libuuid/src/gen_uuid.c
+index 50039fc2e..7225c8ec5 100644
+--- a/libuuid/src/gen_uuid.c
++++ b/libuuid/src/gen_uuid.c
+@@ -81,14 +81,14 @@
+ #include <sys/syscall.h>
+ #endif
+ 
+-#include "all-io.h"
++#include "include/all-io.h"
+ #include "uuidP.h"
+ #include "uuidd.h"
+-#include "randutils.h"
+-#include "strutils.h"
+-#include "c.h"
+-#include "md5.h"
+-#include "sha1.h"
++#include "include/randutils.h"
++#include "include/strutils.h"
++#include "include/c.h"
++#include "include/md5.h"
++#include "include/sha1.h"
+ 
+ #ifdef HAVE_TLS
+ #define THREAD_LOCAL static __thread
+diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
+index dba3bb7d7..c57800b9d 100644
+--- a/misc-utils/blkid.c
++++ b/misc-utils/blkid.c
+@@ -30,21 +30,21 @@
+ #define BLKID_EXIT_OTHER	4	/* bad usage or other error */
+ #define BLKID_EXIT_AMBIVAL	8	/* ambivalent low-level probing detected */
+ 
+-#include <blkid.h>
++#include "blkid.h"
+ 
+-#include "ismounted.h"
++#include "include/ismounted.h"
+ 
+-#include "strutils.h"
++#include "include/strutils.h"
+ #define OPTUTILS_EXIT_CODE	BLKID_EXIT_OTHER	/* exclusive_option() */
+-#include "optutils.h"
++#include "include/optutils.h"
+ #define CLOSE_EXIT_CODE		BLKID_EXIT_OTHER	/* close_stdout() */
+-#include "closestream.h"
++#include "include/closestream.h"
+ 
+-#include "nls.h"
+-#include "ttyutils.h"
++#include "include/nls.h"
++#include "include/ttyutils.h"
+ 
+ #define XALLOC_EXIT_CODE    BLKID_EXIT_OTHER    /* x.*alloc(), xstrndup() */
+-#include "xalloc.h"
++#include "include/xalloc.h"
+ 
+ struct blkid_control {
+ 	int output;
+diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c
+index fa148abae..09b267978 100644
+--- a/misc-utils/uuidgen.c
++++ b/misc-utils/uuidgen.c
+@@ -13,10 +13,10 @@
+ #include <stdlib.h>
+ #include <getopt.h>
+ 
+-#include "uuid.h"
+-#include "nls.h"
+-#include "c.h"
+-#include "closestream.h"
++#include "libuuid/src/uuid.h"
++#include "include/nls.h"
++#include "include/c.h"
++#include "include/closestream.h"
+ 
+ static void __attribute__((__noreturn__)) usage(void)
+ {
+-- 
+2.25.1
+
diff --git a/third_party/util-linux/util-linux.bzl b/third_party/util-linux/util-linux.bzl
new file mode 100644
index 0000000..9e64243
--- /dev/null
+++ b/third_party/util-linux/util-linux.bzl
@@ -0,0 +1,188 @@
+#  Copyright 2020 The Monogon Project Authors.
+#
+#  SPDX-License-Identifier: Apache-2.0
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+load("@rules_cc//cc:defs.bzl", "cc_library")
+load("@dev_source_monogon//build/utils:template_file.bzl", "template_file")
+
+# These are only for the headers of libcommon, which is a private dependency of libblkid and
+# libuuid. Bazel doesn't support private dependencies and we want to avoid propagating these up
+# to all users of libblkid and libuuid, so manually inject them one level up.
+libcommon_hdrs_defines = [
+    "_GNU_SOURCE",
+    "HAVE_BYTESWAP_H",
+    "HAVE_CLOSE_RANGE",
+    "HAVE_CPU_SET_T",
+    "HAVE_DECL_CPU_ALLOC",
+    "HAVE_DIRFD",
+    "HAVE_ENDIAN_H",
+    "HAVE_ERR_H",
+    "HAVE_ERR",
+    "HAVE_ERRX",
+    "HAVE_LOFF_T",
+    "HAVE_MEMPCPY",
+    "HAVE_NANOSLEEP",
+    "HAVE_SETNS",
+    "HAVE_SRANDOM",
+    "HAVE_STDIO_EXT_H",
+    "HAVE_STRNDUP",
+    "HAVE_STRNLEN",
+    "HAVE_SENDFILE",
+    "HAVE_PIDFD_SEND_SIGNAL",
+    "HAVE_PIDFD_OPEN",
+    "HAVE_PATHS_H",
+    "HAVE_LINUX_VERSION_H",
+    "HAVE_OPENAT",
+    "HAVE_SYS_IOCTL_H",
+    "HAVE_SYS_SENDFILE_H",
+    "HAVE_SYS_SYSMACROS_H",
+    "HAVE_SYS_TTYDEFAULTS_H",
+    "HAVE_TIMEGM",
+    "HAVE_TIMER_CREATE",
+    "HAVE_UNSHARE",
+    "HAVE_WARN",
+    "HAVE_WARNX",
+    "HAVE_WIDECHAR",
+    "HAVE_FSYNC",
+    "HAVE___FPENDING",
+]
+
+template_file(
+    name = "blkid.h",
+    src = "libblkid/src/blkid.h.in",
+    substitutions = {
+        "@LIBBLKID_VERSION@": "0.0.0",
+        "@LIBBLKID_DATE@": "01.01.1970",
+    },
+)
+
+cc_library(
+    name = "common",
+    srcs = glob(["lib/*.h"]) + [
+        "lib/blkdev.c",
+        "lib/canonicalize.c",
+        "lib/crc32.c",
+        "lib/crc32c.c",
+        "lib/env.c",
+        "lib/idcache.c",
+        "lib/encode.c",
+        "lib/fileutils.c",
+        "lib/color-names.c",
+        "lib/mangle.c",
+        "lib/match.c",
+        "lib/mbsalign.c",
+        "lib/mbsedit.c",
+        "lib/md5.c",
+        "lib/pager.c",
+        "lib/procutils.c",
+        "lib/pwdutils.c",
+        "lib/randutils.c",
+        "lib/setproctitle.c",
+        "lib/strutils.c",
+        "lib/sysfs.c",
+        "lib/timeutils.c",
+        "lib/ttyutils.c",
+        "lib/strv.c",
+        "lib/path.c",
+        "lib/cpuset.c",
+        "lib/sha1.c",
+        "lib/signames.c",
+    ],
+    hdrs = glob(["include/*.h"]),
+    # Locale-related defines are intentionally missing as we don't want locale support
+    local_defines = libcommon_hdrs_defines + [
+        "HAVE_DECL_CPU_ALLOC",
+        "HAVE_ENVIRON_DECL",
+        "HAVE_ERRNO_H",
+        "HAVE_GETDTABLESIZE",
+        "HAVE_GETRANDOM",
+        "HAVE_GETRLIMIT",
+        "HAVE_LINUX_CDROM_H",
+        "HAVE_LINUX_FD_H",
+        "HAVE_JRAND48",
+        "HAVE_MKOSTEMP",
+        "HAVE_SYS_PRCTL_H",
+        "HAVE_MNTENT_H",
+        "HAVE_PRCTL",
+        "HAVE_SECURE_GETENV",
+        "HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC",
+        "HAVE_SYS_STAT_H",
+        "HAVE_SYS_TYPES_H",
+        "HAVE_EXPLICIT_BZERO",
+        "HAVE_UNISTD_H",
+        "HAVE_TLS",
+    ],
+    visibility = ["//visibility:private"],
+)
+
+cc_library(
+    name = "uuid",
+    srcs = [
+        "libuuid/src/clear.c",
+        "libuuid/src/compare.c",
+        "libuuid/src/copy.c",
+        "libuuid/src/gen_uuid.c",
+        "libuuid/src/isnull.c",
+        "libuuid/src/pack.c",
+        "libuuid/src/parse.c",
+        "libuuid/src/predefined.c",
+        "libuuid/src/unpack.c",
+        "libuuid/src/unparse.c",
+        "libuuid/src/uuidP.h",
+        "libuuid/src/uuid_time.c",
+    ],
+    hdrs = [
+        "libuuid/src/uuid.h",
+        "libuuid/src/uuidd.h",
+    ],
+    local_defines = libcommon_hdrs_defines + [
+        "HAVE_NET_IF_H",
+        "HAVE_NETINET_IN_H",
+        "HAVE_STDLIB_H",
+        "HAVE_SYS_FILE_H",
+        "HAVE_SYS_SOCKET_H",
+        "HAVE_SYS_SYSCALL_H",
+        "HAVE_SYS_TIME_H",
+        "HAVE_SYS_UN_H",
+        "HAVE_TLS",
+        "HAVE_UNISTD_H",
+    ],
+    visibility = ["//visibility:public"],
+    deps = [":common"],
+)
+
+cc_library(
+    name = "blkid",
+    srcs = glob([
+        "libblkid/src/**/*.c",
+        "libblkid/src/**/*.h",
+    ]),
+    hdrs = [":blkid.h"],
+    local_defines = libcommon_hdrs_defines + [
+        "LIBBLKID_VERSION=\\\"0.0.0\\\"",
+        "LIBBLKID_DATE=\\\"01.01.1970\\\"",
+        "HAVE_SYS_STAT_H",
+        "HAVE_ERRNO_H",
+        "HAVE_LINUX_CDROM_H",
+        "HAVE_POSIX_FADVISE",
+        "HAVE_STDLIB_H",
+        "HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC",
+        "HAVE_SYS_STAT_H",
+        "HAVE_SYS_TYPES_H",
+        "HAVE_UNISTD_H",
+    ],
+    visibility = ["//visibility:public"],
+    deps = ["//:common"],
+)
diff --git a/third_party/xfsprogs/BUILD b/third_party/xfsprogs/BUILD
index 51301b7..e69de29 100644
--- a/third_party/xfsprogs/BUILD
+++ b/third_party/xfsprogs/BUILD
@@ -1,86 +0,0 @@
-# TODO(leo): I have not been able to figure out a clever way of separating this
-# into multiple rules, particularly musl, which hardcodes sandbox paths into its
-# toolchain such that a different rule cannot consume it.
-#
-# For now, using a single massive genrule is the least annoying way to do this.
-# As soon as we build more than just mkfs.xfs, we should re-visit this.
-#
-# Some possibilities:
-#
-#  - Build the musl toolchain in the build container and use native rules
-#    for headers_install and util_linux (they should, in theory, generate
-#    well-defined artifacts that we can use in the build).
-#
-#    This would use Bazel's toolchain definition mechanism to consume the
-#    external toolchain, and would be compatible with the native C rules.
-#
-#    Maybe we can even build the external toolchain inside Bazel somehow?
-#
-#  - Write a custom rule that handles the toolchain.
-#
-#  - Converting *everything* to native rules is probably not an option due
-#    to how complex the third party build systems we touch are.
-
-genrule(
-    name = "mkfs.extfs",
-    srcs = [
-        "@xfsprogs//:all",
-        "@musl//:all",
-        "@util_linux//:all",
-        "@linux//:all",
-    ],
-    outs = [
-        "mkfs.xfs",
-    ],
-    cmd = """
-    MUSL=$$PWD/$(RULEDIR)/musl_prefix
-
-    echo "Compiling and installing musl..."
-    (
-        cd external/musl
-        ./configure --prefix=$$MUSL --syslibdir=$$MUSL/lib
-        make -j $$(nproc) install
-    ) > /dev/null
-
-    echo "Installing Linux kernel headers..."
-    (
-        cd external/linux
-        make headers_install ARCH=x86_64 INSTALL_HDR_PATH=$$MUSL
-    ) > /dev/null
-
-    echo "Compiling util_linux..."
-    (
-        cd external/util_linux
-        ./autogen.sh
-        ./configure \
-        CC="$$MUSL/bin/musl-gcc" \
-        --without-systemd \
-        --without-udev \
-        --without-btrfs \
-        --disable-pylibmount \
-        --without-tinfo \
-        --prefix=$$MUSL \
-        --disable-makeinstall-chown \
-        --disable-makeinstall-setuid \
-        --with-bashcompletiondir=$$MUSL/usr/share/bash-completion
-        make -j $$(nproc) libuuid.la libblkid.la
-        echo "Installing util_linux..."
-        cp -v .libs/* $$MUSL/lib/
-        mkdir -p $$MUSL/include/{uuid,blkid}
-        cp libuuid/src/uuid.h $$MUSL/include/uuid/
-        cp libblkid/src/blkid.h $$MUSL/include/blkid/
-    ) > /dev/null
-
-    echo "Compiling mkfs.xfs..."
-    (
-        cd external/xfsprogs
-        make configure
-        ./configure CC="$$MUSL/bin/musl-gcc" CFLAGS="-static" --prefix=$$MUSL
-        echo COMPILERING
-        make mkfs -j8
-    ) > /dev/null
-
-    cp external/xfsprogs/mkfs/mkfs.xfs $(RULEDIR)
-    """,
-    visibility = ["//visibility:public"],
-)
diff --git a/third_party/xfsprogs/cc_fix_spec.prototxt b/third_party/xfsprogs/cc_fix_spec.prototxt
new file mode 100644
index 0000000..ebc9ae0
--- /dev/null
+++ b/third_party/xfsprogs/cc_fix_spec.prototxt
@@ -0,0 +1,80 @@
+# proto-file: build/bazel_cc_fix/ccfixspec/ccfixspec.proto
+# proto-message: CCFixSpec
+
+# Note: As of 5.10 upstream doesn't build on any Linux distro I tried. You have to patch xfs.h to include its own headers
+# and not the system ones to get it to build. Revert this patch before running bazel_cc_fix as it interferes with the
+# auto-rewriting.
+
+# To regenerate the patch, run the following in the checked-out xfsprogs repo
+# make configure
+# ./configure
+# nice intercept-build make -j$(nproc) mkfs
+
+# And the following in the monorepo root
+# bazel run //build/bazel_cc_fix -- -workspace $path_to_repo -compilation_db $path_to_repo/compile_commands.json -spec third_party/xfsprogs/cc_fix_spec.prototxt
+
+# Resolve libuuid to our util_linux workspace
+replace {
+  type: SYSTEM
+  from: "uuid/uuid.h"
+  to: "libuuid/src/uuid.h"
+}
+
+# Resolve libblkid to our util_linux workspace
+replace {
+  type: SYSTEM
+  from: "blkid/blkid.h"
+  to: "blkid.h"
+}
+
+# Resolve libinih to our inih workspace
+replace {
+  type: SYSTEM
+  from: "ini.h"
+  to: "ini.h"
+}
+
+replace {
+  type: SYSTEM
+  from: "xfs/handle.h",
+  to: "include/handle.h",
+}
+
+# Force xfsprogs to use their own headers instead of the ones of the installed (!!) xfsprogs
+replace {
+  type: SYSTEM,
+  from: "xfs/xfs_fs.h",
+  to: "libxfs/xfs_fs.h"
+}
+replace {
+  type: SYSTEM,
+  from: "xfs/xfs_types.h",
+  to: "libxfs/xfs_types.h"
+}
+replace {
+  type: SYSTEM
+  from: "xfs/"
+  to: "include/"
+}
+
+# platform_defs.h is generated and cannot be placed in include/ as targets depend on random
+# things in there. Fix up all includes to instead point to the workspace root where it will be
+# generated.
+generated_file {
+  path: "include/platform_defs.h"
+}
+replace {
+  type: WORKSPACE
+  from: "include/platform_defs.h"
+  to: "platform_defs.h"
+}
+
+# Properly include CRC32 generated file which is also generated in the wrong place
+generated_file {
+  path: "libfrog/crc32table.h"
+}
+replace {
+  type: WORKSPACE
+  from: "libfrog/crc32table.h"
+  to: "crc32table.h"
+}
\ No newline at end of file
diff --git a/third_party/xfsprogs/external.bzl b/third_party/xfsprogs/external.bzl
index 7318df4..2bcb252 100644
--- a/third_party/xfsprogs/external.bzl
+++ b/third_party/xfsprogs/external.bzl
@@ -19,17 +19,15 @@
 def xfsprogs_external(name, version):
     sums = {
         "5.2.1": "6187f25f1744d1ecbb028b0ea210ad586d0f2dae24e258e4688c67740cc861ef",
+        "5.10.0": "e807ca9fd8f01e45c9ec8ffb3c123bdb7dfcfd8e05340520d2ff1ddbc3bd7c88",
     }
-    all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""
 
     http_archive(
         name = name,
-        build_file_content = all_content,
         patch_args = ["-p1"],
-        patches = [
-            "//third_party/xfsprogs/external:0001-Fixes-for-static-compilation.patch",
-        ],
+        patches = ["//third_party/xfsprogs/patches:bazel_cc_fix.patch"],
         sha256 = sums[version],
+        build_file = "@//third_party/xfsprogs:xfsprogs.bzl",
         strip_prefix = "xfsprogs-dev-" + version,
         urls = ["https://git.kernel.org/pub/scm/fs/xfs/xfsprogs-dev.git/snapshot/xfsprogs-dev-%s.tar.gz" % version],
     )
diff --git a/third_party/xfsprogs/external/0001-Fixes-for-static-compilation.patch b/third_party/xfsprogs/external/0001-Fixes-for-static-compilation.patch
deleted file mode 100644
index 14dd4cd..0000000
--- a/third_party/xfsprogs/external/0001-Fixes-for-static-compilation.patch
+++ /dev/null
@@ -1,64 +0,0 @@
-Copyright 2020 The Monogon Project Authors.
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-
-
-From 780a94ddc5c50bded264bfc0dbfffdb4182cdc51 Mon Sep 17 00:00:00 2001
-From: Lorenz Brun <lorenz@nexantic.com>
-Date: Mon, 9 Sep 2019 15:56:42 +0200
-Subject: [PATCH] Fixes for static compilation
-
----
- include/xfs.h | 6 +++---
- mkfs/Makefile | 2 +-
- 2 files changed, 4 insertions(+), 4 deletions(-)
-
-diff --git a/include/xfs.h b/include/xfs.h
-index f2f675df..73687a16 100644
---- a/include/xfs.h
-+++ b/include/xfs.h
-@@ -6,7 +6,7 @@
- #define __XFS_H__
- 
- #if defined(__linux__)
--#include <xfs/linux.h>
-+#include "linux.h"
- #else
- # error unknown platform... have fun porting!
- #endif
-@@ -34,7 +34,7 @@ extern int xfs_assert_largefile[sizeof(off_t)-8];
- #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
- #endif
- 
--#include <xfs/xfs_types.h>
--#include <xfs/xfs_fs.h>
-+#include "xfs_types.h"
-+#include "xfs_fs.h"
- 
- #endif	/* __XFS_H__ */
-diff --git a/mkfs/Makefile b/mkfs/Makefile
-index 31482b08..57fb355d 100644
---- a/mkfs/Makefile
-+++ b/mkfs/Makefile
-@@ -13,7 +13,7 @@ CFILES = proto.c xfs_mkfs.c
- LLDLIBS += $(LIBXFS) $(LIBXCMD) $(LIBFROG) $(LIBRT) $(LIBPTHREAD) $(LIBBLKID) \
- 	$(LIBUUID)
- LTDEPENDENCIES += $(LIBXFS) $(LIBXCMD) $(LIBFROG)
--LLDFLAGS = -static-libtool-libs
-+LLDFLAGS = -all-static
- 
- default: depend $(LTCOMMAND)
- 
--- 
-2.20.1
-
diff --git a/third_party/xfsprogs/external/BUILD b/third_party/xfsprogs/patches/BUILD
similarity index 100%
rename from third_party/xfsprogs/external/BUILD
rename to third_party/xfsprogs/patches/BUILD
diff --git a/third_party/xfsprogs/patches/bazel_cc_fix.patch b/third_party/xfsprogs/patches/bazel_cc_fix.patch
new file mode 100644
index 0000000..cc76d99
--- /dev/null
+++ b/third_party/xfsprogs/patches/bazel_cc_fix.patch
@@ -0,0 +1,1470 @@
+Copyright 2020 The Monogon Project Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+
+From e0c4f6a85bccab7d7e19d01bb790482e558d3f21 Mon Sep 17 00:00:00 2001
+From: Lorenz Brun <lorenz@nexantic.com>
+Date: Thu, 4 Mar 2021 16:59:13 +0100
+Subject: [PATCH] bazel_cc_fix patch
+
+---
+ include/libxfs.h            | 76 ++++++++++++++++++-------------------
+ include/linux.h             |  2 +-
+ include/xfs.h               |  8 ++--
+ include/xfs_inode.h         |  4 +-
+ libfrog/bitmap.c            |  4 +-
+ libfrog/bulkstat.c          |  2 +-
+ libfrog/convert.c           |  2 +-
+ libfrog/crc32.c             |  2 +-
+ libfrog/fsgeom.c            |  4 +-
+ libfrog/linux.c             |  4 +-
+ libfrog/list_sort.c         |  2 +-
+ libfrog/paths.c             |  2 +-
+ libfrog/projects.h          |  2 +-
+ libfrog/scrub.c             |  2 +-
+ libfrog/topology.c          |  8 ++--
+ libxcmd/command.c           |  4 +-
+ libxcmd/help.c              |  4 +-
+ libxcmd/input.c             |  2 +-
+ libxcmd/quit.c              |  4 +-
+ libxfs/cache.c              |  2 +-
+ libxfs/defer_item.c         |  6 +--
+ libxfs/init.c               |  8 ++--
+ libxfs/libxfs_priv.h        | 16 ++++----
+ libxfs/logitem.c            |  6 +--
+ libxfs/rdwr.c               |  8 ++--
+ libxfs/trans.c              |  8 ++--
+ libxfs/util.c               |  8 ++--
+ libxfs/xfs_ag.c             |  2 +-
+ libxfs/xfs_ag_resv.c        |  6 +--
+ libxfs/xfs_alloc.c          |  6 +--
+ libxfs/xfs_alloc_btree.c    |  6 +--
+ libxfs/xfs_attr.c           |  8 ++--
+ libxfs/xfs_attr_leaf.c      |  8 ++--
+ libxfs/xfs_attr_remote.c    |  8 ++--
+ libxfs/xfs_bmap.c           |  8 ++--
+ libxfs/xfs_bmap_btree.c     |  8 ++--
+ libxfs/xfs_btree.c          |  8 ++--
+ libxfs/xfs_btree_staging.c  |  8 ++--
+ libxfs/xfs_da_btree.c       |  8 ++--
+ libxfs/xfs_defer.c          |  8 ++--
+ libxfs/xfs_dir2.c           |  8 ++--
+ libxfs/xfs_dir2_block.c     |  8 ++--
+ libxfs/xfs_dir2_data.c      |  6 +--
+ libxfs/xfs_dir2_leaf.c      |  8 ++--
+ libxfs/xfs_dir2_node.c      |  8 ++--
+ libxfs/xfs_dir2_sf.c        |  8 ++--
+ libxfs/xfs_dquot_buf.c      |  6 +--
+ libxfs/xfs_ialloc.c         |  8 ++--
+ libxfs/xfs_ialloc_btree.c   |  6 +--
+ libxfs/xfs_iext_tree.c      |  6 +--
+ libxfs/xfs_inode_buf.c      |  6 +--
+ libxfs/xfs_inode_fork.c     |  8 ++--
+ libxfs/xfs_log_rlimit.c     |  2 +-
+ libxfs/xfs_refcount.c       |  6 +--
+ libxfs/xfs_refcount_btree.c |  6 +--
+ libxfs/xfs_rmap.c           |  8 ++--
+ libxfs/xfs_rmap_btree.c     |  6 +--
+ libxfs/xfs_rtbitmap.c       |  6 +--
+ libxfs/xfs_sb.c             |  6 +--
+ libxfs/xfs_symlink_remote.c |  6 +--
+ libxfs/xfs_trans_inode.c    |  6 +--
+ libxfs/xfs_trans_resv.c     |  6 +--
+ libxfs/xfs_types.c          |  2 +-
+ mkfs/proto.c                |  2 +-
+ mkfs/xfs_mkfs.c             |  8 ++--
+ 65 files changed, 224 insertions(+), 224 deletions(-)
+
+diff --git a/include/libxfs.h b/include/libxfs.h
+index ad077eaa..d17e7424 100644
+--- a/include/libxfs.h
++++ b/include/libxfs.h
+@@ -7,7 +7,7 @@
+ #ifndef __LIBXFS_H__
+ #define __LIBXFS_H__
+ 
+-#include "libxfs_api_defs.h"
++#include "libxfs/libxfs_api_defs.h"
+ #include "platform_defs.h"
+ #include "xfs.h"
+ 
+@@ -19,15 +19,15 @@
+ #include "libfrog/radix-tree.h"
+ #include "atomic.h"
+ 
+-#include "xfs_types.h"
+-#include "xfs_fs.h"
++#include "libxfs/xfs_types.h"
++#include "libxfs/xfs_fs.h"
+ #include "xfs_arch.h"
+ 
+-#include "xfs_shared.h"
+-#include "xfs_format.h"
+-#include "xfs_log_format.h"
+-#include "xfs_quota_defs.h"
+-#include "xfs_trans_resv.h"
++#include "libxfs/xfs_shared.h"
++#include "libxfs/xfs_format.h"
++#include "libxfs/xfs_log_format.h"
++#include "libxfs/xfs_quota_defs.h"
++#include "libxfs/xfs_trans_resv.h"
+ 
+ 
+ /* CRC stuff, buffer API dependent on it */
+@@ -36,7 +36,7 @@ extern uint32_t crc32c_le(uint32_t crc, unsigned char const *p, size_t len);
+ 
+ /* fake up kernel's iomap, (not) used in xfs_bmap.[ch] */
+ struct iomap;
+-#include "xfs_cksum.h"
++#include "libxfs/xfs_cksum.h"
+ 
+ #define __round_mask(x, y) ((__typeof__(x))((y)-1))
+ #define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1)
+@@ -46,35 +46,35 @@ struct iomap;
+  * This mirrors the kernel include for xfs_buf.h - it's implicitly included in
+  * every files via a similar include in the kernel xfs_linux.h.
+  */
+-#include "libxfs_io.h"
++#include "libxfs/libxfs_io.h"
+ 
+-#include "xfs_bit.h"
+-#include "xfs_sb.h"
++#include "libxfs/xfs_bit.h"
++#include "libxfs/xfs_sb.h"
+ #include "xfs_mount.h"
+-#include "xfs_defer.h"
+-#include "xfs_errortag.h"
+-#include "xfs_da_format.h"
+-#include "xfs_da_btree.h"
++#include "libxfs/xfs_defer.h"
++#include "libxfs/xfs_errortag.h"
++#include "libxfs/xfs_da_format.h"
++#include "libxfs/xfs_da_btree.h"
+ #include "xfs_inode.h"
+-#include "xfs_dir2.h"
+-#include "xfs_dir2_priv.h"
+-#include "xfs_bmap_btree.h"
+-#include "xfs_alloc_btree.h"
+-#include "xfs_ialloc_btree.h"
+-#include "xfs_attr_sf.h"
+-#include "xfs_inode_fork.h"
+-#include "xfs_inode_buf.h"
+-#include "xfs_alloc.h"
+-#include "xfs_btree.h"
+-#include "xfs_bmap.h"
++#include "libxfs/xfs_dir2.h"
++#include "libxfs/xfs_dir2_priv.h"
++#include "libxfs/xfs_bmap_btree.h"
++#include "libxfs/xfs_alloc_btree.h"
++#include "libxfs/xfs_ialloc_btree.h"
++#include "libxfs/xfs_attr_sf.h"
++#include "libxfs/xfs_inode_fork.h"
++#include "libxfs/xfs_inode_buf.h"
++#include "libxfs/xfs_alloc.h"
++#include "libxfs/xfs_btree.h"
++#include "libxfs/xfs_bmap.h"
+ #include "xfs_trace.h"
+ #include "xfs_trans.h"
+-#include "xfs_ag.h"
+-#include "xfs_rmap_btree.h"
+-#include "xfs_rmap.h"
+-#include "xfs_refcount_btree.h"
+-#include "xfs_refcount.h"
+-#include "xfs_btree_staging.h"
++#include "libxfs/xfs_ag.h"
++#include "libxfs/xfs_rmap_btree.h"
++#include "libxfs/xfs_rmap.h"
++#include "libxfs/xfs_refcount_btree.h"
++#include "libxfs/xfs_refcount.h"
++#include "libxfs/xfs_btree_staging.h"
+ 
+ #ifndef ARRAY_SIZE
+ #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+@@ -165,11 +165,11 @@ extern void cmn_err(int, char *, ...);
+ enum ce { CE_DEBUG, CE_CONT, CE_NOTE, CE_WARN, CE_ALERT, CE_PANIC };
+ #endif
+ 
+-#include "xfs_ialloc.h"
++#include "libxfs/xfs_ialloc.h"
+ 
+-#include "xfs_attr_leaf.h"
+-#include "xfs_attr_remote.h"
+-#include "xfs_trans_space.h"
++#include "libxfs/xfs_attr_leaf.h"
++#include "libxfs/xfs_attr_remote.h"
++#include "libxfs/xfs_trans_space.h"
+ 
+ #define XFS_INOBT_IS_FREE_DISK(rp,i)		\
+ 			((be64_to_cpu((rp)->ir_free) & XFS_INOBT_MASK(i)) != 0)
+@@ -212,6 +212,6 @@ libxfs_bmbt_disk_get_all(
+ int libxfs_rtfree_extent(struct xfs_trans *, xfs_rtblock_t, xfs_extlen_t);
+ bool libxfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
+ 
+-#include "xfs_attr.h"
++#include "libxfs/xfs_attr.h"
+ 
+ #endif	/* __LIBXFS_H__ */
+diff --git a/include/linux.h b/include/linux.h
+index 03b3278b..b1e03f19 100644
+--- a/include/linux.h
++++ b/include/linux.h
+@@ -5,7 +5,7 @@
+ #ifndef __XFS_LINUX_H__
+ #define __XFS_LINUX_H__
+ 
+-#include <uuid/uuid.h>
++#include "libuuid/src/uuid.h"
+ #include <sys/vfs.h>
+ #include <sys/ioctl.h>
+ #include <sys/param.h>
+diff --git a/include/xfs.h b/include/xfs.h
+index e97158c8..95d63036 100644
+--- a/include/xfs.h
++++ b/include/xfs.h
+@@ -6,7 +6,7 @@
+ #define __XFS_H__
+ 
+ #if defined(__linux__)
+-#include <xfs/linux.h>
++#include "include/linux.h"
+ #else
+ # error unknown platform... have fun porting!
+ #endif
+@@ -40,9 +40,9 @@ extern int xfs_assert_largefile[sizeof(off_t)-8];
+ 
+ #define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
+ 
+-#include <xfs/xfs_types.h>
++#include "libxfs/xfs_types.h"
+ /* Include deprecated/compat pre-vfs xfs-specific symbols */
+-#include <xfs/xfs_fs_compat.h>
+-#include <xfs/xfs_fs.h>
++#include "include/xfs_fs_compat.h"
++#include "libxfs/xfs_fs.h"
+ 
+ #endif	/* __XFS_H__ */
+diff --git a/include/xfs_inode.h b/include/xfs_inode.h
+index 742aebc8..b24e9aa9 100644
+--- a/include/xfs_inode.h
++++ b/include/xfs_inode.h
+@@ -8,8 +8,8 @@
+ #define __XFS_INODE_H__
+ 
+ /* These match kernel side includes */
+-#include "xfs_inode_buf.h"
+-#include "xfs_inode_fork.h"
++#include "libxfs/xfs_inode_buf.h"
++#include "libxfs/xfs_inode_fork.h"
+ 
+ struct xfs_trans;
+ struct xfs_mount;
+diff --git a/libfrog/bitmap.c b/libfrog/bitmap.c
+index 5af5ab8d..25cd291c 100644
+--- a/libfrog/bitmap.c
++++ b/libfrog/bitmap.c
+@@ -3,14 +3,14 @@
+  * Copyright (C) 2018 Oracle.  All Rights Reserved.
+  * Author: Darrick J. Wong <darrick.wong@oracle.com>
+  */
+-#include "xfs.h"
++#include "include/xfs.h"
+ #include <stdint.h>
+ #include <stdlib.h>
+ #include <assert.h>
+ #include <pthread.h>
+ #include "platform_defs.h"
+ #include "avl64.h"
+-#include "list.h"
++#include "include/list.h"
+ #include "bitmap.h"
+ 
+ /*
+diff --git a/libfrog/bulkstat.c b/libfrog/bulkstat.c
+index 195f6ea0..f347b266 100644
+--- a/libfrog/bulkstat.c
++++ b/libfrog/bulkstat.c
+@@ -5,7 +5,7 @@
+  */
+ #include <string.h>
+ #include <strings.h>
+-#include "xfs.h"
++#include "include/xfs.h"
+ #include "fsgeom.h"
+ #include "bulkstat.h"
+ 
+diff --git a/libfrog/convert.c b/libfrog/convert.c
+index 0ceeb389..46fd3ba0 100644
+--- a/libfrog/convert.c
++++ b/libfrog/convert.c
+@@ -4,7 +4,7 @@
+  * All Rights Reserved.
+  */
+ #include "platform_defs.h"
+-#include "input.h"
++#include "include/input.h"
+ #include <ctype.h>
+ #include <stdbool.h>
+ 
+diff --git a/libfrog/crc32.c b/libfrog/crc32.c
+index 526ce950..c1ef084f 100644
+--- a/libfrog/crc32.c
++++ b/libfrog/crc32.c
+@@ -34,7 +34,7 @@
+ #include <sys/time.h>
+ #include "platform_defs.h"
+ /* For endian conversion routines */
+-#include "xfs_arch.h"
++#include "include/xfs_arch.h"
+ #include "crc32defs.h"
+ #include "crc32c.h"
+ 
+diff --git a/libfrog/fsgeom.c b/libfrog/fsgeom.c
+index 14507668..eb344ba4 100644
+--- a/libfrog/fsgeom.c
++++ b/libfrog/fsgeom.c
+@@ -3,8 +3,8 @@
+  * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
+  */
+ #include "platform_defs.h"
+-#include "xfs.h"
+-#include "bitops.h"
++#include "include/xfs.h"
++#include "include/bitops.h"
+ #include "fsgeom.h"
+ #include "util.h"
+ 
+diff --git a/libfrog/linux.c b/libfrog/linux.c
+index a45d99ab..3c906342 100644
+--- a/libfrog/linux.c
++++ b/libfrog/linux.c
+@@ -10,8 +10,8 @@
+ #include <sys/sysinfo.h>
+ 
+ #include "platform_defs.h"
+-#include "xfs.h"
+-#include "init.h"
++#include "include/xfs.h"
++#include "libxfs/init.h"
+ 
+ extern char *progname;
+ static int max_block_alignment;
+diff --git a/libfrog/list_sort.c b/libfrog/list_sort.c
+index b77eece5..e6ad2266 100644
+--- a/libfrog/list_sort.c
++++ b/libfrog/list_sort.c
+@@ -1,7 +1,7 @@
+ /* List sorting code from Linux::lib/list_sort.c. */
+ #include <stdlib.h>
+ #include <string.h>
+-#include "list.h"
++#include "include/list.h"
+ 
+ #define unlikely(x)	(x)
+ #define MAX_LIST_LENGTH_BITS 20
+diff --git a/libfrog/paths.c b/libfrog/paths.c
+index d6793764..2fa74eac 100644
+--- a/libfrog/paths.c
++++ b/libfrog/paths.c
+@@ -13,7 +13,7 @@
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include "paths.h"
+-#include "input.h"
++#include "include/input.h"
+ #include "projects.h"
+ #include <limits.h>
+ 
+diff --git a/libfrog/projects.h b/libfrog/projects.h
+index 77919474..e88a39c1 100644
+--- a/libfrog/projects.h
++++ b/libfrog/projects.h
+@@ -7,7 +7,7 @@
+ #define __LIBFROG_PROJECTS_H__
+ 
+ #include "platform_defs.h"
+-#include "xfs.h"
++#include "include/xfs.h"
+ 
+ extern int setprojid(const char *__name, int __fd, prid_t __id);
+ extern int getprojid(const char *__name, int __fd, prid_t *__id);
+diff --git a/libfrog/scrub.c b/libfrog/scrub.c
+index d900bf2a..0d58114c 100644
+--- a/libfrog/scrub.c
++++ b/libfrog/scrub.c
+@@ -3,7 +3,7 @@
+  * Copyright (c) 2019 Oracle, Inc.
+  * All Rights Reserved.
+  */
+-#include "xfs.h"
++#include "include/xfs.h"
+ #include "fsgeom.h"
+ #include "scrub.h"
+ 
+diff --git a/libfrog/topology.c b/libfrog/topology.c
+index b1b470c9..b44e5b69 100644
+--- a/libfrog/topology.c
++++ b/libfrog/topology.c
+@@ -4,12 +4,12 @@
+  * All Rights Reserved.
+  */
+ 
+-#include "libxfs.h"
+-#include "libxcmd.h"
++#include "include/libxfs.h"
++#include "include/libxcmd.h"
+ #ifdef ENABLE_BLKID
+-#  include <blkid/blkid.h>
++#include "blkid.h"
+ #endif /* ENABLE_BLKID */
+-#include "xfs_multidisk.h"
++#include "include/xfs_multidisk.h"
+ #include "topology.h"
+ #include "platform.h"
+ 
+diff --git a/libxcmd/command.c b/libxcmd/command.c
+index a76d1515..d3ae840a 100644
+--- a/libxcmd/command.c
++++ b/libxcmd/command.c
+@@ -5,8 +5,8 @@
+  */
+ 
+ #include "platform_defs.h"
+-#include "command.h"
+-#include "input.h"
++#include "include/command.h"
++#include "include/input.h"
+ 
+ cmdinfo_t	*cmdtab;
+ int		ncmds;
+diff --git a/libxcmd/help.c b/libxcmd/help.c
+index b7e02073..36cb59ef 100644
+--- a/libxcmd/help.c
++++ b/libxcmd/help.c
+@@ -5,8 +5,8 @@
+  */
+ 
+ #include "platform_defs.h"
+-#include "command.h"
+-#include "../quota/init.h"
++#include "include/command.h"
++#include "quota/init.h"
+ 
+ static cmdinfo_t help_cmd;
+ static void help_onecmd(const char *cmd, const cmdinfo_t *ct);
+diff --git a/libxcmd/input.c b/libxcmd/input.c
+index e3fa626a..94907182 100644
+--- a/libxcmd/input.c
++++ b/libxcmd/input.c
+@@ -5,7 +5,7 @@
+  */
+ 
+ #include "platform_defs.h"
+-#include "input.h"
++#include "include/input.h"
+ #include <ctype.h>
+ #include <stdbool.h>
+ 
+diff --git a/libxcmd/quit.c b/libxcmd/quit.c
+index 7c2d04f8..de618392 100644
+--- a/libxcmd/quit.c
++++ b/libxcmd/quit.c
+@@ -5,8 +5,8 @@
+  */
+ 
+ #include "platform_defs.h"
+-#include "command.h"
+-#include "../quota/init.h"
++#include "include/command.h"
++#include "quota/init.h"
+ 
+ static cmdinfo_t quit_cmd;
+ 
+diff --git a/libxfs/cache.c b/libxfs/cache.c
+index 139c7c1b..f2e955b5 100644
+--- a/libxfs/cache.c
++++ b/libxfs/cache.c
+@@ -15,7 +15,7 @@
+ #include "xfs_shared.h"
+ #include "xfs_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_bit.h"
+ 
+ #define CACHE_DEBUG 1
+diff --git a/libxfs/defer_item.c b/libxfs/defer_item.c
+index b18182e9..4f31d224 100644
+--- a/libxfs/defer_item.c
++++ b/libxfs/defer_item.c
+@@ -11,15 +11,15 @@
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+ #include "xfs_sb.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_defer.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trans.h"
+ #include "xfs_bmap.h"
+ #include "xfs_alloc.h"
+ #include "xfs_rmap.h"
+ #include "xfs_refcount.h"
+ #include "xfs_bmap.h"
+-#include "xfs_inode.h"
++#include "include/xfs_inode.h"
+ 
+ /* Dummy defer item ops, since we don't do logging. */
+ 
+diff --git a/libxfs/init.c b/libxfs/init.c
+index bd176b50..94024e9c 100644
+--- a/libxfs/init.c
++++ b/libxfs/init.c
+@@ -13,17 +13,17 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_defer.h"
+ #include "xfs_inode_buf.h"
+ #include "xfs_inode_fork.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_rmap_btree.h"
+ #include "xfs_refcount_btree.h"
+ #include "libfrog/platform.h"
+ 
+-#include "libxfs.h"		/* for now */
++#include "include/libxfs.h"		/* for now */
+ 
+ char *progname = "libxfs";	/* default, changed by each tool */
+ 
+diff --git a/libxfs/libxfs_priv.h b/libxfs/libxfs_priv.h
+index e92269f0..ec9b0da2 100644
+--- a/libxfs/libxfs_priv.h
++++ b/libxfs/libxfs_priv.h
+@@ -39,18 +39,18 @@
+ 
+ #include "libxfs_api_defs.h"
+ #include "platform_defs.h"
+-#include "xfs.h"
++#include "include/xfs.h"
+ 
+-#include "list.h"
+-#include "hlist.h"
+-#include "cache.h"
+-#include "bitops.h"
+-#include "kmem.h"
++#include "include/list.h"
++#include "include/hlist.h"
++#include "include/cache.h"
++#include "include/bitops.h"
++#include "include/kmem.h"
+ #include "libfrog/radix-tree.h"
+-#include "atomic.h"
++#include "include/atomic.h"
+ 
+ #include "xfs_types.h"
+-#include "xfs_arch.h"
++#include "include/xfs_arch.h"
+ 
+ #include "xfs_fs.h"
+ #include "libfrog/crc32c.h"
+diff --git a/libxfs/logitem.c b/libxfs/logitem.c
+index 43a98f28..357bf4e5 100644
+--- a/libxfs/logitem.c
++++ b/libxfs/logitem.c
+@@ -10,11 +10,11 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_inode_buf.h"
+ #include "xfs_inode_fork.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ 
+ kmem_zone_t	*xfs_buf_item_zone;
+ kmem_zone_t	*xfs_ili_zone;		/* inode log item zone */
+diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c
+index 2e038401..28000567 100644
+--- a/libxfs/rdwr.c
++++ b/libxfs/rdwr.c
+@@ -12,14 +12,14 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_inode_buf.h"
+ #include "xfs_inode_fork.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "libfrog/platform.h"
+ 
+-#include "libxfs.h"
++#include "include/libxfs.h"
+ 
+ static void libxfs_brelse(struct cache_node *node);
+ 
+diff --git a/libxfs/trans.c b/libxfs/trans.c
+index bc4af26c..45bcc8ce 100644
+--- a/libxfs/trans.c
++++ b/libxfs/trans.c
+@@ -11,14 +11,14 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_inode_buf.h"
+ #include "xfs_inode_fork.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_sb.h"
+ #include "xfs_defer.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ 
+ static void xfs_trans_free_items(struct xfs_trans *tp);
+ STATIC struct xfs_trans *xfs_trans_dup(struct xfs_trans *tp);
+diff --git a/libxfs/util.c b/libxfs/util.c
+index 252cf91e..810809e8 100644
+--- a/libxfs/util.c
++++ b/libxfs/util.c
+@@ -5,7 +5,7 @@
+  */
+ 
+ #include "libxfs_priv.h"
+-#include "libxfs.h"
++#include "include/libxfs.h"
+ #include "libxfs_io.h"
+ #include "init.h"
+ #include "xfs_fs.h"
+@@ -13,12 +13,12 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_defer.h"
+ #include "xfs_inode_buf.h"
+ #include "xfs_inode_fork.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_bmap.h"
+ #include "xfs_bmap_btree.h"
+ #include "xfs_trans_space.h"
+diff --git a/libxfs/xfs_ag.c b/libxfs/xfs_ag.c
+index af8a0afd..30cc25ed 100644
+--- a/libxfs/xfs_ag.c
++++ b/libxfs/xfs_ag.c
+@@ -12,7 +12,7 @@
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+ #include "xfs_sb.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_btree.h"
+ #include "xfs_alloc_btree.h"
+ #include "xfs_rmap_btree.h"
+diff --git a/libxfs/xfs_ag_resv.c b/libxfs/xfs_ag_resv.c
+index 530455a5..ab3a031c 100644
+--- a/libxfs/xfs_ag_resv.c
++++ b/libxfs/xfs_ag_resv.c
+@@ -9,11 +9,11 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_alloc.h"
+ #include "xfs_errortag.h"
+-#include "xfs_trace.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trace.h"
++#include "include/xfs_trans.h"
+ #include "xfs_rmap_btree.h"
+ #include "xfs_btree.h"
+ #include "xfs_refcount_btree.h"
+diff --git a/libxfs/xfs_alloc.c b/libxfs/xfs_alloc.c
+index 92f61fae..9e426889 100644
+--- a/libxfs/xfs_alloc.c
++++ b/libxfs/xfs_alloc.c
+@@ -11,15 +11,15 @@
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+ #include "xfs_sb.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_defer.h"
+ #include "xfs_btree.h"
+ #include "xfs_rmap.h"
+ #include "xfs_alloc_btree.h"
+ #include "xfs_alloc.h"
+ #include "xfs_errortag.h"
+-#include "xfs_trace.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trace.h"
++#include "include/xfs_trans.h"
+ #include "xfs_ag_resv.h"
+ #include "xfs_bmap.h"
+ 
+diff --git a/libxfs/xfs_alloc_btree.c b/libxfs/xfs_alloc_btree.c
+index 2198bbff..1a7a6f1e 100644
+--- a/libxfs/xfs_alloc_btree.c
++++ b/libxfs/xfs_alloc_btree.c
+@@ -10,13 +10,13 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_sb.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_btree.h"
+ #include "xfs_btree_staging.h"
+ #include "xfs_alloc_btree.h"
+ #include "xfs_alloc.h"
+-#include "xfs_trace.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trace.h"
++#include "include/xfs_trans.h"
+ 
+ 
+ STATIC struct xfs_btree_cur *
+diff --git a/libxfs/xfs_attr.c b/libxfs/xfs_attr.c
+index 0c75f46f..218d1efd 100644
+--- a/libxfs/xfs_attr.c
++++ b/libxfs/xfs_attr.c
+@@ -9,13 +9,13 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_defer.h"
+ #include "xfs_da_format.h"
+ #include "xfs_da_btree.h"
+ #include "xfs_attr_sf.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_bmap.h"
+ #include "xfs_bmap_btree.h"
+ #include "xfs_attr.h"
+@@ -23,7 +23,7 @@
+ #include "xfs_attr_remote.h"
+ #include "xfs_quota_defs.h"
+ #include "xfs_trans_space.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ 
+ /*
+  * xfs_attr.c
+diff --git a/libxfs/xfs_attr_leaf.c b/libxfs/xfs_attr_leaf.c
+index a59660f2..089df469 100644
+--- a/libxfs/xfs_attr_leaf.c
++++ b/libxfs/xfs_attr_leaf.c
+@@ -11,18 +11,18 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_sb.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_da_format.h"
+ #include "xfs_da_btree.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_bmap_btree.h"
+ #include "xfs_bmap.h"
+ #include "xfs_attr_sf.h"
+ #include "xfs_attr_remote.h"
+ #include "xfs_attr.h"
+ #include "xfs_attr_leaf.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ #include "xfs_dir2.h"
+ 
+ 
+diff --git a/libxfs/xfs_attr_remote.c b/libxfs/xfs_attr_remote.c
+index 3807cd3d..f9f56d1d 100644
+--- a/libxfs/xfs_attr_remote.c
++++ b/libxfs/xfs_attr_remote.c
+@@ -11,16 +11,16 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_defer.h"
+ #include "xfs_da_format.h"
+ #include "xfs_da_btree.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_bmap.h"
+ #include "xfs_attr.h"
+ #include "xfs_attr_remote.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ 
+ #define ATTR_RMTVALUE_MAPSIZE	1	/* # of map entries at once */
+ 
+diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
+index e0ca8b05..03999b7e 100644
+--- a/libxfs/xfs_bmap.c
++++ b/libxfs/xfs_bmap.c
+@@ -11,18 +11,18 @@
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+ #include "xfs_sb.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_defer.h"
+ #include "xfs_dir2.h"
+-#include "xfs_inode.h"
++#include "include/xfs_inode.h"
+ #include "xfs_btree.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trans.h"
+ #include "xfs_alloc.h"
+ #include "xfs_bmap.h"
+ #include "xfs_bmap_btree.h"
+ #include "xfs_errortag.h"
+ #include "xfs_trans_space.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ #include "xfs_attr_leaf.h"
+ #include "xfs_quota_defs.h"
+ #include "xfs_rmap.h"
+diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c
+index 1ec9f5ff..c28bba13 100644
+--- a/libxfs/xfs_bmap_btree.c
++++ b/libxfs/xfs_bmap_btree.c
+@@ -10,14 +10,14 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_alloc.h"
+ #include "xfs_btree.h"
+ #include "xfs_bmap_btree.h"
+ #include "xfs_bmap.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ #include "xfs_rmap.h"
+ 
+ /*
+diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c
+index a408aa42..cab61bbb 100644
+--- a/libxfs/xfs_btree.c
++++ b/libxfs/xfs_btree.c
+@@ -10,12 +10,12 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_btree.h"
+ #include "xfs_errortag.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ #include "xfs_alloc.h"
+ #include "xfs_btree_staging.h"
+ 
+diff --git a/libxfs/xfs_btree_staging.c b/libxfs/xfs_btree_staging.c
+index fe17538d..d0f5c651 100644
+--- a/libxfs/xfs_btree_staging.c
++++ b/libxfs/xfs_btree_staging.c
+@@ -10,11 +10,11 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_btree.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ #include "xfs_btree_staging.h"
+ 
+ /*
+diff --git a/libxfs/xfs_da_btree.c b/libxfs/xfs_da_btree.c
+index 7448ee6c..db8fa1bf 100644
+--- a/libxfs/xfs_da_btree.c
++++ b/libxfs/xfs_da_btree.c
+@@ -11,14 +11,14 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
+ #include "xfs_dir2.h"
+ #include "xfs_dir2_priv.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trans.h"
+ #include "xfs_bmap.h"
+ #include "xfs_attr_leaf.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ 
+ /*
+  * xfs_da_btree.c
+diff --git a/libxfs/xfs_defer.c b/libxfs/xfs_defer.c
+index 1fdf6c72..68c24aab 100644
+--- a/libxfs/xfs_defer.c
++++ b/libxfs/xfs_defer.c
+@@ -9,11 +9,11 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_defer.h"
+-#include "xfs_trans.h"
+-#include "xfs_inode.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trans.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trace.h"
+ 
+ /*
+  * Deferred Operations in XFS
+diff --git a/libxfs/xfs_dir2.c b/libxfs/xfs_dir2.c
+index 79196788..0e773062 100644
+--- a/libxfs/xfs_dir2.c
++++ b/libxfs/xfs_dir2.c
+@@ -9,14 +9,14 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_bmap.h"
+ #include "xfs_dir2.h"
+ #include "xfs_dir2_priv.h"
+ #include "xfs_errortag.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ 
+ struct xfs_name xfs_name_dotdot = { (unsigned char *)"..", 2, XFS_DIR3_FT_DIR };
+ 
+diff --git a/libxfs/xfs_dir2_block.c b/libxfs/xfs_dir2_block.c
+index eaa2b47a..f8670fe7 100644
+--- a/libxfs/xfs_dir2_block.c
++++ b/libxfs/xfs_dir2_block.c
+@@ -10,13 +10,13 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_bmap.h"
+ #include "xfs_dir2.h"
+ #include "xfs_dir2_priv.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ 
+ /*
+  * Local function prototypes.
+diff --git a/libxfs/xfs_dir2_data.c b/libxfs/xfs_dir2_data.c
+index ddd5e885..4f3d62e5 100644
+--- a/libxfs/xfs_dir2_data.c
++++ b/libxfs/xfs_dir2_data.c
+@@ -10,11 +10,11 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
+ #include "xfs_dir2.h"
+ #include "xfs_dir2_priv.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trans.h"
+ 
+ static xfs_failaddr_t xfs_dir2_data_freefind_verify(
+ 		struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_free *bf,
+diff --git a/libxfs/xfs_dir2_leaf.c b/libxfs/xfs_dir2_leaf.c
+index 0cecd698..c65545f8 100644
+--- a/libxfs/xfs_dir2_leaf.c
++++ b/libxfs/xfs_dir2_leaf.c
+@@ -10,13 +10,13 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
+ #include "xfs_bmap.h"
+ #include "xfs_dir2.h"
+ #include "xfs_dir2_priv.h"
+-#include "xfs_trace.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trace.h"
++#include "include/xfs_trans.h"
+ 
+ /*
+  * Local function declarations.
+diff --git a/libxfs/xfs_dir2_node.c b/libxfs/xfs_dir2_node.c
+index ab156a8e..1a098688 100644
+--- a/libxfs/xfs_dir2_node.c
++++ b/libxfs/xfs_dir2_node.c
+@@ -10,13 +10,13 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
+ #include "xfs_bmap.h"
+ #include "xfs_dir2.h"
+ #include "xfs_dir2_priv.h"
+-#include "xfs_trace.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trace.h"
++#include "include/xfs_trans.h"
+ 
+ /*
+  * Function declarations.
+diff --git a/libxfs/xfs_dir2_sf.c b/libxfs/xfs_dir2_sf.c
+index fbbb6387..8624bc3f 100644
+--- a/libxfs/xfs_dir2_sf.c
++++ b/libxfs/xfs_dir2_sf.c
+@@ -9,12 +9,12 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_dir2.h"
+ #include "xfs_dir2_priv.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ 
+ /*
+  * Prototypes for internal functions.
+diff --git a/libxfs/xfs_dquot_buf.c b/libxfs/xfs_dquot_buf.c
+index 0a5a237d..4af23c41 100644
+--- a/libxfs/xfs_dquot_buf.c
++++ b/libxfs/xfs_dquot_buf.c
+@@ -10,10 +10,10 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_quota_defs.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ 
+ int
+ xfs_calc_dquots_per_chunk(
+diff --git a/libxfs/xfs_ialloc.c b/libxfs/xfs_ialloc.c
+index d78f960c..b4407b00 100644
+--- a/libxfs/xfs_ialloc.c
++++ b/libxfs/xfs_ialloc.c
+@@ -11,16 +11,16 @@
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+ #include "xfs_sb.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
+ #include "xfs_btree.h"
+ #include "xfs_ialloc.h"
+ #include "xfs_ialloc_btree.h"
+ #include "xfs_alloc.h"
+ #include "xfs_errortag.h"
+ #include "xfs_bmap.h"
+-#include "xfs_trans.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trans.h"
++#include "include/xfs_trace.h"
+ #include "xfs_rmap.h"
+ 
+ /*
+diff --git a/libxfs/xfs_ialloc_btree.c b/libxfs/xfs_ialloc_btree.c
+index 95341715..af0b1057 100644
+--- a/libxfs/xfs_ialloc_btree.c
++++ b/libxfs/xfs_ialloc_btree.c
+@@ -10,14 +10,14 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_btree.h"
+ #include "xfs_btree_staging.h"
+ #include "xfs_ialloc.h"
+ #include "xfs_ialloc_btree.h"
+ #include "xfs_alloc.h"
+-#include "xfs_trace.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trace.h"
++#include "include/xfs_trans.h"
+ #include "xfs_rmap.h"
+ 
+ STATIC int
+diff --git a/libxfs/xfs_iext_tree.c b/libxfs/xfs_iext_tree.c
+index a52eed04..aafe5541 100644
+--- a/libxfs/xfs_iext_tree.c
++++ b/libxfs/xfs_iext_tree.c
+@@ -8,10 +8,10 @@
+ #include "xfs_format.h"
+ #include "xfs_bit.h"
+ #include "xfs_log_format.h"
+-#include "xfs_inode.h"
++#include "include/xfs_inode.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
+-#include "xfs_trace.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_trace.h"
+ 
+ /*
+  * In-core extent record layout:
+diff --git a/libxfs/xfs_inode_buf.c b/libxfs/xfs_inode_buf.c
+index 6722d5af..4e5ef001 100644
+--- a/libxfs/xfs_inode_buf.c
++++ b/libxfs/xfs_inode_buf.c
+@@ -9,10 +9,10 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
+ #include "xfs_errortag.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trans.h"
+ #include "xfs_ialloc.h"
+ #include "xfs_dir2.h"
+ 
+diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c
+index 0b1af501..3e0c4f2d 100644
+--- a/libxfs/xfs_inode_fork.c
++++ b/libxfs/xfs_inode_fork.c
+@@ -10,13 +10,13 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ #include "xfs_btree.h"
+ #include "xfs_bmap_btree.h"
+ #include "xfs_bmap.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ #include "xfs_da_format.h"
+ #include "xfs_da_btree.h"
+ #include "xfs_dir2_priv.h"
+diff --git a/libxfs/xfs_log_rlimit.c b/libxfs/xfs_log_rlimit.c
+index c8398b7d..0632887d 100644
+--- a/libxfs/xfs_log_rlimit.c
++++ b/libxfs/xfs_log_rlimit.c
+@@ -9,7 +9,7 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_da_format.h"
+ #include "xfs_trans_space.h"
+ #include "xfs_da_btree.h"
+diff --git a/libxfs/xfs_refcount.c b/libxfs/xfs_refcount.c
+index 723c903e..1fec6a77 100644
+--- a/libxfs/xfs_refcount.c
++++ b/libxfs/xfs_refcount.c
+@@ -9,15 +9,15 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_defer.h"
+ #include "xfs_btree.h"
+ #include "xfs_bmap.h"
+ #include "xfs_refcount_btree.h"
+ #include "xfs_alloc.h"
+ #include "xfs_errortag.h"
+-#include "xfs_trace.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trace.h"
++#include "include/xfs_trans.h"
+ #include "xfs_bit.h"
+ #include "xfs_refcount.h"
+ #include "xfs_rmap.h"
+diff --git a/libxfs/xfs_refcount_btree.c b/libxfs/xfs_refcount_btree.c
+index eb48197b..c378b024 100644
+--- a/libxfs/xfs_refcount_btree.c
++++ b/libxfs/xfs_refcount_btree.c
+@@ -10,13 +10,13 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_sb.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_btree.h"
+ #include "xfs_btree_staging.h"
+ #include "xfs_refcount_btree.h"
+ #include "xfs_alloc.h"
+-#include "xfs_trace.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trace.h"
++#include "include/xfs_trans.h"
+ #include "xfs_bit.h"
+ #include "xfs_rmap.h"
+ 
+diff --git a/libxfs/xfs_rmap.c b/libxfs/xfs_rmap.c
+index 6205b8ed..d0eb95b8 100644
+--- a/libxfs/xfs_rmap.c
++++ b/libxfs/xfs_rmap.c
+@@ -10,16 +10,16 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_defer.h"
+ #include "xfs_btree.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trans.h"
+ #include "xfs_alloc.h"
+ #include "xfs_rmap.h"
+ #include "xfs_rmap_btree.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ #include "xfs_errortag.h"
+-#include "xfs_inode.h"
++#include "include/xfs_inode.h"
+ 
+ /*
+  * Lookup the first record less than or equal to [bno, len, owner, offset]
+diff --git a/libxfs/xfs_rmap_btree.c b/libxfs/xfs_rmap_btree.c
+index 8ddc1790..18b2a8a9 100644
+--- a/libxfs/xfs_rmap_btree.c
++++ b/libxfs/xfs_rmap_btree.c
+@@ -10,14 +10,14 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_sb.h"
+-#include "xfs_mount.h"
+-#include "xfs_trans.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_trans.h"
+ #include "xfs_alloc.h"
+ #include "xfs_btree.h"
+ #include "xfs_btree_staging.h"
+ #include "xfs_rmap.h"
+ #include "xfs_rmap_btree.h"
+-#include "xfs_trace.h"
++#include "include/xfs_trace.h"
+ #include "xfs_ag_resv.h"
+ 
+ /*
+diff --git a/libxfs/xfs_rtbitmap.c b/libxfs/xfs_rtbitmap.c
+index dcb94f20..dcbc5a95 100644
+--- a/libxfs/xfs_rtbitmap.c
++++ b/libxfs/xfs_rtbitmap.c
+@@ -10,10 +10,10 @@
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
+ #include "xfs_bmap.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trans.h"
+ 
+ /*
+  * Realtime allocator bitmap functions shared with userspace.
+diff --git a/libxfs/xfs_sb.c b/libxfs/xfs_sb.c
+index fb2212b8..bd07b00f 100644
+--- a/libxfs/xfs_sb.c
++++ b/libxfs/xfs_sb.c
+@@ -11,11 +11,11 @@
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+ #include "xfs_sb.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_ialloc.h"
+ #include "xfs_alloc.h"
+-#include "xfs_trace.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trace.h"
++#include "include/xfs_trans.h"
+ #include "xfs_bmap_btree.h"
+ #include "xfs_alloc_btree.h"
+ #include "xfs_rmap_btree.h"
+diff --git a/libxfs/xfs_symlink_remote.c b/libxfs/xfs_symlink_remote.c
+index 8eb3d59f..bc184484 100644
+--- a/libxfs/xfs_symlink_remote.c
++++ b/libxfs/xfs_symlink_remote.c
+@@ -10,9 +10,9 @@
+ #include "xfs_log_format.h"
+ #include "xfs_shared.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ 
+ 
+ /*
+diff --git a/libxfs/xfs_trans_inode.c b/libxfs/xfs_trans_inode.c
+index 66dadd87..02ae86ff 100644
+--- a/libxfs/xfs_trans_inode.c
++++ b/libxfs/xfs_trans_inode.c
+@@ -9,9 +9,9 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
+-#include "xfs_inode.h"
+-#include "xfs_trans.h"
++#include "include/xfs_mount.h"
++#include "include/xfs_inode.h"
++#include "include/xfs_trans.h"
+ 
+ 
+ /*
+diff --git a/libxfs/xfs_trans_resv.c b/libxfs/xfs_trans_resv.c
+index 9ce7d8f9..07845084 100644
+--- a/libxfs/xfs_trans_resv.c
++++ b/libxfs/xfs_trans_resv.c
+@@ -10,12 +10,12 @@
+ #include "xfs_format.h"
+ #include "xfs_log_format.h"
+ #include "xfs_trans_resv.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ #include "xfs_da_format.h"
+ #include "xfs_da_btree.h"
+-#include "xfs_inode.h"
++#include "include/xfs_inode.h"
+ #include "xfs_bmap_btree.h"
+-#include "xfs_trans.h"
++#include "include/xfs_trans.h"
+ #include "xfs_trans_space.h"
+ #include "xfs_quota_defs.h"
+ 
+diff --git a/libxfs/xfs_types.c b/libxfs/xfs_types.c
+index fa113727..b95e6e2a 100644
+--- a/libxfs/xfs_types.c
++++ b/libxfs/xfs_types.c
+@@ -10,7 +10,7 @@
+ #include "xfs_shared.h"
+ #include "xfs_trans_resv.h"
+ #include "xfs_bit.h"
+-#include "xfs_mount.h"
++#include "include/xfs_mount.h"
+ 
+ /* Find the size of the AG, in blocks. */
+ xfs_agblock_t
+diff --git a/mkfs/proto.c b/mkfs/proto.c
+index 0fa6ffb0..a45c4a5c 100644
+--- a/mkfs/proto.c
++++ b/mkfs/proto.c
+@@ -4,7 +4,7 @@
+  * All Rights Reserved.
+  */
+ 
+-#include "libxfs.h"
++#include "include/libxfs.h"
+ #include <sys/stat.h>
+ #include "libfrog/convert.h"
+ 
+diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
+index 47acc127..3bfa5607 100644
+--- a/mkfs/xfs_mkfs.c
++++ b/mkfs/xfs_mkfs.c
+@@ -4,14 +4,14 @@
+  * All Rights Reserved.
+  */
+ #include "libfrog/util.h"
+-#include "libxfs.h"
++#include "include/libxfs.h"
+ #include <ctype.h>
+-#include "xfs_multidisk.h"
+-#include "libxcmd.h"
++#include "include/xfs_multidisk.h"
++#include "include/libxcmd.h"
+ #include "libfrog/fsgeom.h"
+ #include "libfrog/topology.h"
+ #include "libfrog/convert.h"
+-#include <ini.h>
++#include "ini.h"
+ 
+ #define TERABYTES(count, blog)	((uint64_t)(count) << (40 - (blog)))
+ #define GIGABYTES(count, blog)	((uint64_t)(count) << (30 - (blog)))
+-- 
+2.25.1
+
diff --git a/third_party/xfsprogs/xfsprogs.bzl b/third_party/xfsprogs/xfsprogs.bzl
new file mode 100644
index 0000000..7265e9f
--- /dev/null
+++ b/third_party/xfsprogs/xfsprogs.bzl
@@ -0,0 +1,212 @@
+#  Copyright 2020 The Monogon Project Authors.
+#
+#  SPDX-License-Identifier: Apache-2.0
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
+load("@dev_source_monogon//build/utils:template_file.bzl", "template_file")
+
+defs = [
+    "NDEBUG",  # Doesn't compile without it because their assertions reference non-existent fields
+    "_GNU_SOURCE",
+    "ENABLE_BLKID",
+    "HAVE_FSETXATTR",
+    "HAVE_GETFSMAP",
+    "HAVE_GETMNTENT",
+    "HAVE_MNTENT",
+    "VERSION=\\\"0.0.0\\\"",
+]
+
+template_file(
+    name = "platform_defs.h",
+    src = "include/platform_defs.h.in",
+    substitutions = {
+        "#undef SIZEOF_LONG": "#define SIZEOF_LONG sizeof(long)",  # Because C reasons
+    },
+)
+
+cc_library(
+    name = "util",
+    srcs = [
+        "libfrog/util.c",
+        ":platform_defs.h",
+    ],
+    hdrs = ["libfrog/util.h"],
+    local_defines = defs,
+)
+
+cc_library(
+    name = "radix_tree",
+    srcs = [
+        "libfrog/radix-tree.c",
+        ":platform_defs.h",
+    ],
+    hdrs = ["libfrog/radix-tree.h"],
+    local_defines = defs,
+)
+
+cc_binary(
+    name = "gen_crc32table",
+    srcs = [
+        "libfrog/crc32defs.h",
+        "libfrog/gen_crc32table.c",
+    ],
+)
+
+genrule(
+    name = "crc32table",
+    srcs = [],
+    outs = ["crc32table.h"],
+    cmd = "./$(location :gen_crc32table) > \"$@\"",
+    tools = [":gen_crc32table"],
+)
+
+cc_library(
+    name = "crc32c",
+    srcs = [
+        "include/xfs_arch.h",
+        "libfrog/crc32.c",
+        "libfrog/crc32defs.h",
+        ":crc32table",
+        ":platform_defs.h",
+    ],
+    hdrs = ["libfrog/crc32c.h"],
+    local_defines = defs,
+)
+
+cc_library(
+    name = "list_sort",
+    srcs = ["libfrog/list_sort.c"],
+    hdrs = ["include/list.h"],
+    local_defines = defs,
+)
+
+cc_library(
+    name = "fsgeom",
+    srcs = ["libfrog/fsgeom.c"],
+    hdrs = ["libfrog/fsgeom.h"],
+    local_defines = defs,
+    deps = [
+        ":libxfs",
+        ":util",
+    ],
+)
+
+cc_library(
+    name = "projects",
+    srcs = [
+        "include/input.h",
+        "libfrog/projects.c",
+        "libfrog/projects.h",
+        ":platform_defs.h",
+    ],
+    hdrs = ["libfrog/projects.h"],
+    local_defines = defs,
+    deps = [
+        ":libxfs",
+    ],
+)
+
+cc_library(
+    name = "convert",
+    srcs = [
+        "include/input.h",
+        "libfrog/convert.c",
+        ":platform_defs.h",
+    ],
+    hdrs = ["libfrog/convert.h"],
+    local_defines = defs,
+    deps = [
+        ":projects",
+    ],
+)
+
+cc_library(
+    name = "topology",
+    srcs = [
+        "include/xfs_multidisk.h",
+        "libfrog/topology.c",
+    ],
+    hdrs = [
+        "include/libxcmd.h",
+        "libfrog/topology.h",
+    ],
+    local_defines = defs,
+    visibility = ["//visibility:public"],
+    deps = [
+        ":libxfs",
+        "@util_linux//:blkid",
+    ],
+)
+
+cc_library(
+    name = "platform",
+    srcs = ["libfrog/linux.c"],
+    local_defines = defs,
+    visibility = ["//visibility:public"],
+    deps = [":libxfs"],
+)
+
+cc_library(
+    name = "libxfs",
+    srcs = glob([
+        "libxfs/*.c",
+        "libxfs/*.h",
+    ]) + [
+        ":platform_defs.h",
+        "include/xfs.h",
+        "libfrog/platform.h",
+        "include/linux.h",
+        "include/hlist.h",
+        "include/cache.h",
+        "include/bitops.h",
+        "include/kmem.h",
+        "include/atomic.h",
+        "include/xfs_mount.h",
+        "include/xfs_inode.h",
+        "include/xfs_trans.h",
+        "include/xfs_trace.h",
+        "libfrog/linux.c",
+        "include/xfs_fs_compat.h",
+    ],
+    hdrs = ["include/libxfs.h"],
+    local_defines = defs,
+    deps = [
+        ":crc32c",
+        ":list_sort",
+        ":radix_tree",
+        "@util_linux//:uuid",
+    ],
+)
+
+cc_binary(
+    name = "mkfs",
+    srcs = [
+        "include/xfs_multidisk.h",
+        "mkfs/proto.c",
+        "mkfs/xfs_mkfs.c",
+    ],
+    linkopts = ["-lpthread"],
+    local_defines = defs,
+    deps = [
+        ":convert",
+        ":fsgeom",
+        ":libxfs",
+        ":platform",
+        ":topology",
+        ":util",
+        "@inih",
+    ],
+    visibility = ["//visibility:public"],
+)