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

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

Added include files for global functions and variables.

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