hostfs.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /****************************************************************************
  2. * nuttx/fs/hostfs/hostfs.h
  3. *
  4. * Copyright (C) 2015 Ken Pettit. All rights reserved.
  5. * Author: Ken Pettit <pettitkd@gmail.com>
  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_HOSTFS_HOSTFS_H
  36. #define __FS_HOSTFS_HOSTFS_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <sys/types.h>
  42. #include <stdint.h>
  43. #include <stdbool.h>
  44. #include <nuttx/semaphore.h>
  45. /****************************************************************************
  46. * Pre-processor Definitions
  47. ****************************************************************************/
  48. /* Quasi-standard definitions */
  49. #ifndef MIN
  50. # define MIN(a,b) (a < b ? a : b)
  51. #endif
  52. #ifndef MAX
  53. # define MAX(a,b) (a > b ? a : b)
  54. #endif
  55. #define HOSTFS_MAX_PATH 256
  56. /****************************************************************************
  57. * Public Types
  58. ****************************************************************************/
  59. /* This structure describes the state of one open file. This structure
  60. * is protected by the volume semaphore.
  61. */
  62. struct hostfs_ofile_s
  63. {
  64. struct hostfs_ofile_s *fnext; /* Supports a singly linked list */
  65. int16_t crefs; /* Reference count */
  66. mode_t oflags; /* Open mode */
  67. int fd;
  68. };
  69. /* This structure represents the overall mountpoint state. An instance of
  70. * this structure is retained as inode private data on each mountpoint that
  71. * is mounted with a hostfs filesystem.
  72. */
  73. struct hostfs_mountpt_s
  74. {
  75. sem_t *fs_sem; /* Used to assure thread-safe access */
  76. FAR struct hostfs_ofile_s *fs_head; /* A singly-linked list of open files */
  77. char fs_root[HOSTFS_MAX_PATH];
  78. };
  79. /****************************************************************************
  80. * Internal function prototypes
  81. ****************************************************************************/
  82. /* Semaphore access for internal use */
  83. int hostfs_semtake(struct hostfs_mountpt_s *fs);
  84. void hostfs_semgive(struct hostfs_mountpt_s *fs);
  85. /* Forward references for utility functions */
  86. struct hostfs_mountpt_s;
  87. struct file; /* Forward references */
  88. struct inode;
  89. struct fs_dirent_s;
  90. struct statfs;
  91. struct stat;
  92. #endif /* __FS_HOSTFS_HOSTFS_H */