1 | /*
|
---|
2 | =============================================================================
|
---|
3 | writern.c -- write a random sector onto a file
|
---|
4 | Version 6 -- 1987-12-15 -- D.N. Lynx Crowe
|
---|
5 |
|
---|
6 | int
|
---|
7 | WriteRN(fcp, buf)
|
---|
8 | struct fcb *fcp;
|
---|
9 | char *buf;
|
---|
10 |
|
---|
11 | Writes a sector onto file 'fcp' from 'buf'. Seeks as needed.
|
---|
12 | Returns SUCCESS (0) if OK, FAILURE (-1) for errors.
|
---|
13 | =============================================================================
|
---|
14 | */
|
---|
15 |
|
---|
16 | #define DEBUGIT 0
|
---|
17 |
|
---|
18 | #include "ram.h"
|
---|
19 |
|
---|
20 | /*
|
---|
21 | =============================================================================
|
---|
22 | WriteRN(fcp, buf) -- Writes a sector onto file 'fcp' from 'buf'.
|
---|
23 | Seeks as needed. Returns SUCCESS (0) if OK, FAILURE (-1) for errors.
|
---|
24 | =============================================================================
|
---|
25 | */
|
---|
26 |
|
---|
27 | int16_t WriteRN(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 |
|
---|
34 | if (sv < 0) { /* seek error ? */
|
---|
35 |
|
---|
36 | #if DEBUGIT
|
---|
37 | if (fsdebug)
|
---|
38 | printf("WriteRN(): _seek FAILED (%d) - curlsn=%ld, curdsn=%ld\n",
|
---|
39 | sv, fcp->curlsn, fcp->curdsn);
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | errno = EIO; /* I/O error or seek past EOF */
|
---|
43 | return(FAILURE);
|
---|
44 |
|
---|
45 | } else if (sv EQ 2) { /* at hard EOF ? */
|
---|
46 |
|
---|
47 | if (_alcnew(fcp)) { /* allocate a new cluster */
|
---|
48 |
|
---|
49 | errno = EIO;
|
---|
50 | return(FAILURE);
|
---|
51 | }
|
---|
52 | #if DEBUGIT
|
---|
53 | if (fsdebug)
|
---|
54 | printf("WriteRN(): cluster allocated - curcls=%d, clsec=%d\n",
|
---|
55 | fcp->curcls, fcp->clsec);
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | #if DEBUGIT
|
---|
62 | if (fsdebug)
|
---|
63 | printf("WriteRN(): curlsn=%ld, curdsn=%ld\n",
|
---|
64 | fcp->curlsn, fcp->curdsn);
|
---|
65 | #endif
|
---|
66 |
|
---|
67 | /* write the sector */
|
---|
68 |
|
---|
69 | if ((brc = BIOS(B_RDWR, 1, buf, 1, (int16_t)fcp->curdsn, 0))) {
|
---|
70 |
|
---|
71 | #if DEBUGIT
|
---|
72 | if (fsdebug)
|
---|
73 | printf("WriteRN(): B_RDWR FAILED - brc=%ld\n", brc);
|
---|
74 | #endif
|
---|
75 |
|
---|
76 | _berrno = brc; /* log the error */
|
---|
77 | errno = EIO; /* ... as an I/O error */
|
---|
78 | return(FAILURE); /* return: ERROR */
|
---|
79 | }
|
---|
80 |
|
---|
81 | #if TBUFFER
|
---|
82 | _secwr(buf, (int16_t)fcp->curdsn);
|
---|
83 | #endif
|
---|
84 |
|
---|
85 | return(SUCCESS); /* return: SUCCESS */
|
---|
86 | }
|
---|
87 |
|
---|