xref: /wlan-driver/qca-wifi-host-cmn/qdf/inc/qdf_file.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
4*5113495bSYour Name  *
5*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
6*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
7*5113495bSYour Name  * above copyright notice and this permission notice appear in all
8*5113495bSYour Name  * copies.
9*5113495bSYour Name  *
10*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
18*5113495bSYour Name  */
19*5113495bSYour Name 
20*5113495bSYour Name /**
21*5113495bSYour Name  * DOC: Thin filesystem API abstractions
22*5113495bSYour Name  */
23*5113495bSYour Name 
24*5113495bSYour Name #ifndef __QDF_FILE_H
25*5113495bSYour Name #define __QDF_FILE_H
26*5113495bSYour Name 
27*5113495bSYour Name #include "qdf_status.h"
28*5113495bSYour Name 
29*5113495bSYour Name /**
30*5113495bSYour Name  * qdf_file_read() - read the entire contents of a file
31*5113495bSYour Name  * @path: the full path of the file to read
32*5113495bSYour Name  * @out_buf: double pointer for referring to the file contents buffer
33*5113495bSYour Name  *
34*5113495bSYour Name  * This API allocates a new, null-terminated buffer containing the contents of
35*5113495bSYour Name  * the file at @path. On success, @out_buf points to this new buffer, otherwise
36*5113495bSYour Name  * @out_buf is set to NULL.
37*5113495bSYour Name  *
38*5113495bSYour Name  * Consumers must free the allocated buffer by calling qdf_file_buf_free().
39*5113495bSYour Name  *
40*5113495bSYour Name  * Return: QDF_STATUS
41*5113495bSYour Name  */
42*5113495bSYour Name QDF_STATUS qdf_file_read(const char *path, char **out_buf);
43*5113495bSYour Name 
44*5113495bSYour Name /**
45*5113495bSYour Name  * qdf_file_read_bytes() - read the entire contents of a file and return the
46*5113495bSYour Name  * size read along with the content
47*5113495bSYour Name  * @path: the full path of the file to read
48*5113495bSYour Name  * @out_buf: double pointer for referring to the file contents buffer
49*5113495bSYour Name  * @out_buff_size: size of the contents read
50*5113495bSYour Name  *
51*5113495bSYour Name  * This API allocates a new, null-terminated buffer containing the contents of
52*5113495bSYour Name  * the file at @path. On success, @out_buf points to this new buffer, otherwise
53*5113495bSYour Name  * @out_buf is set to NULL.
54*5113495bSYour Name  *
55*5113495bSYour Name  * Consumers must free the allocated buffer by calling qdf_file_buf_free().
56*5113495bSYour Name  *
57*5113495bSYour Name  * Return: QDF_STATUS
58*5113495bSYour Name  */
59*5113495bSYour Name QDF_STATUS qdf_file_read_bytes(const char *path, char **out_buf,
60*5113495bSYour Name 			       unsigned int *out_buff_size);
61*5113495bSYour Name 
62*5113495bSYour Name /**
63*5113495bSYour Name  * qdf_file_buf_free() - free a previously allocated file buffer
64*5113495bSYour Name  * @file_buf: pointer to the file buffer to free
65*5113495bSYour Name  *
66*5113495bSYour Name  * This API is used in conjunction with qdf_file_read() and
67*5113495bSYour Name  * qdf_file_read_bytes().
68*5113495bSYour Name  *
69*5113495bSYour Name  * Return: None
70*5113495bSYour Name  */
71*5113495bSYour Name void qdf_file_buf_free(char *file_buf);
72*5113495bSYour Name 
73*5113495bSYour Name #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
74*5113495bSYour Name /**
75*5113495bSYour Name  * qdf_module_param_file_read() - read the entire contents of a file
76*5113495bSYour Name  * @path: the full path of the file to read
77*5113495bSYour Name  * @out_buf: double pointer for referring to the file contents buffer
78*5113495bSYour Name  *
79*5113495bSYour Name  * This API allocates a new buffer before qdf_mem_init() is being called.
80*5113495bSYour Name  * Thus, this API helps to allocate memory which is being used before qdf
81*5113495bSYour Name  * memory tracking framework is available. Buffer is null-terminated,
82*5113495bSYour Name  * containing the contents of the file at @path. On success, @out_buf
83*5113495bSYour Name  * points to this new buffer, otherwise @out_buf is set to NULL.
84*5113495bSYour Name  *
85*5113495bSYour Name  * Consumers must free the allocated buffer by calling
86*5113495bSYour Name  * qdf_module_param_file_free().
87*5113495bSYour Name  *
88*5113495bSYour Name  * Return: QDF_STATUS
89*5113495bSYour Name  */
90*5113495bSYour Name 
91*5113495bSYour Name QDF_STATUS qdf_module_param_file_read(const char *path, char **out_buf);
92*5113495bSYour Name 
93*5113495bSYour Name /**
94*5113495bSYour Name  * qdf_module_param_file_free() - free a previously allocated file buffer
95*5113495bSYour Name  * @file_buf: pointer to the file buffer to free. The buffer allocated in
96*5113495bSYour Name  * qdf_module_param_file_read is not tracked by qdf framework.
97*5113495bSYour Name  *
98*5113495bSYour Name  * This API is used in conjunction with qdf_module_param_file_read().
99*5113495bSYour Name  *
100*5113495bSYour Name  * Return: None
101*5113495bSYour Name  */
102*5113495bSYour Name void qdf_module_param_file_free(char *file_buf);
103*5113495bSYour Name #else
104*5113495bSYour Name static inline
qdf_module_param_file_read(const char * path,char ** out_buf)105*5113495bSYour Name QDF_STATUS qdf_module_param_file_read(const char *path, char **out_buf)
106*5113495bSYour Name {
107*5113495bSYour Name 	return QDF_STATUS_E_INVAL;
108*5113495bSYour Name }
109*5113495bSYour Name 
110*5113495bSYour Name static inline
qdf_module_param_file_free(char * file_buf)111*5113495bSYour Name void qdf_module_param_file_free(char *file_buf)
112*5113495bSYour Name {
113*5113495bSYour Name }
114*5113495bSYour Name #endif
115*5113495bSYour Name #endif /* __QDF_FILE_H */
116*5113495bSYour Name 
117