bcachefs-tools/c_src/posix_to_bcachefs.h
Ariel Miculas d750b2b98b bcachefs: allow initializing a bcachefs filesystem from a source directory
Add a new source command line argument which specifies the directory
tree that will be copied onto the newly formatted bcachefs filesystem.

This commit also fixes an issue in copy_link where uninitialized data is
copied into the symlink because of a round_up of the buffer size.

Signed-off-by: Ariel Miculas <ariel.miculas@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-06-16 14:08:52 -04:00

55 lines
1.9 KiB
C

/* SPDX-License-Identifier: GPL-2.0 */
#ifndef _POSIX_TO_BCACHEFS_H
#define _POSIX_TO_BCACHEFS_H
/*
* This header exports the functionality needed for copying data from existing
* posix compliant filesystems to bcachefs. There are two use cases:
* 1. Creating a new bcachefs filesystem using `bcachefs format`, we can
* specify a source directory tree which will be copied over the new
* bcachefs filesytem.
* 2. Migrating an existing filesystem in place, with `bcachefs migrate`.
* This will allocate space for the bcachefs metadata, but the actual data
* represented by the extents will not be duplicated. The bcachefs metadata
* will simply point to the existing extents.
*
* To avoid code duplication, `copy_fs` deals with both cases. See the function
* documentation for more details.
*/
#include "libbcachefs.h"
enum bch_migrate_type {
BCH_MIGRATE_copy,
BCH_MIGRATE_migrate
};
/*
* The migrate action uses all the fields in this struct.
* The copy action only uses the `hardlinks` field. Since `hardlinks` is
* initialized with zeroes, an empty `copy_fs_state` struct can be passed.
*/
struct copy_fs_state {
u64 bcachefs_inum;
dev_t dev;
GENRADIX(u64) hardlinks;
ranges extents;
enum bch_migrate_type type;
};
/*
* The `copy_fs` function is used for both copying a directory tree to a new
* bcachefs filesystem and migrating an existing one, depending on the value
* from the `type` field in `copy_fs_state` struct.
*
* In case of copy, an empty `copy_fs_state` structure is passed to `copy_fs`
* (only the `hardlinks` field is used, and that is initialized with zeroes).
*
* In the migrate case, all the fields from `copy_fs_state` need to be
* initialized (`hardlinks` is initialized with zeroes).
*/
void copy_fs(struct bch_fs *c, int src_fd, const char *src_path,
struct copy_fs_state *s);
#endif /* _LIBBCACHE_H */