kernel/fd: use function table to identify file descriptor type

It allows introducing new file descriptor types without editing enumeration every time. Anonymous FDs will be needed for Mesa
OpenGL/Vulkan drivers to reference GPU memory buffers and other driver objects that can be referenced as FDs from userland.

This change breaks private VFS API compatibility.
No behavior changes intended.

Change-Id: Iac109aad420b0b6aae704b38619436e01dcf4969
Reviewed-on: https://review.haiku-os.org/c/haiku/+/7838
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
X512
2024-07-23 20:23:19 +00:00
committed by waddlesplash
parent e33e65b36e
commit 65a86bce72
8 changed files with 125 additions and 168 deletions
+4 -4
View File
@@ -26,9 +26,9 @@
struct cache_module_info {
module_info info;
void (*node_opened)(struct vnode *vnode, int32 fdType, dev_t mountID,
void (*node_opened)(struct vnode *vnode, dev_t mountID,
ino_t parentID, ino_t vnodeID, const char *name, off_t size);
void (*node_closed)(struct vnode *vnode, int32 fdType, dev_t mountID,
void (*node_closed)(struct vnode *vnode, dev_t mountID,
ino_t vnodeID, int32 accessType);
void (*node_launched)(size_t argCount, char * const *args);
};
@@ -37,9 +37,9 @@ struct cache_module_info {
extern "C" {
#endif
extern void cache_node_opened(struct vnode *vnode, int32 fdType, VMCache *cache,
extern void cache_node_opened(struct vnode *vnode, VMCache *cache,
dev_t mountID, ino_t parentID, ino_t vnodeID, const char *name);
extern void cache_node_closed(struct vnode *vnode, int32 fdType, VMCache *cache,
extern void cache_node_closed(struct vnode *vnode, VMCache *cache,
dev_t mountID, ino_t vnodeID);
extern void cache_node_launched(size_t argCount, char * const *args);
extern void cache_prefetch_vnode(struct vnode *vnode, off_t offset, size_t size);
+1 -19
View File
@@ -15,10 +15,8 @@
extern "C" {
#endif
struct event_queue;
struct file_descriptor;
struct io_context;
struct net_socket;
struct selectsync;
struct select_info;
@@ -47,15 +45,12 @@ struct fd_ops {
};
struct file_descriptor {
int32 type; /* descriptor type */
int32 ref_count;
int32 open_count;
struct fd_ops *ops;
union {
struct vnode *vnode;
struct fs_mount *mount;
struct net_socket *socket;
struct event_queue *queue;
} u;
void *cookie;
int32 open_mode;
@@ -63,20 +58,6 @@ struct file_descriptor {
};
/* Types of file descriptors we can create */
enum fd_types {
FDTYPE_FILE = 1,
FDTYPE_ATTR,
FDTYPE_DIR,
FDTYPE_ATTR_DIR,
FDTYPE_INDEX,
FDTYPE_INDEX_DIR,
FDTYPE_QUERY,
FDTYPE_SOCKET,
FDTYPE_EVENT_QUEUE
};
// additional open mode - kernel special
#define O_DISCONNECTED 0x80000000
@@ -99,6 +80,7 @@ extern status_t select_fd(int32 fd, struct select_info *info, bool kernel);
extern status_t deselect_fd(int32 fd, struct select_info *info, bool kernel);
extern bool fd_is_valid(int fd, bool kernel);
extern struct vnode *fd_vnode(struct file_descriptor *descriptor);
extern bool fd_is_file(struct file_descriptor* descriptor);
extern bool fd_close_on_exec(struct io_context *context, int fd);
extern void fd_set_close_on_exec(struct io_context *context, int fd,