1 /* 2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. 3 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this list of 9 * conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 * of conditions and the following disclaimer in the documentation and/or other materials 13 * provided with the distribution. 14 * 15 * 3. Neither the name of the copyright holder nor the names of its contributors may be used 16 * to endorse or promote products derived from this software without specific prior written 17 * permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef __INCLUDE_FS_FDTABLE_H 33 #define __INCLUDE_FS_FDTABLE_H 34 35 #include <limits.h> 36 #include <sys/select.h> 37 #include <semaphore.h> 38 #include "linux/spinlock.h" 39 40 /* open file table for process fd */ 41 struct file_table_s { 42 intptr_t sysFd; /* system fd associate with the tg_filelist index */ 43 }; 44 45 struct fd_table_s { 46 unsigned int max_fds; 47 struct file_table_s *ft_fds; /* process fd array associate with system fd */ 48 fd_set *proc_fds; 49 fd_set *cloexec_fds; 50 sem_t ft_sem; /* manage access to the file table */ 51 }; 52 53 struct files_struct { 54 int count; 55 struct fd_table_s *fdt; 56 unsigned int file_lock; 57 unsigned int next_fd; 58 #ifdef VFS_USING_WORKDIR 59 spinlock_t workdir_lock; 60 char workdir[PATH_MAX]; 61 #endif 62 #ifdef LOSCFG_CHROOT 63 struct Vnode *rootVnode; 64 #endif 65 }; 66 67 typedef struct ProcessCB LosProcessCB; 68 69 void files_refer(int fd); 70 71 int files_close_internal(int fd, LosProcessCB *processCB); 72 73 struct files_struct *dup_fd(struct files_struct *oldf); 74 75 struct files_struct *alloc_files(void); 76 77 void delete_files(struct files_struct *files); 78 79 struct files_struct *create_files_snapshot(const struct files_struct *oldf); 80 81 void delete_files_snapshot(struct files_struct *files); 82 83 int alloc_fd(int minfd); 84 85 void alloc_std_fd(struct fd_table_s *fdt); 86 87 void FileTableLock(struct fd_table_s *fdt); 88 89 void FileTableUnLock(struct fd_table_s *fdt); 90 91 struct fd_table_s *GetFdTable(void); 92 #endif 93