Remove vfs_url_t structure (replace with vfs_path_element_t)
[midnight-commander.git] / lib / vfs / xdirentry.h
blob74899c406060790a837e14a6480326dc62873a40
2 /**
3 * \file
4 * \brief Header: Virtual File System directory structure
5 */
8 #ifndef MC__VFS_XDIRENTRY_H
9 #define MC__VFS_XDIRENTRY_H
11 #include <stdio.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 */
23 #define FL_NONE 0
24 #define FL_MKDIR 1
25 #define FL_MKFILE 2
26 #define FL_DIR 4
28 /* For open_super */
29 #define FL_NO_OPEN 1
31 /* For vfs_s_entry_from_path */
32 #define FL_FOLLOW 1
33 #define FL_DIR 4
35 /* For vfs_s_subclass->flags */
36 #define VFS_S_REMOTE 1
37 #define VFS_S_READONLY 2
39 #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
41 #define MEDATA ((struct vfs_s_subclass *) me->data)
43 #define VFSDATA(a) ((struct vfs_s_subclass *) a->class->data)
45 #define FH ((vfs_file_handler_t *) fh)
46 #define FH_SUPER FH->ino->super
48 #define LS_NOT_LINEAR 0
49 #define LS_LINEAR_CLOSED 1
50 #define LS_LINEAR_OPEN 2
51 #define LS_LINEAR_PREOPEN 3
53 /*** enums ***************************************************************************************/
55 /*** structures declarations (and typedefs of structures)*****************************************/
57 /* Single connection or archive */
58 struct vfs_s_super
60 struct vfs_class *me;
61 struct vfs_s_inode *root;
62 char *name; /* My name, whatever it means */
63 int fd_usage; /* Number of open files */
64 int ino_usage; /* Usage count of this superblock */
65 int want_stale; /* If set, we do not flush cache properly */
66 #ifdef ENABLE_VFS_NET
67 vfs_path_element_t *path_element;
68 #endif /* ENABLE_VFS_NET */
70 void *data; /* This is for filesystem-specific use */
74 * Single virtual file - directory entry. The same inode can have many
75 * entries (i.e. hard links), but usually has only one.
77 struct vfs_s_entry
79 struct vfs_s_inode *dir; /* Directory we are in, i.e. our parent */
80 char *name; /* Name of this entry */
81 struct vfs_s_inode *ino; /* ... and its inode */
84 /* Single virtual file - inode */
85 struct vfs_s_inode
87 struct vfs_s_super *super; /* Archive the file is on */
88 struct vfs_s_entry *ent; /* Our entry in the parent directory -
89 use only for directories because they
90 cannot be hardlinked */
91 GList *subdir; /* If this is a directory, its entry. List of vfs_s_entry */
92 struct stat st; /* Parameters of this inode */
93 char *linkname; /* Symlink's contents */
94 char *localname; /* Filename of local file, if we have one */
95 struct timeval timestamp; /* Subclass specific */
96 off_t data_offset; /* Subclass specific */
99 /* Data associated with an open file */
100 typedef struct
102 struct vfs_s_inode *ino;
103 off_t pos; /* This is for module's use */
104 int handle; /* This is for module's use, but if != -1, will be mc_close()d */
105 int changed; /* Did this file change? */
106 int linear; /* Is that file open with O_LINEAR? */
107 void *data; /* This is for filesystem-specific use */
108 } vfs_file_handler_t;
111 * One of our subclasses (tar, cpio, fish, ftpfs) with data and methods.
112 * Extends vfs_class. Stored in the "data" field of vfs_class.
114 struct vfs_s_subclass
116 GList *supers;
117 int inode_counter;
118 int flags; /* whether the subclass is remove, read-only etc */
119 dev_t rdev;
120 FILE *logfile;
121 int flush; /* if set to 1, invalidate directory cache */
123 int (*init_inode) (struct vfs_class * me, struct vfs_s_inode * ino); /* optional */
124 void (*free_inode) (struct vfs_class * me, struct vfs_s_inode * ino); /* optional */
125 int (*init_entry) (struct vfs_class * me, struct vfs_s_entry * entry); /* optional */
127 void *(*archive_check) (struct vfs_class * me, const char *name, char *op); /* optional */
128 int (*archive_same) (struct vfs_class * me, struct vfs_s_super * psup,
129 const char *archive_name, char *op, void *cookie);
130 int (*open_archive) (struct vfs_class * me, struct vfs_s_super * psup,
131 const char *archive_name, char *op);
132 void (*free_archive) (struct vfs_class * me, struct vfs_s_super * psup);
134 int (*fh_open) (struct vfs_class * me, vfs_file_handler_t * fh, int flags, mode_t mode);
135 int (*fh_close) (struct vfs_class * me, vfs_file_handler_t * fh);
137 struct vfs_s_entry *(*find_entry) (struct vfs_class * me,
138 struct vfs_s_inode * root,
139 const char *path, int follow, int flags);
140 int (*dir_load) (struct vfs_class * me, struct vfs_s_inode * ino, char *path);
141 int (*dir_uptodate) (struct vfs_class * me, struct vfs_s_inode * ino);
142 int (*file_store) (struct vfs_class * me, vfs_file_handler_t * fh, char *path, char *localname);
144 int (*linear_start) (struct vfs_class * me, vfs_file_handler_t * fh, off_t from);
145 int (*linear_read) (struct vfs_class * me, vfs_file_handler_t * fh, void *buf, size_t len);
146 void (*linear_close) (struct vfs_class * me, vfs_file_handler_t * fh);
149 /*** global variables defined in .c file *********************************************************/
151 /*** declarations of public functions ************************************************************/
153 /* entries and inodes */
154 struct vfs_s_inode *vfs_s_new_inode (struct vfs_class *me,
155 struct vfs_s_super *super, struct stat *initstat);
156 struct vfs_s_entry *vfs_s_new_entry (struct vfs_class *me, const char *name,
157 struct vfs_s_inode *inode);
158 void vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent);
159 void vfs_s_insert_entry (struct vfs_class *me, struct vfs_s_inode *dir, struct vfs_s_entry *ent);
160 struct stat *vfs_s_default_stat (struct vfs_class *me, mode_t mode);
162 struct vfs_s_entry *vfs_s_generate_entry (struct vfs_class *me, const char *name,
163 struct vfs_s_inode *parent, mode_t mode);
164 struct vfs_s_inode *vfs_s_find_inode (struct vfs_class *me,
165 const struct vfs_s_super *super,
166 const char *path, int follow, int flags);
167 struct vfs_s_inode *vfs_s_find_root (struct vfs_class *me, struct vfs_s_entry *entry);
169 /* outside interface */
170 void vfs_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub);
171 const char *vfs_s_get_path_mangle (const vfs_path_t * vpath, struct vfs_s_super **archive,
172 int flags);
174 void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super);
175 char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino);
177 /* network filesystems support */
178 int vfs_s_select_on_two (int fd1, int fd2);
179 int vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char term);
180 int vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer, int size, int fd);
181 /* misc */
182 int vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino);
184 /*** inline functions ****************************************************************************/
185 #endif