Browse Source

Join vfs_class_flags_t and vfs_subclass_flags_t.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 6 years ago
parent
commit
0fbd98fece
10 changed files with 41 additions and 51 deletions
  1. 3 8
      lib/utilunix.c
  2. 11 11
      lib/vfs/direntry.c
  3. 1 1
      lib/vfs/gc.c
  4. 3 3
      lib/vfs/path.c
  5. 9 8
      lib/vfs/vfs.c
  6. 10 7
      lib/vfs/vfs.h
  7. 0 9
      lib/vfs/xdirentry.h
  8. 1 1
      src/filemanager/file.c
  9. 2 2
      src/vfs/cpio/cpio.c
  10. 1 1
      src/vfs/fish/fish.c

+ 3 - 8
lib/utilunix.c

@@ -956,15 +956,10 @@ custom_canonicalize_pathname (char *path, CANON_PATH_FLAGS flags)
                     vclass = vfs_prefix_to_class (vfs_prefix);
                     *(s - url_delim_len) = *VFS_PATH_URL_DELIMITER;
 
-                    if (vclass != NULL)
+                    if (vclass != NULL && (vclass->flags & VFS_REMOTE) != 0)
                     {
-                        struct vfs_s_subclass *sub = (struct vfs_s_subclass *) vclass;
-
-                        if ((sub->flags & VFS_S_REMOTE) != 0)
-                        {
-                            s = vfs_prefix;
-                            continue;
-                        }
+                        s = vfs_prefix;
+                        continue;
                     }
                 }
 

+ 11 - 11
lib/vfs/direntry.c

@@ -644,7 +644,7 @@ vfs_s_close (void *fh)
         MEDATA->linear_close (me, fh);
     if (MEDATA->fh_close != NULL)
         res = MEDATA->fh_close (me, fh);
-    if ((MEDATA->flags & VFS_S_USETMP) != 0 && FH->changed && MEDATA->file_store != NULL)
+    if ((me->flags & VFS_USETMP) != 0 && FH->changed && MEDATA->file_store != NULL)
     {
         char *s;
 
@@ -733,7 +733,7 @@ vfs_s_getlocalcopy (const vfs_path_t * vpath)
         const struct vfs_class *me;
 
         me = vfs_path_get_by_index (vpath, -1)->class;
-        if ((MEDATA->flags & VFS_S_USETMP) != 0 && fh->ino != NULL)
+        if ((me->flags & VFS_USETMP) != 0 && fh->ino != NULL)
             local = vfs_path_from_str_flags (fh->ino->localname, VPF_NO_CANON);
 
         vfs_s_close (fh);
@@ -895,7 +895,7 @@ vfs_s_free_inode (struct vfs_class *me, struct vfs_s_inode *ino)
 
     CALL (free_inode) (me, ino);
     g_free (ino->linkname);
-    if ((MEDATA->flags & VFS_S_USETMP) != 0 && ino->localname != NULL)
+    if ((me->flags & VFS_USETMP) != 0 && ino->localname != NULL)
     {
         unlink (ino->localname);
         g_free (ino->localname);
@@ -1047,7 +1047,7 @@ vfs_s_find_inode (struct vfs_class *me, const struct vfs_s_super *super,
 {
     struct vfs_s_entry *ent;
 
-    if (((MEDATA->flags & VFS_S_REMOTE) == 0) && (*path == '\0'))
+    if (((me->flags & VFS_REMOTE) == 0) && (*path == '\0'))
         return super->root;
 
     ent = MEDATA->find_entry (me, super->root, path, follow, flags);
@@ -1197,7 +1197,7 @@ vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino)
     if (ino->ent == NULL)
         ERRNOR (EAGAIN, NULL);
 
-    if ((MEDATA->flags & VFS_S_USETMP) == 0)
+    if ((me->flags & VFS_USETMP) == 0)
     {
         /* archives */
         char *path;
@@ -1277,7 +1277,7 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode)
         ent = vfs_s_generate_entry (path_element->class, name, dir, 0755);
         ino = ent->ino;
         vfs_s_insert_entry (path_element->class, dir, ent);
-        if ((s->flags & VFS_S_USETMP) != 0)
+        if ((((struct vfs_class *) s)->flags & VFS_USETMP) != 0)
         {
             int tmp_handle;
             vfs_path_t *tmp_vpath;
@@ -1332,7 +1332,7 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode)
         }
     }
 
-    if ((s->flags & VFS_S_USETMP) != 0 && fh->ino->localname != NULL)
+    if ((((struct vfs_class *) s)->flags & VFS_USETMP) != 0 && fh->ino->localname != NULL)
     {
         fh->handle = open (fh->ino->localname, NO_LINEAR (flags), mode);
         if (fh->handle == -1)
@@ -1389,7 +1389,7 @@ vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino)
     vfs_file_handler_t fh;
     vfs_path_t *tmp_vpath;
 
-    if ((MEDATA->flags & VFS_S_USETMP) == 0)
+    if ((me->flags & VFS_USETMP) == 0)
         return (-1);
 
     memset (&fh, 0, sizeof (fh));
@@ -1466,7 +1466,7 @@ vfs_s_init_class (struct vfs_s_subclass *sub)
     vclass->open = vfs_s_open;
     vclass->close = vfs_s_close;
     vclass->read = vfs_s_read;
-    if ((sub->flags & VFS_S_READONLY) == 0)
+    if ((vclass->flags & VFS_READONLY) == 0)
         vclass->write = vfs_s_write;
     vclass->opendir = vfs_s_opendir;
     vclass->readdir = vfs_s_readdir;
@@ -1481,13 +1481,13 @@ vfs_s_init_class (struct vfs_s_subclass *sub)
     vclass->getid = vfs_s_getid;
     vclass->nothingisopen = vfs_s_nothingisopen;
     vclass->free = vfs_s_free;
-    if ((sub->flags & VFS_S_USETMP) != 0)
+    if ((vclass->flags & VFS_USETMP) != 0)
     {
         vclass->getlocalcopy = vfs_s_getlocalcopy;
         vclass->ungetlocalcopy = vfs_s_ungetlocalcopy;
         sub->find_entry = vfs_s_find_entry_linear;
     }
-    else if ((sub->flags & VFS_S_REMOTE) != 0)
+    else if ((vclass->flags & VFS_REMOTE) != 0)
         sub->find_entry = vfs_s_find_entry_linear;
     else
         sub->find_entry = vfs_s_find_entry_tree;

+ 1 - 1
lib/vfs/gc.c

@@ -133,7 +133,7 @@ vfs_stamp_compare (gconstpointer a, gconstpointer b)
 static void
 vfs_addstamp (struct vfs_class *v, vfsid id)
 {
-    if ((v->flags & VFSF_LOCAL) == 0 && id != NULL && !vfs_stamp (v, id))
+    if ((v->flags & VFS_LOCAL) == 0 && id != NULL && !vfs_stamp (v, id))
     {
         struct vfs_stamping *stamp;
 

+ 3 - 3
lib/vfs/path.c

@@ -462,7 +462,7 @@ vfs_path_from_str_uri_parser (char *path)
 
         url_delimiter += strlen (VFS_PATH_URL_DELIMITER);
         sub = VFS_SUBCLASS (element);
-        if (sub != NULL && (sub->flags & VFS_S_REMOTE) != 0)
+        if (sub != NULL && (((struct vfs_class *) sub)->flags & VFS_REMOTE) != 0)
         {
             char *slash_pointer;
 
@@ -531,7 +531,7 @@ static void
 vfs_path_tokens_add_class_info (const vfs_path_element_t * element, GString * ret_tokens,
                                 GString * element_tokens)
 {
-    if (((element->class->flags & VFSF_LOCAL) == 0 || ret_tokens->len > 0)
+    if (((element->class->flags & VFS_LOCAL) == 0 || ret_tokens->len > 0)
         && element_tokens->len > 0)
     {
         char *url_str;
@@ -596,7 +596,7 @@ vfs_path_strip_home (const char *dir)
 
 #define vfs_append_from_path(appendfrom, is_relative) \
 { \
-    if ((flags & VPF_STRIP_HOME) && element_index == 0 && (element->class->flags & VFSF_LOCAL) != 0) \
+    if ((flags & VPF_STRIP_HOME) && element_index == 0 && (element->class->flags & VFS_LOCAL) != 0) \
     { \
         char *stripped_home_str; \
         stripped_home_str = vfs_path_strip_home (appendfrom); \

+ 9 - 8
lib/vfs/vfs.c

@@ -438,20 +438,20 @@ vfs_set_raw_current_dir (const vfs_path_t * vpath)
 gboolean
 vfs_current_is_local (void)
 {
-    return (current_vfs->flags & VFSF_LOCAL) != 0;
+    return (current_vfs->flags & VFS_LOCAL) != 0;
 }
 
 /* --------------------------------------------------------------------------------------------- */
 /* Return flags of the VFS class of the given filename */
 
-vfs_class_flags_t
+vfs_flags_t
 vfs_file_class_flags (const vfs_path_t * vpath)
 {
     const vfs_path_element_t *path_element;
 
     path_element = vfs_path_get_by_index (vpath, -1);
     if (!vfs_path_element_valid (path_element))
-        return VFSF_UNKNOWN;
+        return VFS_UNKNOWN;
 
     return path_element->class->flags;
 }
@@ -542,10 +542,11 @@ vfs_fill_names (fill_names_f func)
 }
 
 /* --------------------------------------------------------------------------------------------- */
+
 gboolean
 vfs_file_is_local (const vfs_path_t * vpath)
 {
-    return (vfs_file_class_flags (vpath) & VFSF_LOCAL) != 0;
+    return (vfs_file_class_flags (vpath) & VFS_LOCAL) != 0;
 }
 
 /* --------------------------------------------------------------------------------------------- */
@@ -596,7 +597,7 @@ vfs_setup_cwd (void)
 
     path_element = vfs_path_get_by_index (vfs_get_raw_current_dir (), -1);
 
-    if ((path_element->class->flags & VFSF_LOCAL) != 0)
+    if ((path_element->class->flags & VFS_LOCAL) != 0)
     {
         current_dir = g_get_current_dir ();
         tmp_vpath = vfs_path_from_str (current_dir);
@@ -661,7 +662,7 @@ vfs_preallocate (int dest_vfs_fd, off_t src_fsize, off_t dest_fsize)
         return 0;
 
     dest_class = vfs_class_find_by_handle (dest_vfs_fd, &dest_fd);
-    if ((dest_class->flags & VFSF_LOCAL) == 0 || dest_fd == NULL)
+    if ((dest_class->flags & VFS_LOCAL) == 0 || dest_fd == NULL)
         return 0;
 
     return posix_fallocate (*(int *) dest_fd, dest_fsize, src_fsize - dest_fsize);
@@ -681,7 +682,7 @@ vfs_clone_file (int dest_vfs_fd, int src_vfs_fd)
     struct vfs_class *src_class;
 
     dest_class = vfs_class_find_by_handle (dest_vfs_fd, &dest_fd);
-    if ((dest_class->flags & VFSF_LOCAL) == 0)
+    if ((dest_class->flags & VFS_LOCAL) == 0)
     {
         errno = EOPNOTSUPP;
         return (-1);
@@ -693,7 +694,7 @@ vfs_clone_file (int dest_vfs_fd, int src_vfs_fd)
     }
 
     src_class = vfs_class_find_by_handle (src_vfs_fd, &src_fd);
-    if ((src_class->flags & VFSF_LOCAL) == 0)
+    if ((src_class->flags & VFS_LOCAL) == 0)
     {
         errno = EOPNOTSUPP;
         return (-1);

+ 10 - 7
lib/vfs/vfs.h

@@ -107,13 +107,16 @@ typedef struct utimbuf mc_timesbuf_t;
 
 /*** enums ***************************************************************************************/
 
-/* Flags of VFS classes */
 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;
+    VFS_UNKNOWN = 0,
+    VFS_LOCAL = 1 << 0,         /* Class is local (not virtual) filesystem */
+    VFS_NOLINKS = 1 << 1,       /* Hard links not supported */
+
+    VFS_REMOTE = 1 << 2,
+    VFS_READONLY = 1 << 3,
+    VFS_USETMP = 1 << 4
+} vfs_flags_t;
 
 /* Operations for mc_ctl - on open file */
 enum
@@ -139,7 +142,7 @@ enum
 typedef struct vfs_class
 {
     const char *name;           /* "FIles over SHell" */
-    vfs_class_flags_t flags;
+    vfs_flags_t flags;
     const char *prefix;         /* "fish:" */
     int verrno;                 /* can't use errno because glibc2 might define errno as function */
 
@@ -255,7 +258,7 @@ gboolean vfs_file_is_local (const vfs_path_t * vpath);
 
 char *vfs_strip_suffix_from_filename (const char *filename);
 
-vfs_class_flags_t vfs_file_class_flags (const vfs_path_t * vpath);
+vfs_flags_t vfs_file_class_flags (const vfs_path_t * vpath);
 
 /* translate path back to terminal encoding, remove all #enc:
  * every invalid character is replaced with question mark

+ 0 - 9
lib/vfs/xdirentry.h

@@ -43,14 +43,6 @@
 
 /*** enums ***************************************************************************************/
 
-/* For vfs_s_subclass->flags */
-typedef enum
-{
-    VFS_S_REMOTE = 1L << 0,
-    VFS_S_READONLY = 1L << 1,
-    VFS_S_USETMP = 1L << 2,
-} vfs_subclass_flags_t;
-
 typedef enum
 {
     LS_NOT_LINEAR = 0,
@@ -124,7 +116,6 @@ struct vfs_s_subclass
 
     GList *supers;
     int inode_counter;
-    vfs_subclass_flags_t flags; /* whether the subclass is remove, read-only etc */
     dev_t rdev;
     FILE *logfile;
     int flush;                  /* if set to 1, invalidate directory cache */

+ 1 - 1
src/filemanager/file.c

@@ -353,7 +353,7 @@ check_hardlinks (const vfs_path_t * src_vpath, const struct stat *src_stat,
 
     if (src_stat->st_nlink < 2)
         return HARDLINK_NOTLINK;
-    if ((vfs_file_class_flags (src_vpath) & VFSF_NOLINKS) != 0)
+    if ((vfs_file_class_flags (src_vpath) & VFS_NOLINKS) != 0)
         return HARDLINK_UNSUPPORTED;
 
     lnk = (struct link *) is_in_linklist (linklist, src_vpath, src_stat);

+ 2 - 2
src/vfs/cpio/cpio.c

@@ -884,14 +884,14 @@ init_cpiofs (void)
 {
     memset (&cpio_subclass, 0, sizeof (cpio_subclass));
 
-    cpio_subclass.flags = VFS_S_READONLY;       /* FIXME: cpiofs used own temp files */
+    vfs_cpiofs_ops->flags = VFS_READONLY;       /* FIXME: cpiofs used own temp files */
     cpio_subclass.archive_check = cpio_super_check;
     cpio_subclass.archive_same = cpio_super_same;
     cpio_subclass.open_archive = cpio_open_archive;
     cpio_subclass.free_archive = cpio_free_archive;
     cpio_subclass.fh_open = cpio_fh_open;
-
     vfs_s_init_class (&cpio_subclass);
+
     vfs_cpiofs_ops->name = "cpiofs";
     vfs_cpiofs_ops->prefix = "ucpio";
     vfs_cpiofs_ops->read = cpio_read;

+ 1 - 1
src/vfs/fish/fish.c

@@ -1733,7 +1733,7 @@ init_fish (void)
 
     memset (&fish_subclass, 0, sizeof (fish_subclass));
 
-    fish_subclass.flags = VFS_S_REMOTE | VFS_S_USETMP;
+    vfs_fish_ops->flags = VFS_REMOTE | VFS_USETMP;
     fish_subclass.archive_same = fish_archive_same;
     fish_subclass.open_archive = fish_open_archive;
     fish_subclass.free_archive = fish_free_archive;

Some files were not shown because too many files changed in this diff