1998-02-27 07:54:42 +03:00
|
|
|
/* Virtual File System: External file system.
|
2007-09-25 19:33:35 +04:00
|
|
|
Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
|
|
|
|
2006, 2007 Free Software Foundation, Inc.
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
Written by: 1995 Jakub Jelinek
|
1998-05-26 04:53:24 +04:00
|
|
|
Rewritten by: 1998 Pavel Machek
|
1999-04-13 06:05:15 +04:00
|
|
|
Additional changes by: 1999 Andrew T. Veliath
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2 of
|
|
|
|
the License, or (at your option) any later version.
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
1998-09-27 23:27:58 +04:00
|
|
|
GNU Library General Public License for more details.
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
You should have received a copy of the GNU Library General Public
|
|
|
|
License along with this program; if not, write to the Free Software
|
2005-05-27 07:35:10 +04:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-07 15:54:58 +03:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \brief Source: Virtual File System: External file system
|
|
|
|
* \author Jakub Jelinek
|
|
|
|
* \author Pavel Machek
|
|
|
|
* \author Andrew T. Veliath
|
|
|
|
* \date 1995, 1998, 1999
|
|
|
|
*/
|
|
|
|
|
2003-10-30 02:05:27 +03:00
|
|
|
/* Namespace: init_extfs */
|
1998-10-13 02:07:53 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
#include <errno.h>
|
2009-01-31 18:51:58 +03:00
|
|
|
|
2005-02-19 19:36:38 +03:00
|
|
|
#include "../src/global.h"
|
|
|
|
#include "../src/tty.h" /* enable/disable interrupt key */
|
|
|
|
#include "../src/wtools.h" /* message() */
|
|
|
|
#include "../src/main.h" /* print_vfs_message */
|
1999-01-21 01:01:11 +03:00
|
|
|
#include "utilvfs.h"
|
2003-06-22 13:18:12 +04:00
|
|
|
#include "../src/execute.h" /* For shell_execute */
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "vfs.h"
|
2004-08-17 03:18:42 +04:00
|
|
|
#include "vfs-impl.h"
|
2003-11-08 02:43:55 +03:00
|
|
|
#include "gc.h" /* vfs_rmstamp */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2001-02-20 19:24:49 +03:00
|
|
|
#undef ERRNOR
|
1998-10-23 12:26:25 +04:00
|
|
|
#define ERRNOR(x,y) do { my_errno = x; return y; } while(0)
|
|
|
|
|
2001-08-08 03:54:35 +04:00
|
|
|
struct inode {
|
|
|
|
nlink_t nlink;
|
|
|
|
struct entry *first_in_subdir; /* only used if this is a directory */
|
|
|
|
struct entry *last_in_subdir;
|
|
|
|
ino_t inode; /* This is inode # */
|
|
|
|
dev_t dev; /* This is an internal identification of the extfs archive */
|
|
|
|
struct archive *archive; /* And this is an archive structure */
|
|
|
|
dev_t rdev;
|
|
|
|
mode_t mode;
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
2004-08-30 22:38:21 +04:00
|
|
|
off_t size;
|
2001-08-08 03:54:35 +04:00
|
|
|
time_t mtime;
|
|
|
|
char *linkname;
|
|
|
|
time_t atime;
|
|
|
|
time_t ctime;
|
|
|
|
char *local_filename;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct entry {
|
|
|
|
struct entry *next_in_dir;
|
|
|
|
struct entry *dir;
|
|
|
|
char *name;
|
|
|
|
struct inode *inode;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pseudofile {
|
|
|
|
struct archive *archive;
|
|
|
|
unsigned int has_changed:1;
|
|
|
|
int local_handle;
|
|
|
|
struct entry *entry;
|
|
|
|
};
|
|
|
|
|
2003-10-30 02:05:27 +03:00
|
|
|
struct archive {
|
|
|
|
int fstype;
|
|
|
|
char *name;
|
|
|
|
char *local_name;
|
|
|
|
struct stat local_stat;
|
|
|
|
dev_t rdev;
|
|
|
|
int fd_usage;
|
2003-10-30 02:16:31 +03:00
|
|
|
ino_t inode_counter;
|
2003-10-30 02:05:27 +03:00
|
|
|
struct entry *root_entry;
|
|
|
|
struct archive *next;
|
|
|
|
};
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static struct entry *extfs_find_entry (struct entry *dir, char *name,
|
|
|
|
int make_dirs, int make_file);
|
2004-08-16 23:47:21 +04:00
|
|
|
static int extfs_which (struct vfs_class *me, const char *path);
|
2003-10-28 03:57:02 +03:00
|
|
|
static void extfs_remove_entry (struct entry *e);
|
2002-12-26 00:42:59 +03:00
|
|
|
static void extfs_free (vfsid id);
|
2006-03-23 18:00:50 +03:00
|
|
|
static void extfs_free_entry (struct entry *e);
|
1998-04-17 04:59:58 +04:00
|
|
|
|
2003-10-13 02:25:53 +04:00
|
|
|
static struct vfs_class vfs_extfs_ops;
|
1998-09-13 14:40:43 +04:00
|
|
|
static struct archive *first_archive = NULL;
|
|
|
|
static int my_errno = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#define MAXEXTFS 32
|
|
|
|
static char *extfs_prefixes [MAXEXTFS];
|
|
|
|
static char extfs_need_archive [MAXEXTFS];
|
|
|
|
static int extfs_no = 0;
|
|
|
|
|
2003-10-30 02:16:31 +03:00
|
|
|
static void
|
2004-08-16 20:34:11 +04:00
|
|
|
extfs_fill_names (struct vfs_class *me, fill_names_f func)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct archive *a = first_archive;
|
1998-02-27 07:54:42 +03:00
|
|
|
char *name;
|
2003-10-30 02:16:31 +03:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2003-10-30 02:16:31 +03:00
|
|
|
while (a) {
|
|
|
|
name =
|
|
|
|
g_strconcat (a->name ? a->name : "", "#",
|
2004-09-24 19:08:21 +04:00
|
|
|
extfs_prefixes[a->fstype], (char *) NULL);
|
2003-10-30 02:16:31 +03:00
|
|
|
(*func) (name);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (name);
|
1998-02-27 07:54:42 +03:00
|
|
|
a = a->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static void extfs_make_dots (struct entry *ent)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1999-01-21 01:01:11 +03:00
|
|
|
struct entry *entry = g_new (struct entry, 1);
|
1998-09-13 14:40:43 +04:00
|
|
|
struct entry *parentry = ent->dir;
|
|
|
|
struct inode *inode = ent->inode, *parent;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
parent = (parentry != NULL) ? parentry->inode : NULL;
|
2009-02-06 01:40:32 +03:00
|
|
|
entry->name = g_strdup (".");
|
1998-02-27 07:54:42 +03:00
|
|
|
entry->inode = inode;
|
|
|
|
entry->dir = ent;
|
|
|
|
inode->local_filename = NULL;
|
|
|
|
inode->first_in_subdir = entry;
|
|
|
|
inode->nlink++;
|
1999-01-21 01:01:11 +03:00
|
|
|
entry->next_in_dir = g_new (struct entry, 1);
|
2004-12-27 15:12:31 +03:00
|
|
|
entry = entry->next_in_dir;
|
2009-02-06 01:40:32 +03:00
|
|
|
entry->name = g_strdup ("..");
|
1998-02-27 07:54:42 +03:00
|
|
|
inode->last_in_subdir = entry;
|
|
|
|
entry->next_in_dir = NULL;
|
|
|
|
if (parent != NULL) {
|
|
|
|
entry->inode = parent;
|
|
|
|
entry->dir = parentry;
|
|
|
|
parent->nlink++;
|
|
|
|
} else {
|
|
|
|
entry->inode = inode;
|
|
|
|
entry->dir = ent;
|
|
|
|
inode->nlink++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static struct entry *extfs_generate_entry (struct archive *archive,
|
2005-09-05 04:52:56 +04:00
|
|
|
const char *name, struct entry *parentry, mode_t mode)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
mode_t myumask;
|
1998-09-13 14:40:43 +04:00
|
|
|
struct inode *inode, *parent;
|
|
|
|
struct entry *entry;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
parent = (parentry != NULL) ? parentry->inode : NULL;
|
1999-01-21 01:01:11 +03:00
|
|
|
entry = g_new (struct entry, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-06 01:40:32 +03:00
|
|
|
entry->name = g_strdup (name);
|
1998-02-27 07:54:42 +03:00
|
|
|
entry->next_in_dir = NULL;
|
|
|
|
entry->dir = parentry;
|
|
|
|
if (parent != NULL) {
|
|
|
|
parent->last_in_subdir->next_in_dir = entry;
|
|
|
|
parent->last_in_subdir = entry;
|
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
inode = g_new (struct inode, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
entry->inode = inode;
|
|
|
|
inode->local_filename = NULL;
|
2004-12-27 15:12:31 +03:00
|
|
|
inode->linkname = NULL;
|
|
|
|
inode->last_in_subdir = NULL;
|
2003-10-30 02:16:31 +03:00
|
|
|
inode->inode = (archive->inode_counter)++;
|
1998-02-27 07:54:42 +03:00
|
|
|
inode->dev = archive->rdev;
|
|
|
|
inode->archive = archive;
|
|
|
|
myumask = umask (022);
|
|
|
|
umask (myumask);
|
|
|
|
inode->mode = mode & ~myumask;
|
|
|
|
mode = inode->mode;
|
|
|
|
inode->rdev = 0;
|
|
|
|
inode->uid = getuid ();
|
|
|
|
inode->gid = getgid ();
|
|
|
|
inode->size = 0;
|
|
|
|
inode->mtime = time (NULL);
|
|
|
|
inode->atime = inode->mtime;
|
|
|
|
inode->ctime = inode->mtime;
|
|
|
|
inode->nlink = 1;
|
|
|
|
if (S_ISDIR (mode))
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_make_dots (entry);
|
1998-02-27 07:54:42 +03:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2006-03-23 18:00:50 +03:00
|
|
|
#if 0
|
2003-10-28 03:57:02 +03:00
|
|
|
static void extfs_free_entries (struct entry *entry)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) entry;
|
1998-02-27 07:54:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2006-03-23 18:00:50 +03:00
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static void extfs_free_archive (struct archive *archive)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2006-03-23 18:00:50 +03:00
|
|
|
extfs_free_entry (archive->root_entry);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (archive->local_name != NULL) {
|
|
|
|
struct stat my;
|
|
|
|
|
|
|
|
mc_stat (archive->local_name, &my);
|
|
|
|
mc_ungetlocalcopy (archive->name, archive->local_name,
|
|
|
|
archive->local_stat.st_mtime != my.st_mtime);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free(archive->local_name);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (archive->name);
|
|
|
|
g_free (archive);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2002-12-06 06:14:41 +03:00
|
|
|
static FILE *
|
2003-10-28 05:10:33 +03:00
|
|
|
extfs_open_archive (int fstype, const char *name, struct archive **pparc)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2003-10-30 02:16:31 +03:00
|
|
|
static dev_t archive_counter = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
FILE *result;
|
|
|
|
mode_t mode;
|
|
|
|
char *cmd;
|
1998-08-27 00:23:10 +04:00
|
|
|
char *mc_extfsdir;
|
1998-02-27 07:54:42 +03:00
|
|
|
struct stat mystat;
|
1998-09-13 14:40:43 +04:00
|
|
|
struct archive *current_archive;
|
|
|
|
struct entry *root_entry;
|
1998-02-27 07:54:42 +03:00
|
|
|
char *local_name = NULL, *tmp = 0;
|
2002-12-06 06:14:41 +03:00
|
|
|
int uses_archive = extfs_need_archive[fstype];
|
|
|
|
|
|
|
|
if (uses_archive) {
|
1998-02-27 07:54:42 +03:00
|
|
|
if (mc_stat (name, &mystat) == -1)
|
|
|
|
return NULL;
|
|
|
|
if (!vfs_file_is_local (name)) {
|
|
|
|
local_name = mc_getlocalcopy (name);
|
|
|
|
if (local_name == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-12-06 06:14:41 +03:00
|
|
|
tmp = name_quote (name, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2009-02-06 13:17:03 +03:00
|
|
|
mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
|
2002-12-06 06:14:41 +03:00
|
|
|
cmd =
|
|
|
|
g_strconcat (mc_extfsdir, extfs_prefixes[fstype], " list ",
|
2004-09-24 19:08:21 +04:00
|
|
|
local_name ? local_name : tmp, (char *) NULL);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (tmp);
|
|
|
|
g_free (mc_extfsdir);
|
2002-12-05 20:05:27 +03:00
|
|
|
open_error_pipe ();
|
1998-02-27 07:54:42 +03:00
|
|
|
result = popen (cmd, "r");
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (cmd);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (result == NULL) {
|
2009-01-10 16:13:56 +03:00
|
|
|
close_error_pipe (D_ERROR, NULL);
|
2004-08-16 19:18:17 +04:00
|
|
|
if (local_name) {
|
2002-12-06 06:14:41 +03:00
|
|
|
mc_ungetlocalcopy (name, local_name, 0);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free(local_name);
|
2004-08-16 19:18:17 +04:00
|
|
|
}
|
2002-12-06 06:14:41 +03:00
|
|
|
return NULL;
|
2004-09-17 15:44:43 +04:00
|
|
|
}
|
|
|
|
#ifdef ___QNXNTO__
|
|
|
|
setvbuf (result, NULL, _IONBF, 0);
|
|
|
|
#endif
|
2002-12-06 06:14:41 +03:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
current_archive = g_new (struct archive, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
current_archive->fstype = fstype;
|
2009-02-06 01:40:32 +03:00
|
|
|
current_archive->name = name ? g_strdup (name) : NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
current_archive->local_name = local_name;
|
2002-12-06 06:14:41 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (local_name != NULL)
|
2002-12-06 06:14:41 +03:00
|
|
|
mc_stat (local_name, ¤t_archive->local_stat);
|
2003-10-30 02:16:31 +03:00
|
|
|
current_archive->inode_counter = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
current_archive->fd_usage = 0;
|
2003-10-30 02:16:31 +03:00
|
|
|
current_archive->rdev = archive_counter++;
|
1998-02-27 07:54:42 +03:00
|
|
|
current_archive->next = first_archive;
|
|
|
|
first_archive = current_archive;
|
2002-12-06 06:14:41 +03:00
|
|
|
mode = mystat.st_mode & 07777;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (mode & 0400)
|
2002-12-06 06:14:41 +03:00
|
|
|
mode |= 0100;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (mode & 0040)
|
2002-12-06 06:14:41 +03:00
|
|
|
mode |= 0010;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (mode & 0004)
|
2002-12-06 06:14:41 +03:00
|
|
|
mode |= 0001;
|
1998-02-27 07:54:42 +03:00
|
|
|
mode |= S_IFDIR;
|
2003-10-28 03:57:02 +03:00
|
|
|
root_entry = extfs_generate_entry (current_archive, "/", NULL, mode);
|
2002-12-06 06:14:41 +03:00
|
|
|
root_entry->inode->uid = mystat.st_uid;
|
|
|
|
root_entry->inode->gid = mystat.st_gid;
|
|
|
|
root_entry->inode->atime = mystat.st_atime;
|
|
|
|
root_entry->inode->ctime = mystat.st_ctime;
|
|
|
|
root_entry->inode->mtime = mystat.st_mtime;
|
1998-02-27 07:54:42 +03:00
|
|
|
current_archive->root_entry = root_entry;
|
2002-12-06 06:14:41 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
*pparc = current_archive;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Main loop for reading an archive.
|
2002-12-26 00:42:59 +03:00
|
|
|
* Return 0 on success, -1 on error.
|
1998-02-27 07:54:42 +03:00
|
|
|
*/
|
2002-12-06 06:14:41 +03:00
|
|
|
static int
|
2003-10-28 05:10:33 +03:00
|
|
|
extfs_read_archive (int fstype, const char *name, struct archive **pparc)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
FILE *extfsd;
|
|
|
|
char *buffer;
|
1998-09-13 14:40:43 +04:00
|
|
|
struct archive *current_archive;
|
1998-10-23 12:26:25 +04:00
|
|
|
char *current_file_name, *current_link_name;
|
|
|
|
|
2003-10-28 05:10:33 +03:00
|
|
|
if ((extfsd =
|
|
|
|
extfs_open_archive (fstype, name, ¤t_archive)) == NULL) {
|
2009-01-10 16:13:56 +03:00
|
|
|
message (D_ERROR, MSG_ERROR, _("Cannot open %s archive\n%s"),
|
2003-10-28 05:10:33 +03:00
|
|
|
extfs_prefixes[fstype], name);
|
1998-02-27 07:54:42 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
buffer = g_malloc (4096);
|
1998-02-27 07:54:42 +03:00
|
|
|
while (fgets (buffer, 4096, extfsd) != NULL) {
|
2002-12-06 06:14:41 +03:00
|
|
|
struct stat hstat;
|
|
|
|
|
|
|
|
current_link_name = NULL;
|
|
|
|
if (vfs_parse_ls_lga
|
|
|
|
(buffer, &hstat, ¤t_file_name, ¤t_link_name)) {
|
|
|
|
struct entry *entry, *pent;
|
|
|
|
struct inode *inode;
|
|
|
|
char *p, *q, *cfn = current_file_name;
|
|
|
|
|
|
|
|
if (*cfn) {
|
|
|
|
if (*cfn == '/')
|
|
|
|
cfn++;
|
|
|
|
p = strchr (cfn, 0);
|
|
|
|
if (p != cfn && *(p - 1) == '/')
|
|
|
|
*(p - 1) = 0;
|
|
|
|
p = strrchr (cfn, '/');
|
|
|
|
if (p == NULL) {
|
|
|
|
p = cfn;
|
|
|
|
q = strchr (cfn, 0);
|
|
|
|
} else {
|
|
|
|
*(p++) = 0;
|
|
|
|
q = cfn;
|
|
|
|
}
|
|
|
|
if (S_ISDIR (hstat.st_mode)
|
|
|
|
&& (!strcmp (p, ".") || !strcmp (p, "..")))
|
|
|
|
goto read_extfs_continue;
|
2003-10-28 05:10:33 +03:00
|
|
|
pent =
|
|
|
|
extfs_find_entry (current_archive->root_entry, q, 1,
|
|
|
|
0);
|
2002-12-06 06:14:41 +03:00
|
|
|
if (pent == NULL) {
|
|
|
|
/* FIXME: Should clean everything one day */
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
pclose (extfsd);
|
2009-01-10 16:13:56 +03:00
|
|
|
close_error_pipe (D_ERROR, _("Inconsistent extfs archive"));
|
2002-12-06 06:14:41 +03:00
|
|
|
return -1;
|
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
entry = g_new (struct entry, 1);
|
2009-02-06 01:40:32 +03:00
|
|
|
entry->name = g_strdup (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
entry->next_in_dir = NULL;
|
|
|
|
entry->dir = pent;
|
2004-12-27 15:12:31 +03:00
|
|
|
if (pent->inode->last_in_subdir) {
|
|
|
|
pent->inode->last_in_subdir->next_in_dir = entry;
|
|
|
|
pent->inode->last_in_subdir = entry;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
if (!S_ISLNK (hstat.st_mode) && current_link_name != NULL) {
|
2002-12-06 06:14:41 +03:00
|
|
|
pent =
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_find_entry (current_archive->root_entry,
|
2003-10-28 05:10:33 +03:00
|
|
|
current_link_name, 0, 0);
|
2002-12-06 06:14:41 +03:00
|
|
|
if (pent == NULL) {
|
|
|
|
/* FIXME: Should clean everything one day */
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
pclose (extfsd);
|
2009-01-10 16:13:56 +03:00
|
|
|
close_error_pipe (D_ERROR,
|
2002-12-06 06:14:41 +03:00
|
|
|
_("Inconsistent extfs archive"));
|
|
|
|
return -1;
|
|
|
|
} else {
|
1998-02-27 07:54:42 +03:00
|
|
|
entry->inode = pent->inode;
|
|
|
|
pent->inode->nlink++;
|
2002-12-06 06:14:41 +03:00
|
|
|
}
|
|
|
|
} else {
|
1999-01-21 01:01:11 +03:00
|
|
|
inode = g_new (struct inode, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
entry->inode = inode;
|
|
|
|
inode->local_filename = NULL;
|
2003-10-30 02:16:31 +03:00
|
|
|
inode->inode = (current_archive->inode_counter)++;
|
1998-02-27 07:54:42 +03:00
|
|
|
inode->nlink = 1;
|
|
|
|
inode->dev = current_archive->rdev;
|
|
|
|
inode->archive = current_archive;
|
|
|
|
inode->mode = hstat.st_mode;
|
2003-10-29 20:36:16 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_RDEV
|
1998-02-27 07:54:42 +03:00
|
|
|
inode->rdev = hstat.st_rdev;
|
|
|
|
#else
|
|
|
|
inode->rdev = 0;
|
2002-12-06 06:14:41 +03:00
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
inode->uid = hstat.st_uid;
|
|
|
|
inode->gid = hstat.st_gid;
|
|
|
|
inode->size = hstat.st_size;
|
|
|
|
inode->mtime = hstat.st_mtime;
|
|
|
|
inode->atime = hstat.st_atime;
|
|
|
|
inode->ctime = hstat.st_ctime;
|
2004-12-27 15:12:31 +03:00
|
|
|
inode->first_in_subdir = NULL;
|
|
|
|
inode->last_in_subdir = NULL;
|
2002-12-06 06:14:41 +03:00
|
|
|
if (current_link_name != NULL
|
|
|
|
&& S_ISLNK (hstat.st_mode)) {
|
|
|
|
inode->linkname = current_link_name;
|
|
|
|
current_link_name = NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
} else {
|
2002-12-06 06:14:41 +03:00
|
|
|
if (S_ISLNK (hstat.st_mode))
|
|
|
|
inode->mode &= ~S_IFLNK; /* You *DON'T* want to do this always */
|
|
|
|
inode->linkname = NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
if (S_ISDIR (hstat.st_mode))
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_make_dots (entry);
|
2002-12-06 06:14:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
read_extfs_continue:
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (current_file_name);
|
|
|
|
g_free (current_link_name);
|
2002-12-06 06:14:41 +03:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (buffer);
|
2002-12-26 00:42:59 +03:00
|
|
|
|
|
|
|
/* Check if extfs 'list' returned 0 */
|
|
|
|
if (pclose (extfsd) != 0) {
|
|
|
|
extfs_free (current_archive);
|
2009-01-10 16:13:56 +03:00
|
|
|
close_error_pipe (D_ERROR, _("Inconsistent extfs archive"));
|
2002-12-26 00:42:59 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-01-10 16:13:56 +03:00
|
|
|
close_error_pipe (D_ERROR, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
*pparc = current_archive;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
/*
|
2003-11-14 11:25:50 +03:00
|
|
|
* Dissect the path and create corresponding superblock. Note that inname
|
|
|
|
* can be changed and the result may point inside the original string.
|
1998-06-01 00:12:35 +04:00
|
|
|
*/
|
2002-12-06 05:14:28 +03:00
|
|
|
static char *
|
2005-02-22 21:35:22 +03:00
|
|
|
extfs_get_path_mangle (struct vfs_class *me, char *inname, struct archive **archive,
|
2003-11-14 11:25:50 +03:00
|
|
|
int do_not_open)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2003-10-28 05:10:33 +03:00
|
|
|
char *local, *op;
|
|
|
|
const char *archive_name;
|
1998-02-27 07:54:42 +03:00
|
|
|
int result = -1;
|
1998-09-13 14:40:43 +04:00
|
|
|
struct archive *parc;
|
1998-02-27 07:54:42 +03:00
|
|
|
int fstype;
|
2002-12-06 05:14:28 +03:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
archive_name = inname;
|
2002-12-06 05:14:28 +03:00
|
|
|
vfs_split (inname, &local, &op);
|
|
|
|
|
2004-12-07 02:27:23 +03:00
|
|
|
fstype = extfs_which (me, op);
|
2002-12-06 05:14:28 +03:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (fstype == -1)
|
2002-12-06 05:14:28 +03:00
|
|
|
return NULL;
|
2000-01-05 17:13:57 +03:00
|
|
|
if (!local)
|
2005-09-05 04:52:56 +04:00
|
|
|
local = inname + strlen (inname);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2002-12-06 05:14:28 +03:00
|
|
|
/*
|
|
|
|
* All filesystems should have some local archive, at least
|
1998-05-26 04:53:24 +04:00
|
|
|
* it can be '/'.
|
1998-02-27 07:54:42 +03:00
|
|
|
*/
|
|
|
|
for (parc = first_archive; parc != NULL; parc = parc->next)
|
2002-12-06 05:14:28 +03:00
|
|
|
if (parc->name) {
|
1998-05-26 04:53:24 +04:00
|
|
|
if (!strcmp (parc->name, archive_name)) {
|
2002-12-06 05:14:28 +03:00
|
|
|
vfs_stamp (&vfs_extfs_ops, (vfsid) parc);
|
1998-02-27 07:54:42 +03:00
|
|
|
goto return_success;
|
|
|
|
}
|
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
|
2003-10-28 05:10:33 +03:00
|
|
|
result =
|
|
|
|
do_not_open ? -1 : extfs_read_archive (fstype, archive_name,
|
|
|
|
&parc);
|
2002-12-06 05:14:28 +03:00
|
|
|
if (result == -1)
|
|
|
|
ERRNOR (EIO, NULL);
|
1998-05-26 04:53:24 +04:00
|
|
|
|
2002-12-06 05:14:28 +03:00
|
|
|
return_success:
|
1998-02-27 07:54:42 +03:00
|
|
|
*archive = parc;
|
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
2003-11-14 11:25:50 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dissect the path and create corresponding superblock.
|
|
|
|
* The result should be freed.
|
|
|
|
*/
|
2003-10-11 11:20:53 +04:00
|
|
|
static char *
|
2005-02-22 21:35:22 +03:00
|
|
|
extfs_get_path (struct vfs_class *me, const char *inname, struct archive **archive,
|
2003-11-14 11:25:50 +03:00
|
|
|
int do_not_open)
|
2003-10-11 11:20:53 +04:00
|
|
|
{
|
2009-02-06 01:40:32 +03:00
|
|
|
char *buf = g_strdup (inname);
|
2005-02-22 21:35:22 +03:00
|
|
|
char *res = extfs_get_path_mangle (me, buf, archive, do_not_open);
|
2003-10-11 11:20:53 +04:00
|
|
|
char *res2 = NULL;
|
|
|
|
if (res)
|
2009-02-06 01:40:32 +03:00
|
|
|
res2 = g_strdup (res);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (buf);
|
2003-10-11 11:20:53 +04:00
|
|
|
return res2;
|
|
|
|
}
|
|
|
|
|
2003-11-14 11:25:50 +03:00
|
|
|
|
|
|
|
/* Return allocated path (without leading slash) inside the archive */
|
2003-10-28 03:57:02 +03:00
|
|
|
static char *extfs_get_path_from_entry (struct entry *entry)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
struct list {
|
|
|
|
struct list *next;
|
|
|
|
char *name;
|
|
|
|
} *head, *p;
|
|
|
|
char *localpath;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
for (len = 0, head = 0; entry->dir; entry = entry->dir) {
|
1999-01-21 01:01:11 +03:00
|
|
|
p = g_new (struct list, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
p->next = head;
|
|
|
|
p->name = entry->name;
|
|
|
|
head = p;
|
|
|
|
len += strlen (entry->name) + 1;
|
|
|
|
}
|
1999-04-19 07:33:56 +04:00
|
|
|
|
|
|
|
if (len == 0)
|
2009-02-06 01:40:32 +03:00
|
|
|
return g_strdup ("");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
localpath = g_malloc (len);
|
1998-02-27 07:54:42 +03:00
|
|
|
*localpath = '\0';
|
2000-01-13 18:15:42 +03:00
|
|
|
while (head) {
|
1998-02-27 07:54:42 +03:00
|
|
|
strcat (localpath, head->name);
|
|
|
|
if (head->next)
|
|
|
|
strcat (localpath, "/");
|
|
|
|
p = head;
|
|
|
|
head = head->next;
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
return (localpath);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
struct loop_protect {
|
|
|
|
struct entry *entry;
|
|
|
|
struct loop_protect *next;
|
1998-02-27 07:54:42 +03:00
|
|
|
};
|
|
|
|
static int errloop;
|
|
|
|
static int notadir;
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static struct entry *
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_find_entry_int (struct entry *dir, char *name,
|
1998-09-13 14:40:43 +04:00
|
|
|
struct loop_protect *list, int make_dirs, int make_file);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static struct entry *
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_resolve_symlinks_int (struct entry *entry,
|
1998-09-13 14:40:43 +04:00
|
|
|
struct loop_protect *list)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct entry *pent;
|
|
|
|
struct loop_protect *looping;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (!S_ISLNK (entry->inode->mode))
|
|
|
|
return entry;
|
|
|
|
for (looping = list; looping != NULL; looping = looping->next)
|
|
|
|
if (entry == looping->entry) { /* Here we protect us against symlink looping */
|
|
|
|
errloop = 1;
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
looping = g_new (struct loop_protect, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
looping->entry = entry;
|
|
|
|
looping->next = list;
|
2003-10-28 03:57:02 +03:00
|
|
|
pent = extfs_find_entry_int (entry->dir, entry->inode->linkname, looping, 0, 0);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (looping);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (pent == NULL)
|
1998-09-13 14:40:43 +04:00
|
|
|
my_errno = ENOENT;
|
1998-02-27 07:54:42 +03:00
|
|
|
return pent;
|
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static struct entry *extfs_resolve_symlinks (struct entry *entry)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct entry *res;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
errloop = 0;
|
|
|
|
notadir = 0;
|
2003-10-28 03:57:02 +03:00
|
|
|
res = extfs_resolve_symlinks_int (entry, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (res == NULL) {
|
|
|
|
if (errloop)
|
1998-09-13 14:40:43 +04:00
|
|
|
my_errno = ELOOP;
|
1998-02-27 07:54:42 +03:00
|
|
|
else if (notadir)
|
1998-09-13 14:40:43 +04:00
|
|
|
my_errno = ENOTDIR;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2005-09-05 04:52:56 +04:00
|
|
|
static const char *
|
|
|
|
extfs_get_archive_name (struct archive *archive)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-09-05 04:52:56 +04:00
|
|
|
const char *archive_name;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (archive->local_name)
|
|
|
|
archive_name = archive->local_name;
|
|
|
|
else
|
|
|
|
archive_name = archive->name;
|
|
|
|
|
|
|
|
if (!archive_name || !*archive_name)
|
|
|
|
return "no_archive_name";
|
|
|
|
else
|
|
|
|
return archive_name;
|
|
|
|
}
|
|
|
|
|
2002-12-01 23:35:15 +03:00
|
|
|
/* Don't pass localname as NULL */
|
|
|
|
static int
|
|
|
|
extfs_cmd (const char *extfs_cmd, struct archive *archive,
|
|
|
|
struct entry *entry, const char *localname)
|
|
|
|
{
|
|
|
|
char *file;
|
|
|
|
char *quoted_file;
|
2003-03-11 03:01:56 +03:00
|
|
|
char *quoted_localname;
|
2002-12-01 23:35:15 +03:00
|
|
|
char *archive_name;
|
|
|
|
char *mc_extfsdir;
|
|
|
|
char *cmd;
|
|
|
|
int retval;
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
file = extfs_get_path_from_entry (entry);
|
2002-12-01 23:35:15 +03:00
|
|
|
quoted_file = name_quote (file, 0);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (file);
|
2003-10-28 03:57:02 +03:00
|
|
|
archive_name = name_quote (extfs_get_archive_name (archive), 0);
|
2003-03-11 03:01:56 +03:00
|
|
|
quoted_localname = name_quote (localname, 0);
|
2002-12-01 23:35:15 +03:00
|
|
|
|
2009-02-06 13:17:03 +03:00
|
|
|
mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
|
2002-12-01 23:35:15 +03:00
|
|
|
cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype],
|
|
|
|
extfs_cmd, archive_name, " ", quoted_file, " ",
|
2004-09-24 19:08:21 +04:00
|
|
|
quoted_localname, (char *) NULL);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (quoted_file);
|
|
|
|
g_free (quoted_localname);
|
|
|
|
g_free (mc_extfsdir);
|
|
|
|
g_free (archive_name);
|
2002-12-01 23:35:15 +03:00
|
|
|
|
|
|
|
open_error_pipe ();
|
|
|
|
retval = my_system (EXECUTE_AS_SHELL, shell, cmd);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (cmd);
|
2009-01-10 16:13:56 +03:00
|
|
|
close_error_pipe (D_ERROR, NULL);
|
2002-12-01 23:35:15 +03:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2002-12-06 17:44:51 +03:00
|
|
|
static void
|
2004-12-07 02:27:23 +03:00
|
|
|
extfs_run (struct vfs_class *me, const char *file)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-05-21 07:24:50 +04:00
|
|
|
struct archive *archive = NULL;
|
1999-01-21 01:01:11 +03:00
|
|
|
char *p, *q, *archive_name, *mc_extfsdir;
|
|
|
|
char *cmd;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
if ((p = extfs_get_path (me, file, &archive, 0)) == NULL)
|
1998-02-27 07:54:42 +03:00
|
|
|
return;
|
1998-05-26 04:53:24 +04:00
|
|
|
q = name_quote (p, 0);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (p);
|
2002-12-06 17:44:51 +03:00
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
archive_name = name_quote (extfs_get_archive_name (archive), 0);
|
2009-02-06 13:17:03 +03:00
|
|
|
mc_extfsdir = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR);
|
2002-12-06 17:44:51 +03:00
|
|
|
cmd = g_strconcat (mc_extfsdir, extfs_prefixes[archive->fstype],
|
2004-09-24 19:08:21 +04:00
|
|
|
" run ", archive_name, " ", q, (char *) NULL);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mc_extfsdir);
|
|
|
|
g_free (archive_name);
|
|
|
|
g_free (q);
|
2002-12-06 17:44:51 +03:00
|
|
|
shell_execute (cmd, 0);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (cmd);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2002-12-06 17:44:51 +03:00
|
|
|
static void *
|
2003-10-28 05:10:33 +03:00
|
|
|
extfs_open (struct vfs_class *me, const char *file, int flags, int mode)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct pseudofile *extfs_info;
|
2005-05-21 07:24:50 +04:00
|
|
|
struct archive *archive = NULL;
|
1998-05-26 04:53:24 +04:00
|
|
|
char *q;
|
1998-09-13 14:40:43 +04:00
|
|
|
struct entry *entry;
|
1998-02-27 07:54:42 +03:00
|
|
|
int local_handle;
|
2002-02-20 00:32:24 +03:00
|
|
|
int created = 0;
|
2002-12-06 17:44:51 +03:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
if ((q = extfs_get_path (me, file, &archive, 0)) == NULL)
|
1998-02-27 07:54:42 +03:00
|
|
|
return NULL;
|
2003-10-28 03:57:02 +03:00
|
|
|
entry = extfs_find_entry (archive->root_entry, q, 0, 0);
|
2002-02-20 00:32:24 +03:00
|
|
|
if (entry == NULL && (flags & O_CREAT)) {
|
|
|
|
/* Create new entry */
|
2003-10-28 03:57:02 +03:00
|
|
|
entry = extfs_find_entry (archive->root_entry, q, 0, 1);
|
2002-02-20 00:32:24 +03:00
|
|
|
created = (entry != NULL);
|
|
|
|
}
|
2003-11-14 11:25:50 +03:00
|
|
|
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (q);
|
1998-05-26 04:53:24 +04:00
|
|
|
if (entry == NULL)
|
2002-12-06 17:44:51 +03:00
|
|
|
return NULL;
|
2003-10-28 03:57:02 +03:00
|
|
|
if ((entry = extfs_resolve_symlinks (entry)) == NULL)
|
1998-02-27 07:54:42 +03:00
|
|
|
return NULL;
|
2002-12-01 23:35:15 +03:00
|
|
|
|
2002-12-06 17:44:51 +03:00
|
|
|
if (S_ISDIR (entry->inode->mode))
|
|
|
|
ERRNOR (EISDIR, NULL);
|
2002-12-01 23:35:15 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (entry->inode->local_filename == NULL) {
|
2003-10-29 03:50:36 +03:00
|
|
|
char *local_filename;
|
1998-12-15 18:57:39 +03:00
|
|
|
|
2003-10-29 03:50:36 +03:00
|
|
|
local_handle = vfs_mkstemps (&local_filename, "extfs", entry->name);
|
2002-12-01 23:35:15 +03:00
|
|
|
|
2002-12-06 17:44:51 +03:00
|
|
|
if (local_handle == -1)
|
2002-12-01 23:35:15 +03:00
|
|
|
return NULL;
|
2002-12-06 17:44:51 +03:00
|
|
|
close (local_handle);
|
2002-12-01 23:35:15 +03:00
|
|
|
|
2002-12-07 05:37:58 +03:00
|
|
|
if (!created && !(flags & O_TRUNC)
|
|
|
|
&& extfs_cmd (" copyout ", archive, entry, local_filename)) {
|
2002-12-06 17:44:51 +03:00
|
|
|
unlink (local_filename);
|
|
|
|
free (local_filename);
|
2002-12-01 23:35:15 +03:00
|
|
|
my_errno = EIO;
|
|
|
|
return NULL;
|
1998-12-15 18:57:39 +03:00
|
|
|
}
|
2002-12-06 17:44:51 +03:00
|
|
|
entry->inode->local_filename = local_filename;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2002-12-01 23:35:15 +03:00
|
|
|
|
2003-02-26 20:43:18 +03:00
|
|
|
local_handle =
|
|
|
|
open (entry->inode->local_filename, NO_LINEAR (flags), mode);
|
2002-12-06 17:44:51 +03:00
|
|
|
if (local_handle == -1)
|
|
|
|
ERRNOR (EIO, NULL);
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
extfs_info = g_new (struct pseudofile, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
extfs_info->archive = archive;
|
|
|
|
extfs_info->entry = entry;
|
2002-02-20 00:32:24 +03:00
|
|
|
extfs_info->has_changed = created;
|
1998-02-27 07:54:42 +03:00
|
|
|
extfs_info->local_handle = local_handle;
|
|
|
|
|
|
|
|
/* i.e. we had no open files and now we have one */
|
2003-11-27 00:10:42 +03:00
|
|
|
vfs_rmstamp (&vfs_extfs_ops, (vfsid) archive);
|
1998-02-27 07:54:42 +03:00
|
|
|
archive->fd_usage++;
|
|
|
|
return extfs_info;
|
|
|
|
}
|
|
|
|
|
2009-01-13 21:00:25 +03:00
|
|
|
static ssize_t extfs_read (void *data, char *buffer, int count)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct pseudofile *file = (struct pseudofile *)data;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
return read (file->local_handle, buffer, count);
|
|
|
|
}
|
|
|
|
|
2003-10-11 20:54:46 +04:00
|
|
|
static int
|
|
|
|
extfs_close (void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct pseudofile *file;
|
2003-10-11 20:54:46 +04:00
|
|
|
int errno_code = 0;
|
|
|
|
file = (struct pseudofile *) data;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
close (file->local_handle);
|
|
|
|
|
|
|
|
/* Commit the file if it has changed */
|
2002-12-01 23:35:15 +03:00
|
|
|
if (file->has_changed) {
|
2003-10-11 20:54:46 +04:00
|
|
|
if (extfs_cmd
|
|
|
|
(" copyin ", file->archive, file->entry,
|
|
|
|
file->entry->inode->local_filename))
|
1998-02-27 07:54:42 +03:00
|
|
|
errno_code = EIO;
|
2000-01-13 18:15:42 +03:00
|
|
|
{
|
|
|
|
struct stat file_status;
|
2003-10-11 20:54:46 +04:00
|
|
|
if (stat (file->entry->inode->local_filename, &file_status) !=
|
|
|
|
0)
|
2002-12-01 23:35:15 +03:00
|
|
|
errno_code = EIO;
|
2000-01-13 18:15:42 +03:00
|
|
|
else
|
|
|
|
file->entry->inode->size = file_status.st_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
file->entry->inode->mtime = time (NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2002-12-01 23:35:15 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
file->archive->fd_usage--;
|
2003-11-27 00:10:42 +03:00
|
|
|
if (!file->archive->fd_usage)
|
|
|
|
vfs_stamp_create (&vfs_extfs_ops, file->archive);
|
2002-12-05 20:05:27 +03:00
|
|
|
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (data);
|
2003-10-11 20:54:46 +04:00
|
|
|
if (errno_code)
|
|
|
|
ERRNOR (EIO, -1);
|
1998-09-18 15:02:04 +04:00
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
#define RECORDSIZE 512
|
2001-07-10 18:19:11 +04:00
|
|
|
|
|
|
|
static struct entry*
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_find_entry_int (struct entry *dir, char *name,
|
2001-07-10 18:19:11 +04:00
|
|
|
struct loop_protect *list, int make_dirs, int make_file)
|
|
|
|
{
|
|
|
|
struct entry *pent, *pdir;
|
|
|
|
char *p, *q, *name_end;
|
|
|
|
char c;
|
|
|
|
|
|
|
|
if (*name == '/') { /* Handle absolute paths */
|
|
|
|
name++;
|
|
|
|
dir = dir->inode->archive->root_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
pent = dir;
|
|
|
|
p = name;
|
|
|
|
name_end = name + strlen (name);
|
|
|
|
q = strchr (p, '/');
|
|
|
|
c = '/';
|
|
|
|
if (!q)
|
|
|
|
q = strchr (p, 0);
|
|
|
|
|
|
|
|
for (; pent != NULL && c && *p; ){
|
|
|
|
c = *q;
|
|
|
|
*q = 0;
|
|
|
|
|
|
|
|
if (strcmp (p, ".")){
|
|
|
|
if (!strcmp (p, ".."))
|
|
|
|
pent = pent->dir;
|
|
|
|
else {
|
2003-10-28 03:57:02 +03:00
|
|
|
if ((pent = extfs_resolve_symlinks_int (pent, list))==NULL){
|
2001-07-10 18:19:11 +04:00
|
|
|
*q = c;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!S_ISDIR (pent->inode->mode)){
|
|
|
|
*q = c;
|
|
|
|
notadir = 1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
pdir = pent;
|
|
|
|
for (pent = pent->inode->first_in_subdir; pent; pent = pent->next_in_dir)
|
|
|
|
/* Hack: I keep the original semanthic unless
|
|
|
|
q+1 would break in the strchr */
|
|
|
|
if (!strcmp (pent->name, p)){
|
|
|
|
if (q + 1 > name_end){
|
|
|
|
*q = c;
|
|
|
|
notadir = !S_ISDIR (pent->inode->mode);
|
|
|
|
return pent;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-12-05 20:05:27 +03:00
|
|
|
|
2001-07-10 18:19:11 +04:00
|
|
|
/* When we load archive, we create automagically
|
|
|
|
* non-existant directories
|
|
|
|
*/
|
|
|
|
if (pent == NULL && make_dirs) {
|
2003-10-28 03:57:02 +03:00
|
|
|
pent = extfs_generate_entry (dir->inode->archive, p, pdir, S_IFDIR | 0777);
|
2001-07-10 18:19:11 +04:00
|
|
|
}
|
|
|
|
if (pent == NULL && make_file) {
|
2003-10-28 03:57:02 +03:00
|
|
|
pent = extfs_generate_entry (dir->inode->archive, p, pdir, S_IFREG | 0666);
|
2001-07-10 18:19:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Next iteration */
|
|
|
|
*q = c;
|
|
|
|
p = q + 1;
|
|
|
|
q = strchr (p, '/');
|
|
|
|
if (!q)
|
|
|
|
q = strchr (p, 0);
|
|
|
|
}
|
|
|
|
if (pent == NULL)
|
|
|
|
my_errno = ENOENT;
|
|
|
|
return pent;
|
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static struct entry *extfs_find_entry (struct entry *dir, char *name, int make_dirs, int make_file)
|
2001-07-10 18:19:11 +04:00
|
|
|
{
|
|
|
|
struct entry *res;
|
|
|
|
|
|
|
|
errloop = 0;
|
|
|
|
notadir = 0;
|
2003-10-28 03:57:02 +03:00
|
|
|
res = extfs_find_entry_int (dir, name, NULL, make_dirs, make_file);
|
2001-07-10 18:19:11 +04:00
|
|
|
if (res == NULL) {
|
|
|
|
if (errloop)
|
|
|
|
my_errno = ELOOP;
|
|
|
|
else if (notadir)
|
|
|
|
my_errno = ENOTDIR;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static int extfs_errno (struct vfs_class *me)
|
2001-07-10 18:19:11 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2001-07-10 18:19:11 +04:00
|
|
|
return my_errno;
|
|
|
|
}
|
|
|
|
|
2003-11-13 11:29:37 +03:00
|
|
|
static void * extfs_opendir (struct vfs_class *me, const char *dirname)
|
2001-07-10 18:19:11 +04:00
|
|
|
{
|
2005-05-21 07:24:50 +04:00
|
|
|
struct archive *archive = NULL;
|
2001-07-10 18:19:11 +04:00
|
|
|
char *q;
|
|
|
|
struct entry *entry;
|
|
|
|
struct entry **info;
|
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
if ((q = extfs_get_path (me, dirname, &archive, 0)) == NULL)
|
2001-07-10 18:19:11 +04:00
|
|
|
return NULL;
|
2003-10-28 03:57:02 +03:00
|
|
|
entry = extfs_find_entry (archive->root_entry, q, 0, 0);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (q);
|
2001-07-10 18:19:11 +04:00
|
|
|
if (entry == NULL)
|
|
|
|
return NULL;
|
2003-10-28 03:57:02 +03:00
|
|
|
if ((entry = extfs_resolve_symlinks (entry)) == NULL)
|
2001-07-10 18:19:11 +04:00
|
|
|
return NULL;
|
|
|
|
if (!S_ISDIR (entry->inode->mode)) ERRNOR (ENOTDIR, NULL);
|
|
|
|
|
|
|
|
info = g_new (struct entry *, 2);
|
|
|
|
info[0] = entry->inode->first_in_subdir;
|
|
|
|
info[1] = entry->inode->first_in_subdir;
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static void * extfs_readdir(void *data)
|
2001-07-10 18:19:11 +04:00
|
|
|
{
|
2002-08-16 00:29:34 +04:00
|
|
|
static union vfs_dirent dir;
|
2001-07-10 18:19:11 +04:00
|
|
|
struct entry **info = (struct entry **) data;
|
|
|
|
|
|
|
|
if (!*info)
|
2002-08-16 01:15:17 +04:00
|
|
|
return NULL;
|
2001-07-10 18:19:11 +04:00
|
|
|
|
2004-08-26 12:47:50 +04:00
|
|
|
g_strlcpy(dir.dent.d_name, (*info)->name, MC_MAXPATHLEN);
|
2002-08-16 00:29:34 +04:00
|
|
|
|
2002-08-16 01:15:17 +04:00
|
|
|
compute_namelen(&dir.dent);
|
2001-07-10 18:19:11 +04:00
|
|
|
*info = (*info)->next_in_dir;
|
2002-08-16 01:15:17 +04:00
|
|
|
|
|
|
|
return (void *) &dir;
|
2001-07-10 18:19:11 +04:00
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static int extfs_closedir (void *data)
|
2001-07-10 18:19:11 +04:00
|
|
|
{
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (data);
|
2001-07-10 18:19:11 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-12-29 10:32:41 +03:00
|
|
|
static void extfs_stat_move (struct stat *buf, const struct inode *inode)
|
2001-07-10 18:19:11 +04:00
|
|
|
{
|
|
|
|
buf->st_dev = inode->dev;
|
|
|
|
buf->st_ino = inode->inode;
|
|
|
|
buf->st_mode = inode->mode;
|
|
|
|
buf->st_nlink = inode->nlink;
|
|
|
|
buf->st_uid = inode->uid;
|
|
|
|
buf->st_gid = inode->gid;
|
2003-10-29 20:36:16 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_RDEV
|
2001-07-10 18:19:11 +04:00
|
|
|
buf->st_rdev = inode->rdev;
|
|
|
|
#endif
|
|
|
|
buf->st_size = inode->size;
|
2003-10-29 20:36:16 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
|
2001-07-10 18:19:11 +04:00
|
|
|
buf->st_blksize = RECORDSIZE;
|
|
|
|
#endif
|
2003-10-29 20:36:16 +03:00
|
|
|
#ifdef HAVE_STRUCT_STAT_ST_BLOCKS
|
2001-07-10 18:19:11 +04:00
|
|
|
buf->st_blocks = (inode->size + RECORDSIZE - 1) / RECORDSIZE;
|
|
|
|
#endif
|
|
|
|
buf->st_atime = inode->atime;
|
|
|
|
buf->st_mtime = inode->mtime;
|
|
|
|
buf->st_ctime = inode->ctime;
|
|
|
|
}
|
|
|
|
|
2004-12-29 10:32:41 +03:00
|
|
|
static int
|
|
|
|
extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf,
|
|
|
|
int resolve)
|
2001-07-10 18:19:11 +04:00
|
|
|
{
|
|
|
|
struct archive *archive;
|
|
|
|
char *q;
|
|
|
|
struct entry *entry;
|
2009-02-06 01:40:32 +03:00
|
|
|
char *path2 = g_strdup (path);
|
2004-08-24 19:56:24 +04:00
|
|
|
int result = -1;
|
2001-07-10 18:19:11 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
if ((q = extfs_get_path_mangle (me, path2, &archive, 0)) == NULL)
|
2004-08-24 19:56:24 +04:00
|
|
|
goto cleanup;
|
2003-10-28 03:57:02 +03:00
|
|
|
entry = extfs_find_entry (archive->root_entry, q, 0, 0);
|
2001-07-10 18:19:11 +04:00
|
|
|
if (entry == NULL)
|
2004-08-24 19:56:24 +04:00
|
|
|
goto cleanup;
|
2003-10-28 03:57:02 +03:00
|
|
|
if (resolve && (entry = extfs_resolve_symlinks (entry)) == NULL)
|
2004-08-24 19:56:24 +04:00
|
|
|
goto cleanup;
|
2004-12-29 10:32:41 +03:00
|
|
|
extfs_stat_move (buf, entry->inode);
|
2004-08-24 19:56:24 +04:00
|
|
|
result = 0;
|
|
|
|
cleanup:
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (path2);
|
2004-08-24 19:56:24 +04:00
|
|
|
return result;
|
2001-07-10 18:19:11 +04:00
|
|
|
}
|
|
|
|
|
2004-08-17 00:26:42 +04:00
|
|
|
static int extfs_stat (struct vfs_class *me, const char *path, struct stat *buf)
|
2001-07-10 18:19:11 +04:00
|
|
|
{
|
2004-12-07 02:27:23 +03:00
|
|
|
return extfs_internal_stat (me, path, buf, 1);
|
2001-07-10 18:19:11 +04:00
|
|
|
}
|
|
|
|
|
2004-08-17 00:26:42 +04:00
|
|
|
static int extfs_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
2001-07-10 18:19:11 +04:00
|
|
|
{
|
2004-12-07 02:27:23 +03:00
|
|
|
return extfs_internal_stat (me, path, buf, 0);
|
2001-07-10 18:19:11 +04:00
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static int extfs_fstat (void *data, struct stat *buf)
|
2001-07-10 18:19:11 +04:00
|
|
|
{
|
|
|
|
struct pseudofile *file = (struct pseudofile *)data;
|
|
|
|
|
2004-12-29 10:32:41 +03:00
|
|
|
extfs_stat_move (buf, file->entry->inode);
|
2001-07-10 18:19:11 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-08-30 02:48:25 +04:00
|
|
|
static int
|
2004-09-02 17:57:59 +04:00
|
|
|
extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
2001-07-10 18:19:11 +04:00
|
|
|
{
|
|
|
|
struct archive *archive;
|
|
|
|
char *q;
|
2004-09-02 04:09:02 +04:00
|
|
|
size_t len;
|
2001-07-10 18:19:11 +04:00
|
|
|
struct entry *entry;
|
2009-02-06 01:40:32 +03:00
|
|
|
char *mpath = g_strdup (path);
|
2004-08-17 02:15:28 +04:00
|
|
|
int result = -1;
|
2001-07-10 18:19:11 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
if ((q = extfs_get_path_mangle (me, mpath, &archive, 0)) == NULL)
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
2003-10-28 03:57:02 +03:00
|
|
|
entry = extfs_find_entry (archive->root_entry, q, 0, 0);
|
2001-07-10 18:19:11 +04:00
|
|
|
if (entry == NULL)
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
|
|
|
if (!S_ISLNK (entry->inode->mode)) {
|
|
|
|
me->verrno = EINVAL;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2004-09-02 04:09:02 +04:00
|
|
|
len = strlen (entry->inode->linkname);
|
2004-09-02 17:57:59 +04:00
|
|
|
if (size < len)
|
|
|
|
len = size;
|
|
|
|
/* readlink() does not append a NUL character to buf */
|
|
|
|
memcpy (buf, entry->inode->linkname, result = len);
|
2004-08-17 02:15:28 +04:00
|
|
|
cleanup:
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mpath);
|
2004-08-17 02:15:28 +04:00
|
|
|
return result;
|
2001-07-10 18:19:11 +04:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2004-08-17 01:36:39 +04:00
|
|
|
static int extfs_chmod (struct vfs_class *me, const char *path, int mode)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
(void) path;
|
|
|
|
(void) mode;
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-13 21:00:25 +03:00
|
|
|
static ssize_t extfs_write (void *data, const char *buf, int nbyte)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct pseudofile *file = (struct pseudofile *)data;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
file->has_changed = 1;
|
|
|
|
return write (file->local_handle, buf, nbyte);
|
|
|
|
}
|
|
|
|
|
2004-08-17 02:15:28 +04:00
|
|
|
static int extfs_unlink (struct vfs_class *me, const char *file)
|
1999-04-13 06:05:15 +04:00
|
|
|
{
|
|
|
|
struct archive *archive;
|
2009-02-06 01:40:32 +03:00
|
|
|
char *q, *mpath = g_strdup (file);
|
1999-04-13 06:05:15 +04:00
|
|
|
struct entry *entry;
|
2004-08-17 02:15:28 +04:00
|
|
|
int result = -1;
|
1999-04-13 06:05:15 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
if ((q = extfs_get_path_mangle (me, mpath, &archive, 0)) == NULL)
|
2004-12-29 10:32:41 +03:00
|
|
|
goto cleanup;
|
2003-10-28 03:57:02 +03:00
|
|
|
entry = extfs_find_entry (archive->root_entry, q, 0, 0);
|
1999-04-13 06:05:15 +04:00
|
|
|
if (entry == NULL)
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
2003-10-28 03:57:02 +03:00
|
|
|
if ((entry = extfs_resolve_symlinks (entry)) == NULL)
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
|
|
|
if (S_ISDIR (entry->inode->mode)) {
|
|
|
|
me->verrno = EISDIR;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2002-12-01 23:35:15 +03:00
|
|
|
if (extfs_cmd (" rm ", archive, entry, "")){
|
2000-01-13 18:15:42 +03:00
|
|
|
my_errno = EIO;
|
2004-08-24 19:56:24 +04:00
|
|
|
goto cleanup;
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_remove_entry (entry);
|
2004-08-17 02:15:28 +04:00
|
|
|
result = 0;
|
|
|
|
cleanup:
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mpath);
|
2004-08-17 02:15:28 +04:00
|
|
|
return result;
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
|
|
|
|
2004-08-17 02:15:28 +04:00
|
|
|
static int extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
1999-04-13 06:05:15 +04:00
|
|
|
{
|
|
|
|
struct archive *archive;
|
2009-02-06 01:40:32 +03:00
|
|
|
char *q, *mpath = g_strdup(path);
|
1999-04-13 06:05:15 +04:00
|
|
|
struct entry *entry;
|
2004-08-17 02:15:28 +04:00
|
|
|
int result = -1;
|
1999-04-13 06:05:15 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) mode;
|
|
|
|
|
|
|
|
if ((q = extfs_get_path_mangle (me, mpath, &archive, 0)) == NULL)
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
2003-10-28 03:57:02 +03:00
|
|
|
entry = extfs_find_entry (archive->root_entry, q, 0, 0);
|
2004-08-17 02:15:28 +04:00
|
|
|
if (entry != NULL) {
|
|
|
|
me->verrno = EEXIST;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2003-10-28 03:57:02 +03:00
|
|
|
entry = extfs_find_entry (archive->root_entry, q, 1, 0);
|
1999-04-13 06:05:15 +04:00
|
|
|
if (entry == NULL)
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
2003-10-28 03:57:02 +03:00
|
|
|
if ((entry = extfs_resolve_symlinks (entry)) == NULL)
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
|
|
|
if (!S_ISDIR (entry->inode->mode)) {
|
|
|
|
me->verrno = ENOTDIR;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
1999-04-13 06:05:15 +04:00
|
|
|
|
2002-12-01 23:35:15 +03:00
|
|
|
if (extfs_cmd (" mkdir ", archive, entry, "")){
|
2000-01-13 18:15:42 +03:00
|
|
|
my_errno = EIO;
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_remove_entry (entry);
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
2004-08-17 02:15:28 +04:00
|
|
|
result = 0;
|
|
|
|
cleanup:
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mpath);
|
2004-08-17 02:15:28 +04:00
|
|
|
return result;
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
|
|
|
|
2004-08-17 02:15:28 +04:00
|
|
|
static int extfs_rmdir (struct vfs_class *me, const char *path)
|
1999-04-13 06:05:15 +04:00
|
|
|
{
|
|
|
|
struct archive *archive;
|
2009-02-06 01:40:32 +03:00
|
|
|
char *q, *mpath = g_strdup(path);
|
1999-04-13 06:05:15 +04:00
|
|
|
struct entry *entry;
|
2004-08-17 02:15:28 +04:00
|
|
|
int result = -1;
|
1999-04-13 06:05:15 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
if ((q = extfs_get_path_mangle (me, mpath, &archive, 0)) == NULL)
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
2003-10-28 03:57:02 +03:00
|
|
|
entry = extfs_find_entry (archive->root_entry, q, 0, 0);
|
1999-04-13 06:05:15 +04:00
|
|
|
if (entry == NULL)
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
2003-10-28 03:57:02 +03:00
|
|
|
if ((entry = extfs_resolve_symlinks (entry)) == NULL)
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
|
|
|
if (!S_ISDIR (entry->inode->mode)) {
|
|
|
|
me->verrno = ENOTDIR;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
1999-04-13 06:05:15 +04:00
|
|
|
|
2002-12-01 23:35:15 +03:00
|
|
|
if (extfs_cmd (" rmdir ", archive, entry, "")){
|
2000-01-13 18:15:42 +03:00
|
|
|
my_errno = EIO;
|
2004-08-17 02:15:28 +04:00
|
|
|
goto cleanup;
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_remove_entry (entry);
|
2004-08-17 02:15:28 +04:00
|
|
|
result = 0;
|
|
|
|
cleanup:
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mpath);
|
2004-08-17 02:15:28 +04:00
|
|
|
return result;
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
|
|
|
|
2003-11-14 11:25:50 +03:00
|
|
|
static int
|
|
|
|
extfs_chdir (struct vfs_class *me, const char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-05-21 07:24:50 +04:00
|
|
|
struct archive *archive = NULL;
|
2000-01-13 18:15:42 +03:00
|
|
|
char *q;
|
1998-09-13 14:40:43 +04:00
|
|
|
struct entry *entry;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
my_errno = ENOTDIR;
|
2005-02-22 21:35:22 +03:00
|
|
|
if ((q = extfs_get_path (me, path, &archive, 0)) == NULL)
|
1998-02-27 07:54:42 +03:00
|
|
|
return -1;
|
2003-10-28 03:57:02 +03:00
|
|
|
entry = extfs_find_entry (archive->root_entry, q, 0, 0);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (q);
|
1998-05-26 04:53:24 +04:00
|
|
|
if (!entry)
|
2003-11-14 11:25:50 +03:00
|
|
|
return -1;
|
2003-10-28 03:57:02 +03:00
|
|
|
entry = extfs_resolve_symlinks (entry);
|
1998-05-26 04:53:24 +04:00
|
|
|
if ((!entry) || (!S_ISDIR (entry->inode->mode)))
|
2003-11-14 11:25:50 +03:00
|
|
|
return -1;
|
1998-09-13 14:40:43 +04:00
|
|
|
my_errno = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-13 21:00:25 +03:00
|
|
|
static off_t extfs_lseek (void *data, off_t offset, int whence)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct pseudofile *file = (struct pseudofile *) data;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
return lseek (file->local_handle, offset, whence);
|
|
|
|
}
|
|
|
|
|
2003-11-27 00:10:42 +03:00
|
|
|
static vfsid
|
|
|
|
extfs_getid (struct vfs_class *me, const char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-05-21 07:24:50 +04:00
|
|
|
struct archive *archive = NULL;
|
1998-06-01 00:12:35 +04:00
|
|
|
char *p;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
if (!(p = extfs_get_path (me, path, &archive, 1)))
|
2003-11-13 02:00:16 +03:00
|
|
|
return NULL;
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (p);
|
2003-11-27 00:10:42 +03:00
|
|
|
return (vfsid) archive;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int extfs_nothingisopen (vfsid id)
|
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
if (((struct archive *)id)->fd_usage <= 0)
|
1998-02-27 07:54:42 +03:00
|
|
|
return 1;
|
2000-01-13 18:15:42 +03:00
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static void extfs_remove_entry (struct entry *e)
|
1999-04-13 06:05:15 +04:00
|
|
|
{
|
|
|
|
int i = --(e->inode->nlink);
|
|
|
|
struct entry *pe, *ent, *prev;
|
|
|
|
|
|
|
|
if (S_ISDIR (e->inode->mode) && e->inode->first_in_subdir != NULL) {
|
|
|
|
struct entry *f = e->inode->first_in_subdir;
|
|
|
|
e->inode->first_in_subdir = NULL;
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_remove_entry (f);
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
|
|
|
pe = e->dir;
|
|
|
|
if (e == pe->inode->first_in_subdir)
|
2000-01-13 18:15:42 +03:00
|
|
|
pe->inode->first_in_subdir = e->next_in_dir;
|
1999-04-13 06:05:15 +04:00
|
|
|
|
|
|
|
prev = NULL;
|
|
|
|
for (ent = pe->inode->first_in_subdir; ent && ent->next_in_dir;
|
|
|
|
ent = ent->next_in_dir)
|
|
|
|
if (e == ent->next_in_dir) {
|
2000-01-13 18:15:42 +03:00
|
|
|
prev = ent;
|
|
|
|
break;
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
|
|
|
if (prev)
|
2000-01-13 18:15:42 +03:00
|
|
|
prev->next_in_dir = e->next_in_dir;
|
1999-04-13 06:05:15 +04:00
|
|
|
if (e == pe->inode->last_in_subdir)
|
2000-01-13 18:15:42 +03:00
|
|
|
pe->inode->last_in_subdir = prev;
|
1999-04-13 06:05:15 +04:00
|
|
|
|
|
|
|
if (i <= 0) {
|
|
|
|
if (e->inode->local_filename != NULL) {
|
|
|
|
unlink (e->inode->local_filename);
|
1999-04-22 08:36:11 +04:00
|
|
|
free (e->inode->local_filename);
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (e->inode->linkname);
|
|
|
|
g_free (e->inode);
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
|
|
|
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (e->name);
|
|
|
|
g_free (e);
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
|
|
|
|
2003-10-28 03:57:02 +03:00
|
|
|
static void extfs_free_entry (struct entry *e)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int i = --(e->inode->nlink);
|
|
|
|
if (S_ISDIR (e->inode->mode) && e->inode->first_in_subdir != NULL) {
|
1998-09-13 14:40:43 +04:00
|
|
|
struct entry *f = e->inode->first_in_subdir;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
e->inode->first_in_subdir = NULL;
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_free_entry (f);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
if (i <= 0) {
|
|
|
|
if (e->inode->local_filename != NULL) {
|
|
|
|
unlink (e->inode->local_filename);
|
1999-04-22 08:36:11 +04:00
|
|
|
free (e->inode->local_filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (e->inode->linkname);
|
|
|
|
g_free (e->inode);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
if (e->next_in_dir != NULL)
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_free_entry (e->next_in_dir);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (e->name);
|
|
|
|
g_free (e);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void extfs_free (vfsid id)
|
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct archive *parc;
|
|
|
|
struct archive *archive = (struct archive *)id;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (archive == first_archive) {
|
|
|
|
first_archive = archive->next;
|
|
|
|
} else {
|
|
|
|
for (parc = first_archive; parc != NULL; parc = parc->next)
|
2006-03-23 18:00:50 +03:00
|
|
|
if (parc->next == archive) {
|
|
|
|
parc->next = archive->next;
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
2006-03-23 18:00:50 +03:00
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2003-10-28 03:57:02 +03:00
|
|
|
extfs_free_archive (archive);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2003-10-28 05:10:33 +03:00
|
|
|
static char *
|
|
|
|
extfs_getlocalcopy (struct vfs_class *me, const char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2003-10-28 05:10:33 +03:00
|
|
|
struct pseudofile *fp =
|
|
|
|
(struct pseudofile *) extfs_open (me, path, O_RDONLY, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
char *p;
|
2003-10-28 05:10:33 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (fp == NULL)
|
2003-10-28 05:10:33 +03:00
|
|
|
return NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (fp->entry->inode->local_filename == NULL) {
|
2003-10-28 05:10:33 +03:00
|
|
|
extfs_close ((void *) fp);
|
|
|
|
return NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2009-02-06 01:40:32 +03:00
|
|
|
p = g_strdup (fp->entry->inode->local_filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
fp->archive->fd_usage++;
|
|
|
|
extfs_close ((void *) fp);
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2003-10-28 05:10:33 +03:00
|
|
|
static int
|
2003-10-29 00:52:06 +03:00
|
|
|
extfs_ungetlocalcopy (struct vfs_class *me, const char *path,
|
|
|
|
const char *local, int has_changed)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2003-10-28 05:10:33 +03:00
|
|
|
struct pseudofile *fp =
|
|
|
|
(struct pseudofile *) extfs_open (me, path, O_RDONLY, 0);
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (fp == NULL)
|
2003-10-28 05:10:33 +03:00
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!strcmp (fp->entry->inode->local_filename, local)) {
|
2003-10-28 05:10:33 +03:00
|
|
|
fp->archive->fd_usage--;
|
|
|
|
fp->has_changed |= has_changed;
|
|
|
|
extfs_close ((void *) fp);
|
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
} else {
|
2003-10-28 05:10:33 +03:00
|
|
|
/* Should not happen */
|
|
|
|
extfs_close ((void *) fp);
|
2003-10-28 10:09:39 +03:00
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-12 04:24:00 +04:00
|
|
|
static int extfs_init (struct vfs_class *me)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-08-27 00:23:10 +04:00
|
|
|
FILE *cfg;
|
|
|
|
char *mc_extfsini;
|
2004-08-14 14:51:00 +04:00
|
|
|
char key[256];
|
1998-08-27 00:23:10 +04:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2009-02-06 13:17:03 +03:00
|
|
|
mc_extfsini = concat_dir_and_file (mc_home, "extfs" PATH_SEP_STR "extfs.ini");
|
1998-08-27 00:23:10 +04:00
|
|
|
cfg = fopen (mc_extfsini, "r");
|
|
|
|
|
2003-10-26 07:47:20 +03:00
|
|
|
/* We may not use vfs_die() message or message or similar,
|
2002-12-06 17:44:51 +03:00
|
|
|
* UI is not initialized at this time and message would not
|
|
|
|
* appear on screen. */
|
1998-05-26 04:53:24 +04:00
|
|
|
if (!cfg) {
|
2004-08-14 14:51:00 +04:00
|
|
|
fprintf (stderr, _("Warning: file %s not found\n"), mc_extfsini);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mc_extfsini);
|
2001-07-20 18:50:30 +04:00
|
|
|
return 0;
|
1998-05-26 04:53:24 +04:00
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
extfs_no = 0;
|
2004-08-14 14:51:00 +04:00
|
|
|
while (extfs_no < MAXEXTFS && fgets (key, sizeof (key), cfg)) {
|
1998-05-26 04:53:24 +04:00
|
|
|
char *c;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Handle those with a trailing ':', those flag that the
|
|
|
|
* file system does not require an archive to work
|
|
|
|
*/
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (*key == '[') {
|
2001-07-20 18:50:30 +04:00
|
|
|
fprintf(stderr, "Warning: You need to update your %s file.\n",
|
|
|
|
mc_extfsini);
|
1998-05-26 04:53:24 +04:00
|
|
|
fclose(cfg);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mc_extfsini);
|
1998-09-27 23:27:58 +04:00
|
|
|
return 0;
|
1998-05-26 04:53:24 +04:00
|
|
|
}
|
2004-08-14 14:51:00 +04:00
|
|
|
if (*key == '#' || *key == '\n')
|
1998-05-26 04:53:24 +04:00
|
|
|
continue;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-03-24 15:16:52 +03:00
|
|
|
if ((c = strchr (key, '\n'))){
|
2004-08-14 14:51:00 +04:00
|
|
|
*c-- = 0;
|
|
|
|
} else { /* Last line without newline or strlen (key) > 255 */
|
1999-03-30 10:09:56 +04:00
|
|
|
c = &key [strlen (key) - 1];
|
1999-03-24 15:16:52 +03:00
|
|
|
}
|
1999-03-30 10:09:56 +04:00
|
|
|
extfs_need_archive [extfs_no] = !(*c == ':');
|
|
|
|
if (*c == ':')
|
2004-08-14 14:51:00 +04:00
|
|
|
*c = 0;
|
1998-05-26 04:53:24 +04:00
|
|
|
if (!(*key))
|
|
|
|
continue;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-06 01:40:32 +03:00
|
|
|
extfs_prefixes [extfs_no++] = g_strdup (key);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
fclose(cfg);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (mc_extfsini);
|
1998-09-27 23:27:58 +04:00
|
|
|
return 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2004-08-16 23:47:21 +04:00
|
|
|
static int extfs_which (struct vfs_class *me, const char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-05-26 04:53:24 +04:00
|
|
|
int i;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
for (i = 0; i < extfs_no; i++)
|
|
|
|
if (!strcmp (path, extfs_prefixes [i]))
|
1998-02-27 07:54:42 +03:00
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-10-12 04:24:00 +04:00
|
|
|
static void extfs_done (struct vfs_class *me)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int i;
|
2006-03-23 18:00:50 +03:00
|
|
|
struct archive *ar;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2006-03-23 18:00:50 +03:00
|
|
|
for (ar = first_archive; ar != NULL;) {
|
|
|
|
extfs_free ((vfsid) ar);
|
|
|
|
ar = first_archive;
|
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
for (i = 0; i < extfs_no; i++ )
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (extfs_prefixes [i]);
|
1998-02-27 07:54:42 +03:00
|
|
|
extfs_no = 0;
|
|
|
|
}
|
|
|
|
|
2003-10-16 20:12:19 +04:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
extfs_setctl (struct vfs_class *me, const char *path, int ctlop, void *arg)
|
1998-10-13 02:07:53 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) arg;
|
|
|
|
|
2003-10-16 20:12:19 +04:00
|
|
|
if (ctlop == VFS_SETCTL_RUN) {
|
2004-12-07 02:27:23 +03:00
|
|
|
extfs_run (me, path);
|
1998-10-13 02:07:53 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-13 02:25:53 +04:00
|
|
|
void
|
|
|
|
init_extfs (void)
|
|
|
|
{
|
|
|
|
vfs_extfs_ops.name = "extfs";
|
|
|
|
vfs_extfs_ops.init = extfs_init;
|
|
|
|
vfs_extfs_ops.done = extfs_done;
|
|
|
|
vfs_extfs_ops.fill_names = extfs_fill_names;
|
|
|
|
vfs_extfs_ops.which = extfs_which;
|
|
|
|
vfs_extfs_ops.open = extfs_open;
|
|
|
|
vfs_extfs_ops.close = extfs_close;
|
|
|
|
vfs_extfs_ops.read = extfs_read;
|
|
|
|
vfs_extfs_ops.write = extfs_write;
|
2003-10-28 03:57:02 +03:00
|
|
|
vfs_extfs_ops.opendir = extfs_opendir;
|
|
|
|
vfs_extfs_ops.readdir = extfs_readdir;
|
|
|
|
vfs_extfs_ops.closedir = extfs_closedir;
|
|
|
|
vfs_extfs_ops.stat = extfs_stat;
|
|
|
|
vfs_extfs_ops.lstat = extfs_lstat;
|
|
|
|
vfs_extfs_ops.fstat = extfs_fstat;
|
2003-10-13 02:25:53 +04:00
|
|
|
vfs_extfs_ops.chmod = extfs_chmod;
|
2003-10-28 03:57:02 +03:00
|
|
|
vfs_extfs_ops.readlink = extfs_readlink;
|
2003-10-13 02:25:53 +04:00
|
|
|
vfs_extfs_ops.unlink = extfs_unlink;
|
|
|
|
vfs_extfs_ops.chdir = extfs_chdir;
|
2003-10-28 03:57:02 +03:00
|
|
|
vfs_extfs_ops.ferrno = extfs_errno;
|
2003-10-13 02:25:53 +04:00
|
|
|
vfs_extfs_ops.lseek = extfs_lseek;
|
|
|
|
vfs_extfs_ops.getid = extfs_getid;
|
|
|
|
vfs_extfs_ops.nothingisopen = extfs_nothingisopen;
|
|
|
|
vfs_extfs_ops.free = extfs_free;
|
|
|
|
vfs_extfs_ops.getlocalcopy = extfs_getlocalcopy;
|
|
|
|
vfs_extfs_ops.ungetlocalcopy = extfs_ungetlocalcopy;
|
|
|
|
vfs_extfs_ops.mkdir = extfs_mkdir;
|
|
|
|
vfs_extfs_ops.rmdir = extfs_rmdir;
|
|
|
|
vfs_extfs_ops.setctl = extfs_setctl;
|
|
|
|
vfs_register_class (&vfs_extfs_ops);
|
|
|
|
}
|