1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// io/common/include/file.h
|
4 |
|
|
//
|
5 |
|
|
// Defines for high level file I/O
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
16 |
|
|
//
|
17 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
18 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
19 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
20 |
|
|
// for more details.
|
21 |
|
|
//
|
22 |
|
|
// You should have received a copy of the GNU General Public License along
|
23 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
24 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
25 |
|
|
//
|
26 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
27 |
|
|
// or inline functions from this file, or you compile this file and link it
|
28 |
|
|
// with other works to produce a work based on this file, this file does not
|
29 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
30 |
|
|
// License. However the source code for this file must still be made available
|
31 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
32 |
|
|
//
|
33 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
34 |
|
|
// this file might be covered by the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
37 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
38 |
|
|
// -------------------------------------------
|
39 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
40 |
|
|
//==========================================================================
|
41 |
|
|
//#####DESCRIPTIONBEGIN####
|
42 |
|
|
//
|
43 |
|
|
// Author(s): gthomas
|
44 |
|
|
// Contributors: gthomas
|
45 |
|
|
// Date: 2000-01-10
|
46 |
|
|
// Purpose:
|
47 |
|
|
// Description:
|
48 |
|
|
//
|
49 |
|
|
//
|
50 |
|
|
//####DESCRIPTIONEND####
|
51 |
|
|
//
|
52 |
|
|
//==========================================================================
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
#ifndef _CYG_IO_FILE_H_
|
56 |
|
|
#define _CYG_IO_FILE_H_
|
57 |
|
|
|
58 |
|
|
#include <pkgconf/system.h>
|
59 |
|
|
|
60 |
|
|
//==========================================================================
|
61 |
|
|
// If the fileio package is loaded, we need to go through that to do all
|
62 |
|
|
// basic IO operations. This code redefines the tags on the structures so
|
63 |
|
|
// that they have the names expected by BSD based code.
|
64 |
|
|
|
65 |
|
|
#ifdef CYGPKG_IO_FILEIO
|
66 |
|
|
|
67 |
|
|
#include <pkgconf/io_fileio.h>
|
68 |
|
|
|
69 |
|
|
#define CYG_IOVEC_TAG iovec
|
70 |
|
|
#define CYG_UIO_TAG uio
|
71 |
|
|
#define CYG_FILEOPS_TAG fileops
|
72 |
|
|
#define CYG_FILE_TAG file
|
73 |
|
|
#define CYG_SELINFO_TAG selinfo
|
74 |
|
|
|
75 |
|
|
#include <cyg/fileio/fileio.h>
|
76 |
|
|
|
77 |
|
|
// File states
|
78 |
|
|
#define FREAD CYG_FREAD
|
79 |
|
|
#define FWRITE CYG_FWRITE
|
80 |
|
|
#define FNONBLOCK CYG_FNONBLOCK
|
81 |
|
|
#define FASYNC CYG_FASYNC
|
82 |
|
|
|
83 |
|
|
// Type of "file"
|
84 |
|
|
#define DTYPE_VNODE CYG_FILE_TYPE_FILE /* file */
|
85 |
|
|
#define DTYPE_SOCKET CYG_FILE_TYPE_SOCKET /* communications endpoint */
|
86 |
|
|
|
87 |
|
|
//==========================================================================
|
88 |
|
|
// Otherwise define all the structs here...
|
89 |
|
|
|
90 |
|
|
#else // CYGPKG_IO_FILEIO
|
91 |
|
|
|
92 |
|
|
// High-level file I/O interfaces
|
93 |
|
|
// Derived [in part] from OpenBSD <sys/file.h>, <sys/uio.h>, <sys/fcntl.h>
|
94 |
|
|
|
95 |
|
|
#include <pkgconf/io.h>
|
96 |
|
|
#include <cyg/infra/cyg_type.h>
|
97 |
|
|
|
98 |
|
|
#define NFILE CYGPKG_IO_NFILE
|
99 |
|
|
|
100 |
|
|
struct iovec {
|
101 |
|
|
void *iov_base; /* Base address. */
|
102 |
|
|
CYG_ADDRWORD iov_len; /* Length. */
|
103 |
|
|
};
|
104 |
|
|
|
105 |
|
|
enum uio_rw { UIO_READ, UIO_WRITE };
|
106 |
|
|
|
107 |
|
|
/* Segment flag values. */
|
108 |
|
|
enum uio_seg {
|
109 |
|
|
UIO_USERSPACE, /* from user data space */
|
110 |
|
|
UIO_SYSSPACE /* from system space */
|
111 |
|
|
};
|
112 |
|
|
|
113 |
|
|
struct uio {
|
114 |
|
|
struct iovec *uio_iov; /* pointer to array of iovecs */
|
115 |
|
|
int uio_iovcnt; /* number of iovecs in array */
|
116 |
|
|
CYG_ADDRWORD uio_offset; /* offset into file this uio corresponds to */
|
117 |
|
|
CYG_ADDRWORD uio_resid; /* residual i/o count */
|
118 |
|
|
enum uio_seg uio_segflg; /* see above */
|
119 |
|
|
enum uio_rw uio_rw; /* see above */
|
120 |
|
|
};
|
121 |
|
|
|
122 |
|
|
/*
|
123 |
|
|
* Limits
|
124 |
|
|
*/
|
125 |
|
|
#define UIO_SMALLIOV 8 /* 8 on stack, else malloc */
|
126 |
|
|
|
127 |
|
|
// Description of open file
|
128 |
|
|
struct file {
|
129 |
|
|
short f_flag; /* file state */
|
130 |
|
|
short f_type; /* descriptor type */
|
131 |
|
|
struct fileops {
|
132 |
|
|
int (*fo_read)(struct file *fp, struct uio *uio);
|
133 |
|
|
int (*fo_write)(struct file *fp, struct uio *uio);
|
134 |
|
|
int (*fo_ioctl)(struct file *fp, CYG_ADDRWORD com,
|
135 |
|
|
CYG_ADDRWORD data);
|
136 |
|
|
int (*fo_select)(struct file *fp, int which);
|
137 |
|
|
int (*fo_close)(struct file *fp);
|
138 |
|
|
} *f_ops;
|
139 |
|
|
CYG_ADDRWORD f_offset;
|
140 |
|
|
CYG_ADDRWORD f_data; /* vnode or socket */
|
141 |
|
|
};
|
142 |
|
|
|
143 |
|
|
// File states
|
144 |
|
|
#define FREAD 0x01
|
145 |
|
|
#define FWRITE 0x02
|
146 |
|
|
#define FNONBLOCK 0x10
|
147 |
|
|
#define FASYNC 0x20
|
148 |
|
|
#define FALLOC 0x80 // File is "busy", i.e. allocated
|
149 |
|
|
|
150 |
|
|
// Type of "file"
|
151 |
|
|
#define DTYPE_VNODE 1 /* file */
|
152 |
|
|
#define DTYPE_SOCKET 2 /* communications endpoint */
|
153 |
|
|
#define DTYPE_PIPE 3 /* pipe */
|
154 |
|
|
|
155 |
|
|
externC cyg_bool getfp(int fdes, struct file **fp);
|
156 |
|
|
externC int falloc(struct file **fp, int *fd);
|
157 |
|
|
externC void ffree(struct file *fp);
|
158 |
|
|
|
159 |
|
|
//==========================================================================
|
160 |
|
|
|
161 |
|
|
#endif // CYGPKG_IO_FILEIO
|
162 |
|
|
|
163 |
|
|
//==========================================================================
|
164 |
|
|
#endif // _CYG_IO_FILE_H_
|