📄 fileio.h
字号:
CYG_DIR_NULL \
};
//=============================================================================
// IO vector descriptors
struct CYG_IOVEC_TAG
{
void *iov_base; /* Base address. */
ssize_t iov_len; /* Length. */
};
enum cyg_uio_rw { UIO_READ, UIO_WRITE };
/* Segment flag values. */
enum cyg_uio_seg
{
UIO_USERSPACE, /* from user data space */
UIO_SYSSPACE /* from system space */
};
struct CYG_UIO_TAG
{
struct CYG_IOVEC_TAG *uio_iov; /* pointer to array of iovecs */
int uio_iovcnt; /* number of iovecs in array */
off_t uio_offset; /* offset into file this uio corresponds to */
ssize_t uio_resid; /* residual i/o count */
enum cyg_uio_seg uio_segflg; /* see above */
enum cyg_uio_rw uio_rw; /* see above */
};
// Limits
#define UIO_SMALLIOV 8 /* 8 on stack, else malloc */
//=============================================================================
// Description of open file
typedef int cyg_fileop_readwrite (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio);
typedef cyg_fileop_readwrite cyg_fileop_read;
typedef cyg_fileop_readwrite cyg_fileop_write;
typedef int cyg_fileop_lseek (struct CYG_FILE_TAG *fp, off_t *pos, int whence );
typedef int cyg_fileop_ioctl (struct CYG_FILE_TAG *fp, CYG_ADDRWORD com,
CYG_ADDRWORD data);
typedef cyg_bool cyg_fileop_select (struct CYG_FILE_TAG *fp, int which, CYG_ADDRWORD info);
typedef int cyg_fileop_fsync (struct CYG_FILE_TAG *fp, int mode );
typedef int cyg_fileop_close (struct CYG_FILE_TAG *fp);
typedef int cyg_fileop_fstat (struct CYG_FILE_TAG *fp, struct stat *buf );
typedef int cyg_fileop_getinfo (struct CYG_FILE_TAG *fp, int key, void *buf, int len );
typedef int cyg_fileop_setinfo (struct CYG_FILE_TAG *fp, int key, void *buf, int len );
struct CYG_FILEOPS_TAG
{
cyg_fileop_read *fo_read;
cyg_fileop_write *fo_write;
cyg_fileop_lseek *fo_lseek;
cyg_fileop_ioctl *fo_ioctl;
cyg_fileop_select *fo_select;
cyg_fileop_fsync *fo_fsync;
cyg_fileop_close *fo_close;
cyg_fileop_fstat *fo_fstat;
cyg_fileop_getinfo *fo_getinfo;
cyg_fileop_setinfo *fo_setinfo;
};
struct CYG_FILE_TAG
{
cyg_uint32 f_flag; /* file state */
cyg_uint16 f_ucount; /* use count */
cyg_uint16 f_type; /* descriptor type */
cyg_uint32 f_syncmode; /* synchronization protocol */
struct CYG_FILEOPS_TAG *f_ops; /* file operations */
off_t f_offset; /* current offset */
CYG_ADDRWORD f_data; /* file or socket */
CYG_ADDRWORD f_xops; /* extra type specific ops */
cyg_mtab_entry *f_mte; /* mount table entry */
};
//-----------------------------------------------------------------------------
// File flags
// Allocation here is that bits 0..15 are copies of bits from the open
// flags, bits 16..23 are extra bits that are visible to filesystems but
// are not derived from the open call, and bits 24..31 are reserved for
// the fileio infrastructure.
#define CYG_FREAD O_RDONLY
#define CYG_FWRITE O_WRONLY
#define CYG_FNONBLOCK O_NONBLOCK
#define CYG_FAPPEND O_APPEND
#define CYG_FASYNC 0x00010000
#define CYG_FDIR 0x00020000
#define CYG_FLOCKED 0x01000000 // Set if file is locked
#define CYG_FLOCK 0x02000000 // Lock during file ops
#define CYG_FALLOC 0x80000000 // File is "busy", i.e. allocated
// Mask for open mode bits stored in file object
#define CYG_FILE_MODE_MASK (CYG_FREAD|CYG_FWRITE|CYG_FNONBLOCK|CYG_FAPPEND)
//-----------------------------------------------------------------------------
// Type of file
#define CYG_FILE_TYPE_FILE 1 /* file */
#define CYG_FILE_TYPE_SOCKET 2 /* communications endpoint */
#define CYG_FILE_TYPE_DEVICE 3 /* device */
//-----------------------------------------------------------------------------
// Keys for getinfo() and setinfo()
#define FILE_INFO_CONF 1 /* fpathconf() */
//-----------------------------------------------------------------------------
// Modes for fsync()
#define CYG_FSYNC 1
#define CYG_FDATASYNC 2
//-----------------------------------------------------------------------------
// Get/set info buffer structures
// This is used for pathconf() and fpathconf()
struct cyg_pathconf_info
{
int name; // POSIX defined variable name
long value; // Returned variable value
};
//=============================================================================
// Synchronization modes
// These values are filled into the syncmode fields of the above structures
// and define the synchronization protocol used when accessing the object in
// question.
#define CYG_SYNCMODE_NONE (0) // no locking required
#define CYG_SYNCMODE_FILE_FILESYSTEM 0x0002 // lock fs during file ops
#define CYG_SYNCMODE_FILE_MOUNTPOINT 0x0004 // lock mte during file ops
#define CYG_SYNCMODE_IO_FILE 0x0010 // lock file during io ops
#define CYG_SYNCMODE_IO_FILESYSTEM 0x0020 // lock fs during io ops
#define CYG_SYNCMODE_IO_MOUNTPOINT 0x0040 // lock mte during io ops
#define CYG_SYNCMODE_SOCK_FILE 0x0100 // lock socket during socket ops
#define CYG_SYNCMODE_SOCK_NETSTACK 0x0800 // lock netstack during socket ops
#define CYG_SYNCMODE_IO_SHIFT (4) // shift for IO to file bits
#define CYG_SYNCMODE_SOCK_SHIFT (8) // shift for sock to file bits
//=============================================================================
// Mount and umount functions
__externC int mount( const char *devname,
const char *dir,
const char *fsname);
__externC int umount( const char *name);
//=============================================================================
// Get/Set info functions
__externC int cyg_fs_getinfo( const char *path, int key, void *buf, int len );
__externC int cyg_fs_setinfo( const char *path, int key, void *buf, int len );
__externC int cyg_fs_fgetinfo( int fd, int key, void *buf, int len );
__externC int cyg_fs_fsetinfo( int fd, int key, void *buf, int len );
#ifdef CYGFUN_IO_FILEIO_SELECT
//=============================================================================
// Select support
//-----------------------------------------------------------------------------
// Data structure for embedding in client data structures. A pointer to this
// must be passed to cyg_selrecord() and cyg_selwakeup().
struct CYG_SELINFO_TAG
{
CYG_ADDRWORD si_info; // info passed through from fo_select()
cyg_flag_value_t si_waitFlag; // select wait flags
};
//-----------------------------------------------------------------------------
// Select support functions.
// cyg_selinit() is used to initialize a selinfo structure.
__externC void cyg_selinit( struct CYG_SELINFO_TAG *sip );
// cyg_selrecord() is called when a client device needs to register
// the current thread for selection.
__externC void cyg_selrecord( CYG_ADDRWORD info, struct CYG_SELINFO_TAG *sip );
// cyg_selwakeup() is called when the client device matches the select
// criterion, and needs to wake up a selector.
__externC void cyg_selwakeup( struct CYG_SELINFO_TAG *sip );
#endif
//=============================================================================
// Timestamp support
// Provides the current time as a time_t timestamp for use in filesystem
// data strucures.
__externC time_t cyg_timestamp(void);
//=============================================================================
// Miscellaneous functions.
// Provide a function to synchronize an individual file system. (ie write
// file and directory information to disk)
__externC int cyg_fs_fssync(const char *path);
// Functions to set and get attributes of a file, eg FAT attributes
// like hidden and system.
__externC int cyg_fs_set_attrib( const char *fname,
const cyg_fs_attrib_t new_attrib );
__externC int cyg_fs_get_attrib( const char *fname,
cyg_fs_attrib_t * const file_attrib );
// Functions to lock and unlock a filesystem. These are normally used
// internally by the fileio layer, but the file system might need to
// use them when it needs to lock itself, eg when performing garbage
// collect.
__externC void cyg_fs_lock( cyg_mtab_entry *mte, cyg_uint32 syncmode );
__externC void cyg_fs_unlock( cyg_mtab_entry *mte, cyg_uint32 syncmode );
// To be able to lock the filesystem you need the mte. This function
// allows the table of mounted filesystems to be searched to find an
// mte which uses the give filesystem root.
__externC cyg_mtab_entry * cyg_fs_root_lookup( cyg_dir *root );
//=============================================================================
// Default functions.
// Cast to the appropriate type, these functions can be put into any of
// the operation table slots to provide the defined error code.
__externC int cyg_fileio_enosys(void);
__externC int cyg_fileio_erofs(void);
__externC int cyg_fileio_enoerr(void);
__externC int cyg_fileio_enotdir(void);
__externC cyg_fileop_select cyg_fileio_seltrue;
//-----------------------------------------------------------------------------
#endif // ifndef CYGONCE_FILEIO_H
// End of fileio.h
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -