Forced option ro when mounting a read-only device
External devices, such as USB keys, may have a switch to make them temporarily unwriteable. When such a device is plugged in, mount it as read-only by default.edge.strict_endians
parent
4d0b9163c9
commit
0b2a85b612
|
@ -512,8 +512,20 @@ ntfs_volume *ntfs_volume_startup(struct ntfs_device *dev, unsigned long flags)
|
|||
|
||||
/* ...->open needs bracketing to compile with glibc 2.7 */
|
||||
if ((dev->d_ops->open)(dev, NVolReadOnly(vol) ? O_RDONLY: O_RDWR)) {
|
||||
ntfs_log_perror("Error opening '%s'", dev->d_name);
|
||||
goto error_exit;
|
||||
if (!NVolReadOnly(vol) && (errno == EROFS)) {
|
||||
if ((dev->d_ops->open)(dev, O_RDONLY)) {
|
||||
ntfs_log_perror("Error opening read-only '%s'",
|
||||
dev->d_name);
|
||||
goto error_exit;
|
||||
} else {
|
||||
ntfs_log_info("Can only open '%s' as read-only\n",
|
||||
dev->d_name);
|
||||
NVolSetReadOnly(vol);
|
||||
}
|
||||
} else {
|
||||
ntfs_log_perror("Error opening '%s'", dev->d_name);
|
||||
goto error_exit;
|
||||
}
|
||||
}
|
||||
/* Attach the device to the volume. */
|
||||
vol->dev = dev;
|
||||
|
|
|
@ -3906,6 +3906,12 @@ int main(int argc, char *argv[])
|
|||
if (err)
|
||||
goto err_out;
|
||||
|
||||
/* Force read-only mount if the device was found read-only */
|
||||
if (!ctx->ro && NVolReadOnly(ctx->vol)) {
|
||||
ctx->ro = TRUE;
|
||||
if (ntfs_strinsert(&parsed_options, ",ro"))
|
||||
goto err_out;
|
||||
}
|
||||
/* We must do this after ntfs_open() to be able to set the blksize */
|
||||
if (ctx->blkdev && set_fuseblk_options(&parsed_options))
|
||||
goto err_out;
|
||||
|
|
|
@ -3798,6 +3798,12 @@ int main(int argc, char *argv[])
|
|||
if (err)
|
||||
goto err_out;
|
||||
|
||||
/* Force read-only mount if the device was found read-only */
|
||||
if (!ctx->ro && NVolReadOnly(ctx->vol)) {
|
||||
ctx->ro = TRUE;
|
||||
if (ntfs_strinsert(&parsed_options, ",ro"))
|
||||
goto err_out;
|
||||
}
|
||||
/* We must do this after ntfs_open() to be able to set the blksize */
|
||||
if (ctx->blkdev && set_fuseblk_options(&parsed_options))
|
||||
goto err_out;
|
||||
|
|
Loading…
Reference in New Issue