int pakfire_mount_make_mounpoint(struct pakfire* pakfire, const char* path);
+int pakfire_make_ramdisk(struct pakfire* pakfire, char* path, const char* args);
+
int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags);
int pakfire_mount_list(struct pakfire* pakfire);
return 0;
}
+int pakfire_make_ramdisk(struct pakfire* pakfire, char* path, const char* args) {
+ int r;
+
+ // Create a new temporary directory
+ char* p = pakfire_mkdtemp(path);
+ if (!p)
+ return -errno;
+
+ // Mount the ramdisk
+ r = pakfire_mount(pakfire, "pakfire_ramdisk", p, "tmpfs", 0, args);
+ if (r) {
+ ERROR_ERRNO(pakfire, r, "Could not mount ramdisk at %s (%s): %m\n", p, args);
+ return r;
+ }
+
+ DEBUG(pakfire, "Ramdisk mounted at %s (%s)\n", p, args);
+
+ return 0;
+}
+
int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags) {
struct stat st;
char mountpoint[PATH_MAX];
if (pakfire->destroy_on_free && *pakfire->path) {
DEBUG(pakfire, "Destroying %s\n", pakfire->path);
+ // Umount the ramdisk
+ r = umount2(pakfire->path, MNT_DETACH);
+ if (r)
+ ERROR(pakfire, "Could not umount ramdisk at %s: %m\n", pakfire->path);
+
// Destroy the temporary directory
pakfire_rmtree(pakfire->path, 0);
}
goto ERROR;
}
- // Generate a random path if none is set
+ // Create a ramdisk if no path was given
if (!path) {
- path = pakfire_mkdtemp(tempdir);
- if (!path) {
- r = -errno;
+ r = pakfire_make_ramdisk(p, tempdir, NULL);
+ if (r)
goto ERROR;
- }
+
+ // Use the ramdisk as path
+ path = tempdir;
// Destroy everything when done
p->destroy_on_free = 1;