📄 devfs.cxx
字号:
static int dev_rename ( cyg_mtab_entry *mte, cyg_dir dir1, const char *name1, cyg_dir dir2, const char *name2 ){ return EROFS;}// -------------------------------------------------------------------------static int dev_link ( cyg_mtab_entry *mte, cyg_dir dir1, const char *name1, cyg_dir dir2, const char *name2, int type ){ return EROFS;}// -------------------------------------------------------------------------static int dev_opendir ( cyg_mtab_entry *mte, cyg_dir dir, const char *name, cyg_file *fte ){ return ENOTDIR;}// -------------------------------------------------------------------------static int dev_chdir ( cyg_mtab_entry *mte, cyg_dir dir, const char *name, cyg_dir *dir_out ){ return ENOTDIR;}// -------------------------------------------------------------------------static int dev_stat ( cyg_mtab_entry *mte, cyg_dir dir, const char *name, struct stat *buf){ Cyg_ErrNo err; cyg_io_handle_t handle; name -= 5; // See comment in dev_open() err = cyg_io_lookup( name, &handle ); if( err < 0 ) return -err; // Just fill in the stat buffer with some constant values. // FIXME: change this when block devices are available buf->st_mode = __stat_mode_CHR; buf->st_ino = (ino_t)handle; // map dev handle to inode buf->st_dev = 0; // (dev_t)handle; // same with dev id buf->st_nlink = 0; buf->st_uid = 0; buf->st_gid = 0; buf->st_size = 0; buf->st_atime = 0; buf->st_mtime = 0; buf->st_ctime = 0; return ENOERR;}// -------------------------------------------------------------------------static int dev_getinfo ( cyg_mtab_entry *mte, cyg_dir dir, const char *name, int key, void *buf, int len ){ return ENOSYS;}// -------------------------------------------------------------------------static int dev_setinfo ( cyg_mtab_entry *mte, cyg_dir dir, const char *name, int key, void *buf, int len ){ return ENOSYS;}//==========================================================================// File operations// -------------------------------------------------------------------------static int dev_fo_read (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio){ Cyg_ErrNo err = 0; int i; // Now loop over the iovecs until they are all done, or // we get an error. for( i = 0; i < uio->uio_iovcnt; i++ ) { cyg_iovec *iov = &uio->uio_iov[i]; cyg_uint32 len = iov->iov_len; cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)fp->f_data; if (t->status & CYG_DEVTAB_STATUS_BLOCK) err = cyg_io_bread( (cyg_io_handle_t)t, iov->iov_base, &len, fp->f_offset); else err = cyg_io_read( (cyg_io_handle_t)t, iov->iov_base, &len); if( err < 0 ) break; uio->uio_resid -= len; } return -err;}// -------------------------------------------------------------------------static int dev_fo_write (struct CYG_FILE_TAG *fp, struct CYG_UIO_TAG *uio){ Cyg_ErrNo err = 0; int i; // Now loop over the iovecs until they are all done, or // we get an error. for( i = 0; i < uio->uio_iovcnt; i++ ) { cyg_iovec *iov = &uio->uio_iov[i]; cyg_uint32 len = iov->iov_len; cyg_devtab_entry_t *t = (cyg_devtab_entry_t *)fp->f_data; if (t->status & CYG_DEVTAB_STATUS_BLOCK) err = cyg_io_bwrite( (cyg_io_handle_t)t, iov->iov_base, &len, fp->f_offset); else err = cyg_io_write( (cyg_io_handle_t)t, iov->iov_base, &len); if( err < 0 ) break; uio->uio_resid -= len; } return -err;}// -------------------------------------------------------------------------static int dev_fo_lseek (struct CYG_FILE_TAG *fp, off_t *pos, int whence ){ // All current devices have no notion of position. Just return zero // as the new position. *pos = 0; return ENOERR;}// -------------------------------------------------------------------------static int dev_fo_ioctl (struct CYG_FILE_TAG *fp, CYG_ADDRWORD com, CYG_ADDRWORD data){ return ENOSYS;}// -------------------------------------------------------------------------static cyg_bool dev_fo_select (struct CYG_FILE_TAG *fp, int which, CYG_ADDRWORD info){ return cyg_io_select( (cyg_io_handle_t)fp->f_data, which, info);}// -------------------------------------------------------------------------static int dev_fo_fsync (struct CYG_FILE_TAG *fp, int mode ){ Cyg_ErrNo err; err = cyg_io_get_config((cyg_io_handle_t)fp->f_data, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, NULL, NULL); return -err;}// -------------------------------------------------------------------------static int dev_fo_close (struct CYG_FILE_TAG *fp){ return ENOERR;}// -------------------------------------------------------------------------static int dev_fo_fstat (struct CYG_FILE_TAG *fp, struct stat *buf ){ // Just fill in the stat buffer with some constant values. // FIXME: change this when block devices are available buf->st_mode = __stat_mode_CHR; buf->st_ino = (ino_t)fp->f_data; // map dev handle to inode buf->st_dev = (dev_t)fp->f_data; // same with dev id buf->st_nlink = 0; buf->st_uid = 0; buf->st_gid = 0; buf->st_size = 0; buf->st_atime = 0; buf->st_mtime = 0; buf->st_ctime = 0; return ENOERR;}// -------------------------------------------------------------------------static int dev_fo_getinfo (struct CYG_FILE_TAG *fp, int key, void *buf, int len ){ Cyg_ErrNo err = 0; cyg_uint32 ll = len; err = cyg_io_get_config( (cyg_io_handle_t)fp->f_data, key, buf, &ll ); return -err;}// -------------------------------------------------------------------------static int dev_fo_setinfo (struct CYG_FILE_TAG *fp, int key, void *buf, int len ){ Cyg_ErrNo err = 0; cyg_uint32 ll = len; err = cyg_io_set_config( (cyg_io_handle_t)fp->f_data, key, buf, &ll ); return -err;}// -------------------------------------------------------------------------// EOF devfs.cxx
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -