xdirentry.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /**
  2. * \file
  3. * \brief Header: Virtual File System directory structure
  4. */
  5. #ifndef MC__VFS_XDIRENTRY_H
  6. #define MC__VFS_XDIRENTRY_H
  7. #include <stdio.h>
  8. #include <sys/types.h>
  9. #include "lib/global.h" /* GList */
  10. #include "lib/vfs/path.h" /* vfs_path_t */
  11. /*** typedefs(not structures) and defined constants **********************************************/
  12. #define LINK_FOLLOW 15
  13. #define LINK_NO_FOLLOW -1
  14. /* For vfs_s_find_entry and vfs_s_find_inode */
  15. #define FL_NONE 0
  16. #define FL_MKDIR 1
  17. #define FL_MKFILE 2
  18. #define FL_DIR 4
  19. /* For open_super */
  20. #define FL_NO_OPEN 1
  21. /* For vfs_s_entry_from_path */
  22. #define FL_FOLLOW 1
  23. #define FL_DIR 4
  24. #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
  25. #define VFS_SUBCLASS(a) ((struct vfs_s_subclass *) (a))
  26. #define VFS_SUPER(a) ((struct vfs_s_super *) (a))
  27. #define CONST_VFS_SUPER(a) ((const struct vfs_s_super *) (a))
  28. #define VFS_ENTRY(a) ((struct vfs_s_entry *) (a))
  29. #define VFS_INODE(a) ((struct vfs_s_inode *) (a))
  30. #define VFS_FILE_HANDLER(a) ((vfs_file_handler_t *) a)
  31. #define VFS_FILE_HANDLER_SUPER(a) VFS_FILE_HANDLER (a)->ino->super
  32. /*** enums ***************************************************************************************/
  33. typedef enum
  34. {
  35. LS_NOT_LINEAR = 0,
  36. LS_LINEAR_CLOSED = 1,
  37. LS_LINEAR_OPEN = 2,
  38. LS_LINEAR_PREOPEN = 3
  39. } vfs_linear_state_t;
  40. /*** structures declarations (and typedefs of structures)*****************************************/
  41. /* Single connection or archive */
  42. struct vfs_s_super
  43. {
  44. struct vfs_class *me;
  45. struct vfs_s_inode *root;
  46. char *name; /* My name, whatever it means */
  47. int fd_usage; /* Number of open files */
  48. int ino_usage; /* Usage count of this superblock */
  49. gboolean want_stale; /* If set, we do not flush cache properly */
  50. #ifdef ENABLE_VFS_NET
  51. vfs_path_element_t *path_element;
  52. #endif /* ENABLE_VFS_NET */
  53. };
  54. /*
  55. * Single virtual file - directory entry. The same inode can have many
  56. * entries (i.e. hard links), but usually has only one.
  57. */
  58. struct vfs_s_entry
  59. {
  60. struct vfs_s_inode *dir; /* Directory we are in, i.e. our parent */
  61. char *name; /* Name of this entry */
  62. struct vfs_s_inode *ino; /* ... and its inode */
  63. ssize_t leading_spaces; /* number of leading spases in the file name */
  64. };
  65. /* Single virtual file - inode */
  66. struct vfs_s_inode
  67. {
  68. struct vfs_s_super *super; /* Archive the file is on */
  69. struct vfs_s_entry *ent; /* Our entry in the parent directory -
  70. use only for directories because they
  71. cannot be hardlinked */
  72. GQueue *subdir; /* If this is a directory, its entry. List of vfs_s_entry */
  73. struct stat st; /* Parameters of this inode */
  74. char *linkname; /* Symlink's contents */
  75. char *localname; /* Filename of local file, if we have one */
  76. gint64 timestamp; /* Subclass specific */
  77. off_t data_offset; /* Subclass specific */
  78. void *user_data; /* Subclass specific */
  79. };
  80. /* Data associated with an open file */
  81. typedef struct
  82. {
  83. struct vfs_s_inode *ino;
  84. off_t pos; /* This is for module's use */
  85. int handle; /* This is for module's use, but if != -1, will be mc_close()d */
  86. gboolean changed; /* Did this file change? */
  87. vfs_linear_state_t linear; /* Is that file open with O_LINEAR? */
  88. } vfs_file_handler_t;
  89. /*
  90. * One of our subclasses (tar, cpio, shell, ftpfs) with data and methods.
  91. * Extends vfs_class.
  92. */
  93. struct vfs_s_subclass
  94. {
  95. struct vfs_class base; /* base class */
  96. GList *supers;
  97. int inode_counter;
  98. dev_t rdev;
  99. /* *INDENT-OFF* */
  100. int (*init_inode) (struct vfs_class * me, struct vfs_s_inode * ino); /* optional */
  101. void (*free_inode) (struct vfs_class * me, struct vfs_s_inode * ino); /* optional */
  102. int (*init_entry) (struct vfs_class * me, struct vfs_s_entry * entry); /* optional */
  103. void *(*archive_check) (const vfs_path_t * vpath); /* optional */
  104. int (*archive_same) (const vfs_path_element_t * vpath_element, struct vfs_s_super * psup,
  105. const vfs_path_t * vpath, void *cookie);
  106. struct vfs_s_super *(*new_archive) (struct vfs_class * me);
  107. int (*open_archive) (struct vfs_s_super * psup,
  108. const vfs_path_t * vpath, const vfs_path_element_t * vpath_element);
  109. void (*free_archive) (struct vfs_class * me, struct vfs_s_super * psup);
  110. vfs_file_handler_t *(*fh_new) (struct vfs_s_inode * ino, gboolean changed);
  111. int (*fh_open) (struct vfs_class * me, vfs_file_handler_t * fh, int flags, mode_t mode);
  112. int (*fh_close) (struct vfs_class * me, vfs_file_handler_t * fh);
  113. void (*fh_free) (vfs_file_handler_t * fh);
  114. struct vfs_s_entry *(*find_entry) (struct vfs_class * me,
  115. struct vfs_s_inode * root,
  116. const char *path, int follow, int flags);
  117. int (*dir_load) (struct vfs_class * me, struct vfs_s_inode * ino, const char *path);
  118. gboolean (*dir_uptodate) (struct vfs_class * me, struct vfs_s_inode * ino);
  119. int (*file_store) (struct vfs_class * me, vfs_file_handler_t * fh, char *path, char *localname);
  120. int (*linear_start) (struct vfs_class * me, vfs_file_handler_t * fh, off_t from);
  121. ssize_t (*linear_read) (struct vfs_class * me, vfs_file_handler_t * fh, void *buf, size_t len);
  122. void (*linear_close) (struct vfs_class * me, vfs_file_handler_t * fh);
  123. /* *INDENT-ON* */
  124. };
  125. /*** global variables defined in .c file *********************************************************/
  126. /*** declarations of public functions ************************************************************/
  127. /* entries and inodes */
  128. struct vfs_s_inode *vfs_s_new_inode (struct vfs_class *me,
  129. struct vfs_s_super *super, struct stat *initstat);
  130. void vfs_s_free_inode (struct vfs_class *me, struct vfs_s_inode *ino);
  131. struct vfs_s_entry *vfs_s_new_entry (struct vfs_class *me, const char *name,
  132. struct vfs_s_inode *inode);
  133. void vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent);
  134. void vfs_s_insert_entry (struct vfs_class *me, struct vfs_s_inode *dir, struct vfs_s_entry *ent);
  135. int vfs_s_entry_compare (const void *a, const void *b);
  136. struct stat *vfs_s_default_stat (struct vfs_class *me, mode_t mode);
  137. struct vfs_s_entry *vfs_s_generate_entry (struct vfs_class *me, const char *name,
  138. struct vfs_s_inode *parent, mode_t mode);
  139. struct vfs_s_inode *vfs_s_find_inode (struct vfs_class *me,
  140. const struct vfs_s_super *super,
  141. const char *path, int follow, int flags);
  142. struct vfs_s_inode *vfs_s_find_root (struct vfs_class *me, struct vfs_s_entry *entry);
  143. /* outside interface */
  144. void vfs_init_subclass (struct vfs_s_subclass *sub, const char *name, vfs_flags_t flags,
  145. const char *prefix);
  146. const char *vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flags);
  147. struct vfs_s_super *vfs_get_super_by_vpath (const vfs_path_t * vpath);
  148. void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super);
  149. char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino);
  150. void vfs_s_init_fh (vfs_file_handler_t * fh, struct vfs_s_inode *ino, gboolean changed);
  151. /* network filesystems support */
  152. int vfs_s_select_on_two (int fd1, int fd2);
  153. int vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char term);
  154. int vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer, int size, int fd);
  155. /* misc */
  156. int vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino);
  157. void vfs_s_normalize_filename_leading_spaces (struct vfs_s_inode *root_inode, size_t final_filepos);
  158. /*** inline functions ****************************************************************************/
  159. static inline void
  160. vfs_s_store_filename_leading_spaces (struct vfs_s_entry *entry, size_t position)
  161. {
  162. entry->leading_spaces = (ssize_t) position;
  163. }
  164. #endif