4 * \brief Header: Virtual File System directory structure
8 #ifndef MC__VFS_XDIRENTRY_H
9 #define MC__VFS_XDIRENTRY_H
12 #include <sys/types.h>
14 #include "lib/global.h" /* GList */
15 #include "lib/vfs/path.h" /* vfs_path_t */
17 /*** typedefs(not structures) and defined constants **********************************************/
19 #define LINK_FOLLOW 15
20 #define LINK_NO_FOLLOW -1
22 /* For vfs_s_find_entry and vfs_s_find_inode */
31 /* For vfs_s_entry_from_path */
35 #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
37 #define MEDATA ((struct vfs_s_subclass *) me)
39 #define VFS_SUBCLASS(a) ((struct vfs_s_subclass *) a->class)
41 #define FH ((vfs_file_handler_t *) fh)
42 #define FH_SUPER FH->ino->super
44 /*** enums ***************************************************************************************/
46 /* For vfs_s_subclass->flags */
49 VFS_S_REMOTE
= 1L << 0,
50 VFS_S_READONLY
= 1L << 1,
51 VFS_S_USETMP
= 1L << 2,
52 } vfs_subclass_flags_t
;
62 /*** structures declarations (and typedefs of structures)*****************************************/
64 /* Single connection or archive */
68 struct vfs_s_inode
*root
;
69 char *name
; /* My name, whatever it means */
70 int fd_usage
; /* Number of open files */
71 int ino_usage
; /* Usage count of this superblock */
72 gboolean want_stale
; /* If set, we do not flush cache properly */
74 vfs_path_element_t
*path_element
;
75 #endif /* ENABLE_VFS_NET */
77 void *data
; /* This is for filesystem-specific use */
81 * Single virtual file - directory entry. The same inode can have many
82 * entries (i.e. hard links), but usually has only one.
86 struct vfs_s_inode
*dir
; /* Directory we are in, i.e. our parent */
87 char *name
; /* Name of this entry */
88 struct vfs_s_inode
*ino
; /* ... and its inode */
91 /* Single virtual file - inode */
94 struct vfs_s_super
*super
; /* Archive the file is on */
95 struct vfs_s_entry
*ent
; /* Our entry in the parent directory -
96 use only for directories because they
97 cannot be hardlinked */
98 GList
*subdir
; /* If this is a directory, its entry. List of vfs_s_entry */
99 struct stat st
; /* Parameters of this inode */
100 char *linkname
; /* Symlink's contents */
101 char *localname
; /* Filename of local file, if we have one */
102 struct timeval timestamp
; /* Subclass specific */
103 off_t data_offset
; /* Subclass specific */
106 /* Data associated with an open file */
109 struct vfs_s_inode
*ino
;
110 off_t pos
; /* This is for module's use */
111 int handle
; /* This is for module's use, but if != -1, will be mc_close()d */
112 gboolean changed
; /* Did this file change? */
113 vfs_linear_state_t linear
; /* Is that file open with O_LINEAR? */
114 void *data
; /* This is for filesystem-specific use */
115 } vfs_file_handler_t
;
118 * One of our subclasses (tar, cpio, fish, ftpfs) with data and methods.
121 struct vfs_s_subclass
123 struct vfs_class base
; /* base class */
127 vfs_subclass_flags_t flags
; /* whether the subclass is remove, read-only etc */
130 int flush
; /* if set to 1, invalidate directory cache */
133 int (*init_inode
) (struct vfs_class
* me
, struct vfs_s_inode
* ino
); /* optional */
134 void (*free_inode
) (struct vfs_class
* me
, struct vfs_s_inode
* ino
); /* optional */
135 int (*init_entry
) (struct vfs_class
* me
, struct vfs_s_entry
* entry
); /* optional */
137 void *(*archive_check
) (const vfs_path_t
* vpath
); /* optional */
138 int (*archive_same
) (const vfs_path_element_t
* vpath_element
, struct vfs_s_super
* psup
,
139 const vfs_path_t
* vpath
, void *cookie
);
140 int (*open_archive
) (struct vfs_s_super
* psup
,
141 const vfs_path_t
* vpath
, const vfs_path_element_t
* vpath_element
);
142 void (*free_archive
) (struct vfs_class
* me
, struct vfs_s_super
* psup
);
144 int (*fh_open
) (struct vfs_class
* me
, vfs_file_handler_t
* fh
, int flags
, mode_t mode
);
145 int (*fh_close
) (struct vfs_class
* me
, vfs_file_handler_t
* fh
);
146 void (*fh_free_data
) (vfs_file_handler_t
* fh
);
148 struct vfs_s_entry
*(*find_entry
) (struct vfs_class
* me
,
149 struct vfs_s_inode
* root
,
150 const char *path
, int follow
, int flags
);
151 int (*dir_load
) (struct vfs_class
* me
, struct vfs_s_inode
* ino
, char *path
);
152 int (*dir_uptodate
) (struct vfs_class
* me
, struct vfs_s_inode
* ino
);
153 int (*file_store
) (struct vfs_class
* me
, vfs_file_handler_t
* fh
, char *path
, char *localname
);
155 int (*linear_start
) (struct vfs_class
* me
, vfs_file_handler_t
* fh
, off_t from
);
156 ssize_t (*linear_read
) (struct vfs_class
* me
, vfs_file_handler_t
* fh
, void *buf
, size_t len
);
157 void (*linear_close
) (struct vfs_class
* me
, vfs_file_handler_t
* fh
);
161 /*** global variables defined in .c file *********************************************************/
163 /*** declarations of public functions ************************************************************/
165 /* entries and inodes */
166 struct vfs_s_inode
*vfs_s_new_inode (struct vfs_class
*me
,
167 struct vfs_s_super
*super
, struct stat
*initstat
);
168 void vfs_s_free_inode (struct vfs_class
*me
, struct vfs_s_inode
*ino
);
170 struct vfs_s_entry
*vfs_s_new_entry (struct vfs_class
*me
, const char *name
,
171 struct vfs_s_inode
*inode
);
172 void vfs_s_free_entry (struct vfs_class
*me
, struct vfs_s_entry
*ent
);
173 void vfs_s_insert_entry (struct vfs_class
*me
, struct vfs_s_inode
*dir
, struct vfs_s_entry
*ent
);
174 struct stat
*vfs_s_default_stat (struct vfs_class
*me
, mode_t mode
);
176 struct vfs_s_entry
*vfs_s_generate_entry (struct vfs_class
*me
, const char *name
,
177 struct vfs_s_inode
*parent
, mode_t mode
);
178 struct vfs_s_inode
*vfs_s_find_inode (struct vfs_class
*me
,
179 const struct vfs_s_super
*super
,
180 const char *path
, int follow
, int flags
);
181 struct vfs_s_inode
*vfs_s_find_root (struct vfs_class
*me
, struct vfs_s_entry
*entry
);
183 /* outside interface */
184 void vfs_s_init_class (struct vfs_s_subclass
*sub
);
185 const char *vfs_s_get_path (const vfs_path_t
* vpath
, struct vfs_s_super
**archive
, int flags
);
186 struct vfs_s_super
*vfs_get_super_by_vpath (const vfs_path_t
* vpath
);
188 void vfs_s_invalidate (struct vfs_class
*me
, struct vfs_s_super
*super
);
189 char *vfs_s_fullpath (struct vfs_class
*me
, struct vfs_s_inode
*ino
);
191 /* network filesystems support */
192 int vfs_s_select_on_two (int fd1
, int fd2
);
193 int vfs_s_get_line (struct vfs_class
*me
, int sock
, char *buf
, int buf_len
, char term
);
194 int vfs_s_get_line_interruptible (struct vfs_class
*me
, char *buffer
, int size
, int fd
);
196 int vfs_s_retrieve_file (struct vfs_class
*me
, struct vfs_s_inode
*ino
);
198 void vfs_s_normalize_filename_leading_spaces (struct vfs_s_inode
*root_inode
, size_t final_filepos
);
200 /*** inline functions ****************************************************************************/
203 vfs_s_store_filename_leading_spaces (struct vfs_s_entry
*entry
, size_t position
)
205 entry
->ino
->data_offset
= (off_t
) position
;