Changeset 368ee04 in mainline for uspace/srv/vfs/vfs_file.c
- Timestamp:
- 2017-04-05T18:10:39Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 93ad8166
- Parents:
- 39f892a9 (diff), 2166728 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_file.c
r39f892a9 r368ee04 45 45 #include <adt/list.h> 46 46 #include <task.h> 47 #include <vfs/vfs.h> 47 48 #include "vfs.h" 48 49 … … 59 60 typedef struct { 60 61 link_t link; 61 int handle; 62 vfs_node_t *node; 63 int permissions; 62 64 } vfs_boxed_handle_t; 63 65 … … 177 179 * endpoint FS and drop our reference to the underlying VFS node. 178 180 */ 179 rc = vfs_file_close_remote(file); 180 vfs_node_delref(file->node); 181 182 if (file->node != NULL) { 183 if (file->open_read || file->open_write) { 184 rc = vfs_file_close_remote(file); 185 } 186 vfs_node_delref(file->node); 187 } 181 188 free(file); 182 189 } … … 185 192 } 186 193 187 static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, bool desc)194 static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, vfs_file_t **file, bool desc) 188 195 { 189 196 if (!vfs_files_init(vfs_data)) … … 205 212 } 206 213 214 207 215 memset(vfs_data->files[i], 0, sizeof(vfs_file_t)); 208 fibril_mutex_initialize(&vfs_data->files[i]->lock); 216 217 fibril_mutex_initialize(&vfs_data->files[i]->_lock); 218 fibril_mutex_lock(&vfs_data->files[i]->_lock); 209 219 vfs_file_addref(vfs_data, vfs_data->files[i]); 220 221 *file = vfs_data->files[i]; 222 vfs_file_addref(vfs_data, *file); 223 210 224 fibril_mutex_unlock(&vfs_data->lock); 211 225 return (int) i; … … 231 245 /** Allocate a file descriptor. 232 246 * 247 * @param file Is set to point to the newly created file structure. Must be put afterwards. 233 248 * @param desc If true, look for an available file descriptor 234 249 * in a descending order. … … 237 252 * code. 238 253 */ 239 int vfs_fd_alloc( bool desc)240 { 241 return _vfs_fd_alloc(VFS_DATA, desc);254 int vfs_fd_alloc(vfs_file_t **file, bool desc) 255 { 256 return _vfs_fd_alloc(VFS_DATA, file, desc); 242 257 } 243 258 … … 289 304 290 305 fibril_mutex_lock(&VFS_DATA->lock); 291 if ((fd < 0) || (fd >= MAX_OPEN_FILES) || (FILES[fd] != NULL)) {306 if ((fd < 0) || (fd >= MAX_OPEN_FILES)) { 292 307 fibril_mutex_unlock(&VFS_DATA->lock); 293 return EINVAL; 308 return EBADF; 309 } 310 if (FILES[fd] != NULL) { 311 fibril_mutex_unlock(&VFS_DATA->lock); 312 return EEXIST; 294 313 } 295 314 … … 299 318 300 319 return EOK; 320 } 321 322 static void _vfs_file_put(vfs_client_data_t *vfs_data, vfs_file_t *file) 323 { 324 fibril_mutex_unlock(&file->_lock); 325 326 fibril_mutex_lock(&vfs_data->lock); 327 vfs_file_delref(vfs_data, file); 328 fibril_mutex_unlock(&vfs_data->lock); 301 329 } 302 330 … … 312 340 vfs_file_addref(vfs_data, file); 313 341 fibril_mutex_unlock(&vfs_data->lock); 342 343 fibril_mutex_lock(&file->_lock); 344 if (file->node == NULL) { 345 _vfs_file_put(vfs_data, file); 346 return NULL; 347 } 348 assert(file != NULL); 349 assert(file->node != NULL); 314 350 return file; 315 351 } … … 331 367 } 332 368 333 static void _vfs_file_put(vfs_client_data_t *vfs_data, vfs_file_t *file)334 {335 fibril_mutex_lock(&vfs_data->lock);336 vfs_file_delref(vfs_data, file);337 fibril_mutex_unlock(&vfs_data->lock);338 }339 340 369 /** Stop using a file structure. 341 370 * … … 347 376 } 348 377 349 void vfs_ pass_handle(task_id_t donor_id, task_id_t acceptor_id, int donor_fd)378 void vfs_op_pass_handle(task_id_t donor_id, task_id_t acceptor_id, int donor_fd) 350 379 { 351 380 vfs_client_data_t *donor_data = NULL; 352 381 vfs_client_data_t *acceptor_data = NULL; 353 382 vfs_file_t *donor_file = NULL; 354 vfs_file_t *acceptor_file = NULL;355 383 vfs_boxed_handle_t *bh; 356 int acceptor_fd;357 384 358 385 acceptor_data = async_get_client_data_by_id(acceptor_id); … … 364 391 365 392 link_initialize(&bh->link); 366 bh-> handle = -1;393 bh->node = NULL; 367 394 368 395 donor_data = async_get_client_data_by_id(donor_id); … … 373 400 if (!donor_file) 374 401 goto out; 375 376 acceptor_fd = _vfs_fd_alloc(acceptor_data, false);377 if (acceptor_fd < 0)378 goto out;379 380 bh->handle = acceptor_fd;381 402 382 403 /* … … 384 405 */ 385 406 vfs_node_addref(donor_file->node); 386 (void) vfs_open_node_remote(donor_file->node); 387 388 acceptor_file = _vfs_file_get(acceptor_data, acceptor_fd); 389 assert(acceptor_file); 390 391 /* 392 * Inherit attributes from the donor. 393 */ 394 acceptor_file->node = donor_file->node; 395 acceptor_file->append = donor_file->append; 396 acceptor_file->pos = donor_file->pos; 407 bh->node = donor_file->node; 408 bh->permissions = donor_file->permissions; 397 409 398 410 out: … … 408 420 if (donor_file) 409 421 _vfs_file_put(donor_data, donor_file); 410 if (acceptor_file) 411 _vfs_file_put(acceptor_data, acceptor_file); 412 413 } 414 415 int vfs_wait_handle_internal(void) 422 } 423 424 int vfs_wait_handle_internal(bool high_fd) 416 425 { 417 426 vfs_client_data_t *vfs_data = VFS_DATA; 418 int fd;419 427 420 428 fibril_mutex_lock(&vfs_data->lock); … … 426 434 427 435 vfs_boxed_handle_t *bh = list_get_instance(lnk, vfs_boxed_handle_t, link); 428 fd = bh->handle; 436 437 vfs_file_t *file; 438 int fd = _vfs_fd_alloc(vfs_data, &file, high_fd); 439 if (fd < 0) { 440 vfs_node_delref(bh->node); 441 free(bh); 442 return fd; 443 } 444 445 file->node = bh->node; 446 file->permissions = bh->permissions; 447 vfs_file_put(file); 429 448 free(bh); 430 431 449 return fd; 432 450 }
Note:
See TracChangeset
for help on using the changeset viewer.