1998-02-27 07:54:42 +03:00
|
|
|
/* Virtual File System: External file system.
|
|
|
|
Copyright (C) 1995 The Free Software Foundation
|
|
|
|
|
|
|
|
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
|
|
|
|
2000-01-05 17:13:57 +03:00
|
|
|
$Id$
|
|
|
|
|
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
|
2000-08-23 02:50:00 +04:00
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
/* Namespace: exports only vfs_extfs_ops */
|
|
|
|
|
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 <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
#include <errno.h>
|
1999-01-21 01:01:11 +03:00
|
|
|
#include "utilvfs.h"
|
1998-05-26 04:53:24 +04:00
|
|
|
#include "../src/dialog.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "../src/main.h" /* For shell_execute */
|
2001-02-20 19:24:49 +03:00
|
|
|
#include "xdirentry.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "vfs.h"
|
|
|
|
#include "extfs.h"
|
|
|
|
|
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;
|
|
|
|
int size;
|
|
|
|
time_t mtime;
|
|
|
|
char linkflag;
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static struct entry *
|
|
|
|
find_entry (struct entry *dir, char *name, int make_dirs, int make_file);
|
1998-09-29 20:01:16 +04:00
|
|
|
static int extfs_which (vfs *me, char *path);
|
1999-04-13 06:05:15 +04:00
|
|
|
static void remove_entry (struct entry *e);
|
1998-04-17 04:59:58 +04:00
|
|
|
|
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
|
|
|
static struct stat hstat; /* Stat struct corresponding */
|
|
|
|
|
|
|
|
#define MAXEXTFS 32
|
|
|
|
static char *extfs_prefixes [MAXEXTFS];
|
|
|
|
static char extfs_need_archive [MAXEXTFS];
|
|
|
|
static int extfs_no = 0;
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
static void extfs_fill_names (vfs *me, void (*func)(char *))
|
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;
|
|
|
|
|
|
|
|
while (a){
|
2002-07-03 19:54:01 +04:00
|
|
|
name = g_strconcat (a->name ? a->name : "",
|
|
|
|
"#", extfs_prefixes [a->fstype],
|
|
|
|
PATH_SEP_STR, a->current_dir->name, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
(*func)(name);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (name);
|
1998-02-27 07:54:42 +03:00
|
|
|
a = a->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static void make_dot_doubledot (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;
|
1999-01-21 01:01:11 +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->last_in_subdir = entry;
|
|
|
|
inode->nlink++;
|
1999-01-21 01:01:11 +03:00
|
|
|
entry->next_in_dir = g_new (struct entry, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
entry=entry->next_in_dir;
|
1999-01-21 01:01:11 +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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static struct entry *generate_entry (struct archive *archive,
|
|
|
|
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
|
|
|
|
1999-01-21 01:01:11 +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;
|
|
|
|
inode->linkname = 0;
|
|
|
|
inode->inode = (archive->__inode_counter)++;
|
|
|
|
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))
|
|
|
|
make_dot_doubledot (entry);
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static void free_entries (struct entry *entry)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static void free_archive (struct archive *archive)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
free_entries (archive->root_entry);
|
|
|
|
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);
|
|
|
|
/* ungetlocalcopy frees local_name for us */
|
|
|
|
}
|
|
|
|
if (archive->name)
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (archive->name);
|
|
|
|
g_free (archive);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static FILE *open_archive (int fstype, char *name, struct archive **pparc)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
static dev_t __extfs_no = 0;
|
|
|
|
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;
|
1998-05-26 04:53:24 +04:00
|
|
|
int uses_archive = extfs_need_archive [fstype];
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
tmp = name_quote (name, 0);
|
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
#if 0
|
|
|
|
/* Sorry, what is this good for? */
|
1998-02-27 07:54:42 +03:00
|
|
|
if (uses_archive == EFS_NEED_ARG){
|
|
|
|
tmp = name_quote (name, 0);
|
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-08-27 00:23:10 +04:00
|
|
|
mc_extfsdir = concat_dir_and_file (mc_home, "extfs/");
|
1999-01-27 03:49:11 +03:00
|
|
|
cmd = g_strconcat (mc_extfsdir, extfs_prefixes [fstype],
|
1999-01-21 01:01:11 +03:00
|
|
|
" list ", local_name ? local_name : tmp, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (tmp)
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (tmp);
|
2000-01-13 18:15:42 +03:00
|
|
|
g_free (mc_extfsdir);
|
1998-02-27 07:54:42 +03:00
|
|
|
result = popen (cmd, "r");
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (cmd);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (result == NULL) {
|
|
|
|
if (local_name != NULL && uses_archive)
|
|
|
|
mc_ungetlocalcopy (name, local_name, 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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;
|
1999-01-21 01:01:11 +03:00
|
|
|
current_archive->name = name ? g_strdup (name): name;
|
1998-02-27 07:54:42 +03:00
|
|
|
current_archive->local_name = local_name;
|
|
|
|
|
|
|
|
if (local_name != NULL)
|
|
|
|
mc_stat (local_name, ¤t_archive->local_stat);
|
|
|
|
current_archive->__inode_counter = 0;
|
|
|
|
current_archive->fd_usage = 0;
|
|
|
|
current_archive->extfsstat = mystat;
|
|
|
|
current_archive->rdev = __extfs_no++;
|
|
|
|
current_archive->next = first_archive;
|
|
|
|
first_archive = current_archive;
|
|
|
|
mode = current_archive->extfsstat.st_mode & 07777;
|
|
|
|
if (mode & 0400)
|
|
|
|
mode |= 0100;
|
|
|
|
if (mode & 0040)
|
|
|
|
mode |= 0010;
|
|
|
|
if (mode & 0004)
|
|
|
|
mode |= 0001;
|
|
|
|
mode |= S_IFDIR;
|
|
|
|
root_entry = generate_entry (current_archive, "/", NULL, mode);
|
|
|
|
root_entry->inode->uid = current_archive->extfsstat.st_uid;
|
|
|
|
root_entry->inode->gid = current_archive->extfsstat.st_gid;
|
|
|
|
root_entry->inode->atime = current_archive->extfsstat.st_atime;
|
|
|
|
root_entry->inode->ctime = current_archive->extfsstat.st_ctime;
|
|
|
|
root_entry->inode->mtime = current_archive->extfsstat.st_mtime;
|
|
|
|
current_archive->root_entry = root_entry;
|
|
|
|
current_archive->current_dir = root_entry;
|
|
|
|
|
|
|
|
*pparc = current_archive;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Main loop for reading an archive.
|
|
|
|
* Returns 0 on success, -1 on error.
|
|
|
|
*/
|
1998-10-13 02:07:53 +04:00
|
|
|
static int read_archive (int fstype, 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;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
if ((extfsd = open_archive (fstype, name, ¤t_archive)) == NULL) {
|
1998-05-26 04:53:24 +04:00
|
|
|
message_3s (1, MSG_ERROR, _("Couldn't open %s archive\n%s"),
|
1998-02-27 07:54:42 +03:00
|
|
|
extfs_prefixes [fstype], name);
|
|
|
|
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) {
|
|
|
|
current_link_name = NULL;
|
1998-10-13 02:07:53 +04:00
|
|
|
if (vfs_parse_ls_lga (buffer, &hstat, ¤t_file_name, ¤t_link_name)) {
|
1998-09-13 14:40:43 +04:00
|
|
|
struct entry *entry, *pent;
|
|
|
|
struct inode *inode;
|
1998-02-27 07:54:42 +03:00
|
|
|
char *p, *q, *cfn = current_file_name;
|
|
|
|
|
|
|
|
if (*cfn) {
|
|
|
|
if (*cfn == '/')
|
|
|
|
cfn++;
|
|
|
|
p = strchr (cfn, 0);
|
2000-01-13 18:15:42 +03:00
|
|
|
if (p != cfn && *(p - 1) == '/')
|
1998-02-27 07:54:42 +03:00
|
|
|
*(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;
|
1998-09-13 14:40:43 +04:00
|
|
|
pent = find_entry (current_archive->root_entry, q, 1, 0) ;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (pent == NULL) {
|
1998-05-26 04:53:24 +04:00
|
|
|
message_1s (1, MSG_ERROR, _("Inconsistent extfs archive"));
|
1998-02-27 07:54:42 +03:00
|
|
|
/* FIXME: Should clean everything one day */
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
pclose (extfsd);
|
|
|
|
return -1;
|
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
entry = g_new (struct entry, 1);
|
|
|
|
entry->name = g_strdup (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
entry->next_in_dir = NULL;
|
|
|
|
entry->dir = pent;
|
|
|
|
if (pent != NULL) {
|
|
|
|
if (pent->inode->last_in_subdir){
|
|
|
|
pent->inode->last_in_subdir->next_in_dir = entry;
|
|
|
|
pent->inode->last_in_subdir = entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!S_ISLNK (hstat.st_mode) && current_link_name != NULL) {
|
1998-09-13 14:40:43 +04:00
|
|
|
pent = find_entry (current_archive->root_entry, current_link_name, 0, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (pent == NULL) {
|
1998-05-26 04:53:24 +04:00
|
|
|
message_1s (1, MSG_ERROR, _("Inconsistent extfs archive"));
|
1998-02-27 07:54:42 +03:00
|
|
|
/* FIXME: Should clean everything one day */
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
pclose (extfsd);
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
entry->inode = pent->inode;
|
|
|
|
pent->inode->nlink++;
|
|
|
|
}
|
|
|
|
} 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;
|
|
|
|
inode->inode = (current_archive->__inode_counter)++;
|
|
|
|
inode->nlink = 1;
|
|
|
|
inode->dev = current_archive->rdev;
|
|
|
|
inode->archive = current_archive;
|
|
|
|
inode->mode = hstat.st_mode;
|
|
|
|
#ifdef HAVE_ST_RDEV
|
|
|
|
inode->rdev = hstat.st_rdev;
|
|
|
|
#else
|
|
|
|
inode->rdev = 0;
|
|
|
|
#endif
|
|
|
|
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;
|
|
|
|
if (current_link_name != NULL && S_ISLNK (hstat.st_mode)) {
|
|
|
|
inode->linkname = current_link_name;
|
|
|
|
current_link_name = NULL;
|
|
|
|
} else {
|
1998-05-26 04:53:24 +04:00
|
|
|
if (S_ISLNK( hstat.st_mode))
|
|
|
|
inode->mode &= ~S_IFLNK; /* You *DON'T* want to do this always */
|
1998-02-27 07:54:42 +03:00
|
|
|
inode->linkname = NULL;
|
|
|
|
}
|
|
|
|
if (S_ISDIR (hstat.st_mode))
|
|
|
|
make_dot_doubledot (entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
read_extfs_continue:
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (current_file_name);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (current_link_name != NULL)
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (current_link_name);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pclose (extfsd);
|
|
|
|
#ifdef SCO_FLAVOR
|
2000-01-05 17:13:57 +03:00
|
|
|
waitpid(-1,NULL,WNOHANG);
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif /* SCO_FLAVOR */
|
|
|
|
*pparc = current_archive;
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (buffer);
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static char *get_path (char *inname, struct archive **archive, int is_dir,
|
1998-06-01 00:12:35 +04:00
|
|
|
int do_not_open);
|
|
|
|
|
|
|
|
/* Returns path inside argument. Returned char* is inside inname, which is mangled
|
|
|
|
* by this operation (so you must not free it's return value)
|
|
|
|
*/
|
1998-09-13 14:40:43 +04:00
|
|
|
static char *get_path_mangle (char *inname, struct archive **archive, int is_dir,
|
1998-02-27 07:54:42 +03:00
|
|
|
int do_not_open)
|
|
|
|
{
|
1998-05-26 04:53:24 +04:00
|
|
|
char *local, *archive_name, *op;
|
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
|
|
|
struct vfs_stamping *parent;
|
|
|
|
vfs *v;
|
|
|
|
int fstype;
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
archive_name = inname;
|
|
|
|
vfs_split( inname, &local, &op );
|
1998-09-29 20:01:16 +04:00
|
|
|
fstype = extfs_which( NULL, op ); /* FIXME: we really should pass
|
|
|
|
self pointer. But as we know that extfs_which does not touch vfs
|
|
|
|
*me, it does not matter for now */
|
1998-05-26 04:53:24 +04:00
|
|
|
if (fstype == -1)
|
|
|
|
return NULL;
|
2000-01-05 17:13:57 +03:00
|
|
|
if (!local)
|
|
|
|
local = "";
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
/* All filesystems should have some local archive, at least
|
|
|
|
* it can be '/'.
|
1998-02-27 07:54:42 +03:00
|
|
|
*
|
|
|
|
* Actually, we should implement an alias mechanism that would
|
|
|
|
* translate: "a:" to "dos:a.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
for (parc = first_archive; parc != NULL; parc = parc->next)
|
1998-05-26 04:53:24 +04:00
|
|
|
if (parc->name) {
|
|
|
|
if (!strcmp (parc->name, archive_name)) {
|
1998-08-25 20:00:16 +04:00
|
|
|
struct stat *s=&(parc->extfsstat);
|
|
|
|
if (vfs_uid && (!(s->st_mode & 0004)))
|
|
|
|
if ((s->st_gid != vfs_gid) || !(s->st_mode & 0040))
|
|
|
|
if ((s->st_uid != vfs_uid) || !(s->st_mode & 0400))
|
|
|
|
return NULL;
|
|
|
|
/* This is not too secure - in some cases (/#mtools) files created
|
|
|
|
under user a are probably visible to everyone else since / usually
|
|
|
|
has permissions 755 */
|
1998-10-13 02:07:53 +04: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
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
result = do_not_open ? -1 : read_archive (fstype, archive_name, &parc);
|
1998-09-18 15:02:04 +04:00
|
|
|
if (result == -1) ERRNOR (EIO, NULL);
|
1998-05-26 04:53:24 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (archive_name){
|
|
|
|
v = vfs_type (archive_name);
|
1998-10-13 02:07:53 +04:00
|
|
|
if (v == &vfs_local_ops) {
|
1998-02-27 07:54:42 +03:00
|
|
|
parent = NULL;
|
|
|
|
} else {
|
1999-01-21 01:01:11 +03:00
|
|
|
parent = g_new (struct vfs_stamping, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
parent->v = v;
|
|
|
|
parent->next = 0;
|
1998-09-27 23:27:58 +04:00
|
|
|
parent->id = (*v->getid) (v, archive_name, &(parent->parent));
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1998-10-13 02:07:53 +04:00
|
|
|
vfs_add_noncurrent_stamps (&vfs_extfs_ops, (vfsid) parc, parent);
|
1998-02-27 07:54:42 +03:00
|
|
|
vfs_rm_parents (parent);
|
|
|
|
}
|
|
|
|
return_success:
|
|
|
|
*archive = parc;
|
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns allocated path (without leading slash) inside the archive */
|
1998-09-13 14:40:43 +04:00
|
|
|
static char *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)
|
2000-01-13 18:15:42 +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;
|
1999-01-21 01:01:11 +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 *
|
|
|
|
__find_entry (struct entry *dir, char *name,
|
|
|
|
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 *
|
|
|
|
__resolve_symlinks (struct entry *entry,
|
|
|
|
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;
|
1998-09-13 14:40:43 +04:00
|
|
|
pent = __find_entry (entry->dir, entry->inode->linkname, looping, 0, 0);
|
1999-01-21 01:01:11 +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;
|
|
|
|
}
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static struct entry *my_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;
|
1998-09-13 14:40:43 +04:00
|
|
|
res = __resolve_symlinks (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;
|
|
|
|
}
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static char *get_archive_name (struct archive *archive)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *archive_name;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-06-15 00:08:27 +04:00
|
|
|
static void extfs_run (char *file)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct archive *archive;
|
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
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
if ((p = get_path (file, &archive, 0, 0)) == NULL)
|
1998-02-27 07:54:42 +03:00
|
|
|
return;
|
1998-05-26 04:53:24 +04:00
|
|
|
q = name_quote (p, 0);
|
2000-01-05 17:13:57 +03:00
|
|
|
g_free (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
archive_name = name_quote (get_archive_name(archive), 0);
|
1998-08-27 00:23:10 +04:00
|
|
|
mc_extfsdir = concat_dir_and_file (mc_home, "extfs/");
|
1999-01-27 03:49:11 +03:00
|
|
|
cmd = g_strconcat (mc_extfsdir, extfs_prefixes [archive->fstype],
|
1999-01-21 01:01:11 +03:00
|
|
|
" run ", archive_name, " ", q, NULL);
|
|
|
|
g_free (mc_extfsdir);
|
|
|
|
g_free (archive_name);
|
|
|
|
g_free (q);
|
1998-05-26 04:53:24 +04:00
|
|
|
#ifndef VFS_STANDALONE
|
1998-02-27 07:54:42 +03:00
|
|
|
shell_execute(cmd, 0);
|
1998-05-26 04:53:24 +04:00
|
|
|
#else
|
|
|
|
vfs_die( "shell_execute: implement me!" );
|
|
|
|
#endif
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free(cmd);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
static void *extfs_open (vfs *me, 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;
|
|
|
|
struct archive *archive;
|
1998-05-26 04:53:24 +04:00
|
|
|
char *q;
|
1998-08-27 22:51:20 +04:00
|
|
|
char *mc_extfsdir;
|
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;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
if ((q = get_path_mangle (file, &archive, 0, 0)) == NULL)
|
1998-02-27 07:54:42 +03:00
|
|
|
return NULL;
|
2002-02-20 00:32:24 +03:00
|
|
|
entry = find_entry (archive->root_entry, q, 0, 0);
|
|
|
|
if (entry == NULL && (flags & O_CREAT)) {
|
|
|
|
/* Create new entry */
|
|
|
|
entry = find_entry (archive->root_entry, q, 0, 1);
|
|
|
|
created = (entry != NULL);
|
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
if (entry == NULL)
|
1998-02-27 07:54:42 +03:00
|
|
|
return NULL;
|
1998-09-13 14:40:43 +04:00
|
|
|
if ((entry = my_resolve_symlinks (entry)) == NULL)
|
1998-02-27 07:54:42 +03:00
|
|
|
return NULL;
|
1998-09-18 15:02:04 +04:00
|
|
|
if (S_ISDIR (entry->inode->mode)) ERRNOR (EISDIR, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (entry->inode->local_filename == NULL) {
|
1999-01-21 01:01:11 +03:00
|
|
|
char *cmd;
|
|
|
|
char *archive_name, *p;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-12-15 18:57:39 +03:00
|
|
|
{
|
|
|
|
int handle;
|
2001-05-21 20:21:07 +04:00
|
|
|
handle = mc_mkstemps (&entry->inode->local_filename, "extfs", NULL);
|
1998-12-15 18:57:39 +03:00
|
|
|
|
|
|
|
if (handle == -1)
|
2000-01-13 18:15:42 +03:00
|
|
|
return NULL;
|
1998-12-15 18:57:39 +03:00
|
|
|
close(handle);
|
|
|
|
}
|
1998-09-13 14:40:43 +04:00
|
|
|
p = get_path_from_entry (entry);
|
1998-02-27 07:54:42 +03:00
|
|
|
q = name_quote (p, 0);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
archive_name = name_quote (get_archive_name (archive), 0);
|
1998-08-27 00:23:10 +04:00
|
|
|
|
|
|
|
mc_extfsdir = concat_dir_and_file (mc_home, "extfs/");
|
1999-01-27 03:49:11 +03:00
|
|
|
cmd = g_strconcat (mc_extfsdir, extfs_prefixes [archive->fstype],
|
1998-08-27 00:23:10 +04:00
|
|
|
" copyout ",
|
1998-02-27 07:54:42 +03:00
|
|
|
archive_name,
|
1999-01-21 01:01:11 +03:00
|
|
|
" ", q, " ", entry->inode->local_filename, NULL);
|
|
|
|
g_free (q);
|
|
|
|
g_free (mc_extfsdir);
|
|
|
|
g_free (archive_name);
|
2002-08-20 03:20:03 +04:00
|
|
|
if (my_system (EXECUTE_AS_SHELL, shell, cmd) && !created){
|
1999-04-22 08:36:11 +04:00
|
|
|
free (entry->inode->local_filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
entry->inode->local_filename = NULL;
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (cmd);
|
1998-09-13 14:40:43 +04:00
|
|
|
my_errno = EIO;
|
1998-02-27 07:54:42 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (cmd);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
2002-07-10 21:56:27 +04:00
|
|
|
local_handle = open (entry->inode->local_filename, NO_LINEAR(flags),
|
|
|
|
mode);
|
1998-09-18 15:02:04 +04:00
|
|
|
if (local_handle == -1) ERRNOR (EIO, NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
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 */
|
1998-10-13 02:07:53 +04:00
|
|
|
vfs_rmstamp (&vfs_extfs_ops, (vfsid) archive, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
archive->fd_usage++;
|
|
|
|
return extfs_info;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int extfs_read (void *data, char *buffer, int count)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int extfs_close (void *data)
|
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct pseudofile *file;
|
1998-02-27 07:54:42 +03:00
|
|
|
int errno_code = 0;
|
1998-09-13 14:40:43 +04:00
|
|
|
file = (struct pseudofile *)data;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
close (file->local_handle);
|
|
|
|
|
|
|
|
/* Commit the file if it has changed */
|
|
|
|
if (file->has_changed){
|
1998-09-13 14:40:43 +04:00
|
|
|
struct archive *archive;
|
1998-02-27 07:54:42 +03:00
|
|
|
char *archive_name, *file_name;
|
|
|
|
char *cmd;
|
1998-08-27 00:23:10 +04:00
|
|
|
char *mc_extfsdir;
|
1998-02-27 07:54:42 +03:00
|
|
|
char *p;
|
|
|
|
|
|
|
|
archive = file->archive;
|
|
|
|
archive_name = name_quote (get_archive_name (archive), 0);
|
1998-09-13 14:40:43 +04:00
|
|
|
p = get_path_from_entry (file->entry);
|
1998-02-27 07:54:42 +03:00
|
|
|
file_name = name_quote (p, 0);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-08-27 00:23:10 +04:00
|
|
|
mc_extfsdir = concat_dir_and_file (mc_home, "extfs/");
|
1999-01-27 03:49:11 +03:00
|
|
|
cmd = g_strconcat (mc_extfsdir,
|
1998-02-27 07:54:42 +03:00
|
|
|
extfs_prefixes [archive->fstype],
|
|
|
|
" copyin ", archive_name, " ",
|
|
|
|
file_name, " ",
|
1999-01-21 01:01:11 +03:00
|
|
|
file->entry->inode->local_filename, NULL);
|
|
|
|
g_free (archive_name);
|
|
|
|
g_free (file_name);
|
2000-01-13 18:15:42 +03:00
|
|
|
g_free (mc_extfsdir);
|
2002-08-20 03:20:03 +04:00
|
|
|
if (my_system (EXECUTE_AS_SHELL, shell, cmd))
|
1998-02-27 07:54:42 +03:00
|
|
|
errno_code = EIO;
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (cmd);
|
2000-01-13 18:15:42 +03:00
|
|
|
{
|
|
|
|
struct stat file_status;
|
|
|
|
if (stat(file->entry->inode->local_filename,&file_status) != 0)
|
|
|
|
errno_code = EIO;
|
|
|
|
else
|
|
|
|
file->entry->inode->size = file_status.st_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
file->entry->inode->mtime = time (NULL);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
file->archive->fd_usage--;
|
|
|
|
if (!file->archive->fd_usage) {
|
|
|
|
struct vfs_stamping *parent;
|
|
|
|
vfs *v;
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
if (!file->archive->name || !*file->archive->name || (v = vfs_type (file->archive->name)) == &vfs_local_ops) {
|
1998-02-27 07:54:42 +03:00
|
|
|
parent = NULL;
|
|
|
|
} else {
|
1999-01-21 01:01:11 +03:00
|
|
|
parent = g_new (struct vfs_stamping, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
parent->v = v;
|
|
|
|
parent->next = 0;
|
1998-09-27 23:27:58 +04:00
|
|
|
parent->id = (*v->getid) (v, file->archive->name, &(parent->parent));
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1998-10-13 02:07:53 +04:00
|
|
|
vfs_add_noncurrent_stamps (&vfs_extfs_ops, (vfsid) (file->archive), parent);
|
1998-02-27 07:54:42 +03:00
|
|
|
vfs_rm_parents (parent);
|
|
|
|
}
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (data);
|
1998-09-18 15:02:04 +04:00
|
|
|
if (errno_code) ERRNOR (EIO, -1);
|
|
|
|
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 char *get_path (char *inname, struct archive **archive, int is_dir,
|
|
|
|
int do_not_open)
|
|
|
|
{
|
|
|
|
char *buf = g_strdup (inname);
|
|
|
|
char *res = get_path_mangle( buf, archive, is_dir, do_not_open );
|
|
|
|
char *res2 = NULL;
|
|
|
|
if (res)
|
|
|
|
res2 = g_strdup(res);
|
|
|
|
g_free(buf);
|
|
|
|
return res2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct entry*
|
|
|
|
__find_entry (struct entry *dir, char *name,
|
|
|
|
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 {
|
|
|
|
if ((pent = __resolve_symlinks (pent, list))==NULL){
|
|
|
|
*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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* When we load archive, we create automagically
|
|
|
|
* non-existant directories
|
|
|
|
*/
|
|
|
|
if (pent == NULL && make_dirs) {
|
|
|
|
pent = generate_entry (dir->inode->archive, p, pdir, S_IFDIR | 0777);
|
|
|
|
}
|
|
|
|
if (pent == NULL && make_file) {
|
|
|
|
pent = generate_entry (dir->inode->archive, p, pdir, 0777);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Next iteration */
|
|
|
|
*q = c;
|
|
|
|
p = q + 1;
|
|
|
|
q = strchr (p, '/');
|
|
|
|
if (!q)
|
|
|
|
q = strchr (p, 0);
|
|
|
|
}
|
|
|
|
if (pent == NULL)
|
|
|
|
my_errno = ENOENT;
|
|
|
|
return pent;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct entry *find_entry (struct entry *dir, char *name, int make_dirs, int make_file)
|
|
|
|
{
|
|
|
|
struct entry *res;
|
|
|
|
|
|
|
|
errloop = 0;
|
|
|
|
notadir = 0;
|
|
|
|
res = __find_entry (dir, name, NULL, make_dirs, make_file);
|
|
|
|
if (res == NULL) {
|
|
|
|
if (errloop)
|
|
|
|
my_errno = ELOOP;
|
|
|
|
else if (notadir)
|
|
|
|
my_errno = ENOTDIR;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int s_errno (vfs *me)
|
|
|
|
{
|
|
|
|
return my_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void * s_opendir (vfs *me, char *dirname)
|
|
|
|
{
|
|
|
|
struct archive *archive;
|
|
|
|
char *q;
|
|
|
|
struct entry *entry;
|
|
|
|
struct entry **info;
|
|
|
|
|
|
|
|
if ((q = get_path_mangle (dirname, &archive, 1, 0)) == NULL)
|
|
|
|
return NULL;
|
|
|
|
entry = find_entry (archive->root_entry, q, 0, 0);
|
|
|
|
if (entry == NULL)
|
|
|
|
return NULL;
|
|
|
|
if ((entry = my_resolve_symlinks (entry)) == NULL)
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-08-16 01:15:17 +04:00
|
|
|
static void * s_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
|
|
|
|
2002-08-16 01:15:17 +04:00
|
|
|
strncpy(dir.dent.d_name, (*info)->name, MC_MAXPATHLEN);
|
|
|
|
dir.dent.d_name[MC_MAXPATHLEN] = 0;
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static int s_telldir (void *data)
|
|
|
|
{
|
|
|
|
struct entry **info = (struct entry **) data;
|
|
|
|
struct entry *cur;
|
|
|
|
int num = 0;
|
|
|
|
|
|
|
|
cur = info[1];
|
|
|
|
while (cur!=NULL) {
|
|
|
|
if (cur == info[0]) return num;
|
|
|
|
num++;
|
|
|
|
cur = cur->next_in_dir;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void s_seekdir (void *data, int offset)
|
|
|
|
{
|
|
|
|
struct entry **info = (struct entry **) data;
|
|
|
|
int i;
|
|
|
|
info[0] = info[1];
|
|
|
|
for (i=0; i<offset; i++)
|
|
|
|
s_readdir( data );
|
|
|
|
}
|
|
|
|
|
|
|
|
static int s_closedir (void *data)
|
|
|
|
{
|
|
|
|
g_free (data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stat_move( struct stat *buf, struct inode *inode )
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
#ifdef HAVE_ST_RDEV
|
|
|
|
buf->st_rdev = inode->rdev;
|
|
|
|
#endif
|
|
|
|
buf->st_size = inode->size;
|
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
|
|
|
buf->st_blksize = RECORDSIZE;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ST_BLOCKS
|
|
|
|
buf->st_blocks = (inode->size + RECORDSIZE - 1) / RECORDSIZE;
|
|
|
|
#endif
|
|
|
|
buf->st_atime = inode->atime;
|
|
|
|
buf->st_mtime = inode->mtime;
|
|
|
|
buf->st_ctime = inode->ctime;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int s_internal_stat (char *path, struct stat *buf, int resolve)
|
|
|
|
{
|
|
|
|
struct archive *archive;
|
|
|
|
char *q;
|
|
|
|
struct entry *entry;
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
if ((q = get_path_mangle (path, &archive, 0, 0)) == NULL)
|
|
|
|
return -1;
|
|
|
|
entry = find_entry (archive->root_entry, q, 0, 0);
|
|
|
|
if (entry == NULL)
|
|
|
|
return -1;
|
|
|
|
if (resolve && (entry = my_resolve_symlinks (entry)) == NULL)
|
|
|
|
return -1;
|
|
|
|
inode = entry->inode;
|
|
|
|
stat_move( buf, inode );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int s_stat (vfs *me, char *path, struct stat *buf)
|
|
|
|
{
|
|
|
|
return s_internal_stat (path, buf, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int s_lstat (vfs *me, char *path, struct stat *buf)
|
|
|
|
{
|
|
|
|
return s_internal_stat (path, buf, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int s_fstat (void *data, struct stat *buf)
|
|
|
|
{
|
|
|
|
struct pseudofile *file = (struct pseudofile *)data;
|
|
|
|
struct inode *inode;
|
|
|
|
|
|
|
|
inode = file->entry->inode;
|
|
|
|
stat_move( buf, inode );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int s_readlink (vfs *me, char *path, char *buf, int size)
|
|
|
|
{
|
|
|
|
struct archive *archive;
|
|
|
|
char *q;
|
|
|
|
int i;
|
|
|
|
struct entry *entry;
|
|
|
|
|
|
|
|
if ((q = get_path_mangle (path, &archive, 0, 0)) == NULL)
|
|
|
|
return -1;
|
|
|
|
entry = find_entry (archive->root_entry, q, 0, 0);
|
|
|
|
if (entry == NULL)
|
|
|
|
return -1;
|
|
|
|
if (!S_ISLNK (entry->inode->mode)) ERRNOR (EINVAL, -1);
|
|
|
|
if (size > (i = strlen (entry->inode->linkname))) {
|
|
|
|
size = i;
|
|
|
|
}
|
|
|
|
strncpy (buf, entry->inode->linkname, i);
|
|
|
|
return i;
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
static int extfs_chmod (vfs *me, char *path, int mode)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int extfs_write (void *data, char *buf, int nbyte)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
1999-04-13 06:05:15 +04:00
|
|
|
static int extfs_unlink (vfs *me, char *file)
|
|
|
|
{
|
|
|
|
struct archive *archive;
|
|
|
|
char *q;
|
|
|
|
char *mc_extfsdir;
|
|
|
|
struct entry *entry;
|
|
|
|
char *cmd;
|
|
|
|
char *archive_name, *p;
|
|
|
|
|
|
|
|
if ((q = get_path_mangle (file, &archive, 0, 0)) == NULL)
|
|
|
|
return -1;
|
|
|
|
entry = find_entry (archive->root_entry, q, 0, 0);
|
|
|
|
if (entry == NULL)
|
|
|
|
return -1;
|
|
|
|
if ((entry = my_resolve_symlinks (entry)) == NULL)
|
|
|
|
return -1;
|
|
|
|
if (S_ISDIR (entry->inode->mode)) ERRNOR (EISDIR, -1);
|
|
|
|
|
|
|
|
p = get_path_from_entry (entry);
|
|
|
|
q = name_quote (p, 0);
|
|
|
|
g_free (p);
|
|
|
|
archive_name = name_quote (get_archive_name (archive), 0);
|
|
|
|
|
|
|
|
mc_extfsdir = concat_dir_and_file (mc_home, "extfs/");
|
|
|
|
cmd = g_strconcat (mc_extfsdir, extfs_prefixes [archive->fstype],
|
|
|
|
" rm ", archive_name, " ", q, NULL);
|
|
|
|
g_free (q);
|
|
|
|
g_free (mc_extfsdir);
|
|
|
|
g_free (archive_name);
|
2002-08-20 03:20:03 +04:00
|
|
|
if (my_system (EXECUTE_AS_SHELL, shell, cmd)){
|
2000-01-13 18:15:42 +03:00
|
|
|
g_free (cmd);
|
|
|
|
my_errno = EIO;
|
|
|
|
return -1;
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
|
|
|
g_free (cmd);
|
|
|
|
remove_entry (entry);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int extfs_mkdir (vfs *me, char *path, mode_t mode)
|
|
|
|
{
|
|
|
|
struct archive *archive;
|
|
|
|
char *q;
|
|
|
|
char *mc_extfsdir;
|
|
|
|
struct entry *entry;
|
|
|
|
char *cmd;
|
|
|
|
char *archive_name, *p;
|
|
|
|
|
|
|
|
if ((q = get_path_mangle (path, &archive, 0, 0)) == NULL)
|
2000-01-13 18:15:42 +03:00
|
|
|
return -1;
|
1999-04-13 06:05:15 +04:00
|
|
|
entry = find_entry (archive->root_entry, q, 0, 0);
|
|
|
|
if (entry != NULL) ERRNOR (EEXIST, -1);
|
|
|
|
entry = find_entry (archive->root_entry, q, 1, 0);
|
|
|
|
if (entry == NULL)
|
2000-01-13 18:15:42 +03:00
|
|
|
return -1;
|
1999-04-13 06:05:15 +04:00
|
|
|
if ((entry = my_resolve_symlinks (entry)) == NULL)
|
|
|
|
return -1;
|
|
|
|
if (!S_ISDIR (entry->inode->mode)) ERRNOR (ENOTDIR, -1);
|
|
|
|
|
|
|
|
p = get_path_from_entry (entry);
|
|
|
|
q = name_quote (p, 0);
|
|
|
|
g_free (p);
|
|
|
|
archive_name = name_quote (get_archive_name (archive), 0);
|
|
|
|
|
|
|
|
mc_extfsdir = concat_dir_and_file (mc_home, "extfs/");
|
|
|
|
cmd = g_strconcat (mc_extfsdir, extfs_prefixes [archive->fstype],
|
|
|
|
" mkdir ", archive_name, " ", q, NULL);
|
|
|
|
g_free (q);
|
|
|
|
g_free (mc_extfsdir);
|
|
|
|
g_free (archive_name);
|
2002-08-20 03:20:03 +04:00
|
|
|
if (my_system (EXECUTE_AS_SHELL, shell, cmd)){
|
2000-01-13 18:15:42 +03:00
|
|
|
g_free (cmd);
|
|
|
|
my_errno = EIO;
|
|
|
|
remove_entry (entry);
|
|
|
|
return -1;
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
|
|
|
g_free (cmd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int extfs_rmdir (vfs *me, char *path)
|
|
|
|
{
|
|
|
|
struct archive *archive;
|
|
|
|
char *q;
|
|
|
|
char *mc_extfsdir;
|
|
|
|
struct entry *entry;
|
|
|
|
char *cmd;
|
|
|
|
char *archive_name, *p;
|
|
|
|
|
|
|
|
if ((q = get_path_mangle (path, &archive, 0, 0)) == NULL)
|
|
|
|
return -1;
|
|
|
|
entry = find_entry (archive->root_entry, q, 0, 0);
|
|
|
|
if (entry == NULL)
|
|
|
|
return -1;
|
|
|
|
if ((entry = my_resolve_symlinks (entry)) == NULL)
|
|
|
|
return -1;
|
|
|
|
if (!S_ISDIR (entry->inode->mode)) ERRNOR (ENOTDIR, -1);
|
|
|
|
|
|
|
|
p = get_path_from_entry (entry);
|
|
|
|
q = name_quote (p, 0);
|
|
|
|
g_free (p);
|
|
|
|
archive_name = name_quote (get_archive_name (archive), 0);
|
|
|
|
|
|
|
|
mc_extfsdir = concat_dir_and_file (mc_home, "extfs/");
|
|
|
|
cmd = g_strconcat (mc_extfsdir, extfs_prefixes [archive->fstype],
|
|
|
|
" rmdir ", archive_name, " ", q, NULL);
|
|
|
|
g_free (q);
|
|
|
|
g_free (mc_extfsdir);
|
|
|
|
g_free (archive_name);
|
2002-08-20 03:20:03 +04:00
|
|
|
if (my_system (EXECUTE_AS_SHELL, shell, cmd)){
|
2000-01-13 18:15:42 +03:00
|
|
|
g_free (cmd);
|
|
|
|
my_errno = EIO;
|
|
|
|
return -1;
|
1999-04-13 06:05:15 +04:00
|
|
|
}
|
|
|
|
g_free (cmd);
|
|
|
|
remove_entry (entry);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
static int extfs_chdir (vfs *me, char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct archive *archive;
|
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;
|
|
|
|
if ((q = get_path_mangle (path, &archive, 1, 0)) == NULL)
|
1998-02-27 07:54:42 +03:00
|
|
|
return -1;
|
1998-09-13 14:40:43 +04:00
|
|
|
entry = find_entry (archive->root_entry, q, 0, 0);
|
1998-05-26 04:53:24 +04:00
|
|
|
if (!entry)
|
1998-02-27 07:54:42 +03:00
|
|
|
return -1;
|
1998-09-13 14:40:43 +04:00
|
|
|
entry = my_resolve_symlinks (entry);
|
1998-05-26 04:53:24 +04:00
|
|
|
if ((!entry) || (!S_ISDIR (entry->inode->mode)))
|
1998-02-27 07:54:42 +03:00
|
|
|
return -1;
|
|
|
|
entry->inode->archive->current_dir = entry;
|
1998-09-13 14:40:43 +04:00
|
|
|
my_errno = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int extfs_lseek (void *data, off_t offset, int whence)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
static vfsid extfs_getid (vfs *me, char *path, struct vfs_stamping **parent)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct archive *archive;
|
1998-02-27 07:54:42 +03:00
|
|
|
vfs *v;
|
|
|
|
vfsid id;
|
|
|
|
struct vfs_stamping *par;
|
1998-06-01 00:12:35 +04:00
|
|
|
char *p;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
*parent = NULL;
|
1998-09-13 14:40:43 +04:00
|
|
|
if (!(p = get_path (path, &archive, 1, 1)))
|
1998-02-27 07:54:42 +03:00
|
|
|
return (vfsid) -1;
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free(p);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (archive->name){
|
|
|
|
v = vfs_type (archive->name);
|
1998-09-27 23:27:58 +04:00
|
|
|
id = (*v->getid) (v, archive->name, &par);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (id != (vfsid)-1) {
|
1999-01-21 01:01:11 +03:00
|
|
|
*parent = g_new (struct vfs_stamping, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
(*parent)->v = v;
|
|
|
|
(*parent)->id = id;
|
|
|
|
(*parent)->parent = par;
|
|
|
|
(*parent)->next = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (vfsid) archive;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-04-13 06:05:15 +04:00
|
|
|
static void remove_entry (struct entry *e)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
remove_entry (f);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
if (e->inode->linkname != NULL)
|
|
|
|
g_free (e->inode->linkname);
|
|
|
|
g_free (e->inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (e->name);
|
|
|
|
g_free (e);
|
|
|
|
}
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
static void 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;
|
|
|
|
free_entry (f);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
if (e->inode->linkname != NULL)
|
1999-01-21 01:01:11 +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)
|
|
|
|
free_entry (e->next_in_dir);
|
1999-01-21 01:01:11 +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
|
|
|
|
|
|
|
free_entry (archive->root_entry);
|
|
|
|
if (archive == first_archive) {
|
|
|
|
first_archive = archive->next;
|
|
|
|
} else {
|
|
|
|
for (parc = first_archive; parc != NULL; parc = parc->next)
|
|
|
|
if (parc->next == archive)
|
|
|
|
break;
|
|
|
|
if (parc != NULL)
|
|
|
|
parc->next = archive->next;
|
|
|
|
}
|
|
|
|
free_archive (archive);
|
|
|
|
}
|
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
static char *extfs_getlocalcopy (vfs *me, char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct pseudofile *fp =
|
1998-09-27 23:27:58 +04:00
|
|
|
(struct pseudofile *) extfs_open (me, path, O_RDONLY, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (fp == NULL)
|
|
|
|
return NULL;
|
|
|
|
if (fp->entry->inode->local_filename == NULL) {
|
|
|
|
extfs_close ((void *) fp);
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-01-21 01:01:11 +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;
|
|
|
|
}
|
|
|
|
|
1999-11-11 17:23:40 +03:00
|
|
|
static int extfs_ungetlocalcopy (vfs *me, char *path, char *local, int has_changed)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
struct pseudofile *fp =
|
2002-02-20 00:32:24 +03:00
|
|
|
(struct pseudofile *) extfs_open (me, path, O_RDONLY, 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (fp == NULL)
|
2000-01-05 17:13:57 +03:00
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!strcmp (fp->entry->inode->local_filename, local)) {
|
|
|
|
fp->archive->fd_usage--;
|
2002-02-20 00:32:24 +03:00
|
|
|
fp->has_changed |= has_changed;
|
1998-02-27 07:54:42 +03:00
|
|
|
extfs_close ((void *) fp);
|
1999-11-11 17:23:40 +03:00
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
} else {
|
|
|
|
/* Should not happen */
|
|
|
|
extfs_close ((void *) fp);
|
1999-11-11 17:23:40 +03:00
|
|
|
return mc_def_ungetlocalcopy (me, path, local, has_changed);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#include "../src/profile.h"
|
1998-09-29 20:01:16 +04:00
|
|
|
static int extfs_init (vfs *me)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-08-27 00:23:10 +04:00
|
|
|
FILE *cfg;
|
|
|
|
char *mc_extfsini;
|
|
|
|
|
|
|
|
mc_extfsini = concat_dir_and_file (mc_home, "extfs/extfs.ini");
|
|
|
|
cfg = fopen (mc_extfsini, "r");
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (!cfg) {
|
2001-08-17 00:43:47 +04:00
|
|
|
fprintf(stderr, _("Warning: file %s not found\n"), mc_extfsini);
|
2001-07-20 18:50:30 +04:00
|
|
|
g_free (mc_extfsini);
|
|
|
|
return 0;
|
1998-05-26 04:53:24 +04:00
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
extfs_no = 0;
|
1998-05-26 04:53:24 +04:00
|
|
|
while ( extfs_no < MAXEXTFS ) {
|
|
|
|
char key[256];
|
|
|
|
char *c;
|
|
|
|
|
1999-01-02 10:46:20 +03:00
|
|
|
if (!fgets( key, sizeof (key)-1, cfg ))
|
1998-05-26 04:53:24 +04:00
|
|
|
break;
|
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 == '[') {
|
|
|
|
/* We may not use vfs_die() message or message_1s or similar,
|
|
|
|
* UI is not initialized at this time and message would not
|
|
|
|
* appear on screen. */
|
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);
|
2001-07-20 18:50:30 +04:00
|
|
|
g_free (mc_extfsini);
|
1998-09-27 23:27:58 +04:00
|
|
|
return 0;
|
1998-05-26 04:53:24 +04:00
|
|
|
}
|
|
|
|
if (*key == '#')
|
|
|
|
continue;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-03-24 15:16:52 +03:00
|
|
|
if ((c = strchr (key, '\n'))){
|
1998-05-26 04:53:24 +04:00
|
|
|
*c = 0;
|
1999-03-30 10:09:56 +04:00
|
|
|
c = &key [strlen (key) - 1];
|
1999-03-24 15:16:52 +03:00
|
|
|
} else {
|
1999-03-30 10:09:56 +04:00
|
|
|
c = key;
|
1999-03-24 15:16:52 +03:00
|
|
|
}
|
1999-03-30 10:09:56 +04:00
|
|
|
extfs_need_archive [extfs_no] = !(*c == ':');
|
|
|
|
if (*c == ':')
|
1999-03-24 15:16:52 +03:00
|
|
|
*c = 0;
|
1998-05-26 04:53:24 +04:00
|
|
|
if (!(*key))
|
|
|
|
continue;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
extfs_prefixes [extfs_no] = g_strdup (key);
|
1998-05-26 04:53:24 +04:00
|
|
|
extfs_no++;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
fclose(cfg);
|
2001-07-20 18:50:30 +04:00
|
|
|
g_free (mc_extfsini);
|
1998-09-27 23:27:58 +04:00
|
|
|
return 1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-09-29 20:01:16 +04:00
|
|
|
/* Do NOT use me argument in this function */
|
|
|
|
static int extfs_which (vfs *me, 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
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
1998-09-29 20:01:16 +04:00
|
|
|
static void extfs_done (vfs *me)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
for (i = 0; i < extfs_no; i++ )
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (extfs_prefixes [i]);
|
1998-02-27 07:54:42 +03:00
|
|
|
extfs_no = 0;
|
|
|
|
}
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
static int extfs_setctl (vfs *me, char *path, int ctlop, char *arg)
|
|
|
|
{
|
|
|
|
if (ctlop == MCCTL_EXTFS_RUN) {
|
|
|
|
extfs_run (path);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
vfs vfs_extfs_ops = {
|
1998-09-27 23:27:58 +04:00
|
|
|
NULL, /* This is place of next pointer */
|
2001-06-12 01:58:58 +04:00
|
|
|
"extfs",
|
1998-09-27 23:27:58 +04:00
|
|
|
F_EXEC, /* flags */
|
|
|
|
NULL, /* prefix */
|
|
|
|
NULL, /* data */
|
|
|
|
0, /* errno */
|
|
|
|
extfs_init,
|
|
|
|
extfs_done,
|
|
|
|
extfs_fill_names,
|
|
|
|
extfs_which,
|
|
|
|
|
|
|
|
extfs_open,
|
|
|
|
extfs_close,
|
|
|
|
extfs_read,
|
|
|
|
extfs_write,
|
|
|
|
|
|
|
|
s_opendir,
|
|
|
|
s_readdir,
|
|
|
|
s_closedir,
|
|
|
|
s_telldir,
|
|
|
|
s_seekdir,
|
|
|
|
|
|
|
|
s_stat,
|
|
|
|
s_lstat,
|
|
|
|
s_fstat,
|
|
|
|
|
|
|
|
extfs_chmod, /* chmod ... strange, returns success? */
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
s_readlink,
|
|
|
|
|
|
|
|
NULL, /* symlink */
|
|
|
|
NULL,
|
1999-04-13 06:05:15 +04:00
|
|
|
extfs_unlink,
|
1998-09-27 23:27:58 +04:00
|
|
|
|
|
|
|
NULL,
|
|
|
|
extfs_chdir,
|
|
|
|
s_errno,
|
|
|
|
extfs_lseek,
|
|
|
|
NULL,
|
|
|
|
|
|
|
|
extfs_getid,
|
|
|
|
extfs_nothingisopen,
|
|
|
|
extfs_free,
|
|
|
|
|
|
|
|
extfs_getlocalcopy,
|
|
|
|
extfs_ungetlocalcopy,
|
|
|
|
|
1999-04-13 06:05:15 +04:00
|
|
|
extfs_mkdir, /* mkdir */
|
|
|
|
extfs_rmdir,
|
1998-09-27 23:27:58 +04:00
|
|
|
NULL,
|
1998-10-13 02:07:53 +04:00
|
|
|
extfs_setctl
|
1998-09-27 23:27:58 +04:00
|
|
|
|
|
|
|
MMAPNULL
|
|
|
|
};
|