xdirentry.h 7.3 KB

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