dfs_fs.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file dfs_fs.h
  29. * @author Nations
  30. * @version v1.0.0
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef __DFS_FS_H__
  35. #define __DFS_FS_H__
  36. #include <dfs.h>
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /* Pre-declaration */
  41. struct dfs_filesystem;
  42. struct dfs_fd;
  43. /* File system operations */
  44. struct dfs_filesystem_ops
  45. {
  46. char *name;
  47. uint32_t flags; /* flags for file system operations */
  48. /* operations for file */
  49. const struct dfs_file_ops *fops;
  50. /* mount and unmount file system */
  51. int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data);
  52. int (*unmount) (struct dfs_filesystem *fs);
  53. /* make a file system */
  54. int (*mkfs) (rt_device_t devid);
  55. int (*statfs) (struct dfs_filesystem *fs, struct statfs *buf);
  56. int (*unlink) (struct dfs_filesystem *fs, const char *pathname);
  57. int (*stat) (struct dfs_filesystem *fs, const char *filename, struct stat *buf);
  58. int (*rename) (struct dfs_filesystem *fs, const char *oldpath, const char *newpath);
  59. };
  60. /* Mounted file system */
  61. struct dfs_filesystem
  62. {
  63. rt_device_t dev_id; /* Attached device */
  64. char *path; /* File system mount point */
  65. const struct dfs_filesystem_ops *ops; /* Operations for file system type */
  66. void *data; /* Specific file system data */
  67. };
  68. /* file system partition table */
  69. struct dfs_partition
  70. {
  71. uint8_t type; /* file system type */
  72. off_t offset; /* partition start offset */
  73. size_t size; /* partition size */
  74. rt_sem_t lock;
  75. };
  76. /* mount table */
  77. struct dfs_mount_tbl
  78. {
  79. const char *device_name;
  80. const char *path;
  81. const char *filesystemtype;
  82. unsigned long rwflag;
  83. const void *data;
  84. };
  85. int dfs_register(const struct dfs_filesystem_ops *ops);
  86. struct dfs_filesystem *dfs_filesystem_lookup(const char *path);
  87. const char *dfs_filesystem_get_mounted_path(struct rt_device *device);
  88. int dfs_filesystem_get_partition(struct dfs_partition *part,
  89. uint8_t *buf,
  90. uint32_t pindex);
  91. int dfs_mount(const char *device_name,
  92. const char *path,
  93. const char *filesystemtype,
  94. unsigned long rwflag,
  95. const void *data);
  96. int dfs_unmount(const char *specialfile);
  97. int dfs_mkfs(const char *fs_name, const char *device_name);
  98. int dfs_statfs(const char *path, struct statfs *buffer);
  99. int dfs_mount_device(rt_device_t dev);
  100. #ifdef __cplusplus
  101. }
  102. #endif
  103. #endif