#include <dlog.h>
#include "dir_backend_fixed_size.hpp"
+#include "fs_helpers.hpp"
#include "os_ops.hpp"
#include <sys/mount.h>
return subsession_path;
}
-static void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB)
-{
- const auto child_pid = OS::throwing_fork();
- if (child_pid == 0) {
- const auto mkfs = "/usr/sbin/mkfs.ext2"sv;
-
- /* Would ideally be std::format instead of this ugly stack,
- * but some important downstream forks use obsolete gcc. */
- std::string owner_arg = "root_owner=";
- owner_arg += std::to_string(uid);
- owner_arg += ":";
- owner_arg += std::to_string(gid);
-
- std::string size_arg = std::to_string(size_kB);
-
- execl
- ( mkfs.data(), mkfs.data() /* argv[0] convention */
- , "-E", owner_arg.c_str()
- , "-m", "0"
- , image_path.c_str()
- , size_arg.c_str()
- , (char *) NULL
- );
-
- _exit(1);
- } else {
- OS::throw_if_child_failed(child_pid, "mkfs.ext2 failed!");
- }
-}
-
-static void do_mount(const fs::path& image_path, const fs::path& mount_path)
-{
- /* Don't just call mount() since there's some extra steps involved
- * in making it work properly, such as setting up a loop device,
- * that the mount binary does for us. */
-
- const auto child_pid = OS::throwing_fork();
- if (child_pid == 0) {
- const auto mount_exe = "/usr/bin/mount"sv;
-
- execl
- ( mount_exe.data(), mount_exe.data() /* argv[0] convention */
- , "-o", "loop"
- , image_path.c_str()
- , mount_path.c_str()
- , (char *) NULL
- );
-
- _exit(1);
- } else {
- OS::throw_if_child_failed(child_pid, "mount failed!");
- }
-}
-
-static void do_umount(const fs::path& path)
-{
- const auto child_pid = OS::throwing_fork();
- if (child_pid == 0) {
- const auto umount_exe = "/usr/bin/umount"sv;
-
- execl
- ( umount_exe.data(), umount_exe.data() /* argv[0] convention */
- , path.c_str()
- , (char *) NULL
- );
-
- _exit(1);
- } else {
- OS::throw_if_child_failed(child_pid, "umount failed!");
- }
-}
-
fs::path DirBackendAddFixedSize::AddSubsessionPrepare (const fs::path& subsession_path, int uid, int gid) const
{
/* Work off a temp image first so that the "real" image
return tmp_subsession_path;
}
-static void umount_and_remove (const fs::path& path) try {
- do_umount(path);
- fs::remove(path);
-} catch (const std::exception& ex) {
- LOGE("umount & rmdir (%s) failed!", path.c_str());
- throw;
-}
-
void DirBackendAddFixedSize::AddSubsessionCleanupFailure (const fs::path& tmpdir_path, const fs::path& subsession_path) const
{
auto tmp_image_path = DirBackendFixedSize::GetImagePathFromSubsessionPath(subsession_path);
namespace fs = std::filesystem;
using namespace std::string_literals;
+using namespace std::string_view_literals;
fs::path get_main_dir_by_user_id(const int uid)
{
throw std::runtime_error("Couldn't enumerate user subsessions");
}
+void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB)
+{
+ const auto child_pid = OS::throwing_fork();
+ if (child_pid == 0) {
+ const auto mkfs = "/usr/sbin/mkfs.ext2"sv;
+
+ /* Would ideally be std::format instead of this ugly stack,
+ * but some important downstream forks use obsolete gcc. */
+ std::string owner_arg = "root_owner=";
+ owner_arg += std::to_string(uid);
+ owner_arg += ":";
+ owner_arg += std::to_string(gid);
+
+ std::string size_arg = std::to_string(size_kB);
+
+ execl
+ ( mkfs.data(), mkfs.data() /* argv[0] convention */
+ , "-E", owner_arg.c_str()
+ , "-m", "0"
+ , image_path.c_str()
+ , size_arg.c_str()
+ , (char *) NULL
+ );
+
+ _exit(1);
+ } else {
+ OS::throw_if_child_failed(child_pid, "mkfs.ext2 failed!");
+ }
+}
+
+void do_mount(const fs::path& image_path, const fs::path& mount_path)
+{
+ /* Don't just call mount() since there's some extra steps involved
+ * in making it work properly, such as setting up a loop device,
+ * that the mount binary does for us. */
+
+ const auto child_pid = OS::throwing_fork();
+ if (child_pid == 0) {
+ const auto mount_exe = "/usr/bin/mount"sv;
+
+ execl
+ ( mount_exe.data(), mount_exe.data() /* argv[0] convention */
+ , "-o", "loop"
+ , image_path.c_str()
+ , mount_path.c_str()
+ , (char *) NULL
+ );
+
+ _exit(1);
+ } else {
+ OS::throw_if_child_failed(child_pid, "mount failed!");
+ }
+}
+
+void do_umount(const fs::path& path)
+{
+ const auto child_pid = OS::throwing_fork();
+ if (child_pid == 0) {
+ const auto umount_exe = "/usr/bin/umount"sv;
+
+ execl
+ ( umount_exe.data(), umount_exe.data() /* argv[0] convention */
+ , path.c_str()
+ , (char *) NULL
+ );
+
+ _exit(1);
+ } else {
+ OS::throw_if_child_failed(child_pid, "umount failed!");
+ }
+}
+
+void umount_and_remove (const fs::path& path) try {
+ do_umount(path);
+ fs::remove(path);
+} catch (const std::exception& ex) {
+ LOGE("umount & rmdir (%s) failed!", path.c_str());
+ throw;
+}
void remove_user_subsession(const int session_uid, const std::string_view subsession_id);
bool switch_user_subsession(const int session_uid, const std::string_view prev_subsession, const std::string_view next_subsession);
std::vector<std::string> get_user_list(const int session_uid);
+void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB);
+void do_mount(const fs::path& image_path, const fs::path& mount_path);
+void do_umount(const fs::path& path);
+void umount_and_remove (const fs::path& path);
constexpr static std::string_view main_dir_name = "subsession";
constexpr static std::string_view system_share_group = "system_share";
constexpr static std::string_view main_dir_smack = "User::Home";
+