return subsession_path;
}
+fs::path DirBackendAddFixedSize::AddSubsessionPrepareFromTemplate (const fs::path& subsession_path, const fs::path& main_path, int uid, int gid) const
+{
+ fs::path template_path = main_path / ".template";
+ fs::copy(GetImagePathFromSubsessionPath(subsession_path), GetImagePathFromSubsessionPath(template_path));
+ do_resizefs(GetImagePathFromSubsessionPath(subsession_path);
+}
+
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
const int system_share_gid = OS::get_gid_from_name(system_share_group);
+ // Work off a temporary dir and then switch it at once so that it appears atomically
+ const auto tmp_subsession_path = backend.AddSubsessionPrepareFromTemplate
+ ( subsession_path, main_path,
+ , session_uid, system_share_gid
+ );
+ }
+ catch (std::exception const &ex) {
+ LOGE("Exception while creating user subsession data [session_uid=%d subsession_id=%s]: %s", session_uid, subsession_id.data(), ex.what());
+ throw std::runtime_error("Couldn't add user subsession data");
+ }
+}
+
+void add_user_subsession_internal(const int session_uid, const std::string_view subsession_id, const DirBackendAdd &backend)
+{
+ try {
+ fs::path main_path = get_main_dir_by_user_id(session_uid);
+
+ create_main_subdirectory(session_uid, main_path);
+
+ fs::path subsession_path = main_path / subsession_id;
+
+ if (fs::exists(subsession_path))
+ throw std::system_error(EEXIST, std::generic_category(),
+ "Subsession directory already exists");
+
+ const int system_share_gid = OS::get_gid_from_name(system_share_group);
+
// Work off a temporary dir and then switch it at once so that it appears atomically
const auto tmp_subsession_path = backend.AddSubsessionPrepare
( subsession_path
throw std::runtime_error("Couldn't enumerate user subsessions");
}
+void do_resizefs(const fs::path& image_path, uint64_t size_kB)
+{
+ const auto child_pid = OS::throwing_fork();
+ if (child_pid == 0) {
+ const auto cmd = "/usr/sbin/resize2fs"sv;
+
+ std::string size_arg = std::to_string(size_kB);
+
+ execl
+ ( cmd.data(), cmd.data() /* argv[0] convention */
+ , image_path.c_str()
+ , size_arg.c_str()
+ , (char *) NULL
+ );
+
+ _exit(1);
+ } else {
+ OS::throw_if_child_failed(child_pid, "resize2fs failed!");
+ }
+}
+
+
void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB)
{
const auto child_pid = OS::throwing_fork();
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_resize2fs(const fs::path& image_path, uint64_t size_kB);
void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB);
void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB, const fs::path& contents_path);
void do_mount(const fs::path& image_path, const fs::path& mount_path);