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

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

Use correct writern.c file.

  • 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
[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
[c091ef8]24extern long _berrno;
25extern int _seek();
[f40a309]26
27#if DEBUGIT
28extern short fsdebug;
29#endif
30
[c091ef8]31#if TBUFFER
32extern long _secwr(); /* update buffer function */
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*/
45
[c091ef8]46int
47WriteRN(fcp, buf)
[f40a309]48struct fcb *fcp;
49char *buf;
[c091ef8]50{
51 int sv; /* seek return code */
[f40a309]52 long brc; /* bios return code */
[c091ef8]53
[f40a309]54 if (sv = _seek(fcp)) { /* try to find the sector we want */
[c091ef8]55
[f40a309]56 if (sv < 0) { /* seek error ? */
57
58#if DEBUGIT
[c091ef8]59 if (fsdebug)
60 printf("WriteRN(): _seek FAILED (%d) - curlsn=%ld, curdsn=%ld\n",
[f40a309]61 sv, fcp->curlsn, fcp->curdsn);
62#endif
[c091ef8]63
[f40a309]64 errno = EIO; /* I/O error or seek past EOF */
65 return(FAILURE);
[c091ef8]66
[f40a309]67 } else if (sv EQ 2) { /* at hard EOF ? */
[c091ef8]68
[f40a309]69 if (_alcnew(fcp)) { /* allocate a new cluster */
[c091ef8]70
71 errno = EIO;
72 return(FAILURE);
[f40a309]73 }
74#if DEBUGIT
[c091ef8]75 if (fsdebug)
76 printf("WriteRN(): cluster allocated - curcls=%d, clsec=%d\n",
[f40a309]77 fcp->curcls, fcp->clsec);
78#endif
79
80 }
81 }
82
83#if DEBUGIT
[c091ef8]84 if (fsdebug)
85 printf("WriteRN(): curlsn=%ld, curdsn=%ld\n",
[f40a309]86 fcp->curlsn, fcp->curdsn);
87#endif
[c091ef8]88
[f40a309]89 /* write the sector */
[c091ef8]90
[f40a309]91 if (brc = BIOS(B_RDWR, 1, buf, 1, (short)fcp->curdsn, 0)) {
92
93#if DEBUGIT
[c091ef8]94 if (fsdebug)
[f40a309]95 printf("WriteRN(): B_RDWR FAILED - brc=%ld\n", brc);
96#endif
[c091ef8]97
98 _berrno = brc; /* log the error */
99 errno = EIO; /* ... as an I/O error */
[f40a309]100 return(FAILURE); /* return: ERROR */
101 }
[c091ef8]102
103#if TBUFFER
[f40a309]104 _secwr(buf, (short)fcp->curdsn);
105#endif
[c091ef8]106
[f40a309]107 return(SUCCESS); /* return: SUCCESS */
108}
Note: See TracBrowser for help on using the repository browser.