Ticket #8449: fs_func_c_2.patch

File fs_func_c_2.patch, 1.8 KB (added by kag_anil, 12 years ago)

patch with modifications --> conforming to the guidelines and using B_READ_ONLY_DEVICE instead of B_OK for read only volumes

  • 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..cc6ed67 100644
    a b typedef struct identify_cookie {  
    4848    char label[256];
    4949} identify_cookie;
    5050
     51status_t
     52check_read_only(const char *dev)
     53{
     54    status_t check = B_OK;                          // NO ERROR during READ_ONLY check
     55    int fd = open(dev, O_RDONLY | O_NOCACHE);
     56    if (fd < 0)
     57        check = errno;
     58
     59    if (fd >= 0) {
     60        // opening succeeded
     61        device_geometry geometry;
     62       
     63        if (!ioctl(fd, B_GET_GEOMETRY, &geometry)) {
     64            if (geometry.read_only) {
     65                check = B_READ_ONLY_DEVICE;         // READ_ONLY device
     66            }
     67        }
     68       
     69        // close the descriptor
     70        close(fd);
     71    }
     72    return check;                                   // go the default way
     73}
    5174
    5275static status_t
    5376get_node_type(ntfs_inode* ni, int* _type)
    fs_mount(fs_volume *_vol, const char *device, ulong flags, const char *args,  
    204227    void *handle;
    205228    unsigned long mountFlags = 0;
    206229    status_t result = B_NO_ERROR;
     230    status_t rd_only_check;
    207231
    208232    TRACE("fs_mount - ENTER\n");
    209233
    fs_mount(fs_volume *_vol, const char *device, ulong flags, const char *args,  
    234258        "true"), "true") == 0;
    235259    unload_driver_settings(handle);
    236260
    237     if (ns->ro || (flags & B_MOUNT_READ_ONLY) != 0) {
     261    // checking whether the device is READ_ONLY or not
     262    rd_only_check = check_read_only(device);
     263   
     264    // check for the read only status if the device
     265    if (ns->ro || (flags & B_MOUNT_READ_ONLY) != 0 || rd_only_check == B_READ_ONLY_DEVICE) {
    238266        mountFlags |= MS_RDONLY;
    239267        ns->flags |= B_FS_IS_READONLY;
    240268    }
    241 
    242     // TODO: this does not take read-only volumes into account!
     269   
    243270    ns->ntvol = utils_mount_volume(device, mountFlags, true);
    244271    if (ns->ntvol != NULL)
    245272        result = B_NO_ERROR;