Add OS::do_resize2fs 54/324254/4
authorKarol Lewandowski <k.lewandowsk@samsung.com>
Tue, 13 May 2025 14:09:19 +0000 (16:09 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Tue, 20 May 2025 17:34:37 +0000 (19:34 +0200)
Change-Id: I7558a4e2f866a3b3990124cebf803f44ee3663df

packaging/sessiond.spec
src/service/src/os_ops.cpp
src/service/src/os_ops.hpp

index f3b8625aa28376430d94f37960877345dbe7562f..ea55f1ca5879af260721e7dacfa25fb7a094bef3 100644 (file)
@@ -18,6 +18,7 @@ BuildRequires: pkgconfig(libxml-2.0)
 BuildRequires: pkgconfig(pkgmgr-info)
 
 Requires:   /usr/sbin/mkfs.ext4
+Requires:   /usr/sbin/resize2fs
 
 %description
 
index 00768d13ffd2b9f588bfc81b8b01816e43bb295c..a66d4e815664e8a7aa750c3966b79079ba507a61 100644 (file)
@@ -152,6 +152,34 @@ void OS::do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB)
        }
 }
 
+void OS::do_resize2fs(const fs::path& fs_path, uint64_t size_kB)
+{
+       const auto child_pid = OS::throwing_fork();
+       if (child_pid == 0) {
+               const auto cmd = "/usr/sbin/resize2fs"sv;
+
+               const auto size_arg = std::to_string(size_kB);
+
+               const auto r = execl
+                       ( cmd.data(), cmd.data() /* argv[0] convention */
+                       , fs_path.c_str()
+                       , size_arg.c_str()
+                       , (char *) NULL
+               );
+
+               LOGE("Failed to execute `%s %s %s`: %m"
+                       , cmd.data()
+                       , fs_path.c_str()
+                       , size_arg.c_str()
+               );
+               assert(r == -1);
+
+               _exit(1);
+       } else {
+               OS::throw_if_child_failed(child_pid, "resize2fs failed!");
+       }
+}
+
 void OS::do_umount(const fs::path& path)
 {
        const auto child_pid = OS::throwing_fork();
index a365f497da9eef2c6bee527de3fd10ca132bd118..31c11d325be59d00c365ca37c7a155b434d08864 100644 (file)
@@ -18,6 +18,8 @@ namespace OS {
 
        void do_mkfs(const fs::path& image_path, int uid, int gid, uint64_t size_kB);
 
+       void do_resize2fs(const fs::path& fs_path, uint64_t size_kB);
+
        void do_mount(const fs::path& image_path, const fs::path& mount_path);
 
        void do_umount(const fs::path& path);