Ticket #8449: fs_func_c_final.patch

File fs_func_c_final.patch, 1.2 KB (added by kag_anil, 12 years ago)

Conforming to the suggestions made by bonefish

  • src/add-ons/kernel/file_systems/ntfs/fs_func.c

    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 166fbbc..2a023fb 100644
    a b typedef struct identify_cookie {  
    4848    char label[256];
    4949} identify_cookie;
    5050
     51bool
     52is_device_read_only(const char *device)
     53{
     54    bool isReadOnly = FALSE;
     55    int fd = open(device, O_RDONLY | O_NOCACHE);
     56
     57    if (fd >= 0) {
     58        device_geometry geometry;
     59       
     60        if (ioctl(fd, B_GET_GEOMETRY, &geometry) == 0) {
     61            if (geometry.read_only) {
     62                isReadOnly = TRUE;
     63            }
     64        }
     65
     66        close(fd);
     67    }
     68    return isReadOnly;
     69}
    5170
    5271static status_t
    5372get_node_type(ntfs_inode* ni, int* _type)
    fs_mount(fs_volume *_vol, const char *device, ulong flags, const char *args,  
    234253        "true"), "true") == 0;
    235254    unload_driver_settings(handle);
    236255
    237     if (ns->ro || (flags & B_MOUNT_READ_ONLY) != 0) {
     256    if (ns->ro || (flags & B_MOUNT_READ_ONLY) != 0 || is_device_read_only(device)) {
    238257        mountFlags |= MS_RDONLY;
    239258        ns->flags |= B_FS_IS_READONLY;
    240259    }
    241260
    242     // TODO: this does not take read-only volumes into account!
    243261    ns->ntvol = utils_mount_volume(device, mountFlags, true);
    244262    if (ns->ntvol != NULL)
    245263        result = B_NO_ERROR;