From a2cbc788e0320a065e7e592dfb78fb1547a6f0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 29 Oct 2002 03:49:57 +0000 Subject: [PATCH] Adds support for select(), and poll() in the kernel - both are realized using the current BeOS device API. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1745 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/fd.h | 35 ++++++++++++++++++++--------------- headers/private/kernel/vfs.h | 14 ++++++++++++++ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/headers/private/kernel/fd.h b/headers/private/kernel/fd.h index 2179bc819a..86fd85d0a7 100644 --- a/headers/private/kernel/fd.h +++ b/headers/private/kernel/fd.h @@ -1,10 +1,9 @@ -/* file.h - * - * File Descriptors - */ - -#ifndef _FILE_H -#define _FILE_H +/* +** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ +#ifndef _FD_H +#define _FD_H #include #include @@ -14,6 +13,7 @@ struct file_descriptor; +struct select_sync; struct fs_mount; struct vnode; @@ -31,8 +31,9 @@ struct fd_ops { ssize_t (*fd_write)(struct file_descriptor *, off_t pos, const void *buffer, size_t *length); off_t (*fd_seek)(struct file_descriptor *, off_t pos, int seekType); status_t (*fd_ioctl)(struct file_descriptor *, ulong op, void *buffer, size_t length); -// int (*fd_poll)(struct file_descriptor *, int); - status_t (*fd_read_dir)(struct file_descriptor *,struct dirent *buffer,size_t bufferSize,uint32 *_count); + status_t (*fd_select)(struct file_descriptor *, uint8 event, uint32 ref, struct select_sync *sync); + status_t (*fd_deselect)(struct file_descriptor *, uint8 event, struct select_sync *sync); + status_t (*fd_read_dir)(struct file_descriptor *, struct dirent *buffer, size_t bufferSize, uint32 *_count); status_t (*fd_rewind_dir)(struct file_descriptor *); status_t (*fd_read_stat)(struct file_descriptor *, struct stat *); status_t (*fd_write_stat)(struct file_descriptor *, const struct stat *, int statMask); @@ -70,11 +71,15 @@ enum fd_types { /* Prototypes */ -struct file_descriptor *alloc_fd(void); -int new_fd(struct io_context *, struct file_descriptor *); -struct file_descriptor *get_fd(struct io_context *, int); -void put_fd(struct file_descriptor *); -void free_fd(struct file_descriptor *); +extern struct file_descriptor *alloc_fd(void); +extern int new_fd(struct io_context *, struct file_descriptor *); +extern struct file_descriptor *get_fd(struct io_context *, int); +extern void put_fd(struct file_descriptor *); +extern void free_fd(struct file_descriptor *); +extern status_t select_fd(int fd, uint8 event, uint32 ref, struct select_sync *sync, bool kernel); +extern status_t deselect_fd(int fd, uint8 event, struct select_sync *sync, bool kernel); +extern bool fd_is_valid(int fd, bool kernel); + static struct io_context *get_current_io_context(bool kernel); /* The prototypes of the (sys|user)_ functions are currently defined in vfs.h */ @@ -90,4 +95,4 @@ static __inline struct io_context *get_current_io_context(bool kernel) return thread_get_current_thread()->team->ioctx; } -#endif /* _FILE_H */ +#endif /* _FD_H */ diff --git a/headers/private/kernel/vfs.h b/headers/private/kernel/vfs.h index 62b9d13e8c..ec084f2b20 100755 --- a/headers/private/kernel/vfs.h +++ b/headers/private/kernel/vfs.h @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include @@ -22,6 +24,8 @@ uint8 _##name[sizeof(iovecs) + (size)*sizeof(iovec)]; \ iovecs *name = (iovecs *)_##name +struct selectsync; +struct pollfd; #ifdef __cplusplus extern "C" { @@ -38,6 +42,10 @@ struct rlimit; int vfs_getrlimit(int resource, struct rlimit * rlp); int vfs_setrlimit(int resource, const struct rlimit * rlp); +// ToDo: for now; this prototype should be in os/drivers/Drivers.h +// or similar places. +extern status_t notify_select_event(struct selectsync *sync, uint32 ref); + /* calls needed by fs internals */ int vfs_get_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode *v); int vfs_put_vnode(mount_id mountID, vnode_id vnodeID); @@ -80,6 +88,9 @@ int sys_rename(const char *oldpath, const char *newpath); int sys_access(const char *path, int mode); int sys_read_path_stat(const char *path, bool traverseLink, struct stat *stat); int sys_write_path_stat(const char *path, bool traverseLink, const struct stat *stat, int statMask); +int sys_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet, + bigtime_t timeout, sigset_t *sigMask); +int sys_poll(struct pollfd *fds, int numfds, bigtime_t timeout); int sys_open_attr_dir(int fd, const char *path); int sys_create_attr(int fd, const char *name, uint32 type, int openMode); int sys_open_attr(int fd, const char *name, int openMode); @@ -117,6 +128,9 @@ int user_rename(const char *oldpath, const char *newpath); int user_access(const char *path, int mode); int user_read_path_stat(const char *path, bool traverseLink, struct stat *stat); int user_write_path_stat(const char *path, bool traverseLink, const struct stat *stat, int statMask); +int user_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet, + bigtime_t timeout, sigset_t *sigMask); +int user_poll(struct pollfd *fds, int numfds, bigtime_t timeout); int user_open_attr_dir(int fd, const char *path); int user_create_attr(int fd, const char *name, uint32 type, int openMode); int user_open_attr(int fd, const char *name, int openMode);