@@ -14,6 +14,9 @@
#include <fcntl.h>
#include <sys/file.h>
#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/uio.h>
#include <dirent.h>
#include "swupdate.h"
#include "util.h"
@@ -492,3 +495,55 @@ unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base)
}
return result;
}
+
+int swupdate_mount(const char *device, const char *dir, const char *fstype)
+{
+#if defined(__linux__)
+ return mount(device, dir, fstype, 0, NULL);
+#elif defined(__FreeBSD__)
+ int iovlen = 8;
+ struct iovec iov[iovlen];
+ int mntflags = 0;
+ char errmsg[255];
+ memset(errmsg, 0, sizeof(errmsg));
+ iov[0].iov_base = (void*)"fstype";
+ iov[0].iov_len = strlen("fstype") + 1;
+ iov[1].iov_base = (void*)fstype;
+ iov[1].iov_len = strlen(fstype) + 1;
+ iov[2].iov_base = (void*)"fspath";
+ iov[2].iov_len = strlen("fspath") + 1;
+ iov[3].iov_base = (void*)dir;
+ iov[3].iov_len = strlen(dir) + 1;
+ iov[4].iov_base = (void*)"from";
+ iov[4].iov_len = strlen("from") + 1;
+ iov[5].iov_base = (void*)device;
+ iov[5].iov_len = strlen(device) + 1;
+ /* The underlying fs driver may require a
+ buffer for an error message, even if we
+ do not use it here. */
+ iov[6].iov_base = (void*)"errmsg";
+ iov[6].iov_len = strlen("errmsg") + 1;
+ iov[7].iov_base = errmsg;
+ iov[7].iov_len = strlen(errmsg) + 1;
+ return nmount(iov, iovlen, mntflags);
+#else
+ /* Not implemented for this OS, no specific errno. */
+ errno = 0;
+ return -1;
+#endif
+}
+
+int swupdate_umount(const char *dir)
+{
+#if defined(__linux__)
+ return umount(dir);
+#elif defined(__FreeBSD__)
+ int mntflags = 0;
+ return unmount(dir, mntflags);
+#else
+ /* Not implemented for this OS, no specific errno. */
+ errno = 0;
+ return -1;
+#endif
+}
+
@@ -10,7 +10,6 @@
#include <unistd.h>
#include <stdbool.h>
#include <errno.h>
-#include <sys/mount.h>
#include "lua.h"
#include "lauxlib.h"
@@ -698,7 +697,7 @@ static int l_mount(lua_State *L) {
goto l_mount_free_exit;
}
- if (mount(device, target, filesystem, 0, NULL) == -1) {
+ if (swupdate_mount(device, target, filesystem) == -1) {
TRACE("Device %s with filesystem %s cannot be mounted: %s",
device, filesystem, strerror(errno));
goto l_mount_rmdir_exit;
@@ -724,7 +723,7 @@ l_mount_exit:
static int l_umount(lua_State *L) {
const char *target = luaL_checkstring(L, 1);
- if (umount(target) == -1) {
+ if (swupdate_umount(target) == -1) {
TRACE("Unable to unmount %s: %s\n", target, strerror(errno));
goto l_umount_exit;
}
@@ -8,7 +8,6 @@
#include <sys/types.h>
#include <stdio.h>
#include <sys/stat.h>
-#include <sys/mount.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -158,7 +157,7 @@ static int install_archive_image(struct img_type *img,
}
if (use_mount) {
- ret = mount(img->device, DATADST_DIR, img->filesystem, 0, NULL);
+ ret = swupdate_mount(img->device, DATADST_DIR, img->filesystem);
if (ret) {
ERROR("Device %s with filesystem %s cannot be mounted",
img->device, img->filesystem);
@@ -241,7 +240,7 @@ static int install_archive_image(struct img_type *img,
}
if (use_mount) {
- umount(DATADST_DIR);
+ swupdate_umount(DATADST_DIR);
}
return ret;
@@ -7,7 +7,6 @@
*/
#include <stdio.h>
-#include <sys/mount.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
@@ -55,7 +54,7 @@ static int install_raw_file(struct img_type *img,
}
if (use_mount) {
- ret = mount(img->device, DATADST_DIR, img->filesystem, 0, NULL);
+ ret = swupdate_mount(img->device, DATADST_DIR, img->filesystem);
if (ret) {
ERROR("Device %s with filesystem %s cannot be mounted",
img->device, img->filesystem);
@@ -84,7 +83,7 @@ static int install_raw_file(struct img_type *img,
close(fdout);
if (use_mount) {
- umount(DATADST_DIR);
+ swupdate_umount(DATADST_DIR);
}
return ret;
@@ -169,4 +169,7 @@ unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base);
const char* get_tmpdir(void);
const char* get_tmpdirscripts(void);
+int swupdate_mount(const char *device, const char *dir, const char *fstype);
+int swupdate_umount(const char *dir);
+
#endif