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

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

No more warnings in libcio.

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