Changes in uspace/srv/vfs/vfs_file.c [6ad454f:fcab7ef] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_file.c
r6ad454f rfcab7ef 192 192 } 193 193 194 static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, vfs_file_t **file, bool desc , int *out_fd)194 static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, vfs_file_t **file, bool desc) 195 195 { 196 196 if (!vfs_files_init(vfs_data)) … … 223 223 224 224 fibril_mutex_unlock(&vfs_data->lock); 225 *out_fd = (int) i; 226 return EOK; 225 return (int) i; 227 226 } 228 227 … … 250 249 * in a descending order. 251 250 * 252 * @param[out] out_fd First available file descriptor 253 * 254 * @return Error code. 255 */ 256 int vfs_fd_alloc(vfs_file_t **file, bool desc, int *out_fd) 257 { 258 return _vfs_fd_alloc(VFS_DATA, file, desc, out_fd); 259 } 260 261 static int _vfs_fd_free_locked(vfs_client_data_t *vfs_data, int fd) 262 { 263 if ((fd < 0) || (fd >= MAX_OPEN_FILES) || !vfs_data->files[fd]) { 264 return EBADF; 265 } 266 267 int rc = vfs_file_delref(vfs_data, vfs_data->files[fd]); 268 vfs_data->files[fd] = NULL; 269 return rc; 251 * @return First available file descriptor or a negative error 252 * code. 253 */ 254 int vfs_fd_alloc(vfs_file_t **file, bool desc) 255 { 256 return _vfs_fd_alloc(VFS_DATA, file, desc); 270 257 } 271 258 … … 278 265 279 266 fibril_mutex_lock(&vfs_data->lock); 280 rc = _vfs_fd_free_locked(vfs_data, fd); 267 if ((fd < 0) || (fd >= MAX_OPEN_FILES) || !vfs_data->files[fd]) { 268 fibril_mutex_unlock(&vfs_data->lock); 269 return EBADF; 270 } 271 272 rc = vfs_file_delref(vfs_data, vfs_data->files[fd]); 273 vfs_data->files[fd] = NULL; 281 274 fibril_mutex_unlock(&vfs_data->lock); 282 275 … … 315 308 return EBADF; 316 309 } 317 318 /* Make sure fd is closed. */319 (void) _vfs_fd_free_locked(VFS_DATA, fd);320 assert(FILES[fd] == NULL);310 if (FILES[fd] != NULL) { 311 fibril_mutex_unlock(&VFS_DATA->lock); 312 return EEXIST; 313 } 321 314 322 315 FILES[fd] = file; … … 429 422 } 430 423 431 int vfs_wait_handle_internal(bool high_fd , int *out_fd)424 int vfs_wait_handle_internal(bool high_fd) 432 425 { 433 426 vfs_client_data_t *vfs_data = VFS_DATA; … … 443 436 444 437 vfs_file_t *file; 445 int rc = _vfs_fd_alloc(vfs_data, &file, high_fd, out_fd);446 if ( rc != EOK) {438 int fd = _vfs_fd_alloc(vfs_data, &file, high_fd); 439 if (fd < 0) { 447 440 vfs_node_delref(bh->node); 448 441 free(bh); 449 return rc;442 return fd; 450 443 } 451 444 … … 454 447 vfs_file_put(file); 455 448 free(bh); 456 return EOK;449 return fd; 457 450 } 458 451
Note:
See TracChangeset
for help on using the changeset viewer.