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

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