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 "ram.h"
|
---|
19 |
|
---|
20 | /*
|
---|
21 | =============================================================================
|
---|
22 | ReadRN(fcp, buf) -- Reads a sector from file 'fcp' into 'buf'.
|
---|
23 | Seeks as needed. Returns SUCCESS (0) if OK, FAILURE (-1) for errors.
|
---|
24 | =============================================================================
|
---|
25 | */
|
---|
26 |
|
---|
27 | int16_t ReadRN(struct fcb *fcp, int8_t *buf)
|
---|
28 | {
|
---|
29 | int16_t sv; /* seek return code */
|
---|
30 | int32_t brc; /* bios return code */
|
---|
31 |
|
---|
32 | if (sv = _seek(fcp)) /* try to find the sector we want */
|
---|
33 | if (sv < 0) {
|
---|
34 |
|
---|
35 | errno = EIO; /* I/O error */
|
---|
36 | return(-1); /* return: ERROR */
|
---|
37 |
|
---|
38 | } else {
|
---|
39 |
|
---|
40 | errno = EINVAL; /* invalid argument */
|
---|
41 | return(1); /* return: EOF */
|
---|
42 | }
|
---|
43 |
|
---|
44 | #if DEBUGIT
|
---|
45 | if (fsdebug)
|
---|
46 | printf("ReadRN(): curlsn=%ld, curdsn=%ld, offset=%u\n",
|
---|
47 | fcp->curlsn, fcp->curdsn, fcp->offset);
|
---|
48 | #endif
|
---|
49 |
|
---|
50 | #if TBUFFER
|
---|
51 | if (brc = _secrd(buf, (int16_t)fcp->curdsn)) {
|
---|
52 | #else
|
---|
53 | if (brc = BIOS(B_RDWR, 0, buf, 1, (short)fcp->curdsn, 0)) {
|
---|
54 | #endif
|
---|
55 |
|
---|
56 | _berrno = brc; /* log the error */
|
---|
57 | errno = EIO; /* ... as an I/O error */
|
---|
58 | return(FAILURE); /* return: ERROR */
|
---|
59 | }
|
---|
60 |
|
---|
61 | return(SUCCESS); /* return: SUCCESS */
|
---|
62 | }
|
---|
63 |
|
---|