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