Add patch file which is attached to the ticket #16,
[midnight-commander.git] / vfs / xdirentry.h
blobc58a2f95cbc67c8eb549b0059ee2b5fb79a5d455
1 #ifndef MC_VFS_XDIRENTRY_H
2 #define MC_VFS_XDIRENTRY_H
4 #include <stdio.h>
6 #include <sys/types.h>
8 #define LINK_FOLLOW 15
9 #define LINK_NO_FOLLOW -1
11 /* For vfs_s_find_entry */
12 #define FL_NONE 0
13 #define FL_MKDIR 1
14 #define FL_MKFILE 2
15 #define FL_DIR 4
17 /* For open_super */
18 #define FL_NO_OPEN 1
20 /* For vfs_s_entry_from_path */
21 #define FL_FOLLOW 1
22 #define FL_DIR 4
24 /* For vfs_s_subclass->flags */
25 #define VFS_S_REMOTE 1
26 #define VFS_S_READONLY 2
29 /* Single connection or archive */
30 struct vfs_s_super {
31 struct vfs_s_super **prevp, *next;
32 struct vfs_class *me;
33 struct vfs_s_inode *root;
34 char *name; /* My name, whatever it means */
35 int fd_usage; /* Number of open files */
36 int ino_usage; /* Usage count of this superblock */
37 int want_stale; /* If set, we do not flush cache properly */
39 union {
40 struct {
41 int sockr, sockw;
42 char *cwdir;
43 char *host, *user;
44 char *password;
45 int flags;
46 } fish;
47 struct {
48 int sock;
49 char *cwdir;
50 char *host, *user;
51 char *password;
52 int port;
54 char *proxy; /* proxy server, NULL if no proxy */
55 int failed_on_login; /* used to pass the failure reason to upper levels */
56 int use_passive_connection;
57 int remote_is_amiga; /* No leading slash allowed for AmiTCP (Amiga) */
58 int isbinary;
59 int cwd_deferred; /* current_directory was changed but CWD command hasn't
60 been sent yet */
61 int strict; /* ftp server doesn't understand
62 "LIST -la <path>"; use "CWD <path>"/
63 "LIST" instead */
64 int ctl_connection_busy;
65 } ftp;
66 struct {
67 int fd;
68 struct stat st;
69 int type; /* Type of the archive */
70 struct defer_inode *deferred; /* List of inodes for which another entries may appear */
71 } arch;
72 } u;
76 * Single virtual file - directory entry. The same inode can have many
77 * entries (i.e. hard links), but usually has only one.
79 struct vfs_s_entry {
80 struct vfs_s_entry **prevp, *next; /* Pointers in the entry list */
81 struct vfs_s_inode *dir; /* Directory we are in, i.e. our parent */
82 char *name; /* Name of this entry */
83 struct vfs_s_inode *ino; /* ... and its inode */
86 /* Single virtual file - inode */
87 struct vfs_s_inode {
88 struct vfs_s_super *super; /* Archive the file is on */
89 struct vfs_s_entry *ent; /* Our entry in the parent directory -
90 use only for directories because they
91 cannot be hardlinked */
92 struct vfs_s_entry *subdir; /* If this is a directory, its entry */
93 struct stat st; /* Parameters of this inode */
94 char *linkname; /* Symlink's contents */
95 char *localname; /* Filename of local file, if we have one */
96 struct timeval timestamp; /* Subclass specific */
97 long data_offset; /* Subclass specific */
100 /* Data associated with an open file */
101 struct vfs_s_fh {
102 struct vfs_s_inode *ino;
103 long 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 union {
108 struct {
109 off_t got, total;
110 int append;
111 } fish;
112 struct {
113 int sock, append;
114 } ftp;
115 } u;
119 * One of our subclasses (tar, cpio, fish, ftpfs) with data and methods.
120 * Extends vfs_class. Stored in the "data" field of vfs_class.
122 struct vfs_s_subclass {
123 struct vfs_s_super *supers;
124 int inode_counter;
125 int flags; /* whether the subclass is remove, read-only etc */
126 dev_t rdev;
127 FILE *logfile;
128 int flush; /* if set to 1, invalidate directory cache */
130 int (*init_inode) (struct vfs_class *me, struct vfs_s_inode *ino); /* optional */
131 void (*free_inode) (struct vfs_class *me, struct vfs_s_inode *ino); /* optional */
132 int (*init_entry) (struct vfs_class *me, struct vfs_s_entry *entry); /* optional */
134 void *(*archive_check) (struct vfs_class *me, const char *name, char *op); /* optional */
135 int (*archive_same) (struct vfs_class *me, struct vfs_s_super *psup,
136 const char *archive_name, char *op, void *cookie);
137 int (*open_archive) (struct vfs_class *me, struct vfs_s_super *psup,
138 const char *archive_name, char *op);
139 void (*free_archive) (struct vfs_class *me,
140 struct vfs_s_super *psup);
142 int (*fh_open) (struct vfs_class *me, struct vfs_s_fh *fh, int flags,
143 int mode);
144 int (*fh_close) (struct vfs_class *me, struct vfs_s_fh *fh);
146 struct vfs_s_entry *(*find_entry) (struct vfs_class *me,
147 struct vfs_s_inode *root,
148 const char *path, int follow, int flags);
149 int (*dir_load) (struct vfs_class *me, struct vfs_s_inode *ino,
150 char *path);
151 int (*dir_uptodate) (struct vfs_class *me, struct vfs_s_inode *ino);
152 int (*file_store) (struct vfs_class *me, struct vfs_s_fh *fh,
153 char *path, char *localname);
155 int (*linear_start) (struct vfs_class *me, struct vfs_s_fh *fh,
156 off_t from);
157 int (*linear_read) (struct vfs_class *me, struct vfs_s_fh *fh,
158 void *buf, int len);
159 void (*linear_close) (struct vfs_class *me, struct vfs_s_fh *fh);
163 /* entries and inodes */
164 struct vfs_s_inode *vfs_s_new_inode (struct vfs_class *me,
165 struct vfs_s_super *super,
166 struct stat *initstat);
167 struct vfs_s_entry *vfs_s_new_entry (struct vfs_class *me, const char *name,
168 struct vfs_s_inode *inode);
169 void vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent);
170 void vfs_s_insert_entry (struct vfs_class *me, struct vfs_s_inode *dir,
171 struct vfs_s_entry *ent);
172 struct stat *vfs_s_default_stat (struct vfs_class *me, mode_t mode);
174 struct vfs_s_entry *vfs_s_generate_entry (struct vfs_class *me, const char *name,
175 struct vfs_s_inode *parent,
176 mode_t mode);
177 struct vfs_s_inode *vfs_s_find_inode (struct vfs_class *me,
178 const struct vfs_s_super *super,
179 const char *path, int follow, int flags);
180 struct vfs_s_inode *vfs_s_find_root (struct vfs_class *me,
181 struct vfs_s_entry *entry);
183 /* outside interface */
184 void vfs_s_init_class (struct vfs_class *vclass,
185 struct vfs_s_subclass *sub);
186 const char *vfs_s_get_path_mangle (struct vfs_class *me, char *inname,
187 struct vfs_s_super **archive, int flags);
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,
194 char term);
195 int vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer,
196 int size, int fd);
198 /* misc */
199 int vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino);
201 #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
203 #define MEDATA ((struct vfs_s_subclass *) me->data)
205 #define FH ((struct vfs_s_fh *) fh)
206 #define FH_SUPER FH->ino->super
208 #define LS_NOT_LINEAR 0
209 #define LS_LINEAR_CLOSED 1
210 #define LS_LINEAR_OPEN 2
211 #define LS_LINEAR_PREOPEN 3
213 #endif