• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 PROC_FILE_H
33 #define PROC_FILE_H
34 
35 #include "proc_fs.h"
36 
37 /**
38  * @ingroup  procfs
39  * @brief open a proc node
40  *
41  * @par Description:
42  * This API is used to open the  node by 'fileName' and flags,
43  *
44  * @attention
45  * <ul>
46  * <li>None.</li>
47  * </ul>
48  *
49  * @param  fileName [IN] Type  #const char * the fileName of the node to  be opened
50  * @param  flags    [IN] Type  #int the flags of open's node
51  *
52  * @retval #NULL                open failed
53  * @retval #NOT NULL            open successfully
54  * @par Dependency:
55  * <ul><li>proc_fs.h: the header file that contains the API declaration.</li></ul>
56  * @see proc_close
57  *
58  */
59 extern struct ProcDirEntry *OpenProcFile(const char *fileName, int flags, ...);
60 
61 /**
62  * @ingroup  procfs
63  * @brief read a proc node
64  *
65  * @par Description:
66  * This API is used to read the node by pde
67  *
68  * @attention
69  * <ul>
70  * <li>None.</li>
71  * </ul>
72  *
73  * @param  pde     [IN] Type #struct ProcDirEntry * pointer of the node structure to be read
74  * @param  buf     [IN] Type #void *  user-provided to save the data
75  * @param  len     [IN] Type #size_t  the length of want to read
76  *
77  * @retval #-1                read failed
78  * @retval #>0                Number of bytes read success
79  * @par Dependency:
80  * <ul><li>proc_fs.h: the header file that contains the API declaration.</li></ul>
81  * @see proc_open
82  *
83  */
84 extern int ReadProcFile(struct ProcDirEntry *pde, void *buf, size_t len);
85 
86 /**
87  * @ingroup  procfs
88  * @brief write a proc node
89  *
90  * @par Description:
91  * This API is used to write the node by pde
92  *
93  * @attention
94  * <ul>
95  * <li>None.</li>
96  * </ul>
97  *
98  * @param  pde     [IN] Type #struct ProcDirEntry * pointer of the node structure to be written
99  * @param  buf     [IN] Type #const void *    data to write
100  * @param  len     [IN] Type #size_t    length of data to write
101  *
102  * @retval #-1                write failed
103  * @retval #>0                Number of bytes write successfully
104  * @par Dependency:
105  * <ul><li>proc_fs.h: the header file that contains the API declaration.</li></ul>
106  * @see proc_open
107  *
108  */
109 extern int WriteProcFile(struct ProcDirEntry *pde, const void *buf, size_t len);
110 
111 /**
112  * @ingroup  procfs
113  * @brief File migration
114  *
115  * @par Description:
116  * This API is used to set the proc file migration
117  *
118  * @attention
119  * <ul>
120  * <li>None.</li>
121  * </ul>
122  *
123  * @param  pde     [IN] Type #struct ProcDirEntry *   pointer of the node structure to be deviation
124  * @param  offset  [IN] Type #loff_t    the number of deviation
125  * @param  whence  [IN] Type #int       the begin of  deviation
126  *
127  * @retval #<0                deviation failed
128  * @retval #>=0               deviation successfully
129  * @par Dependency:
130  * <ul><li>proc_fs.h: the header file that contains the API declaration.</li></ul>
131  * @see proc_open
132  *
133  */
134 extern loff_t LseekProcFile(struct ProcDirEntry *pde, loff_t offset, int whence);
135 
136 /**
137  * @ingroup  procfs
138  * @brief directory migration
139  *
140  * @par Description:
141  * This API is used to set the proc directory migration
142  *
143  * @attention
144  * <ul>
145  * <li>Only allow SEEK_SET to zero.</li>
146  * </ul>
147  *
148  * @param  pde     [IN] Type #struct ProcDirEntry *   pointer of the node structure to be deviated
149  * @param  pos     [IN] Type #off_t *      the number of deviation
150  * @param  whence  [IN] Type #int       the begin of deviation
151  *
152  * @retval #EINVAL            deviation failed
153  * @retval #ENOERR            deviation successfully
154  * @par Dependency:
155  * <ul><li>proc_fs.h: the header file that contains the API declaration.</li></ul>
156  * @see proc_open
157  *
158  */
159 int LseekDirProcFile(struct ProcDirEntry *pde, off_t *pos, int whence);
160 
161 /**
162  * @ingroup  procfs
163  * @brief close a proc node
164  *
165  * @par Description:
166  * This API is used to close the node by pde
167  *
168  * @attention
169  * <ul>
170  * <li>None.</li>
171  * </ul>
172  *
173  * @param  pde [IN] Type #struct ProcDirEntry * pointer of the node structure to be closed
174  *
175  * @retval #-1                close failed
176  * @retval #0                 close successfully
177  * @par Dependency:
178  * <ul><li>proc_fs.h: the header file that contains the API declaration.</li></ul>
179  * @see proc_open
180  *
181  */
182 extern int CloseProcFile(struct ProcDirEntry *pde);
183 
184 extern struct ProcDirEntry *GetProcRootEntry(void);
185 extern int ProcOpen(struct ProcFile *procFile);
186 
187 #endif
188