Ticket #8449: fs_func_c.patch

File fs_func_c.patch, 1.5 KB (added by kag_anil, 12 years ago)
  • .c

    old new  
    4848    char label[256];
    4949} identify_cookie;
    5050
     51status_t
     52checkReadOnly(const char *dev)
     53{
     54    status_t check = B_NO_ERROR;        // 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_OK;           // 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)
     
    204227    void *handle;
    205228    unsigned long mountFlags = 0;
    206229    status_t result = B_NO_ERROR;
     230    status_t rdOnlyCheck = B_NO_ERROR;
    207231
    208232    TRACE("fs_mount - ENTER\n");
    209233
     
    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    rdOnlyCheck = checkReadOnly(device);
     263   
     264    // set the status given by checkReadOnly, can be B_NO_ERROR or ERRNO set during function call
     265    if(rdOnlyCheck != B_OK)
     266        result = rdOnlyCheck;
     267   
     268    if (ns->ro || (flags & B_MOUNT_READ_ONLY) != 0 || rdOnlyCheck == B_OK) {
    238269        mountFlags |= MS_RDONLY;
    239270        ns->flags |= B_FS_IS_READONLY;
    240271    }
    241 
     272   
    242273    // TODO: this does not take read-only volumes into account!
    243274    ns->ntvol = utils_mount_volume(device, mountFlags, true);
    244275    if (ns->ntvol != NULL)