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