diff --git a/libntfs-3g/unix_io.c b/libntfs-3g/unix_io.c index bf46825d..5f2c825b 100644 --- a/libntfs-3g/unix_io.c +++ b/libntfs-3g/unix_io.c @@ -98,20 +98,20 @@ static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags) if (!dev->d_private) return -1; /* - * Open the device/file obtaining the file descriptor for exclusive - * access (but only if mounting r/w). + * Open file for exclusive access if mounting r/w. + * Fuseblk takes care about block devices. */ - if ((flags & O_RDWR) == O_RDWR) + if (!NDevBlock(dev) && (flags & O_RDWR) == O_RDWR) flags |= O_EXCL; *(int*)dev->d_private = open(dev->d_name, flags); if (*(int*)dev->d_private == -1) { err = errno; goto err_out; } - /* Setup our read-only flag. */ + if ((flags & O_RDWR) != O_RDWR) NDevSetReadOnly(dev); - /* Acquire exclusive (mandatory) lock on the whole device. */ + memset(&flk, 0, sizeof(flk)); if (NDevReadOnly(dev)) flk.l_type = F_RDLCK; @@ -121,14 +121,13 @@ static int ntfs_device_unix_io_open(struct ntfs_device *dev, int flags) flk.l_start = flk.l_len = 0LL; if (fcntl(DEV_FD(dev), F_SETLK, &flk)) { err = errno; - ntfs_log_debug("ntfs_device_unix_io_open: Could not lock %s for %s\n", - dev->d_name, NDevReadOnly(dev) ? "reading" : "writing"); + ntfs_log_perror("Failed to %s lock '%s'", NDevReadOnly(dev) ? + "read" : "write", dev->d_name); if (close(DEV_FD(dev))) - ntfs_log_perror("ntfs_device_unix_io_open: Warning: Could not " - "close %s", dev->d_name); + ntfs_log_perror("Failed to close '%s'", dev->d_name); goto err_out; } - /* Set our open flag. */ + NDevSetOpen(dev); return 0; err_out: diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index 6702f118..129e6b77 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -1562,23 +1562,24 @@ static void signal_handler(int arg __attribute__((unused))) fuse_exit((fuse_get_context())->fuse); } -static char *parse_mount_options(const char *org_options) +static char *parse_mount_options(const char *orig_opts) { char *options, *s, *opt, *val, *ret; BOOL no_def_opts = FALSE; /* - * +7 for "fsname=". - * +1 for comma. - * +1 for null-terminator. - * +PATH_MAX for resolved by realpath() device name. + * +7 fsname= + * +1 comma + * +1 null-terminator + * +21 ,blkdev,blksize=65536 + * +PATH_MAX resolved realpath() device name */ - ret = ntfs_malloc(strlen(def_opts) + strlen(org_options) + 9 + PATH_MAX); + ret = ntfs_malloc(strlen(def_opts) + strlen(orig_opts) + 64 + PATH_MAX); if (!ret) return NULL; *ret = 0; - options = strdup(org_options); + options = strdup(orig_opts); if (!options) { ntfs_log_perror("strdup failed"); return NULL; @@ -1974,6 +1975,11 @@ int main(int argc, char *argv[]) return 4; } + if (NDevBlock(ctx->vol->dev)) { + /* parsed_options already allocated enough space. */ + strcat(parsed_options, ",blkdev"); + } + /* Libfuse can't always find fusermount, so let's help it. */ if (setenv("PATH", ":/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin", 0)) ntfs_log_perror("WARNING: Failed to set $PATH\n");