2009-02-07 15:54:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \brief Header: Virtual File System directory structure
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
#ifndef MC__VFS_XDIRENTRY_H
|
|
|
|
#define MC__VFS_XDIRENTRY_H
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2005-07-04 02:55:55 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2011-03-28 15:18:21 +04:00
|
|
|
#include "lib/global.h" /* GList */
|
2011-04-28 15:39:59 +04:00
|
|
|
#include "lib/vfs/path.h" /* vfs_path_t */
|
2011-03-28 15:18:21 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** typedefs(not structures) and defined constants **********************************************/
|
|
|
|
|
1998-12-02 16:17:24 +03:00
|
|
|
#define LINK_FOLLOW 15
|
|
|
|
#define LINK_NO_FOLLOW -1
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2018-07-22 17:20:27 +03:00
|
|
|
/* For vfs_s_find_entry and vfs_s_find_inode */
|
1998-10-23 12:26:25 +04:00
|
|
|
#define FL_NONE 0
|
|
|
|
#define FL_MKDIR 1
|
|
|
|
#define FL_MKFILE 2
|
1998-11-21 22:36:01 +03:00
|
|
|
#define FL_DIR 4
|
1998-10-23 12:26:25 +04:00
|
|
|
|
|
|
|
/* For open_super */
|
|
|
|
#define FL_NO_OPEN 1
|
|
|
|
|
|
|
|
/* For vfs_s_entry_from_path */
|
|
|
|
#define FL_FOLLOW 1
|
1998-11-21 22:36:01 +03:00
|
|
|
#define FL_DIR 4
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
#define ERRNOR(a, b) do { me->verrno = a; return b; } while (0)
|
|
|
|
|
2018-09-12 14:01:28 +03:00
|
|
|
#define VFS_SUBCLASS(a) ((struct vfs_s_subclass *) (a))
|
2011-04-18 18:08:55 +04:00
|
|
|
|
2016-08-17 13:54:08 +03:00
|
|
|
#define VFS_SUPER(a) ((struct vfs_s_super *) (a))
|
2018-03-02 15:02:55 +03:00
|
|
|
#define VFS_ENTRY(a) ((struct vfs_s_entry *) (a))
|
|
|
|
#define VFS_INODE(a) ((struct vfs_s_inode *) (a))
|
2016-08-17 13:54:08 +03:00
|
|
|
|
2018-09-12 14:01:28 +03:00
|
|
|
#define VFS_FILE_HANDLER(a) ((vfs_file_handler_t *) a)
|
|
|
|
#define VFS_FILE_HANDLER_SUPER(a) VFS_FILE_HANDLER (a)->ino->super
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
/*** enums ***************************************************************************************/
|
|
|
|
|
2018-01-08 13:06:32 +03:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
LS_NOT_LINEAR = 0,
|
|
|
|
LS_LINEAR_CLOSED = 1,
|
|
|
|
LS_LINEAR_OPEN = 2,
|
|
|
|
LS_LINEAR_PREOPEN = 3
|
|
|
|
} vfs_linear_state_t;
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** structures declarations (and typedefs of structures)*****************************************/
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2003-10-16 10:50:05 +04:00
|
|
|
/* Single connection or archive */
|
2010-07-05 20:49:01 +04:00
|
|
|
struct vfs_s_super
|
|
|
|
{
|
2003-10-12 04:24:00 +04:00
|
|
|
struct vfs_class *me;
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_inode *root;
|
2010-07-05 20:49:01 +04:00
|
|
|
char *name; /* My name, whatever it means */
|
|
|
|
int fd_usage; /* Number of open files */
|
|
|
|
int ino_usage; /* Usage count of this superblock */
|
2018-01-08 11:23:10 +03:00
|
|
|
gboolean want_stale; /* If set, we do not flush cache properly */
|
2011-03-29 11:20:34 +04:00
|
|
|
#ifdef ENABLE_VFS_NET
|
2011-06-07 14:18:08 +04:00
|
|
|
vfs_path_element_t *path_element;
|
2011-03-29 11:20:34 +04:00
|
|
|
#endif /* ENABLE_VFS_NET */
|
2003-10-12 05:00:44 +04:00
|
|
|
};
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2003-10-16 12:00:05 +04:00
|
|
|
/*
|
|
|
|
* Single virtual file - directory entry. The same inode can have many
|
|
|
|
* entries (i.e. hard links), but usually has only one.
|
|
|
|
*/
|
2010-07-05 20:49:01 +04:00
|
|
|
struct vfs_s_entry
|
|
|
|
{
|
|
|
|
struct vfs_s_inode *dir; /* Directory we are in, i.e. our parent */
|
|
|
|
char *name; /* Name of this entry */
|
|
|
|
struct vfs_s_inode *ino; /* ... and its inode */
|
2003-10-16 12:00:05 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Single virtual file - inode */
|
2010-07-05 20:49:01 +04:00
|
|
|
struct vfs_s_inode
|
|
|
|
{
|
|
|
|
struct vfs_s_super *super; /* Archive the file is on */
|
|
|
|
struct vfs_s_entry *ent; /* Our entry in the parent directory -
|
|
|
|
use only for directories because they
|
|
|
|
cannot be hardlinked */
|
2015-01-16 10:56:08 +03:00
|
|
|
GQueue *subdir; /* If this is a directory, its entry. List of vfs_s_entry */
|
2010-07-05 20:49:01 +04:00
|
|
|
struct stat st; /* Parameters of this inode */
|
|
|
|
char *linkname; /* Symlink's contents */
|
|
|
|
char *localname; /* Filename of local file, if we have one */
|
2020-03-07 12:31:46 +03:00
|
|
|
guint64 timestamp; /* Subclass specific */
|
2010-07-21 21:35:10 +04:00
|
|
|
off_t data_offset; /* Subclass specific */
|
2003-10-16 12:00:05 +04:00
|
|
|
};
|
|
|
|
|
2003-10-16 10:50:05 +04:00
|
|
|
/* Data associated with an open file */
|
2011-02-09 14:34:13 +03:00
|
|
|
typedef struct
|
2010-07-05 20:49:01 +04:00
|
|
|
{
|
1998-10-23 12:26:25 +04:00
|
|
|
struct vfs_s_inode *ino;
|
2010-07-21 21:35:10 +04:00
|
|
|
off_t pos; /* This is for module's use */
|
2010-07-05 20:49:01 +04:00
|
|
|
int handle; /* This is for module's use, but if != -1, will be mc_close()d */
|
2018-01-08 11:27:09 +03:00
|
|
|
gboolean changed; /* Did this file change? */
|
2018-01-08 13:06:32 +03:00
|
|
|
vfs_linear_state_t linear; /* Is that file open with O_LINEAR? */
|
2011-02-09 14:34:13 +03:00
|
|
|
} vfs_file_handler_t;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2003-10-16 10:50:05 +04:00
|
|
|
/*
|
|
|
|
* One of our subclasses (tar, cpio, fish, ftpfs) with data and methods.
|
2016-08-17 11:27:57 +03:00
|
|
|
* Extends vfs_class.
|
2003-10-16 10:50:05 +04:00
|
|
|
*/
|
2010-07-05 20:49:01 +04:00
|
|
|
struct vfs_s_subclass
|
|
|
|
{
|
2016-08-17 11:27:57 +03:00
|
|
|
struct vfs_class base; /* base class */
|
|
|
|
|
2011-03-28 15:18:21 +04:00
|
|
|
GList *supers;
|
1998-10-23 12:26:25 +04:00
|
|
|
int inode_counter;
|
|
|
|
dev_t rdev;
|
2010-07-05 20:49:01 +04:00
|
|
|
|
2012-12-20 16:18:32 +04:00
|
|
|
/* *INDENT-OFF* */
|
2010-07-05 20:49:01 +04:00
|
|
|
int (*init_inode) (struct vfs_class * me, struct vfs_s_inode * ino); /* optional */
|
|
|
|
void (*free_inode) (struct vfs_class * me, struct vfs_s_inode * ino); /* optional */
|
|
|
|
int (*init_entry) (struct vfs_class * me, struct vfs_s_entry * entry); /* optional */
|
|
|
|
|
2011-06-13 15:44:25 +04:00
|
|
|
void *(*archive_check) (const vfs_path_t * vpath); /* optional */
|
|
|
|
int (*archive_same) (const vfs_path_element_t * vpath_element, struct vfs_s_super * psup,
|
|
|
|
const vfs_path_t * vpath, void *cookie);
|
2016-08-17 13:54:08 +03:00
|
|
|
struct vfs_s_super *(*new_archive) (struct vfs_class * me);
|
2011-06-13 15:44:25 +04:00
|
|
|
int (*open_archive) (struct vfs_s_super * psup,
|
|
|
|
const vfs_path_t * vpath, const vfs_path_element_t * vpath_element);
|
2010-07-05 20:49:01 +04:00
|
|
|
void (*free_archive) (struct vfs_class * me, struct vfs_s_super * psup);
|
|
|
|
|
2016-08-17 14:34:37 +03:00
|
|
|
vfs_file_handler_t *(*fh_new) (struct vfs_s_inode * ino, gboolean changed);
|
2011-02-09 14:34:13 +03:00
|
|
|
int (*fh_open) (struct vfs_class * me, vfs_file_handler_t * fh, int flags, mode_t mode);
|
|
|
|
int (*fh_close) (struct vfs_class * me, vfs_file_handler_t * fh);
|
2016-08-17 14:34:37 +03:00
|
|
|
void (*fh_free) (vfs_file_handler_t * fh);
|
2010-07-05 20:49:01 +04:00
|
|
|
|
|
|
|
struct vfs_s_entry *(*find_entry) (struct vfs_class * me,
|
|
|
|
struct vfs_s_inode * root,
|
|
|
|
const char *path, int follow, int flags);
|
|
|
|
int (*dir_load) (struct vfs_class * me, struct vfs_s_inode * ino, char *path);
|
|
|
|
int (*dir_uptodate) (struct vfs_class * me, struct vfs_s_inode * ino);
|
2011-02-09 14:34:13 +03:00
|
|
|
int (*file_store) (struct vfs_class * me, vfs_file_handler_t * fh, char *path, char *localname);
|
2010-07-05 20:49:01 +04:00
|
|
|
|
2011-02-09 14:34:13 +03:00
|
|
|
int (*linear_start) (struct vfs_class * me, vfs_file_handler_t * fh, off_t from);
|
2012-11-18 14:31:04 +04:00
|
|
|
ssize_t (*linear_read) (struct vfs_class * me, vfs_file_handler_t * fh, void *buf, size_t len);
|
2011-02-09 14:34:13 +03:00
|
|
|
void (*linear_close) (struct vfs_class * me, vfs_file_handler_t * fh);
|
2012-12-20 16:18:32 +04:00
|
|
|
/* *INDENT-ON* */
|
1998-10-23 12:26:25 +04:00
|
|
|
};
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** global variables defined in .c file *********************************************************/
|
|
|
|
|
|
|
|
/*** declarations of public functions ************************************************************/
|
2003-10-16 12:00:05 +04:00
|
|
|
|
1998-10-23 12:26:25 +04:00
|
|
|
/* entries and inodes */
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_inode *vfs_s_new_inode (struct vfs_class *me,
|
2010-07-05 20:49:01 +04:00
|
|
|
struct vfs_s_super *super, struct stat *initstat);
|
2011-07-20 01:36:05 +04:00
|
|
|
void vfs_s_free_inode (struct vfs_class *me, struct vfs_s_inode *ino);
|
|
|
|
|
2004-09-22 15:28:14 +04:00
|
|
|
struct vfs_s_entry *vfs_s_new_entry (struct vfs_class *me, const char *name,
|
2010-07-05 20:49:01 +04:00
|
|
|
struct vfs_s_inode *inode);
|
2003-10-12 05:00:44 +04:00
|
|
|
void vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent);
|
2010-07-05 20:49:01 +04:00
|
|
|
void vfs_s_insert_entry (struct vfs_class *me, struct vfs_s_inode *dir, struct vfs_s_entry *ent);
|
2018-03-02 15:02:55 +03:00
|
|
|
int vfs_s_entry_compare (const void *a, const void *b);
|
2003-10-12 05:00:44 +04:00
|
|
|
struct stat *vfs_s_default_stat (struct vfs_class *me, mode_t mode);
|
|
|
|
|
2004-09-22 15:28:14 +04:00
|
|
|
struct vfs_s_entry *vfs_s_generate_entry (struct vfs_class *me, const char *name,
|
2010-07-05 20:49:01 +04:00
|
|
|
struct vfs_s_inode *parent, mode_t mode);
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_inode *vfs_s_find_inode (struct vfs_class *me,
|
2010-07-05 20:49:01 +04:00
|
|
|
const struct vfs_s_super *super,
|
|
|
|
const char *path, int follow, int flags);
|
|
|
|
struct vfs_s_inode *vfs_s_find_root (struct vfs_class *me, struct vfs_s_entry *entry);
|
1999-01-11 03:48:23 +03:00
|
|
|
|
1998-10-23 12:26:25 +04:00
|
|
|
/* outside interface */
|
2018-09-14 13:24:17 +03:00
|
|
|
void vfs_init_subclass (struct vfs_s_subclass *sub, const char *name, vfs_flags_t flags,
|
|
|
|
const char *prefix);
|
2011-06-24 22:09:12 +04:00
|
|
|
const char *vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flags);
|
2012-07-06 14:56:29 +04:00
|
|
|
struct vfs_s_super *vfs_get_super_by_vpath (const vfs_path_t * vpath);
|
2011-04-28 15:39:59 +04:00
|
|
|
|
2003-10-12 05:00:44 +04:00
|
|
|
void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super);
|
|
|
|
char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino);
|
1999-01-11 03:48:23 +03:00
|
|
|
|
2016-08-17 14:34:37 +03:00
|
|
|
void vfs_s_init_fh (vfs_file_handler_t * fh, struct vfs_s_inode *ino, gboolean changed);
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
/* network filesystems support */
|
|
|
|
int vfs_s_select_on_two (int fd1, int fd2);
|
2010-07-05 20:49:01 +04:00
|
|
|
int vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char term);
|
|
|
|
int vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer, int size, int fd);
|
2000-02-02 19:59:19 +03:00
|
|
|
/* misc */
|
2003-10-12 04:24:00 +04:00
|
|
|
int vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino);
|
2000-02-02 19:59:19 +03:00
|
|
|
|
2011-08-27 21:22:41 +04:00
|
|
|
void vfs_s_normalize_filename_leading_spaces (struct vfs_s_inode *root_inode, size_t final_filepos);
|
2011-06-24 22:09:12 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** inline functions ****************************************************************************/
|
2011-06-24 22:09:12 +04:00
|
|
|
|
|
|
|
static inline void
|
2011-08-27 21:22:41 +04:00
|
|
|
vfs_s_store_filename_leading_spaces (struct vfs_s_entry *entry, size_t position)
|
2011-06-24 22:09:12 +04:00
|
|
|
{
|
|
|
|
entry->ino->data_offset = (off_t) position;
|
|
|
|
}
|
|
|
|
|
1998-10-23 12:26:25 +04:00
|
|
|
#endif
|