Changeset 08cba4b in mainline


Ignore:
Timestamp:
2011-09-05T15:42:46Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a26895d
Parents:
d7f6248
Message:

improve the interface of block_get_toc()

Location:
uspace/lib/block
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/block/libblock.c

    rd7f6248 r08cba4b  
    9393static int get_block_size(async_sess_t *, size_t *);
    9494static int get_num_blocks(async_sess_t *, aoff64_t *);
    95 static int read_toc(async_sess_t *, uint8_t);
    9695static aoff64_t ba_ltop(devcon_t *, aoff64_t);
    9796
     
    896895 * @param service_id Service ID of the block device.
    897896 * @param session    Starting session.
    898  * @param data       Buffer to read TOC into.
    899  *
    900  * @return EOK on success.
    901  * @return Error code on failure.
    902  *
    903  */
    904 int block_get_toc(service_id_t service_id, uint8_t session, void *data)
     897 *
     898 * @return Allocated TOC structure.
     899 * @return NULL on failure.
     900 *
     901 */
     902toc_block_t *block_get_toc(service_id_t service_id, uint8_t session)
    905903{
    906904        devcon_t *devcon = devcon_search(service_id);
    907905        assert(devcon);
    908906       
     907        toc_block_t *toc = NULL;
     908       
    909909        fibril_mutex_lock(&devcon->comm_area_lock);
    910910       
    911         int rc = read_toc(devcon->sess, session);
    912         if (rc == EOK)
    913                 memcpy(data, devcon->comm_area, devcon->pblock_size);
     911        async_exch_t *exch = async_exchange_begin(devcon->sess);
     912        int rc = async_req_1_0(exch, BD_READ_TOC, session);
     913        async_exchange_end(exch);
     914       
     915        if (rc == EOK) {
     916                toc = (toc_block_t *) malloc(sizeof(toc_block_t));
     917                if (toc != NULL) {
     918                        memset(toc, 0, sizeof(toc_block_t));
     919                        memcpy(toc, devcon->comm_area,
     920                            min(devcon->pblock_size, sizeof(toc_block_t)));
     921                }
     922        }
     923       
    914924       
    915925        fibril_mutex_unlock(&devcon->comm_area_lock);
    916926       
    917         return rc;
     927        return toc;
    918928}
    919929
     
    10081018}
    10091019
    1010 /** Get TOC from block device. */
    1011 static int read_toc(async_sess_t *sess, uint8_t session)
    1012 {
    1013         async_exch_t *exch = async_exchange_begin(sess);
    1014         int rc = async_req_1_0(exch, BD_READ_TOC, session);
    1015         async_exchange_end(exch);
    1016 
    1017         return rc;
    1018 }
    1019 
    10201020/** Convert logical block address to physical block address. */
    10211021static aoff64_t ba_ltop(devcon_t *devcon, aoff64_t lba)
  • uspace/lib/block/libblock.h

    rd7f6248 r08cba4b  
    9797};
    9898
     99typedef struct {
     100        uint16_t size;
     101        uint8_t first_session;
     102        uint8_t last_session;
     103       
     104        uint8_t res0;
     105        uint8_t adr_ctrl;
     106        uint8_t first_track;
     107        uint8_t res1;
     108       
     109        uint32_t first_lba;
     110} __attribute__((packed)) toc_block_t;
     111
    99112extern int block_init(exch_mgmt_t, service_id_t, size_t);
    100113extern void block_fini(service_id_t);
     
    114127extern int block_get_bsize(service_id_t, size_t *);
    115128extern int block_get_nblocks(service_id_t, aoff64_t *);
    116 extern int block_get_toc(service_id_t, uint8_t, void *);
     129extern toc_block_t *block_get_toc(service_id_t, uint8_t);
    117130extern int block_read_direct(service_id_t, aoff64_t, size_t, void *);
    118131extern int block_read_bytes_direct(service_id_t, aoff64_t, size_t, void *);
     
    123136/** @}
    124137 */
    125 
Note: See TracChangeset for help on using the changeset viewer.