[320c884] | 1 | /*
|
---|
| 2 | * Copyright (c) 2007 Jakub Jermar
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup fs
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * @file vfs_file.c
|
---|
| 35 | * @brief Various operations on files have their home in this file.
|
---|
| 36 | */
|
---|
| 37 |
|
---|
| 38 | #include <errno.h>
|
---|
| 39 | #include <stdlib.h>
|
---|
[19f857a] | 40 | #include <str.h>
|
---|
[320c884] | 41 | #include <assert.h>
|
---|
[3e6a98c5] | 42 | #include <stdbool.h>
|
---|
[26360f7] | 43 | #include <fibril.h>
|
---|
[1e4cada] | 44 | #include <fibril_synch.h>
|
---|
[27b76ca] | 45 | #include <adt/list.h>
|
---|
[e2ab36f1] | 46 | #include <task.h>
|
---|
[320c884] | 47 | #include "vfs.h"
|
---|
| 48 |
|
---|
[79ae36dd] | 49 | #define VFS_DATA ((vfs_client_data_t *) async_get_client_data())
|
---|
[b75e929] | 50 | #define FILES (VFS_DATA->files)
|
---|
| 51 |
|
---|
| 52 | typedef struct {
|
---|
| 53 | fibril_mutex_t lock;
|
---|
[27b76ca] | 54 | fibril_condvar_t cv;
|
---|
| 55 | list_t passed_handles;
|
---|
[b75e929] | 56 | vfs_file_t **files;
|
---|
| 57 | } vfs_client_data_t;
|
---|
[320c884] | 58 |
|
---|
[27b76ca] | 59 | typedef struct {
|
---|
| 60 | link_t link;
|
---|
| 61 | int handle;
|
---|
| 62 | } vfs_boxed_handle_t;
|
---|
| 63 |
|
---|
[2bc13887] | 64 | static int _vfs_fd_free(vfs_client_data_t *, int);
|
---|
| 65 |
|
---|
[320c884] | 66 | /** Initialize the table of open files. */
|
---|
[2bc13887] | 67 | static bool vfs_files_init(vfs_client_data_t *vfs_data)
|
---|
[320c884] | 68 | {
|
---|
[2bc13887] | 69 | fibril_mutex_lock(&vfs_data->lock);
|
---|
| 70 | if (!vfs_data->files) {
|
---|
| 71 | vfs_data->files = malloc(MAX_OPEN_FILES * sizeof(vfs_file_t *));
|
---|
| 72 | if (!vfs_data->files) {
|
---|
| 73 | fibril_mutex_unlock(&vfs_data->lock);
|
---|
[320c884] | 74 | return false;
|
---|
[b75e929] | 75 | }
|
---|
[2bc13887] | 76 | memset(vfs_data->files, 0, MAX_OPEN_FILES * sizeof(vfs_file_t *));
|
---|
[320c884] | 77 | }
|
---|
[2bc13887] | 78 | fibril_mutex_unlock(&vfs_data->lock);
|
---|
[320c884] | 79 | return true;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[f29a3a2] | 82 | /** Cleanup the table of open files. */
|
---|
[2bc13887] | 83 | static void vfs_files_done(vfs_client_data_t *vfs_data)
|
---|
[f29a3a2] | 84 | {
|
---|
| 85 | int i;
|
---|
| 86 |
|
---|
[2bc13887] | 87 | if (!vfs_data->files)
|
---|
[f29a3a2] | 88 | return;
|
---|
| 89 |
|
---|
| 90 | for (i = 0; i < MAX_OPEN_FILES; i++) {
|
---|
[2bc13887] | 91 | if (vfs_data->files[i])
|
---|
| 92 | (void) _vfs_fd_free(vfs_data, i);
|
---|
[f29a3a2] | 93 | }
|
---|
| 94 |
|
---|
[2bc13887] | 95 | free(vfs_data->files);
|
---|
[27b76ca] | 96 |
|
---|
| 97 | while (!list_empty(&vfs_data->passed_handles)) {
|
---|
| 98 | link_t *lnk;
|
---|
| 99 | vfs_boxed_handle_t *bh;
|
---|
| 100 |
|
---|
| 101 | lnk = list_first(&vfs_data->passed_handles);
|
---|
| 102 | list_remove(lnk);
|
---|
| 103 |
|
---|
| 104 | bh = list_get_instance(lnk, vfs_boxed_handle_t, link);
|
---|
| 105 | free(bh);
|
---|
| 106 | }
|
---|
[b75e929] | 107 | }
|
---|
| 108 |
|
---|
| 109 | void *vfs_client_data_create(void)
|
---|
| 110 | {
|
---|
| 111 | vfs_client_data_t *vfs_data;
|
---|
| 112 |
|
---|
| 113 | vfs_data = malloc(sizeof(vfs_client_data_t));
|
---|
| 114 | if (vfs_data) {
|
---|
| 115 | fibril_mutex_initialize(&vfs_data->lock);
|
---|
[27b76ca] | 116 | fibril_condvar_initialize(&vfs_data->cv);
|
---|
| 117 | list_initialize(&vfs_data->passed_handles);
|
---|
[b75e929] | 118 | vfs_data->files = NULL;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | return vfs_data;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | void vfs_client_data_destroy(void *data)
|
---|
| 125 | {
|
---|
| 126 | vfs_client_data_t *vfs_data = (vfs_client_data_t *) data;
|
---|
| 127 |
|
---|
[2bc13887] | 128 | vfs_files_done(vfs_data);
|
---|
[b75e929] | 129 | free(vfs_data);
|
---|
| 130 | }
|
---|
| 131 |
|
---|
[25bef0ff] | 132 | /** Close the file in the endpoint FS server. */
|
---|
| 133 | static int vfs_file_close_remote(vfs_file_t *file)
|
---|
| 134 | {
|
---|
| 135 | assert(!file->refcnt);
|
---|
[79ae36dd] | 136 |
|
---|
| 137 | async_exch_t *exch = vfs_exchange_grab(file->node->fs_handle);
|
---|
| 138 |
|
---|
| 139 | ipc_call_t answer;
|
---|
[15f3c3f] | 140 | aid_t msg = async_send_2(exch, VFS_OUT_CLOSE, file->node->service_id,
|
---|
[25bef0ff] | 141 | file->node->index, &answer);
|
---|
[79ae36dd] | 142 |
|
---|
| 143 | vfs_exchange_release(exch);
|
---|
| 144 |
|
---|
| 145 | sysarg_t rc;
|
---|
[25bef0ff] | 146 | async_wait_for(msg, &rc);
|
---|
[79ae36dd] | 147 |
|
---|
[25bef0ff] | 148 | return IPC_GET_ARG1(answer);
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[b75e929] | 151 | /** Increment reference count of VFS file structure.
|
---|
| 152 | *
|
---|
| 153 | * @param file File structure that will have reference count
|
---|
| 154 | * incremented.
|
---|
| 155 | */
|
---|
[2bc13887] | 156 | static void vfs_file_addref(vfs_client_data_t *vfs_data, vfs_file_t *file)
|
---|
[b75e929] | 157 | {
|
---|
[2bc13887] | 158 | assert(fibril_mutex_is_locked(&vfs_data->lock));
|
---|
[b75e929] | 159 |
|
---|
| 160 | file->refcnt++;
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | /** Decrement reference count of VFS file structure.
|
---|
| 164 | *
|
---|
| 165 | * @param file File structure that will have reference count
|
---|
| 166 | * decremented.
|
---|
| 167 | */
|
---|
[2bc13887] | 168 | static int vfs_file_delref(vfs_client_data_t *vfs_data, vfs_file_t *file)
|
---|
[b75e929] | 169 | {
|
---|
[25bef0ff] | 170 | int rc = EOK;
|
---|
| 171 |
|
---|
[2bc13887] | 172 | assert(fibril_mutex_is_locked(&vfs_data->lock));
|
---|
[b75e929] | 173 |
|
---|
| 174 | if (file->refcnt-- == 1) {
|
---|
| 175 | /*
|
---|
[25bef0ff] | 176 | * Lost the last reference to a file, need to close it in the
|
---|
| 177 | * endpoint FS and drop our reference to the underlying VFS node.
|
---|
[b75e929] | 178 | */
|
---|
[25bef0ff] | 179 | rc = vfs_file_close_remote(file);
|
---|
[b75e929] | 180 | vfs_node_delref(file->node);
|
---|
| 181 | free(file);
|
---|
| 182 | }
|
---|
[25bef0ff] | 183 |
|
---|
| 184 | return rc;
|
---|
[f29a3a2] | 185 | }
|
---|
| 186 |
|
---|
[2bc13887] | 187 | static int _vfs_fd_alloc(vfs_client_data_t *vfs_data, bool desc)
|
---|
[320c884] | 188 | {
|
---|
[2bc13887] | 189 | if (!vfs_files_init(vfs_data))
|
---|
[ac23b9d3] | 190 | return ENOMEM;
|
---|
| 191 |
|
---|
| 192 | unsigned int i;
|
---|
[2b88074b] | 193 | if (desc)
|
---|
[42fa698] | 194 | i = MAX_OPEN_FILES - 1;
|
---|
[2b88074b] | 195 | else
|
---|
| 196 | i = 0;
|
---|
| 197 |
|
---|
[2bc13887] | 198 | fibril_mutex_lock(&vfs_data->lock);
|
---|
[2b88074b] | 199 | while (true) {
|
---|
[2bc13887] | 200 | if (!vfs_data->files[i]) {
|
---|
| 201 | vfs_data->files[i] = (vfs_file_t *) malloc(sizeof(vfs_file_t));
|
---|
| 202 | if (!vfs_data->files[i]) {
|
---|
| 203 | fibril_mutex_unlock(&vfs_data->lock);
|
---|
[320c884] | 204 | return ENOMEM;
|
---|
[b75e929] | 205 | }
|
---|
[ac23b9d3] | 206 |
|
---|
[2bc13887] | 207 | memset(vfs_data->files[i], 0, sizeof(vfs_file_t));
|
---|
| 208 | fibril_mutex_initialize(&vfs_data->files[i]->lock);
|
---|
| 209 | vfs_file_addref(vfs_data, vfs_data->files[i]);
|
---|
| 210 | fibril_mutex_unlock(&vfs_data->lock);
|
---|
[ac23b9d3] | 211 | return (int) i;
|
---|
[320c884] | 212 | }
|
---|
[2b88074b] | 213 |
|
---|
| 214 | if (desc) {
|
---|
| 215 | if (i == 0)
|
---|
| 216 | break;
|
---|
| 217 |
|
---|
| 218 | i--;
|
---|
| 219 | } else {
|
---|
[d8f92868] | 220 | if (i == MAX_OPEN_FILES - 1)
|
---|
[2b88074b] | 221 | break;
|
---|
| 222 |
|
---|
| 223 | i++;
|
---|
| 224 | }
|
---|
[320c884] | 225 | }
|
---|
[2bc13887] | 226 | fibril_mutex_unlock(&vfs_data->lock);
|
---|
[ac23b9d3] | 227 |
|
---|
[320c884] | 228 | return EMFILE;
|
---|
| 229 | }
|
---|
| 230 |
|
---|
[2bc13887] | 231 | /** Allocate a file descriptor.
|
---|
[320c884] | 232 | *
|
---|
[2bc13887] | 233 | * @param desc If true, look for an available file descriptor
|
---|
| 234 | * in a descending order.
|
---|
[b7f9087] | 235 | *
|
---|
[2bc13887] | 236 | * @return First available file descriptor or a negative error
|
---|
| 237 | * code.
|
---|
[320c884] | 238 | */
|
---|
[2bc13887] | 239 | int vfs_fd_alloc(bool desc)
|
---|
| 240 | {
|
---|
| 241 | return _vfs_fd_alloc(VFS_DATA, desc);
|
---|
| 242 | }
|
---|
| 243 |
|
---|
| 244 | static int _vfs_fd_free(vfs_client_data_t *vfs_data, int fd)
|
---|
[320c884] | 245 | {
|
---|
[25bef0ff] | 246 | int rc;
|
---|
| 247 |
|
---|
[2bc13887] | 248 | if (!vfs_files_init(vfs_data))
|
---|
[ac23b9d3] | 249 | return ENOMEM;
|
---|
[b75e929] | 250 |
|
---|
[2bc13887] | 251 | fibril_mutex_lock(&vfs_data->lock);
|
---|
| 252 | if ((fd < 0) || (fd >= MAX_OPEN_FILES) || !vfs_data->files[fd]) {
|
---|
| 253 | fibril_mutex_unlock(&vfs_data->lock);
|
---|
[b7f9087] | 254 | return EBADF;
|
---|
[b75e929] | 255 | }
|
---|
[ac23b9d3] | 256 |
|
---|
[2bc13887] | 257 | rc = vfs_file_delref(vfs_data, vfs_data->files[fd]);
|
---|
| 258 | vfs_data->files[fd] = NULL;
|
---|
| 259 | fibril_mutex_unlock(&vfs_data->lock);
|
---|
[ac23b9d3] | 260 |
|
---|
[25bef0ff] | 261 | return rc;
|
---|
[320c884] | 262 | }
|
---|
| 263 |
|
---|
[2bc13887] | 264 | /** Release file descriptor.
|
---|
| 265 | *
|
---|
| 266 | * @param fd File descriptor being released.
|
---|
| 267 | *
|
---|
| 268 | * @return EOK on success or EBADF if fd is an invalid file
|
---|
| 269 | * descriptor.
|
---|
| 270 | */
|
---|
| 271 | int vfs_fd_free(int fd)
|
---|
| 272 | {
|
---|
| 273 | return _vfs_fd_free(VFS_DATA, fd);
|
---|
| 274 | }
|
---|
| 275 |
|
---|
[2b88074b] | 276 | /** Assign a file to a file descriptor.
|
---|
| 277 | *
|
---|
| 278 | * @param file File to assign.
|
---|
| 279 | * @param fd File descriptor to assign to.
|
---|
| 280 | *
|
---|
| 281 | * @return EOK on success or EINVAL if fd is an invalid or already
|
---|
| 282 | * used file descriptor.
|
---|
| 283 | *
|
---|
| 284 | */
|
---|
| 285 | int vfs_fd_assign(vfs_file_t *file, int fd)
|
---|
| 286 | {
|
---|
[2bc13887] | 287 | if (!vfs_files_init(VFS_DATA))
|
---|
[2b88074b] | 288 | return ENOMEM;
|
---|
[b75e929] | 289 |
|
---|
| 290 | fibril_mutex_lock(&VFS_DATA->lock);
|
---|
| 291 | if ((fd < 0) || (fd >= MAX_OPEN_FILES) || (FILES[fd] != NULL)) {
|
---|
| 292 | fibril_mutex_unlock(&VFS_DATA->lock);
|
---|
[2b88074b] | 293 | return EINVAL;
|
---|
[b75e929] | 294 | }
|
---|
[2b88074b] | 295 |
|
---|
[b75e929] | 296 | FILES[fd] = file;
|
---|
[2bc13887] | 297 | vfs_file_addref(VFS_DATA, FILES[fd]);
|
---|
[b75e929] | 298 | fibril_mutex_unlock(&VFS_DATA->lock);
|
---|
[2b88074b] | 299 |
|
---|
| 300 | return EOK;
|
---|
| 301 | }
|
---|
| 302 |
|
---|
[2bc13887] | 303 | static vfs_file_t *_vfs_file_get(vfs_client_data_t *vfs_data, int fd)
|
---|
[320c884] | 304 | {
|
---|
[2bc13887] | 305 | if (!vfs_files_init(vfs_data))
|
---|
[ac23b9d3] | 306 | return NULL;
|
---|
| 307 |
|
---|
[2bc13887] | 308 | fibril_mutex_lock(&vfs_data->lock);
|
---|
[b75e929] | 309 | if ((fd >= 0) && (fd < MAX_OPEN_FILES)) {
|
---|
[2bc13887] | 310 | vfs_file_t *file = vfs_data->files[fd];
|
---|
[6639ae1] | 311 | if (file != NULL) {
|
---|
[2bc13887] | 312 | vfs_file_addref(vfs_data, file);
|
---|
| 313 | fibril_mutex_unlock(&vfs_data->lock);
|
---|
[6639ae1] | 314 | return file;
|
---|
| 315 | }
|
---|
[b75e929] | 316 | }
|
---|
[2bc13887] | 317 | fibril_mutex_unlock(&vfs_data->lock);
|
---|
[ac23b9d3] | 318 |
|
---|
[ebd9392] | 319 | return NULL;
|
---|
[320c884] | 320 | }
|
---|
| 321 |
|
---|
[2bc13887] | 322 | /** Find VFS file structure for a given file descriptor.
|
---|
| 323 | *
|
---|
| 324 | * @param fd File descriptor.
|
---|
| 325 | *
|
---|
| 326 | * @return VFS file structure corresponding to fd.
|
---|
| 327 | */
|
---|
| 328 | vfs_file_t *vfs_file_get(int fd)
|
---|
| 329 | {
|
---|
| 330 | return _vfs_file_get(VFS_DATA, fd);
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 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 |
|
---|
[4fe94c66] | 340 | /** Stop using a file structure.
|
---|
| 341 | *
|
---|
| 342 | * @param file VFS file structure.
|
---|
| 343 | */
|
---|
| 344 | void vfs_file_put(vfs_file_t *file)
|
---|
| 345 | {
|
---|
[2bc13887] | 346 | _vfs_file_put(VFS_DATA, file);
|
---|
| 347 | }
|
---|
| 348 |
|
---|
[e2ab36f1] | 349 | void vfs_pass_handle(task_id_t donor_id, task_id_t acceptor_id, int donor_fd)
|
---|
[2bc13887] | 350 | {
|
---|
| 351 | vfs_client_data_t *donor_data = NULL;
|
---|
| 352 | vfs_client_data_t *acceptor_data = NULL;
|
---|
| 353 | vfs_file_t *donor_file = NULL;
|
---|
| 354 | vfs_file_t *acceptor_file = NULL;
|
---|
[27b76ca] | 355 | vfs_boxed_handle_t *bh;
|
---|
[2bc13887] | 356 | int acceptor_fd;
|
---|
| 357 |
|
---|
[e2ab36f1] | 358 | acceptor_data = async_get_client_data_by_id(acceptor_id);
|
---|
[2bc13887] | 359 | if (!acceptor_data)
|
---|
[27b76ca] | 360 | return;
|
---|
| 361 |
|
---|
| 362 | bh = malloc(sizeof(vfs_boxed_handle_t));
|
---|
| 363 | assert(bh);
|
---|
| 364 |
|
---|
| 365 | link_initialize(&bh->link);
|
---|
| 366 | bh->handle = -1;
|
---|
| 367 |
|
---|
[e2ab36f1] | 368 | donor_data = async_get_client_data_by_id(donor_id);
|
---|
[27b76ca] | 369 | if (!donor_data)
|
---|
[2bc13887] | 370 | goto out;
|
---|
| 371 |
|
---|
| 372 | donor_file = _vfs_file_get(donor_data, donor_fd);
|
---|
| 373 | if (!donor_file)
|
---|
| 374 | goto out;
|
---|
| 375 |
|
---|
| 376 | acceptor_fd = _vfs_fd_alloc(acceptor_data, false);
|
---|
| 377 | if (acceptor_fd < 0)
|
---|
| 378 | goto out;
|
---|
| 379 |
|
---|
[27b76ca] | 380 | bh->handle = acceptor_fd;
|
---|
| 381 |
|
---|
[2bc13887] | 382 | /*
|
---|
| 383 | * Add a new reference to the underlying VFS node.
|
---|
| 384 | */
|
---|
| 385 | vfs_node_addref(donor_file->node);
|
---|
[221ab41a] | 386 | (void) vfs_open_node_remote(donor_file->node);
|
---|
[2bc13887] | 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;
|
---|
| 397 |
|
---|
| 398 | out:
|
---|
[27b76ca] | 399 | fibril_mutex_lock(&acceptor_data->lock);
|
---|
| 400 | list_append(&bh->link, &acceptor_data->passed_handles);
|
---|
| 401 | fibril_condvar_broadcast(&acceptor_data->cv);
|
---|
| 402 | fibril_mutex_unlock(&acceptor_data->lock);
|
---|
| 403 |
|
---|
[2bc13887] | 404 | if (donor_data)
|
---|
[e2ab36f1] | 405 | async_put_client_data_by_id(donor_id);
|
---|
[2bc13887] | 406 | if (acceptor_data)
|
---|
[e2ab36f1] | 407 | async_put_client_data_by_id(acceptor_id);
|
---|
[2bc13887] | 408 | if (donor_file)
|
---|
| 409 | _vfs_file_put(donor_data, donor_file);
|
---|
| 410 | if (acceptor_file)
|
---|
| 411 | _vfs_file_put(acceptor_data, acceptor_file);
|
---|
[27b76ca] | 412 |
|
---|
| 413 | }
|
---|
| 414 |
|
---|
| 415 | int vfs_wait_handle_internal(void)
|
---|
| 416 | {
|
---|
| 417 | vfs_client_data_t *vfs_data = VFS_DATA;
|
---|
| 418 | int fd;
|
---|
| 419 |
|
---|
| 420 | fibril_mutex_lock(&vfs_data->lock);
|
---|
| 421 | while (list_empty(&vfs_data->passed_handles))
|
---|
| 422 | fibril_condvar_wait(&vfs_data->cv, &vfs_data->lock);
|
---|
| 423 | link_t *lnk = list_first(&vfs_data->passed_handles);
|
---|
| 424 | list_remove(lnk);
|
---|
| 425 | fibril_mutex_unlock(&vfs_data->lock);
|
---|
| 426 |
|
---|
| 427 | vfs_boxed_handle_t *bh = list_get_instance(lnk, vfs_boxed_handle_t, link);
|
---|
| 428 | fd = bh->handle;
|
---|
| 429 | free(bh);
|
---|
| 430 |
|
---|
| 431 | return fd;
|
---|
[4fe94c66] | 432 | }
|
---|
| 433 |
|
---|
[320c884] | 434 | /**
|
---|
| 435 | * @}
|
---|
[ac23b9d3] | 436 | */
|
---|