2009-02-07 15:54:58 +03:00
|
|
|
/** \file
|
|
|
|
* \brief Source: directory cache support
|
|
|
|
*
|
|
|
|
* So that you do not have copy of this in each and every filesystem.
|
1998-10-23 12:26:25 +04:00
|
|
|
*
|
2009-02-07 15:54:58 +03:00
|
|
|
* Very loosely based on tar.c from midnight and archives.[ch] from
|
|
|
|
* avfs by Miklos Szeredi (mszeredi@inf.bme.hu)
|
1998-10-23 12:26:25 +04:00
|
|
|
*
|
2009-02-07 15:54:58 +03:00
|
|
|
* Unfortunately, I was unable to keep all filesystems
|
|
|
|
* uniform. tar-like filesystems use tree structure where each
|
|
|
|
* directory has pointers to its subdirectories. We can do this
|
|
|
|
* because we have full information about our archive.
|
1998-11-21 22:36:01 +03:00
|
|
|
*
|
2009-02-07 15:54:58 +03:00
|
|
|
* At ftp-like filesystems, situation is a little bit different. When
|
|
|
|
* you cd /usr/src/linux/drivers/char, you do _not_ want /usr,
|
|
|
|
* /usr/src, /usr/src/linux and /usr/src/linux/drivers to be
|
|
|
|
* listed. That means that we do not have complete information, and if
|
|
|
|
* /usr is symlink to /4, we will not know. Also we have to time out
|
|
|
|
* entries and things would get messy with tree-like approach. So we
|
|
|
|
* do different trick: root directory is completely special and
|
|
|
|
* completely fake, it contains entries such as 'usr', 'usr/src', ...,
|
|
|
|
* and we'll try to use custom find_entry function.
|
1998-11-21 22:36:01 +03:00
|
|
|
*
|
2009-02-07 15:54:58 +03:00
|
|
|
* \author Pavel Machek <pavel@ucw.cz>, distribute under LGPL.
|
|
|
|
* \date 1998
|
1998-11-21 22:36:01 +03:00
|
|
|
*
|
2009-02-07 15:54:58 +03:00
|
|
|
* \warning Paths here do _not_ begin with '/', so root directory of
|
|
|
|
* archive/site is simply "".
|
|
|
|
*/
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2001-06-26 01:34:46 +04:00
|
|
|
#include <config.h>
|
2009-01-30 22:10:40 +03:00
|
|
|
|
2003-10-16 12:47:33 +04:00
|
|
|
#include <errno.h>
|
2010-03-30 12:10:25 +04:00
|
|
|
#include <fcntl.h> /* include fcntl.h -> sys/fcntl.h only */
|
|
|
|
/* includes fcntl.h see IEEE Std 1003.1-2008 */
|
2009-02-06 02:30:45 +03:00
|
|
|
#include <time.h>
|
2010-03-30 12:10:25 +04:00
|
|
|
#include <sys/time.h> /* gettimeofday() */
|
2010-11-26 11:31:18 +03:00
|
|
|
#include <inttypes.h> /* uintmax_t */
|
2011-02-16 14:26:59 +03:00
|
|
|
#include <stdarg.h>
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2010-01-20 18:11:52 +03:00
|
|
|
#include "lib/global.h"
|
2009-05-08 14:01:05 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
#include "lib/tty/tty.h" /* enable/disable interrupt key */
|
2010-07-22 15:55:23 +04:00
|
|
|
#include "lib/util.h" /* concat_dir_and_file */
|
2010-11-12 11:03:57 +03:00
|
|
|
#if 0
|
|
|
|
#include "lib/widget.h" /* message() */
|
|
|
|
#endif
|
2010-01-07 02:57:27 +03:00
|
|
|
|
2011-02-15 16:44:17 +03:00
|
|
|
#include "vfs.h"
|
2010-07-22 12:07:07 +04:00
|
|
|
#include "utilvfs.h"
|
1998-10-24 00:18:48 +04:00
|
|
|
#include "xdirentry.h"
|
2010-07-22 12:07:07 +04:00
|
|
|
#include "gc.h" /* vfs_rmstamp */
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** global variables ****************************************************************************/
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope macro definitions ****************************************************************/
|
2009-12-12 13:54:22 +03:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
#define CALL(x) if (MEDATA->x) MEDATA->x
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope type declarations ****************************************************************/
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
struct dirhandle
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2011-03-28 16:17:45 +04:00
|
|
|
GList *cur;
|
2010-11-08 13:21:45 +03:00
|
|
|
struct vfs_s_inode *dir;
|
|
|
|
};
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope variables ************************************************************************/
|
2000-04-28 11:43:13 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
static volatile int total_inodes = 0, total_entries = 0;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/*** file scope functions ************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
static int
|
|
|
|
vfs_s_entry_compare (const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const struct vfs_s_entry *e = (const struct vfs_s_entry *) a;
|
|
|
|
const char *name = (const char *) b;
|
|
|
|
|
|
|
|
return strcmp (e->name, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2001-06-15 00:08:27 +04:00
|
|
|
static void
|
2003-10-12 05:00:44 +04:00
|
|
|
vfs_s_free_inode (struct vfs_class *me, struct vfs_s_inode *ino)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2011-03-28 16:17:45 +04:00
|
|
|
if (ino == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_die ("Don't pass NULL to me");
|
1998-10-23 12:26:25 +04:00
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
/* ==0 can happen if freshly created entry is deleted */
|
2011-03-28 16:17:45 +04:00
|
|
|
if (ino->st.st_nlink > 1)
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
2011-03-28 16:17:45 +04:00
|
|
|
ino->st.st_nlink--;
|
|
|
|
return;
|
|
|
|
}
|
2010-03-30 12:10:25 +04:00
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
while (ino->subdir != NULL)
|
|
|
|
vfs_s_free_entry (me, (struct vfs_s_entry *) ino->subdir->data);
|
|
|
|
|
|
|
|
CALL (free_inode) (me, ino);
|
|
|
|
g_free (ino->linkname);
|
|
|
|
if (ino->localname != NULL)
|
|
|
|
{
|
|
|
|
unlink (ino->localname);
|
|
|
|
g_free (ino->localname);
|
2010-03-30 12:10:25 +04:00
|
|
|
}
|
2011-03-28 16:17:45 +04:00
|
|
|
total_inodes--;
|
|
|
|
ino->super->ino_usage--;
|
|
|
|
g_free (ino);
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
1998-11-21 22:36:01 +03:00
|
|
|
/* We were asked to create entries automagically */
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2003-10-12 05:00:44 +04:00
|
|
|
static struct vfs_s_entry *
|
|
|
|
vfs_s_automake (struct vfs_class *me, struct vfs_s_inode *dir, char *path, int flags)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
|
|
|
struct vfs_s_entry *res;
|
2011-03-28 16:17:45 +04:00
|
|
|
char *sep;
|
|
|
|
|
|
|
|
sep = strchr (path, PATH_SEP);
|
|
|
|
if (sep != NULL)
|
|
|
|
*sep = '\0';
|
2010-03-30 12:10:25 +04:00
|
|
|
|
1999-01-18 02:10:05 +03:00
|
|
|
res = vfs_s_generate_entry (me, path, dir, flags & FL_MKDIR ? (0777 | S_IFDIR) : 0777);
|
|
|
|
vfs_s_insert_entry (me, dir, res);
|
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
if (sep != NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
*sep = PATH_SEP;
|
1999-01-18 02:10:05 +03:00
|
|
|
|
1998-10-23 12:26:25 +04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2003-10-17 03:58:43 +04:00
|
|
|
/* If the entry is a symlink, find the entry for its target */
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2003-10-17 03:58:43 +04:00
|
|
|
static struct vfs_s_entry *
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_s_resolve_symlink (struct vfs_class *me, struct vfs_s_entry *entry, int follow)
|
2003-10-17 03:58:43 +04:00
|
|
|
{
|
|
|
|
char *linkname;
|
|
|
|
char *fullname = NULL;
|
|
|
|
struct vfs_s_entry *target;
|
|
|
|
|
|
|
|
if (follow == LINK_NO_FOLLOW)
|
2010-03-30 12:10:25 +04:00
|
|
|
return entry;
|
2003-10-17 03:58:43 +04:00
|
|
|
if (follow == 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
ERRNOR (ELOOP, NULL);
|
2003-10-17 03:58:43 +04:00
|
|
|
if (!entry)
|
2010-03-30 12:10:25 +04:00
|
|
|
ERRNOR (ENOENT, NULL);
|
2003-10-17 03:58:43 +04:00
|
|
|
if (!S_ISLNK (entry->ino->st.st_mode))
|
2010-03-30 12:10:25 +04:00
|
|
|
return entry;
|
2003-10-17 03:58:43 +04:00
|
|
|
|
|
|
|
linkname = entry->ino->linkname;
|
|
|
|
if (linkname == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
ERRNOR (EFAULT, NULL);
|
2003-10-17 03:58:43 +04:00
|
|
|
|
|
|
|
/* make full path from relative */
|
2010-03-30 12:10:25 +04:00
|
|
|
if (*linkname != PATH_SEP)
|
|
|
|
{
|
|
|
|
char *fullpath = vfs_s_fullpath (me, entry->dir);
|
|
|
|
if (fullpath)
|
|
|
|
{
|
|
|
|
fullname = g_strconcat (fullpath, "/", linkname, (char *) NULL);
|
|
|
|
linkname = fullname;
|
|
|
|
g_free (fullpath);
|
|
|
|
}
|
2003-10-17 03:58:43 +04:00
|
|
|
}
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
target = (MEDATA->find_entry) (me, entry->dir->super->root, linkname, follow - 1, 0);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (fullname);
|
2003-10-17 03:58:43 +04:00
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
1999-01-18 02:10:05 +03:00
|
|
|
/*
|
|
|
|
* Follow > 0: follow links, serves as loop protect,
|
|
|
|
* == -1: do not follow links
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2003-10-28 10:09:39 +03:00
|
|
|
static struct vfs_s_entry *
|
2003-10-17 03:58:43 +04:00
|
|
|
vfs_s_find_entry_tree (struct vfs_class *me, struct vfs_s_inode *root,
|
2010-03-30 12:10:25 +04:00
|
|
|
const char *a_path, int follow, int flags)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2004-09-04 01:23:05 +04:00
|
|
|
size_t pseg;
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_entry *ent = NULL;
|
2010-03-30 12:10:25 +04:00
|
|
|
char *const pathref = g_strdup (a_path);
|
2004-09-22 15:28:14 +04:00
|
|
|
char *path = pathref;
|
2003-10-17 03:58:43 +04:00
|
|
|
|
2009-11-23 11:45:46 +03:00
|
|
|
/* canonicalize as well, but don't remove '../' from path */
|
2009-12-25 18:18:50 +03:00
|
|
|
custom_canonicalize_pathname (path, CANON_PATH_ALL & (~CANON_PATH_REMDOUBLEDOTS));
|
2003-10-17 07:25:43 +04:00
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
while (root != NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
2011-03-28 16:17:45 +04:00
|
|
|
GList *iter;
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
while (*path == PATH_SEP) /* Strip leading '/' */
|
|
|
|
path++;
|
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
if (path[0] == '\0')
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
|
|
|
g_free (pathref);
|
|
|
|
return ent;
|
|
|
|
}
|
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
for (pseg = 0; path[pseg] != '\0' && path[pseg] != PATH_SEP; pseg++)
|
|
|
|
;
|
2010-03-30 12:10:25 +04:00
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
for (iter = root->subdir; iter != NULL; iter = g_list_next (iter))
|
|
|
|
{
|
|
|
|
ent = (struct vfs_s_entry *) iter->data;
|
|
|
|
if (strlen (ent->name) == pseg && strncmp (ent->name, path, pseg) == 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
/* FOUND! */
|
|
|
|
break;
|
2011-03-28 16:17:45 +04:00
|
|
|
}
|
2010-03-30 12:10:25 +04:00
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
ent = iter != NULL ? (struct vfs_s_entry *) iter->data : NULL;
|
|
|
|
|
|
|
|
if (ent == NULL && (flags & (FL_MKFILE | FL_MKDIR)) != 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
ent = vfs_s_automake (me, root, path, flags);
|
2011-03-28 16:17:45 +04:00
|
|
|
if (ent == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
|
|
|
me->verrno = ENOENT;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-03-28 16:17:45 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
path += pseg;
|
|
|
|
/* here we must follow leading directories always;
|
|
|
|
only the actual file is optional */
|
2011-03-28 16:17:45 +04:00
|
|
|
ent = vfs_s_resolve_symlink (me, ent,
|
|
|
|
strchr (path, PATH_SEP) != NULL ? LINK_FOLLOW : follow);
|
|
|
|
if (ent == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
goto cleanup;
|
|
|
|
root = ent->ino;
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
2010-03-30 12:10:25 +04:00
|
|
|
cleanup:
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (pathref);
|
2000-04-28 11:43:13 +04:00
|
|
|
return NULL;
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
1999-01-18 02:10:05 +03:00
|
|
|
static void
|
2003-10-12 04:24:00 +04:00
|
|
|
split_dir_name (struct vfs_class *me, char *path, char **dir, char **name, char **save)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
|
|
|
char *s;
|
2005-02-22 21:35:22 +03:00
|
|
|
|
|
|
|
(void) me;
|
|
|
|
|
1999-01-18 02:10:05 +03:00
|
|
|
s = strrchr (path, PATH_SEP);
|
2010-03-30 12:10:25 +04:00
|
|
|
if (s == NULL)
|
|
|
|
{
|
|
|
|
*save = NULL;
|
|
|
|
*name = path;
|
|
|
|
*dir = path + strlen (path); /* an empty string */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*save = s;
|
|
|
|
*dir = path;
|
|
|
|
*s++ = '\0';
|
|
|
|
*name = s;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-28 10:09:39 +03:00
|
|
|
static struct vfs_s_entry *
|
|
|
|
vfs_s_find_entry_linear (struct vfs_class *me, struct vfs_s_inode *root,
|
2010-03-30 12:10:25 +04:00
|
|
|
const char *a_path, int follow, int flags)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
2003-10-28 10:09:39 +03:00
|
|
|
struct vfs_s_entry *ent = NULL;
|
2010-03-30 12:10:25 +04:00
|
|
|
char *const path = g_strdup (a_path);
|
2004-09-22 15:28:14 +04:00
|
|
|
struct vfs_s_entry *retval = NULL;
|
2011-03-28 16:17:45 +04:00
|
|
|
GList *iter;
|
1998-11-21 22:36:01 +03:00
|
|
|
|
1999-11-03 17:51:22 +03:00
|
|
|
if (root->super->root != root)
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_die ("We have to use _real_ root. Always. Sorry.");
|
1999-11-03 17:51:22 +03:00
|
|
|
|
2009-11-23 11:45:46 +03:00
|
|
|
/* canonicalize as well, but don't remove '../' from path */
|
2009-12-25 18:18:50 +03:00
|
|
|
custom_canonicalize_pathname (path, CANON_PATH_ALL & (~CANON_PATH_REMDOUBLEDOTS));
|
2002-07-27 01:58:43 +04:00
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
if ((flags & FL_DIR) == 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
|
|
|
char *dirname, *name, *save;
|
|
|
|
struct vfs_s_inode *ino;
|
|
|
|
split_dir_name (me, path, &dirname, &name, &save);
|
|
|
|
ino = vfs_s_find_inode (me, root->super, dirname, follow, flags | FL_DIR);
|
2011-03-28 16:17:45 +04:00
|
|
|
if (save != NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
*save = PATH_SEP;
|
|
|
|
retval = vfs_s_find_entry_tree (me, ino, name, follow, flags);
|
|
|
|
g_free (path);
|
|
|
|
return retval;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
iter = g_list_find_custom (root->subdir, path, (GCompareFunc) vfs_s_entry_compare);
|
|
|
|
ent = iter != NULL ? (struct vfs_s_entry *) iter->data : NULL;
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
if (ent != NULL && !MEDATA->dir_uptodate (me, ent->ino))
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
1998-12-09 23:22:53 +03:00
|
|
|
#if 1
|
2011-02-16 14:26:59 +03:00
|
|
|
vfs_print_message (_("Directory cache expired for %s"), path);
|
1998-11-21 22:36:01 +03:00
|
|
|
#endif
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_s_free_entry (me, ent);
|
|
|
|
ent = NULL;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
if (ent == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
|
|
|
struct vfs_s_inode *ino;
|
|
|
|
|
|
|
|
ino = vfs_s_new_inode (me, root->super, vfs_s_default_stat (me, S_IFDIR | 0755));
|
|
|
|
ent = vfs_s_new_entry (me, path, ino);
|
2011-03-28 16:17:45 +04:00
|
|
|
if (MEDATA->dir_load (me, ino, path) == -1)
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
|
|
|
vfs_s_free_entry (me, ent);
|
|
|
|
g_free (path);
|
|
|
|
return NULL;
|
|
|
|
}
|
2011-03-28 16:17:45 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_s_insert_entry (me, root, ent);
|
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
iter = g_list_find_custom (root->subdir, path, (GCompareFunc) vfs_s_entry_compare);
|
|
|
|
ent = iter != NULL ? (struct vfs_s_entry *) iter->data : NULL;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
2011-03-28 16:17:45 +04:00
|
|
|
if (ent == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_die ("find_linear: success but directory is not there\n");
|
1998-11-21 22:36:01 +03:00
|
|
|
|
|
|
|
#if 0
|
2010-03-30 12:10:25 +04:00
|
|
|
if (!vfs_s_resolve_symlink (me, ent, follow))
|
|
|
|
{
|
|
|
|
g_free (path);
|
|
|
|
return NULL;
|
2004-09-22 15:28:14 +04:00
|
|
|
}
|
1998-11-21 22:36:01 +03:00
|
|
|
#endif
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (path);
|
1998-11-21 22:36:01 +03:00
|
|
|
return ent;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
2002-03-06 11:46:35 +03:00
|
|
|
/* Ook, these were functions around directory entries / inodes */
|
1998-10-23 12:26:25 +04:00
|
|
|
/* -------------------------------- superblock games -------------------------- */
|
|
|
|
|
2003-10-12 05:00:44 +04:00
|
|
|
static struct vfs_s_super *
|
2003-10-12 04:24:00 +04:00
|
|
|
vfs_s_new_super (struct vfs_class *me)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2003-10-12 05:00:44 +04:00
|
|
|
struct vfs_s_super *super;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
super = g_new0 (struct vfs_s_super, 1);
|
1998-10-23 12:26:25 +04:00
|
|
|
super->me = me;
|
1998-12-02 08:11:48 +03:00
|
|
|
return super;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2011-03-28 15:18:21 +04:00
|
|
|
static inline void
|
2003-10-12 05:00:44 +04:00
|
|
|
vfs_s_insert_super (struct vfs_class *me, struct vfs_s_super *super)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
2011-03-28 15:18:21 +04:00
|
|
|
MEDATA->supers = g_list_prepend (MEDATA->supers, super);
|
2010-03-30 12:10:25 +04:00
|
|
|
}
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-08 02:38:28 +04:00
|
|
|
static void
|
2003-10-12 05:00:44 +04:00
|
|
|
vfs_s_free_super (struct vfs_class *me, struct vfs_s_super *super)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2011-03-28 16:17:45 +04:00
|
|
|
if (super->root != NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
|
|
|
vfs_s_free_inode (me, super->root);
|
|
|
|
super->root = NULL;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
1998-10-23 12:26:25 +04:00
|
|
|
|
1999-12-08 14:39:14 +03:00
|
|
|
#if 0
|
1999-12-16 15:55:16 +03:00
|
|
|
/* FIXME: We currently leak small ammount of memory, sometimes. Fix it if you can. */
|
1998-12-31 18:54:49 +03:00
|
|
|
if (super->ino_usage)
|
2010-05-15 18:45:13 +04:00
|
|
|
message (D_ERROR, "Direntry warning",
|
2010-03-30 12:10:25 +04:00
|
|
|
"Super ino_usage is %d, memory leak", super->ino_usage);
|
1998-12-09 23:22:53 +03:00
|
|
|
|
|
|
|
if (super->want_stale)
|
2010-05-15 18:45:13 +04:00
|
|
|
message (D_ERROR, "Direntry warning", "%s", "Super has want_stale set");
|
1998-11-21 22:36:01 +03:00
|
|
|
#endif
|
|
|
|
|
2011-03-28 15:18:21 +04:00
|
|
|
MEDATA->supers = g_list_remove (MEDATA->supers, super);
|
1998-10-23 12:26:25 +04:00
|
|
|
|
1999-01-18 02:10:05 +03:00
|
|
|
CALL (free_archive) (me, super);
|
2011-03-29 11:20:34 +04:00
|
|
|
#ifdef ENABLE_VFS_NET
|
|
|
|
vfs_url_free (super->url);
|
|
|
|
#endif
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (super->name);
|
2010-03-30 12:10:25 +04:00
|
|
|
g_free (super);
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
2003-11-14 11:25:50 +03:00
|
|
|
* Dissect the path and create corresponding superblock.
|
|
|
|
* The result should be freed.
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2003-10-08 02:38:28 +04:00
|
|
|
static char *
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_s_get_path (struct vfs_class *me, const char *inname, struct vfs_s_super **archive, int flags)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2005-09-05 04:52:56 +04:00
|
|
|
char *buf, *retval;
|
|
|
|
|
2009-02-06 01:40:32 +03:00
|
|
|
buf = g_strdup (inname);
|
|
|
|
retval = g_strdup (vfs_s_get_path_mangle (me, buf, archive, flags));
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (buf);
|
2005-09-05 04:52:56 +04:00
|
|
|
return retval;
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
1998-10-23 12:26:25 +04:00
|
|
|
/* Support of archives */
|
1998-11-21 22:36:01 +03:00
|
|
|
/* ------------------------ readdir & friends ----------------------------- */
|
|
|
|
|
2003-10-12 05:00:44 +04:00
|
|
|
static struct vfs_s_inode *
|
2003-10-28 05:10:33 +03:00
|
|
|
vfs_s_inode_from_path (struct vfs_class *me, const char *name, int flags)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
|
|
|
struct vfs_s_super *super;
|
2000-05-03 23:10:52 +04:00
|
|
|
struct vfs_s_inode *ino;
|
1998-11-21 22:36:01 +03:00
|
|
|
char *q;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2003-11-14 11:25:50 +03:00
|
|
|
if (!(q = vfs_s_get_path (me, name, &super, 0)))
|
2010-03-30 12:10:25 +04:00
|
|
|
return NULL;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2003-10-27 06:09:40 +03:00
|
|
|
ino =
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_s_find_inode (me, super, q,
|
|
|
|
flags & FL_FOLLOW ? LINK_FOLLOW : LINK_NO_FOLLOW, flags & ~FL_FOLLOW);
|
2006-03-30 17:04:50 +04:00
|
|
|
if ((!ino) && (!*q))
|
2010-03-30 12:10:25 +04:00
|
|
|
/* We are asking about / directory of ftp server: assume it exists */
|
|
|
|
ino =
|
|
|
|
vfs_s_find_inode (me, super, q,
|
|
|
|
flags & FL_FOLLOW ? LINK_FOLLOW :
|
|
|
|
LINK_NO_FOLLOW, FL_DIR | (flags & ~FL_FOLLOW));
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (q);
|
2000-05-03 23:10:52 +04:00
|
|
|
return ino;
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static void *
|
2011-04-20 16:59:06 +04:00
|
|
|
vfs_s_opendir (const vfs_path_t * vpath)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
1998-11-21 22:36:01 +03:00
|
|
|
struct vfs_s_inode *dir;
|
|
|
|
struct dirhandle *info;
|
2011-04-20 16:59:06 +04:00
|
|
|
vfs_path_element_t *path_element;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2011-04-20 16:59:06 +04:00
|
|
|
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
|
|
|
|
dir = vfs_s_inode_from_path (path_element->class, vpath->unparsed, FL_DIR | FL_FOLLOW);
|
2011-03-28 16:17:45 +04:00
|
|
|
if (dir == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
return NULL;
|
1999-01-11 03:48:23 +03:00
|
|
|
if (!S_ISDIR (dir->st.st_mode))
|
2011-04-20 16:59:06 +04:00
|
|
|
{
|
|
|
|
path_element->class->verrno = ENOTDIR;
|
|
|
|
return NULL;
|
|
|
|
}
|
1998-10-23 12:26:25 +04:00
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
dir->st.st_nlink++;
|
|
|
|
#if 0
|
2011-03-28 16:17:45 +04:00
|
|
|
if (dir->subdir == NULL) /* This can actually happen if we allow empty directories */
|
2011-04-20 16:59:06 +04:00
|
|
|
{
|
|
|
|
path_element->class->verrno = EAGAIN;
|
|
|
|
return NULL;
|
|
|
|
}
|
1998-11-21 22:36:01 +03:00
|
|
|
#endif
|
1999-01-21 01:01:11 +03:00
|
|
|
info = g_new (struct dirhandle, 1);
|
1998-11-21 22:36:01 +03:00
|
|
|
info->cur = dir->subdir;
|
|
|
|
info->dir = dir;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static void *
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_s_readdir (void *data)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2002-08-16 01:15:17 +04:00
|
|
|
static union vfs_dirent dir;
|
1998-11-21 22:36:01 +03:00
|
|
|
struct dirhandle *info = (struct dirhandle *) data;
|
2011-03-28 16:17:45 +04:00
|
|
|
const char *name;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
if (info->cur == NULL || info->cur->data == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
return NULL;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
name = ((struct vfs_s_entry *) info->cur->data)->name;
|
|
|
|
if (name != NULL)
|
|
|
|
g_strlcpy (dir.dent.d_name, name, MC_MAXPATHLEN);
|
2010-03-30 12:10:25 +04:00
|
|
|
else
|
|
|
|
vfs_die ("Null in structure-cannot happen");
|
1999-01-11 03:48:23 +03:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
compute_namelen (&dir.dent);
|
2011-03-28 16:17:45 +04:00
|
|
|
info->cur = g_list_next (info->cur);
|
2002-08-16 01:15:17 +04:00
|
|
|
|
|
|
|
return (void *) &dir;
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static int
|
1999-01-18 02:10:05 +03:00
|
|
|
vfs_s_closedir (void *data)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
1998-11-21 22:36:01 +03:00
|
|
|
struct dirhandle *info = (struct dirhandle *) data;
|
|
|
|
struct vfs_s_inode *dir = info->dir;
|
|
|
|
|
1999-01-18 02:10:05 +03:00
|
|
|
vfs_s_free_inode (dir->super->me, dir);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (data);
|
1998-10-23 12:26:25 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static int
|
2011-04-20 16:59:06 +04:00
|
|
|
vfs_s_chdir (const vfs_path_t * vpath)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
|
|
|
void *data;
|
2010-03-30 22:59:41 +04:00
|
|
|
|
2011-04-20 16:59:06 +04:00
|
|
|
data = vfs_s_opendir (vpath);
|
2010-03-30 22:59:41 +04:00
|
|
|
if (data == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
return -1;
|
1999-01-18 02:10:05 +03:00
|
|
|
vfs_s_closedir (data);
|
1998-10-23 12:26:25 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
1998-11-21 22:36:01 +03:00
|
|
|
/* --------------------------- stat and friends ---------------------------- */
|
1998-10-23 12:26:25 +04:00
|
|
|
|
1999-01-18 02:10:05 +03:00
|
|
|
static int
|
2011-04-20 16:59:06 +04:00
|
|
|
vfs_s_internal_stat (const vfs_path_t * vpath, struct stat *buf, int flag)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
|
|
|
struct vfs_s_inode *ino;
|
2011-04-20 16:59:06 +04:00
|
|
|
vfs_path_element_t *path_element;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2011-04-20 16:59:06 +04:00
|
|
|
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
|
|
|
|
ino = vfs_s_inode_from_path (path_element->class, vpath->unparsed, flag);
|
2010-03-30 22:59:41 +04:00
|
|
|
if (ino == NULL)
|
2000-05-03 23:10:52 +04:00
|
|
|
return -1;
|
1998-10-23 12:26:25 +04:00
|
|
|
*buf = ino->st;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static int
|
2011-04-20 16:59:06 +04:00
|
|
|
vfs_s_stat (const vfs_path_t * vpath, struct stat *buf)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2011-04-20 16:59:06 +04:00
|
|
|
return vfs_s_internal_stat (vpath, buf, FL_FOLLOW);
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static int
|
2011-04-20 16:59:06 +04:00
|
|
|
vfs_s_lstat (const vfs_path_t * vpath, struct stat *buf)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2011-04-20 16:59:06 +04:00
|
|
|
return vfs_s_internal_stat (vpath, buf, FL_NONE);
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static int
|
1999-01-18 02:10:05 +03:00
|
|
|
vfs_s_fstat (void *fh, struct stat *buf)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
|
|
|
*buf = FH->ino->st;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static int
|
2011-04-21 11:46:20 +04:00
|
|
|
vfs_s_readlink (const vfs_path_t * vpath, char *buf, size_t size)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
|
|
|
struct vfs_s_inode *ino;
|
2004-09-02 18:12:21 +04:00
|
|
|
size_t len;
|
2011-04-21 11:46:20 +04:00
|
|
|
vfs_path_element_t *path_element;
|
|
|
|
|
|
|
|
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2011-04-21 11:46:20 +04:00
|
|
|
ino = vfs_s_inode_from_path (path_element->class, vpath->unparsed, 0);
|
1999-01-11 03:48:23 +03:00
|
|
|
if (!ino)
|
2010-03-30 12:10:25 +04:00
|
|
|
return -1;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
1999-01-11 03:48:23 +03:00
|
|
|
if (!S_ISLNK (ino->st.st_mode))
|
2011-04-21 11:46:20 +04:00
|
|
|
{
|
|
|
|
path_element->class->verrno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
2000-01-31 16:48:00 +03:00
|
|
|
|
|
|
|
if (ino->linkname == NULL)
|
2011-04-21 11:46:20 +04:00
|
|
|
{
|
|
|
|
path_element->class->verrno = EFAULT;
|
|
|
|
return -1;
|
|
|
|
}
|
2000-01-31 16:48:00 +03:00
|
|
|
|
2004-11-29 21:44:49 +03:00
|
|
|
len = strlen (ino->linkname);
|
2004-09-02 18:12:21 +04:00
|
|
|
if (size < len)
|
2010-03-30 12:10:25 +04:00
|
|
|
len = size;
|
2004-09-02 18:12:21 +04:00
|
|
|
/* readlink() does not append a NUL character to buf */
|
|
|
|
memcpy (buf, ino->linkname, len);
|
|
|
|
return len;
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2009-01-13 21:00:25 +03:00
|
|
|
static ssize_t
|
2010-07-18 17:46:59 +04:00
|
|
|
vfs_s_read (void *fh, char *buffer, size_t count)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
|
|
|
int n;
|
2003-10-12 04:24:00 +04:00
|
|
|
struct vfs_class *me = FH_SUPER->me;
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
if (FH->linear == LS_LINEAR_PREOPEN)
|
|
|
|
{
|
|
|
|
if (!MEDATA->linear_start (me, FH, FH->pos))
|
|
|
|
return -1;
|
2006-01-25 17:04:27 +03:00
|
|
|
}
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
if (FH->linear == LS_LINEAR_CLOSED)
|
|
|
|
vfs_die ("linear_start() did not set linear_state!");
|
|
|
|
|
|
|
|
if (FH->linear == LS_LINEAR_OPEN)
|
|
|
|
return MEDATA->linear_read (me, FH, buffer, count);
|
2010-03-30 12:10:25 +04:00
|
|
|
|
|
|
|
if (FH->handle != -1)
|
|
|
|
{
|
|
|
|
n = read (FH->handle, buffer, count);
|
|
|
|
if (n < 0)
|
|
|
|
me->verrno = errno;
|
|
|
|
return n;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
1999-01-18 02:10:05 +03:00
|
|
|
vfs_die ("vfs_s_read: This should not happen\n");
|
1999-01-02 10:46:20 +03:00
|
|
|
return -1;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-04-23 23:14:11 +04:00
|
|
|
static ssize_t
|
2010-07-18 17:46:59 +04:00
|
|
|
vfs_s_write (void *fh, const char *buffer, size_t count)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
|
|
|
int n;
|
2003-10-12 04:24:00 +04:00
|
|
|
struct vfs_class *me = FH_SUPER->me;
|
2010-03-30 12:10:25 +04:00
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
if (FH->linear)
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_die ("no writing to linear files, please");
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
FH->changed = 1;
|
2010-03-30 12:10:25 +04:00
|
|
|
if (FH->handle != -1)
|
|
|
|
{
|
|
|
|
n = write (FH->handle, buffer, count);
|
|
|
|
if (n < 0)
|
|
|
|
me->verrno = errno;
|
|
|
|
return n;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
1999-01-18 02:10:05 +03:00
|
|
|
vfs_die ("vfs_s_write: This should not happen\n");
|
1999-01-02 10:46:20 +03:00
|
|
|
return 0;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2009-01-13 21:00:25 +03:00
|
|
|
static off_t
|
1999-01-18 02:10:05 +03:00
|
|
|
vfs_s_lseek (void *fh, off_t offset, int whence)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
|
|
|
off_t size = FH->ino->st.st_size;
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2006-01-25 17:04:27 +03:00
|
|
|
if (FH->linear == LS_LINEAR_OPEN)
|
|
|
|
vfs_die ("cannot lseek() after linear_read!");
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
if (FH->handle != -1)
|
|
|
|
{ /* If we have local file opened, we want to work with it */
|
2010-07-18 17:46:59 +04:00
|
|
|
off_t retval = lseek (FH->handle, offset, whence);
|
2010-03-30 12:10:25 +04:00
|
|
|
if (retval == -1)
|
|
|
|
FH->ino->super->me->verrno = errno;
|
|
|
|
return retval;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
switch (whence)
|
|
|
|
{
|
|
|
|
case SEEK_CUR:
|
|
|
|
offset += FH->pos;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
offset += size;
|
|
|
|
break;
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
if (offset < 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
FH->pos = 0;
|
1998-10-23 12:26:25 +04:00
|
|
|
else if (offset < size)
|
2010-03-30 12:10:25 +04:00
|
|
|
FH->pos = offset;
|
1998-10-23 12:26:25 +04:00
|
|
|
else
|
2010-03-30 12:10:25 +04:00
|
|
|
FH->pos = size;
|
1998-10-23 12:26:25 +04:00
|
|
|
return FH->pos;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static int
|
1999-01-18 02:10:05 +03:00
|
|
|
vfs_s_close (void *fh)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
1998-11-21 22:36:01 +03:00
|
|
|
int res = 0;
|
2003-10-12 04:24:00 +04:00
|
|
|
struct vfs_class *me = FH_SUPER->me;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
FH_SUPER->fd_usage--;
|
2003-11-13 11:03:03 +03:00
|
|
|
if (!FH_SUPER->fd_usage)
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_stamp_create (me, FH_SUPER);
|
2003-11-13 11:03:03 +03:00
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
if (FH->linear == LS_LINEAR_OPEN)
|
2010-03-30 12:10:25 +04:00
|
|
|
MEDATA->linear_close (me, fh);
|
1998-11-21 22:36:01 +03:00
|
|
|
if (MEDATA->fh_close)
|
2010-03-30 12:10:25 +04:00
|
|
|
res = MEDATA->fh_close (me, fh);
|
|
|
|
if (FH->changed && MEDATA->file_store)
|
|
|
|
{
|
|
|
|
char *s = vfs_s_fullpath (me, FH->ino);
|
|
|
|
if (!s)
|
|
|
|
res = -1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
res = MEDATA->file_store (me, fh, s, FH->ino->localname);
|
|
|
|
g_free (s);
|
|
|
|
}
|
|
|
|
vfs_s_invalidate (me, FH_SUPER);
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
2002-03-06 11:46:35 +03:00
|
|
|
if (FH->handle != -1)
|
2010-03-30 12:10:25 +04:00
|
|
|
close (FH->handle);
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
vfs_s_free_inode (me, FH->ino);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (fh);
|
1998-11-21 22:36:01 +03:00
|
|
|
return res;
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-11-05 09:08:16 +03:00
|
|
|
static void
|
|
|
|
vfs_s_print_stats (const char *fs_name, const char *action,
|
2010-03-30 12:10:25 +04:00
|
|
|
const char *file_name, off_t have, off_t need)
|
2003-11-05 09:08:16 +03:00
|
|
|
{
|
2004-09-19 20:07:17 +04:00
|
|
|
static const char *i18n_percent_transf_format = NULL;
|
|
|
|
static const char *i18n_transf_format = NULL;
|
2003-11-05 09:08:16 +03:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
if (i18n_percent_transf_format == NULL)
|
|
|
|
{
|
2010-12-02 21:50:57 +03:00
|
|
|
i18n_percent_transf_format = "%s: %s: %s %3d%% (%" PRIuMAX " %s";
|
|
|
|
i18n_transf_format = "%s: %s: %s %" PRIuMAX " %s";
|
2003-11-05 09:08:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (need)
|
2011-02-16 14:26:59 +03:00
|
|
|
vfs_print_message (i18n_percent_transf_format, fs_name, action,
|
2010-12-02 21:50:57 +03:00
|
|
|
file_name, (int) ((double) have * 100 / need), (uintmax_t) have,
|
|
|
|
_("bytes transferred"));
|
2003-11-05 09:08:16 +03:00
|
|
|
else
|
2011-02-16 14:26:59 +03:00
|
|
|
vfs_print_message (i18n_transf_format, fs_name, action, file_name, (uintmax_t) have,
|
2010-12-02 21:50:57 +03:00
|
|
|
_("bytes transferred"));
|
2003-11-05 09:08:16 +03:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
1998-10-23 12:26:25 +04:00
|
|
|
/* ------------------------------- mc support ---------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static void
|
2004-08-16 20:34:11 +04:00
|
|
|
vfs_s_fill_names (struct vfs_class *me, fill_names_f func)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2011-03-28 15:18:21 +04:00
|
|
|
GList *iter;
|
2010-03-30 12:10:25 +04:00
|
|
|
|
2011-03-28 15:18:21 +04:00
|
|
|
for (iter = MEDATA->supers; iter != NULL; iter = g_list_next (iter))
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
2011-03-28 15:18:21 +04:00
|
|
|
const struct vfs_s_super *super = (const struct vfs_s_super *) iter->data;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
name = g_strconcat (super->name, "#", me->prefix, "/",
|
|
|
|
/* super->current_dir->name, */ (char *) NULL);
|
|
|
|
func (name);
|
2010-03-30 12:10:25 +04:00
|
|
|
g_free (name);
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static int
|
2003-10-12 04:24:00 +04:00
|
|
|
vfs_s_ferrno (struct vfs_class *me)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
|
|
|
return me->verrno;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
2003-10-28 11:20:30 +03:00
|
|
|
* Get local copy of the given file. We reuse the existing file cache
|
|
|
|
* for remote filesystems. Archives use standard VFS facilities.
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static char *
|
2011-04-18 18:08:55 +04:00
|
|
|
vfs_s_getlocalcopy (const vfs_path_t * vpath)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2011-02-09 14:34:13 +03:00
|
|
|
vfs_file_handler_t *fh;
|
2010-03-05 21:37:09 +03:00
|
|
|
char *local = NULL;
|
2003-10-28 10:09:39 +03:00
|
|
|
|
2011-04-18 18:08:55 +04:00
|
|
|
fh = vfs_s_open (vpath, O_RDONLY, 0);
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
if (fh != NULL)
|
|
|
|
{
|
|
|
|
if ((fh->ino != NULL) && (fh->ino->localname != NULL))
|
|
|
|
local = g_strdup (fh->ino->localname);
|
2010-03-05 21:37:09 +03:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_s_close (fh);
|
2010-03-05 21:37:09 +03:00
|
|
|
}
|
|
|
|
|
2003-10-28 10:09:39 +03:00
|
|
|
return local;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/**
|
2003-10-28 10:09:39 +03:00
|
|
|
* Return the local copy. Since we are using our cache, we do nothing -
|
|
|
|
* the cache will be removed when the archive is closed.
|
|
|
|
*/
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2003-10-28 10:09:39 +03:00
|
|
|
static int
|
2011-04-18 18:08:55 +04:00
|
|
|
vfs_s_ungetlocalcopy (const vfs_path_t * vpath, const char *local, int has_changed)
|
2003-10-28 10:09:39 +03:00
|
|
|
{
|
2011-04-18 18:08:55 +04:00
|
|
|
(void) vpath;
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) local;
|
|
|
|
(void) has_changed;
|
2003-10-28 10:09:39 +03:00
|
|
|
return 0;
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-16 20:12:19 +04:00
|
|
|
static int
|
2011-04-21 14:27:56 +04:00
|
|
|
vfs_s_setctl (const vfs_path_t * vpath, int ctlop, void *arg)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
2011-04-21 14:27:56 +04:00
|
|
|
vfs_path_element_t *path_element;
|
|
|
|
|
|
|
|
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
|
2010-03-30 12:10:25 +04:00
|
|
|
switch (ctlop)
|
|
|
|
{
|
2003-10-16 20:12:19 +04:00
|
|
|
case VFS_SETCTL_STALE_DATA:
|
2010-03-30 12:10:25 +04:00
|
|
|
{
|
2011-04-21 14:27:56 +04:00
|
|
|
struct vfs_s_inode *ino =
|
|
|
|
vfs_s_inode_from_path (path_element->class, vpath->unparsed, 0);
|
2010-03-30 12:10:25 +04:00
|
|
|
|
2010-03-30 22:59:41 +04:00
|
|
|
if (ino == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
return 0;
|
|
|
|
if (arg)
|
|
|
|
ino->super->want_stale = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ino->super->want_stale = 0;
|
2011-04-21 14:27:56 +04:00
|
|
|
vfs_s_invalidate (path_element->class, ino->super);
|
2010-03-30 12:10:25 +04:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2003-10-16 21:08:38 +04:00
|
|
|
case VFS_SETCTL_LOGFILE:
|
2011-04-21 14:27:56 +04:00
|
|
|
((struct vfs_s_subclass *) path_element->class->data)->logfile = fopen ((char *) arg, "w");
|
2010-03-30 12:10:25 +04:00
|
|
|
return 1;
|
2003-10-16 22:51:41 +04:00
|
|
|
case VFS_SETCTL_FLUSH:
|
2011-04-21 14:27:56 +04:00
|
|
|
((struct vfs_s_subclass *) path_element->class->data)->flush = 1;
|
2010-03-30 12:10:25 +04:00
|
|
|
return 1;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
1998-11-21 22:36:01 +03:00
|
|
|
/* ----------------------------- Stamping support -------------------------- */
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static vfsid
|
2011-04-21 14:27:56 +04:00
|
|
|
vfs_s_getid (const vfs_path_t * vpath)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2010-03-30 22:59:41 +04:00
|
|
|
struct vfs_s_super *archive = NULL;
|
1998-10-23 12:26:25 +04:00
|
|
|
char *p;
|
2011-04-21 14:27:56 +04:00
|
|
|
vfs_path_element_t *path_element;
|
1998-10-23 12:26:25 +04:00
|
|
|
|
2011-04-21 14:27:56 +04:00
|
|
|
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
|
|
|
|
|
|
|
|
p = vfs_s_get_path (path_element->class, vpath->unparsed, &archive, FL_NO_OPEN);
|
2010-03-30 22:59:41 +04:00
|
|
|
if (p == NULL)
|
2010-03-30 12:10:25 +04:00
|
|
|
return NULL;
|
|
|
|
g_free (p);
|
|
|
|
return (vfsid) archive;
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static int
|
1999-01-18 02:10:05 +03:00
|
|
|
vfs_s_nothingisopen (vfsid id)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) id;
|
|
|
|
/* Our data structures should survive free of superblock at any time */
|
1999-11-03 17:51:22 +03:00
|
|
|
return 1;
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2003-10-11 14:13:36 +04:00
|
|
|
static void
|
1999-01-18 02:10:05 +03:00
|
|
|
vfs_s_free (vfsid id)
|
1998-10-23 12:26:25 +04:00
|
|
|
{
|
2010-03-30 12:10:25 +04:00
|
|
|
vfs_s_free_super (((struct vfs_s_super *) id)->me, (struct vfs_s_super *) id);
|
1998-10-23 12:26:25 +04:00
|
|
|
}
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
2006-02-23 13:46:29 +03:00
|
|
|
static int
|
|
|
|
vfs_s_dir_uptodate (struct vfs_class *me, struct vfs_s_inode *ino)
|
|
|
|
{
|
|
|
|
struct timeval tim;
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
if (MEDATA->flush)
|
|
|
|
{
|
|
|
|
MEDATA->flush = 0;
|
|
|
|
return 0;
|
2006-02-23 13:46:29 +03:00
|
|
|
}
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
gettimeofday (&tim, NULL);
|
2006-02-23 13:46:29 +03:00
|
|
|
if (tim.tv_sec < ino->timestamp.tv_sec)
|
2010-03-30 12:10:25 +04:00
|
|
|
return 1;
|
2006-02-23 13:46:29 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-10-11 03:13:09 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/*** public functions ****************************************************************************/
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
struct vfs_s_inode *
|
|
|
|
vfs_s_new_inode (struct vfs_class *me, struct vfs_s_super *super, struct stat *initstat)
|
2010-07-22 15:55:23 +04:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
struct vfs_s_inode *ino;
|
2010-07-22 15:55:23 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
ino = g_try_new0 (struct vfs_s_inode, 1);
|
|
|
|
if (ino == NULL)
|
|
|
|
return NULL;
|
2010-07-22 15:55:23 +04:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
if (initstat)
|
|
|
|
ino->st = *initstat;
|
|
|
|
ino->super = super;
|
|
|
|
ino->st.st_nlink = 0;
|
|
|
|
ino->st.st_ino = MEDATA->inode_counter++;
|
|
|
|
ino->st.st_dev = MEDATA->rdev;
|
|
|
|
|
|
|
|
super->ino_usage++;
|
|
|
|
total_inodes++;
|
|
|
|
|
|
|
|
CALL (init_inode) (me, ino);
|
|
|
|
|
|
|
|
return ino;
|
2010-07-22 15:55:23 +04:00
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
struct vfs_s_entry *
|
|
|
|
vfs_s_new_entry (struct vfs_class *me, const char *name, struct vfs_s_inode *inode)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
2010-11-08 13:21:45 +03:00
|
|
|
struct vfs_s_entry *entry;
|
|
|
|
|
|
|
|
entry = g_new0 (struct vfs_s_entry, 1);
|
|
|
|
total_entries++;
|
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
entry->name = g_strdup (name);
|
2010-11-08 13:21:45 +03:00
|
|
|
entry->ino = inode;
|
|
|
|
entry->ino->ent = entry;
|
|
|
|
CALL (init_entry) (me, entry);
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
vfs_s_free_entry (struct vfs_class *me, struct vfs_s_entry *ent)
|
|
|
|
{
|
2011-03-28 16:17:45 +04:00
|
|
|
if (ent->dir != NULL)
|
|
|
|
ent->dir->subdir = g_list_remove (ent->dir->subdir, ent);
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
g_free (ent->name);
|
2011-03-28 16:17:45 +04:00
|
|
|
/* ent->name = NULL; */
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2011-03-28 16:17:45 +04:00
|
|
|
if (ent->ino != NULL)
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
|
|
|
ent->ino->ent = NULL;
|
|
|
|
vfs_s_free_inode (me, ent->ino);
|
|
|
|
}
|
|
|
|
|
|
|
|
total_entries--;
|
|
|
|
g_free (ent);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
vfs_s_insert_entry (struct vfs_class *me, struct vfs_s_inode *dir, struct vfs_s_entry *ent)
|
|
|
|
{
|
|
|
|
(void) me;
|
|
|
|
|
|
|
|
ent->dir = dir;
|
|
|
|
|
|
|
|
ent->ino->st.st_nlink++;
|
2011-03-28 16:17:45 +04:00
|
|
|
dir->subdir = g_list_append (dir->subdir, ent);
|
2010-11-08 13:21:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
struct stat *
|
|
|
|
vfs_s_default_stat (struct vfs_class *me, mode_t mode)
|
|
|
|
{
|
|
|
|
static struct stat st;
|
|
|
|
int myumask;
|
|
|
|
|
|
|
|
(void) me;
|
|
|
|
|
|
|
|
myumask = umask (022);
|
|
|
|
umask (myumask);
|
|
|
|
mode &= ~myumask;
|
|
|
|
|
|
|
|
st.st_mode = mode;
|
|
|
|
st.st_ino = 0;
|
|
|
|
st.st_dev = 0;
|
|
|
|
st.st_rdev = 0;
|
|
|
|
st.st_uid = getuid ();
|
|
|
|
st.st_gid = getgid ();
|
|
|
|
st.st_size = 0;
|
|
|
|
st.st_mtime = st.st_atime = st.st_ctime = time (NULL);
|
|
|
|
|
|
|
|
return &st;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
struct vfs_s_entry *
|
|
|
|
vfs_s_generate_entry (struct vfs_class *me, const char *name, struct vfs_s_inode *parent,
|
|
|
|
mode_t mode)
|
|
|
|
{
|
|
|
|
struct vfs_s_inode *inode;
|
|
|
|
struct stat *st;
|
|
|
|
|
|
|
|
st = vfs_s_default_stat (me, mode);
|
|
|
|
inode = vfs_s_new_inode (me, parent->super, st);
|
|
|
|
|
|
|
|
return vfs_s_new_entry (me, name, inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
struct vfs_s_inode *
|
|
|
|
vfs_s_find_inode (struct vfs_class *me, const struct vfs_s_super *super,
|
|
|
|
const char *path, int follow, int flags)
|
|
|
|
{
|
|
|
|
struct vfs_s_entry *ent;
|
|
|
|
|
|
|
|
if (((MEDATA->flags & VFS_S_REMOTE) == 0) && (*path == '\0'))
|
|
|
|
return super->root;
|
|
|
|
|
|
|
|
ent = (MEDATA->find_entry) (me, super->root, path, follow, flags);
|
|
|
|
return (ent != NULL) ? ent->ino : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/* Ook, these were functions around directory entries / inodes */
|
|
|
|
/* -------------------------------- superblock games -------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dissect the path and create corresponding superblock. Note that inname
|
|
|
|
* can be changed and the result may point inside the original string.
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
vfs_s_get_path_mangle (struct vfs_class *me, char *inname, struct vfs_s_super **archive, int flags)
|
|
|
|
{
|
2011-03-28 15:18:21 +04:00
|
|
|
GList *iter;
|
2010-11-08 13:21:45 +03:00
|
|
|
const char *retval;
|
|
|
|
char *local, *op;
|
|
|
|
const char *archive_name;
|
|
|
|
int result = -1;
|
|
|
|
struct vfs_s_super *super;
|
|
|
|
void *cookie = NULL;
|
|
|
|
|
|
|
|
archive_name = inname;
|
|
|
|
vfs_split (inname, &local, &op);
|
|
|
|
retval = (local != NULL) ? local : "";
|
|
|
|
|
|
|
|
if (MEDATA->archive_check != NULL)
|
|
|
|
{
|
|
|
|
cookie = MEDATA->archive_check (me, archive_name, op);
|
|
|
|
if (cookie == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-03-28 15:18:21 +04:00
|
|
|
for (iter = MEDATA->supers; iter != NULL; iter = g_list_next (iter))
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
2011-03-28 15:18:21 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
super = (struct vfs_s_super *) iter->data;
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* 0 == other, 1 == same, return it, 2 == other but stop scanning */
|
2011-03-28 15:18:21 +04:00
|
|
|
i = MEDATA->archive_same (me, super, archive_name, op, cookie);
|
2010-11-08 13:21:45 +03:00
|
|
|
if (i != 0)
|
|
|
|
{
|
|
|
|
if (i == 1)
|
|
|
|
goto return_success;
|
2011-03-28 15:18:21 +04:00
|
|
|
break;
|
2010-11-08 13:21:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & FL_NO_OPEN)
|
|
|
|
ERRNOR (EIO, NULL);
|
|
|
|
|
|
|
|
super = vfs_s_new_super (me);
|
2011-04-12 12:40:28 +04:00
|
|
|
if (MEDATA->open_archive != NULL)
|
|
|
|
result = MEDATA->open_archive (me, super, archive_name, op);
|
2010-11-08 13:21:45 +03:00
|
|
|
if (result == -1)
|
|
|
|
{
|
|
|
|
vfs_s_free_super (me, super);
|
|
|
|
ERRNOR (EIO, NULL);
|
|
|
|
}
|
|
|
|
if (!super->name)
|
|
|
|
vfs_die ("You have to fill name\n");
|
|
|
|
if (!super->root)
|
|
|
|
vfs_die ("You have to fill root inode\n");
|
|
|
|
|
|
|
|
vfs_s_insert_super (me, super);
|
|
|
|
vfs_stamp_create (me, super);
|
|
|
|
|
|
|
|
return_success:
|
|
|
|
*archive = super;
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
void
|
|
|
|
vfs_s_invalidate (struct vfs_class *me, struct vfs_s_super *super)
|
|
|
|
{
|
|
|
|
if (!super->want_stale)
|
|
|
|
{
|
|
|
|
vfs_s_free_inode (me, super->root);
|
|
|
|
super->root = vfs_s_new_inode (me, super, vfs_s_default_stat (me, S_IFDIR | 0755));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
char *
|
|
|
|
vfs_s_fullpath (struct vfs_class *me, struct vfs_s_inode *ino)
|
|
|
|
{
|
|
|
|
if (!ino->ent)
|
|
|
|
ERRNOR (EAGAIN, NULL);
|
|
|
|
|
|
|
|
if (!(MEDATA->flags & VFS_S_REMOTE))
|
|
|
|
{
|
|
|
|
/* archives */
|
|
|
|
char *newpath;
|
|
|
|
char *path = g_strdup (ino->ent->name);
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
ino = ino->ent->dir;
|
|
|
|
if (ino == ino->super->root)
|
|
|
|
break;
|
|
|
|
newpath = g_strconcat (ino->ent->name, "/", path, (char *) NULL);
|
|
|
|
g_free (path);
|
|
|
|
path = newpath;
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remote systems */
|
|
|
|
if ((!ino->ent->dir) || (!ino->ent->dir->ent))
|
|
|
|
return g_strdup (ino->ent->name);
|
|
|
|
|
|
|
|
return g_strconcat (ino->ent->dir->ent->name, PATH_SEP_STR, ino->ent->name, (char *) NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/* --------------------------- stat and friends ---------------------------- */
|
|
|
|
|
|
|
|
void *
|
2011-04-18 18:08:55 +04:00
|
|
|
vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode)
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
|
|
|
int was_changed = 0;
|
2011-02-09 14:34:13 +03:00
|
|
|
vfs_file_handler_t *fh;
|
2010-11-08 13:21:45 +03:00
|
|
|
struct vfs_s_super *super;
|
|
|
|
char *q;
|
|
|
|
struct vfs_s_inode *ino;
|
2011-04-18 18:08:55 +04:00
|
|
|
vfs_path_element_t *path_element;
|
|
|
|
|
|
|
|
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2011-04-18 18:08:55 +04:00
|
|
|
q = vfs_s_get_path (path_element->class, vpath->unparsed, &super, 0);
|
2010-11-08 13:21:45 +03:00
|
|
|
if (q == NULL)
|
|
|
|
return NULL;
|
2011-04-18 18:08:55 +04:00
|
|
|
ino = vfs_s_find_inode (path_element->class, super, q, LINK_FOLLOW, FL_NONE);
|
2010-11-08 13:21:45 +03:00
|
|
|
if (ino && ((flags & (O_CREAT | O_EXCL)) == (O_CREAT | O_EXCL)))
|
|
|
|
{
|
|
|
|
g_free (q);
|
2011-04-18 18:08:55 +04:00
|
|
|
path_element->class->verrno = EEXIST;
|
|
|
|
return NULL;
|
2010-11-08 13:21:45 +03:00
|
|
|
}
|
|
|
|
if (!ino)
|
|
|
|
{
|
|
|
|
char *dirname, *name, *save;
|
|
|
|
struct vfs_s_entry *ent;
|
|
|
|
struct vfs_s_inode *dir;
|
|
|
|
int tmp_handle;
|
|
|
|
|
|
|
|
/* If the filesystem is read-only, disable file creation */
|
2011-04-18 18:08:55 +04:00
|
|
|
if (!(flags & O_CREAT) || !(path_element->class->write))
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
|
|
|
g_free (q);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-04-18 18:08:55 +04:00
|
|
|
split_dir_name (path_element->class, q, &dirname, &name, &save);
|
|
|
|
dir = vfs_s_find_inode (path_element->class, super, dirname, LINK_FOLLOW, FL_DIR);
|
2010-12-09 11:40:12 +03:00
|
|
|
if (dir == NULL)
|
|
|
|
{
|
|
|
|
g_free (q);
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
if (save)
|
|
|
|
*save = PATH_SEP;
|
2011-04-18 18:08:55 +04:00
|
|
|
ent = vfs_s_generate_entry (path_element->class, name, dir, 0755);
|
2010-11-08 13:21:45 +03:00
|
|
|
ino = ent->ino;
|
2011-04-18 18:08:55 +04:00
|
|
|
vfs_s_insert_entry (path_element->class, dir, ent);
|
|
|
|
tmp_handle = vfs_mkstemps (&ino->localname, path_element->class->name, name);
|
2010-11-08 13:21:45 +03:00
|
|
|
if (tmp_handle == -1)
|
|
|
|
{
|
|
|
|
g_free (q);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
close (tmp_handle);
|
|
|
|
was_changed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (q);
|
|
|
|
|
|
|
|
if (S_ISDIR (ino->st.st_mode))
|
2011-04-18 18:08:55 +04:00
|
|
|
{
|
|
|
|
path_element->class->verrno = EISDIR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2011-02-09 14:34:13 +03:00
|
|
|
fh = g_new (vfs_file_handler_t, 1);
|
2010-11-08 13:21:45 +03:00
|
|
|
fh->pos = 0;
|
|
|
|
fh->ino = ino;
|
|
|
|
fh->handle = -1;
|
|
|
|
fh->changed = was_changed;
|
|
|
|
fh->linear = 0;
|
2011-04-12 12:31:50 +04:00
|
|
|
fh->data = NULL;
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
if (IS_LINEAR (flags))
|
|
|
|
{
|
2011-04-18 18:08:55 +04:00
|
|
|
if (VFSDATA (path_element)->linear_start)
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
2011-02-16 14:26:59 +03:00
|
|
|
vfs_print_message (_("Starting linear transfer..."));
|
2010-11-08 13:21:45 +03:00
|
|
|
fh->linear = LS_LINEAR_PREOPEN;
|
|
|
|
}
|
|
|
|
}
|
2011-04-18 18:08:55 +04:00
|
|
|
else if ((VFSDATA (path_element)->fh_open != NULL)
|
|
|
|
&& (VFSDATA (path_element)->fh_open (path_element->class, fh, flags, mode) != 0))
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
|
|
|
g_free (fh);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fh->ino->localname)
|
|
|
|
{
|
|
|
|
fh->handle = open (fh->ino->localname, NO_LINEAR (flags), mode);
|
|
|
|
if (fh->handle == -1)
|
|
|
|
{
|
|
|
|
g_free (fh);
|
2011-04-18 18:08:55 +04:00
|
|
|
path_element->class->verrno = errno;
|
|
|
|
return NULL;
|
2010-11-08 13:21:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* i.e. we had no open files and now we have one */
|
2011-04-18 18:08:55 +04:00
|
|
|
vfs_rmstamp (path_element->class, (vfsid) super);
|
2010-11-08 13:21:45 +03:00
|
|
|
super->fd_usage++;
|
|
|
|
fh->ino->st.st_nlink++;
|
|
|
|
return fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
int
|
|
|
|
vfs_s_retrieve_file (struct vfs_class *me, struct vfs_s_inode *ino)
|
|
|
|
{
|
|
|
|
/* If you want reget, you'll have to open file with O_LINEAR */
|
|
|
|
off_t total = 0;
|
|
|
|
char buffer[8192];
|
|
|
|
int handle, n;
|
|
|
|
off_t stat_size = ino->st.st_size;
|
2011-02-09 14:34:13 +03:00
|
|
|
vfs_file_handler_t fh;
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
memset (&fh, 0, sizeof (fh));
|
|
|
|
|
|
|
|
fh.ino = ino;
|
|
|
|
fh.handle = -1;
|
|
|
|
|
|
|
|
handle = vfs_mkstemps (&ino->localname, me->name, ino->ent->name);
|
|
|
|
if (handle == -1)
|
|
|
|
{
|
|
|
|
me->verrno = errno;
|
|
|
|
goto error_4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!MEDATA->linear_start (me, &fh, 0))
|
|
|
|
goto error_3;
|
|
|
|
|
|
|
|
/* Clear the interrupt status */
|
|
|
|
tty_got_interrupt ();
|
|
|
|
tty_enable_interrupt_key ();
|
|
|
|
|
|
|
|
while ((n = MEDATA->linear_read (me, &fh, buffer, sizeof (buffer))))
|
|
|
|
{
|
|
|
|
int t;
|
|
|
|
if (n < 0)
|
|
|
|
goto error_1;
|
|
|
|
|
|
|
|
total += n;
|
|
|
|
vfs_s_print_stats (me->name, _("Getting file"), ino->ent->name, total, stat_size);
|
|
|
|
|
|
|
|
if (tty_got_interrupt ())
|
|
|
|
goto error_1;
|
|
|
|
|
|
|
|
t = write (handle, buffer, n);
|
|
|
|
if (t != n)
|
|
|
|
{
|
|
|
|
if (t == -1)
|
|
|
|
me->verrno = errno;
|
|
|
|
goto error_1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
MEDATA->linear_close (me, &fh);
|
|
|
|
close (handle);
|
|
|
|
|
|
|
|
tty_disable_interrupt_key ();
|
2011-03-28 18:08:56 +04:00
|
|
|
g_free (fh.data);
|
2010-11-08 13:21:45 +03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
error_1:
|
|
|
|
MEDATA->linear_close (me, &fh);
|
|
|
|
error_3:
|
|
|
|
tty_disable_interrupt_key ();
|
|
|
|
close (handle);
|
|
|
|
unlink (ino->localname);
|
|
|
|
error_4:
|
|
|
|
g_free (ino->localname);
|
|
|
|
ino->localname = NULL;
|
2011-03-28 18:08:56 +04:00
|
|
|
g_free (fh.data);
|
2010-11-08 13:21:45 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/* ----------------------------- Stamping support -------------------------- */
|
|
|
|
|
|
|
|
/* Initialize one of our subclasses - fill common functions */
|
|
|
|
void
|
|
|
|
vfs_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub)
|
|
|
|
{
|
|
|
|
vclass->data = sub;
|
|
|
|
vclass->fill_names = vfs_s_fill_names;
|
|
|
|
vclass->open = vfs_s_open;
|
|
|
|
vclass->close = vfs_s_close;
|
|
|
|
vclass->read = vfs_s_read;
|
|
|
|
if (!(sub->flags & VFS_S_READONLY))
|
|
|
|
{
|
|
|
|
vclass->write = vfs_s_write;
|
|
|
|
}
|
|
|
|
vclass->opendir = vfs_s_opendir;
|
|
|
|
vclass->readdir = vfs_s_readdir;
|
|
|
|
vclass->closedir = vfs_s_closedir;
|
|
|
|
vclass->stat = vfs_s_stat;
|
|
|
|
vclass->lstat = vfs_s_lstat;
|
|
|
|
vclass->fstat = vfs_s_fstat;
|
|
|
|
vclass->readlink = vfs_s_readlink;
|
|
|
|
vclass->chdir = vfs_s_chdir;
|
|
|
|
vclass->ferrno = vfs_s_ferrno;
|
|
|
|
vclass->lseek = vfs_s_lseek;
|
|
|
|
vclass->getid = vfs_s_getid;
|
|
|
|
vclass->nothingisopen = vfs_s_nothingisopen;
|
|
|
|
vclass->free = vfs_s_free;
|
|
|
|
if (sub->flags & VFS_S_REMOTE)
|
|
|
|
{
|
|
|
|
vclass->getlocalcopy = vfs_s_getlocalcopy;
|
|
|
|
vclass->ungetlocalcopy = vfs_s_ungetlocalcopy;
|
|
|
|
sub->find_entry = vfs_s_find_entry_linear;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sub->find_entry = vfs_s_find_entry_tree;
|
|
|
|
}
|
|
|
|
vclass->setctl = vfs_s_setctl;
|
|
|
|
sub->dir_uptodate = vfs_s_dir_uptodate;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/** Find VFS id for given directory name */
|
|
|
|
|
|
|
|
vfsid
|
2011-04-21 14:27:56 +04:00
|
|
|
vfs_getid (const vfs_path_t * vpath)
|
2010-11-08 13:21:45 +03:00
|
|
|
{
|
2011-04-21 14:27:56 +04:00
|
|
|
vfs_path_element_t *path_element;
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2011-04-21 14:27:56 +04:00
|
|
|
path_element = vfs_path_get_by_index (vpath, vfs_path_length (vpath) - 1);
|
|
|
|
if (path_element == NULL || path_element->class->getid == NULL)
|
|
|
|
return NULL;
|
2010-11-08 13:21:45 +03:00
|
|
|
|
2011-04-21 14:27:56 +04:00
|
|
|
return (*path_element->class->getid) (vpath);
|
2010-11-08 13:21:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
/* ----------- Utility functions for networked filesystems -------------- */
|
|
|
|
|
|
|
|
#ifdef ENABLE_VFS_NET
|
|
|
|
int
|
|
|
|
vfs_s_select_on_two (int fd1, int fd2)
|
|
|
|
{
|
|
|
|
fd_set set;
|
|
|
|
struct timeval time_out;
|
|
|
|
int v;
|
|
|
|
int maxfd = (fd1 > fd2 ? fd1 : fd2) + 1;
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
time_out.tv_sec = 1;
|
2010-02-02 13:48:08 +03:00
|
|
|
time_out.tv_usec = 0;
|
1999-01-18 02:10:05 +03:00
|
|
|
FD_ZERO (&set);
|
|
|
|
FD_SET (fd1, &set);
|
|
|
|
FD_SET (fd2, &set);
|
2010-02-02 13:48:08 +03:00
|
|
|
v = select (maxfd, &set, 0, 0, &time_out);
|
1998-11-21 22:36:01 +03:00
|
|
|
if (v <= 0)
|
2010-03-30 12:10:25 +04:00
|
|
|
return v;
|
1998-11-21 22:36:01 +03:00
|
|
|
if (FD_ISSET (fd1, &set))
|
2010-03-30 12:10:25 +04:00
|
|
|
return 1;
|
1998-11-21 22:36:01 +03:00
|
|
|
if (FD_ISSET (fd2, &set))
|
2010-03-30 12:10:25 +04:00
|
|
|
return 2;
|
1998-11-21 22:36:01 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
int
|
2003-10-12 04:24:00 +04:00
|
|
|
vfs_s_get_line (struct vfs_class *me, int sock, char *buf, int buf_len, char term)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
|
|
|
FILE *logfile = MEDATA->logfile;
|
2005-08-16 01:25:02 +04:00
|
|
|
int i;
|
1998-11-21 22:36:01 +03:00
|
|
|
char c;
|
|
|
|
|
2010-03-30 12:10:25 +04:00
|
|
|
for (i = 0; i < buf_len - 1; i++, buf++)
|
|
|
|
{
|
|
|
|
if (read (sock, buf, sizeof (char)) <= 0)
|
|
|
|
return 0;
|
|
|
|
if (logfile)
|
|
|
|
{
|
2009-12-29 01:53:09 +03:00
|
|
|
size_t ret1;
|
|
|
|
int ret2;
|
|
|
|
ret1 = fwrite (buf, 1, 1, logfile);
|
|
|
|
ret2 = fflush (logfile);
|
2010-03-30 12:10:25 +04:00
|
|
|
}
|
|
|
|
if (*buf == term)
|
|
|
|
{
|
|
|
|
*buf = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
2002-08-20 05:08:34 +04:00
|
|
|
|
|
|
|
/* Line is too long - terminate buffer and discard the rest of line */
|
1998-11-21 22:36:01 +03:00
|
|
|
*buf = 0;
|
2010-03-30 12:10:25 +04:00
|
|
|
while (read (sock, &c, sizeof (c)) > 0)
|
|
|
|
{
|
|
|
|
if (logfile)
|
|
|
|
{
|
2009-12-29 01:53:09 +03:00
|
|
|
size_t ret1;
|
|
|
|
int ret2;
|
|
|
|
ret1 = fwrite (&c, 1, 1, logfile);
|
|
|
|
ret2 = fflush (logfile);
|
2010-03-30 12:10:25 +04:00
|
|
|
}
|
|
|
|
if (c == '\n')
|
|
|
|
return 1;
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-08 13:21:45 +03:00
|
|
|
/* --------------------------------------------------------------------------------------------- */
|
|
|
|
|
1998-11-21 22:36:01 +03:00
|
|
|
int
|
2003-10-12 04:24:00 +04:00
|
|
|
vfs_s_get_line_interruptible (struct vfs_class *me, char *buffer, int size, int fd)
|
1998-11-21 22:36:01 +03:00
|
|
|
{
|
|
|
|
int n;
|
2000-01-31 16:48:00 +03:00
|
|
|
int i;
|
1998-11-21 22:36:01 +03:00
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2009-05-19 17:42:37 +04:00
|
|
|
tty_enable_interrupt_key ();
|
2010-03-30 12:10:25 +04:00
|
|
|
for (i = 0; i < size - 1; i++)
|
|
|
|
{
|
|
|
|
n = read (fd, buffer + i, 1);
|
|
|
|
tty_disable_interrupt_key ();
|
|
|
|
if (n == -1 && errno == EINTR)
|
|
|
|
{
|
|
|
|
buffer[i] = 0;
|
|
|
|
return EINTR;
|
|
|
|
}
|
|
|
|
if (n == 0)
|
|
|
|
{
|
|
|
|
buffer[i] = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (buffer[i] == '\n')
|
|
|
|
{
|
|
|
|
buffer[i] = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
1998-11-21 22:36:01 +03:00
|
|
|
}
|
2010-03-30 12:10:25 +04:00
|
|
|
buffer[size - 1] = 0;
|
1998-11-21 22:36:01 +03:00
|
|
|
return 0;
|
|
|
|
}
|
2010-07-18 12:42:28 +04:00
|
|
|
#endif /* ENABLE_VFS_NET */
|
2010-11-08 13:21:45 +03:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------------------------------- */
|