Security fix patch. Fix insecure temporary file and directory creations. (CAN-2004...
[midnight-commander.git] / vfs / xdirentry.h
blob152c76c06f562b985cc2d4669d66305f888df112
1 #ifndef DIRENTRY_H
2 #define DIRENTRY_H
4 #define LINK_FOLLOW 15
5 #define LINK_NO_FOLLOW -1
7 /* For vfs_s_find_entry */
8 #define FL_NONE 0
9 #define FL_MKDIR 1
10 #define FL_MKFILE 2
11 #define FL_DIR 4
13 /* For open_super */
14 #define FL_NO_OPEN 1
16 /* For vfs_s_entry_from_path */
17 #define FL_FOLLOW 1
18 #define FL_DIR 4
20 /* For vfs_s_subclass->flags */
21 #define VFS_S_REMOTE 1
22 #define VFS_S_READONLY 2
25 /* Single connection or archive */
26 struct vfs_s_super {
27 struct vfs_s_super **prevp, *next;
28 struct vfs_class *me;
29 struct vfs_s_inode *root;
30 char *name; /* My name, whatever it means */
31 int fd_usage; /* Number of open files */
32 int ino_usage; /* Usage count of this superblock */
33 int want_stale; /* If set, we do not flush cache properly */
35 union {
36 struct {
37 int sockr, sockw;
38 char *cwdir;
39 char *host, *user;
40 char *password;
41 int flags;
42 } fish;
43 struct {
44 int sock;
45 char *cwdir;
46 char *host, *user;
47 char *password;
48 int port;
50 char *proxy; /* proxy server, NULL if no proxy */
51 int failed_on_login; /* used to pass the failure reason to upper levels */
52 int use_passive_connection;
53 int remote_is_amiga; /* No leading slash allowed for AmiTCP (Amiga) */
54 int isbinary;
55 int cwd_deferred; /* current_directory was changed but CWD command hasn't
56 been sent yet */
57 int strict; /* ftp server doesn't understand
58 "LIST -la <path>"; use "CWD <path>"/
59 "LIST" instead */
60 int ctl_connection_busy;
61 } ftp;
62 struct {
63 int fd;
64 struct stat st;
65 int type; /* Type of the archive */
66 struct defer_inode *deferred; /* List of inodes for which another entries may appear */
67 } arch;
68 } u;
72 * Single virtual file - directory entry. The same inode can have many
73 * entries (i.e. hard links), but usually has only one.
75 struct vfs_s_entry {
76 struct vfs_s_entry **prevp, *next; /* Pointers in the entry list */
77 struct vfs_s_inode *dir; /* Directory we are in, i.e. our parent */
78 char *name; /* Name of this entry */
79 struct vfs_s_inode *ino; /* ... and its inode */
82 /* Single virtual file - inode */
83 struct vfs_s_inode {
84 struct vfs_s_super *super; /* Archive the file is on */
85 struct vfs_s_entry *ent; /* Our entry in the parent directory -
86 use only for directories because they
87 cannot be hardlinked */
88 struct vfs_s_entry *subdir; /* If this is a directory, its entry */
89 struct stat st; /* Parameters of this inode */
90 char *linkname; /* Symlink's contents */
91 char *localname; /* Filename of local file, if we have one */
92 struct timeval timestamp; /* Subclass specific */
93 long data_offset; /* Subclass specific */
96 /* Data associated with an open file */
97 struct vfs_s_fh {
98 struct vfs_s_inode *ino;
99 long pos; /* This is for module's use */
100 int handle; /* This is for module's use, but if != -1, will be mc_close()d */
101 int changed; /* Did this file change? */
102 int linear; /* Is that file open with O_LINEAR? */
103 union {
104 struct {
105 int got, total, append;
106 } fish;
107 struct {
108 int sock, append;
109 } ftp;
110 } u;
114 * One of our subclasses (tar, cpio, fish, ftpfs) with data and methods.
115 * Extends vfs_class. Stored in the "data" field of vfs_class.
117 struct vfs_s_subclass {
118 struct vfs_s_super *supers;
119 int inode_counter;
120 int flags; /* whether the subclass is remove, read-only etc */
121 dev_t rdev;
122 FILE *logfile;
123 int flush; /* if set to 1, invalidate directory cache */
125 int (*init_inode) (struct vfs_class *me, struct vfs_s_inode *ino); /* optional */
126 void (*free_inode) (struct vfs_class *me, struct vfs_s_inode *ino); /* optional */
127 int (*init_entry) (struct vfs_class *me, struct vfs_s_entry *entry); /* optional */
129 void *(*archive_check) (struct vfs_class *me, const char *name, char *op); /* optional */
130 int (*archive_same) (struct vfs_class *me, struct vfs_s_super *psup,
131 const char *archive_name, char *op, void *cookie);
132 int (*open_archive) (struct vfs_class *me, struct vfs_s_super *psup,
133 const char *archive_name, char *op);
134 void (*free_archive) (struct vfs_class *me,
135 struct vfs_s_super *psup);
137 int (*fh_open) (struct vfs_class *me, struct vfs_s_fh *fh, int flags,
138 int mode);
139 int (*fh_close) (struct vfs_class *me, struct vfs_s_fh *fh);
141 struct vfs_s_entry *(*find_entry) (struct vfs_class *me,
142 struct vfs_s_inode *root,
143 char *path, int follow, int flags);
144 int (*dir_load) (struct vfs_class *me, struct vfs_s_inode *ino,
145 char *path);
146 int (*dir_uptodate) (struct vfs_class *me, struct vfs_s_inode *ino);
147 int (*file_store) (struct vfs_class *me, struct vfs_s_fh *fh,
148 char *path, char *localname);
150 int (*linear_start) (struct vfs_class *me, struct vfs_s_fh *fh,
151 int from);
152 int (*linear_read) (struct vfs_class *me, struct vfs_s_fh *fh,
153 void *buf, int len);
154 void (*linear_close) (struct vfs_class *me, struct vfs_s_fh *fh);
158 /* entries and inodes */
159 struct vfs_s_inode *vfs_s_new_inode (struct vfs_class *me,
160 struct vfs_s_super *super,
161 struct stat *initstat);
162 struct vfs_s_entry *vfs_s_new_entry (struct vfs_class *me, char *name,
163 struct vfs_s_inode *inode);
164 void vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent);
165 void vfs_s_insert_entry (struct vfs_class *me, struct vfs_s_inode *dir,
166 struct vfs_s_entry *ent);
167 struct stat *vfs_s_default_stat (struct vfs_class *me, mode_t mode);
169 struct vfs_s_entry *vfs_s_generate_entry (struct vfs_class *me, char *name,
170 struct vfs_s_inode *parent,
171 mode_t mode);
172 struct vfs_s_inode *vfs_s_find_inode (struct vfs_class *me,
173 const struct vfs_s_super *super,
174 char *path, int follow, int flags);
175 struct vfs_s_inode *vfs_s_find_root (struct vfs_class *me,
176 struct vfs_s_entry *entry);
178 /* outside interface */
179 void vfs_s_init_class (struct vfs_class *vclass,
180 struct vfs_s_subclass *sub);
181 char *vfs_s_get_path_mangle (struct vfs_class *me, char *inname,
182 struct vfs_s_super **archive, int flags);
183 void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super);
184 char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino);
186 /* network filesystems support */
187 int vfs_s_select_on_two (int fd1, int fd2);
188 int vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len,
189 char term);
190 int vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer,
191 int size, int fd);
193 /* misc */
194 int vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino);
196 #define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
198 #define MEDATA ((struct vfs_s_subclass *) me->data)
200 #define FH ((struct vfs_s_fh *) fh)
201 #define FH_SUPER FH->ino->super
203 #define LS_NOT_LINEAR 0
204 #define LS_LINEAR_CLOSED 1
205 #define LS_LINEAR_OPEN 2
207 #endif