[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | readrn.c -- read a random sector from a file
|
---|
| 4 | Version 8 -- 1987-12-15 -- D.N. Lynx Crowe
|
---|
| 5 |
|
---|
| 6 | int
|
---|
| 7 | ReadRN(fcp, buf)
|
---|
| 8 | struct fcb *fcp;
|
---|
| 9 | char *buf;
|
---|
| 10 |
|
---|
| 11 | Reads a sector from file 'fcp' into 'buf'. Seeks as needed.
|
---|
| 12 | Returns 0 if OK, -1 for errors, 1 for EOF (no data returned).
|
---|
| 13 | =============================================================================
|
---|
| 14 | */
|
---|
| 15 |
|
---|
| 16 | #define DEBUGIT 0
|
---|
| 17 |
|
---|
| 18 | #include "stddefs.h"
|
---|
| 19 | #include "biosdefs.h"
|
---|
| 20 | #include "errno.h"
|
---|
| 21 | #include "errdefs.h"
|
---|
| 22 | #include "fspars.h"
|
---|
| 23 |
|
---|
| 24 | #if DEBUGIT
|
---|
| 25 | extern short fsdebug;
|
---|
| 26 | #endif
|
---|
| 27 |
|
---|
| 28 | #if TBUFFER
|
---|
[7258c6a] | 29 | extern int32_t _secrd(int8_t *buf, int16_t rec);
|
---|
[f40a309] | 30 | #endif
|
---|
| 31 |
|
---|
[7258c6a] | 32 | extern int32_t _berrno;
|
---|
| 33 | extern int16_t _seek(struct fcb *fcp);
|
---|
[f40a309] | 34 |
|
---|
| 35 | /* |
---|
| 36 |
|
---|
| 37 | */
|
---|
| 38 |
|
---|
| 39 | /*
|
---|
| 40 | =============================================================================
|
---|
| 41 | ReadRN(fcp, buf) -- Reads a sector from file 'fcp' into 'buf'.
|
---|
| 42 | Seeks as needed. Returns SUCCESS (0) if OK, FAILURE (-1) for errors.
|
---|
| 43 | =============================================================================
|
---|
| 44 | */
|
---|
[7258c6a] | 45 |
|
---|
[f40a309] | 46 | int16_t ReadRN(struct fcb *fcp, int8_t *buf)
|
---|
[7258c6a] | 47 | {
|
---|
| 48 | int16_t sv; /* seek return code */
|
---|
[f40a309] | 49 | int32_t brc; /* bios return code */
|
---|
| 50 |
|
---|
| 51 | if (sv = _seek(fcp)) /* try to find the sector we want */
|
---|
| 52 | if (sv < 0) {
|
---|
| 53 |
|
---|
| 54 | errno = EIO; /* I/O error */
|
---|
| 55 | return(-1); /* return: ERROR */
|
---|
| 56 |
|
---|
| 57 | } else {
|
---|
| 58 |
|
---|
| 59 | errno = EINVAL; /* invalid argument */
|
---|
| 60 | return(1); /* return: EOF */
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | #if DEBUGIT
|
---|
| 64 | if (fsdebug)
|
---|
| 65 | printf("ReadRN(): curlsn=%ld, curdsn=%ld, offset=%u\n",
|
---|
| 66 | fcp->curlsn, fcp->curdsn, fcp->offset);
|
---|
| 67 | #endif
|
---|
| 68 |
|
---|
[7258c6a] | 69 | #if TBUFFER
|
---|
[f40a309] | 70 | if (brc = _secrd(buf, (int16_t)fcp->curdsn)) {
|
---|
| 71 | #else
|
---|
| 72 | if (brc = BIOS(B_RDWR, 0, buf, 1, (short)fcp->curdsn, 0)) {
|
---|
| 73 | #endif
|
---|
| 74 |
|
---|
| 75 | _berrno = brc; /* log the error */
|
---|
| 76 | errno = EIO; /* ... as an I/O error */
|
---|
| 77 | return(FAILURE); /* return: ERROR */
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | return(SUCCESS); /* return: SUCCESS */
|
---|
| 81 | }
|
---|