Ticket #2242 (improved FISH)
[midnight-commander.git] / lib / vfs / mc-vfs / xdirentry.h
blobe8bb8807308fd090cc82cf3b9c12cc262b33c593
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>
13 #include <sys/types.h>
15 #define LINK_FOLLOW 15
16 #define LINK_NO_FOLLOW -1
18 /* For vfs_s_find_entry */
19 #define FL_NONE 0
20 #define FL_MKDIR 1
21 #define FL_MKFILE 2
22 #define FL_DIR 4
24 /* For open_super */
25 #define FL_NO_OPEN 1
27 /* For vfs_s_entry_from_path */
28 #define FL_FOLLOW 1
29 #define FL_DIR 4
31 /* For vfs_s_subclass->flags */
32 #define VFS_S_REMOTE 1
33 #define VFS_S_READONLY 2
36 /* Single connection or archive */
37 struct vfs_s_super {
38 struct vfs_s_super **prevp, *next;
39 struct vfs_class *me;
40 struct vfs_s_inode *root;
41 char *name; /* My name, whatever it means */
42 int fd_usage; /* Number of open files */
43 int ino_usage; /* Usage count of this superblock */
44 int want_stale; /* If set, we do not flush cache properly */
46 union {
47 struct {
48 int sockr, sockw;
49 char *cwdir;
50 char *host, *user;
51 char *password;
52 int flags;
53 char *scr_ls;
54 char *scr_chmod;
55 char *scr_exists;
56 char *scr_mkdir;
57 char *scr_unlink;
58 char *scr_chown;
59 char *scr_rmdir;
60 char *scr_ln;
61 char *scr_mv;
62 char *scr_hardlink;
63 char *scr_get;
64 char *scr_send;
65 char *scr_append;
66 char *scr_info;
67 int host_flags;
68 char *scr_env;
69 } fish;
70 struct {
71 int sock;
72 char *cwdir;
73 char *host, *user;
74 char *password;
75 int port;
77 char *proxy; /* proxy server, NULL if no proxy */
78 int failed_on_login; /* used to pass the failure reason to upper levels */
79 int use_passive_connection;
80 int remote_is_amiga; /* No leading slash allowed for AmiTCP (Amiga) */
81 int isbinary;
82 int cwd_deferred; /* current_directory was changed but CWD command hasn't
83 been sent yet */
84 int strict; /* ftp server doesn't understand
85 "LIST -la <path>"; use "CWD <path>"/
86 "LIST" instead */
87 int ctl_connection_busy;
88 } ftp;
89 struct {
90 int fd;
91 struct stat st;
92 int type; /* Type of the archive */
93 struct defer_inode *deferred; /* List of inodes for which another entries may appear */
94 } arch;
95 } u;
99 * Single virtual file - directory entry. The same inode can have many
100 * entries (i.e. hard links), but usually has only one.
102 struct vfs_s_entry {
103 struct vfs_s_entry **prevp, *next; /* Pointers in the entry list */
104 struct vfs_s_inode *dir; /* Directory we are in, i.e. our parent */
105 char *name; /* Name of this entry */
106 struct vfs_s_inode *ino; /* ... and its inode */
109 /* Single virtual file - inode */
110 struct vfs_s_inode {
111 struct vfs_s_super *super; /* Archive the file is on */
112 struct vfs_s_entry *ent; /* Our entry in the parent directory -
113 use only for directories because they
114 cannot be hardlinked */
115 struct vfs_s_entry *subdir; /* If this is a directory, its entry */
116 struct stat st; /* Parameters of this inode */
117 char *linkname; /* Symlink's contents */
118 char *localname; /* Filename of local file, if we have one */
119 struct timeval timestamp; /* Subclass specific */
120 long data_offset; /* Subclass specific */
123 /* Data associated with an open file */
124 struct vfs_s_fh {
125 struct vfs_s_inode *ino;
126 long pos; /* This is for module's use */
127 int handle; /* This is for module's use, but if != -1, will be mc_close()d */
128 int changed; /* Did this file change? */
129 int linear; /* Is that file open with O_LINEAR? */
130 union {
131 struct {
132 off_t got, total;
133 int append;
134 } fish;
135 struct {
136 int sock, append;
137 } ftp;
138 } u;
142 * One of our subclasses (tar, cpio, fish, ftpfs) with data and methods.
143 * Extends vfs_class. Stored in the "data" field of vfs_class.
145 struct vfs_s_subclass {
146 struct vfs_s_super *supers;
147 int inode_counter;
148 int flags; /* whether the subclass is remove, read-only etc */
149 dev_t rdev;
150 FILE *logfile;
151 int flush; /* if set to 1, invalidate directory cache */
153 int (*init_inode) (struct vfs_class *me, struct vfs_s_inode *ino); /* optional */
154 void (*free_inode) (struct vfs_class *me, struct vfs_s_inode *ino); /* optional */
155 int (*init_entry) (struct vfs_class *me, struct vfs_s_entry *entry); /* optional */
157 void *(*archive_check) (struct vfs_class *me, const char *name, char *op); /* optional */
158 int (*archive_same) (struct vfs_class *me, struct vfs_s_super *psup,
159 const char *archive_name, char *op, void *cookie);
160 int (*open_archive) (struct vfs_class *me, struct vfs_s_super *psup,
161 const char *archive_name, char *op);
162 void (*free_archive) (struct vfs_class *me,
163 struct vfs_s_super *psup);
165 int (*fh_open) (struct vfs_class *me, struct vfs_s_fh *fh, int flags,
166 int mode);
167 int (*fh_close) (struct vfs_class *me, struct vfs_s_fh *fh);
169 struct vfs_s_entry *(*find_entry) (struct vfs_class *me,
170 struct vfs_s_inode *root,
171 const char *path, int follow, int flags);
172 int (*dir_load) (struct vfs_class *me, struct vfs_s_inode *ino,
173 char *path);
174 int (*dir_uptodate) (struct vfs_class *me, struct vfs_s_inode *ino);
175 int (*file_store) (struct vfs_class *me, struct vfs_s_fh *fh,
176 char *path, char *localname);
178 int (*linear_start) (struct vfs_class *me, struct vfs_s_fh *fh,
179 off_t from);
180 int (*linear_read) (struct vfs_class *me, struct vfs_s_fh *fh,
181 void *buf, int len);
182 void (*linear_close) (struct vfs_class *me, struct vfs_s_fh *fh);
186 /* entries and inodes */
187 struct vfs_s_inode *vfs_s_new_inode (struct vfs_class *me,
188 struct vfs_s_super *super,
189 struct stat *initstat);
190 struct vfs_s_entry *vfs_s_new_entry (struct vfs_class *me, const char *name,
191 struct vfs_s_inode *inode);
192 void vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent);
193 void vfs_s_insert_entry (struct vfs_class *me, struct vfs_s_inode *dir,
194 struct vfs_s_entry *ent);
195 struct stat *vfs_s_default_stat (struct vfs_class *me, mode_t mode);
197 struct vfs_s_entry *vfs_s_generate_entry (struct vfs_class *me, const char *name,
198 struct vfs_s_inode *parent,
199 mode_t mode);
200 struct vfs_s_inode *vfs_s_find_inode (struct vfs_class *me,
201 const struct vfs_s_super *super,
202 const char *path, int follow, int flags);
203 struct vfs_s_inode *vfs_s_find_root (struct vfs_class *me,
204 struct vfs_s_entry *entry);
206 /* outside interface */
207 void vfs_s_init_class (struct vfs_class *vclass,
208 struct vfs_s_subclass *sub);
209 const char *vfs_s_get_path_mangle (struct vfs_class *me, char *inname,
210 struct vfs_s_super **archive, int flags);
211 void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super);
212 char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino);
214 /* network filesystems support */
215 int vfs_s_select_on_two (int fd1, int fd2);
216 int vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len,
217 char term);
218 int vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer,
219 int size, int fd);
221 /* misc */
222 int vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino);
224 #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
226 #define MEDATA ((struct vfs_s_subclass *) me->data)
228 #define FH ((struct vfs_s_fh *) fh)
229 #define FH_SUPER FH->ino->super
231 #define LS_NOT_LINEAR 0
232 #define LS_LINEAR_CLOSED 1
233 #define LS_LINEAR_OPEN 2
234 #define LS_LINEAR_PREOPEN 3
236 #endif