#include <mntent.h>
#include <sys/stat.h>
#include <sys/wait.h>
+#include <sys/mount.h>
#include <talloc/talloc.h>
#include <list/list.h>
static int mount_device(struct discover_device *dev)
{
+ const char *fstype;
int rc;
if (!dev->device_path)
if (check_existing_mount(dev))
return 0;
+ fstype = discover_device_get_param(dev, "ID_FS_TYPE");
+ if (!fstype)
+ return 0;
+
dev->mount_path = join_paths(dev, mount_base(),
dev->device_path);
goto err_free;
}
- rc = process_run_simple(dev, pb_system_apps.mount,
- dev->device_path, dev->mount_path,
- "-o", "ro", NULL);
+ pb_log("mounting device %s read-only\n", dev->device_path);
+ errno = 0;
+ rc = mount(dev->device_path, dev->mount_path, fstype,
+ MS_RDONLY | MS_SILENT, "");
if (!rc) {
dev->mounted = true;
dev->mounted_rw = false;
return 0;
}
+ pb_log("couldn't mount device %s: mount failed: %s\n",
+ dev->device_path, strerror(errno));
+
pb_rmdir_recursive(mount_base(), dev->mount_path);
err_free:
talloc_free(dev->mount_path);
static int umount_device(struct discover_device *dev)
{
- int status;
+ int rc;
if (!dev->mounted || !dev->unmount)
return 0;
- status = process_run_simple(dev, pb_system_apps.umount,
- dev->mount_path, NULL);
-
- if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+ pb_log("unmounting device %s\n", dev->device_path);
+ rc = umount(dev->mount_path);
+ if (rc)
return -1;
dev->mounted = false;
if (dev->mounted_rw)
return 0;
- rc = process_run_simple(dev, pb_system_apps.mount, dev->mount_path,
- "-o", "remount,rw", NULL);
+ pb_log("remounting device %s read-write\n", dev->device_path);
+ rc = mount(dev->device_path, dev->mount_path, "",
+ MS_REMOUNT | MS_SILENT, "");
if (rc)
return -1;
if (!release)
return;
- process_run_simple(dev, pb_system_apps.mount, dev->mount_path,
- "-o", "remount,ro", NULL);
+ pb_log("remounting device %s read-only\n", dev->device_path);
+ mount(dev->device_path, dev->mount_path, "",
+ MS_REMOUNT | MS_RDONLY | MS_SILENT, "");
dev->mounted_rw = false;
}