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