Bug Summary

File:build-scan/../src/partition/growfs.c
Warning:line 253, column 19
Null pointer passed to 1st parameter expecting 'nonnull'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name growfs.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I systemd-growfs.p -I . -I .. -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/partition/growfs.c
1/* SPDX-License-Identifier: LGPL-2.1+ */
2
3#include <errno(*__errno_location ()).h>
4#include <fcntl.h>
5#include <getopt.h>
6#include <linux1/magic.h>
7#include <sys/ioctl.h>
8#include <sys/mount.h>
9#include <sys/stat.h>
10#include <sys/types.h>
11#include <sys/vfs.h>
12
13#include "blockdev-util.h"
14#include "crypt-util.h"
15#include "device-nodes.h"
16#include "dissect-image.h"
17#include "escape.h"
18#include "fd-util.h"
19#include "format-util.h"
20#include "log.h"
21#include "missing.h"
22#include "mount-util.h"
23#include "parse-util.h"
24#include "path-util.h"
25#include "strv.h"
26
27const char *arg_target = NULL((void*)0);
28bool_Bool arg_dry_run = false0;
29
30static int resize_ext4(const char *path, int mountfd, int devfd, uint64_t numblocks, uint64_t blocksize) {
31 assert((uint64_t) (int) blocksize == blocksize)do { if ((__builtin_expect(!!(!((uint64_t) (int) blocksize ==
blocksize)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, (
"(uint64_t) (int) blocksize == blocksize"), "../src/partition/growfs.c"
, 31, __PRETTY_FUNCTION__); } while (0)
;
32
33 if (arg_dry_run)
34 return 0;
35
36 if (ioctl(mountfd, EXT4_IOC_RESIZE_FS(((1U) << (((0 +8)+8)+14)) | ((('f')) << (0 +8)) |
(((16)) << 0) | ((((sizeof(__u64)))) << ((0 +8)+
8)))
, &numblocks) != 0)
37 return log_error_errno(errno, "Failed to resize \"%s\" to %"PRIu64" blocks (ext4): %m",({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 38, __func__
, "Failed to resize \"%s\" to %""l" "u"" blocks (ext4): %m", path
, numblocks) : -abs(_e); })
38 path, numblocks)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 38, __func__
, "Failed to resize \"%s\" to %""l" "u"" blocks (ext4): %m", path
, numblocks) : -abs(_e); })
;
39
40 return 0;
41}
42
43static int resize_btrfs(const char *path, int mountfd, int devfd, uint64_t numblocks, uint64_t blocksize) {
44 struct btrfs_ioctl_vol_args args = {};
45 int r;
46
47 assert((uint64_t) (int) blocksize == blocksize)do { if ((__builtin_expect(!!(!((uint64_t) (int) blocksize ==
blocksize)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, (
"(uint64_t) (int) blocksize == blocksize"), "../src/partition/growfs.c"
, 47, __PRETTY_FUNCTION__); } while (0)
;
48
49 /* https://bugzilla.kernel.org/show_bug.cgi?id=118111 */
50 if (numblocks * blocksize < 256*1024*1024) {
51 log_warning("%s: resizing of btrfs volumes smaller than 256M is not supported", path)({ int _level = (((4))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 51, __func__, "%s: resizing of btrfs volumes smaller than 256M is not supported"
, path) : -abs(_e); })
;
52 return -EOPNOTSUPP95;
53 }
54
55 r = snprintf(args.name, sizeof(args.name), "%"PRIu64"l" "u", numblocks * blocksize);
56 /* The buffer is large enough for any number to fit... */
57 assert((size_t) r < sizeof(args.name))do { if ((__builtin_expect(!!(!((size_t) r < sizeof(args.name
))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("(size_t) r < sizeof(args.name)"
), "../src/partition/growfs.c", 57, __PRETTY_FUNCTION__); } while
(0)
;
58
59 if (arg_dry_run)
60 return 0;
61
62 if (ioctl(mountfd, BTRFS_IOC_RESIZE(((1U) << (((0 +8)+8)+14)) | (((0x94)) << (0 +8))
| (((3)) << 0) | ((((sizeof(struct btrfs_ioctl_vol_args
)))) << ((0 +8)+8)))
, &args) != 0)
63 return log_error_errno(errno, "Failed to resize \"%s\" to %"PRIu64" blocks (btrfs): %m",({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 64, __func__
, "Failed to resize \"%s\" to %""l" "u"" blocks (btrfs): %m",
path, numblocks) : -abs(_e); })
64 path, numblocks)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 64, __func__
, "Failed to resize \"%s\" to %""l" "u"" blocks (btrfs): %m",
path, numblocks) : -abs(_e); })
;
65
66 return 0;
67}
68
69#if HAVE_LIBCRYPTSETUP1
70static int resize_crypt_luks_device(dev_t devno, const char *fstype, dev_t main_devno) {
71 char devpath[DEV_NUM_PATH_MAX((sizeof("""/dev/block/""") - 1) + (2+(sizeof(dev_t) <= 1 ?
3 : sizeof(dev_t) <= 2 ? 5 : sizeof(dev_t) <= 4 ? 10 :
sizeof(dev_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(dev_t) >
8)]))) + 1 + (2+(sizeof(dev_t) <= 1 ? 3 : sizeof(dev_t) <=
2 ? 5 : sizeof(dev_t) <= 4 ? 10 : sizeof(dev_t) <= 8 ?
20 : sizeof(int[-2*(sizeof(dev_t) > 8)]))))
], main_devpath[DEV_NUM_PATH_MAX((sizeof("""/dev/block/""") - 1) + (2+(sizeof(dev_t) <= 1 ?
3 : sizeof(dev_t) <= 2 ? 5 : sizeof(dev_t) <= 4 ? 10 :
sizeof(dev_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(dev_t) >
8)]))) + 1 + (2+(sizeof(dev_t) <= 1 ? 3 : sizeof(dev_t) <=
2 ? 5 : sizeof(dev_t) <= 4 ? 10 : sizeof(dev_t) <= 8 ?
20 : sizeof(int[-2*(sizeof(dev_t) > 8)]))))
];
72 _cleanup_close___attribute__((cleanup(closep))) int main_devfd = -1;
73 _cleanup_(crypt_freep)__attribute__((cleanup(crypt_freep))) struct crypt_device *cd = NULL((void*)0);
74 uint64_t size;
75 int r;
76
77 xsprintf_dev_num_path(main_devpath, "block", main_devno)do { if ((__builtin_expect(!!(!(((size_t) snprintf(main_devpath
, __extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(main_devpath), typeof(&*(main_devpath))), sizeof(
main_devpath)/sizeof((main_devpath)[0]), ((void)0))), "/dev/%s/%u:%u"
, "block", gnu_dev_major (main_devno), gnu_dev_minor (main_devno
)) < (__extension__ (__builtin_choose_expr( !__builtin_types_compatible_p
(typeof(main_devpath), typeof(&*(main_devpath))), sizeof(
main_devpath)/sizeof((main_devpath)[0]), ((void)0))))))),0)))
log_assert_failed_realm(LOG_REALM_SYSTEMD, ("xsprintf: " "main_devpath"
"[] must be big enough"), "../src/partition/growfs.c", 77, __PRETTY_FUNCTION__
); } while (0)
;
78 main_devfd = open(main_devpath, O_RDONLY00|O_CLOEXEC02000000);
79 if (main_devfd < 0)
80 return log_error_errno(errno, "Failed to open \"%s\": %m", main_devpath)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 80, __func__
, "Failed to open \"%s\": %m", main_devpath) : -abs(_e); })
;
81
82 if (ioctl(main_devfd, BLKGETSIZE64(((2U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8))
| (((114)) << 0) | ((((sizeof(size_t)))) << ((0 +
8)+8)))
, &size) != 0)
83 return log_error_errno(errno, "Failed to query size of \"%s\" (before resize): %m",({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 84, __func__
, "Failed to query size of \"%s\" (before resize): %m", main_devpath
) : -abs(_e); })
84 main_devpath)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 84, __func__
, "Failed to query size of \"%s\" (before resize): %m", main_devpath
) : -abs(_e); })
;
85
86 log_debug("%s is %"PRIu64" bytes", main_devpath, size)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 86, __func__, "%s is %""l" "u"
" bytes", main_devpath, size) : -abs(_e); })
;
87
88 xsprintf_dev_num_path(devpath, "block", devno)do { if ((__builtin_expect(!!(!(((size_t) snprintf(devpath, __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(devpath), typeof(&*(devpath))), sizeof(devpath)/sizeof((
devpath)[0]), ((void)0))), "/dev/%s/%u:%u", "block", gnu_dev_major
(devno), gnu_dev_minor (devno)) < (__extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(devpath), typeof(&
*(devpath))), sizeof(devpath)/sizeof((devpath)[0]), ((void)0)
)))))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("xsprintf: "
"devpath" "[] must be big enough"), "../src/partition/growfs.c"
, 88, __PRETTY_FUNCTION__); } while (0)
;
89 r = crypt_init(&cd, devpath);
90 if (r < 0)
91 return log_error_errno(r, "crypt_init(\"%s\") failed: %m", devpath)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 91, __func__, "crypt_init(\"%s\") failed: %m"
, devpath) : -abs(_e); })
;
92
93 crypt_set_log_callback(cd, cryptsetup_log_glue, NULL((void*)0));
94
95 r = crypt_load(cd, CRYPT_LUKS((void*)0), NULL((void*)0));
96 if (r < 0)
97 return log_debug_errno(r, "Failed to load LUKS metadata for %s: %m", devpath)({ int _level = ((7)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 97, __func__, "Failed to load LUKS metadata for %s: %m"
, devpath) : -abs(_e); })
;
98
99 if (arg_dry_run)
100 return 0;
101
102 r = crypt_resize(cd, main_devpath, 0);
103 if (r < 0)
104 return log_error_errno(r, "crypt_resize() of %s failed: %m", devpath)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 104, __func__, "crypt_resize() of %s failed: %m"
, devpath) : -abs(_e); })
;
105
106 if (ioctl(main_devfd, BLKGETSIZE64(((2U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8))
| (((114)) << 0) | ((((sizeof(size_t)))) << ((0 +
8)+8)))
, &size) != 0)
107 log_warning_errno(errno, "Failed to query size of \"%s\" (after resize): %m",({ int _level = ((4)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 108, __func__
, "Failed to query size of \"%s\" (after resize): %m", devpath
) : -abs(_e); })
108 devpath)({ int _level = ((4)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 108, __func__
, "Failed to query size of \"%s\" (after resize): %m", devpath
) : -abs(_e); })
;
109 else
110 log_debug("%s is now %"PRIu64" bytes", main_devpath, size)({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 110, __func__, "%s is now %""l"
"u"" bytes", main_devpath, size) : -abs(_e); })
;
111
112 return 1;
113}
114#endif
115
116static int maybe_resize_slave_device(const char *mountpath, dev_t main_devno) {
117 dev_t devno;
118 char devpath[DEV_NUM_PATH_MAX((sizeof("""/dev/block/""") - 1) + (2+(sizeof(dev_t) <= 1 ?
3 : sizeof(dev_t) <= 2 ? 5 : sizeof(dev_t) <= 4 ? 10 :
sizeof(dev_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(dev_t) >
8)]))) + 1 + (2+(sizeof(dev_t) <= 1 ? 3 : sizeof(dev_t) <=
2 ? 5 : sizeof(dev_t) <= 4 ? 10 : sizeof(dev_t) <= 8 ?
20 : sizeof(int[-2*(sizeof(dev_t) > 8)]))))
];
119 _cleanup_free___attribute__((cleanup(freep))) char *fstype = NULL((void*)0);
120 int r;
121
122#if HAVE_LIBCRYPTSETUP1
123 crypt_set_log_callback(NULL((void*)0), cryptsetup_log_glue, NULL((void*)0));
124 crypt_set_debug_level(1);
125#endif
126
127 r = get_block_device_harder(mountpath, &devno);
128 if (r < 0)
129 return log_error_errno(r, "Failed to determine underlying block device of \"%s\": %m",({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 130, __func__, "Failed to determine underlying block device of \"%s\": %m"
, mountpath) : -abs(_e); })
130 mountpath)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 130, __func__, "Failed to determine underlying block device of \"%s\": %m"
, mountpath) : -abs(_e); })
;
131
132 log_debug("Underlying device %d:%d, main dev %d:%d, %s",({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 135, __func__, "Underlying device %d:%d, main dev %d:%d, %s"
, gnu_dev_major (devno), gnu_dev_minor (devno), gnu_dev_major
(main_devno), gnu_dev_minor (main_devno), devno == main_devno
? "same" : "different") : -abs(_e); })
133 major(devno), minor(devno),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 135, __func__, "Underlying device %d:%d, main dev %d:%d, %s"
, gnu_dev_major (devno), gnu_dev_minor (devno), gnu_dev_major
(main_devno), gnu_dev_minor (main_devno), devno == main_devno
? "same" : "different") : -abs(_e); })
134 major(main_devno), minor(main_devno),({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 135, __func__, "Underlying device %d:%d, main dev %d:%d, %s"
, gnu_dev_major (devno), gnu_dev_minor (devno), gnu_dev_major
(main_devno), gnu_dev_minor (main_devno), devno == main_devno
? "same" : "different") : -abs(_e); })
135 devno == main_devno ? "same" : "different")({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 135, __func__, "Underlying device %d:%d, main dev %d:%d, %s"
, gnu_dev_major (devno), gnu_dev_minor (devno), gnu_dev_major
(main_devno), gnu_dev_minor (main_devno), devno == main_devno
? "same" : "different") : -abs(_e); })
;
136 if (devno == main_devno)
137 return 0;
138
139 xsprintf_dev_num_path(devpath, "block", devno)do { if ((__builtin_expect(!!(!(((size_t) snprintf(devpath, __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(devpath), typeof(&*(devpath))), sizeof(devpath)/sizeof((
devpath)[0]), ((void)0))), "/dev/%s/%u:%u", "block", gnu_dev_major
(devno), gnu_dev_minor (devno)) < (__extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(devpath), typeof(&
*(devpath))), sizeof(devpath)/sizeof((devpath)[0]), ((void)0)
)))))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("xsprintf: "
"devpath" "[] must be big enough"), "../src/partition/growfs.c"
, 139, __PRETTY_FUNCTION__); } while (0)
;
140 r = probe_filesystem(devpath, &fstype);
141 if (r == -EUCLEAN117)
142 return log_warning_errno(r, "Cannot reliably determine probe \"%s\", refusing to proceed.", devpath)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 142, __func__, "Cannot reliably determine probe \"%s\", refusing to proceed."
, devpath) : -abs(_e); })
;
143 if (r < 0)
144 return log_warning_errno(r, "Failed to probe \"%s\": %m", devpath)({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 144, __func__, "Failed to probe \"%s\": %m"
, devpath) : -abs(_e); })
;
145
146#if HAVE_LIBCRYPTSETUP1
147 if (streq_ptr(fstype, "crypto_LUKS"))
148 return resize_crypt_luks_device(devno, fstype, main_devno);
149#endif
150
151 log_debug("Don't know how to resize %s of type %s, ignoring", devpath, strnull(fstype))({ int _level = (((7))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 151, __func__, "Don't know how to resize %s of type %s, ignoring"
, devpath, strnull(fstype)) : -abs(_e); })
;
152 return 0;
153}
154
155static void help(void) {
156 printf("%s [OPTIONS...] /path/to/mountpoint\n\n"
157 "Grow filesystem or encrypted payload to device size.\n\n"
158 "Options:\n"
159 " -h --help Show this help and exit\n"
160 " --version Print version string and exit\n"
161 " -n --dry-run Just print what would be done\n"
162 , program_invocation_short_name);
163}
164
165static int parse_argv(int argc, char *argv[]) {
166 enum {
167 ARG_VERSION = 0x100,
168 };
169
170 int c;
171
172 static const struct option options[] = {
173 { "help", no_argument0, NULL((void*)0), 'h' },
174 { "version" , no_argument0, NULL((void*)0), ARG_VERSION },
175 { "dry-run", no_argument0, NULL((void*)0), 'n' },
176 {}
177 };
178
179 assert(argc >= 0)do { if ((__builtin_expect(!!(!(argc >= 0)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("argc >= 0"), "../src/partition/growfs.c"
, 179, __PRETTY_FUNCTION__); } while (0)
;
180 assert(argv)do { if ((__builtin_expect(!!(!(argv)),0))) log_assert_failed_realm
(LOG_REALM_SYSTEMD, ("argv"), "../src/partition/growfs.c", 180
, __PRETTY_FUNCTION__); } while (0)
;
181
182 while ((c = getopt_long(argc, argv, "hn", options, NULL((void*)0))) >= 0)
183 switch(c) {
184 case 'h':
185 help();
186 return 0;
187
188 case ARG_VERSION:
189 version();
190 return 0;
191
192 case 'n':
193 arg_dry_run = true1;
194 break;
195
196 case '?':
197 return -EINVAL22;
198
199 default:
200 assert_not_reached("Unhandled option")do { log_assert_failed_unreachable_realm(LOG_REALM_SYSTEMD, (
"Unhandled option"), "../src/partition/growfs.c", 200, __PRETTY_FUNCTION__
); } while (0)
;
201 }
202
203 if (optind + 1 != argc) {
204 log_error("%s excepts exactly one argument (the mount point).",({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 205, __func__, "%s excepts exactly one argument (the mount point)."
, program_invocation_short_name) : -abs(_e); })
205 program_invocation_short_name)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 205, __func__, "%s excepts exactly one argument (the mount point)."
, program_invocation_short_name) : -abs(_e); })
;
206 return -EINVAL22;
207 }
208
209 arg_target = argv[optind];
210
211 return 1;
212}
213
214int main(int argc, char *argv[]) {
215 dev_t devno;
216 _cleanup_close___attribute__((cleanup(closep))) int mountfd = -1, devfd = -1;
217 int blocksize;
218 uint64_t size, numblocks;
219 char devpath[DEV_NUM_PATH_MAX((sizeof("""/dev/block/""") - 1) + (2+(sizeof(dev_t) <= 1 ?
3 : sizeof(dev_t) <= 2 ? 5 : sizeof(dev_t) <= 4 ? 10 :
sizeof(dev_t) <= 8 ? 20 : sizeof(int[-2*(sizeof(dev_t) >
8)]))) + 1 + (2+(sizeof(dev_t) <= 1 ? 3 : sizeof(dev_t) <=
2 ? 5 : sizeof(dev_t) <= 4 ? 10 : sizeof(dev_t) <= 8 ?
20 : sizeof(int[-2*(sizeof(dev_t) > 8)]))))
], fb[FORMAT_BYTES_MAX8];
220 struct statfs sfs;
221 int r;
222
223 log_set_target(LOG_TARGET_AUTO);
224 log_parse_environment()log_parse_environment_realm(LOG_REALM_SYSTEMD);
225 log_open();
226
227 r = parse_argv(argc, argv);
228 if (r < 0)
1
Assuming 'r' is >= 0
2
Taking false branch
229 return EXIT_FAILURE1;
230 if (r == 0)
3
Assuming 'r' is not equal to 0
4
Taking false branch
231 return EXIT_SUCCESS0;
232
233 r = path_is_mount_point(arg_target, NULL((void*)0), 0);
234 if (r < 0) {
5
Assuming 'r' is >= 0
6
Taking false branch
235 log_error_errno(r, "Failed to check if \"%s\" is a mount point: %m", arg_target)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 235, __func__, "Failed to check if \"%s\" is a mount point: %m"
, arg_target) : -abs(_e); })
;
236 return EXIT_FAILURE1;
237 }
238 if (r == 0) {
7
Assuming 'r' is not equal to 0
8
Taking false branch
239 log_error_errno(r, "\"%s\" is not a mount point: %m", arg_target)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 239, __func__, "\"%s\" is not a mount point: %m"
, arg_target) : -abs(_e); })
;
240 return EXIT_FAILURE1;
241 }
242
243 r = get_block_device(arg_target, &devno);
244 if (r < 0) {
9
Assuming 'r' is >= 0
10
Taking false branch
245 log_error_errno(r, "Failed to determine block device of \"%s\": %m", arg_target)({ int _level = ((3)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 245, __func__, "Failed to determine block device of \"%s\": %m"
, arg_target) : -abs(_e); })
;
246 return EXIT_FAILURE1;
247 }
248
249 r = maybe_resize_slave_device(arg_target, devno);
250 if (r < 0)
11
Assuming 'r' is >= 0
12
Taking false branch
251 return EXIT_FAILURE1;
252
253 mountfd = open(arg_target, O_RDONLY00|O_CLOEXEC02000000);
13
Null pointer passed to 1st parameter expecting 'nonnull'
254 if (mountfd < 0) {
255 log_error_errno(errno, "Failed to open \"%s\": %m", arg_target)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 255, __func__
, "Failed to open \"%s\": %m", arg_target) : -abs(_e); })
;
256 return EXIT_FAILURE1;
257 }
258
259 xsprintf_dev_num_path(devpath, "block", devno)do { if ((__builtin_expect(!!(!(((size_t) snprintf(devpath, __extension__
(__builtin_choose_expr( !__builtin_types_compatible_p(typeof
(devpath), typeof(&*(devpath))), sizeof(devpath)/sizeof((
devpath)[0]), ((void)0))), "/dev/%s/%u:%u", "block", gnu_dev_major
(devno), gnu_dev_minor (devno)) < (__extension__ (__builtin_choose_expr
( !__builtin_types_compatible_p(typeof(devpath), typeof(&
*(devpath))), sizeof(devpath)/sizeof((devpath)[0]), ((void)0)
)))))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("xsprintf: "
"devpath" "[] must be big enough"), "../src/partition/growfs.c"
, 259, __PRETTY_FUNCTION__); } while (0)
;
260 devfd = open(devpath, O_RDONLY00|O_CLOEXEC02000000);
261 if (devfd < 0) {
262 log_error_errno(errno, "Failed to open \"%s\": %m", devpath)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 262, __func__
, "Failed to open \"%s\": %m", devpath) : -abs(_e); })
;
263 return EXIT_FAILURE1;
264 }
265
266 if (ioctl(devfd, BLKBSZGET(((2U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8))
| (((112)) << 0) | ((((sizeof(size_t)))) << ((0 +
8)+8)))
, &blocksize) != 0) {
267 log_error_errno(errno, "Failed to query block size of \"%s\": %m", devpath)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 267, __func__
, "Failed to query block size of \"%s\": %m", devpath) : -abs
(_e); })
;
268 return EXIT_FAILURE1;
269 }
270
271 if (ioctl(devfd, BLKGETSIZE64(((2U) << (((0 +8)+8)+14)) | (((0x12)) << (0 +8))
| (((114)) << 0) | ((((sizeof(size_t)))) << ((0 +
8)+8)))
, &size) != 0) {
272 log_error_errno(errno, "Failed to query size of \"%s\": %m", devpath)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 272, __func__
, "Failed to query size of \"%s\": %m", devpath) : -abs(_e); }
)
;
273 return EXIT_FAILURE1;
274 }
275
276 if (size % blocksize != 0)
277 log_notice("Partition size %"PRIu64" is not a multiple of the blocksize %d,"({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 278, __func__, "Partition size %"
"l" "u"" is not a multiple of the blocksize %d," " ignoring %"
"l" "u"" bytes", size, blocksize, size % blocksize) : -abs(_e
); })
278 " ignoring %"PRIu64" bytes", size, blocksize, size % blocksize)({ int _level = (((5))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 278, __func__, "Partition size %"
"l" "u"" is not a multiple of the blocksize %d," " ignoring %"
"l" "u"" bytes", size, blocksize, size % blocksize) : -abs(_e
); })
;
279
280 numblocks = size / blocksize;
281
282 if (fstatfs(mountfd, &sfs) < 0) {
283 log_error_errno(errno, "Failed to stat file system \"%s\": %m", arg_target)({ int _level = ((3)), _e = (((*__errno_location ()))), _realm
= (LOG_REALM_SYSTEMD); (log_get_max_level_realm(_realm) >=
((_level) & 0x07)) ? log_internal_realm(((_realm) <<
10 | (_level)), _e, "../src/partition/growfs.c", 283, __func__
, "Failed to stat file system \"%s\": %m", arg_target) : -abs
(_e); })
;
284 return EXIT_FAILURE1;
285 }
286
287 switch(sfs.f_type) {
288 case EXT4_SUPER_MAGIC0xEF53:
289 r = resize_ext4(arg_target, mountfd, devfd, numblocks, blocksize);
290 break;
291 case BTRFS_SUPER_MAGIC0x9123683E:
292 r = resize_btrfs(arg_target, mountfd, devfd, numblocks, blocksize);
293 break;
294 default:
295 log_error("Don't know how to resize fs %llx on \"%s\"",({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 296, __func__, "Don't know how to resize fs %llx on \"%s\""
, (long long unsigned) sfs.f_type, arg_target) : -abs(_e); })
296 (long long unsigned) sfs.f_type, arg_target)({ int _level = (((3))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 296, __func__, "Don't know how to resize fs %llx on \"%s\""
, (long long unsigned) sfs.f_type, arg_target) : -abs(_e); })
;
297 return EXIT_FAILURE1;
298 }
299
300 if (r < 0)
301 return EXIT_FAILURE1;
302
303 log_info("Successfully resized \"%s\" to %s bytes (%"PRIu64" blocks of %d bytes).",({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 304, __func__, "Successfully resized \"%s\" to %s bytes (%"
"l" "u"" blocks of %d bytes).", arg_target, format_bytes(fb, sizeof
fb, size), numblocks, blocksize) : -abs(_e); })
304 arg_target, format_bytes(fb, sizeof fb, size), numblocks, blocksize)({ int _level = (((6))), _e = ((0)), _realm = (LOG_REALM_SYSTEMD
); (log_get_max_level_realm(_realm) >= ((_level) & 0x07
)) ? log_internal_realm(((_realm) << 10 | (_level)), _e
, "../src/partition/growfs.c", 304, __func__, "Successfully resized \"%s\" to %s bytes (%"
"l" "u"" blocks of %d bytes).", arg_target, format_bytes(fb, sizeof
fb, size), numblocks, blocksize) : -abs(_e); })
;
305 return EXIT_SUCCESS0;
306}