2009-02-07 15:54:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \brief Header: Virtual File System switch code
|
|
|
|
*/
|
|
|
|
|
2005-02-19 00:15:37 +03:00
|
|
|
#ifndef MC_VFS_VFS_H
|
|
|
|
#define MC_VFS_VFS_H
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-27 14:54:26 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <utime.h>
|
2009-12-29 08:08:29 +03:00
|
|
|
#include <stdio.h>
|
2009-02-27 14:54:26 +03:00
|
|
|
|
2010-07-08 14:24:58 +04:00
|
|
|
#include "lib/global.h"
|
|
|
|
|
2010-07-08 11:32:37 +04:00
|
|
|
struct vfs_class;
|
|
|
|
|
2009-12-31 05:17:48 +03:00
|
|
|
/* Flags of VFS classes */
|
2010-07-08 14:24:58 +04:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
VFSF_UNKNOWN = 0,
|
|
|
|
VFSF_LOCAL = 1 << 0, /* Class is local (not virtual) filesystem */
|
|
|
|
VFSF_NOLINKS = 1 << 1 /* Hard links not supported */
|
|
|
|
} vfs_class_flags_t;
|
2009-12-31 05:17:48 +03:00
|
|
|
|
2009-12-29 14:39:13 +03:00
|
|
|
#ifdef ENABLE_VFS
|
2009-12-29 06:51:01 +03:00
|
|
|
|
2010-07-08 11:32:37 +04:00
|
|
|
/**
|
|
|
|
* This is the type of callback function passed to vfs_fill_names.
|
|
|
|
* It gets the name of the virtual file system as its first argument.
|
|
|
|
* See also:
|
|
|
|
* vfs_fill_names().
|
|
|
|
*/
|
|
|
|
typedef void (*fill_names_f) (const char *);
|
|
|
|
|
2010-04-17 12:06:09 +04:00
|
|
|
extern int vfs_timeout;
|
|
|
|
|
|
|
|
#ifdef USE_NETCODE
|
|
|
|
extern int use_netrc;
|
|
|
|
#endif
|
|
|
|
|
2003-10-11 10:25:29 +04:00
|
|
|
void vfs_init (void);
|
|
|
|
void vfs_shut (void);
|
2010-07-08 11:32:37 +04:00
|
|
|
void vfs_expire (int now);
|
2003-10-11 10:25:29 +04:00
|
|
|
|
2010-07-08 14:24:58 +04:00
|
|
|
gboolean vfs_current_is_local (void);
|
|
|
|
gboolean vfs_file_is_local (const char *filename);
|
2010-07-18 17:46:59 +04:00
|
|
|
ssize_t mc_read (int handle, void *buffer, size_t count);
|
|
|
|
ssize_t mc_write (int handle, const void *buffer, size_t count);
|
2009-12-29 07:06:49 +03:00
|
|
|
int mc_utime (const char *path, struct utimbuf *times);
|
2010-07-18 17:46:59 +04:00
|
|
|
int mc_readlink (const char *path, char *buf, size_t bufsiz);
|
2009-12-29 07:35:34 +03:00
|
|
|
int mc_ungetlocalcopy (const char *pathname, const char *local, int has_changed);
|
2009-12-31 05:17:48 +03:00
|
|
|
int mc_close (int handle);
|
|
|
|
off_t mc_lseek (int fd, off_t offset, int whence);
|
|
|
|
DIR *mc_opendir (const char *dirname);
|
|
|
|
struct dirent *mc_readdir (DIR * dirp);
|
|
|
|
int mc_closedir (DIR * dir);
|
|
|
|
int mc_stat (const char *path, struct stat *buf);
|
2010-07-18 17:46:59 +04:00
|
|
|
int mc_mknod (const char *path, mode_t mode, dev_t dev);
|
2009-12-31 05:17:48 +03:00
|
|
|
int mc_link (const char *name1, const char *name2);
|
|
|
|
int mc_mkdir (const char *path, mode_t mode);
|
|
|
|
int mc_rmdir (const char *path);
|
|
|
|
int mc_fstat (int fd, struct stat *buf);
|
|
|
|
int mc_lstat (const char *path, struct stat *buf);
|
|
|
|
int mc_symlink (const char *name1, const char *name2);
|
|
|
|
int mc_rename (const char *original, const char *target);
|
|
|
|
int mc_chmod (const char *path, mode_t mode);
|
|
|
|
int mc_chown (const char *path, uid_t owner, gid_t group);
|
|
|
|
int mc_chdir (const char *path);
|
|
|
|
int mc_unlink (const char *path);
|
|
|
|
int mc_ctl (int fd, int ctlop, void *arg);
|
|
|
|
int mc_setctl (const char *path, int ctlop, void *arg);
|
|
|
|
int mc_open (const char *filename, int flags, ...);
|
2010-07-18 17:46:59 +04:00
|
|
|
char *mc_get_current_wd (char *buffer, size_t bufsize);
|
2009-12-31 05:17:48 +03:00
|
|
|
char *vfs_canon (const char *path);
|
|
|
|
char *mc_getlocalcopy (const char *pathname);
|
|
|
|
char *vfs_strip_suffix_from_filename (const char *filename);
|
|
|
|
char *vfs_translate_url (const char *url);
|
2009-12-29 06:53:07 +03:00
|
|
|
|
2010-07-08 14:24:58 +04:00
|
|
|
struct vfs_class *vfs_get_class (const char *path);
|
|
|
|
vfs_class_flags_t vfs_file_class_flags (const char *filename);
|
|
|
|
|
2009-12-29 08:00:18 +03:00
|
|
|
/* return encoding after last #enc: or NULL, if part does not contain #enc:
|
|
|
|
* return static buffer */
|
|
|
|
const char *vfs_get_encoding (const char *path);
|
|
|
|
|
2009-12-29 08:02:43 +03:00
|
|
|
/* return new string */
|
|
|
|
char *vfs_translate_path_n (const char *path);
|
|
|
|
|
2009-12-31 05:17:48 +03:00
|
|
|
/* canonize and translate path, return new string */
|
|
|
|
char *vfs_canon_and_translate (const char *path);
|
|
|
|
|
2010-07-08 11:32:37 +04:00
|
|
|
void vfs_stamp_path (const char *path);
|
|
|
|
|
|
|
|
void vfs_release_path (const char *dir);
|
|
|
|
|
|
|
|
void vfs_fill_names (fill_names_f);
|
|
|
|
|
2009-12-29 14:39:13 +03:00
|
|
|
#else /* ENABLE_VFS */
|
2009-12-29 06:51:01 +03:00
|
|
|
|
2009-12-31 05:17:48 +03:00
|
|
|
/* Only the routines outside of the VFS module need the emulation macros */
|
|
|
|
|
2009-12-29 06:51:01 +03:00
|
|
|
#define vfs_init() do { } while (0)
|
|
|
|
#define vfs_shut() do { } while (0)
|
2010-07-08 14:24:58 +04:00
|
|
|
#define vfs_current_is_local() (TRUE)
|
|
|
|
#define vfs_file_is_local(x) (TRUE)
|
2009-12-31 05:17:48 +03:00
|
|
|
#define vfs_strip_suffix_from_filename(x) g_strdup(x)
|
|
|
|
#define vfs_get_class(x) (struct vfs_class *)(NULL)
|
|
|
|
#define vfs_translate_url(s) g_strdup(s)
|
|
|
|
#define vfs_file_class_flags(x) (VFSF_LOCAL)
|
|
|
|
#define vfs_release_path(x)
|
|
|
|
#define vfs_timeout_handler() do { } while (0)
|
|
|
|
#define vfs_timeouts() 0
|
|
|
|
|
|
|
|
#define mc_getlocalcopy(x) vfs_canon(x)
|
2009-12-29 07:00:44 +03:00
|
|
|
#define mc_read read
|
2009-12-29 07:02:50 +03:00
|
|
|
#define mc_write write
|
2009-12-29 07:06:49 +03:00
|
|
|
#define mc_utime utime
|
2009-12-29 07:10:25 +03:00
|
|
|
#define mc_readlink readlink
|
2009-12-29 07:35:34 +03:00
|
|
|
#define mc_ungetlocalcopy(x,y,z) do { } while (0)
|
2009-12-31 05:17:48 +03:00
|
|
|
#define mc_close close
|
|
|
|
#define mc_lseek lseek
|
|
|
|
#define mc_opendir opendir
|
|
|
|
#define mc_readdir readdir
|
|
|
|
#define mc_closedir closedir
|
|
|
|
#define mc_stat stat
|
|
|
|
#define mc_mknod mknod
|
|
|
|
#define mc_link link
|
|
|
|
#define mc_mkdir mkdir
|
|
|
|
#define mc_rmdir rmdir
|
|
|
|
#define mc_fstat fstat
|
|
|
|
#define mc_lstat lstat
|
|
|
|
#define mc_symlink symlink
|
|
|
|
#define mc_rename rename
|
|
|
|
#define mc_chmod chmod
|
|
|
|
#define mc_chown chown
|
|
|
|
#define mc_chdir chdir
|
|
|
|
#define mc_unlink unlink
|
|
|
|
#define mc_open open
|
|
|
|
#define mc_get_current_wd(x,size) get_current_wd (x, size)
|
|
|
|
|
|
|
|
static inline int mc_setctl (const char *path, int ctlop, void *arg)
|
|
|
|
{
|
|
|
|
(void) path;
|
|
|
|
(void) ctlop;
|
|
|
|
(void) arg;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int mc_ctl (int fd, int ctlop, void *arg)
|
|
|
|
{
|
|
|
|
(void) fd;
|
|
|
|
(void) ctlop;
|
|
|
|
(void) arg;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-12-29 06:51:01 +03:00
|
|
|
|
2009-12-29 08:00:18 +03:00
|
|
|
static inline const char *vfs_get_encoding (const char *path)
|
|
|
|
{
|
|
|
|
(void) path;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-12-29 08:02:43 +03:00
|
|
|
/* return new string */
|
|
|
|
static inline char *vfs_translate_path_n (const char *path)
|
|
|
|
{
|
|
|
|
return ((path == NULL) ? g_strdup ("") : g_strdup (path));
|
|
|
|
}
|
|
|
|
|
2009-12-29 08:08:29 +03:00
|
|
|
static inline char* vfs_canon_and_translate(const char* path)
|
|
|
|
{
|
2009-12-29 17:11:59 +03:00
|
|
|
char *ret_str;
|
2009-12-29 08:08:29 +03:00
|
|
|
|
|
|
|
if (path == NULL)
|
2009-12-29 17:11:59 +03:00
|
|
|
return g_strdup("");
|
2009-12-29 08:08:29 +03:00
|
|
|
|
|
|
|
if (path[0] == PATH_SEP)
|
|
|
|
{
|
2009-12-29 17:11:59 +03:00
|
|
|
char *curr_dir = g_get_current_dir();
|
|
|
|
ret_str = g_strdup_printf("%s" PATH_SEP_STR "%s", curr_dir, path);
|
|
|
|
g_free(curr_dir);
|
2009-12-29 08:08:29 +03:00
|
|
|
}
|
|
|
|
else
|
2009-12-29 17:11:59 +03:00
|
|
|
ret_str = g_strdup(path);
|
2009-12-29 08:08:29 +03:00
|
|
|
|
2009-12-29 17:11:59 +03:00
|
|
|
canonicalize_pathname (ret_str);
|
|
|
|
return ret_str;
|
2009-12-29 08:08:29 +03:00
|
|
|
}
|
|
|
|
|
2009-12-31 05:17:48 +03:00
|
|
|
static inline char *
|
|
|
|
vfs_canon (const char *path)
|
|
|
|
{
|
|
|
|
char *p = g_strdup (path);
|
|
|
|
canonicalize_pathname(p);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2009-12-29 14:39:13 +03:00
|
|
|
#endif /* ENABLE_VFS */
|
2009-12-29 06:51:01 +03:00
|
|
|
|
2003-10-11 10:25:29 +04:00
|
|
|
char *vfs_get_current_dir (void);
|
2008-12-29 02:54:37 +03:00
|
|
|
/* translate path back to terminal encoding, remove all #enc:
|
|
|
|
* every invalid character is replaced with question mark
|
|
|
|
* return static buffer */
|
|
|
|
char *vfs_translate_path (const char *path);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-10-16 20:12:19 +04:00
|
|
|
/* Operations for mc_ctl - on open file */
|
|
|
|
enum {
|
|
|
|
VFS_CTL_IS_NOTREADY
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Operations for mc_setctl - on path */
|
|
|
|
enum {
|
|
|
|
VFS_SETCTL_FORGET,
|
|
|
|
VFS_SETCTL_RUN,
|
|
|
|
VFS_SETCTL_LOGFILE,
|
2003-10-16 22:51:41 +04:00
|
|
|
VFS_SETCTL_FLUSH, /* invalidate directory cache */
|
2003-10-16 20:12:19 +04:00
|
|
|
|
|
|
|
/* Setting this makes vfs layer give out potentially incorrect data,
|
|
|
|
but it also makes some operations much faster. Use with caution. */
|
|
|
|
VFS_SETCTL_STALE_DATA
|
|
|
|
};
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-09-18 15:02:04 +04:00
|
|
|
#define O_ALL (O_CREAT | O_EXCL | O_NOCTTY | O_NDELAY | O_SYNC | O_WRONLY | O_RDWR | O_RDONLY)
|
|
|
|
/* Midnight commander code should _not_ use other flags than those
|
|
|
|
listed above and O_APPEND */
|
|
|
|
|
|
|
|
#if (O_ALL & O_APPEND)
|
2001-06-14 19:26:29 +04:00
|
|
|
#warning "Unexpected problem with flags, O_LINEAR disabled, contact pavel@ucw.cz"
|
1998-09-18 15:02:04 +04:00
|
|
|
#define O_LINEAR 0
|
|
|
|
#define IS_LINEAR(a) 0
|
|
|
|
#define NO_LINEAR(a) a
|
|
|
|
#else
|
|
|
|
#define O_LINEAR O_APPEND
|
1998-10-13 02:07:53 +04:00
|
|
|
#define IS_LINEAR(a) ((a) == (O_RDONLY | O_LINEAR)) /* Return only 0 and 1 ! */
|
1998-09-18 15:02:04 +04:00
|
|
|
#define NO_LINEAR(a) (((a) == (O_RDONLY | O_LINEAR)) ? O_RDONLY : (a))
|
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-06-02 23:47:30 +04:00
|
|
|
/* O_LINEAR is strange beast, be careful. If you open file asserting
|
1998-09-21 13:52:07 +04:00
|
|
|
* O_RDONLY | O_LINEAR, you promise:
|
|
|
|
*
|
2002-01-21 14:10:57 +03:00
|
|
|
* a) to read file linearly from beginning to the end
|
1998-09-21 13:52:07 +04:00
|
|
|
* b) not to open another file before you close this one
|
|
|
|
* (this will likely go away in future)
|
1998-10-13 02:07:53 +04:00
|
|
|
* as a special gift, you may
|
|
|
|
* c) lseek() immediately after open(), giving ftpfs chance to
|
|
|
|
* reget. Be warned that this lseek() can fail, and you _have_
|
|
|
|
* to handle that gratefully.
|
1998-09-21 13:52:07 +04:00
|
|
|
*
|
|
|
|
* O_LINEAR allows filesystems not to create temporary file in some
|
|
|
|
* cases (ftp transfer). -- pavel@ucw.cz
|
|
|
|
*/
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
/* And now some defines for our errors. */
|
|
|
|
|
1998-11-29 02:56:59 +03:00
|
|
|
#ifdef ENOSYS
|
1998-11-21 22:36:01 +03:00
|
|
|
#define E_NOTSUPP ENOSYS /* for use in vfs when module does not provide function */
|
1998-11-29 02:56:59 +03:00
|
|
|
#else
|
1998-12-09 23:22:53 +03:00
|
|
|
#define E_NOTSUPP EFAULT /* Does this happen? */
|
1998-11-29 02:56:59 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENOMSG
|
1998-11-21 22:36:01 +03:00
|
|
|
#define E_UNKNOWN ENOMSG /* if we do not know what error happened */
|
1998-11-29 02:56:59 +03:00
|
|
|
#else
|
2003-10-11 10:25:29 +04:00
|
|
|
#define E_UNKNOWN EIO /* if we do not know what error happened */
|
1998-11-29 02:56:59 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EREMOTEIO
|
1998-11-21 22:36:01 +03:00
|
|
|
#define E_REMOTE EREMOTEIO /* if other side of ftp/fish reports error */
|
1998-11-29 02:56:59 +03:00
|
|
|
#else
|
1998-12-09 23:22:53 +03:00
|
|
|
#define E_REMOTE ENETUNREACH /* :-( there's no EREMOTEIO on some systems */
|
1998-11-29 02:56:59 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef EPROTO
|
1998-11-21 22:36:01 +03:00
|
|
|
#define E_PROTO EPROTO /* if other side fails to follow protocol */
|
1998-11-29 02:56:59 +03:00
|
|
|
#else
|
1998-12-09 23:22:53 +03:00
|
|
|
#define E_PROTO EIO
|
1998-11-29 02:56:59 +03:00
|
|
|
#endif
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2010-07-08 11:32:37 +04:00
|
|
|
#endif /* MC_VFS_VFS_H */
|