]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-mount-util.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
5 #include "alloc-util.h"
6 #include "mount-util.h"
7 #include "string-util.h"
10 static void test_mount_option_mangle(void) {
14 assert_se(mount_option_mangle(NULL
, MS_RDONLY
|MS_NOSUID
, &f
, &opts
) == 0);
15 assert_se(f
== (MS_RDONLY
|MS_NOSUID
));
16 assert_se(opts
== NULL
);
18 assert_se(mount_option_mangle("", MS_RDONLY
|MS_NOSUID
, &f
, &opts
) == 0);
19 assert_se(f
== (MS_RDONLY
|MS_NOSUID
));
20 assert_se(opts
== NULL
);
22 assert_se(mount_option_mangle("ro,nosuid,nodev,noexec", 0, &f
, &opts
) == 0);
23 assert_se(f
== (MS_RDONLY
|MS_NOSUID
|MS_NODEV
|MS_NOEXEC
));
24 assert_se(opts
== NULL
);
26 assert_se(mount_option_mangle("ro,nosuid,nodev,noexec,mode=755", 0, &f
, &opts
) == 0);
27 assert_se(f
== (MS_RDONLY
|MS_NOSUID
|MS_NODEV
|MS_NOEXEC
));
28 assert_se(streq(opts
, "mode=755"));
31 assert_se(mount_option_mangle("rw,nosuid,foo,hogehoge,nodev,mode=755", 0, &f
, &opts
) == 0);
32 assert_se(f
== (MS_NOSUID
|MS_NODEV
));
33 assert_se(streq(opts
, "foo,hogehoge,mode=755"));
36 assert_se(mount_option_mangle("rw,nosuid,nodev,noexec,relatime,net_cls,net_prio", MS_RDONLY
, &f
, &opts
) == 0);
37 assert_se(f
== (MS_NOSUID
|MS_NODEV
|MS_NOEXEC
|MS_RELATIME
));
38 assert_se(streq(opts
, "net_cls,net_prio"));
41 assert_se(mount_option_mangle("rw,nosuid,nodev,relatime,size=1630748k,mode=700,uid=1000,gid=1000", MS_RDONLY
, &f
, &opts
) == 0);
42 assert_se(f
== (MS_NOSUID
|MS_NODEV
|MS_RELATIME
));
43 assert_se(streq(opts
, "size=1630748k,mode=700,uid=1000,gid=1000"));
46 assert_se(mount_option_mangle("size=1630748k,rw,gid=1000,,,nodev,relatime,,mode=700,nosuid,uid=1000", MS_RDONLY
, &f
, &opts
) == 0);
47 assert_se(f
== (MS_NOSUID
|MS_NODEV
|MS_RELATIME
));
48 assert_se(streq(opts
, "size=1630748k,gid=1000,mode=700,uid=1000"));
51 assert_se(mount_option_mangle("rw,exec,size=8143984k,nr_inodes=2035996,mode=755", MS_RDONLY
|MS_NOSUID
|MS_NOEXEC
|MS_NODEV
, &f
, &opts
) == 0);
52 assert_se(f
== (MS_NOSUID
|MS_NODEV
));
53 assert_se(streq(opts
, "size=8143984k,nr_inodes=2035996,mode=755"));
56 assert_se(mount_option_mangle("rw,relatime,fmask=0022,,,dmask=0022", MS_RDONLY
, &f
, &opts
) == 0);
57 assert_se(f
== MS_RELATIME
);
58 assert_se(streq(opts
, "fmask=0022,dmask=0022"));
61 assert_se(mount_option_mangle("rw,relatime,fmask=0022,dmask=0022,\"hogehoge", MS_RDONLY
, &f
, &opts
) < 0);
64 int main(int argc
, char *argv
[]) {
65 test_setup_logging(LOG_DEBUG
);
67 test_mount_option_mangle();