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 |
|
---|
45 | #if DEBUGIT
|
---|
46 | if (fsdebug)
|
---|
47 | printf("ReadRN(): curlsn=%ld, curdsn=%ld, offset=%u\n",
|
---|
48 | fcp->curlsn, fcp->curdsn, fcp->offset);
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | #if TBUFFER
|
---|
52 | if ((brc = _secrd(buf, (int16_t)fcp->curdsn))) {
|
---|
53 | #else
|
---|
54 | if (brc = BIOS(B_RDWR, 0, buf, 1, (short)fcp->curdsn, 0)) {
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | _berrno = brc; /* log the error */
|
---|
58 | errno = EIO; /* ... as an I/O error */
|
---|
59 | return(FAILURE); /* return: ERROR */
|
---|
60 | }
|
---|
61 |
|
---|
62 | return(SUCCESS); /* return: SUCCESS */
|
---|
63 | }
|
---|
64 |
|
---|