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