source: buchla-68k/libcio/readrn.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: 1.7 KB
RevLine 
[f40a309]1/*
2 =============================================================================
3 readrn.c -- read a random sector from a file
4 Version 8 -- 1987-12-15 -- D.N. Lynx Crowe
5
6 int
7 ReadRN(fcp, buf)
8 struct fcb *fcp;
9 char *buf;
10
11 Reads a sector from file 'fcp' into 'buf'. Seeks as needed.
12 Returns 0 if OK, -1 for errors, 1 for EOF (no data returned).
13 =============================================================================
14*/
15
16#define DEBUGIT 0
17
[6262b5c]18#include "all.h"
[f40a309]19
20#if DEBUGIT
21extern short fsdebug;
22#endif
23
24#if TBUFFER
[7258c6a]25extern int32_t _secrd(int8_t *buf, int16_t rec);
[f40a309]26#endif
27
[7258c6a]28extern int32_t _berrno;
29extern int16_t _seek(struct fcb *fcp);
[f40a309]30
31/*
32
33*/
34
35/*
36 =============================================================================
37 ReadRN(fcp, buf) -- Reads a sector from file 'fcp' into 'buf'.
38 Seeks as needed. Returns SUCCESS (0) if OK, FAILURE (-1) for errors.
39 =============================================================================
40*/
[7258c6a]41
[f40a309]42int16_t ReadRN(struct fcb *fcp, int8_t *buf)
[7258c6a]43{
44 int16_t sv; /* seek return code */
[f40a309]45 int32_t brc; /* bios return code */
46
47 if (sv = _seek(fcp)) /* try to find the sector we want */
48 if (sv < 0) {
49
50 errno = EIO; /* I/O error */
51 return(-1); /* return: ERROR */
52
53 } else {
54
55 errno = EINVAL; /* invalid argument */
56 return(1); /* return: EOF */
57 }
58
59#if DEBUGIT
60 if (fsdebug)
61 printf("ReadRN(): curlsn=%ld, curdsn=%ld, offset=%u\n",
62 fcp->curlsn, fcp->curdsn, fcp->offset);
63#endif
64
[7258c6a]65#if TBUFFER
[f40a309]66 if (brc = _secrd(buf, (int16_t)fcp->curdsn)) {
67#else
68 if (brc = BIOS(B_RDWR, 0, buf, 1, (short)fcp->curdsn, 0)) {
69#endif
70
71 _berrno = brc; /* log the error */
72 errno = EIO; /* ... as an I/O error */
73 return(FAILURE); /* return: ERROR */
74 }
75
76 return(SUCCESS); /* return: SUCCESS */
[6262b5c]77}
78
Note: See TracBrowser for help on using the repository browser.