1998-02-27 07:54:42 +03:00
|
|
|
/* Virtual File System switch code
|
|
|
|
Copyright (C) 1995 The Free Software Foundation
|
|
|
|
|
|
|
|
Written by: 1995 Miguel de Icaza
|
|
|
|
1995 Jakub Jelinek
|
1998-05-26 04:53:24 +04:00
|
|
|
1998 Pavel Machek
|
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
|
1998-02-27 07:54:42 +03:00
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
/* Warning: funtions like extfs_lstat() have right to destroy any
|
1999-01-21 01:01:11 +03:00
|
|
|
* strings you pass to them. This is acutally ok as you g_strdup what
|
1998-09-13 14:40:43 +04:00
|
|
|
* you are passing to them, anyway; still, beware. */
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
/* Namespace: exports *many* functions with vfs_ prefix; exports
|
|
|
|
parse_ls_lga and friends which do not have that prefix. */
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <config.h>
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1999-02-14 00:39:18 +03:00
|
|
|
#ifndef NO_SYSLOG_H
|
|
|
|
# include <syslog.h>
|
|
|
|
#endif
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h> /* For atol() */
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#ifdef SCO_FLAVOR
|
|
|
|
#include <sys/timeb.h> /* alex: for struct timeb definition */
|
|
|
|
#endif /* SCO_FLAVOR */
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/time.h>
|
1999-01-21 01:01:11 +03:00
|
|
|
|
|
|
|
#include "utilvfs.h"
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "../src/dir.h"
|
|
|
|
#include "../src/main.h"
|
1998-05-26 04:53:24 +04:00
|
|
|
#ifndef VFS_STANDALONE
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "../src/panel.h"
|
|
|
|
#include "../src/key.h" /* Required for the async alarm handler */
|
|
|
|
#include "../src/layout.h" /* For get_panel_widget and get_other_index */
|
1998-09-18 18:28:07 +04:00
|
|
|
#include "../src/dialog.h"
|
1998-05-26 04:53:24 +04:00
|
|
|
#endif
|
1999-01-21 01:01:11 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "vfs.h"
|
1998-10-13 02:07:53 +04:00
|
|
|
#include "extfs.h" /* FIXME: we should not know anything about our modules */
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "names.h"
|
|
|
|
#ifdef USE_NETCODE
|
|
|
|
# include "tcputil.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int get_other_type (void);
|
|
|
|
|
|
|
|
int vfs_timeout = 60; /* VFS timeout in seconds */
|
1998-10-05 22:32:53 +04:00
|
|
|
int vfs_flags = 0; /* Flags */
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
extern int cd_symlinks; /* Defined in main.c */
|
|
|
|
|
|
|
|
/* They keep track of the current directory */
|
1998-10-13 02:07:53 +04:00
|
|
|
static vfs *current_vfs = &vfs_local_ops;
|
|
|
|
static char *current_dir = NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-08-25 20:00:16 +04:00
|
|
|
/*
|
|
|
|
* FIXME: this is broken. It depends on mc not crossing border on month!
|
|
|
|
*/
|
1998-06-01 16:52:18 +04:00
|
|
|
static int current_mday;
|
1998-02-27 07:54:42 +03:00
|
|
|
static int current_mon;
|
|
|
|
static int current_year;
|
|
|
|
|
1998-08-25 20:00:16 +04:00
|
|
|
uid_t vfs_uid = 0;
|
|
|
|
gid_t vfs_gid = 0;
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
/* FIXME: Open files managed by the vfs layer, should be dynamical */
|
1998-02-27 07:54:42 +03:00
|
|
|
#define MAX_VFS_FILES 100
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
static struct {
|
|
|
|
void *fs_info;
|
|
|
|
vfs *operations;
|
|
|
|
} vfs_file_table [MAX_VFS_FILES];
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
static int
|
|
|
|
get_bucket (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* 0, 1, 2 are reserved file descriptors, while (DIR *) 0 means error */
|
|
|
|
for (i = 3; i < MAX_VFS_FILES; i++){
|
|
|
|
if (!vfs_file_table [i].fs_info)
|
|
|
|
return i;
|
|
|
|
}
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
vfs_die ("No more virtual file handles");
|
1998-10-14 06:56:18 +04:00
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
/* vfs_local_ops needs to be the first one */
|
|
|
|
static vfs *vfs_list = &vfs_local_ops;
|
1998-09-27 23:27:58 +04:00
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
vfs_register (vfs *vfs)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1999-01-11 03:48:23 +03:00
|
|
|
if (!vfs)
|
|
|
|
vfs_die("You can not register NULL.");
|
|
|
|
|
2000-02-24 15:00:30 +03:00
|
|
|
if (vfs->init) /* vfs has own initialization function */
|
|
|
|
if (!(*vfs->init)(vfs)) /* but it failed */
|
|
|
|
return 0;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
vfs->next = vfs_list;
|
|
|
|
vfs_list = vfs;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
vfs *
|
|
|
|
vfs_type_from_op (char *path)
|
1998-09-27 23:27:58 +04:00
|
|
|
{
|
|
|
|
vfs *vfs;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1999-01-11 03:48:23 +03:00
|
|
|
if (!path)
|
|
|
|
vfs_die ("vfs_type_from_op got NULL: impossible");
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-12-09 23:22:53 +03:00
|
|
|
for (vfs = vfs_list; vfs != &vfs_local_ops; vfs = vfs->next){
|
1998-09-27 23:27:58 +04:00
|
|
|
if (vfs->which) {
|
1998-12-09 23:22:53 +03:00
|
|
|
if ((*vfs->which) (vfs, path) == -1)
|
|
|
|
continue;
|
|
|
|
return vfs;
|
1998-09-27 23:27:58 +04:00
|
|
|
}
|
|
|
|
if (!strncmp (path, vfs->prefix, strlen (vfs->prefix)))
|
|
|
|
return vfs;
|
|
|
|
}
|
|
|
|
return NULL; /* shut up stupid gcc */
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-12-16 09:16:13 +03:00
|
|
|
/* Strip known vfs suffixes from a filename (possible improvement: strip
|
|
|
|
suffix from last path component).
|
|
|
|
Returns a malloced string which has to be freed. */
|
|
|
|
char *
|
|
|
|
vfs_strip_suffix_from_filename (char *filename)
|
|
|
|
{
|
|
|
|
vfs *vfs;
|
|
|
|
char *semi;
|
|
|
|
char *p;
|
|
|
|
|
1999-01-11 03:48:23 +03:00
|
|
|
if (!filename)
|
|
|
|
vfs_die("vfs_strip_suffix_from_path got NULL: impossible");
|
1998-12-16 09:16:13 +03:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
p = g_strdup (filename);
|
1998-12-16 09:16:13 +03:00
|
|
|
if (!(semi = strrchr (p, '#')))
|
|
|
|
return p;
|
|
|
|
|
|
|
|
for (vfs = vfs_list; vfs != &vfs_local_ops; vfs = vfs->next){
|
1999-01-11 03:48:23 +03:00
|
|
|
if (vfs->which){
|
1998-12-16 09:16:13 +03:00
|
|
|
if ((*vfs->which) (vfs, semi + 1) == -1)
|
|
|
|
continue;
|
1999-01-31 23:28:13 +03:00
|
|
|
*semi = '\0'; /* Found valid suffix */
|
1998-12-16 09:16:13 +03:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
if (!strncmp (semi + 1, vfs->prefix, strlen (vfs->prefix))) {
|
1999-01-31 23:28:13 +03:00
|
|
|
*semi = '\0'; /* Found valid suffix */
|
1998-12-16 09:16:13 +03:00
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
static int
|
|
|
|
path_magic (char *path)
|
1998-08-25 20:00:16 +04:00
|
|
|
{
|
1998-10-05 22:32:53 +04:00
|
|
|
struct stat buf;
|
|
|
|
|
|
|
|
if (vfs_flags & FL_ALWAYS_MAGIC)
|
|
|
|
return 1;
|
1998-08-25 20:00:16 +04:00
|
|
|
|
1998-10-05 22:32:53 +04:00
|
|
|
if (!stat(path, &buf))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
1998-08-25 20:00:16 +04:00
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
/*
|
1998-08-25 20:00:16 +04:00
|
|
|
* Splits path '/p1#op/inpath' into inpath,op; returns which vfs it is.
|
1999-01-21 01:01:11 +03:00
|
|
|
* What is left in path is p1. You still want to g_free(path), you DON'T
|
1998-05-26 04:53:24 +04:00
|
|
|
* want to free neither *inpath nor *op
|
|
|
|
*/
|
1998-10-14 06:56:18 +04:00
|
|
|
vfs *
|
|
|
|
vfs_split (char *path, char **inpath, char **op)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-10-14 06:56:18 +04:00
|
|
|
char *semi;
|
1998-05-26 04:53:24 +04:00
|
|
|
char *slash;
|
|
|
|
vfs *ret;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1999-01-11 03:48:23 +03:00
|
|
|
if (!path)
|
|
|
|
vfs_die("Can not split NULL");
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
semi = strrchr (path, '#');
|
1998-10-05 22:32:53 +04:00
|
|
|
if (!semi || !path_magic(path))
|
1998-05-26 04:53:24 +04:00
|
|
|
return NULL;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
slash = strchr (semi, PATH_SEP);
|
1998-05-26 04:53:24 +04:00
|
|
|
*semi = 0;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (op)
|
|
|
|
*op = NULL;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (inpath)
|
|
|
|
*inpath = NULL;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (slash)
|
|
|
|
*slash = 0;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if ((ret = vfs_type_from_op (semi+1))){
|
|
|
|
if (op)
|
1998-10-14 06:56:18 +04:00
|
|
|
*op = semi + 1;
|
1998-05-26 04:53:24 +04:00
|
|
|
if (inpath)
|
1998-10-14 06:56:18 +04:00
|
|
|
*inpath = slash ? slash + 1 : NULL;
|
1998-05-26 04:53:24 +04:00
|
|
|
return ret;
|
|
|
|
}
|
1998-10-14 06:56:18 +04:00
|
|
|
|
2000-04-16 23:13:00 +04:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (slash)
|
1999-01-21 01:01:11 +03:00
|
|
|
*slash = PATH_SEP;
|
1998-05-26 04:53:24 +04:00
|
|
|
ret = vfs_split (path, inpath, op);
|
|
|
|
*semi = '#';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
vfs *
|
1998-05-26 04:53:24 +04:00
|
|
|
vfs_rosplit (char *path)
|
|
|
|
{
|
1998-10-14 06:56:18 +04:00
|
|
|
char *semi;
|
1998-05-26 04:53:24 +04:00
|
|
|
char *slash;
|
|
|
|
vfs *ret;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
2000-04-16 23:13:00 +04:00
|
|
|
g_return_val_if_fail(path, NULL);
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
semi = strrchr (path, '#');
|
|
|
|
if (!semi || !path_magic (path))
|
1998-05-26 04:53:24 +04:00
|
|
|
return NULL;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
slash = strchr (semi, PATH_SEP);
|
1998-05-26 04:53:24 +04:00
|
|
|
*semi = 0;
|
|
|
|
if (slash)
|
|
|
|
*slash = 0;
|
|
|
|
|
|
|
|
ret = vfs_type_from_op (semi+1);
|
2000-04-16 23:13:00 +04:00
|
|
|
if (!ret && (vfs_flags & FL_NO_LOCALHASH))
|
|
|
|
return &vfs_nil_ops;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (slash)
|
1999-01-21 01:01:11 +03:00
|
|
|
*slash = PATH_SEP;
|
1998-05-26 04:53:24 +04:00
|
|
|
if (!ret)
|
|
|
|
ret = vfs_rosplit (path);
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
*semi = '#';
|
|
|
|
return ret;
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
vfs *
|
|
|
|
vfs_type (char *path)
|
1998-05-26 04:53:24 +04:00
|
|
|
{
|
1998-10-14 06:56:18 +04:00
|
|
|
vfs *vfs;
|
|
|
|
|
|
|
|
vfs = vfs_rosplit(path);
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (!vfs)
|
2000-04-16 23:13:00 +04:00
|
|
|
vfs = &vfs_local_ops;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
return vfs;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct vfs_stamping *stamps;
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
/*
|
|
|
|
* Returns the number of seconds remaining to the vfs timeout
|
1998-02-27 07:54:42 +03:00
|
|
|
*
|
|
|
|
* FIXME: currently this is set to 10 seconds. We should compute this.
|
|
|
|
*/
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
vfs_timeouts ()
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return stamps ? 10 : 0;
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
vfs_addstamp (vfs *v, vfsid id, struct vfs_stamping *parent)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-10-13 02:07:53 +04:00
|
|
|
if (v != &vfs_local_ops && id != (vfsid)-1){
|
1998-02-27 07:54:42 +03:00
|
|
|
struct vfs_stamping *stamp, *st1;
|
|
|
|
|
|
|
|
for (stamp = stamps; stamp != NULL; st1 = stamp, stamp = stamp->next)
|
1998-05-26 04:53:24 +04:00
|
|
|
if (stamp->v == v && stamp->id == id){
|
1998-02-27 07:54:42 +03:00
|
|
|
gettimeofday(&(stamp->time), NULL);
|
|
|
|
return;
|
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
stamp = g_new (struct vfs_stamping, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
stamp->v = v;
|
|
|
|
stamp->id = id;
|
1998-05-26 04:53:24 +04:00
|
|
|
if (parent){
|
1998-02-27 07:54:42 +03:00
|
|
|
struct vfs_stamping *st = stamp;
|
1999-12-16 15:55:16 +03:00
|
|
|
while (parent){
|
1999-01-21 01:01:11 +03:00
|
|
|
st->parent = g_new (struct vfs_stamping, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
*st->parent = *parent;
|
|
|
|
parent = parent->parent;
|
|
|
|
st = st->parent;
|
|
|
|
}
|
|
|
|
st->parent = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
stamp->parent = 0;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
gettimeofday (&(stamp->time), NULL);
|
|
|
|
stamp->next = 0;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (stamps)
|
|
|
|
st1->next = stamp;
|
|
|
|
else
|
|
|
|
stamps = stamp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
vfs_stamp (vfs *v, vfsid id)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
struct vfs_stamping *stamp;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
for (stamp = stamps; stamp != NULL; stamp = stamp->next)
|
1998-05-26 04:53:24 +04:00
|
|
|
if (stamp->v == v && stamp->id == id){
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
gettimeofday (&(stamp->time), NULL);
|
|
|
|
if (stamp->parent != NULL)
|
|
|
|
vfs_stamp (stamp->parent->v, stamp->parent->id);
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
vfs_rm_parents (struct vfs_stamping *stamp)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2000-01-05 17:13:57 +03:00
|
|
|
struct vfs_stamping *parent;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
2000-01-05 17:13:57 +03:00
|
|
|
while (stamp) {
|
|
|
|
parent = stamp->parent;
|
|
|
|
g_free (stamp);
|
|
|
|
stamp = parent;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
vfs_rmstamp (vfs *v, vfsid id, int removeparents)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
struct vfs_stamping *stamp, *st1;
|
|
|
|
|
|
|
|
for (stamp = stamps, st1 = NULL; stamp != NULL; st1 = stamp, stamp = stamp->next)
|
1998-05-26 04:53:24 +04:00
|
|
|
if (stamp->v == v && stamp->id == id){
|
|
|
|
if (stamp->parent != NULL){
|
1998-02-27 07:54:42 +03:00
|
|
|
if (removeparents)
|
|
|
|
vfs_rmstamp (stamp->parent->v, stamp->parent->id, 1);
|
|
|
|
vfs_rm_parents (stamp->parent);
|
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
if (st1 == NULL){
|
1998-02-27 07:54:42 +03:00
|
|
|
stamps = stamp->next;
|
|
|
|
} else {
|
|
|
|
st1->next = stamp->next;
|
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (stamp);
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
static int
|
|
|
|
ferrno (vfs *vfs)
|
|
|
|
{
|
1998-11-21 22:36:01 +03:00
|
|
|
return vfs->ferrno ? (*vfs->ferrno)(vfs) : E_UNKNOWN;
|
1998-05-26 04:53:24 +04:00
|
|
|
/* Hope that error message is obscure enough ;-) */
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
2000-02-24 15:00:30 +03:00
|
|
|
mc_open (const char *filename, int flags, ...)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int handle;
|
|
|
|
int mode;
|
|
|
|
void *info;
|
|
|
|
va_list ap;
|
2000-02-24 15:00:30 +03:00
|
|
|
|
|
|
|
char *file = vfs_canon (filename);
|
|
|
|
vfs *vfs = vfs_type (file);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
/* Get the mode flag */ /* FIXME: should look if O_CREAT is present */
|
1998-02-27 07:54:42 +03:00
|
|
|
va_start (ap, flags);
|
|
|
|
mode = va_arg (ap, int);
|
|
|
|
va_end (ap);
|
|
|
|
|
2000-04-16 23:13:00 +04:00
|
|
|
if (!vfs->open) {
|
|
|
|
errno = -EOPNOTSUPP;
|
|
|
|
return -1;
|
|
|
|
}
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
info = (*vfs->open) (vfs, file, flags, mode); /* open must be supported */
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (file);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!info){
|
1998-05-26 04:53:24 +04:00
|
|
|
errno = ferrno (vfs);
|
1998-02-27 07:54:42 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
handle = get_bucket ();
|
|
|
|
vfs_file_table [handle].fs_info = info;
|
|
|
|
vfs_file_table [handle].operations = vfs;
|
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define vfs_op(handle) vfs_file_table [handle].operations
|
|
|
|
#define vfs_info(handle) vfs_file_table [handle].fs_info
|
|
|
|
#define vfs_free_bucket(handle) vfs_info(handle) = 0;
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
#define MC_OP(name, inarg, callarg, pre, post) \
|
|
|
|
int mc_##name inarg \
|
|
|
|
{ \
|
|
|
|
vfs *vfs; \
|
|
|
|
int result; \
|
|
|
|
\
|
|
|
|
pre \
|
|
|
|
result = vfs->name ? (*vfs->name)callarg : -1; \
|
|
|
|
post \
|
|
|
|
if (result == -1) \
|
1998-11-21 22:36:01 +03:00
|
|
|
errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
|
1998-05-26 04:53:24 +04:00
|
|
|
return result; \
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-08-31 14:02:52 +04:00
|
|
|
#define MC_NAMEOP(name, inarg, callarg) \
|
1999-01-21 01:01:11 +03:00
|
|
|
MC_OP (name, inarg, callarg, path = vfs_canon (path); vfs = vfs_type (path);, g_free (path); )
|
1998-08-31 14:02:52 +04:00
|
|
|
#define MC_HANDLEOP(name, inarg, callarg) \
|
|
|
|
MC_OP (name, inarg, callarg, if (handle == -1) return -1; vfs = vfs_op (handle);, )
|
1998-05-26 04:53:24 +04:00
|
|
|
|
1999-08-01 15:37:25 +04:00
|
|
|
MC_HANDLEOP(read, (int handle, char *buffer, int count), (vfs_info (handle), buffer, count) )
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
mc_ctl (int handle, int ctlop, int arg)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1999-12-16 15:55:16 +03:00
|
|
|
vfs *vfs = vfs_op (handle);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-12-16 15:55:16 +03:00
|
|
|
return vfs->ctl ? (*vfs->ctl)(vfs_info (handle), ctlop, arg) : 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
mc_setctl (char *path, int ctlop, char *arg)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
vfs *vfs;
|
|
|
|
int result;
|
|
|
|
|
1998-12-09 23:22:53 +03:00
|
|
|
if (!path)
|
1999-01-11 03:48:23 +03:00
|
|
|
vfs_die("You don't want to pass NULL to mc_setctl.");
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
path = vfs_canon (path);
|
|
|
|
vfs = vfs_type (path);
|
1998-09-27 23:27:58 +04:00
|
|
|
result = vfs->setctl ? (*vfs->setctl)(vfs, path, ctlop, arg) : 0;
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (path);
|
1998-02-27 07:54:42 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
mc_close (int handle)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
vfs *vfs;
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (handle == -1 || !vfs_info (handle))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
vfs = vfs_op (handle);
|
|
|
|
if (handle < 3)
|
|
|
|
return close (handle);
|
|
|
|
|
1998-08-31 14:02:52 +04:00
|
|
|
if (!vfs->close)
|
1998-10-14 06:56:18 +04:00
|
|
|
vfs_die ("VFS must support close.\n");
|
1998-08-31 14:02:52 +04:00
|
|
|
result = (*vfs->close)(vfs_info (handle));
|
1998-02-27 07:54:42 +03:00
|
|
|
vfs_free_bucket (handle);
|
|
|
|
if (result == -1)
|
1998-05-26 04:53:24 +04:00
|
|
|
errno = ferrno (vfs);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
DIR *
|
|
|
|
mc_opendir (char *dirname)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int handle, *handlep;
|
|
|
|
void *info;
|
|
|
|
vfs *vfs;
|
|
|
|
|
|
|
|
dirname = vfs_canon (dirname);
|
|
|
|
vfs = vfs_type (dirname);
|
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
info = vfs->opendir ? (*vfs->opendir)(vfs, dirname) : NULL;
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (dirname);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!info){
|
1998-11-21 22:36:01 +03:00
|
|
|
errno = vfs->opendir ? ferrno (vfs) : E_NOTSUPP;
|
1998-02-27 07:54:42 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
handle = get_bucket ();
|
|
|
|
vfs_file_table [handle].fs_info = info;
|
|
|
|
vfs_file_table [handle].operations = vfs;
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
handlep = g_new (int, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
*handlep = handle;
|
|
|
|
return (DIR *) handlep;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This should strip the non needed part of a path name */
|
|
|
|
#define vfs_name(x) x
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
mc_seekdir (DIR *dirp, int offset)
|
1998-08-31 14:02:52 +04:00
|
|
|
{
|
|
|
|
int handle;
|
|
|
|
vfs *vfs;
|
|
|
|
|
|
|
|
if (!dirp){
|
|
|
|
errno = EFAULT;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
handle = *(int *) dirp;
|
|
|
|
vfs = vfs_op (handle);
|
|
|
|
if (vfs->seekdir)
|
|
|
|
(*vfs->seekdir) (vfs_info (handle), offset);
|
|
|
|
else
|
1998-11-21 22:36:01 +03:00
|
|
|
errno = E_NOTSUPP;
|
1998-05-26 04:53:24 +04:00
|
|
|
}
|
|
|
|
|
1998-08-31 14:02:52 +04:00
|
|
|
#define MC_DIROP(name, type, onerr ) \
|
|
|
|
type mc_##name (DIR *dirp) \
|
1998-05-26 23:46:37 +04:00
|
|
|
{ \
|
|
|
|
int handle; \
|
|
|
|
vfs *vfs; \
|
1998-08-31 14:02:52 +04:00
|
|
|
type result; \
|
1998-05-26 23:46:37 +04:00
|
|
|
\
|
|
|
|
if (!dirp){ \
|
|
|
|
errno = EFAULT; \
|
1998-08-31 14:02:52 +04:00
|
|
|
return onerr; \
|
1998-05-26 23:46:37 +04:00
|
|
|
} \
|
|
|
|
handle = *(int *) dirp; \
|
|
|
|
vfs = vfs_op (handle); \
|
1998-08-31 14:02:52 +04:00
|
|
|
result = vfs->name ? (*vfs->name) (vfs_info (handle)) : onerr; \
|
|
|
|
if (result == onerr) \
|
1998-11-21 22:36:01 +03:00
|
|
|
errno = vfs->name ? ferrno(vfs) : E_NOTSUPP; \
|
1998-08-31 14:02:52 +04:00
|
|
|
return result; \
|
1998-05-26 23:46:37 +04:00
|
|
|
}
|
|
|
|
|
1998-08-31 14:02:52 +04:00
|
|
|
MC_DIROP (readdir, struct dirent *, NULL)
|
|
|
|
MC_DIROP (telldir, int, -1)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
mc_closedir (DIR *dirp)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int handle = *(int *) dirp;
|
|
|
|
vfs *vfs = vfs_op (handle);
|
|
|
|
int result;
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
result = vfs->closedir ? (*vfs->closedir)(vfs_info (handle)) : -1;
|
1998-02-27 07:54:42 +03:00
|
|
|
vfs_free_bucket (handle);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (dirp);
|
1998-02-27 07:54:42 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
MC_NAMEOP (stat, (char *path, struct stat *buf), (vfs, vfs_name (path), buf))
|
|
|
|
MC_NAMEOP (lstat, (char *path, struct stat *buf), (vfs, vfs_name (path), buf))
|
1998-05-26 04:53:24 +04:00
|
|
|
MC_HANDLEOP (fstat, (int handle, struct stat *buf), (vfs_info (handle), buf))
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
/*
|
1999-01-21 01:01:11 +03:00
|
|
|
* You must g_strdup whatever this function returns, static buffers are in use
|
1998-05-26 04:53:24 +04:00
|
|
|
*/
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
char *
|
|
|
|
mc_return_cwd (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
struct stat my_stat, my_stat2;
|
1998-05-26 04:53:24 +04:00
|
|
|
|
|
|
|
if (!vfs_rosplit (current_dir)){
|
|
|
|
static char buffer[MC_MAXPATHLEN];
|
|
|
|
|
|
|
|
p = get_current_wd (buffer, MC_MAXPATHLEN);
|
|
|
|
if (!p) /* One of the directories in the path is not readable */
|
|
|
|
return current_dir;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* Otherwise check if it is O.K. to use the current_dir */
|
1998-05-26 04:53:24 +04:00
|
|
|
mc_stat (p, &my_stat);
|
1998-02-27 07:54:42 +03:00
|
|
|
mc_stat (current_dir, &my_stat2);
|
|
|
|
if (my_stat.st_ino != my_stat2.st_ino ||
|
|
|
|
my_stat.st_dev != my_stat2.st_dev ||
|
1998-05-26 04:53:24 +04:00
|
|
|
!cd_symlinks){
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (current_dir);
|
|
|
|
current_dir = g_strdup (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
return p;
|
|
|
|
} /* Otherwise we return current_dir below */
|
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
return current_dir;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
char *
|
|
|
|
mc_get_current_wd (char *buffer, int size)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-05-26 04:53:24 +04:00
|
|
|
char *cwd = mc_return_cwd();
|
1999-01-15 22:02:39 +03:00
|
|
|
|
1999-01-13 02:49:37 +03:00
|
|
|
strncpy (buffer, cwd, size);
|
1998-05-26 04:53:24 +04:00
|
|
|
return buffer;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
MC_NAMEOP (chmod, (char *path, int mode), (vfs, vfs_name (path), mode))
|
|
|
|
MC_NAMEOP (chown, (char *path, int owner, int group), (vfs, vfs_name (path), owner, group))
|
|
|
|
MC_NAMEOP (utime, (char *path, struct utimbuf *times), (vfs, vfs_name (path), times))
|
|
|
|
MC_NAMEOP (readlink, (char *path, char *buf, int bufsiz), (vfs, vfs_name (path), buf, bufsiz))
|
|
|
|
MC_NAMEOP (unlink, (char *path), (vfs, vfs_name (path)))
|
|
|
|
MC_NAMEOP (symlink, (char *name1, char *path), (vfs, vfs_name (name1), vfs_name (path)))
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-08-31 14:02:52 +04:00
|
|
|
#define MC_RENAMEOP(name) \
|
|
|
|
int mc_##name (char *name1, char *name2) \
|
|
|
|
{ \
|
|
|
|
vfs *vfs; \
|
|
|
|
int result; \
|
|
|
|
\
|
|
|
|
name1 = vfs_canon (name1); \
|
|
|
|
vfs = vfs_type (name1); \
|
|
|
|
name2 = vfs_canon (name2); \
|
|
|
|
if (vfs != vfs_type (name2)){ \
|
|
|
|
errno = EXDEV; \
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (name1); \
|
|
|
|
g_free (name2); \
|
1998-08-31 14:02:52 +04:00
|
|
|
return -1; \
|
|
|
|
} \
|
|
|
|
\
|
1998-09-27 23:27:58 +04:00
|
|
|
result = vfs->name ? (*vfs->name)(vfs, vfs_name (name1), vfs_name (name2)) : -1; \
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (name1); \
|
|
|
|
g_free (name2); \
|
1998-08-31 14:02:52 +04:00
|
|
|
if (result == -1) \
|
1998-11-21 22:36:01 +03:00
|
|
|
errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \
|
1998-08-31 14:02:52 +04:00
|
|
|
return result; \
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1999-08-01 15:37:25 +04:00
|
|
|
MC_RENAMEOP (link)
|
|
|
|
MC_RENAMEOP (rename)
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-08-01 15:37:25 +04:00
|
|
|
MC_HANDLEOP (write, (int handle, char *buf, int nbyte), (vfs_info (handle), buf, nbyte))
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
off_t mc_lseek (int fd, off_t offset, int whence)
|
|
|
|
{
|
|
|
|
vfs *vfs;
|
1998-08-31 14:02:52 +04:00
|
|
|
int result;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
vfs = vfs_op (fd);
|
1998-08-31 14:02:52 +04:00
|
|
|
result = vfs->lseek ? (*vfs->lseek)(vfs_info (fd), offset, whence) : -1;
|
|
|
|
if (result == -1)
|
1998-11-21 22:36:01 +03:00
|
|
|
errno = vfs->lseek ? ferrno (vfs) : E_NOTSUPP;
|
1998-08-31 14:02:52 +04:00
|
|
|
return result;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
/*
|
|
|
|
* remove //, /./ and /../, local should point to big enough buffer
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define ISSLASH(a) (!a || (a == '/'))
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
char *
|
2000-02-24 15:00:30 +03:00
|
|
|
vfs_canon (const char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1999-01-11 03:48:23 +03:00
|
|
|
if (!path)
|
|
|
|
vfs_die("Can not canonize NULL");
|
1998-10-14 06:56:18 +04:00
|
|
|
|
|
|
|
/* Tilde expansion */
|
|
|
|
if (*path == '~'){
|
1998-02-27 07:54:42 +03:00
|
|
|
char *local, *result;
|
|
|
|
|
|
|
|
local = tilde_expand (path);
|
|
|
|
if (local){
|
|
|
|
result = vfs_canon (local);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (local);
|
1998-02-27 07:54:42 +03:00
|
|
|
return result;
|
2000-02-24 15:00:30 +03:00
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
/* Relative to current directory */
|
1999-01-21 01:01:11 +03:00
|
|
|
if (*path != PATH_SEP){
|
1998-02-27 07:54:42 +03:00
|
|
|
char *local, *result;
|
|
|
|
|
2000-02-24 15:00:30 +03:00
|
|
|
local = concat_dir_and_file (current_dir, path);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
result = vfs_canon (local);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (local);
|
1998-02-27 07:54:42 +03:00
|
|
|
return result;
|
|
|
|
}
|
1998-10-14 06:56:18 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* So we have path of following form:
|
1998-08-25 20:00:16 +04:00
|
|
|
* /p1/p2#op/.././././p3#op/p4. Good luck.
|
1998-05-26 04:53:24 +04:00
|
|
|
*/
|
2000-02-24 15:00:30 +03:00
|
|
|
{
|
|
|
|
char *result = g_strdup (path);
|
|
|
|
|
|
|
|
mad_check("(pre-canonicalize)", 0);
|
|
|
|
canonicalize_pathname (result);
|
|
|
|
mad_check("(post-canonicalize)", 0);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2000-02-24 15:00:30 +03:00
|
|
|
return result;
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
vfsid
|
|
|
|
vfs_ncs_getid (vfs *nvfs, char *dir, struct vfs_stamping **par)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
vfsid nvfsid;
|
|
|
|
|
1999-01-27 03:49:11 +03:00
|
|
|
dir = concat_dir_and_file (dir, "");
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
nvfsid = (*nvfs->getid)(nvfs, dir, par);
|
1999-01-21 01:01:11 +03:00
|
|
|
|
|
|
|
g_free (dir);
|
1998-02-27 07:54:42 +03:00
|
|
|
return nvfsid;
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
static int
|
|
|
|
is_parent (vfs * nvfs, vfsid nvfsid, struct vfs_stamping *parent)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
struct vfs_stamping *stamp;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
for (stamp = parent; stamp; stamp = stamp->parent)
|
|
|
|
if (stamp->v == nvfs && stamp->id == nvfsid)
|
|
|
|
break;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return (stamp ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
vfs_add_noncurrent_stamps (vfs * oldvfs, vfsid oldvfsid, struct vfs_stamping *parent)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-05-26 04:53:24 +04:00
|
|
|
#ifndef VFS_STANDALONE
|
1998-02-27 07:54:42 +03:00
|
|
|
vfs *nvfs, *n2vfs, *n3vfs;
|
|
|
|
vfsid nvfsid, n2vfsid, n3vfsid;
|
|
|
|
struct vfs_stamping *par, *stamp;
|
|
|
|
int f;
|
|
|
|
|
|
|
|
/* FIXME: As soon as we convert to multiple panels, this stuff
|
|
|
|
has to change. It works like this: We do not time out the
|
|
|
|
vfs's which are current in any panel and on the other
|
|
|
|
side we add the old directory with all its parents which
|
|
|
|
are not in any panel (if we find such one, we stop adding
|
|
|
|
parents to the time-outing structure. */
|
|
|
|
|
|
|
|
/* There are three directories we have to take care of: current_dir,
|
|
|
|
cpanel->cwd and opanel->cwd. Athough most of the time either
|
|
|
|
current_dir and cpanel->cwd or current_dir and opanel->cwd are the
|
|
|
|
same, it's possible that all three are different -- Norbert */
|
|
|
|
|
|
|
|
if (!cpanel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nvfs = vfs_type (current_dir);
|
|
|
|
nvfsid = vfs_ncs_getid (nvfs, current_dir, &par);
|
|
|
|
vfs_rmstamp (nvfs, nvfsid, 1);
|
|
|
|
|
|
|
|
f = is_parent (oldvfs, oldvfsid, par);
|
|
|
|
vfs_rm_parents (par);
|
1998-10-13 20:45:00 +04:00
|
|
|
if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == (vfsid *)-1 || f){
|
1998-02-27 07:54:42 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (get_current_type () == view_listing){
|
1998-02-27 07:54:42 +03:00
|
|
|
n2vfs = vfs_type (cpanel->cwd);
|
|
|
|
n2vfsid = vfs_ncs_getid (n2vfs, cpanel->cwd, &par);
|
|
|
|
f = is_parent (oldvfs, oldvfsid, par);
|
|
|
|
vfs_rm_parents (par);
|
|
|
|
if ((n2vfs == oldvfs && n2vfsid == oldvfsid) || f)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
n2vfs = (vfs *) -1;
|
|
|
|
n2vfsid = (vfs *) -1;
|
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (get_other_type () == view_listing){
|
1998-02-27 07:54:42 +03:00
|
|
|
n3vfs = vfs_type (opanel->cwd);
|
|
|
|
n3vfsid = vfs_ncs_getid (n3vfs, opanel->cwd, &par);
|
|
|
|
f = is_parent (oldvfs, oldvfsid, par);
|
|
|
|
vfs_rm_parents (par);
|
|
|
|
if ((n3vfs == oldvfs && n3vfsid == oldvfsid) || f)
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
n3vfs = (vfs *)-1;
|
|
|
|
n3vfsid = (vfs *)-1;
|
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if ((*oldvfs->nothingisopen) (oldvfsid)){
|
1998-10-13 02:07:53 +04:00
|
|
|
if (oldvfs == &vfs_extfs_ops && ((extfs_archive *) oldvfsid)->name == 0){
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Free the resources immediatly when we leave a mtools fs
|
|
|
|
('cd a:') instead of waiting for the vfs-timeout */
|
|
|
|
(oldvfs->free) (oldvfsid);
|
|
|
|
} else
|
|
|
|
vfs_addstamp (oldvfs, oldvfsid, parent);
|
1998-05-26 04:53:24 +04:00
|
|
|
for (stamp = parent; stamp != NULL; stamp = stamp->parent){
|
1998-02-27 07:54:42 +03:00
|
|
|
if ((stamp->v == nvfs && stamp->id == nvfsid) ||
|
|
|
|
(stamp->v == n2vfs && stamp->id == n2vfsid) ||
|
|
|
|
(stamp->v == n3vfs && stamp->id == n3vfsid) ||
|
|
|
|
stamp->id == (vfsid) - 1 ||
|
|
|
|
!(*stamp->v->nothingisopen) (stamp->id))
|
|
|
|
break;
|
1998-10-13 02:07:53 +04:00
|
|
|
if (stamp->v == &vfs_extfs_ops && ((extfs_archive *) stamp->id)->name == 0){
|
1998-02-27 07:54:42 +03:00
|
|
|
(stamp->v->free) (stamp->id);
|
|
|
|
vfs_rmstamp (stamp->v, stamp->id, 0);
|
|
|
|
} else
|
|
|
|
vfs_addstamp (stamp->v, stamp->id, stamp->parent);
|
|
|
|
}
|
|
|
|
}
|
1998-08-25 20:00:16 +04:00
|
|
|
#else
|
|
|
|
vfs_addstamp (oldvfs, oldvfsid, parent);
|
1998-05-26 04:53:24 +04:00
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
static void
|
|
|
|
vfs_stamp_path (char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
vfs *vfs;
|
|
|
|
vfsid id;
|
|
|
|
struct vfs_stamping *par, *stamp;
|
|
|
|
|
|
|
|
vfs = vfs_type (path);
|
|
|
|
id = vfs_ncs_getid (vfs, path, &par);
|
|
|
|
vfs_addstamp (vfs, id, par);
|
|
|
|
|
|
|
|
for (stamp = par; stamp != NULL; stamp = stamp->parent)
|
|
|
|
vfs_addstamp (stamp->v, stamp->id, stamp->parent);
|
|
|
|
vfs_rm_parents (par);
|
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
#ifndef VFS_STANDALONE
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
vfs_add_current_stamps (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
vfs_stamp_path (current_dir);
|
1999-03-30 10:09:56 +04:00
|
|
|
|
|
|
|
if (cpanel) {
|
|
|
|
if (get_current_type () == view_listing)
|
|
|
|
vfs_stamp_path (cpanel->cwd);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opanel) {
|
|
|
|
if (get_other_type () == view_listing)
|
|
|
|
vfs_stamp_path (opanel->cwd);
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
/* This function is really broken */
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
mc_chdir (char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-05-26 04:53:24 +04:00
|
|
|
char *a, *b;
|
1998-02-27 07:54:42 +03:00
|
|
|
int result;
|
|
|
|
char *p = NULL;
|
|
|
|
vfs *oldvfs;
|
|
|
|
vfsid oldvfsid;
|
|
|
|
struct vfs_stamping *parent;
|
|
|
|
|
|
|
|
a = current_dir; /* Save a copy for case of failure */
|
|
|
|
current_dir = vfs_canon (path);
|
|
|
|
current_vfs = vfs_type (current_dir);
|
1999-01-21 01:01:11 +03:00
|
|
|
b = g_strdup (current_dir);
|
1998-09-27 23:27:58 +04:00
|
|
|
result = (*current_vfs->chdir) ? (*current_vfs->chdir)(current_vfs, vfs_name (b)) : -1;
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (b);
|
1998-05-26 04:53:24 +04:00
|
|
|
if (result == -1){
|
1998-08-31 14:02:52 +04:00
|
|
|
errno = ferrno (current_vfs);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (current_dir);
|
1998-02-27 07:54:42 +03:00
|
|
|
current_vfs = vfs_type (a);
|
|
|
|
current_dir = a;
|
|
|
|
} else {
|
|
|
|
oldvfs = vfs_type (a);
|
|
|
|
oldvfsid = vfs_ncs_getid (oldvfs, a, &parent);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (a);
|
1998-02-27 07:54:42 +03:00
|
|
|
vfs_add_noncurrent_stamps (oldvfs, oldvfsid, parent);
|
|
|
|
vfs_rm_parents (parent);
|
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
|
|
|
|
if (*current_dir){
|
1998-02-27 07:54:42 +03:00
|
|
|
p = strchr (current_dir, 0) - 1;
|
1999-01-21 01:01:11 +03:00
|
|
|
if (*p == PATH_SEP && p > current_dir)
|
1998-02-27 07:54:42 +03:00
|
|
|
*p = 0; /* Sometimes we assume no trailing slash on cwd */
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
vfs_current_is_local (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-10-13 02:07:53 +04:00
|
|
|
return current_vfs == &vfs_local_ops;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
#if 0
|
|
|
|
/* External world should not do differences between VFS-s */
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
vfs_current_is_extfs (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-10-13 02:07:53 +04:00
|
|
|
return current_vfs == &vfs_extfs_ops;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
vfs_current_is_tarfs (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-10-13 02:07:53 +04:00
|
|
|
return current_vfs == &vfs_tarfs_ops;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
2000-02-22 21:21:41 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
vfs_current_is_cpiofs (void)
|
|
|
|
{
|
|
|
|
return current_vfs == &vfs_cpiofs_ops;
|
|
|
|
}
|
1998-10-13 02:07:53 +04:00
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
2000-02-24 15:00:30 +03:00
|
|
|
vfs_file_is_local (const char *file)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2000-02-24 15:00:30 +03:00
|
|
|
char *filename = vfs_canon (file);
|
|
|
|
vfs *vfs = vfs_type (filename);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (filename);
|
1998-10-13 02:07:53 +04:00
|
|
|
return vfs == &vfs_local_ops;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
vfs_file_is_ftp (char *filename)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
#ifdef USE_NETCODE
|
|
|
|
vfs *vfs;
|
|
|
|
|
|
|
|
filename = vfs_canon (filename);
|
|
|
|
vfs = vfs_type (filename);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (filename);
|
1998-10-13 02:07:53 +04:00
|
|
|
return vfs == &vfs_ftpfs_ops;
|
1998-02-27 07:54:42 +03:00
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1999-06-22 23:56:36 +04:00
|
|
|
int
|
|
|
|
vfs_file_is_smb (char *filename)
|
|
|
|
{
|
2000-02-24 15:00:30 +03:00
|
|
|
#ifdef WITH_SMBFS
|
1999-06-22 23:56:36 +04:00
|
|
|
#ifdef USE_NETCODE
|
|
|
|
vfs *vfs;
|
|
|
|
|
|
|
|
filename = vfs_canon (filename);
|
|
|
|
vfs = vfs_type (filename);
|
|
|
|
g_free (filename);
|
|
|
|
return vfs == &vfs_smbfs_ops;
|
2000-02-24 15:00:30 +03:00
|
|
|
#endif /* USE_NETCODE */
|
|
|
|
#endif /* WITH_SMBFS */
|
2000-03-06 19:31:37 +03:00
|
|
|
return 0;
|
1999-06-22 23:56:36 +04:00
|
|
|
}
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
char *vfs_get_current_dir (void)
|
|
|
|
{
|
|
|
|
return current_dir;
|
|
|
|
}
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
static void vfs_setup_wd (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1999-01-21 01:01:11 +03:00
|
|
|
current_dir = g_strdup (PATH_SEP_STR);
|
1998-09-13 14:40:43 +04:00
|
|
|
if (!(vfs_flags & FL_NO_CWDSETUP))
|
|
|
|
mc_return_cwd();
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (strlen(current_dir)>MC_MAXPATHLEN-2)
|
1998-08-31 14:02:52 +04:00
|
|
|
vfs_die ("Current dir too long.\n");
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
MC_NAMEOP (mkdir, (char *path, mode_t mode), (vfs, vfs_name (path), mode))
|
|
|
|
MC_NAMEOP (rmdir, (char *path), (vfs, vfs_name (path)))
|
|
|
|
MC_NAMEOP (mknod, (char *path, int mode, int dev), (vfs, vfs_name (path), mode, dev))
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_MMAP
|
1998-10-13 02:07:53 +04:00
|
|
|
static struct mc_mmapping {
|
1998-02-27 07:54:42 +03:00
|
|
|
caddr_t addr;
|
|
|
|
void *vfs_info;
|
|
|
|
vfs *vfs;
|
|
|
|
struct mc_mmapping *next;
|
|
|
|
} *mc_mmaparray = NULL;
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
caddr_t
|
|
|
|
mc_mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
vfs *vfs;
|
|
|
|
caddr_t result;
|
|
|
|
struct mc_mmapping *mcm;
|
|
|
|
|
|
|
|
if (fd == -1)
|
|
|
|
return (caddr_t) -1;
|
|
|
|
|
|
|
|
vfs = vfs_op (fd);
|
1998-09-27 23:27:58 +04:00
|
|
|
result = vfs->mmap ? (*vfs->mmap)(vfs, addr, len, prot, flags, vfs_info (fd), offset) : (caddr_t)-1;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (result == (caddr_t)-1){
|
1998-08-31 14:02:52 +04:00
|
|
|
errno = ferrno (vfs);
|
1998-02-27 07:54:42 +03:00
|
|
|
return (caddr_t)-1;
|
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
mcm =g_new (struct mc_mmapping, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
mcm->addr = result;
|
|
|
|
mcm->vfs_info = vfs_info (fd);
|
|
|
|
mcm->vfs = vfs;
|
|
|
|
mcm->next = mc_mmaparray;
|
|
|
|
mc_mmaparray = mcm;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
mc_munmap (caddr_t addr, size_t len)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
struct mc_mmapping *mcm, *mcm2 = NULL;
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
for (mcm = mc_mmaparray; mcm != NULL; mcm2 = mcm, mcm = mcm->next){
|
|
|
|
if (mcm->addr == addr){
|
1998-02-27 07:54:42 +03:00
|
|
|
if (mcm2 == NULL)
|
|
|
|
mc_mmaparray = mcm->next;
|
|
|
|
else
|
|
|
|
mcm2->next = mcm->next;
|
1999-08-01 15:37:25 +04:00
|
|
|
if (mcm->vfs->munmap)
|
1998-09-27 23:27:58 +04:00
|
|
|
(*mcm->vfs->munmap)(mcm->vfs, addr, len, mcm->vfs_info);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (mcm);
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
char *
|
|
|
|
mc_def_getlocalcopy (vfs *vfs, char *filename)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
int fdin, fdout, i;
|
|
|
|
char buffer[8192];
|
|
|
|
struct stat mystat;
|
|
|
|
|
|
|
|
fdin = mc_open (filename, O_RDONLY);
|
|
|
|
if (fdin == -1)
|
|
|
|
return NULL;
|
1998-10-13 02:07:53 +04:00
|
|
|
tmp = tempnam (NULL, "mclocalcopy");
|
1998-10-16 19:30:51 +04:00
|
|
|
fdout = open (tmp, O_CREAT|O_WRONLY|O_TRUNC|O_EXCL, 0600);
|
1999-11-11 17:23:40 +03:00
|
|
|
if (fdout == -1)
|
|
|
|
goto fail;
|
2000-05-25 18:47:48 +04:00
|
|
|
while ((i = mc_read (fdin, buffer, sizeof (buffer))) > 0){
|
|
|
|
if (write (fdout, buffer, i) != i)
|
|
|
|
goto fail;
|
|
|
|
}
|
1999-11-11 17:23:40 +03:00
|
|
|
if (i == -1)
|
|
|
|
goto fail;
|
|
|
|
i = mc_close (fdin);
|
|
|
|
fdin = -1;
|
|
|
|
if (i==-1)
|
|
|
|
goto fail;
|
|
|
|
if (close (fdout)==-1)
|
|
|
|
goto fail;
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (mc_stat (filename, &mystat) != -1){
|
1998-02-27 07:54:42 +03:00
|
|
|
chmod (tmp, mystat.st_mode);
|
|
|
|
}
|
|
|
|
return tmp;
|
1999-11-11 17:23:40 +03:00
|
|
|
|
|
|
|
fail:
|
|
|
|
if (fdout) close(fdout);
|
|
|
|
if (fdin) mc_close (fdin);
|
2000-04-05 17:08:42 +04:00
|
|
|
g_free (tmp);
|
1999-11-11 17:23:40 +03:00
|
|
|
return NULL;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
char *
|
2000-02-24 15:00:30 +03:00
|
|
|
mc_getlocalcopy (const char *pathname)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *result;
|
2000-02-24 15:00:30 +03:00
|
|
|
char *path = vfs_canon (pathname);
|
|
|
|
vfs *vfs = vfs_type (path);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
result = vfs->getlocalcopy ? (*vfs->getlocalcopy)(vfs, vfs_name (path)) :
|
|
|
|
mc_def_getlocalcopy (vfs, vfs_name (path));
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (path);
|
1998-08-31 14:02:52 +04:00
|
|
|
if (!result)
|
1998-05-26 04:53:24 +04:00
|
|
|
errno = ferrno (vfs);
|
1998-02-27 07:54:42 +03:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-11-11 17:23:40 +03:00
|
|
|
int
|
1998-10-14 06:56:18 +04:00
|
|
|
mc_def_ungetlocalcopy (vfs *vfs, char *filename, char *local, int has_changed)
|
1999-11-11 17:23:40 +03:00
|
|
|
{ /* Dijkstra probably hates me... But he should teach me how to do this nicely. */
|
|
|
|
int fdin = -1, fdout = -1, i;
|
1998-05-26 04:53:24 +04:00
|
|
|
if (has_changed){
|
|
|
|
char buffer [8192];
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
fdin = open (local, O_RDONLY);
|
1999-11-11 17:23:40 +03:00
|
|
|
if (fdin == -1)
|
|
|
|
goto failed;
|
1998-02-27 07:54:42 +03:00
|
|
|
fdout = mc_open (filename, O_WRONLY | O_TRUNC);
|
1999-11-11 17:23:40 +03:00
|
|
|
if (fdout == -1)
|
|
|
|
goto failed;
|
2000-05-25 18:47:48 +04:00
|
|
|
while ((i = read (fdin, buffer, sizeof (buffer))) > 0){
|
|
|
|
if (mc_write (fdout, buffer, i) != i)
|
|
|
|
goto failed;
|
|
|
|
}
|
1999-11-11 17:23:40 +03:00
|
|
|
if (i == -1)
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
if (close (fdin)==-1)
|
|
|
|
goto failed;
|
|
|
|
if (mc_close (fdout)==-1) {
|
|
|
|
fdout = -1;
|
|
|
|
goto failed;
|
|
|
|
}
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
unlink (local);
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (local);
|
1999-11-11 17:23:40 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed:
|
1999-12-16 15:55:16 +03:00
|
|
|
message_1s (1, _("Changes to file lost"), filename);
|
1999-11-11 17:23:40 +03:00
|
|
|
if (fdout) mc_close(fdout);
|
|
|
|
if (fdin) close(fdin);
|
|
|
|
unlink (local);
|
|
|
|
g_free (local);
|
|
|
|
return -1;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1999-11-11 17:23:40 +03:00
|
|
|
int
|
2000-02-24 15:00:30 +03:00
|
|
|
mc_ungetlocalcopy (const char *pathname, char *local, int has_changed)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2000-02-24 15:00:30 +03:00
|
|
|
char *path = vfs_canon (pathname);
|
|
|
|
vfs *vfs = vfs_type (path);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
vfs->ungetlocalcopy ? (*vfs->ungetlocalcopy)(vfs, vfs_name (path), local, has_changed) :
|
|
|
|
mc_def_ungetlocalcopy (vfs, vfs_name (path), local, has_changed);
|
1999-11-11 17:23:40 +03:00
|
|
|
/* FIXME: errors are ignored at this point */
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (path);
|
1999-11-11 17:23:40 +03:00
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-08-25 20:00:16 +04:00
|
|
|
/*
|
|
|
|
* Hmm, as timeout is minute or so, do we need to care about usecs?
|
|
|
|
*/
|
1998-10-14 06:56:18 +04:00
|
|
|
inline int
|
|
|
|
timeoutcmp (struct timeval *t1, struct timeval *t2)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return ((t1->tv_sec < t2->tv_sec)
|
|
|
|
|| ((t1->tv_sec == t2->tv_sec) && (t1->tv_usec <= t2->tv_usec)));
|
|
|
|
}
|
|
|
|
|
1999-11-11 17:23:40 +03:00
|
|
|
/* This is called from timeout handler with now = 0, or can be called
|
|
|
|
with now = 1 to force freeing all filesystems that are not in use */
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
1999-11-11 17:23:40 +03:00
|
|
|
vfs_expire (int now)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1999-11-11 17:23:40 +03:00
|
|
|
static int locked = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
struct timeval time;
|
|
|
|
struct vfs_stamping *stamp, *st;
|
|
|
|
|
1999-01-10 02:08:41 +03:00
|
|
|
/* Avoid recursive invocation, e.g. when one of the free functions
|
|
|
|
calls message_1s */
|
|
|
|
if (locked)
|
|
|
|
return;
|
|
|
|
locked = 1;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
gettimeofday (&time, NULL);
|
|
|
|
time.tv_sec -= vfs_timeout;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
for (stamp = stamps; stamp != NULL;){
|
1999-11-11 17:23:40 +03:00
|
|
|
if (now || (timeoutcmp (&stamp->time, &time))){
|
1998-02-27 07:54:42 +03:00
|
|
|
st = stamp->next;
|
|
|
|
(*stamp->v->free) (stamp->id);
|
|
|
|
vfs_rmstamp (stamp->v, stamp->id, 0);
|
|
|
|
stamp = st;
|
|
|
|
} else
|
|
|
|
stamp = stamp->next;
|
|
|
|
}
|
1999-01-10 02:08:41 +03:00
|
|
|
locked = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1999-11-11 17:23:40 +03:00
|
|
|
void
|
|
|
|
vfs_timeout_handler (void)
|
|
|
|
{
|
|
|
|
vfs_expire (0);
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
vfs_init (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
time_t current_time;
|
|
|
|
struct tm *t;
|
1999-11-11 17:23:40 +03:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
memset (vfs_file_table, 0, sizeof (vfs_file_table));
|
1998-02-27 07:54:42 +03:00
|
|
|
current_time = time (NULL);
|
|
|
|
t = localtime (¤t_time);
|
1998-06-01 16:52:18 +04:00
|
|
|
current_mday = t->tm_mday;
|
|
|
|
current_mon = t->tm_mon;
|
1998-02-27 07:54:42 +03:00
|
|
|
current_year = t->tm_year;
|
1998-09-27 23:27:58 +04:00
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
/* We do not want to register vfs_local_ops */
|
1998-09-27 23:27:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#ifdef USE_NETCODE
|
|
|
|
tcp_init();
|
1998-10-13 02:07:53 +04:00
|
|
|
vfs_register (&vfs_ftpfs_ops);
|
1999-06-23 01:02:08 +04:00
|
|
|
#ifdef WITH_SMBFS
|
1999-06-22 23:56:36 +04:00
|
|
|
vfs_register (&vfs_smbfs_ops);
|
1999-06-23 01:02:08 +04:00
|
|
|
#endif
|
1998-10-13 02:07:53 +04:00
|
|
|
vfs_register (&vfs_mcfs_ops);
|
1998-09-27 23:27:58 +04:00
|
|
|
#endif
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
vfs_register (&vfs_fish_ops);
|
|
|
|
vfs_register (&vfs_extfs_ops);
|
|
|
|
vfs_register (&vfs_sfs_ops);
|
|
|
|
vfs_register (&vfs_tarfs_ops);
|
2000-02-22 21:21:41 +03:00
|
|
|
vfs_register (&vfs_cpiofs_ops);
|
1998-09-27 23:27:58 +04:00
|
|
|
|
|
|
|
#ifdef USE_EXT2FSLIB
|
1998-10-13 02:07:53 +04:00
|
|
|
vfs_register (&vfs_undelfs_ops);
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif
|
1998-09-27 23:27:58 +04:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
vfs_setup_wd ();
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
vfs_free_resources (char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
vfs *vfs;
|
|
|
|
vfsid vid;
|
|
|
|
struct vfs_stamping *parent;
|
|
|
|
|
|
|
|
vfs = vfs_type (path);
|
|
|
|
vid = vfs_ncs_getid (vfs, path, &parent);
|
|
|
|
if (vid != (vfsid) -1)
|
|
|
|
(*vfs->free)(vid);
|
|
|
|
vfs_rm_parents (parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Shutdown a vfs given a path name */
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
vfs_shut_path (char *p)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
vfs *the_vfs;
|
|
|
|
struct vfs_stamping *par;
|
|
|
|
|
|
|
|
the_vfs = vfs_type (p);
|
|
|
|
vfs_ncs_getid (the_vfs, p, &par);
|
|
|
|
(*par->v->free)(par->id);
|
|
|
|
vfs_rm_parents (par);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
vfs_shut (void)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
struct vfs_stamping *stamp, *st;
|
1998-09-27 23:27:58 +04:00
|
|
|
vfs *vfs;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
for (stamp = stamps, stamps = 0; stamp != NULL;){
|
1998-02-27 07:54:42 +03:00
|
|
|
(*stamp->v->free)(stamp->id);
|
|
|
|
st = stamp->next;
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (stamp);
|
1998-02-27 07:54:42 +03:00
|
|
|
stamp = st;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stamps)
|
|
|
|
vfs_rmstamp (stamps->v, stamps->id, 1);
|
|
|
|
|
|
|
|
if (current_dir)
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (current_dir);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
for (vfs=vfs_list; vfs; vfs=vfs->next)
|
1998-09-27 23:27:58 +04:00
|
|
|
if (vfs->done)
|
|
|
|
(*vfs->done) (vfs);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
/*
|
|
|
|
* These ones grab information from the VFS
|
1998-02-27 07:54:42 +03:00
|
|
|
* and handles them to an upper layer
|
|
|
|
*/
|
1998-10-14 06:56:18 +04:00
|
|
|
void
|
|
|
|
vfs_fill_names (void (*func)(char *))
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-27 23:27:58 +04:00
|
|
|
vfs *vfs;
|
1998-10-14 06:56:18 +04:00
|
|
|
|
|
|
|
for (vfs=vfs_list; vfs; vfs=vfs->next)
|
1998-09-27 23:27:58 +04:00
|
|
|
if (vfs->fill_names)
|
|
|
|
(*vfs->fill_names) (vfs, func);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Following stuff (parse_ls_lga) is used by ftpfs and extfs */
|
1999-01-09 22:55:31 +03:00
|
|
|
#define MAXCOLS 30
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
static char *columns [MAXCOLS]; /* Points to the string in column n */
|
|
|
|
static int column_ptr [MAXCOLS]; /* Index from 0 to the starting positions of the columns */
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
vfs_split_text (char *p)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
char *original = p;
|
|
|
|
int numcols;
|
|
|
|
|
|
|
|
for (numcols = 0; *p && numcols < MAXCOLS; numcols++){
|
|
|
|
while (*p == ' ' || *p == '\r' || *p == '\n'){
|
|
|
|
*p = 0;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
columns [numcols] = p;
|
|
|
|
column_ptr [numcols] = p - original;
|
|
|
|
while (*p && *p != ' ' && *p != '\r' && *p != '\n')
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
return numcols;
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
static int
|
|
|
|
is_num (int idx)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
if (!columns [idx] || columns [idx][0] < '0' || columns [idx][0] > '9')
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1999-01-09 22:55:31 +03:00
|
|
|
static int
|
|
|
|
is_dos_date(char *str)
|
|
|
|
{
|
|
|
|
if (strlen(str) == 8 && str[2] == str[5] && strchr("\\-/", (int)str[2]) != NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_week (char *str, struct tm *tim)
|
|
|
|
{
|
|
|
|
static char *week = "SunMonTueWedThuFriSat";
|
|
|
|
char *pos;
|
|
|
|
|
|
|
|
if((pos=strstr(week, str)) != NULL){
|
|
|
|
if(tim != NULL)
|
|
|
|
tim->tm_wday = (pos - week)/3;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
is_month (char *str, struct tm *tim)
|
|
|
|
{
|
|
|
|
static char *month = "JanFebMarAprMayJunJulAugSepOctNovDec";
|
|
|
|
char *pos;
|
|
|
|
|
|
|
|
if((pos=strstr(month, str)) != NULL){
|
|
|
|
if(tim != NULL)
|
|
|
|
tim->tm_mon = (pos - month)/3;
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
static int
|
|
|
|
is_time (char *str, struct tm *tim)
|
1998-06-01 16:52:18 +04:00
|
|
|
{
|
|
|
|
char *p, *p2;
|
|
|
|
|
|
|
|
if ((p=strchr(str, ':')) && (p2=strrchr(str, ':'))) {
|
|
|
|
if (p != p2) {
|
|
|
|
if (sscanf (str, "%2d:%2d:%2d", &tim->tm_hour, &tim->tm_min, &tim->tm_sec) != 3)
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (sscanf (str, "%2d:%2d", &tim->tm_hour, &tim->tm_min) != 2)
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int is_year(char *str, struct tm *tim)
|
|
|
|
{
|
|
|
|
long year;
|
|
|
|
|
1998-08-31 14:02:52 +04:00
|
|
|
if (strchr(str,':'))
|
1999-01-09 22:55:31 +03:00
|
|
|
return (0);
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-08-31 14:02:52 +04:00
|
|
|
if (strlen(str)!=4)
|
1999-01-09 22:55:31 +03:00
|
|
|
return (0);
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-09-18 18:28:07 +04:00
|
|
|
if (sscanf(str, "%ld", &year) != 1)
|
1999-01-09 22:55:31 +03:00
|
|
|
return (0);
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-08-31 14:02:52 +04:00
|
|
|
if (year < 1900 || year > 3000)
|
1999-01-09 22:55:31 +03:00
|
|
|
return (0);
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1998-08-31 14:02:52 +04:00
|
|
|
tim->tm_year = (int) (year - 1900);
|
1998-10-14 06:56:18 +04:00
|
|
|
|
1999-01-09 22:55:31 +03:00
|
|
|
return (1);
|
1998-06-01 16:52:18 +04:00
|
|
|
}
|
|
|
|
|
1998-08-31 14:02:52 +04:00
|
|
|
/*
|
|
|
|
* FIXME: this is broken. Consider following entry:
|
1998-10-14 06:56:18 +04:00
|
|
|
* -rwx------ 1 root root 1 Aug 31 10:04 2904 1234
|
|
|
|
* where "2904 1234" is filename. Well, this code decodes it as year :-(.
|
1998-08-31 14:02:52 +04:00
|
|
|
*/
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
vfs_parse_filetype (char c)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
1998-09-13 14:40:43 +04:00
|
|
|
switch (c){
|
|
|
|
case 'd': return S_IFDIR;
|
|
|
|
case 'b': return S_IFBLK;
|
|
|
|
case 'c': return S_IFCHR;
|
|
|
|
case 'l': return S_IFLNK;
|
|
|
|
case 's':
|
|
|
|
#ifdef IS_IFSOCK /* And if not, we fall through to IFIFO, which is pretty close */
|
|
|
|
return S_IFSOCK;
|
|
|
|
#endif
|
|
|
|
case 'p': return S_IFIFO;
|
|
|
|
case 'm': case 'n': /* Don't know what these are :-) */
|
|
|
|
case '-': case '?': return S_IFREG;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
int vfs_parse_filemode (char *p)
|
1998-09-13 14:40:43 +04:00
|
|
|
{ /* converts rw-rw-rw- into 0666 */
|
|
|
|
int res = 0;
|
|
|
|
switch (*(p++)){
|
|
|
|
case 'r': res |= 0400; break;
|
|
|
|
case '-': break;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
switch (*(p++)){
|
|
|
|
case 'w': res |= 0200; break;
|
|
|
|
case '-': break;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
switch (*(p++)){
|
|
|
|
case 'x': res |= 0100; break;
|
|
|
|
case 's': res |= 0100 | S_ISUID; break;
|
|
|
|
case 'S': res |= S_ISUID; break;
|
|
|
|
case '-': break;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
switch (*(p++)){
|
|
|
|
case 'r': res |= 0040; break;
|
|
|
|
case '-': break;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
switch (*(p++)){
|
|
|
|
case 'w': res |= 0020; break;
|
|
|
|
case '-': break;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
switch (*(p++)){
|
|
|
|
case 'x': res |= 0010; break;
|
|
|
|
case 's': res |= 0010 | S_ISGID; break;
|
1999-04-23 14:38:13 +04:00
|
|
|
case 'l': /* Solaris produces these */
|
1998-09-13 14:40:43 +04:00
|
|
|
case 'S': res |= S_ISGID; break;
|
|
|
|
case '-': break;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
switch (*(p++)){
|
|
|
|
case 'r': res |= 0004; break;
|
|
|
|
case '-': break;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
switch (*(p++)){
|
|
|
|
case 'w': res |= 0002; break;
|
|
|
|
case '-': break;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
switch (*(p++)){
|
|
|
|
case 'x': res |= 0001; break;
|
|
|
|
case 't': res |= 0001 | S_ISVTX; break;
|
|
|
|
case 'T': res |= S_ISVTX; break;
|
|
|
|
case '-': break;
|
|
|
|
default: return -1;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
int vfs_parse_filedate(int idx, time_t *t)
|
1998-09-13 14:40:43 +04:00
|
|
|
{ /* This thing parses from idx in columns[] array */
|
1999-01-09 22:55:31 +03:00
|
|
|
|
|
|
|
char *p;
|
1998-09-13 14:40:43 +04:00
|
|
|
struct tm tim;
|
1999-01-09 22:55:31 +03:00
|
|
|
int d[3];
|
1999-01-11 03:48:23 +03:00
|
|
|
int got_year = 0;
|
1998-09-13 14:40:43 +04:00
|
|
|
|
|
|
|
/* Let's setup default time values */
|
|
|
|
tim.tm_year = current_year;
|
|
|
|
tim.tm_mon = current_mon;
|
|
|
|
tim.tm_mday = current_mday;
|
|
|
|
tim.tm_hour = 0;
|
|
|
|
tim.tm_min = 0;
|
|
|
|
tim.tm_sec = 0;
|
1999-01-09 22:55:31 +03:00
|
|
|
tim.tm_isdst = -1; /* Let mktime() try to guess correct dst offset */
|
1998-09-13 14:40:43 +04:00
|
|
|
|
|
|
|
p = columns [idx++];
|
|
|
|
|
1999-01-09 22:55:31 +03:00
|
|
|
/* We eat weekday name in case of extfs */
|
|
|
|
if(is_week(p, &tim))
|
1998-09-13 14:40:43 +04:00
|
|
|
p = columns [idx++];
|
|
|
|
|
1999-01-09 22:55:31 +03:00
|
|
|
/* Month name */
|
|
|
|
if(is_month(p, &tim)){
|
|
|
|
/* And we expect, it followed by day number */
|
|
|
|
if (is_num (idx))
|
|
|
|
tim.tm_mday = (int)atol (columns [idx++]);
|
|
|
|
else
|
|
|
|
return 0; /* No day */
|
|
|
|
|
|
|
|
} else {
|
|
|
|
/* We usually expect:
|
1998-09-13 14:40:43 +04:00
|
|
|
Mon DD hh:mm
|
1999-01-09 22:55:31 +03:00
|
|
|
Mon DD YYYY
|
|
|
|
But in case of extfs we allow these date formats:
|
1998-09-13 14:40:43 +04:00
|
|
|
Mon DD YYYY hh:mm
|
1999-01-09 22:55:31 +03:00
|
|
|
Mon DD hh:mm YYYY
|
1998-09-13 14:40:43 +04:00
|
|
|
Wek Mon DD hh:mm:ss YYYY
|
|
|
|
MM-DD-YY hh:mm
|
|
|
|
where Mon is Jan-Dec, DD, MM, YY two digit day, month, year,
|
1999-01-09 22:55:31 +03:00
|
|
|
YYYY four digit year, hh, mm, ss two digit hour, minute or second. */
|
|
|
|
|
|
|
|
/* Here just this special case with MM-DD-YY */
|
|
|
|
if (is_dos_date(p)){
|
|
|
|
p[2] = p[5] = '-';
|
|
|
|
|
|
|
|
if(sscanf(p, "%2d-%2d-%2d", &d[0], &d[1], &d[2]) == 3){
|
|
|
|
/* We expect to get:
|
|
|
|
1. MM-DD-YY
|
|
|
|
2. DD-MM-YY
|
|
|
|
3. YY-MM-DD
|
|
|
|
4. YY-DD-MM */
|
|
|
|
|
|
|
|
/* Hmm... maybe, next time :)*/
|
|
|
|
|
|
|
|
/* At last, MM-DD-YY */
|
|
|
|
d[0]--; /* Months are zerobased */
|
|
|
|
/* Y2K madness */
|
|
|
|
if(d[2] < 70)
|
|
|
|
d[2] += 100;
|
|
|
|
|
|
|
|
tim.tm_mon = d[0];
|
|
|
|
tim.tm_mday = d[1];
|
|
|
|
tim.tm_year = d[2];
|
|
|
|
got_year = 1;
|
|
|
|
} else
|
|
|
|
return 0; /* sscanf failed */
|
1998-09-13 14:40:43 +04:00
|
|
|
} else
|
1999-01-09 22:55:31 +03:00
|
|
|
return 0; /* unsupported format */
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
|
1999-01-09 22:55:31 +03:00
|
|
|
/* Here we expect to find time and/or year */
|
1998-09-13 14:40:43 +04:00
|
|
|
|
|
|
|
if (is_num (idx)) {
|
1999-01-07 08:54:16 +03:00
|
|
|
if(is_time(columns[idx], &tim) || (got_year = is_year(columns[idx], &tim))) {
|
2000-01-05 17:13:57 +03:00
|
|
|
idx++;
|
1999-01-09 22:55:31 +03:00
|
|
|
|
|
|
|
/* This is a special case for ctime() or Mon DD YYYY hh:mm */
|
2000-01-05 17:13:57 +03:00
|
|
|
if(is_num (idx) && (columns[idx+1][0]) &&
|
1999-01-07 08:54:16 +03:00
|
|
|
((got_year = is_year(columns[idx], &tim)) || is_time(columns[idx], &tim)))
|
1999-01-09 22:55:31 +03:00
|
|
|
idx++; /* time & year or reverse */
|
|
|
|
} /* only time or date */
|
1998-09-13 14:40:43 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0; /* Nor time or date */
|
|
|
|
|
1999-01-07 08:54:16 +03:00
|
|
|
/*
|
|
|
|
* If the date is less than 6 months in the past, it is shown without year
|
|
|
|
* other dates in the past or future are shown with year but without time
|
|
|
|
* This does not check for years before 1900 ... I don't know, how
|
|
|
|
* to represent them at all
|
|
|
|
*/
|
|
|
|
if (!got_year &&
|
1999-01-09 22:55:31 +03:00
|
|
|
current_mon < 6 && current_mon < tim.tm_mon &&
|
|
|
|
tim.tm_mon - current_mon >= 6)
|
1999-01-07 08:54:16 +03:00
|
|
|
|
1999-01-09 22:55:31 +03:00
|
|
|
tim.tm_year--;
|
1999-01-07 08:54:16 +03:00
|
|
|
|
1999-01-09 22:55:31 +03:00
|
|
|
if ((*t = mktime(&tim)) < 0)
|
1998-09-13 14:40:43 +04:00
|
|
|
*t = 0;
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
int
|
|
|
|
vfs_parse_ls_lga (char *p, struct stat *s, char **filename, char **linkname)
|
1998-09-13 14:40:43 +04:00
|
|
|
{
|
1999-01-11 03:48:23 +03:00
|
|
|
int idx, idx2, num_cols;
|
1998-02-27 07:54:42 +03:00
|
|
|
int i;
|
|
|
|
char *p_copy;
|
|
|
|
|
1998-09-13 14:40:43 +04:00
|
|
|
if (strncmp (p, "total", 5) == 0)
|
1998-02-27 07:54:42 +03:00
|
|
|
return 0;
|
1998-09-13 14:40:43 +04:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
p_copy = g_strdup(p);
|
1998-10-13 02:07:53 +04:00
|
|
|
if ((i = vfs_parse_filetype(*(p++))) == -1)
|
1998-11-16 18:52:27 +03:00
|
|
|
goto error;
|
1998-09-13 14:40:43 +04:00
|
|
|
|
|
|
|
s->st_mode = i;
|
1999-01-28 20:28:11 +03:00
|
|
|
if (*p == ' ') /* Notwell 4 */
|
|
|
|
p++;
|
1998-05-26 04:53:24 +04:00
|
|
|
if (*p == '['){
|
1998-02-27 07:54:42 +03:00
|
|
|
if (strlen (p) <= 8 || p [8] != ']')
|
1998-11-16 18:52:27 +03:00
|
|
|
goto error;
|
1998-02-27 07:54:42 +03:00
|
|
|
/* Should parse here the Notwell permissions :) */
|
|
|
|
if (S_ISDIR (s->st_mode))
|
|
|
|
s->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IXUSR | S_IXGRP | S_IXOTH);
|
|
|
|
else
|
|
|
|
s->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR);
|
|
|
|
p += 9;
|
|
|
|
} else {
|
1998-11-26 02:34:00 +03:00
|
|
|
if ((i = vfs_parse_filemode(p)) == -1)
|
1998-11-16 18:52:27 +03:00
|
|
|
goto error;
|
1998-09-13 14:40:43 +04:00
|
|
|
s->st_mode |= i;
|
|
|
|
p += 9;
|
1998-11-26 02:34:00 +03:00
|
|
|
|
|
|
|
/* This is for an extra ACL attribute (HP-UX) */
|
|
|
|
if (*p == '+')
|
|
|
|
p++;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
1998-11-22 19:17:42 +03:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free(p_copy);
|
|
|
|
p_copy = g_strdup(p);
|
1998-10-13 02:07:53 +04:00
|
|
|
num_cols = vfs_split_text (p);
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
s->st_nlink = atol (columns [0]);
|
1999-03-13 01:11:07 +03:00
|
|
|
if (s->st_nlink < 0)
|
1998-11-16 18:52:27 +03:00
|
|
|
goto error;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
if (!is_num (1))
|
|
|
|
s->st_uid = finduid (columns [1]);
|
|
|
|
else
|
|
|
|
s->st_uid = (uid_t) atol (columns [1]);
|
|
|
|
|
|
|
|
/* Mhm, the ls -lg did not produce a group field */
|
|
|
|
for (idx = 3; idx <= 5; idx++)
|
1999-01-09 22:55:31 +03:00
|
|
|
if (is_month(columns [idx], NULL) || is_week(columns [idx], NULL) || is_dos_date(columns[idx]))
|
1998-02-27 07:54:42 +03:00
|
|
|
break;
|
1999-01-09 22:55:31 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
if (idx == 6 || (idx == 5 && !S_ISCHR (s->st_mode) && !S_ISBLK (s->st_mode)))
|
1999-01-09 22:55:31 +03:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* We don't have gid */
|
|
|
|
if (idx == 3 || (idx == 4 && (S_ISCHR(s->st_mode) || S_ISBLK (s->st_mode))))
|
1998-02-27 07:54:42 +03:00
|
|
|
idx2 = 2;
|
1999-01-09 22:55:31 +03:00
|
|
|
else {
|
|
|
|
/* We have gid field */
|
1998-02-27 07:54:42 +03:00
|
|
|
if (is_num (2))
|
|
|
|
s->st_gid = (gid_t) atol (columns [2]);
|
|
|
|
else
|
|
|
|
s->st_gid = findgid (columns [2]);
|
|
|
|
idx2 = 3;
|
|
|
|
}
|
|
|
|
|
1999-01-09 22:55:31 +03:00
|
|
|
/* This is device */
|
1998-05-26 04:53:24 +04:00
|
|
|
if (S_ISCHR (s->st_mode) || S_ISBLK (s->st_mode)){
|
1999-01-09 22:55:31 +03:00
|
|
|
int maj, min;
|
|
|
|
|
|
|
|
if (!is_num (idx2) || sscanf(columns [idx2], " %d,", &maj) != 1)
|
|
|
|
goto error;
|
|
|
|
|
1999-01-11 03:48:23 +03:00
|
|
|
if (!is_num (++idx2) || sscanf(columns [idx2], " %d", &min) != 1)
|
1998-11-16 18:52:27 +03:00
|
|
|
goto error;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_ST_RDEV
|
1999-01-09 22:55:31 +03:00
|
|
|
s->st_rdev = ((maj & 0xff) << 8) | (min & 0xffff00ff);
|
1998-02-27 07:54:42 +03:00
|
|
|
#endif
|
|
|
|
s->st_size = 0;
|
1999-01-09 22:55:31 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
} else {
|
1999-01-09 22:55:31 +03:00
|
|
|
/* Common file size */
|
1998-02-27 07:54:42 +03:00
|
|
|
if (!is_num (idx2))
|
1998-11-16 18:52:27 +03:00
|
|
|
goto error;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
s->st_size = (size_t) atol (columns [idx2]);
|
|
|
|
#ifdef HAVE_ST_RDEV
|
|
|
|
s->st_rdev = 0;
|
|
|
|
#endif
|
|
|
|
}
|
1998-06-01 16:52:18 +04:00
|
|
|
|
1998-10-13 02:07:53 +04:00
|
|
|
idx = vfs_parse_filedate(idx, &s->st_mtime);
|
1998-09-13 14:40:43 +04:00
|
|
|
if (!idx)
|
1998-11-16 18:52:27 +03:00
|
|
|
goto error;
|
1998-09-13 14:40:43 +04:00
|
|
|
/* Use resulting time value */
|
|
|
|
s->st_atime = s->st_ctime = s->st_mtime;
|
2000-03-06 19:31:37 +03:00
|
|
|
#if 0
|
|
|
|
/* These variables must be initialized by vfs_s_new_inode () */
|
1998-02-27 07:54:42 +03:00
|
|
|
s->st_dev = 0;
|
|
|
|
s->st_ino = 0;
|
2000-03-06 19:31:37 +03:00
|
|
|
#endif
|
1998-02-27 07:54:42 +03:00
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
|
|
|
s->st_blksize = 512;
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ST_BLOCKS
|
|
|
|
s->st_blocks = (s->st_size + 511) / 512;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (i = idx + 1, idx2 = 0; i < num_cols; i++ )
|
1998-05-26 04:53:24 +04:00
|
|
|
if (strcmp (columns [i], "->") == 0){
|
1998-02-27 07:54:42 +03:00
|
|
|
idx2 = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((S_ISLNK (s->st_mode) ||
|
|
|
|
(num_cols == idx + 3 && s->st_nlink > 1))) /* Maybe a hardlink? (in extfs) */
|
|
|
|
&& idx2){
|
|
|
|
int p;
|
|
|
|
char *s;
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
if (filename){
|
1999-01-21 01:01:11 +03:00
|
|
|
s = g_strndup (p_copy + column_ptr [idx], column_ptr [idx2] - column_ptr [idx] - 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
*filename = s;
|
|
|
|
}
|
1998-05-26 04:53:24 +04:00
|
|
|
if (linkname){
|
1999-01-21 01:01:11 +03:00
|
|
|
s = g_strdup (p_copy + column_ptr [idx2+1]);
|
1999-12-16 15:55:16 +03:00
|
|
|
p = strlen (s) - 1;
|
|
|
|
if (s [p] == '\r' || s [p] == '\n')
|
|
|
|
s [p] = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (s [p-1] == '\r' || s [p-1] == '\n')
|
|
|
|
s [p-1] = 0;
|
|
|
|
|
|
|
|
*linkname = s;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Extract the filename from the string copy, not from the columns
|
|
|
|
* this way we have a chance of entering hidden directories like ". ."
|
|
|
|
*/
|
|
|
|
if (filename){
|
|
|
|
/*
|
1999-01-21 01:01:11 +03:00
|
|
|
*filename = g_strdup (columns [idx++]);
|
1998-02-27 07:54:42 +03:00
|
|
|
*/
|
|
|
|
int p;
|
|
|
|
char *s;
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
s = g_strdup (p_copy + column_ptr [idx++]);
|
1999-12-16 15:55:16 +03:00
|
|
|
p = strlen (s) - 1;
|
1999-01-21 01:01:11 +03:00
|
|
|
/* g_strchomp(); */
|
1999-12-16 15:55:16 +03:00
|
|
|
if (s [p] == '\r' || s [p] == '\n')
|
|
|
|
s [p] = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
if (s [p-1] == '\r' || s [p-1] == '\n')
|
1999-12-16 15:55:16 +03:00
|
|
|
s [p-1] = 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
|
|
|
|
*filename = s;
|
|
|
|
}
|
|
|
|
if (linkname)
|
|
|
|
*linkname = NULL;
|
|
|
|
}
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (p_copy);
|
1998-11-16 18:52:27 +03:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
error:
|
1999-04-23 15:32:53 +04:00
|
|
|
{
|
|
|
|
static int errorcount = 0;
|
|
|
|
|
|
|
|
if (++errorcount < 5) {
|
1999-12-16 15:55:16 +03:00
|
|
|
message_1s (1, _("Could not parse:"), p_copy);
|
2000-05-16 18:59:33 +04:00
|
|
|
} else if (errorcount == 5)
|
1999-12-16 15:55:16 +03:00
|
|
|
message_1s (1, _("More parsing errors will be ignored."), _("(sorry)"));
|
1999-04-23 15:32:53 +04:00
|
|
|
}
|
|
|
|
|
1998-11-22 19:17:42 +03:00
|
|
|
if (p_copy != p) /* Carefull! */
|
1999-01-21 01:01:11 +03:00
|
|
|
g_free (p_copy);
|
1998-11-16 18:52:27 +03:00
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
void
|
|
|
|
vfs_die (char *m)
|
|
|
|
{
|
1999-12-16 15:55:16 +03:00
|
|
|
message_1s (1, _("Internal error:"), m);
|
1998-05-26 04:53:24 +04:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
1998-09-21 13:52:07 +04:00
|
|
|
void
|
1998-10-13 02:07:53 +04:00
|
|
|
vfs_print_stats (char *fs_name, char *action, char *file_name, int have, int need)
|
1998-09-21 13:52:07 +04:00
|
|
|
{
|
1999-08-16 09:31:23 +04:00
|
|
|
static char *i18n_percent_transf_format = NULL, *i18n_transf_format = NULL;
|
|
|
|
|
|
|
|
if (i18n_percent_transf_format == NULL) {
|
|
|
|
i18n_percent_transf_format = _("%s: %s: %s %3d%% (%ld bytes transfered)");
|
|
|
|
i18n_transf_format = _("%s: %s: %s %ld bytes transfered");
|
|
|
|
}
|
|
|
|
|
1998-09-21 13:52:07 +04:00
|
|
|
if (need)
|
1999-08-16 09:31:23 +04:00
|
|
|
print_vfs_message (i18n_percent_transf_format,
|
1998-09-21 13:52:07 +04:00
|
|
|
fs_name, action, file_name, have*100/need, have);
|
|
|
|
else
|
1999-08-16 09:31:23 +04:00
|
|
|
print_vfs_message (i18n_transf_format,
|
1998-09-21 13:52:07 +04:00
|
|
|
fs_name, action, file_name, have);
|
|
|
|
}
|
|
|
|
|
1998-05-26 04:53:24 +04:00
|
|
|
#ifndef VFS_STANDALONE
|
|
|
|
char *
|
|
|
|
vfs_get_password (char *msg)
|
|
|
|
{
|
1998-05-26 23:46:37 +04:00
|
|
|
return (char *) input_dialog (msg, _("Password:"), "");
|
1998-05-26 04:53:24 +04:00
|
|
|
}
|
|
|
|
#endif
|
1998-10-13 02:07:53 +04:00
|
|
|
|
1998-10-14 06:56:18 +04:00
|
|
|
/*
|
|
|
|
* Returns vfs path corresponding to given url. If passed string is
|
1999-01-21 01:01:11 +03:00
|
|
|
* not recognized as url, g_strdup(url) is returned.
|
1998-10-14 06:56:18 +04:00
|
|
|
*/
|
1998-10-13 02:07:53 +04:00
|
|
|
char *
|
|
|
|
vfs_translate_url (char *url)
|
|
|
|
{
|
|
|
|
if (strncmp (url, "ftp://", 6) == 0)
|
1999-01-27 03:49:11 +03:00
|
|
|
return g_strconcat ("/#ftp:", url + 6, NULL);
|
1998-10-13 02:07:53 +04:00
|
|
|
else
|
1999-01-21 01:01:11 +03:00
|
|
|
return g_strdup (url);
|
1998-10-13 02:07:53 +04:00
|
|
|
}
|