]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ | |
2 | #pragma once | |
3 | ||
4 | #include <sys/sysmacros.h> | |
5 | ||
6 | #include "forward.h" | |
7 | #include "stdio-util.h" | |
8 | ||
9 | #define SYS_BLOCK_PATH_MAX(suffix) \ | |
10 | (STRLEN("/sys/dev/block/") + DECIMAL_STR_MAX(dev_t) + 1 + DECIMAL_STR_MAX(dev_t) + STRLEN(suffix)) | |
11 | #define xsprintf_sys_block_path(buf, suffix, devno) \ | |
12 | xsprintf(buf, "/sys/dev/block/%u:%u%s", major(devno), minor(devno), suffix ?: "") | |
13 | ||
14 | typedef 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 | ||
22 | int block_device_new_from_fd(int fd, BlockDeviceLookupFlag flag, sd_device **ret); | |
23 | int block_device_new_from_path(const char *path, BlockDeviceLookupFlag flag, sd_device **ret); | |
24 | ||
25 | int block_device_is_whole_disk(sd_device *dev); | |
26 | int block_device_get_whole_disk(sd_device *dev, sd_device **ret); | |
27 | int block_device_get_originating(sd_device *dev, sd_device **ret); | |
28 | ||
29 | int block_get_whole_disk(dev_t d, dev_t *ret); | |
30 | int block_get_originating(dev_t d, dev_t *ret); | |
31 | ||
32 | int get_block_device_fd(int fd, dev_t *ret); | |
33 | int get_block_device(const char *path, dev_t *dev); | |
34 | ||
35 | int get_block_device_harder_fd(int fd, dev_t *dev); | |
36 | int get_block_device_harder(const char *path, dev_t *dev); | |
37 | ||
38 | int lock_whole_block_device(dev_t devt, int operation); | |
39 | ||
40 | int blockdev_partscan_enabled(sd_device *d); | |
41 | int blockdev_partscan_enabled_fd(int fd); | |
42 | ||
43 | int fd_is_encrypted(int fd); | |
44 | int path_is_encrypted(const char *path); | |
45 | ||
46 | int fd_get_whole_disk(int fd, bool backing, dev_t *ret); | |
47 | int path_get_whole_disk(const char *path, bool backing, dev_t *ret); | |
48 | ||
49 | int block_device_add_partition(int fd, const char *name, int nr, uint64_t start, uint64_t size); | |
50 | int block_device_remove_partition(int fd, const char *name, int nr); | |
51 | int block_device_resize_partition(int fd, int nr, uint64_t start, uint64_t size); | |
52 | int partition_enumerator_new(sd_device *dev, sd_device_enumerator **ret); | |
53 | int block_device_remove_all_partitions(sd_device *dev, int fd); | |
54 | int blockdev_reread_partition_table(sd_device *dev); | |
55 | ||
56 | int blockdev_get_sector_size(int fd, uint32_t *ret); | |
57 | int blockdev_get_device_size(int fd, uint64_t *ret); | |
58 | ||
59 | int blockdev_get_root(int level, dev_t *ret); |