fs_rammap.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /****************************************************************************
  2. * fs/mmap/rammap.h
  3. *
  4. * Copyright (C) 2011 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * References: Linux/Documentation/filesystems/romfs.txt
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. * 3. Neither the name NuttX nor the names of its contributors may be
  20. * used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  30. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  31. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  32. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  33. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. ****************************************************************************/
  37. #ifndef __FS_MMAP_RAMMAP_H
  38. #define __FS_MMAP_RAMMAP_H
  39. /****************************************************************************
  40. * Included Files
  41. ****************************************************************************/
  42. #include <nuttx/config.h>
  43. #include <sys/types.h>
  44. #include <semaphore.h>
  45. #ifdef CONFIG_FS_RAMMAP
  46. /****************************************************************************
  47. * Public Types
  48. ****************************************************************************/
  49. /* This structure describes one file that has been copied to memory and
  50. * managed as a share-able "memory mapped" file. This functionality is
  51. * intended to provide a substitute for memory mapped files for architectures
  52. * that do not have MMUs and, hence, cannot support on demand paging of
  53. * blocks of a file.
  54. *
  55. * This copied file has many of the properties of a standard memory mapped
  56. * file except:
  57. *
  58. * - All of the file must be present in memory. This limits the size of
  59. * files that may be memory mapped (especially on MCUs with no significant
  60. * RAM resources).
  61. * - All mapped files are read-only. You can write to the in-memory image,
  62. * but the file contents will not change.
  63. * - There are not access privileges.
  64. */
  65. struct fs_rammap_s
  66. {
  67. struct fs_rammap_s *flink; /* Implements a singly linked list */
  68. FAR void *addr; /* Start of allocated memory */
  69. size_t length; /* Length of region */
  70. off_t offset; /* File offset */
  71. };
  72. /* This structure defines all "mapped" files */
  73. struct fs_allmaps_s
  74. {
  75. bool initialized; /* True: This structure has been initialized */
  76. sem_t exclsem; /* Provides exclusive access the list */
  77. struct fs_rammap_s *head; /* List of mapped files */
  78. };
  79. /****************************************************************************
  80. * Public Data
  81. ****************************************************************************/
  82. /* This is the list of all mapped files */
  83. extern struct fs_allmaps_s g_rammaps;
  84. /****************************************************************************
  85. * Public Function Prototypes
  86. ****************************************************************************/
  87. /****************************************************************************
  88. * Name: rammap_initialize
  89. *
  90. * Description:
  91. * Verified that this capability has been initialized.
  92. *
  93. * Input Parameters:
  94. * None
  95. *
  96. * Returned Value:
  97. * None
  98. *
  99. ****************************************************************************/
  100. void rammap_initialize(void);
  101. /****************************************************************************
  102. * Name: rammmap
  103. *
  104. * Description:
  105. * Support simulation of memory mapped files by copying files into RAM.
  106. *
  107. * Input Parameters:
  108. * fd file descriptor of the backing file -- required.
  109. * length The length of the mapping. For exception #1 above, this length
  110. * ignored: The entire underlying media is always accessible.
  111. * offset The offset into the file to map
  112. *
  113. * Returned Value:
  114. * On success, rammmap() returns a pointer to the mapped area. On error, the
  115. * value MAP_FAILED is returned, and errno is set appropriately.
  116. *
  117. * EBADF
  118. * 'fd' is not a valid file descriptor.
  119. * EINVAL
  120. * 'length' or 'offset' are invalid
  121. * ENOMEM
  122. * Insufficient memory is available to map the file.
  123. *
  124. ****************************************************************************/
  125. FAR void *rammap(int fd, size_t length, off_t offset);
  126. #endif /* CONFIG_FS_RAMMAP */
  127. #endif /* __FS_MMAP_RAMMAP_H */