Changeset 03ad6b1d in rtems


Ignore:
Timestamp:
Feb 27, 2012, 4:23:05 PM (7 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
4f3cbd9
Parents:
5e88538
git-author:
Sebastian Huber <sebastian.huber@…> (02/27/12 16:23:05)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/13/12 11:24:17)
Message:

libblock: Avoid bdbuf API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libblock/src/ide_part_table.c

    r5e88538 r03ad6b1d  
    3232 *
    3333 * PARAMETERS:
    34  *      dev        - device number
     34 *      fd         - file descriptor
    3535 *      sector_num - number of sector to read
    3636 *      sector     - returned pointer to pointer to allocated
     
    4747 */
    4848static rtems_status_code
    49 get_sector(dev_t dev, uint32_t sector_num, rtems_sector_data_t **sector)
     49get_sector(int fd,
     50           uint32_t sector_num,
     51           rtems_sector_data_t **sector)
    5052{
    5153    rtems_sector_data_t *s;
    52     rtems_bdbuf_buffer  *buf;
    53     rtems_status_code    rc;
     54    ssize_t              n;
     55    off_t                off;
     56    off_t                new_off;
    5457
    5558    if (sector == NULL)
    5659    {
    5760        return RTEMS_INTERNAL_ERROR;
     61    }
     62
     63    off = sector_num * RTEMS_IDE_SECTOR_SIZE;
     64    new_off = lseek(fd, off, SEEK_SET);
     65    if (new_off != off) {
     66        return RTEMS_IO_ERROR;
    5867    }
    5968
     
    6473    }
    6574
    66     rc = rtems_bdbuf_read(dev, sector_num, &buf);
    67     if (rc != RTEMS_SUCCESSFUL)
     75    n = read(fd, s->data, RTEMS_IDE_SECTOR_SIZE);
     76    if (n != RTEMS_IDE_SECTOR_SIZE)
    6877    {
    6978        free(s);
    70         return rc;
    71     }
    72 
    73     memcpy(s->data, buf->buffer, RTEMS_IDE_SECTOR_SIZE);
     79        return RTEMS_IO_ERROR;
     80    }
     81
    7482    s->sector_num = sector_num;
    7583
    7684    *sector = s;
    77 
    78     rtems_bdbuf_release(buf);
    7985
    8086    return RTEMS_SUCCESSFUL;
     
    210216 *
    211217 * PARAMETERS:
     218 *      fd       - file descriptor
    212219 *      start    - start sector of primary extended partition, used for
    213220 *                 calculation of absolute partition sector address
     
    220227 */
    221228static rtems_status_code
    222 read_extended_partition(uint32_t start, rtems_part_desc_t *ext_part)
     229read_extended_partition(int fd, uint32_t start, rtems_part_desc_t *ext_part)
    223230{
    224231    int                  i;
    225     dev_t                dev;
    226232    rtems_sector_data_t *sector = NULL;
    227233    uint32_t             here;
     
    235241    }
    236242
    237     dev = ext_part->disk_desc->dev;
    238 
    239243    /* get start sector of current extended partition */
    240244    here = ext_part->start;
     
    242246    /* get first extended partition sector */
    243247
    244     rc = get_sector(dev, here, &sector);
     248    rc = get_sector(fd, here, &sector);
    245249    if (rc != RTEMS_SUCCESSFUL)
    246250    {
     
    286290            new_part_desc->log_id = EMPTY_PARTITION;
    287291            new_part_desc->start += start;
    288             read_extended_partition(start, new_part_desc);
     292            read_extended_partition(fd, start, new_part_desc);
    289293        }
    290294        else
     
    318322 */
    319323static rtems_status_code
    320 read_mbr(rtems_disk_desc_t *disk_desc)
     324read_mbr(int fd, rtems_disk_desc_t *disk_desc)
    321325{
    322326    int                  part_num;
     
    325329    uint8_t             *data;
    326330    rtems_status_code    rc;
    327     dev_t                dev = disk_desc->dev;
    328331
    329332    /* get MBR sector */
    330     rc = get_sector(dev, 0, &sector);
     333    rc = get_sector(fd, 0, &sector);
    331334    if (rc != RTEMS_SUCCESSFUL)
    332335    {
     
    386389        if (part_desc != NULL && is_extended(part_desc->sys_type))
    387390        {
    388             read_extended_partition(part_desc->start, part_desc);
     391            read_extended_partition(fd, part_desc->start, part_desc);
    389392        }
    390393    }
     
    468471    struct stat         dev_stat;
    469472    rtems_status_code   rc;
    470 
    471     rc = stat(dev_name, &dev_stat);
     473    int                 fd;
     474
     475    fd = open(dev_name, O_RDONLY);
     476    if (fd < 0)
     477    {
     478        return RTEMS_INTERNAL_ERROR;
     479    }
     480
     481    rc = fstat(fd, &dev_stat);
    472482    if (rc != RTEMS_SUCCESSFUL)
    473483    {
     484        close(fd);
    474485        return RTEMS_INTERNAL_ERROR;
    475486    }
     
    480491                                              RTEMS_IDE_SECTOR_SIZE;
    481492
    482     rc = read_mbr(disk_desc);
     493    rc = read_mbr(fd, disk_desc);
     494
     495    close(fd);
    483496
    484497    return rc;
Note: See TracChangeset for help on using the changeset viewer.