• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 17962269173

23 Sep 2025 11:38PM UTC coverage: 72.283% (-0.008%) from 72.291%
17962269173

push

github

bluca
mkosi: update debian commit reference to 49dd9371a

* 49dd9371a0 d/rules: Ubuntu moved vmlinux.h too
* c81ce364eb Install new files for upstream build
* 35abaf33bc Override more Lintian warnings about appstream
* a3d3690c45 Override Lintian warning for appstream-metadata-missing-modalias-provide
* 1bcda1fd90 Override Lintian warning for binaries-have-file-conflict
* c597c00ffc Drop versioned conflicts added for bullseye upgrades
* 9cd845af25 Override lintian warnings for conflicts-with-version
* 359da95d09 Override Lintian warning for spare-manual-page
* 3ef8c31cb2 Override Lintian warning for groff-message
* dbe51582a9 Update changelog for 258-1 release
* ffd971a27d autopkgtest: ensure /usr/sbin is in the PATH for unit-tests job
* f086b8e881 autopkgtest: enable debug logs for unit-tests job
* 02142b9eae autopkgest: install dosfstools for test-loop-block
* 0319d890bd salsa-ci: enable ppc64el builds
* 645b1fa318 autopkgtest: use -20 instead of -22 for zstd compression
* b8dc9b0ce7 salsa-ci: switch to recommended entry point yml
* 152a2b3140 autopkgtest: set default_device_timeout_sec=240
* 6d46436878 autopkgtest: manually compress logs on failure
* c6c70bbb0c Update changelog for 258~rc4-1 release
* 2695112df7 Update changelog for 258~rc3-1 release
* 2c293cb2be systemd-boot: update version for rm_conffile

302850 of 418978 relevant lines covered (72.28%)

1062848.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.73
/src/shared/blockdev-list.c
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2

3
#include "sd-device.h"
4

5
#include "alloc-util.h"
6
#include "ansi-color.h"
7
#include "blockdev-list.h"
8
#include "blockdev-util.h"
9
#include "device-private.h"
10
#include "device-util.h"
11
#include "strv.h"
12
#include "terminal-util.h"
13

14
void block_device_done(BlockDevice *d) {
×
15
        assert(d);
×
16

17
        d->node = mfree(d->node);
×
18
        d->symlinks = strv_free(d->symlinks);
×
19
 }
×
20

21
void block_device_array_free(BlockDevice *d, size_t n_devices) {
×
22

23
        FOREACH_ARRAY(i, d, n_devices)
×
24
                block_device_done(d);
×
25

26
        free(d);
×
27
}
×
28

29
int blockdev_list(BlockDevListFlags flags, BlockDevice **ret_devices, size_t *ret_n_devices) {
6✔
30
        _cleanup_(sd_device_enumerator_unrefp) sd_device_enumerator *e = NULL;
6✔
31
        int r;
6✔
32

33
        assert(!!ret_devices == !!ret_n_devices);
6✔
34

35
        /* If ret_devices/ret_n_devices are passed, returns a list of matching block devices, otherwise
36
         * prints the list to stdout */
37

38
        BlockDevice *l = NULL;
6✔
39
        size_t n = 0;
6✔
40
        CLEANUP_ARRAY(l, n, block_device_array_free);
6✔
41

42
        dev_t root_devno = 0;
6✔
43
        if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_ROOT))
6✔
44
                if (blockdev_get_root(LOG_DEBUG, &root_devno) > 0) {
2✔
45
                        r = block_get_whole_disk(root_devno, &root_devno);
2✔
46
                        if (r < 0)
2✔
47
                                log_debug_errno(r, "Failed to get whole block device of root device: %m");
×
48
                }
49

50
        if (sd_device_enumerator_new(&e) < 0)
6✔
51
                return log_oom();
×
52

53
        r = sd_device_enumerator_add_match_subsystem(e, "block", /* match = */ true);
6✔
54
        if (r < 0)
6✔
55
                return log_error_errno(r, "Failed to add subsystem match: %m");
×
56

57
        if (FLAGS_SET(flags, BLOCKDEV_LIST_REQUIRE_LUKS)) {
6✔
58
                r = sd_device_enumerator_add_match_property(e, "ID_FS_TYPE", "crypto_LUKS");
1✔
59
                if (r < 0)
1✔
60
                        return log_error_errno(r, "Failed to add match for LUKS block devices: %m");
×
61
        }
62

63
        FOREACH_DEVICE(e, dev) {
29✔
64
                const char *node;
23✔
65

66
                r = sd_device_get_devname(dev, &node);
23✔
67
                if (r < 0) {
23✔
68
                        log_warning_errno(r, "Failed to get device node of discovered block device, ignoring: %m");
×
69
                        continue;
16✔
70
                }
71

72
                if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_ROOT) && root_devno != 0) {
23✔
73
                        dev_t devno;
10✔
74

75
                        r = sd_device_get_devnum(dev, &devno);
10✔
76
                        if (r < 0) {
10✔
77
                                log_warning_errno(r, "Failed to get major/minor of discovered block device, ignoring: %m");
×
78
                                continue;
2✔
79
                        }
80

81
                        if (devno == root_devno)
10✔
82
                                continue;
2✔
83
                }
84

85
                if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_ZRAM)) {
21✔
86
                        r = device_sysname_startswith(dev, "zram");
20✔
87
                        if (r < 0) {
20✔
88
                                log_warning_errno(r, "Failed to check device name of discovered block device '%s', ignoring: %m", node);
×
89
                                continue;
×
90
                        }
91
                        if (r > 0)
20✔
92
                                continue;
×
93
                }
94

95
                if (FLAGS_SET(flags, BLOCKDEV_LIST_REQUIRE_PARTITION_SCANNING)) {
21✔
96
                        r = blockdev_partscan_enabled(dev);
16✔
97
                        if (r < 0) {
16✔
98
                                log_warning_errno(r, "Unable to determine whether '%s' supports partition scanning, skipping device: %m", node);
×
99
                                continue;
×
100
                        }
101
                        if (r == 0) {
16✔
102
                                log_debug("Device '%s' does not support partition scanning, skipping.", node);
14✔
103
                                continue;
14✔
104
                        }
105
                }
106

107
                uint64_t size = UINT64_MAX;
7✔
108
                if (FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_EMPTY) || ret_devices) {
7✔
109

110
                        r = device_get_sysattr_u64(dev, "size", &size);
×
111
                        if (r < 0)
×
112
                                log_debug_errno(r, "Failed to acquire size of device '%s', ignoring: %m", node);
×
113
                        else
114
                                size *= 512; /* the 'size' sysattr is always in multiples of 512, even on 4K sector block devices! */
×
115

116
                        if (size == 0 && FLAGS_SET(flags, BLOCKDEV_LIST_IGNORE_EMPTY)) {
×
117
                                log_debug("Device '%s' has a zero size, assuming drive without a medium, skipping.", node);
×
118
                                continue;
×
119
                        }
120
                }
121

122
                _cleanup_strv_free_ char **list = NULL;
7✔
123
                if (FLAGS_SET(flags, BLOCKDEV_LIST_SHOW_SYMLINKS)) {
7✔
124
                        FOREACH_DEVICE_DEVLINK(dev, sl)
67✔
125
                                if (strv_extend(&list, sl) < 0)
60✔
126
                                        return log_oom();
×
127

128
                        strv_sort(list);
7✔
129
                }
130

131
                if (ret_devices) {
7✔
132
                        uint64_t diskseq = UINT64_MAX;
×
133
                        r = sd_device_get_diskseq(dev, &diskseq);
×
134
                        if (r < 0)
×
135
                                log_debug_errno(r, "Failed to acquire diskseq of device '%s', ignoring: %m", node);
×
136

137
                        if (!GREEDY_REALLOC(l, n+1))
×
138
                                return log_oom();
×
139

140
                        _cleanup_free_ char *m = strdup(node);
×
141
                        if (!m)
×
142
                                return log_oom();
×
143

144
                        l[n++] = (BlockDevice) {
×
145
                                .node = TAKE_PTR(m),
×
146
                                .symlinks = TAKE_PTR(list),
×
147
                                .diskseq = diskseq,
148
                                .size = size,
149
                        };
150

151
                } else {
152
                        printf("%s\n", node);
7✔
153

154
                        if (FLAGS_SET(flags, BLOCKDEV_LIST_SHOW_SYMLINKS))
7✔
155
                                STRV_FOREACH(i, list)
67✔
156
                                        printf("%s%s%s%s\n", on_tty() ? "    " : "", ansi_grey(), *i, ansi_normal());
180✔
157
                }
158
        }
159

160
        if (ret_devices)
6✔
161
                *ret_devices = TAKE_PTR(l);
2✔
162
        if (ret_n_devices)
6✔
163
                *ret_n_devices = n;
2✔
164

165
        return 0;
166
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc