]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/home/homework-mount.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #include "alloc-util.h"
7 #include "homework-mount.h"
9 #include "mount-util.h"
10 #include "path-util.h"
11 #include "string-util.h"
13 static const char *mount_options_for_fstype(const char *fstype
) {
14 if (streq(fstype
, "ext4"))
15 return "noquota,user_xattr";
16 if (streq(fstype
, "xfs"))
18 if (streq(fstype
, "btrfs"))
23 int home_mount_node(const char *node
, const char *fstype
, bool discard
, unsigned long flags
) {
24 _cleanup_free_
char *joined
= NULL
;
25 const char *options
, *discard_option
;
28 options
= mount_options_for_fstype(fstype
);
30 discard_option
= discard
? "discard" : "nodiscard";
33 joined
= strjoin(options
, ",", discard_option
);
39 options
= discard_option
;
41 r
= mount_verbose(LOG_ERR
, node
, "/run/systemd/user-home-mount", fstype
, flags
|MS_RELATIME
, strempty(options
));
45 log_info("Mounting file system completed.");
49 int home_unshare_and_mount(const char *node
, const char *fstype
, bool discard
, unsigned long flags
) {
52 if (unshare(CLONE_NEWNS
) < 0)
53 return log_error_errno(errno
, "Couldn't unshare file system namespace: %m");
55 r
= mount_verbose(LOG_ERR
, "/run", "/run", NULL
, MS_SLAVE
|MS_REC
, NULL
); /* Mark /run as MS_SLAVE in our new namespace */
59 (void) mkdir_p("/run/systemd/user-home-mount", 0700);
62 return home_mount_node(node
, fstype
, discard
, flags
);
67 int home_move_mount(const char *user_name_and_realm
, const char *target
) {
68 _cleanup_free_
char *subdir
= NULL
;
72 assert(user_name_and_realm
);
75 if (user_name_and_realm
) {
76 subdir
= path_join("/run/systemd/user-home-mount/", user_name_and_realm
);
82 d
= "/run/systemd/user-home-mount/";
84 (void) mkdir_p(target
, 0700);
86 r
= mount_verbose(LOG_ERR
, d
, target
, NULL
, MS_BIND
, NULL
);
90 r
= umount_verbose("/run/systemd/user-home-mount");
94 log_info("Moving to final mount point %s completed.", target
);