]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/shared/blockdev-util.h
Merge pull request #30284 from YHNdnzj/fstab-wantedby-defaultdeps
[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
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
17typedef 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
25int block_device_new_from_fd(int fd, BlockDeviceLookupFlag flag, sd_device **ret);
26int block_device_new_from_path(const char *path, BlockDeviceLookupFlag flag, sd_device **ret);
27
2f9d2317 28int block_device_is_whole_disk(sd_device *dev);
55a437f8 29int block_device_get_whole_disk(sd_device *dev, sd_device **ret);
50ab93eb 30int block_device_get_originating(sd_device *dev, sd_device **ret);
55a437f8 31
18c528e9 32int block_get_whole_disk(dev_t d, dev_t *ret);
880f09bd 33int block_get_originating(dev_t d, dev_t *ret);
18c528e9 34
0bfef8b4 35int get_block_device_fd(int fd, dev_t *ret);
18c528e9
LP
36int get_block_device(const char *path, dev_t *dev);
37
bcf8fc26 38int get_block_device_harder_fd(int fd, dev_t *dev);
18c528e9 39int get_block_device_harder(const char *path, dev_t *dev);
ac83e5ae
LP
40
41int lock_whole_block_device(dev_t devt, int operation);
e8467cd3
LP
42
43int blockdev_partscan_enabled(int fd);
b25a930f 44
91358db9 45int fd_is_encrypted(int fd);
b25a930f 46int path_is_encrypted(const char *path);
26aa4800
DDM
47
48int fd_get_whole_disk(int fd, bool backing, dev_t *ret);
49int path_get_whole_disk(const char *path, bool backing, dev_t *ret);
d25697f5
DDM
50
51int block_device_add_partition(int fd, const char *name, int nr, uint64_t start, uint64_t size);
52int block_device_remove_partition(int fd, const char *name, int nr);
91e1ce1a 53int block_device_resize_partition(int fd, int nr, uint64_t start, uint64_t size);
9409174e 54int partition_enumerator_new(sd_device *dev, sd_device_enumerator **ret);
46c3a288 55int block_device_remove_all_partitions(sd_device *dev, int fd);
aa0295f1 56int block_device_has_partitions(sd_device *dev);
86f9b69a 57int blockdev_reread_partition_table(sd_device *dev);
65046b92
LP
58
59int blockdev_get_sector_size(int fd, uint32_t *ret);
01db9c85 60int blockdev_get_device_size(int fd, uint64_t *ret);
c56be2c2
LP
61
62int blockdev_get_root(int level, dev_t *ret);