cromfs.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /****************************************************************************
  2. * fs/cromfs/cromfs.h
  3. *
  4. * Copyright (C) 2018 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __FS_CROMFS_CROMFS_H
  36. #define __FS_CROMFS_CROMFS_H 1
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <sys/types.h>
  41. #include <stdint.h>
  42. /****************************************************************************
  43. * Public Types
  44. ****************************************************************************/
  45. /* Maximum size of an offset. This should normally be size_t since this is
  46. * an in-memory file system. However, uint32_t is 32-bits on most 32-bit
  47. * target machines but 64-bits on 64-host machines. We restrict offsets to
  48. * 32-bits for commonality (limiting the size of the CROMFS image to 4Gb).
  49. *
  50. * REVISIT: What about small memory systems where the size_t is only 16-bits?
  51. *
  52. * Similarly, the NuttX mode_t is only 16-bits so uint16_t is explicitly used
  53. * for NuttX file modes.
  54. */
  55. /* This structure describes the CROMFS volume. It provides most of the
  56. * information needed for statfs() including:
  57. *
  58. * f_type - Type of filesystem
  59. * Return cv_magic (CROMFS_MAGIC)
  60. * f_namelen - Maximum length of filenames
  61. * Return NAME_MAX
  62. * f_bsize - Optimal block size for transfers
  63. * Return cv_bsize, the block size used when file system was
  64. * compressed
  65. * f_blocks - Total data blocks in the file system
  66. * - Return cv_nblocks
  67. * f_bfree - Free blocks in the file system
  68. * Return 0
  69. * f_bavail - Free blocks avail to non-superuser
  70. * Return 0
  71. * f_files - Total file nodes in the file system
  72. * - Return cv_nnodes
  73. * f_ffree - Free file nodes in the file system
  74. * Return 0
  75. *
  76. * The volume header is followed immediately by the root directory node. An
  77. * offset to that node is used to permit future variable length data (such as
  78. * a volume name) which may intervene.
  79. */
  80. struct cromfs_volume_s
  81. {
  82. uint32_t cv_magic; /* Must be first. Must be CROMFS_MAGIC */
  83. uint16_t cv_nnodes; /* Total number of nodes in-use */
  84. uint16_t cv_nblocks; /* Total number of data blocks in-use */
  85. uint32_t cv_root; /* Offset to the first node in the root file system */
  86. uint32_t cv_fsize; /* Size of the compressed file system image */
  87. uint32_t cv_bsize; /* Optimal block size for transfers */
  88. };
  89. /* This describes one node in the CROMFS file system. It holds node meta
  90. * data that provides the information that will be return by stat() or fstat()
  91. * and also provides the information needed by the CROMFS file system to
  92. * access the node data.
  93. *
  94. * Relationship to struct stat:
  95. *
  96. * st_mode - File type, attributes, and access mode bits
  97. * Return cn_mode from the node structure
  98. * st_size - Size of file/directory, in bytes
  99. * Return cn_size from the node structure
  100. * st_blksize - Block size used for filesystem I/O
  101. * Return cv_bsize from the volume header.
  102. * st_blocks - Number of blocks allocated
  103. * Return (cn_size + (cv_bsize - 1)) / cv_bsize
  104. * st_atime - Time of last access
  105. * Return 0
  106. * st_mtime - Time of last modification
  107. * Return 0
  108. * st_ctime - Time of last status change
  109. * Return 0
  110. */
  111. struct cromfs_node_s
  112. {
  113. uint16_t cn_mode; /* File type, attributes, and access mode bits */
  114. uint16_t cn_pad; /* Not used */
  115. uint32_t cn_name; /* Offset from the beginning of the volume header to the
  116. * node name string. NUL-terminated. */
  117. uint32_t cn_size; /* Size of the uncompressed data (in bytes) */
  118. uint32_t cn_peer; /* Offset to next node in this directory (for readdir()) */
  119. union
  120. {
  121. uint32_t cn_child; /* Offset to first node in sub-directory (directories only) */
  122. uint32_t cn_link; /* Offset to an arbitrary node (for hard link) */
  123. uint32_t cn_blocks; /* Offset to first block of compressed data (for read) */
  124. } u;
  125. };
  126. #endif /* __FS_CROMFS_CROMFS_H */