root/lib/vfs/xdirentry.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. vfs_s_store_filename_leading_spaces

   1 
   2 /**
   3  * \file
   4  * \brief Header: Virtual File System directory structure
   5  */
   6 
   7 #ifndef MC__VFS_XDIRENTRY_H
   8 #define MC__VFS_XDIRENTRY_H
   9 
  10 #include <stdio.h>
  11 #include <sys/types.h>
  12 
  13 #include "lib/global.h"    // GList
  14 #include "lib/vfs/path.h"  // vfs_path_t
  15 
  16 /*** typedefs(not structures) and defined constants **********************************************/
  17 
  18 #define LINK_FOLLOW    15
  19 #define LINK_NO_FOLLOW -1
  20 
  21 /* For vfs_s_find_entry and vfs_s_find_inode */
  22 #define FL_NONE   0
  23 #define FL_MKDIR  1
  24 #define FL_MKFILE 2
  25 #define FL_DIR    4
  26 
  27 /* For open_super */
  28 #define FL_NO_OPEN 1
  29 
  30 /* For vfs_s_entry_from_path */
  31 #define FL_FOLLOW 1
  32 #define FL_DIR    4
  33 
  34 #define ERRNOR(a, b)                                                                               \
  35     do                                                                                             \
  36     {                                                                                              \
  37         me->verrno = a;                                                                            \
  38         return b;                                                                                  \
  39     }                                                                                              \
  40     while (0)
  41 
  42 #define VFS_SUBCLASS(a)           ((struct vfs_s_subclass *) (a))
  43 
  44 #define VFS_SUPER(a)              ((struct vfs_s_super *) (a))
  45 #define CONST_VFS_SUPER(a)        ((const struct vfs_s_super *) (a))
  46 #define VFS_ENTRY(a)              ((struct vfs_s_entry *) (a))
  47 #define VFS_INODE(a)              ((struct vfs_s_inode *) (a))
  48 
  49 #define VFS_FILE_HANDLER(a)       ((vfs_file_handler_t *) a)
  50 #define VFS_FILE_HANDLER_SUPER(a) VFS_FILE_HANDLER (a)->ino->super
  51 
  52 /*** enums ***************************************************************************************/
  53 
  54 typedef enum
  55 {
  56     LS_NOT_LINEAR = 0,
  57     LS_LINEAR_CLOSED = 1,
  58     LS_LINEAR_OPEN = 2,
  59     LS_LINEAR_PREOPEN = 3
  60 } vfs_linear_state_t;
  61 
  62 /*** structures declarations (and typedefs of structures)*****************************************/
  63 
  64 /* Single connection or archive */
  65 struct vfs_s_super
  66 {
  67     struct vfs_class *me;
  68     struct vfs_s_inode *root;
  69     char *name;           // My name, whatever it means
  70     int fd_usage;         // Number of open files
  71     int ino_usage;        // Usage count of this superblock
  72     gboolean want_stale;  // If set, we do not flush cache properly
  73 #ifdef ENABLE_VFS_NET
  74     vfs_path_element_t *path_element;
  75 #endif
  76 };
  77 
  78 /*
  79  * Single virtual file - directory entry.  The same inode can have many
  80  * entries (i.e. hard links), but usually has only one.
  81  */
  82 struct vfs_s_entry
  83 {
  84     struct vfs_s_inode *dir;  // Directory we are in, i.e. our parent
  85     char *name;               // Name of this entry
  86     struct vfs_s_inode *ino;  // ... and its inode
  87     ssize_t leading_spaces;   // number of leading spases in the file name
  88 };
  89 
  90 /* Single virtual file - inode */
  91 struct vfs_s_inode
  92 {
  93     struct vfs_s_super *super;  // Archive the file is on
  94     struct vfs_s_entry *ent;    /* Our entry in the parent directory -
  95                                    use only for directories because they
  96                                    cannot be hardlinked */
  97     GQueue *subdir;             // If this is a directory, its entry. List of vfs_s_entry
  98     struct stat st;             // Parameters of this inode
  99     char *linkname;             // Symlink's contents
 100     char *localname;            // Filename of local file, if we have one
 101     gint64 timestamp;           // Subclass specific
 102     off_t data_offset;          // Subclass specific
 103     void *user_data;            // Subclass specific
 104 };
 105 
 106 /* Data associated with an open file */
 107 typedef struct
 108 {
 109     struct vfs_s_inode *ino;
 110     off_t pos;                  // This is for module's use
 111     int handle;                 // This is for module's use, but if != -1, will be mc_close()d
 112     gboolean changed;           // Did this file change?
 113     vfs_linear_state_t linear;  // Is that file open with O_LINEAR?
 114 } vfs_file_handler_t;
 115 
 116 /*
 117  * One of our subclasses (tar, cpio, shell, ftpfs) with data and methods.
 118  * Extends vfs_class.
 119  */
 120 struct vfs_s_subclass
 121 {
 122     struct vfs_class base;  // base class
 123 
 124     GList *supers;
 125     int inode_counter;
 126     dev_t rdev;
 127 
 128     int (*init_inode) (struct vfs_class *me, struct vfs_s_inode *ino);    // optional
 129     void (*free_inode) (struct vfs_class *me, struct vfs_s_inode *ino);   // optional
 130     int (*init_entry) (struct vfs_class *me, struct vfs_s_entry *entry);  // optional
 131 
 132     void *(*archive_check) (const vfs_path_t *vpath);  // optional
 133     int (*archive_same) (const vfs_path_element_t *vpath_element, struct vfs_s_super *psup,
 134                          const vfs_path_t *vpath, void *cookie);
 135     struct vfs_s_super *(*new_archive) (struct vfs_class *me);
 136     int (*open_archive) (struct vfs_s_super *psup, const vfs_path_t *vpath,
 137                          const vfs_path_element_t *vpath_element);
 138     void (*free_archive) (struct vfs_class *me, struct vfs_s_super *psup);
 139 
 140     vfs_file_handler_t *(*fh_new) (struct vfs_s_inode *ino, gboolean changed);
 141     int (*fh_open) (struct vfs_class *me, vfs_file_handler_t *fh, int flags, mode_t mode);
 142     int (*fh_close) (struct vfs_class *me, vfs_file_handler_t *fh);
 143     void (*fh_free) (vfs_file_handler_t *fh);
 144 
 145     struct vfs_s_entry *(*find_entry) (struct vfs_class *me, struct vfs_s_inode *root,
 146                                        const char *path, int follow, int flags);
 147     int (*dir_load) (struct vfs_class *me, struct vfs_s_inode *ino, const char *path);
 148     gboolean (*dir_uptodate) (struct vfs_class *me, struct vfs_s_inode *ino);
 149     int (*file_store) (struct vfs_class *me, vfs_file_handler_t *fh, char *path, char *localname);
 150 
 151     int (*linear_start) (struct vfs_class *me, vfs_file_handler_t *fh, off_t from);
 152     ssize_t (*linear_read) (struct vfs_class *me, vfs_file_handler_t *fh, void *buf, size_t len);
 153     void (*linear_close) (struct vfs_class *me, vfs_file_handler_t *fh);
 154 };
 155 
 156 /*** global variables defined in .c file *********************************************************/
 157 
 158 /*** declarations of public functions ************************************************************/
 159 
 160 /* entries and inodes */
 161 struct vfs_s_inode *vfs_s_new_inode (struct vfs_class *me, struct vfs_s_super *super,
 162                                      struct stat *initstat);
 163 void vfs_s_free_inode (struct vfs_class *me, struct vfs_s_inode *ino);
 164 
 165 struct vfs_s_entry *vfs_s_new_entry (struct vfs_class *me, const char *name,
 166                                      struct vfs_s_inode *inode);
 167 void vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent);
 168 void vfs_s_insert_entry (struct vfs_class *me, struct vfs_s_inode *dir, struct vfs_s_entry *ent);
 169 int vfs_s_entry_compare (const void *a, const void *b);
 170 struct stat *vfs_s_default_stat (struct vfs_class *me, mode_t mode);
 171 
 172 struct vfs_s_entry *vfs_s_generate_entry (struct vfs_class *me, const char *name,
 173                                           struct vfs_s_inode *parent, mode_t mode);
 174 struct vfs_s_inode *vfs_s_find_inode (struct vfs_class *me, const struct vfs_s_super *super,
 175                                       const char *path, int follow, int flags);
 176 struct vfs_s_inode *vfs_s_find_root (struct vfs_class *me, struct vfs_s_entry *entry);
 177 
 178 /* outside interface */
 179 void vfs_init_subclass (struct vfs_s_subclass *sub, const char *name, vfs_flags_t flags,
 180                         const char *prefix);
 181 const char *vfs_s_get_path (const vfs_path_t *vpath, struct vfs_s_super **archive, int flags);
 182 struct vfs_s_super *vfs_get_super_by_vpath (const vfs_path_t *vpath);
 183 
 184 void vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super);
 185 char *vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino);
 186 
 187 void vfs_s_init_fh (vfs_file_handler_t *fh, struct vfs_s_inode *ino, gboolean changed);
 188 
 189 /* network filesystems support */
 190 int vfs_s_select_on_two (int fd1, int fd2);
 191 int vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char term);
 192 int vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer, int size, int fd);
 193 /* misc */
 194 int vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino);
 195 
 196 void vfs_s_normalize_filename_leading_spaces (struct vfs_s_inode *root_inode, size_t final_filepos);
 197 
 198 /*** inline functions ****************************************************************************/
 199 
 200 static inline void
 201 vfs_s_store_filename_leading_spaces (struct vfs_s_entry *entry, size_t position)
     /* [previous][next][first][last][top][bottom][index][help]  */
 202 {
 203     entry->leading_spaces = (ssize_t) position;
 204 }
 205 
 206 #endif

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