]> xenbits.xensource.com Git - people/aperard/mini-os.git/commitdiff
introduce get_file_from_fd()
authorJuergen Gross <jgross@suse.com>
Sun, 16 Jan 2022 06:45:23 +0000 (07:45 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 17 Jan 2022 10:51:21 +0000 (10:51 +0000)
Exporting the files[] array especially for components outside the
mini-os source tree is limiting the ability to change any file handling
in mini-os.

Introduce a new function get_file_from_fd() to return the struct file
pointer (or NULL) for a given file descriptor.

Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
include/lib.h
lib/sys.c

index 91364ba7eddc782b4983d4db96d1173bdcefcca8..7a0546bdac8391a78c73284764574bce7c77ad06 100644 (file)
@@ -198,6 +198,7 @@ struct file {
 
 extern struct file files[];
 
+struct file *get_file_from_fd(int fd);
 int alloc_fd(enum fd_type type);
 void close_all_files(void);
 extern struct thread *main_thread;
index 6f2b026da0cc1714e76da537ba3ed8c5a110e1e8..9a03875c95623ff3555b6edaa7bf52f6e2a56fbe 100644 (file)
--- a/lib/sys.c
+++ b/lib/sys.c
@@ -98,6 +98,14 @@ struct file files[NOFILE] = {
     { .type = FTYPE_CONSOLE }, /* stderr */
 };
 
+struct file *get_file_from_fd(int fd)
+{
+    if ( fd < 0 || fd >= ARRAY_SIZE(files) )
+        return NULL;
+
+    return (files[fd].type == FTYPE_NONE) ? NULL : files + fd;
+}
+
 DECLARE_WAIT_QUEUE_HEAD(event_queue);
 
 int alloc_fd(enum fd_type type)