Changeset bdac0eed in rtems


Ignore:
Timestamp:
Apr 9, 2010, 12:28:24 PM (10 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, master
Children:
5e657e2
Parents:
22f107b6
Message:

fixed disk delete
Obtain/release disk during open/close

Location:
cpukit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r22f107b6 rbdac0eed  
     12010-04-09      Sebastian Huber <sebastian.huber@embedded-brains.de>
     2
     3        * libblock/src/blkdev.c: Fixed disk delete.
     4        * libblock/src/diskdevs.c: Obtain/release disk during open/close.
     5        This avoids unprotected usage of private disk variables.
     6
    172010-04-08      Sebastian Huber <sebastian.huber@embedded-brains.de>
    28
  • cpukit/libblock/src/blkdev.c

    r22f107b6 rbdac0eed  
    3434rtems_device_driver
    3535rtems_blkdev_generic_read(
    36     rtems_device_major_number major,
    37     rtems_device_minor_number minor,
     36    rtems_device_major_number major __attribute__((unused)),
     37    rtems_device_minor_number minor __attribute__((unused)),
    3838    void                    * arg)
    3939{
    4040    rtems_status_code rc = RTEMS_SUCCESSFUL;
    4141    rtems_libio_rw_args_t *args = arg;
    42     uint32_t block_size;
    43     char *buf;
    44     uint32_t count;
    45     rtems_blkdev_bnum block;
    46     uint32_t blkofs;
    47     dev_t dev;
    48     rtems_disk_device *dd;
    49 
    50     dev = rtems_filesystem_make_dev_t(major, minor);
    51     dd = rtems_disk_obtain(dev);
    52     if (dd == NULL)
    53         return RTEMS_INVALID_NUMBER;
    54 
    55     block_size = dd->block_size;
    56 
    57     buf = args->buffer;
    58     count = args->count;
     42    rtems_libio_t *iop = args->iop;
     43    rtems_disk_device *dd = iop->data1;
     44    uint32_t block_size = dd->block_size;
     45    char *buf = args->buffer;
     46    uint32_t count = args->count;
     47    rtems_blkdev_bnum block = (rtems_blkdev_bnum) (args->offset / block_size);
     48    uint32_t blkofs = (uint32_t) (args->offset % block_size);
     49    dev_t dev = dd->dev;
     50
    5951    args->bytes_moved = 0;
    60 
    61     block = (rtems_blkdev_bnum) (args->offset / block_size);
    62     blkofs = (uint32_t) (args->offset % block_size);
    6352
    6453    while (count > 0)
     
    8473    }
    8574
    86     rtems_disk_release(dd);
    87 
    8875    return rc;
    8976}
     
    9582rtems_device_driver
    9683rtems_blkdev_generic_write(
    97     rtems_device_major_number major,
    98     rtems_device_minor_number minor,
     84    rtems_device_major_number major __attribute__((unused)),
     85    rtems_device_minor_number minor __attribute__((unused)),
    9986    void                    * arg)
    10087{
    10188    rtems_status_code rc = RTEMS_SUCCESSFUL;
    10289    rtems_libio_rw_args_t *args = arg;
    103     uint32_t block_size;
    104     char *buf;
    105     uint32_t count;
    106     rtems_blkdev_bnum block;
    107     uint32_t blkofs;
    108     dev_t dev;
    109     rtems_disk_device *dd;
    110 
    111     dev = rtems_filesystem_make_dev_t(major, minor);
    112     dd = rtems_disk_obtain(dev);
    113     if (dd == NULL)
    114         return RTEMS_INVALID_NUMBER;
    115 
    116     block_size = dd->block_size;
    117 
    118     buf = args->buffer;
    119     count = args->count;
     90    rtems_libio_t *iop = args->iop;
     91    rtems_disk_device *dd = iop->data1;
     92    uint32_t block_size = dd->block_size;
     93    char *buf = args->buffer;
     94    uint32_t count = args->count;
     95    rtems_blkdev_bnum block = (rtems_blkdev_bnum) (args->offset / block_size);
     96    uint32_t blkofs = (uint32_t) (args->offset % block_size);
     97    dev_t dev = dd->dev;
     98
    12099    args->bytes_moved = 0;
    121 
    122     block = (rtems_blkdev_bnum) (args->offset / block_size);
    123     blkofs = (uint32_t) (args->offset % block_size);
    124100
    125101    while (count > 0)
     
    151127    }
    152128
    153     rtems_disk_release(dd);
    154 
    155129    return rc;
    156130}
     
    163137    rtems_device_major_number major,
    164138    rtems_device_minor_number minor,
    165     void                    * arg __attribute__((unused)))
    166 {
    167     dev_t dev;
    168     rtems_disk_device *dd;
    169 
    170     dev = rtems_filesystem_make_dev_t(major, minor);
    171     dd = rtems_disk_obtain(dev);
    172     if (dd == NULL)
    173         return RTEMS_INVALID_NUMBER;
    174 
    175     dd->uses++;
    176 
    177     rtems_disk_release(dd);
    178 
     139    void                    * arg)
     140{
     141  rtems_libio_open_close_args_t *oc = arg;
     142  rtems_libio_t *iop = oc->iop;
     143  dev_t dev = rtems_filesystem_make_dev_t(major, minor);
     144  rtems_disk_device *dd = rtems_disk_obtain(dev);
     145
     146  iop->data1 = dd;
     147
     148  if (dd != NULL)
    179149    return RTEMS_SUCCESSFUL;
     150  else
     151    return RTEMS_UNSATISFIED;
    180152}
    181153
     
    186158rtems_device_driver
    187159rtems_blkdev_generic_close(
    188     rtems_device_major_number major,
    189     rtems_device_minor_number minor,
    190     void                    * arg __attribute__((unused)))
    191 {
    192     dev_t dev;
    193     rtems_disk_device *dd;
    194 
    195     dev = rtems_filesystem_make_dev_t(major, minor);
    196     dd = rtems_disk_obtain(dev);
    197     if (dd == NULL)
    198         return RTEMS_INVALID_NUMBER;
    199 
    200     dd->uses--;
    201 
    202     rtems_disk_release(dd);
    203 
    204     return RTEMS_SUCCESSFUL;
     160    rtems_device_major_number major __attribute__((unused)),
     161    rtems_device_minor_number minor __attribute__((unused)),
     162    void                    * arg)
     163{
     164  rtems_libio_open_close_args_t *oc = arg;
     165  rtems_libio_t *iop = oc->iop;
     166  rtems_disk_device *dd = iop->data1;
     167
     168  rtems_disk_release(dd);
     169
     170  return RTEMS_SUCCESSFUL;
    205171}
    206172
     
    210176rtems_device_driver
    211177rtems_blkdev_generic_ioctl(
    212     rtems_device_major_number major,
    213     rtems_device_minor_number minor,
     178    rtems_device_major_number major __attribute__((unused)),
     179    rtems_device_minor_number minor __attribute__((unused)),
    214180    void                    * arg)
    215181{
    216182    rtems_libio_ioctl_args_t *args = arg;
    217     dev_t dev;
    218     rtems_disk_device *dd;
     183    rtems_libio_t *iop = args->iop;
     184    rtems_disk_device *dd = iop->data1;
    219185    int rc;
    220 
    221     dev = rtems_filesystem_make_dev_t(major, minor);
    222     dd = rtems_disk_obtain(dev);
    223     if (dd == NULL)
    224         return RTEMS_INVALID_NUMBER;
    225186
    226187    switch (args->command)
     
    256217             * the cache.
    257218             */
    258             rc = RTEMS_INVALID_NAME;
    259             args->ioctl_return = -1;
     219            args->ioctl_return = (uint32_t) -1;
    260220            break;
    261221
     
    266226            break;
    267227    }
    268     rtems_disk_release(dd);
    269228
    270229    return RTEMS_SUCCESSFUL;
  • cpukit/libblock/src/diskdevs.c

    r22f107b6 rbdac0eed  
    9090
    9191static rtems_disk_device *
    92 get_disk_entry(dev_t dev)
     92get_disk_entry(dev_t dev, bool lookup_only)
    9393{
    9494  rtems_device_major_number major = 0;
     
    103103      rtems_disk_device *dd = dtab->minor [minor];
    104104
    105       if (dd != NULL && !dd->deleted) {
    106         ++dd->uses;
    107 
    108         return dd;
     105      if (dd != NULL && !lookup_only) {
     106        if (!dd->deleted) {
     107          ++dd->uses;
     108        } else {
     109          dd = NULL;
     110        }
    109111      }
     112
     113      return dd;
    110114    }
    111115  }
     
    289293  }
    290294
    291   physical_disk = get_disk_entry(phys);
     295  physical_disk = get_disk_entry(phys, true);
    292296  if (physical_disk == NULL || !is_physical_disk(physical_disk)) {
    293     if (physical_disk != NULL) {
    294       --physical_disk->uses;
    295     }
    296297    disk_unlock();
    297298
     
    304305      || end_block > physical_disk->size
    305306  ) {
    306     --physical_disk->uses;
    307307    disk_unlock();
    308308
     
    312312  sc = create_disk(dev, name, &dd);
    313313  if (sc != RTEMS_SUCCESSFUL) {
    314     --physical_disk->uses;
    315314    disk_unlock();
    316315
     
    324323  dd->ioctl = physical_disk->ioctl;
    325324  dd->driver_data = physical_disk->driver_data;
     325
     326  ++physical_disk->uses;
    326327
    327328  disk_unlock();
     
    399400  }
    400401
    401   dd = get_disk_entry(dev);
     402  dd = get_disk_entry(dev, true);
    402403  if (dd == NULL) {
    403404    disk_unlock();
     
    406407  }
    407408
    408   --dd->uses;
    409409  dd->deleted = true;
    410410  rtems_disk_cleanup(dd);
     
    425425  if (!diskdevs_protected) {
    426426    /* Frequent and quickest case */
    427     dd = get_disk_entry(dev);
     427    dd = get_disk_entry(dev, false);
    428428    rtems_interrupt_enable(level);
    429429  } else {
     
    432432    sc = disk_lock();
    433433    if (sc == RTEMS_SUCCESSFUL) {
    434       dd = get_disk_entry(dev);
     434      dd = get_disk_entry(dev, false);
    435435      disk_unlock();
    436436    }
Note: See TracChangeset for help on using the changeset viewer.