Changes in uspace/srv/vfs/vfs_file.c [1e4cada:553492be] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_file.c
r1e4cada r553492be 42 42 #include <bool.h> 43 43 #include <fibril.h> 44 #include <fibril_sync h.h>44 #include <fibril_sync.h> 45 45 #include "vfs.h" 46 46 … … 76 76 /** Allocate a file descriptor. 77 77 * 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. 78 * @return First available file descriptor or a negative error 79 * code. 83 80 */ 84 int vfs_fd_alloc( bool desc)81 int vfs_fd_alloc(void) 85 82 { 86 83 if (!vfs_files_init()) … … 88 85 89 86 unsigned int i; 90 if (desc) 91 i = MAX_OPEN_FILES - 1; 92 else 93 i = 0; 94 95 while (true) { 87 for (i = 0; i < MAX_OPEN_FILES; i++) { 96 88 if (!files[i]) { 97 89 files[i] = (vfs_file_t *) malloc(sizeof(vfs_file_t)); … … 103 95 vfs_file_addref(files[i]); 104 96 return (int) i; 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 97 } 118 98 } … … 138 118 vfs_file_delref(files[fd]); 139 119 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 already150 * 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]);163 120 164 121 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.