Lines Matching refs:fdtable
46 static struct fd_entry fdtable[CONFIG_ZVFS_OPEN_MAX] = { variable
55 .lock = Z_MUTEX_INITIALIZER(fdtable[0].lock),
56 .cond = Z_CONDVAR_INITIALIZER(fdtable[0].cond),
62 .lock = Z_MUTEX_INITIALIZER(fdtable[1].lock),
63 .cond = Z_CONDVAR_INITIALIZER(fdtable[1].cond),
69 .lock = Z_MUTEX_INITIALIZER(fdtable[2].lock),
70 .cond = Z_CONDVAR_INITIALIZER(fdtable[2].cond),
81 return atomic_inc(&fdtable[fd].refcount) + 1; in z_fd_ref()
94 old_rc = atomic_get(&fdtable[fd].refcount); in z_fd_unref()
98 } while (!atomic_cas(&fdtable[fd].refcount, old_rc, old_rc - 1)); in z_fd_unref()
104 fdtable[fd].obj = NULL; in z_fd_unref()
105 fdtable[fd].vtable = NULL; in z_fd_unref()
114 for (fd = 0; fd < ARRAY_SIZE(fdtable); fd++) { in _find_fd_entry()
115 if (!atomic_get(&fdtable[fd].refcount)) { in _find_fd_entry()
126 if ((fd < 0) || (fd >= ARRAY_SIZE(fdtable))) { in _check_fd()
131 fd = k_array_index_sanitize(fd, ARRAY_SIZE(fdtable)); in _check_fd()
133 if (!atomic_get(&fdtable[fd].refcount)) { in _check_fd()
147 if (fd < 0 || fd >= ARRAY_SIZE(fdtable)) { in fdtable_fd_is_initialized()
151 ref_lock = (struct k_mutex)Z_MUTEX_INITIALIZER(fdtable[fd].lock); in fdtable_fd_is_initialized()
152 if (memcmp(&ref_lock, &fdtable[fd].lock, sizeof(ref_lock)) != 0) { in fdtable_fd_is_initialized()
156 ref_cond = (struct k_condvar)Z_CONDVAR_INITIALIZER(fdtable[fd].cond); in fdtable_fd_is_initialized()
157 if (memcmp(&ref_cond, &fdtable[fd].cond, sizeof(ref_cond)) != 0) { in fdtable_fd_is_initialized()
173 entry = &fdtable[fd]; in zvfs_get_fd_obj()
187 for (fd = 0; fd < ARRAY_SIZE(fdtable); fd++) { in z_get_fd_by_obj_and_vtable()
188 if (fdtable[fd].obj == obj && fdtable[fd].vtable == vtable) { in z_get_fd_by_obj_and_vtable()
208 entry = &fdtable[fd]; in zvfs_get_obj_lock_and_cond()
230 entry = &fdtable[fd]; in zvfs_get_fd_obj_and_vtable()
250 fdtable[fd].obj = NULL; in zvfs_reserve_fd()
251 fdtable[fd].vtable = NULL; in zvfs_reserve_fd()
252 k_mutex_init(&fdtable[fd].lock); in zvfs_reserve_fd()
253 k_condvar_init(&fdtable[fd].cond); in zvfs_reserve_fd()
274 fdtable[fd].obj = obj; in zvfs_finalize_typed_fd()
275 fdtable[fd].vtable = vtable; in zvfs_finalize_typed_fd()
276 fdtable[fd].mode = mode; in zvfs_finalize_typed_fd()
284 &fdtable[fd].lock); in zvfs_finalize_typed_fd()
326 (void)k_mutex_lock(&fdtable[fd].lock, K_FOREVER); in zvfs_rw()
328 prw = supports_pread_pwrite(fdtable[fd].mode); in zvfs_rw()
340 off = (from_offset == NULL) ? &fdtable[fd].offset : from_offset; in zvfs_rw()
343 if (fdtable[fd].vtable->write_offs == NULL) { in zvfs_rw()
347 res = fdtable[fd].vtable->write_offs(fdtable[fd].obj, buf, sz, *off); in zvfs_rw()
350 if (fdtable[fd].vtable->read_offs == NULL) { in zvfs_rw()
354 res = fdtable[fd].vtable->read_offs(fdtable[fd].obj, buf, sz, *off); in zvfs_rw()
362 fdtable[fd].offset += res; in zvfs_rw()
366 k_mutex_unlock(&fdtable[fd].lock); in zvfs_rw()
389 (void)k_mutex_lock(&fdtable[fd].lock, K_FOREVER); in zvfs_close()
390 if (fdtable[fd].vtable->close != NULL) { in zvfs_close()
392 if (fdtable[fd].mode & ZVFS_MODE_IFSOCK) { in zvfs_close()
396 res = fdtable[fd].vtable->close2(fdtable[fd].obj, fd); in zvfs_close()
398 res = fdtable[fd].vtable->close(fdtable[fd].obj); in zvfs_close()
401 k_mutex_unlock(&fdtable[fd].lock); in zvfs_close()
416 return (FILE *)&fdtable[fd]; in zvfs_fdopen()
421 if (!IS_ARRAY_ELEMENT(fdtable, file)) { in zvfs_fileno()
426 return (struct fd_entry *)file - fdtable; in zvfs_fileno()
435 return zvfs_fdtable_call_ioctl(fdtable[fd].vtable, fdtable[fd].obj, ZFD_IOCTL_STAT, buf); in zvfs_fstat()
444 return zvfs_fdtable_call_ioctl(fdtable[fd].vtable, fdtable[fd].obj, ZFD_IOCTL_FSYNC); in zvfs_fsync()
452 __ASSERT_NO_MSG(fd < ARRAY_SIZE(fdtable)); in zvfs_lseek_wrap()
454 (void)k_mutex_lock(&fdtable[fd].lock, K_FOREVER); in zvfs_lseek_wrap()
456 res = fdtable[fd].vtable->ioctl(fdtable[fd].obj, cmd, args); in zvfs_lseek_wrap()
459 switch (fdtable[fd].mode & ZVFS_MODE_IFMT) { in zvfs_lseek_wrap()
464 fdtable[fd].offset = res; in zvfs_lseek_wrap()
470 k_mutex_unlock(&fdtable[fd].lock); in zvfs_lseek_wrap()
481 return zvfs_lseek_wrap(fd, ZFD_IOCTL_LSEEK, offset, whence, fdtable[fd].offset); in zvfs_lseek()
493 res = fdtable[fd].vtable->ioctl(fdtable[fd].obj, cmd, args); in zvfs_fcntl()
503 __ASSERT_NO_MSG(fd < ARRAY_SIZE(fdtable)); in zvfs_ftruncate_wrap()
505 (void)k_mutex_lock(&fdtable[fd].lock, K_FOREVER); in zvfs_ftruncate_wrap()
507 res = fdtable[fd].vtable->ioctl(fdtable[fd].obj, cmd, args); in zvfs_ftruncate_wrap()
509 k_mutex_unlock(&fdtable[fd].lock); in zvfs_ftruncate_wrap()
529 return fdtable[fd].vtable->ioctl(fdtable[fd].obj, request, args); in zvfs_ioctl()