return 0;
}
-int btrfs_is_filesystem(int fd) {
- struct statfs sfs;
-
- assert(fd >= 0);
-
- if (fstatfs(fd, &sfs) < 0)
- return -errno;
-
- return F_TYPE_EQUAL(sfs.f_type, BTRFS_SUPER_MAGIC);
-}
-
int btrfs_is_subvol_fd(int fd) {
struct stat st;
if (!btrfs_might_be_subvol(&st))
return 0;
- return btrfs_is_filesystem(fd);
+ return fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
}
int btrfs_is_subvol(const char *path) {
assert(fd >= 0);
assert(dev);
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (!r)
assert(fd >= 0);
assert(ret);
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (!r)
if (r < 0)
return r;
} else {
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (!r)
if (r < 0)
return r;
} else {
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (!r)
return btrfs_subvol_get_subtree_quota_fd(fd, subvol_id, ret);
}
-int btrfs_defrag_fd(int fd) {
- int r;
-
- assert(fd >= 0);
-
- r = fd_verify_regular(fd);
- if (r < 0)
- return r;
-
- if (ioctl(fd, BTRFS_IOC_DEFRAG, NULL) < 0)
- return -errno;
-
- return 0;
-}
-
int btrfs_defrag(const char *p) {
_cleanup_close_ int fd = -1;
assert(fd >= 0);
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (!r)
if (r < 0)
return r;
} else {
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (!r)
};
int r;
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (r == 0)
};
int r;
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (r == 0)
int r;
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (!r)
if (r < 0)
return r;
} else {
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (!r)
if (r < 0)
return r;
} else {
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (!r)
BTRFS_REMOVE_QUOTA = 1 << 1,
} BtrfsRemoveFlags;
-int btrfs_is_filesystem(int fd);
-
int btrfs_is_subvol_fd(int fd);
int btrfs_is_subvol(const char *path);
int btrfs_get_block_device_fd(int fd, dev_t *dev);
int btrfs_get_block_device(const char *path, dev_t *dev);
-int btrfs_defrag_fd(int fd);
int btrfs_defrag(const char *p);
int btrfs_quota_enable_fd(int fd, bool b);
#include <errno.h>
#include <fcntl.h>
+#include <linux/btrfs.h>
+#include <linux/magic.h>
+#include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <unistd.h>
/* If we fail, fall back to the hard-coded kernel limit of 1024 * 1024. */
return 1024 * 1024;
}
+
+/* This is here because it's fd-related and is called from sd-journal code. Other btrfs-related utilities are
+ * in src/shared, but libsystemd must not link to libsystemd-shared, see docs/ARCHITECTURE.md. */
+int btrfs_defrag_fd(int fd) {
+ int r;
+
+ assert(fd >= 0);
+
+ r = fd_verify_regular(fd);
+ if (r < 0)
+ return r;
+
+ if (ioctl(fd, BTRFS_IOC_DEFRAG, NULL) < 0)
+ return -errno;
+
+ return 0;
+}
int fd_reopen(int fd, int flags);
-
int read_nr_open(void);
+int btrfs_defrag_fd(int fd);
#include <errno.h>
#include <fcntl.h>
#include <linux/fs.h>
+#include <linux/magic.h>
#include <pthread.h>
#include <stddef.h>
#include <sys/mman.h>
#include "sd-event.h"
#include "alloc-util.h"
-#include "btrfs-util.h"
#include "chattr-util.h"
#include "compress.h"
#include "env-util.h"
* expense of data integrity features (which shouldn't be too
* bad, given that we do our own checksumming). */
- r = btrfs_is_filesystem(f->fd);
+ r = fd_is_fs_type(f->fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return log_warning_errno(r, "Failed to determine if journal is on btrfs: %m");
if (!r)
#include <fcntl.h>
#include <linux/fs.h>
#include <linux/loop.h>
+#include <linux/magic.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/file.h>
#include "os-util.h"
#include "path-util.h"
#include "rm-rf.h"
+#include "stat-util.h"
#include "string-table.h"
#include "string-util.h"
#include "strv.h"
if (btrfs_might_be_subvol(st)) {
- r = btrfs_is_filesystem(fd);
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
if (r < 0)
return r;
if (r) {
#include <errno.h>
#include <fcntl.h>
#include <linux/fs.h>
+#include <linux/magic.h>
#include <stdbool.h>
#include <stddef.h>
#include <sys/ioctl.h>
#include "parse-util.h"
#include "path-util.h"
#include "sleep-config.h"
+#include "stat-util.h"
#include "stdio-util.h"
#include "string-table.h"
#include "string-util.h"
_cleanup_close_ int fd = -1;
_cleanup_free_ struct fiemap *fiemap = NULL;
struct stat sb;
- int r, btrfs;
+ int r;
assert(swap);
assert(swap->device);
if (fstat(fd, &sb) < 0)
return log_debug_errno(errno, "Failed to stat %s: %m", swap->device);
- btrfs = btrfs_is_filesystem(fd);
- if (btrfs < 0)
- return log_debug_errno(btrfs, "Error checking %s for Btrfs filesystem: %m", swap->device);
- if (btrfs > 0) {
+ r = fd_is_fs_type(fd, BTRFS_SUPER_MAGIC);
+ if (r < 0)
+ return log_debug_errno(r, "Error checking %s for Btrfs filesystem: %m", swap->device);
+ if (r > 0) {
log_debug("%s: detection of swap file offset on Btrfs is not supported", swap->device);
*ret_offset = UINT64_MAX;
return 0;