source: buchla-68k/libcio/writern.c@ e225e77

Last change on this file since e225e77 was e225e77, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Added missing includes and declarations.

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