Changeset 11882
- Timestamp:
- 03/17/05 15:25:07 (4 years ago)
- Location:
- haiku/trunk
- Files:
-
- 2 modified
-
headers/private/kernel/fd.h (modified) (1 diff)
-
src/kernel/core/fs/fd.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
haiku/trunk/headers/private/kernel/fd.h
r10434 r11882 37 37 int32 type; /* descriptor type */ 38 38 int32 ref_count; 39 int32 open_count; 39 40 struct fd_ops *ops; 40 41 union { -
haiku/trunk/src/kernel/core/fs/fd.c
r10221 r11882 55 55 descriptor->cookie = NULL; 56 56 descriptor->ref_count = 1; 57 descriptor->open_count = 1; 57 58 descriptor->open_mode = 0; 58 59 descriptor->pos = 0; … … 109 110 // free the descriptor if we don't need it anymore 110 111 if (atomic_add(&descriptor->ref_count, -1) == 1) { 111 // close the underlying object (and free any resources allocated there) 112 if (descriptor->ops->fd_close) 113 descriptor->ops->fd_close(descriptor); 112 // free the underlying object 114 113 if (descriptor->ops->fd_free) 115 114 descriptor->ops->fd_free(descriptor); … … 142 141 143 142 144 /** Removes the file descriptor in the specified slot, and 145 * reduces its reference counter. 143 /** Removes the file descriptor in the specified slot. 146 144 */ 147 145 148 static void146 static struct file_descriptor * 149 147 remove_fd(struct io_context *context, int fd) 150 148 { … … 152 150 153 151 if (fd < 0) 154 return ;152 return NULL; 155 153 156 154 mutex_lock(&context->io_mutex); … … 166 164 mutex_unlock(&context->io_mutex); 167 165 168 if (descriptor) 169 put_fd(descriptor); 166 return descriptor; 170 167 } 171 168 … … 303 300 304 301 302 static status_t 303 common_close(int fd, bool kernel) 304 { 305 struct io_context *io = get_current_io_context(kernel); 306 struct file_descriptor *descriptor = remove_fd(io, fd); 307 308 if (descriptor == NULL) 309 return B_FILE_ERROR; 310 311 #ifdef TRACE_FD 312 if (!kernel) 313 TRACE(("_user_close(descriptor = %p)\n", descriptor)); 314 #endif 315 316 if (atomic_add(&descriptor->open_count, -1) == 1) { 317 if (descriptor->ops->fd_close) 318 descriptor->ops->fd_close(descriptor); 319 } 320 321 put_fd(descriptor); 322 // the reference associated with the slot 323 324 return B_OK; 325 } 326 327 305 328 // #pragma mark - 306 329 /*** USER routines ***/ … … 593 616 _user_close(int fd) 594 617 { 595 struct io_context *io = get_current_io_context(false); 596 struct file_descriptor *descriptor = get_fd(io, fd); 597 598 if (descriptor == NULL) 599 return B_FILE_ERROR; 600 601 TRACE(("user_close(descriptor = %p)\n", descriptor)); 602 603 remove_fd(io, fd); 604 605 put_fd(descriptor); 606 return B_OK; 618 return common_close(fd, true); 607 619 } 608 620 … … 857 869 _kern_close(int fd) 858 870 { 859 struct io_context *io = get_current_io_context(true); 860 struct file_descriptor *descriptor = get_fd(io, fd); 861 862 if (descriptor == NULL) 863 return B_FILE_ERROR; 864 865 remove_fd(io, fd); 866 867 put_fd(descriptor); 868 return B_OK; 871 return common_close(fd, true); 869 872 } 870 873
