Changes in uspace/srv/vfs/vfs_file.c [553492be:1e4cada] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_file.c
r553492be r1e4cada 42 42 #include <bool.h> 43 43 #include <fibril.h> 44 #include <fibril_sync .h>44 #include <fibril_synch.h> 45 45 #include "vfs.h" 46 46 … … 76 76 /** Allocate a file descriptor. 77 77 * 78 * @return First available file descriptor or a negative error 79 * code. 80 */ 81 int vfs_fd_alloc(void) 78 * @param desc If true, look for an available file descriptor 79 * in a descending order. 80 * 81 * @return First available file descriptor or a negative error 82 * code. 83 */ 84 int vfs_fd_alloc(bool desc) 82 85 { 83 86 if (!vfs_files_init()) … … 85 88 86 89 unsigned int i; 87 for (i = 0; i < MAX_OPEN_FILES; i++) { 90 if (desc) 91 i = MAX_OPEN_FILES - 1; 92 else 93 i = 0; 94 95 while (true) { 88 96 if (!files[i]) { 89 97 files[i] = (vfs_file_t *) malloc(sizeof(vfs_file_t)); … … 96 104 return (int) i; 97 105 } 106 107 if (desc) { 108 if (i == 0) 109 break; 110 111 i--; 112 } else { 113 if (i == MAX_OPEN_FILES - 1) 114 break; 115 116 i++; 117 } 98 118 } 99 119 … … 118 138 vfs_file_delref(files[fd]); 119 139 files[fd] = NULL; 140 141 return EOK; 142 } 143 144 /** Assign a file to a file descriptor. 145 * 146 * @param file File to assign. 147 * @param fd File descriptor to assign to. 148 * 149 * @return EOK on success or EINVAL if fd is an invalid or already 150 * used file descriptor. 151 * 152 */ 153 int vfs_fd_assign(vfs_file_t *file, int fd) 154 { 155 if (!vfs_files_init()) 156 return ENOMEM; 157 158 if ((fd < 0) || (fd >= MAX_OPEN_FILES) || (files[fd] != NULL)) 159 return EINVAL; 160 161 files[fd] = file; 162 vfs_file_addref(files[fd]); 120 163 121 164 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.