Lines Matching refs:fd

11 #include <fd.h>
47 int fd);
48 static struct file_descriptor* remove_fd(struct io_context* context, int fd);
53 // #pragma mark - General fd routines
57 void dump_fd(int fd, struct file_descriptor* descriptor);
60 dump_fd(int fd,struct file_descriptor* descriptor)
62 dprintf("fd[%d] = %p: type = %" B_PRId32 ", ref_count = %" B_PRId32 ", ops "
65 fd, descriptor, descriptor->type, descriptor->ref_count,
94 fd_close_on_exec(struct io_context* context, int fd)
96 return CHECK_BIT(context->fds_close_on_exec[fd / 8], fd & 7) ? true : false;
101 fd_set_close_on_exec(struct io_context* context, int fd, bool closeFD)
104 context->fds_close_on_exec[fd / 8] |= (1 << (fd & 7));
106 context->fds_close_on_exec[fd / 8] &= ~(1 << (fd & 7));
117 int fd = -1;
127 fd = i;
131 if (fd < 0) {
132 fd = B_NO_MORE_FDS;
136 TFD(NewFD(context, fd, descriptor));
138 context->fds[fd] = descriptor;
145 return fd;
218 close_fd_index(struct io_context* context, int fd)
220 struct file_descriptor* descriptor = remove_fd(context, fd);
254 get_fd_locked(struct io_context* context, int fd)
256 if (fd < 0 || (uint32)fd >= context->table_size)
259 struct file_descriptor* descriptor = context->fds[fd];
266 TFD(GetFD(context, fd, descriptor));
275 get_fd(struct io_context* context, int fd)
279 return get_fd_locked(context, fd);
284 get_open_fd(struct io_context* context, int fd)
288 file_descriptor* descriptor = get_fd_locked(context, fd);
301 remove_fd(struct io_context* context, int fd)
305 if (fd < 0)
310 if ((uint32)fd < context->table_size)
311 descriptor = context->fds[fd];
317 // fd is valid
318 TFD(RemoveFD(context, fd, descriptor));
320 context->fds[fd] = NULL;
321 fd_set_close_on_exec(context, fd, false);
324 selectInfos = context->select_infos[fd];
325 context->select_infos[fd] = NULL;
340 dup_fd(int fd, bool kernel)
346 TRACE(("dup_fd: fd = %d\n", fd));
348 // Try to get the fd structure
349 descriptor = get_fd(context, fd);
353 // now put the fd in place
423 // Say bye bye to the evicted fd
435 \param fd The FD to duplicate.
441 dup_foreign_fd(team_id fromTeam, int fd, bool kernel)
452 file_descriptor* descriptor = get_fd(fromContext, fd);
469 fd_ioctl(bool kernelFD, int fd, uint32 op, void* buffer, size_t length)
471 FileDescriptorPutter descriptor(get_fd(get_current_io_context(kernelFD), fd));
520 select_fd(int32 fd, struct select_info* info, bool kernel)
522 TRACE(("select_fd(fd = %" B_PRId32 ", info = %p (%p), 0x%x)\n", fd, info,
531 descriptor.SetTo(get_fd_locked(context, fd));
569 if (context->fds[fd] != descriptor.Get()) {
582 info->next = context->select_infos[fd];
583 context->select_infos[fd] = info;
599 deselect_fd(int32 fd, struct select_info* info, bool kernel)
601 TRACE(("deselect_fd(fd = %" B_PRId32 ", info = %p (%p), 0x%x)\n", fd, info,
610 descriptor.SetTo(get_fd_locked(context, fd));
616 select_info** infoLocation = &context->select_infos[fd];
645 /*! This function checks if the specified fd is valid in the current
646 context. It can be used for a quick check; the fd is not locked
650 fd_is_valid(int fd, bool kernel)
653 = get_fd(get_current_io_context(kernel), fd);
678 common_close(int fd, bool kernel)
680 return close_fd_index(get_current_io_context(kernel), fd);
685 common_user_io(int fd, off_t pos, void* buffer, size_t length, bool write)
690 FileDescriptorPutter descriptor(get_fd(get_current_io_context(false), fd));
736 common_user_vector_io(int fd, off_t pos, const iovec* userVecs, size_t count,
748 FileDescriptorPutter descriptor(get_fd(get_current_io_context(false), fd));
812 user_fd_kernel_ioctl(int fd, uint32 op, void* buffer, size_t length)
814 TRACE(("user_fd_kernel_ioctl: fd %d\n", fd));
816 return fd_ioctl(false, fd, op, buffer, length);
824 _user_read(int fd, off_t pos, void* buffer, size_t length)
826 return common_user_io(fd, pos, buffer, length, false);
831 _user_readv(int fd, off_t pos, const iovec* userVecs, size_t count)
833 return common_user_vector_io(fd, pos, userVecs, count, false);
838 _user_write(int fd, off_t pos, const void* buffer, size_t length)
840 return common_user_io(fd, pos, (void*)buffer, length, true);
845 _user_writev(int fd, off_t pos, const iovec* userVecs, size_t count)
847 return common_user_vector_io(fd, pos, userVecs, count, true);
852 _user_seek(int fd, off_t pos, int seekType)
856 FileDescriptorPutter descriptor(get_fd(get_current_io_context(false), fd));
872 _user_ioctl(int fd, uint32 op, void* buffer, size_t length)
874 TRACE(("user_ioctl: fd %d\n", fd));
885 return status = fd_ioctl(false, fd, op, buffer, length);
890 _user_read_dir(int fd, struct dirent* userBuffer, size_t bufferSize,
893 TRACE(("user_read_dir(fd = %d, userBuffer = %p, bufferSize = %ld, count = "
894 "%" B_PRIu32 ")\n", fd, userBuffer, bufferSize, maxCount));
904 FileDescriptorPutter descriptor(get_fd(ioContext, fd));
947 _user_rewind_dir(int fd)
949 TRACE(("user_rewind_dir(fd = %d)\n", fd));
951 FileDescriptorPutter descriptor(get_fd(get_current_io_context(false), fd));
966 _user_close(int fd)
968 return common_close(fd, false);
973 _user_dup(int fd)
975 return dup_fd(fd, false);
990 _kern_read(int fd, off_t pos, void* buffer, size_t length)
995 FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
1030 _kern_readv(int fd, off_t pos, const iovec* vecs, size_t count)
1037 FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
1082 _kern_write(int fd, off_t pos, const void* buffer, size_t length)
1087 FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
1122 _kern_writev(int fd, off_t pos, const iovec* vecs, size_t count)
1129 FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
1174 _kern_seek(int fd, off_t pos, int seekType)
1176 FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
1190 _kern_ioctl(int fd, uint32 op, void* buffer, size_t length)
1192 TRACE(("kern_ioctl: fd %d\n", fd));
1196 return fd_ioctl(true, fd, op, buffer, length);
1201 _kern_read_dir(int fd, struct dirent* buffer, size_t bufferSize,
1204 TRACE(("sys_read_dir(fd = %d, buffer = %p, bufferSize = %ld, count = "
1205 "%" B_PRIu32 ")\n",fd, buffer, bufferSize, maxCount));
1208 FileDescriptorPutter descriptor(get_fd(ioContext, fd));
1227 _kern_rewind_dir(int fd)
1229 TRACE(("sys_rewind_dir(fd = %d)\n",fd));
1231 FileDescriptorPutter descriptor(get_fd(get_current_io_context(true), fd));
1246 _kern_close(int fd)
1248 return common_close(fd, true);
1253 _kern_dup(int fd)
1255 return dup_fd(fd, true);