[0b990d] | 1 | /*!
|
---|
| 2 | \file read.c
|
---|
| 3 | \ingroup (PSIO)
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | #include <unistd.h>
|
---|
| 7 | #include <string.h>
|
---|
| 8 | #include <util/psi3/libpsio/psio.h>
|
---|
| 9 |
|
---|
| 10 | namespace psi3 {
|
---|
| 11 | namespace libpsio {
|
---|
| 12 |
|
---|
| 13 | /*!
|
---|
| 14 | ** PSIO_READ(): Reads data from within a TOC entry from a PSI file.
|
---|
| 15 | **
|
---|
| 16 | ** \param unit = The PSI unit number used to identify the file to all
|
---|
| 17 | ** read and write functions.
|
---|
| 18 | ** \param key = The TOC keyword identifying the desired entry.
|
---|
| 19 | ** \param buffer = The buffer to store the data as it is read.
|
---|
| 20 | ** \param size = The number of bytes to read.
|
---|
| 21 | ** \param sadd = The entry-relative starting page/offset of the desired data.
|
---|
| 22 | ** \param eadd = A pointer to the entry-relative page/offset for the next
|
---|
| 23 | ** byte after the end of the read request.
|
---|
| 24 | **
|
---|
| 25 | ** \ingroup (PSIO)
|
---|
| 26 | */
|
---|
| 27 |
|
---|
| 28 | int psio_read(unsigned int unit, char *key, char *buffer, ULI size,
|
---|
| 29 | psio_address sadd, psio_address *eadd)
|
---|
| 30 | {
|
---|
| 31 | psio_ud *this_unit;
|
---|
| 32 | psio_address address, end_address;
|
---|
| 33 | psio_tocentry *this_entry;
|
---|
| 34 |
|
---|
| 35 | this_unit = &(psio_unit[unit]);
|
---|
| 36 |
|
---|
| 37 | /* Find the entry in the TOC */
|
---|
| 38 | this_entry = psio_tocscan(unit, key);
|
---|
| 39 |
|
---|
| 40 | if(this_entry == NULL) {
|
---|
| 41 | fprintf(stderr, "PSIO_ERROR: Can't find TOC Entry %s\n", key);
|
---|
| 42 | psio_error(unit,PSIO_ERROR_NOTOCENT);
|
---|
| 43 | }
|
---|
| 44 | else {
|
---|
| 45 |
|
---|
| 46 | /* Compute the starting page and offset for the block */
|
---|
| 47 | address = psio_get_global_address(this_entry->sadd, sadd);
|
---|
| 48 |
|
---|
| 49 | /* Make sure the block starts and ends within the entry */
|
---|
| 50 | if(address.page > this_entry->eadd.page)
|
---|
| 51 | psio_error(unit,PSIO_ERROR_BLKSTART);
|
---|
| 52 | else if((address.page == this_entry->eadd.page) &&
|
---|
| 53 | (address.offset > this_entry->eadd.offset))
|
---|
| 54 | psio_error(unit,PSIO_ERROR_BLKSTART);
|
---|
| 55 |
|
---|
| 56 | end_address = psio_get_address(address, size);
|
---|
| 57 | if((end_address.page > this_entry->eadd.page))
|
---|
| 58 | psio_error(unit,PSIO_ERROR_BLKEND);
|
---|
| 59 | else if((end_address.page == this_entry->eadd.page) &&
|
---|
| 60 | (end_address.offset > this_entry->eadd.offset))
|
---|
| 61 | psio_error(unit,PSIO_ERROR_BLKEND);
|
---|
| 62 |
|
---|
| 63 | /* Update the eadd argument value for the caller */
|
---|
| 64 | *eadd = psio_get_address(sadd, size);
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | /* Now read the actual data from the unit */
|
---|
| 68 | psio_rw(unit, buffer, address, size, 0);
|
---|
| 69 |
|
---|
| 70 | #ifdef PSIO_STATS
|
---|
| 71 | psio_readlen[unit] += size;
|
---|
| 72 | #endif
|
---|
| 73 |
|
---|
| 74 | return(0);
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | }
|
---|
| 78 | }
|
---|