[f40a309] | 1 | /*
|
---|
[c091ef8] | 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 | =============================================================================
|
---|
[f40a309] | 14 | */
|
---|
| 15 |
|
---|
| 16 | #define DEBUGIT 0
|
---|
| 17 |
|
---|
[c091ef8] | 18 | #include "stddefs.h"
|
---|
[f40a309] | 19 | #include "biosdefs.h"
|
---|
| 20 | #include "errno.h"
|
---|
[c091ef8] | 21 | #include "errdefs.h"
|
---|
| 22 | #include "fspars.h"
|
---|
[f40a309] | 23 |
|
---|
[7258c6a] | 24 | extern int32_t _berrno;
|
---|
| 25 | extern int16_t _seek(struct fcb *fcp);
|
---|
[f40a309] | 26 |
|
---|
| 27 | #if DEBUGIT
|
---|
| 28 | extern short fsdebug;
|
---|
| 29 | #endif
|
---|
| 30 |
|
---|
[c091ef8] | 31 | #if TBUFFER
|
---|
[7258c6a] | 32 | extern int32_t _secwr(int8_t *buf, int16_t rec);
|
---|
[c091ef8] | 33 | #endif
|
---|
[f40a309] | 34 |
|
---|
| 35 | /* |
---|
| 36 |
|
---|
| 37 | */
|
---|
| 38 |
|
---|
[c091ef8] | 39 | /*
|
---|
| 40 | =============================================================================
|
---|
| 41 | WriteRN(fcp, buf) -- Writes a sector onto file 'fcp' from 'buf'.
|
---|
| 42 | Seeks as needed. Returns SUCCESS (0) if OK, FAILURE (-1) for errors.
|
---|
[f40a309] | 43 | =============================================================================
|
---|
| 44 | */
|
---|
[7258c6a] | 45 |
|
---|
[f40a309] | 46 | int16_t WriteRN(struct fcb *fcp, int8_t *buf)
|
---|
[7258c6a] | 47 | {
|
---|
| 48 | int16_t sv; /* seek return code */
|
---|
[f40a309] | 49 | int32_t brc; /* bios return code */
|
---|
[c091ef8] | 50 |
|
---|
[f40a309] | 51 | if (sv = _seek(fcp)) { /* try to find the sector we want */
|
---|
[c091ef8] | 52 |
|
---|
[f40a309] | 53 | if (sv < 0) { /* seek error ? */
|
---|
| 54 |
|
---|
| 55 | #if DEBUGIT
|
---|
[c091ef8] | 56 | if (fsdebug)
|
---|
| 57 | printf("WriteRN(): _seek FAILED (%d) - curlsn=%ld, curdsn=%ld\n",
|
---|
[f40a309] | 58 | sv, fcp->curlsn, fcp->curdsn);
|
---|
| 59 | #endif
|
---|
[c091ef8] | 60 |
|
---|
[f40a309] | 61 | errno = EIO; /* I/O error or seek past EOF */
|
---|
| 62 | return(FAILURE);
|
---|
[c091ef8] | 63 |
|
---|
[f40a309] | 64 | } else if (sv EQ 2) { /* at hard EOF ? */
|
---|
[c091ef8] | 65 |
|
---|
[f40a309] | 66 | if (_alcnew(fcp)) { /* allocate a new cluster */
|
---|
[c091ef8] | 67 |
|
---|
| 68 | errno = EIO;
|
---|
| 69 | return(FAILURE);
|
---|
[f40a309] | 70 | }
|
---|
| 71 | #if DEBUGIT
|
---|
[c091ef8] | 72 | if (fsdebug)
|
---|
| 73 | printf("WriteRN(): cluster allocated - curcls=%d, clsec=%d\n",
|
---|
[f40a309] | 74 | fcp->curcls, fcp->clsec);
|
---|
| 75 | #endif
|
---|
| 76 |
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | #if DEBUGIT
|
---|
[c091ef8] | 81 | if (fsdebug)
|
---|
| 82 | printf("WriteRN(): curlsn=%ld, curdsn=%ld\n",
|
---|
[f40a309] | 83 | fcp->curlsn, fcp->curdsn);
|
---|
| 84 | #endif
|
---|
[c091ef8] | 85 |
|
---|
[f40a309] | 86 | /* write the sector */
|
---|
[7258c6a] | 87 |
|
---|
[f40a309] | 88 | if (brc = BIOS(B_RDWR, 1, buf, 1, (int16_t)fcp->curdsn, 0)) {
|
---|
| 89 |
|
---|
| 90 | #if DEBUGIT
|
---|
[c091ef8] | 91 | if (fsdebug)
|
---|
[f40a309] | 92 | printf("WriteRN(): B_RDWR FAILED - brc=%ld\n", brc);
|
---|
| 93 | #endif
|
---|
[c091ef8] | 94 |
|
---|
| 95 | _berrno = brc; /* log the error */
|
---|
| 96 | errno = EIO; /* ... as an I/O error */
|
---|
[f40a309] | 97 | return(FAILURE); /* return: ERROR */
|
---|
| 98 | }
|
---|
[c091ef8] | 99 |
|
---|
[7258c6a] | 100 | #if TBUFFER
|
---|
[f40a309] | 101 | _secwr(buf, (int16_t)fcp->curdsn);
|
---|
| 102 | #endif
|
---|
[c091ef8] | 103 |
|
---|
[f40a309] | 104 | return(SUCCESS); /* return: SUCCESS */
|
---|
| 105 | }
|
---|