smart.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /****************************************************************************
  2. * include/nuttx/fs/smart.h
  3. * Sector Mapped Allocation for Really Tiny (SMART) FLASH interface
  4. *
  5. * Copyright (C) 2013 Ken Pettit. All rights reserved.
  6. * Author: Ken Pettit <pettitkd@gmail.com>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. * 3. Neither the name NuttX nor the names of its contributors may be
  19. * used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  32. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ****************************************************************************/
  36. #ifndef __INCLUDE_NUTTX_SMART_H
  37. #define __INCLUDE_NUTTX_SMART_H
  38. /****************************************************************************
  39. * Included Files
  40. ****************************************************************************/
  41. #include <nuttx/config.h>
  42. #include <sys/types.h>
  43. #include <stdint.h>
  44. #include <stdbool.h>
  45. /****************************************************************************
  46. * Pre-processor Definitions
  47. ****************************************************************************/
  48. /* Macros to hide implementation */
  49. #define SMART_FMT_ISFORMATTED 0x01
  50. #define SMART_FMT_HASBYTEWRITE 0x02
  51. /* The logical sector number of the root directory. */
  52. #define SMARTFS_ROOT_DIR_SECTOR 3
  53. /* Defines the sector types */
  54. #define SMARTFS_SECTOR_TYPE_DIR 1
  55. #define SMARTFS_SECTOR_TYPE_FILE 2
  56. #ifdef CONFIG_SMART_DEV_LOOP
  57. /* Loop device IOCTL commands */
  58. /* Command: SMART_LOOPIOC_SETUP
  59. * Description: Setup the loop device
  60. * Argument: A pointer to a read-only instance of struct losetup_s.
  61. * Dependencies: The loop device must be enabled (CONFIG_DEV_LOOP=y)
  62. */
  63. /* Command: SMART_LOOPIOC_TEARDOWN
  64. * Description: Teardown a loop device previously setup vis LOOPIOC_SETUP
  65. * Argument: A read-able pointer to the path of the device to be
  66. * torn down
  67. * Dependencies: The loop device must be enabled (CONFIG_DEV_LOOP=y)
  68. */
  69. #define SMART_LOOPIOC_SETUP _LOOPIOC(0x0001)
  70. #define SMART_LOOPIOC_TEARDOWN _LOOPIOC(0x0002)
  71. #endif
  72. /****************************************************************************
  73. * Public Types
  74. ****************************************************************************/
  75. /* The following defines the format information for the device. This
  76. * information is retrieved via the BIOC_GETFORMAT ioctl.
  77. */
  78. struct smart_format_s
  79. {
  80. uint16_t sectorsize; /* Size of one read/write sector */
  81. uint16_t availbytes; /* Number of bytes available in each sector */
  82. uint16_t nsectors; /* Total number of sectors on device */
  83. uint16_t nfreesectors; /* Number of free sectors on device */
  84. uint8_t flags; /* Format flags (see above) */
  85. uint8_t namesize; /* Size of filenames on this volume */
  86. #ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
  87. uint8_t nrootdirentries; /* Number of root directories on this device */
  88. uint8_t rootdirnum; /* Root directory number for this dev entry */
  89. #endif
  90. };
  91. /* The following defines the information for writing a logical sector
  92. * to the device.
  93. */
  94. struct smart_read_write_s
  95. {
  96. uint16_t logsector; /* The logical sector number */
  97. uint16_t offset; /* Offset within the sector to write to */
  98. uint16_t count; /* Number of bytes to write */
  99. const uint8_t *buffer; /* Pointer to the data to write */
  100. };
  101. /* The following defines the procfs data exchange interface between the
  102. * SMART MTD and FS layers.
  103. */
  104. #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_SMARTFS)
  105. struct smart_procfs_data_s
  106. {
  107. #ifdef CONFIG_MTD_SMART_ERASE_DEBUG
  108. const uint16_t *erasecounts; /* Pointer to the erase counts array */
  109. uint16_t erasesize; /* Number of entries in the erase counts array */
  110. #endif
  111. };
  112. #endif
  113. #ifdef CONFIG_SMART_DEV_LOOP
  114. /* This is the structure referred to in the argument to the LOOPIOC_SETUP
  115. * IOCTL command.
  116. */
  117. struct smart_losetup_s
  118. {
  119. FAR const char *filename; /* The file or character device to use */
  120. int minor; /* The minor number of thedevice */
  121. int erasesize; /* The erase size to use on the file */
  122. int sectsize; /* The sector / page size of the file */
  123. off_t offset; /* An offset that may be applied to the device */
  124. bool readonly; /* True: Read access will be supported only */
  125. };
  126. #endif
  127. /****************************************************************************
  128. * Public Data
  129. ****************************************************************************/
  130. #ifndef __ASSEMBLY__
  131. #ifdef __cplusplus
  132. #define EXTERN extern "C"
  133. extern "C"
  134. {
  135. #else
  136. #define EXTERN extern
  137. #endif
  138. /****************************************************************************
  139. * Public Function Prototypes
  140. ****************************************************************************/
  141. #undef EXTERN
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif /* __ASSEMBLY__ */
  146. #endif /* __INCLUDE_NUTTX_SMART_H */