]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/blockdev-util.h
basic/include: replace _Static_assert() with static_assert()
[thirdparty/systemd.git] / src / shared / blockdev-util.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
18c528e9
LP
2#pragma once
3
69a283c5 4#include <sys/sysmacros.h>
18c528e9 5
69a283c5 6#include "forward.h"
18c528e9 7#include "stdio-util.h"
18c528e9
LP
8
9#define SYS_BLOCK_PATH_MAX(suffix) \
bdcd47a2 10 (STRLEN("/sys/dev/block/") + DECIMAL_STR_MAX(dev_t) + 1 + DECIMAL_STR_MAX(dev_t) + STRLEN(suffix))
18c528e9 11#define xsprintf_sys_block_path(buf, suffix, devno) \
bdcd47a2 12 xsprintf(buf, "/sys/dev/block/%u:%u%s", major(devno), minor(devno), suffix ?: "")
18c528e9 13
fd690a4b
YW
14typedef enum BlockDeviceLookupFlag {
15 BLOCK_DEVICE_LOOKUP_WHOLE_DISK = 1 << 0, /* whole block device, e.g. sda, nvme0n1, or loop0. */
16 BLOCK_DEVICE_LOOKUP_BACKING = 1 << 1, /* fd may be regular file or directory on file system, in
17 * which case backing block device is determined. */
18 BLOCK_DEVICE_LOOKUP_ORIGINATING = 1 << 2, /* Try to find the underlying layer device for stacked
19 * block device, e.g. LUKS-style DM. */
20} BlockDeviceLookupFlag;
21
22int block_device_new_from_fd(int fd, BlockDeviceLookupFlag flag, sd_device **ret);
23int block_device_new_from_path(const char *path, BlockDeviceLookupFlag flag, sd_device **ret);
24
2f9d2317 25int block_device_is_whole_disk(sd_device *dev);
55a437f8 26int block_device_get_whole_disk(sd_device *dev, sd_device **ret);
50ab93eb 27int block_device_get_originating(sd_device *dev, sd_device **ret);
55a437f8 28
18c528e9 29int block_get_whole_disk(dev_t d, dev_t *ret);
880f09bd 30int block_get_originating(dev_t d, dev_t *ret);
18c528e9 31
0bfef8b4 32int get_block_device_fd(int fd, dev_t *ret);
18c528e9
LP
33int get_block_device(const char *path, dev_t *dev);
34
bcf8fc26 35int get_block_device_harder_fd(int fd, dev_t *dev);
18c528e9 36int get_block_device_harder(const char *path, dev_t *dev);
ac83e5ae
LP
37
38int lock_whole_block_device(dev_t devt, int operation);
e8467cd3 39
bff5d2fd
LP
40int blockdev_partscan_enabled(sd_device *d);
41int blockdev_partscan_enabled_fd(int fd);
b25a930f 42
91358db9 43int fd_is_encrypted(int fd);
b25a930f 44int path_is_encrypted(const char *path);
26aa4800
DDM
45
46int fd_get_whole_disk(int fd, bool backing, dev_t *ret);
47int path_get_whole_disk(const char *path, bool backing, dev_t *ret);
d25697f5
DDM
48
49int block_device_add_partition(int fd, const char *name, int nr, uint64_t start, uint64_t size);
50int block_device_remove_partition(int fd, const char *name, int nr);
91e1ce1a 51int block_device_resize_partition(int fd, int nr, uint64_t start, uint64_t size);
9409174e 52int partition_enumerator_new(sd_device *dev, sd_device_enumerator **ret);
46c3a288 53int block_device_remove_all_partitions(sd_device *dev, int fd);
86f9b69a 54int blockdev_reread_partition_table(sd_device *dev);
65046b92
LP
55
56int blockdev_get_sector_size(int fd, uint32_t *ret);
01db9c85 57int blockdev_get_device_size(int fd, uint64_t *ret);
c56be2c2
LP
58
59int blockdev_get_root(int level, dev_t *ret);