From: Michael Tremer Date: Sun, 17 Jul 2022 18:34:09 +0000 (+0000) Subject: mount: Move pakfire_bind() into mount.c X-Git-Tag: 0.9.28~692 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=163851bc7ee1d2fb7aaf1ed4d41799d0797f3e72;p=pakfire.git mount: Move pakfire_bind() into mount.c There are no functional changes, but this function rather belongs here, and as a bonus, we get to make pakfire_mount() static and declutter pakfire.c slightly. Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/pakfire.c b/src/_pakfire/pakfire.c index b9b3eb3be..cc42fddb4 100644 --- a/src/_pakfire/pakfire.c +++ b/src/_pakfire/pakfire.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include diff --git a/src/libpakfire/build.c b/src/libpakfire/build.c index 66a21fb5d..230d2c0dd 100644 --- a/src/libpakfire/build.c +++ b/src/libpakfire/build.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include diff --git a/src/libpakfire/include/pakfire/mount.h b/src/libpakfire/include/pakfire/mount.h index 20330e08c..f47184a6b 100644 --- a/src/libpakfire/include/pakfire/mount.h +++ b/src/libpakfire/include/pakfire/mount.h @@ -18,18 +18,20 @@ # # #############################################################################*/ -#ifdef PAKFIRE_PRIVATE - -#include +#ifndef PAKFIRE_MOUNT_H +#define PAKFIRE_MOUNT_H #include -int pakfire_mount_list(struct pakfire* pakfire); +int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags); -int pakfire_mount(struct pakfire* pakfire, const char* source, const char* target, - const char* filesystemtype, unsigned long mountflags, const void* data); +#ifdef PAKFIRE_PRIVATE + +int pakfire_mount_list(struct pakfire* pakfire); int pakfire_mount_all(struct pakfire* pakfire); int pakfire_umount_all(struct pakfire* pakfire); #endif /* PAKFIRE_PRIVATE */ + +#endif /* PAKFIRE_MOUNT_H */ diff --git a/src/libpakfire/include/pakfire/pakfire.h b/src/libpakfire/include/pakfire/pakfire.h index 1b855c011..835bc4705 100644 --- a/src/libpakfire/include/pakfire/pakfire.h +++ b/src/libpakfire/include/pakfire/pakfire.h @@ -74,8 +74,6 @@ const char* pakfire_get_path(struct pakfire* pakfire); int pakfire_clean(struct pakfire* pakfire, int flags); int pakfire_refresh(struct pakfire* pakfire, int flags); -int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags); - int pakfire_list_keys(struct pakfire* pakfire, struct pakfire_key*** keys); int pakfire_copy_in(struct pakfire* pakfire, const char* src, const char* dst); diff --git a/src/libpakfire/mount.c b/src/libpakfire/mount.c index 52eb381cb..e563449f7 100644 --- a/src/libpakfire/mount.c +++ b/src/libpakfire/mount.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -165,7 +166,7 @@ int pakfire_is_mountpoint(struct pakfire* pakfire, const char* path) { __pakfire_is_mountpoint, path); } -int pakfire_mount(struct pakfire* pakfire, const char* source, const char* target, +static int pakfire_mount(struct pakfire* pakfire, const char* source, const char* target, const char* fstype, unsigned long mflags, const void* data) { const char* options = (const char*)data; int r; @@ -432,3 +433,53 @@ int pakfire_umount_all(struct pakfire* pakfire) { return pakfire_mount_foreach(pakfire, MNT_ITER_BACKWARD, __pakfire_umount, NULL); } + +PAKFIRE_EXPORT int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags) { + struct stat st; + char mountpoint[PATH_MAX]; + + if (!dst) + dst = src; + + int r = pakfire_make_path(pakfire, mountpoint, dst); + if (r < 0) + return 1; + + DEBUG(pakfire, "Bind-mounting %s to %s\n", src, mountpoint); + + r = stat(src, &st); + if (r < 0) { + ERROR(pakfire, "Could not stat %s: %m\n", src); + return 1; + } + + // Make sure the mountpoint exists + switch (st.st_mode & S_IFMT) { + case S_IFDIR: + r = pakfire_mkdir(mountpoint, 0); + if (r && errno != EEXIST) + return r; + break; + + case S_IFREG: + case S_IFLNK: + // Make parent directory + r = pakfire_mkparentdir(mountpoint, 0); + if (r) + return r; + + // Create a file + FILE* f = fopen(mountpoint, "w"); + if (!f) + return 1; + fclose(f); + break; + + default: + errno = ENOTSUP; + return 1; + } + + // Perform mount + return pakfire_mount(pakfire, src, mountpoint, NULL, flags|MS_BIND, NULL); +} diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 0c5bc8833..da24e4fd0 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -873,56 +873,6 @@ int __pakfire_make_path(struct pakfire* pakfire, char* dst, size_t length, const return __pakfire_path_join(dst, length, pakfire->path, path); } -PAKFIRE_EXPORT int pakfire_bind(struct pakfire* pakfire, const char* src, const char* dst, int flags) { - struct stat st; - char mountpoint[PATH_MAX]; - - if (!dst) - dst = src; - - int r = pakfire_make_path(pakfire, mountpoint, dst); - if (r < 0) - return 1; - - DEBUG(pakfire, "Bind-mounting %s to %s\n", src, mountpoint); - - r = stat(src, &st); - if (r < 0) { - ERROR(pakfire, "Could not stat %s: %m\n", src); - return 1; - } - - // Make sure the mountpoint exists - switch (st.st_mode & S_IFMT) { - case S_IFDIR: - r = pakfire_mkdir(mountpoint, 0); - if (r && errno != EEXIST) - return r; - break; - - case S_IFREG: - case S_IFLNK: - // Make parent directory - r = pakfire_mkparentdir(mountpoint, 0); - if (r) - return r; - - // Create a file - FILE* f = fopen(mountpoint, "w"); - if (!f) - return 1; - fclose(f); - break; - - default: - errno = ENOTSUP; - return 1; - } - - // Perform mount - return pakfire_mount(pakfire, src, mountpoint, NULL, flags|MS_BIND, NULL); -} - gpgme_ctx_t pakfire_get_gpgctx(struct pakfire* pakfire) { return pakfire->gpgctx; }