From 5e4a2efb479d3b3957f89fd3d318996541f00aeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 12 Jul 2012 21:03:17 +0200 Subject: [PATCH] ntfs: takes read only volumes into account #8449 * initial patch from kag_anil fixed by myself * fix log message in fs_write_attrib() --- .../kernel/file_systems/ntfs/attributes.c | 2 +- .../kernel/file_systems/ntfs/fs_func.c | 21 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/add-ons/kernel/file_systems/ntfs/attributes.c b/src/add-ons/kernel/file_systems/ntfs/attributes.c index 2d5aa4d304..c6fe2a56c8 100644 --- a/src/add-ons/kernel/file_systems/ntfs/attributes.c +++ b/src/add-ons/kernel/file_systems/ntfs/attributes.c @@ -582,7 +582,7 @@ fs_write_attrib(fs_volume *_vol, fs_vnode *_node, void *_cookie,off_t pos, ERROR("%s - ntfs_attr_pwrite returned less bytes than " "requested.\n", __FUNCTION__); if (bytesWritten <= 0) { - ERROR(("%s - ntfs_attr_pwrite()<=0\n", __FUNCTION__)); + ERROR("%s - ntfs_attr_pwrite()<=0\n", __FUNCTION__); *_length = 0; result = EINVAL; goto exit; diff --git a/src/add-ons/kernel/file_systems/ntfs/fs_func.c b/src/add-ons/kernel/file_systems/ntfs/fs_func.c index aee6569949..82736afb99 100644 --- a/src/add-ons/kernel/file_systems/ntfs/fs_func.c +++ b/src/add-ons/kernel/file_systems/ntfs/fs_func.c @@ -49,6 +49,23 @@ typedef struct identify_cookie { } identify_cookie; +static bool +is_device_read_only(const char *device) +{ + bool isReadOnly = false; + device_geometry geometry; + int fd = open(device, O_RDONLY | O_NOCACHE); + if (fd < 0) + return false; + + if (ioctl(fd, B_GET_GEOMETRY, &geometry) == 0) + isReadOnly = geometry.read_only; + + close(fd); + return isReadOnly; +} + + static status_t get_node_type(ntfs_inode* ni, int* _type) { @@ -234,12 +251,12 @@ fs_mount(fs_volume *_vol, const char *device, ulong flags, const char *args, "true"), "true") == 0; unload_driver_settings(handle); - if (ns->ro || (flags & B_MOUNT_READ_ONLY) != 0) { + if (ns->ro || (flags & B_MOUNT_READ_ONLY) != 0 + || is_device_read_only(device)) { mountFlags |= MS_RDONLY; ns->flags |= B_FS_IS_READONLY; } - // TODO: this does not take read-only volumes into account! ns->ntvol = utils_mount_volume(device, mountFlags, true); if (ns->ntvol != NULL) result = B_NO_ERROR;