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