Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset c2844735 in mainline


Ignore:
Timestamp:
2014-08-03T15:37:06Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
251d4dd
Parents:
94c49fd3
Message:

ATAPI CD-ROM needs to return device capacity. (Could not mount HelenOS CD since block address check was added to libblock.)

Location:
uspace/drv/block/ata_bd
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/block/ata_bd/Makefile

    r94c49fd3 rc2844735  
    2828
    2929USPACE_PREFIX = ../../..
    30 LIBS = $(LIBDRV_PREFIX)/libdrv.a
    31 EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include
     30LIBS = $(LIBDRV_PREFIX)/libdrv.a $(LIBSCSI_PREFIX)/libscsi.a
     31EXTRA_CFLAGS += -I$(LIBDRV_PREFIX)/include -I$(LIBSCSI_PREFIX)/include
    3232BINARY = ata_bd
    3333
  • uspace/drv/block/ata_bd/ata_bd.c

    r94c49fd3 rc2844735  
    5454#include <bd_srv.h>
    5555#include <fibril_synch.h>
     56#include <scsi/sbc.h>
    5657#include <stdint.h>
    5758#include <str.h>
     
    103104static int ata_identify_pkt_dev(disk_t *disk, void *buf);
    104105static int ata_cmd_packet(disk_t *disk, const void *cpkt, size_t cpkt_size,
    105     void *obuf, size_t obuf_size);
    106 static int ata_pcmd_inquiry(disk_t *disk, void *obuf, size_t obuf_size);
     106    void *obuf, size_t obuf_size, size_t *rcvd_size);
     107static int ata_pcmd_inquiry(disk_t *disk, void *obuf, size_t obuf_size,
     108    size_t *rcvd_size);
    107109static int ata_pcmd_read_12(disk_t *disk, uint64_t ba, size_t cnt,
    108110    void *obuf, size_t obuf_size);
     111static int ata_pcmd_read_capacity(disk_t *disk, uint64_t *nblocks,
     112    size_t *block_size);
    109113static int ata_pcmd_read_toc(disk_t *disk, uint8_t ses,
    110114    void *obuf, size_t obuf_size);
     
    340344        uint8_t model[40];
    341345        ata_inquiry_data_t inq_data;
     346        size_t isize;
    342347        uint16_t w;
    343348        uint8_t c;
    344349        uint16_t bc;
     350        uint64_t nblocks;
     351        size_t block_size;
    345352        size_t pos, len;
    346353        int rc;
     
    457464        if (d->dev_type == ata_pkt_dev) {
    458465                /* Send inquiry. */
    459                 rc = ata_pcmd_inquiry(d, &inq_data, sizeof(inq_data));
    460                 if (rc != EOK) {
     466                rc = ata_pcmd_inquiry(d, &inq_data, sizeof(inq_data), &isize);
     467                if (rc != EOK || isize < sizeof(inq_data)) {
    461468                        ddf_msg(LVL_ERROR, "Device inquiry failed.");
    462469                        d->present = false;
     
    468475                        ddf_msg(LVL_WARN, "Peripheral device type is not CD-ROM.");
    469476
    470                 /* Assume 2k block size for now. */
    471                 d->block_size = 2048;
     477                rc = ata_pcmd_read_capacity(d, &nblocks, &block_size);
     478                if (rc != EOK) {
     479                        ddf_msg(LVL_ERROR, "Read capacity command failed.");
     480                        d->present = false;
     481                        return EIO;
     482                }
     483
     484                d->blocks = nblocks;
     485                d->block_size = block_size;
    472486        } else {
    473487                /* Assume register Read always uses 512-byte blocks. */
     
    722736 * @param obuf          Buffer for storing data read from device
    723737 * @param obuf_size     Size of obuf in bytes
     738 * @param rcvd_size     Place to store number of bytes read or @c NULL
    724739 *
    725740 * @return EOK on success, EIO on error.
    726741 */
    727742static int ata_cmd_packet(disk_t *disk, const void *cpkt, size_t cpkt_size,
    728     void *obuf, size_t obuf_size)
     743    void *obuf, size_t obuf_size, size_t *rcvd_size)
    729744{
    730745        ata_ctrl_t *ctrl = disk->ctrl;
     
    800815                return EIO;
    801816
     817        if (rcvd_size != NULL)
     818                *rcvd_size = data_size;
    802819        return EOK;
    803820}
     
    811828 * @return EOK on success, EIO on error.
    812829 */
    813 static int ata_pcmd_inquiry(disk_t *disk, void *obuf, size_t obuf_size)
     830static int ata_pcmd_inquiry(disk_t *disk, void *obuf, size_t obuf_size,
     831    size_t *rcvd_size)
    814832{
    815833        ata_pcmd_inquiry_t cp;
     
    821839        cp.alloc_len = min(obuf_size, 0xff); /* Allocation length */
    822840
    823         rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size);
     841        rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size, rcvd_size);
    824842        if (rc != EOK)
    825843                return rc;
     844
     845        return EOK;
     846}
     847
     848/** Issue ATAPI read capacity(10) command.
     849 *
     850 * @param disk          Disk
     851 * @param nblocks       Place to store number of blocks
     852 * @param block_size    Place to store block size
     853 *
     854 * @return EOK on success, EIO on error.
     855 */
     856static int ata_pcmd_read_capacity(disk_t *disk, uint64_t *nblocks,
     857    size_t *block_size)
     858{
     859        scsi_cdb_read_capacity_10_t cdb;
     860        scsi_read_capacity_10_data_t data;
     861        size_t rsize;
     862        int rc;
     863
     864        memset(&cdb, 0, sizeof(cdb));
     865        cdb.op_code = SCSI_CMD_READ_CAPACITY_10;
     866
     867        rc = ata_cmd_packet(disk, &cdb, sizeof(cdb), &data, sizeof(data), &rsize);
     868        if (rc != EOK)
     869                return rc;
     870
     871        if (rsize != sizeof(data))
     872                return EIO;
     873
     874        *nblocks = uint32_t_be2host(data.last_lba) + 1;
     875        *block_size = uint32_t_be2host(data.block_size);
    826876
    827877        return EOK;
     
    856906        cp.nblocks = host2uint32_t_be(cnt);
    857907
    858         rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size);
     908        rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size, NULL);
    859909        if (rc != EOK)
    860910                return rc;
     
    895945        cp.oldformat = 0x40; /* 0x01 = multi-session mode (shifted to MSB) */
    896946       
    897         rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size);
     947        rc = ata_cmd_packet(disk, &cp, sizeof(cp), obuf, obuf_size, NULL);
    898948        if (rc != EOK)
    899949                return rc;
Note: See TracChangeset for help on using the changeset viewer.