root/lib/vfs/vfs.h

/* [previous][next][first][last][top][bottom][index][help]  */

INCLUDED FROM


   1 
   2 /**
   3  * \file
   4  * \brief Header: Virtual File System switch code
   5  */
   6 
   7 #ifndef MC__VFS_VFS_H
   8 #define MC__VFS_VFS_H
   9 
  10 #include <sys/types.h>
  11 #include <sys/stat.h>
  12 #include <dirent.h>             /* DIR */
  13 #ifdef HAVE_UTIMENSAT
  14 #include <sys/time.h>
  15 #elif defined (HAVE_UTIME_H)
  16 #include <utime.h>
  17 #endif
  18 #include <stdio.h>
  19 #include <unistd.h>
  20 #include <stddef.h>
  21 
  22 #include "lib/global.h"
  23 
  24 #include "path.h"
  25 
  26 /*** typedefs(not structures) and defined constants **********************************************/
  27 
  28 #define VFS_CLASS(a) ((struct vfs_class *) (a))
  29 
  30 #if defined (ENABLE_VFS_FTP) || defined (ENABLE_VFS_FISH) || defined (ENABLE_VFS_SMB)
  31 #define ENABLE_VFS_NET 1
  32 #endif
  33 
  34 /**
  35  * This is the type of callback function passed to vfs_fill_names.
  36  * It gets the name of the virtual file system as its first argument.
  37  * See also:
  38  *    vfs_fill_names().
  39  */
  40 
  41 #define VFS_ENCODING_PREFIX "#enc:"
  42 
  43 #define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
  44 /* Midnight commander code should _not_ use other flags than those
  45    listed above and O_APPEND */
  46 
  47 #if (O_ALL & O_APPEND)
  48 #warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
  49 #define O_LINEAR 0
  50 #define IS_LINEAR(a) 0
  51 #define NO_LINEAR(a) a
  52 #else
  53 #define O_LINEAR O_APPEND
  54 #define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR))     /* Return only 0 and 1 ! */
  55 #define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
  56 #endif
  57 
  58 /* O_LINEAR is strange beast, be careful. If you open file asserting
  59  * O_RDONLY | O_LINEAR, you promise:
  60  *
  61  *      a) to read file linearly from beginning to the end
  62  *      b) not to open another file before you close this one
  63  *              (this will likely go away in future)
  64  *      as a special gift, you may
  65  *      c) lseek() immediately after open(), giving ftpfs chance to
  66  *         reget. Be warned that this lseek() can fail, and you _have_
  67  *         to handle that gratefully.
  68  *
  69  * O_LINEAR allows filesystems not to create temporary file in some
  70  * cases (ftp transfer).                                -- pavel@ucw.cz
  71  */
  72 
  73 /* And now some defines for our errors. */
  74 
  75 #ifdef ENOSYS
  76 #define E_NOTSUPP ENOSYS        /* for use in vfs when module does not provide function */
  77 #else
  78 #define E_NOTSUPP EFAULT        /* Does this happen? */
  79 #endif
  80 
  81 #ifdef ENOMSG
  82 #define E_UNKNOWN ENOMSG        /* if we do not know what error happened */
  83 #else
  84 #define E_UNKNOWN EIO           /* if we do not know what error happened */
  85 #endif
  86 
  87 #ifdef EREMOTEIO
  88 #define E_REMOTE EREMOTEIO      /* if other side of ftp/fish reports error */
  89 #else
  90 #define E_REMOTE ENETUNREACH    /* :-( there's no EREMOTEIO on some systems */
  91 #endif
  92 
  93 #ifdef EPROTO
  94 #define E_PROTO EPROTO          /* if other side fails to follow protocol */
  95 #else
  96 #define E_PROTO EIO
  97 #endif
  98 
  99 typedef void (*fill_names_f) (const char *);
 100 
 101 typedef void *vfsid;
 102 
 103 #ifdef HAVE_UTIMENSAT
 104 typedef struct timespec mc_timesbuf_t[2];
 105 #else
 106 typedef struct utimbuf mc_timesbuf_t;
 107 #endif
 108 
 109 /*** enums ***************************************************************************************/
 110 
 111 typedef enum
 112 {
 113     VFSF_UNKNOWN = 0,
 114     VFSF_LOCAL = 1 << 0,        /* Class is local (not virtual) filesystem */
 115     VFSF_NOLINKS = 1 << 1,      /* Hard links not supported */
 116 
 117     VFSF_REMOTE = 1 << 2,
 118     VFSF_READONLY = 1 << 3,
 119     VFSF_USETMP = 1 << 4
 120 } vfs_flags_t;
 121 
 122 /* Operations for mc_ctl - on open file */
 123 enum
 124 {
 125     VFS_CTL_IS_NOTREADY
 126 };
 127 
 128 /* Operations for mc_setctl - on path */
 129 enum
 130 {
 131     VFS_SETCTL_FORGET,
 132     VFS_SETCTL_RUN,
 133     VFS_SETCTL_LOGFILE,
 134     VFS_SETCTL_FLUSH,           /* invalidate directory cache */
 135 
 136     /* Setting this makes vfs layer give out potentially incorrect data,
 137        but it also makes some operations much faster. Use with caution. */
 138     VFS_SETCTL_STALE_DATA
 139 };
 140 
 141 /*** structures declarations (and typedefs of structures)*****************************************/
 142 
 143 typedef struct vfs_class
 144 {
 145     const char *name;           /* "FIles over SHell" */
 146     vfs_flags_t flags;
 147     const char *prefix;         /* "fish:" */
 148     int verrno;                 /* can't use errno because glibc2 might define errno as function */
 149     gboolean flush;             /* if set to TRUE, invalidate directory cache */
 150     FILE *logfile;
 151 
 152     /* *INDENT-OFF* */
 153     int (*init) (struct vfs_class * me);
 154     void (*done) (struct vfs_class * me);
 155 
 156     /**
 157      * The fill_names method shall call the callback function for every
 158      * filesystem name that this vfs module supports.
 159      */
 160     void (*fill_names) (struct vfs_class * me, fill_names_f);
 161 
 162     /**
 163      * The which() method shall return the index of the vfs subsystem
 164      * or -1 if this vfs cannot handle the given pathname.
 165      */
 166     int (*which) (struct vfs_class * me, const char *path);
 167 
 168     void *(*open) (const vfs_path_t * vpath, int flags, mode_t mode);
 169     int (*close) (void *vfs_info);
 170     ssize_t (*read) (void *vfs_info, char *buffer, size_t count);
 171     ssize_t (*write) (void *vfs_info, const char *buf, size_t count);
 172 
 173     void *(*opendir) (const vfs_path_t * vpath);
 174     struct vfs_dirent *(*readdir) (void *vfs_info);
 175     int (*closedir) (void *vfs_info);
 176 
 177     int (*stat) (const vfs_path_t * vpath, struct stat * buf);
 178     int (*lstat) (const vfs_path_t * vpath, struct stat * buf);
 179     int (*fstat) (void *vfs_info, struct stat * buf);
 180 
 181     int (*chmod) (const vfs_path_t * vpath, mode_t mode);
 182     int (*chown) (const vfs_path_t * vpath, uid_t owner, gid_t group);
 183     int (*utime) (const vfs_path_t * vpath, mc_timesbuf_t * times);
 184 
 185     int (*readlink) (const vfs_path_t * vpath, char *buf, size_t size);
 186     int (*symlink) (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
 187     int (*link) (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
 188     int (*unlink) (const vfs_path_t * vpath);
 189     int (*rename) (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
 190     int (*chdir) (const vfs_path_t * vpath);
 191     int (*ferrno) (struct vfs_class * me);
 192     off_t (*lseek) (void *vfs_info, off_t offset, int whence);
 193     int (*mknod) (const vfs_path_t * vpath, mode_t mode, dev_t dev);
 194 
 195     vfsid (*getid) (const vfs_path_t * vpath);
 196 
 197     gboolean (*nothingisopen) (vfsid id);
 198     void (*free) (vfsid id);
 199 
 200     vfs_path_t *(*getlocalcopy) (const vfs_path_t * vpath);
 201     int (*ungetlocalcopy) (const vfs_path_t * vpath, const vfs_path_t * local_vpath,
 202                            gboolean has_changed);
 203 
 204     int (*mkdir) (const vfs_path_t * vpath, mode_t mode);
 205     int (*rmdir) (const vfs_path_t * vpath);
 206 
 207     int (*ctl) (void *vfs_info, int ctlop, void *arg);
 208     int (*setctl) (const vfs_path_t * vpath, int ctlop, void *arg);
 209     /* *INDENT-ON* */
 210 } vfs_class;
 211 
 212 /*
 213  * This struct is used instead of standard dirent to hold file name of any length
 214  * (not limited to NAME_MAX).
 215  */
 216 struct vfs_dirent
 217 {
 218     /* private */
 219     GString *d_name_str;
 220 
 221     /* public */
 222     ino_t d_ino;
 223     char *d_name;               /* Alias of d_name_str->str */
 224 };
 225 
 226 /*** global variables defined in .c file *********************************************************/
 227 
 228 extern int vfs_timeout;
 229 
 230 #ifdef ENABLE_VFS_NET
 231 extern int use_netrc;
 232 #endif
 233 
 234 /*** declarations of public functions ************************************************************/
 235 
 236 /* lib/vfs/direntry.c: */
 237 void vfs_init_class (struct vfs_class *vclass, const char *name, vfs_flags_t flags,
 238                      const char *prefix);
 239 
 240 void *vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode);
 241 int vfs_s_stat (const vfs_path_t * vpath, struct stat *buf);
 242 int vfs_s_lstat (const vfs_path_t * vpath, struct stat *buf);
 243 int vfs_s_fstat (void *fh, struct stat *buf);
 244 
 245 void vfs_adjust_stat (struct stat *s);
 246 
 247 vfsid vfs_getid (const vfs_path_t * vpath);
 248 
 249 void vfs_init (void);
 250 void vfs_shut (void);
 251 /* Register a file system class */
 252 gboolean vfs_register_class (struct vfs_class *vfs);
 253 void vfs_unregister_class (struct vfs_class *vfs);
 254 
 255 void vfs_setup_work_dir (void);
 256 
 257 void vfs_timeout_handler (void);
 258 int vfs_timeouts (void);
 259 void vfs_expire (gboolean now);
 260 
 261 const char *vfs_get_current_dir (void);
 262 char *vfs_get_current_dir_n (void);
 263 const vfs_path_t *vfs_get_raw_current_dir (void);
 264 void vfs_set_raw_current_dir (const vfs_path_t * vpath);
 265 
 266 gboolean vfs_current_is_local (void);
 267 gboolean vfs_file_is_local (const vfs_path_t * vpath);
 268 
 269 char *vfs_strip_suffix_from_filename (const char *filename);
 270 
 271 vfs_flags_t vfs_file_class_flags (const vfs_path_t * vpath);
 272 
 273 /* translate path back to terminal encoding, remove all #enc:
 274  * every invalid character is replaced with question mark
 275  * return static buffer */
 276 const char *vfs_translate_path (const char *path);
 277 /* return new string */
 278 char *vfs_translate_path_n (const char *path);
 279 
 280 void vfs_stamp_path (const vfs_path_t * path);
 281 
 282 void vfs_release_path (const vfs_path_t * vpath);
 283 
 284 struct vfs_dirent *vfs_dirent_init (struct vfs_dirent *d, const char *fname, ino_t ino);
 285 void vfs_dirent_assign (struct vfs_dirent *d, const char *fname, ino_t ino);
 286 void vfs_dirent_free (struct vfs_dirent *d);
 287 
 288 void vfs_fill_names (fill_names_f);
 289 
 290 /* *INDENT-OFF* */
 291 void vfs_print_message (const char *msg, ...) G_GNUC_PRINTF (1, 2);
 292 /* *INDENT-ON* */
 293 
 294 int vfs_ferrno (struct vfs_class *vfs);
 295 
 296 int vfs_new_handle (struct vfs_class *vclass, void *fsinfo);
 297 
 298 struct vfs_class *vfs_class_find_by_handle (int handle, void **fsinfo);
 299 
 300 void vfs_free_handle (int handle);
 301 
 302 void vfs_setup_cwd (void);
 303 char *_vfs_get_cwd (void);
 304 
 305 int vfs_preallocate (int dest_desc, off_t src_fsize, off_t dest_fsize);
 306 
 307 int vfs_clone_file (int dest_vfs_fd, int src_vfs_fd);
 308 
 309 /**
 310  * Interface functions described in interface.c
 311  */
 312 ssize_t mc_read (int handle, void *buffer, size_t count);
 313 ssize_t mc_write (int handle, const void *buffer, size_t count);
 314 int mc_utime (const vfs_path_t * vpath, mc_timesbuf_t * times);
 315 int mc_readlink (const vfs_path_t * vpath, char *buf, size_t bufsiz);
 316 int mc_close (int handle);
 317 off_t mc_lseek (int fd, off_t offset, int whence);
 318 DIR *mc_opendir (const vfs_path_t * vpath);
 319 struct vfs_dirent *mc_readdir (DIR * dirp);
 320 int mc_closedir (DIR * dir);
 321 int mc_stat (const vfs_path_t * vpath, struct stat *buf);
 322 int mc_mknod (const vfs_path_t * vpath, mode_t mode, dev_t dev);
 323 int mc_link (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
 324 int mc_mkdir (const vfs_path_t * vpath, mode_t mode);
 325 int mc_rmdir (const vfs_path_t * vpath);
 326 int mc_fstat (int fd, struct stat *buf);
 327 int mc_lstat (const vfs_path_t * vpath, struct stat *buf);
 328 int mc_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
 329 int mc_rename (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
 330 int mc_chmod (const vfs_path_t * vpath, mode_t mode);
 331 int mc_chown (const vfs_path_t * vpath, uid_t owner, gid_t group);
 332 int mc_chdir (const vfs_path_t * vpath);
 333 int mc_unlink (const vfs_path_t * vpath);
 334 int mc_ctl (int fd, int ctlop, void *arg);
 335 int mc_setctl (const vfs_path_t * vpath, int ctlop, void *arg);
 336 int mc_open (const vfs_path_t * vpath, int flags, ...);
 337 vfs_path_t *mc_getlocalcopy (const vfs_path_t * pathname_vpath);
 338 int mc_ungetlocalcopy (const vfs_path_t * pathname_vpath, const vfs_path_t * local_vpath,
 339                        gboolean has_changed);
 340 int mc_mkstemps (vfs_path_t ** pname_vpath, const char *prefix, const char *suffix);
 341 
 342 /* Creating temporary files safely */
 343 const char *mc_tmpdir (void);
 344 
 345 
 346 /*** inline functions ****************************************************************************/
 347 
 348 #endif /* MC_VFS_VFS_H */

/* [previous][next][first][last][top][bottom][index][help]  */