1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 
5 #ifndef VFS_FILE_H
6 #define VFS_FILE_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 /**
13  * @brief Get the file descriptor by file structure
14  *
15  * @param[in] file pointer the file structure
16  *
17  * @return the file descriptor
18  *
19  */
20 int32_t vfs_fd_get(vfs_file_t *file);
21 
22 /**
23  * @brief Get the file structure by file descriptor
24  *
25  * @param[in] fd the file descriptor
26  *
27  * @return the pointer of the file structure
28  *
29  */
30 vfs_file_t *vfs_file_get(int32_t fd);
31 
32 /**
33  * @brief Create a new file structure
34  *
35  * @param[in] node pointer to the inode
36  *
37  * @return the pointer of the file structure
38  *
39  */
40 vfs_file_t *vfs_file_new(vfs_inode_t *node);
41 
42 /**
43  * @brief Delete the file structure
44  *
45  * @param[in] file pointer to the file structure
46  *
47  * @return none
48  */
49 void vfs_file_del(vfs_file_t *file);
50 
51 /**
52  * @brief Mark fd as opened
53  *
54  * @param[in] fd the file descriptor
55  *
56  * @return On success return 0
57  *         if the fd is invalid return -1
58  *         if the fd has already been marked return 1
59  */
60 int32_t vfs_fd_mark_open(int32_t fd);
61 
62 /**
63  * @brief mark fd as closed
64  *
65  * @param[in] fd the file descriptor
66  *
67  * @return On success return 0
68  *         if the fd is invalid return -1
69  *         if the fd has already been marked return 1
70  */
71 int32_t vfs_fd_mark_close(int32_t fd);
72 
73 /**
74  * @brief query wether the fd is opened
75  *
76  * @param[in] fd the file descriptor
77  *
78  * @return if the fd is opened, return 1
79  *         else return 0
80  */
81 int32_t vfs_fd_is_open(int32_t fd);
82 
83 /* adapter tmp */
84 #define get_fd vfs_fd_get
85 #define get_file vfs_file_get
86 #define new_file vfs_file_new
87 #define del_file vfs_file_del
88 
89 #ifdef __cplusplus
90 }
91 #endif
92 
93 #endif /* VFS_FILE_H */
94