]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commit
proto: add ability to populate a filesystem from a directory
authorLuca Di Maio <luca.dimaio1@gmail.com>
Wed, 30 Jul 2025 16:12:22 +0000 (18:12 +0200)
committerAndrey Albershteyn <aalbersh@kernel.org>
Mon, 8 Sep 2025 11:10:53 +0000 (13:10 +0200)
commit8a4ea72724930cfe262ccda03028264e1a81b145
tree0b847ca51f51182c0d75772806b7f3a554c895c5
parent1d287f3d958ebc425275d6a08ad6977e13e52fac
proto: add ability to populate a filesystem from a directory

This patch implements the functionality to populate a newly created XFS
filesystem directly from an existing directory structure.

It resuses existing protofile logic, it branches if input is a
directory.

The population process steps are as follows:
  - create the root inode before populating content
  - recursively process nested directories
  - handle regular files, directories, symlinks, char devices, block
    devices, sockets, fifos
  - preserve attributes (ownership, permissions)
  - preserve mtime timestamps from source files to maintain file history
    - use current time for atime/ctime/crtime
    - possible to specify atime=1 to preserve atime timestamps from
      source files
  - preserve extended attributes and fsxattrs for all file types
  - preserve hardlinks

At the moment, the implementation for the hardlink tracking is very
simple, as it involves a linear search.
from my local testing using larger source directories
(1.3mln inodes, ~400k hardlinks) the difference was actually
just a few seconds (given that most of the time is doing i/o).
We might want to revisit that in the future if this becomes a
bottleneck.

This functionality makes it easier to create populated filesystems
without having to mount them, it's particularly useful for
reproducible builds.

Signed-off-by: Luca Di Maio <luca.dimaio1@gmail.com>
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
man/man8/mkfs.xfs.8.in
mkfs/proto.c
mkfs/proto.h
mkfs/xfs_mkfs.c