Mercurial > ecos-v3_0-branch
comparison packages/io/fileio/current/include/fileio.h @ 115:6ed91473a1cd ecos-sw-2000-08-21
Merge from eCos master repository on 2000-08-21-22:40:54-BST
| author | jlarmour |
|---|---|
| date | Fri, 25 Aug 2000 17:32:38 +0000 |
| parents | |
| children | 6bd9d475ed4b |
comparison
equal
deleted
inserted
replaced
| 114:5ad2b71d525e | 115:6ed91473a1cd |
|---|---|
| 1 #ifndef CYGONCE_FILEIO_H | |
| 2 #define CYGONCE_FILEIO_H | |
| 3 //============================================================================= | |
| 4 // | |
| 5 // fileio.h | |
| 6 // | |
| 7 // Fileio header | |
| 8 // | |
| 9 //============================================================================= | |
| 10 //####COPYRIGHTBEGIN#### | |
| 11 // | |
| 12 // ------------------------------------------- | |
| 13 // The contents of this file are subject to the Red Hat eCos Public License | |
| 14 // Version 1.1 (the "License"); you may not use this file except in | |
| 15 // compliance with the License. You may obtain a copy of the License at | |
| 16 // http://www.redhat.com/ | |
| 17 // | |
| 18 // Software distributed under the License is distributed on an "AS IS" | |
| 19 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 20 // License for the specific language governing rights and limitations under | |
| 21 // the License. | |
| 22 // | |
| 23 // The Original Code is eCos - Embedded Configurable Operating System, | |
| 24 // released September 30, 1998. | |
| 25 // | |
| 26 // The Initial Developer of the Original Code is Red Hat. | |
| 27 // Portions created by Red Hat are | |
| 28 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. | |
| 29 // All Rights Reserved. | |
| 30 // ------------------------------------------- | |
| 31 // | |
| 32 //####COPYRIGHTEND#### | |
| 33 //============================================================================= | |
| 34 //#####DESCRIPTIONBEGIN#### | |
| 35 // | |
| 36 // Author(s): nickg | |
| 37 // Contributors: nickg | |
| 38 // Date: 2000-05-25 | |
| 39 // Purpose: Fileio header | |
| 40 // Description: This header contains the external definitions of the general file | |
| 41 // IO subsystem for POSIX and EL/IX compatability. | |
| 42 // | |
| 43 // Usage: | |
| 44 // #include <fileio.h> | |
| 45 // ... | |
| 46 // | |
| 47 // | |
| 48 //####DESCRIPTIONEND#### | |
| 49 // | |
| 50 //============================================================================= | |
| 51 | |
| 52 #include <pkgconf/hal.h> | |
| 53 #include <pkgconf/kernel.h> | |
| 54 #include <pkgconf/io_fileio.h> | |
| 55 | |
| 56 #include <cyg/infra/cyg_type.h> | |
| 57 #include <cyg/hal/hal_tables.h> | |
| 58 | |
| 59 #include <stddef.h> // NULL, size_t | |
| 60 #include <limits.h> | |
| 61 #include <sys/types.h> | |
| 62 #include <fcntl.h> | |
| 63 #include <sys/stat.h> | |
| 64 | |
| 65 //============================================================================= | |
| 66 // forward definitions | |
| 67 | |
| 68 struct cyg_mtab_entry; | |
| 69 typedef struct cyg_mtab_entry cyg_mtab_entry; | |
| 70 | |
| 71 struct cyg_fstab_entry; | |
| 72 typedef struct cyg_fstab_entry cyg_fstab_entry; | |
| 73 | |
| 74 struct CYG_FILEOPS_TAG; | |
| 75 typedef struct CYG_FILEOPS_TAG cyg_fileops; | |
| 76 | |
| 77 struct CYG_FILE_TAG; | |
| 78 typedef struct CYG_FILE_TAG cyg_file; | |
| 79 | |
| 80 struct CYG_IOVEC_TAG; | |
| 81 typedef struct CYG_IOVEC_TAG cyg_iovec; | |
| 82 | |
| 83 struct CYG_UIO_TAG; | |
| 84 typedef struct CYG_UIO_TAG cyg_uio; | |
| 85 | |
| 86 struct CYG_SELINFO_TAG; | |
| 87 typedef struct CYG_SELINFO_TAG cyg_selinfo; | |
| 88 | |
| 89 //============================================================================= | |
| 90 // Directory pointer | |
| 91 | |
| 92 typedef CYG_ADDRWORD cyg_dir; | |
| 93 | |
| 94 #define CYG_DIR_NULL 0 | |
| 95 | |
| 96 //============================================================================= | |
| 97 // Filesystem table entry | |
| 98 | |
| 99 typedef int cyg_fsop_mount ( cyg_fstab_entry *fste, cyg_mtab_entry *mte ); | |
| 100 typedef int cyg_fsop_umount ( cyg_mtab_entry *mte ); | |
| 101 typedef int cyg_fsop_open ( cyg_mtab_entry *mte, cyg_dir dir, const char *name, | |
| 102 int mode, cyg_file *fte ); | |
| 103 typedef int cyg_fsop_unlink ( cyg_mtab_entry *mte, cyg_dir dir, const char *name ); | |
| 104 typedef int cyg_fsop_mkdir ( cyg_mtab_entry *mte, cyg_dir dir, const char *name ); | |
| 105 typedef int cyg_fsop_rmdir ( cyg_mtab_entry *mte, cyg_dir dir, const char *name ); | |
| 106 typedef int cyg_fsop_rename ( cyg_mtab_entry *mte, cyg_dir dir1, const char *name1, | |
| 107 cyg_dir dir2, const char *name2 ); | |
| 108 typedef int cyg_fsop_link ( cyg_mtab_entry *mte, cyg_dir dir1, const char *name1, | |
| 109 cyg_dir dir2, const char *name2, int type ); | |
| 110 typedef int cyg_fsop_opendir ( cyg_mtab_entry *mte, cyg_dir dir, const char *name, | |
| 111 cyg_file *fte ); | |
| 112 typedef int cyg_fsop_chdir ( cyg_mtab_entry *mte, cyg_dir dir, const char *name, | |
| 113 cyg_dir *dir_out ); | |
| 114 typedef int cyg_fsop_stat ( cyg_mtab_entry *mte, cyg_dir dir, const char *name, | |
| 115 struct stat *buf); | |
| 116 typedef int cyg_fsop_getinfo ( cyg_mtab_entry *mte, cyg_dir dir, const char *name, | |
| 117 int key, void *buf, int len ); | |
| 118 typedef int cyg_fsop_setinfo ( cyg_mtab_entry *mte, cyg_dir dir, const char *name, | |
| 119 int key, void *buf, int len ); | |
| 120 | |
| 121 | |
| 122 struct cyg_fstab_entry | |
| 123 { | |
| 124 const char *name; // filesystem name | |
| 125 CYG_ADDRWORD data; // private data value | |
| 126 cyg_uint32 syncmode; // synchronization mode | |
| 127 | |
| 128 cyg_fsop_mount *mount; | |
| 129 cyg_fsop_umount *umount; | |
| 130 cyg_fsop_open *open; | |
| 131 cyg_fsop_unlink *unlink; | |
| 132 cyg_fsop_mkdir *mkdir; | |
| 133 cyg_fsop_rmdir *rmdir; | |
| 134 cyg_fsop_rename *rename; | |
| 135 cyg_fsop_link *link; | |
| 136 cyg_fsop_opendir *opendir; | |
| 137 cyg_fsop_chdir *chdir; | |
| 138 cyg_fsop_stat *stat; | |
| 139 cyg_fsop_getinfo *getinfo; | |
| 140 cyg_fsop_setinfo *setinfo; | |
| 141 }; | |
| 142 | |
| 143 //----------------------------------------------------------------------------- | |
| 144 // Keys for getinfo() and setinfo() | |
| 145 | |
| 146 #define FS_INFO_CONF 1 /* pathconf() */ | |
| 147 #define FS_INFO_ACCESS 2 /* access() */ | |
| 148 | |
| 149 //----------------------------------------------------------------------------- | |
| 150 // Types for link() | |
| 151 | |
| 152 #define CYG_FSLINK_HARD 1 /* form a hard link */ | |
| 153 #define CYG_FSLINK_SOFT 2 /* form a soft link */ | |
| 154 | |
| 155 //----------------------------------------------------------------------------- | |
| 156 // Macro to define an initialized fstab entry | |
| 157 | |
| 158 #define FSTAB_ENTRY( _l, _name, _data, _syncmode, _mount, _umount, \ | |
| 159 _open, _unlink, _mkdir, _rmdir, _rename, _link, \ | |
| 160 _opendir, _chdir, _stat, _getinfo, _setinfo) \ | |
| 161 struct cyg_fstab_entry _l CYG_HAL_TABLE_ENTRY( fstab ) = \ | |
| 162 { \ | |
| 163 _name, \ | |
| 164 _data, \ | |
| 165 _syncmode, \ | |
| 166 _mount, \ | |
| 167 _umount, \ | |
| 168 _open, \ | |
| 169 _unlink, \ | |
| 170 _mkdir, \ | |
| 171 _rmdir, \ | |
| 172 _rename, \ | |
| 173 _link, \ | |
| 174 _opendir, \ | |
| 175 _chdir, \ | |
| 176 _stat, \ | |
| 177 _getinfo, \ | |
| 178 _setinfo \ | |
| 179 }; | |
| 180 | |
| 181 //============================================================================= | |
| 182 // Mount table entry | |
| 183 | |
| 184 struct cyg_mtab_entry | |
| 185 { | |
| 186 const char *name; // name of mount point | |
| 187 const char *fsname; // name of implementing filesystem | |
| 188 const char *devname; // name of hardware device | |
| 189 CYG_ADDRWORD data; // private data value | |
| 190 | |
| 191 // The following are filled in after a successful mount operation | |
| 192 cyg_bool valid; // Valid entry? | |
| 193 cyg_fstab_entry *fs; // pointer to fstab entry | |
| 194 cyg_dir root; // root directory pointer | |
| 195 }; | |
| 196 | |
| 197 | |
| 198 // This macro defines an initialized mtab entry | |
| 199 | |
| 200 #define MTAB_ENTRY( _l, _name, _fsname, _devname, _data ) \ | |
| 201 struct cyg_mtab_entry _l CYG_HAL_TABLE_ENTRY( mtab ) = \ | |
| 202 { \ | |
| 203 _name, \ | |
| 204 _fsname, \ | |
| 205 _devname, \ | |
| 206 _data, \ | |
| 207 false, \ | |
| 208 NULL, \ | |
| 209 CYG_DIR_NULL \ | |
| 210 }; | |
| 211 | |
| 212 //============================================================================= | |
| 213 // IO vector descriptors | |
| 214 | |
| 215 struct CYG_IOVEC_TAG | |
| 216 { | |
| 217 void *iov_base; /* Base address. */ | |
| 218 ssize_t iov_len; /* Length. */ | |
| 219 }; | |
| 220 | |
| 221 enum cyg_uio_rw { UIO_READ, UIO_WRITE }; | |
| 222 | |
| 223 /* Segment flag values. */ | |
| 224 enum cyg_uio_seg | |
| 225 { | |
| 226 UIO_USERSPACE, /* from user data space */ | |
| 227 UIO_SYSSPACE /* from system space */ | |
| 228 }; | |
| 229 | |
| 230 struct CYG_UIO_TAG | |
| 231 { | |
| 232 struct CYG_IOVEC_TAG *uio_iov; /* pointer to array of iovecs */ | |
| 233 int uio_iovcnt; /* number of iovecs in array */ | |
| 234 off_t uio_offset; /* offset into file this uio corresponds to */ | |
| 235 ssize_t uio_resid; /* residual i/o count */ | |
| 236 enum cyg_uio_seg uio_segflg; /* see above */ | |
| 237 enum cyg_uio_rw uio_rw; /* see above */ | |
| 238 }; | |
| 239 | |
| 240 // Limits | |
| 241 #define UIO_SMALLIOV 8 /* 8 on stack, else malloc */ | |
| 242 | |
| 243 //============================================================================= | |
| 244 // Description of open file | |
| 245 | |
| 246 typedef int cyg_fileop_read (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio); | |
| 247 typedef int cyg_fileop_write (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio); | |
| 248 typedef int cyg_fileop_lseek (struct CYG_FILE_TAG *fp, off_t *pos, int whence ); | |
| 249 typedef int cyg_fileop_ioctl (struct CYG_FILE_TAG *fp, CYG_ADDRWORD com, | |
| 250 CYG_ADDRWORD data); | |
| 251 typedef int cyg_fileop_select (struct CYG_FILE_TAG *fp, int which, CYG_ADDRWORD info); | |
| 252 typedef int cyg_fileop_fsync (struct CYG_FILE_TAG *fp, int mode ); | |
| 253 typedef int cyg_fileop_close (struct CYG_FILE_TAG *fp); | |
| 254 typedef int cyg_fileop_fstat (struct CYG_FILE_TAG *fp, struct stat *buf ); | |
| 255 typedef int cyg_fileop_getinfo (struct CYG_FILE_TAG *fp, int key, void *buf, int len ); | |
| 256 typedef int cyg_fileop_setinfo (struct CYG_FILE_TAG *fp, int key, void *buf, int len ); | |
| 257 | |
| 258 struct CYG_FILEOPS_TAG | |
| 259 { | |
| 260 cyg_fileop_read *fo_read; | |
| 261 cyg_fileop_write *fo_write; | |
| 262 cyg_fileop_lseek *fo_lseek; | |
| 263 cyg_fileop_ioctl *fo_ioctl; | |
| 264 cyg_fileop_select *fo_select; | |
| 265 cyg_fileop_fsync *fo_fsync; | |
| 266 cyg_fileop_close *fo_close; | |
| 267 cyg_fileop_fstat *fo_fstat; | |
| 268 cyg_fileop_getinfo *fo_getinfo; | |
| 269 cyg_fileop_setinfo *fo_setinfo; | |
| 270 }; | |
| 271 | |
| 272 struct CYG_FILE_TAG | |
| 273 { | |
| 274 cyg_uint32 f_flag; /* file state */ | |
| 275 cyg_uint16 f_ucount; /* use count */ | |
| 276 cyg_uint16 f_type; /* descriptor type */ | |
| 277 cyg_uint32 f_syncmode; /* synchronization protocol */ | |
| 278 struct CYG_FILEOPS_TAG *f_ops; /* file operations */ | |
| 279 off_t f_offset; /* current offset */ | |
| 280 CYG_ADDRWORD f_data; /* file or socket */ | |
| 281 CYG_ADDRWORD f_xops; /* extra type specific ops */ | |
| 282 cyg_mtab_entry *f_mte; /* mount table entry */ | |
| 283 }; | |
| 284 | |
| 285 //----------------------------------------------------------------------------- | |
| 286 // File flags | |
| 287 | |
| 288 // Allocation here is that bits 0..15 are copies of bits from the open | |
| 289 // flags, bits 16..23 are extra bits that are visible to filesystems but | |
| 290 // are not derived from the open call, and bits 24..31 are reserved for | |
| 291 // the fileio infrastructure. | |
| 292 #define CYG_FREAD O_RDONLY | |
| 293 #define CYG_FWRITE O_WRONLY | |
| 294 #define CYG_FNONBLOCK O_NONBLOCK | |
| 295 #define CYG_FAPPEND O_APPEND | |
| 296 #define CYG_FASYNC 0x00010000 | |
| 297 #define CYG_FDIR 0x00020000 | |
| 298 | |
| 299 #define CYG_FLOCKED 0x01000000 // Set if file is locked | |
| 300 #define CYG_FLOCK 0x02000000 // Lock during file ops | |
| 301 #define CYG_FALLOC 0x80000000 // File is "busy", i.e. allocated | |
| 302 | |
| 303 // Mask for open mode bits stored in file object | |
| 304 #define CYG_FILE_MODE_MASK (CYG_FREAD|CYG_FWRITE|CYG_FNONBLOCK|CYG_FAPPEND) | |
| 305 | |
| 306 //----------------------------------------------------------------------------- | |
| 307 // Type of file | |
| 308 | |
| 309 #define CYG_FILE_TYPE_FILE 1 /* file */ | |
| 310 #define CYG_FILE_TYPE_SOCKET 2 /* communications endpoint */ | |
| 311 #define CYG_FILE_TYPE_DEVICE 3 /* device */ | |
| 312 | |
| 313 //----------------------------------------------------------------------------- | |
| 314 // Keys for getinf() and setinfo() | |
| 315 | |
| 316 #define FILE_INFO_CONF 1 /* fpathconf() */ | |
| 317 | |
| 318 //----------------------------------------------------------------------------- | |
| 319 // Modes for fsync() | |
| 320 | |
| 321 #define CYG_FSYNC 1 | |
| 322 #define CYG_FDATASYNC 2 | |
| 323 | |
| 324 //----------------------------------------------------------------------------- | |
| 325 // Get/set info buffer structures | |
| 326 | |
| 327 // This is used for pathconf() and fpathconf() | |
| 328 struct cyg_pathconf_info | |
| 329 { | |
| 330 int name; // POSIX defined variable name | |
| 331 long value; // Returned variable value | |
| 332 }; | |
| 333 | |
| 334 //============================================================================= | |
| 335 // Synchronization modes | |
| 336 // These values are filled into the syncmode fields of the above structures | |
| 337 // and define the synchronization protocol used when accessing the object in | |
| 338 // question. | |
| 339 | |
| 340 #define CYG_SYNCMODE_NONE (0) // no locking required | |
| 341 | |
| 342 #define CYG_SYNCMODE_FILE_FILESYSTEM 0x0002 // lock fs during file ops | |
| 343 #define CYG_SYNCMODE_FILE_MOUNTPOINT 0x0004 // lock mte during file ops | |
| 344 #define CYG_SYNCMODE_IO_FILE 0x0010 // lock file during io ops | |
| 345 #define CYG_SYNCMODE_IO_FILESYSTEM 0x0020 // lock fs during io ops | |
| 346 #define CYG_SYNCMODE_IO_MOUNTPOINT 0x0040 // lock mte during io ops | |
| 347 #define CYG_SYNCMODE_SOCK_FILE 0x0100 // lock socket during socket ops | |
| 348 #define CYG_SYNCMODE_SOCK_NETSTACK 0x0800 // lock netstack during socket ops | |
| 349 | |
| 350 #define CYG_SYNCMODE_IO_SHIFT (4) // shift for IO to file bits | |
| 351 #define CYG_SYNCMODE_SOCK_SHIFT (8) // shift for sock to file bits | |
| 352 | |
| 353 //============================================================================= | |
| 354 // Mount and umount functions | |
| 355 | |
| 356 __externC int mount( const char *devname, | |
| 357 const char *dir, | |
| 358 const char *fsname); | |
| 359 | |
| 360 __externC int umount( const char *name); | |
| 361 | |
| 362 //============================================================================= | |
| 363 // Select support | |
| 364 | |
| 365 //----------------------------------------------------------------------------- | |
| 366 // Data structure for embedding in client data structures. A pointer to this | |
| 367 // must be passed to cyg_selrecord() and cyg_selwakeup(). | |
| 368 | |
| 369 struct CYG_SELINFO_TAG | |
| 370 { | |
| 371 CYG_ADDRWORD si_info; // info passed through from fo_select() | |
| 372 CYG_ADDRESS si_thread; // selecting thread pointer | |
| 373 }; | |
| 374 | |
| 375 //----------------------------------------------------------------------------- | |
| 376 // Select support functions. | |
| 377 | |
| 378 // cyg_selinit() is used to initialize a selinfo structure. | |
| 379 __externC void cyg_selinit( struct CYG_SELINFO_TAG *sip ); | |
| 380 | |
| 381 // cyg_selrecord() is called when a client device needs to register | |
| 382 // the current thread for selection. | |
| 383 __externC void cyg_selrecord( CYG_ADDRWORD info, struct CYG_SELINFO_TAG *sip ); | |
| 384 | |
| 385 // cyg_selwakeup() is called when the client device matches the select | |
| 386 // criterion, and needs to wake up a selector. | |
| 387 __externC void cyg_selwakeup( struct CYG_SELINFO_TAG *sip ); | |
| 388 | |
| 389 //============================================================================= | |
| 390 // Timestamp support | |
| 391 | |
| 392 // Provides the current time as a time_t timestamp for use in filesystem | |
| 393 // data strucures. | |
| 394 | |
| 395 __externC time_t cyg_timestamp(void); | |
| 396 | |
| 397 //============================================================================= | |
| 398 // Default functions. | |
| 399 // Cast to the appropriate type, these functions can be put into any of | |
| 400 // the operation table slots to provide the defined error code. | |
| 401 | |
| 402 __externC int cyg_fileio_enosys(void); | |
| 403 __externC int cyg_fileio_erofs(void); | |
| 404 __externC int cyg_fileio_enoerr(void); | |
| 405 __externC int cyg_fileio_enotdir(void); | |
| 406 __externC cyg_fileop_select cyg_fileio_seltrue; | |
| 407 | |
| 408 //----------------------------------------------------------------------------- | |
| 409 #endif // ifndef CYGONCE_FILEIO_H | |
| 410 // End of fileio.h |
