#undef LOG_TAG
#define LOG_TAG "SESSIOND"
#include <dlog.h>
+#include <fcntl.h>
#include "dir_backend_fixed_size.hpp"
#include "os_ops.hpp"
static void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB)
{
+ // Pre-create empty file is needed for VD only, which uses obsolete mkfs.ext4 from 2013
+ int fd = open(image_path.c_str(), O_WRONLY | O_CREAT| O_TRUNC, 0777);
+ if (fd < 0)
+ throw std::runtime_error("Unable to create empty file to contain subsession filesystem: %m");
+ close(fd);
+ fd = -1;
+
const auto child_pid = OS::throwing_fork();
if (child_pid == 0) {
execl
( mkfs.data(), mkfs.data() /* argv[0] convention */
- , "-t", "ext4"
+ , "-F" /* dangerous, but needed for old mkfs.ext4 */
, "-E", owner_arg.c_str()
, "-m", "0"
, image_path.c_str()
_exit(1);
} else {
- OS::throw_if_child_failed(child_pid, "mkfs.ext4 failed!");
+ try {
+ OS::throw_if_child_failed(child_pid, "mkfs.ext4 failed!");
+ } catch (std::exception& ex) {
+ unlink(image_path.c_str());
+ throw;
+ }
}
}