xdirentry.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 */
  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 MEDATA ((struct vfs_s_subclass *) me->data)
  26. #define VFSDATA(a) ((a->class != NULL) ? (struct vfs_s_subclass *) a->class->data : NULL)
  27. #define FH ((vfs_file_handler_t *) fh)
  28. #define FH_SUPER FH->ino->super
  29. #define LS_NOT_LINEAR 0
  30. #define LS_LINEAR_CLOSED 1
  31. #define LS_LINEAR_OPEN 2
  32. #define LS_LINEAR_PREOPEN 3
  33. /*** enums ***************************************************************************************/
  34. /* For vfs_s_subclass->flags */
  35. typedef enum
  36. {
  37. VFS_S_REMOTE = 1L << 0,
  38. VFS_S_READONLY = 1L << 1,
  39. VFS_S_USETMP = 1L << 2,
  40. } vfs_subclass_flags_t;
  41. /*** structures declarations (and typedefs of structures)*****************************************/
  42. /* Single connection or archive */
  43. struct vfs_s_super
  44. {
  45. struct vfs_class *me;
  46. struct vfs_s_inode *root;
  47. char *name; /* My name, whatever it means */
  48. int fd_usage; /* Number of open files */
  49. int ino_usage; /* Usage count of this superblock */
  50. int want_stale; /* If set, we do not flush cache properly */
  51. #ifdef ENABLE_VFS_NET
  52. vfs_path_element_t *path_element;
  53. #endif /* ENABLE_VFS_NET */
  54. void *data; /* This is for filesystem-specific use */
  55. };
  56. /*
  57. * Single virtual file - directory entry. The same inode can have many
  58. * entries (i.e. hard links), but usually has only one.
  59. */
  60. struct vfs_s_entry
  61. {
  62. struct vfs_s_inode *dir; /* Directory we are in, i.e. our parent */
  63. char *name; /* Name of this entry */
  64. struct vfs_s_inode *ino; /* ... and its inode */
  65. };
  66. /* Single virtual file - inode */
  67. struct vfs_s_inode
  68. {
  69. struct vfs_s_super *super; /* Archive the file is on */
  70. struct vfs_s_entry *ent; /* Our entry in the parent directory -
  71. use only for directories because they
  72. cannot be hardlinked */
  73. GList *subdir; /* If this is a directory, its entry. List of vfs_s_entry */
  74. struct stat st; /* Parameters of this inode */
  75. char *linkname; /* Symlink's contents */
  76. char *localname; /* Filename of local file, if we have one */
  77. struct timeval timestamp; /* Subclass specific */
  78. off_t data_offset; /* 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. int changed; /* Did this file change? */
  87. int linear; /* Is that file open with O_LINEAR? */
  88. void *data; /* This is for filesystem-specific use */
  89. } vfs_file_handler_t;
  90. /*
  91. * One of our subclasses (tar, cpio, fish, ftpfs) with data and methods.
  92. * Extends vfs_class. Stored in the "data" field of vfs_class.
  93. */
  94. struct vfs_s_subclass
  95. {
  96. GList *supers;
  97. int inode_counter;
  98. vfs_subclass_flags_t flags; /* whether the subclass is remove, read-only etc */
  99. dev_t rdev;
  100. FILE *logfile;
  101. int flush; /* if set to 1, invalidate directory cache */
  102. /* *INDENT-OFF* */
  103. int (*init_inode) (struct vfs_class * me, struct vfs_s_inode * ino); /* optional */
  104. void (*free_inode) (struct vfs_class * me, struct vfs_s_inode * ino); /* optional */
  105. int (*init_entry) (struct vfs_class * me, struct vfs_s_entry * entry); /* optional */
  106. void *(*archive_check) (const vfs_path_t * vpath); /* optional */
  107. int (*archive_same) (const vfs_path_element_t * vpath_element, struct vfs_s_super * psup,
  108. const vfs_path_t * vpath, void *cookie);
  109. int (*open_archive) (struct vfs_s_super * psup,
  110. const vfs_path_t * vpath, const vfs_path_element_t * vpath_element);
  111. void (*free_archive) (struct vfs_class * me, struct vfs_s_super * psup);
  112. int (*fh_open) (struct vfs_class * me, vfs_file_handler_t * fh, int flags, mode_t mode);
  113. int (*fh_close) (struct vfs_class * me, vfs_file_handler_t * fh);
  114. void (*fh_free_data) (vfs_file_handler_t * fh);
  115. struct vfs_s_entry *(*find_entry) (struct vfs_class * me,
  116. struct vfs_s_inode * root,
  117. const char *path, int follow, int flags);
  118. int (*dir_load) (struct vfs_class * me, struct vfs_s_inode * ino, char *path);
  119. int (*dir_uptodate) (struct vfs_class * me, struct vfs_s_inode * ino);
  120. int (*file_store) (struct vfs_class * me, vfs_file_handler_t * fh, char *path, char *localname);
  121. int (*linear_start) (struct vfs_class * me, vfs_file_handler_t * fh, off_t from);
  122. ssize_t (*linear_read) (struct vfs_class * me, vfs_file_handler_t * fh, void *buf, size_t len);
  123. void (*linear_close) (struct vfs_class * me, vfs_file_handler_t * fh);
  124. /* *INDENT-ON* */
  125. };
  126. /*** global variables defined in .c file *********************************************************/
  127. /*** declarations of public functions ************************************************************/
  128. /* entries and inodes */
  129. struct vfs_s_inode *vfs_s_new_inode (struct vfs_class *me,
  130. struct vfs_s_super *super, struct stat *initstat);
  131. void vfs_s_free_inode (struct vfs_class *me, struct vfs_s_inode *ino);
  132. struct vfs_s_entry *vfs_s_new_entry (struct vfs_class *me, const char *name,
  133. struct vfs_s_inode *inode);
  134. void vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent);
  135. void vfs_s_insert_entry (struct vfs_class *me, struct vfs_s_inode *dir, struct vfs_s_entry *ent);
  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_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub);
  145. const char *vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flags);
  146. struct vfs_s_super *vfs_get_super_by_vpath (const vfs_path_t * vpath);
  147. void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super);
  148. char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino);
  149. /* network filesystems support */
  150. int vfs_s_select_on_two (int fd1, int fd2);
  151. int vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char term);
  152. int vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer, int size, int fd);
  153. /* misc */
  154. int vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino);
  155. void vfs_s_normalize_filename_leading_spaces (struct vfs_s_inode *root_inode, size_t final_filepos);
  156. /*** inline functions ****************************************************************************/
  157. static inline void
  158. vfs_s_store_filename_leading_spaces (struct vfs_s_entry *entry, size_t position)
  159. {
  160. entry->ino->data_offset = (off_t) position;
  161. }
  162. #endif