qdf_file.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * DOC: Thin filesystem API abstractions
  21. */
  22. #ifndef __QDF_FILE_H
  23. #define __QDF_FILE_H
  24. #include "qdf_status.h"
  25. /**
  26. * qdf_file_read() - read the entire contents of a file
  27. * @path: the full path of the file to read
  28. * @out_buf: double pointer for referring to the file contents buffer
  29. *
  30. * This API allocates a new, null-terminated buffer containing the contents of
  31. * the file at @path. On success, @out_buf points to this new buffer, otherwise
  32. * @out_buf is set to NULL.
  33. *
  34. * Consumers must free the allocated buffer by calling qdf_file_buf_free().
  35. *
  36. * Return: QDF_STATUS
  37. */
  38. QDF_STATUS qdf_file_read(const char *path, char **out_buf);
  39. /**
  40. * qdf_file_read_bytes() - read the entire contents of a file and return the
  41. * size read along with the content
  42. * @path: the full path of the file to read
  43. * @out_buf: double pointer for referring to the file contents buffer
  44. * @out_buff_size: size of the contents read
  45. *
  46. * This API allocates a new, null-terminated buffer containing the contents of
  47. * the file at @path. On success, @out_buf points to this new buffer, otherwise
  48. * @out_buf is set to NULL.
  49. *
  50. * Consumers must free the allocated buffer by calling qdf_file_buf_free().
  51. *
  52. * Return: QDF_STATUS
  53. */
  54. QDF_STATUS qdf_file_read_bytes(const char *path, char **out_buf,
  55. unsigned int *out_buff_size);
  56. /**
  57. * qdf_file_buf_free() - free a previously allocated file buffer
  58. * @file_buf: pointer to the file buffer to free
  59. *
  60. * This API is used in conjunction with qdf_file_read() and
  61. * qdf_file_read_bytes().
  62. *
  63. * Return: None
  64. */
  65. void qdf_file_buf_free(char *file_buf);
  66. #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
  67. /**
  68. * qdf_module_param_file_read() - read the entire contents of a file
  69. * @path: the full path of the file to read
  70. * @out_buf: double pointer for referring to the file contents buffer
  71. *
  72. * This API allocates a new buffer before qdf_mem_init() is being called.
  73. * Thus, this API helps to allocate memory which is being used before qdf
  74. * memory tracking framework is available. Buffer is null-terminated,
  75. * containing the contents of the file at @path. On success, @out_buf
  76. * points to this new buffer, otherwise @out_buf is set to NULL.
  77. *
  78. * Consumers must free the allocated buffer by calling
  79. * qdf_module_param_file_free().
  80. *
  81. * Return: QDF_STATUS
  82. */
  83. QDF_STATUS qdf_module_param_file_read(const char *path, char **out_buf);
  84. /**
  85. * qdf_module_param_file_free() - free a previously allocated file buffer
  86. * @file_buf: pointer to the file buffer to free. The buffer allocated in
  87. * qdf_module_param_file_read is not tracked by qdf framework.
  88. *
  89. * This API is used in conjunction with qdf_module_param_file_read().
  90. *
  91. * Return: None
  92. */
  93. void qdf_module_param_file_free(char *file_buf);
  94. #else
  95. static inline
  96. QDF_STATUS qdf_module_param_file_read(const char *path, char **out_buf)
  97. {
  98. return QDF_STATUS_E_INVAL;
  99. }
  100. static inline
  101. void qdf_module_param_file_free(char *file_buf)
  102. {
  103. }
  104. #endif
  105. #endif /* __QDF_FILE_H */