*** empty log message ***
[midnight-commander.git] / vfs / xdirentry.h
blobe14da1c5ac6095e69dae72c721d58d3511deb18e
1 #ifndef DIRENTRY_H
2 #define DIRENTRY_H
4 /* $Id$ */
6 #include <stdio.h>
7 #include <ctype.h>
8 #include <string.h>
9 #include <stdlib.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <fcntl.h>
13 #include <unistd.h>
14 #include <signal.h>
15 #include <errno.h>
16 #include <pwd.h>
17 #include <grp.h>
19 #include "vfs.h"
22 #define LINK_FOLLOW 15
23 #define LINK_NO_FOLLOW -1
25 /* For vfs_s_find_entry */
26 #define FL_NONE 0
27 #define FL_MKDIR 1
28 #define FL_MKFILE 2
29 #define FL_DIR 4
31 /* For open_super */
32 #define FL_NO_OPEN 1
34 /* For vfs_s_entry_from_path */
35 #define FL_FOLLOW 1
36 #define FL_DIR 4
38 typedef struct vfs_s_entry {
39 struct vfs_s_entry **prevp, *next;
40 struct vfs_s_inode *dir; /* Directory we are in - needed for invalidating directory when file in it changes */
41 char *name; /* Name of this entry */
42 struct vfs_s_inode *ino; /* ... and its inode */
43 int magic;
44 #define ENTRY_MAGIC 0x014512563
45 } vfs_s_entry;
47 typedef struct vfs_s_inode {
48 struct vfs_s_entry *subdir;
49 struct vfs_s_super *super;
50 struct stat st; /* Parameters of this inode */
51 char *linkname; /* Symlink's contents */
52 char *localname; /* Filename of local file, if we have one */
53 int flags;
55 vfs_s_entry *ent; /* ftp needs this backpointer; don't use if you can avoid it */
57 union {
58 struct {
59 long data_offset;
60 } tar;
61 struct {
62 long offset;
63 } cpio;
64 struct {
65 struct timeval timestamp;
66 struct stat local_stat;
67 } fish;
68 struct {
69 struct timeval timestamp;
70 } ftp;
71 } u;
72 int magic;
73 #define INODE_MAGIC 0x93451656
74 } vfs_s_inode;
76 typedef struct vfs_s_super {
77 struct vfs_s_super **prevp, *next;
78 vfs *me;
79 vfs_s_inode *root;
80 char *name; /* My name, whatever it means */
81 int fd_usage; /* Number of open files */
82 int ino_usage; /* Usage count of this superblock */
83 int want_stale; /* If set, we do not flush cache properly */
85 union {
86 struct {
87 int fd;
88 struct stat tarstat;
89 } tar;
90 struct {
91 int sockr, sockw;
92 char *cwdir;
93 char *host, *user;
94 char *password;
95 int flags;
96 } fish;
97 struct {
98 int sock;
99 char *cwdir;
100 char *host, *user;
101 char *password;
102 int port;
104 char *proxy; /* proxy server, NULL if no proxy */
105 int failed_on_login; /* used to pass the failure reason to upper levels */
106 int use_source_route;
107 int use_passive_connection;
108 int remote_is_amiga; /* No leading slash allowed for AmiTCP (Amiga) */
109 int isbinary;
110 int cwd_defered; /* current_directory was changed but CWD command hasn't
111 been sent yet */
112 int strict; /* ftp server doesn't understand
113 "LIST -la <path>"; use "CWD <path>"/
114 "LIST" instead */
115 int control_connection_buzy;
116 #define RFC_AUTODETECT 0
117 #define RFC_DARING 1
118 #define RFC_STRICT 2
119 } ftp;
120 struct {
121 int fd;
122 struct stat stat;
123 int type; /* Type of the archive */
124 /*int pos; In case reentrancy will be needed */
125 struct defer_inode *defered; /* List of inodes for which another entries may appear */
126 } cpio;
127 } u;
128 int magic;
129 #define SUPER_MAGIC 0x915ac312
130 } vfs_s_super;
132 typedef struct vfs_s_fh {
133 struct vfs_s_inode *ino;
134 long pos; /* This is for module's use */
135 int handle; /* This is for module's use, but if != -1, will be mc_close()d */
136 int changed; /* Did this file change? */
137 int linear; /* Is that file open with O_LINEAR? */
138 union {
139 struct {
140 int got, total, append;
141 } fish;
142 struct {
143 int sock, append;
144 } ftp;
145 } u;
146 int magic;
147 #define FH_MAGIC 0x91324682
148 } vfs_s_fh;
150 struct vfs_s_data {
151 struct vfs_s_super *supers;
152 int inode_counter;
153 dev_t rdev;
154 FILE *logfile;
156 int (*init_inode) (vfs *me, vfs_s_inode *ino); /* optional */
157 void (*free_inode) (vfs *me, vfs_s_inode *ino); /* optional */
158 int (*init_entry) (vfs *me, vfs_s_entry *entry); /* optional */
160 void* (*archive_check) (vfs *me, char *name, char *op); /* optional */
161 int (*archive_same) (vfs *me, vfs_s_super *psup, char *archive_name, char *op, void *cookie);
162 int (*open_archive) (vfs *me, vfs_s_super *psup, char *archive_name, char *op);
163 void (*free_archive) (vfs *me, vfs_s_super *psup);
165 int (*fh_open) (vfs *me, vfs_s_fh *fh, int flags, int mode);
166 int (*fh_close) (vfs *me, vfs_s_fh *fh);
168 vfs_s_entry* (*find_entry) (vfs *me, vfs_s_inode *root, char *path, int follow, int flags);
169 int (*dir_load) (vfs *me, vfs_s_inode *ino, char *path);
170 int (*dir_uptodate) (vfs *me, vfs_s_inode *ino);
171 int (*file_store) (vfs *me, vfs_s_fh *fh, char *path, char *localname);
173 int (*linear_start) (vfs *me, vfs_s_fh *fh, int from);
174 int (*linear_read) (vfs *me, vfs_s_fh *fh, void *buf, int len);
175 void (*linear_close) (vfs *me, vfs_s_fh *fh);
178 /* entries and inodes */
179 vfs_s_inode *vfs_s_new_inode (vfs *me, vfs_s_super *super,
180 struct stat *initstat);
181 vfs_s_entry *vfs_s_new_entry (vfs *me, char *name, vfs_s_inode *inode);
182 void vfs_s_free_entry (vfs *me, vfs_s_entry *ent);
183 void vfs_s_insert_entry (vfs *me, vfs_s_inode *dir,
184 vfs_s_entry *ent);
185 struct stat *vfs_s_default_stat (vfs *me, mode_t mode);
187 void vfs_s_add_dots (vfs *me, vfs_s_inode *dir,
188 vfs_s_inode *parent);
189 vfs_s_entry *vfs_s_generate_entry (vfs *me, char *name,
190 struct vfs_s_inode *parent, mode_t mode);
191 vfs_s_entry *vfs_s_automake (vfs *me, vfs_s_inode *dir, char *path,
192 int flags);
193 vfs_s_entry *vfs_s_find_entry_tree (vfs *me, vfs_s_inode *root, char *path,
194 int follow, int flags);
195 vfs_s_entry *vfs_s_find_entry_linear (vfs *me, vfs_s_inode *root, char *path,
196 int follow, int flags);
197 vfs_s_inode *vfs_s_find_inode (vfs *me, vfs_s_inode *root, char *path,
198 int follow, int flags);
199 vfs_s_inode *vfs_s_find_root (vfs *me, vfs_s_entry *entry);
200 vfs_s_entry *vfs_s_resolve_symlink (vfs *me, vfs_s_entry *entry, char *path,
201 int follow);
203 /* superblock games */
204 vfs_s_super *vfs_s_new_super (vfs *me);
205 void vfs_s_free_super (vfs *me, vfs_s_super *super);
207 /* outside interface */
208 char *vfs_s_get_path_mangle (vfs *me, char *inname, vfs_s_super **archive,
209 int flags);
210 char *vfs_s_get_path (vfs *me, char *inname, vfs_s_super **archive,
211 int flags);
212 void vfs_s_invalidate (vfs *me, vfs_s_super *super);
213 char *vfs_s_fullpath (vfs *me, vfs_s_inode *ino);
215 /* readdir & friends */
216 vfs_s_super *vfs_s_super_from_path (vfs *me, char *name);
217 vfs_s_inode *vfs_s_inode_from_path (vfs *me, char *name, int flags);
218 void *vfs_s_opendir (vfs *me, char *dirname);
219 void *vfs_s_readdir (void *data);
220 int vfs_s_telldir (void *data);
221 void vfs_s_seekdir (void *data, int offset);
222 int vfs_s_closedir (void *data);
223 int vfs_s_chdir (vfs *me, char *path);
225 /* stat & friends */
226 int vfs_s_stat (vfs *me, char *path, struct stat *buf);
227 int vfs_s_lstat (vfs *me, char *path, struct stat *buf);
228 int vfs_s_fstat (void *fh, struct stat *buf);
229 int vfs_s_readlink (vfs *me, char *path, char *buf, int size);
230 void *vfs_s_open (vfs *me, char *file, int flags, int mode);
231 int vfs_s_read (void *fh, char *buffer, int count);
232 int vfs_s_write (void *fh, char *buffer, int count);
233 int vfs_s_lseek (void *fh, off_t offset, int whence);
234 int vfs_s_close (void *fh);
236 /* mc support */
237 void vfs_s_fill_names (vfs *me, void (*func)(char *));
238 int vfs_s_ferrno(vfs *me);
239 void vfs_s_dump(vfs *me, char *prefix, vfs_s_inode *ino);
240 char *vfs_s_getlocalcopy (vfs *me, char *path);
242 /* stamping support */
243 vfsid vfs_s_getid (vfs *me, char *path, struct vfs_stamping **parent);
244 int vfs_s_nothingisopen (vfsid id);
245 void vfs_s_free (vfsid id);
246 int vfs_s_setctl (vfs *me, char *path, int ctlop, char *arg);
248 /* network filesystems support */
249 int vfs_s_select_on_two (int fd1, int fd2);
250 int vfs_s_get_line (vfs *me, int sock, char *buf, int buf_len, char term);
251 int vfs_s_get_line_interruptible (vfs *me, char *buffer, int size, int fd);
253 /* misc */
254 int vfs_s_retrieve_file (vfs *me, struct vfs_s_inode *ino);
256 #if 0
257 #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
258 #else
259 #define ERRNOR(a, b) { me->verrno = a; return b; }
260 #endif
262 #define MEDATA ((struct vfs_s_data *) me->data)
264 #define FH ((struct vfs_s_fh *) fh)
265 #define FH_SUPER FH->ino->super
267 #define LS_NOT_LINEAR 0
268 #define LS_LINEAR_CLOSED 1
269 #define LS_LINEAR_OPEN 2
271 #endif