filesystem.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * filesystem.h
  3. *
  4. * Copyright (C) 2016 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _FILESYSTEM_H_
  20. #define _FILESYSTEM_H_
  21. #include <common.h>
  22. #include <object.h>
  23. #include <sdk/list.h>
  24. #include <clock.h>
  25. #include <lock.h>
  26. #include <sdk/filesystem.h>
  27. #include <pipe.h>
  28. typedef struct mounted_volume mounted_volume_t;
  29. typedef struct file file_t;
  30. typedef struct file_instance file_instance_t;
  31. typedef dword_t (*fs_mount_proc_t)(const char *device, const char *mountpoint, dword_t flags);
  32. typedef dword_t (*fs_unmount_proc_t)(mounted_volume_t *volume);
  33. typedef dword_t (*fs_load_proc_t)(file_t **file);
  34. typedef dword_t (*fs_unload_proc_t)(file_t *file);
  35. typedef dword_t (*fs_open_proc_t)(file_instance_t **instance);
  36. typedef dword_t (*fs_close_proc_t)(file_instance_t *instance);
  37. typedef dword_t (*fs_delete_proc_t)(mounted_volume_t *volume, const char *path, bool_t purge);
  38. typedef dword_t (*fs_read_proc_t)(file_instance_t *file, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
  39. typedef dword_t (*fs_write_proc_t)(file_instance_t *file, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
  40. typedef dword_t (*fs_list_dir_proc_t)(file_instance_t *directory, char *filename, bool_t continue_scan);
  41. typedef dword_t (*fs_set_proc_t)(file_t *file, dword_t info_type, const void *buffer, size_t size);
  42. typedef struct
  43. {
  44. list_entry_t list;
  45. char name[16];
  46. fs_mount_proc_t mount;
  47. fs_unmount_proc_t unmount;
  48. fs_load_proc_t load_file;
  49. fs_unload_proc_t unload_file;
  50. fs_open_proc_t open_file;
  51. fs_close_proc_t close_file;
  52. fs_delete_proc_t delete_file;
  53. fs_read_proc_t read_file;
  54. fs_write_proc_t write_file;
  55. fs_list_dir_proc_t list_dir;
  56. fs_set_proc_t set_file;
  57. } fs_driver_t;
  58. typedef struct
  59. {
  60. list_entry_t list;
  61. pipe_t pipe;
  62. dword_t event_mask;
  63. file_instance_t *directory; /* weak reference */
  64. } event_watch_entry_t;
  65. struct file
  66. {
  67. object_t header;
  68. mounted_volume_t *volume;
  69. char *path;
  70. dword_t global_mode;
  71. dword_t attributes;
  72. qword_t size;
  73. dword_t owner_uid;
  74. };
  75. struct file_instance
  76. {
  77. object_t header;
  78. file_t *global; /* strong reference */
  79. dword_t mode;
  80. event_watch_entry_t *watch;
  81. };
  82. #include <device.h>
  83. struct mounted_volume
  84. {
  85. list_entry_t list;
  86. char *mountpoint;
  87. dword_t flags;
  88. lock_t lock;
  89. device_t *device;
  90. qword_t open_files;
  91. fs_driver_t *driver;
  92. list_entry_t event_watch_list;
  93. lock_t event_watch_list_lock;
  94. };
  95. void register_filesystem_driver(fs_driver_t *driver);
  96. bool_t unregister_filesystem_driver(fs_driver_t *driver);
  97. dword_t register_mounted_volume(mounted_volume_t *volume);
  98. dword_t unregister_mounted_volume(mounted_volume_t *volume);
  99. dword_t normalize_path(const char *path, char *normalized_path);
  100. dword_t open_file_internal(const char *path, file_instance_t **instance, dword_t mode, dword_t attributes);
  101. void report_filesystem_event(const char *path, dword_t type);
  102. #endif