File: zfiosf.c

package info (click to toggle)
iraf 2.17-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 95,288 kB
  • sloc: ansic: 228,894; fortran: 75,606; lisp: 18,369; xml: 8,401; sh: 6,111; yacc: 5,648; lex: 596; makefile: 575; asm: 153; csh: 95; sed: 4
file content (131 lines) | stat: -rw-r--r-- 4,073 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
 */

#include <stdio.h>

#define	import_kernel
#define	import_knames
#define import_spp
#include <iraf.h>

/*
 * ZFIOSF -- Static file device driver.  In the 4.1BSD UNIX kernel the ordinary
 * binary file driver is used for static files (files that do not change in
 * size once created by ZFALOC), hence all we need do to implement a SF routine
 * is call the corresponding BF routine.  A great gain in i/o efficiency could 
 * probably be gained by replacing this driver by one using raw i/o, but we do
 * not want to bother with that for 4.1BSD UNIX because the time would be
 * better spent doing it for 4.2BSD.
 *
 * If anyone is stuck with 4.1BSD for some reason and wants fast static file
 * i/o, the strategy is to try to allocate contiguous files with ZFALOC, either
 * in a raw partition using a special file manager or within an ordinary
 * partition adding a new system call to allocate contiguous storage for a file.
 * The latter scheme has the advantage that files thus created are ordinary
 * UNIX files and can be accessed normally as well as by the static file driver.
 * Given a contiguous or near-contiguous file on disk, all the static file
 * driver needs for direct access with large transfers is the physical block
 * offset of the file.  The raw device is then accessed via physio calls to
 * transfer data directly to or from the user's buffer, bypassing the system
 * buffer cache.  Write perm is required on the raw device for the target
 * filesystem; this opens up the possibility of trashing the files system.
 * Static file access should be restricted to one or more large temporary files
 * systems.  If one gets really ambitious a special UNIX driver can be added to
 * permit asynchronous i/o, bypassing the UNIX files system entirely except
 * during file creation and deletion.
 */

extern	int ZARDBF (XINT *chan, XCHAR *buf, XINT *maxbytes, XLONG *offset);
extern	int ZAWRBF (XINT *chan, XCHAR *buf, XINT *nbytes, XLONG *offset);
extern	int ZAWTBF (XINT *fd, XINT *status);
extern	int ZCLSBF (XINT *fd, XINT *status);
extern	int ZOPNBF (PKCHAR *osfn, XINT *mode, XINT *chan);
extern	int ZSTTBF (XINT *fd, XINT *param, XLONG *lvalue);


/* ZOPNSF -- Open a static file.  Only RO, WO, and RW modes are permitted
 * for static files, since allocation is via ZFALOC and appending is not
 * permitted.
 */
int
ZOPNSF (
  PKCHAR  *osfn,			/* UNIX name of file		*/
  XINT	  *mode,			/* file access mode		*/
  XINT	  *chan 			/* file number (output)		*/
)
{
	switch (*mode) {
	case READ_ONLY:
	case WRITE_ONLY:
	case READ_WRITE:
	    return ZOPNBF (osfn, mode, chan);
	    break;
	default:
	    *chan = XERR;
	    return (*chan);
	}
}


/* ZCLSSF -- Close a static file.
 */
int
ZCLSSF (XINT *fd, XINT *status)
{
	return ZCLSBF (fd, status);
}


/* ZARDSF -- "Asynchronous" static block read.  Initiate a read of at most
 * maxbytes bytes from the file FD into the buffer BUF.  Status is returned
 * in a subsequent call to ZAWTSF.
 */
int
ZARDSF (
  XINT	*chan,			/* UNIX file number			*/
  XCHAR	*buf,			/* output buffer			*/
  XINT	*maxbytes,		/* max bytes to read			*/
  XLONG	*offset 		/* 1-indexed file offset to read at	*/
)
{
	return ZARDBF (chan, buf, maxbytes, offset);
}


/* ZAWRSF -- "Asynchronous" static block write.  Initiate a write of exactly
 * nbytes bytes from the buffer BUF to the file FD.  Status is returned in a
 * subsequent call to ZAWTSF.
 */
int
ZAWRSF (
  XINT	*chan,			/* UNIX file number		*/
  XCHAR	*buf,			/* buffer containing data	*/
  XINT	*nbytes,		/* nbytes to be written		*/
  XLONG	*offset 		/* 1-indexed file offset	*/
)
{
	return ZAWRBF (chan, buf, nbytes, offset);
}


/* ZAWTSF -- "Wait" for an "asynchronous" read or write to complete, and
 * return the number of bytes read or written, or ERR.
 */
int
ZAWTSF (XINT *fd, XINT *status)
{
	return ZAWTBF (fd, status);
}


/* ZSTTSF -- Return status on a static file.
 */
int
ZSTTSF (
  XINT	*fd,
  XINT	*param,
  XLONG	*lvalue
)
{
	return ZSTTBF (fd, param, lvalue);
}