fs_mount.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _FS_MOUNT_H_
  13. #define _FS_MOUNT_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include "osi_compiler.h"
  17. OSI_EXTERN_C_BEGIN
  18. /**
  19. * \brief file system usage scenario
  20. *
  21. * The file system mount options may be different on varioud scenario.
  22. */
  23. typedef enum
  24. {
  25. FS_SCENRARIO_UNKNOWN, ///< prohibitted
  26. FS_SCENRARIO_APP, ///< normal application
  27. FS_SCENRARIO_BOOTLOADER, ///< bootloader
  28. FS_SCENRARIO_FDL, ///< FDL
  29. } fsMountScenario_t;
  30. /**
  31. * \brief set file system usage scenario
  32. *
  33. * The default scenario is \p FS_SCENRARIO_APP.
  34. *
  35. * \param scenario file system usage scenario
  36. */
  37. void fsMountSetScenario(fsMountScenario_t scenario);
  38. /**
  39. * \brief mount all file systems
  40. *
  41. * It will return false on the first error, such as mount fail.
  42. *
  43. * When a block device or file system is already mounted, the mounted block
  44. * device or file system won't be touched. So, it won't cause duplicated
  45. * mount.
  46. *
  47. * \return
  48. * - true on success
  49. * - false on fail
  50. */
  51. bool fsMountAll(void);
  52. /**
  53. * \brief mount all file systems, format on fail
  54. *
  55. * It is **dangerous**. Only call it at absolutely needed. Also, Don't call
  56. * this in application.
  57. *
  58. * \return
  59. * - true on success
  60. * - false on fail
  61. */
  62. bool fsMountWithFormatAll(void);
  63. /**
  64. * \brief format a file system
  65. *
  66. * It will perform:
  67. * - unmount file system;
  68. * - create flash block device, and format on fail;
  69. * - format and mount file system;
  70. *
  71. * \param path mount point
  72. * \return
  73. * - true on success
  74. * - false on fail
  75. */
  76. bool fsMountFormat(const char *path);
  77. /**
  78. * \brief mount file system by mount point
  79. *
  80. * When the file system is already mounted, it will do nothing and return
  81. * true.
  82. *
  83. * At mount fail and \p format_on_fail is true, when there is only one file
  84. * system on the underlay device, the device will be formatted. Otherwise,
  85. * when there are multiple file systems on the underlay device, due to
  86. * sub-partition, it will return false.
  87. *
  88. * \param path mount point
  89. * \param format_on_fail try to format at mount fail
  90. * \return
  91. * - true on success
  92. * - false on fail
  93. */
  94. bool fsMountFsPath(const char *path, bool format_on_fail);
  95. /**
  96. * \brief format all file systems on flash block device
  97. *
  98. * When sub-partition is not used, there will only exist one file system
  99. * on the block device. When sub-partition is used, there may exist
  100. * multiple sub-partitions on the flash block device, and there may exit
  101. * one file system on each sub-partition.
  102. *
  103. * It will perform:
  104. * - unmount all file systems;
  105. * - create flash block device, and format on fail;
  106. * - format and mount all file systems;
  107. *
  108. * \param name flash block device name
  109. * \return
  110. * - true on success
  111. * - false on fail
  112. */
  113. bool fsMountFormatFlash(unsigned name);
  114. /**
  115. * \brief umount all file system and block devices
  116. */
  117. void fsUmountAll(void);
  118. /**
  119. * \brief remount factory file system
  120. *
  121. * Refer to \p vfs_remount.
  122. *
  123. * \param flags file system mount flags
  124. */
  125. void fsRemountFactory(unsigned flags);
  126. /**
  127. * \brief find block device by device name
  128. *
  129. * \p name is the name in partition information configuration file.
  130. *
  131. * \param name block device name
  132. * \return
  133. * - block device instance
  134. * - NULL if not found
  135. */
  136. struct blockDevice *fsFindBlockDeviceByName(unsigned name);
  137. /**
  138. * \brief get all block device names
  139. *
  140. * \param names output for block device names
  141. * \param count maximum count
  142. * \return block device name count
  143. */
  144. int fsGetBlockDeviceNames(unsigned names[], unsigned count);
  145. OSI_EXTERN_C_END
  146. #endif