2009-02-07 15:54:58 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* \brief Source: local FS
|
|
|
|
*/
|
|
|
|
|
2001-06-26 01:34:46 +04:00
|
|
|
#include <config.h>
|
1998-02-27 07:54:42 +03:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2009-02-06 02:30:45 +03:00
|
|
|
#include <fcntl.h>
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2005-02-19 19:36:38 +03:00
|
|
|
#include "../src/global.h"
|
2009-05-08 14:01:05 +04:00
|
|
|
|
2005-02-19 19:36:38 +03:00
|
|
|
#include "../src/wtools.h" /* message() */
|
|
|
|
#include "../src/main.h" /* print_vfs_message */
|
2009-05-08 14:01:05 +04:00
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
#include "utilvfs.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
#include "vfs.h"
|
1998-12-15 22:53:55 +03:00
|
|
|
#include "local.h"
|
1998-02-27 07:54:42 +03:00
|
|
|
|
2009-02-07 15:54:58 +03:00
|
|
|
/**
|
|
|
|
* Note: Some of this functions are not static. This has rather good
|
1998-08-25 20:00:16 +04:00
|
|
|
* reason: exactly same functions would have to appear in sfs.c. This
|
|
|
|
* saves both computer's memory and my work. <pavel@ucw.cz>
|
2009-02-07 15:54:58 +03:00
|
|
|
*/
|
|
|
|
|
2003-10-12 23:57:27 +04:00
|
|
|
static struct vfs_class vfs_local_ops;
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static void *
|
2003-10-28 05:10:33 +03:00
|
|
|
local_open (struct vfs_class *me, const char *file, int flags, int mode)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int *local_info;
|
|
|
|
int fd;
|
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2003-10-28 05:10:33 +03:00
|
|
|
fd = open (file, NO_LINEAR (flags), mode);
|
1998-02-27 07:54:42 +03:00
|
|
|
if (fd == -1)
|
|
|
|
return 0;
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
local_info = g_new (int, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
*local_info = fd;
|
2003-10-28 05:10:33 +03:00
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return local_info;
|
|
|
|
}
|
|
|
|
|
2009-01-13 21:00:25 +03:00
|
|
|
ssize_t
|
1998-12-15 22:53:55 +03:00
|
|
|
local_read (void *data, char *buffer, int count)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
while ((n = read (*((int *) data), buffer, count)) == -1){
|
|
|
|
#ifdef EAGAIN
|
|
|
|
if (errno == EAGAIN) continue;
|
|
|
|
#endif
|
|
|
|
#ifdef EINTR
|
|
|
|
if (errno == EINTR) continue;
|
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
int
|
|
|
|
local_close (void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fd = *(int *) data;
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (data);
|
1998-02-27 07:54:42 +03:00
|
|
|
return close (fd);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
int
|
2003-10-12 04:24:00 +04:00
|
|
|
local_errno (struct vfs_class *me)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
1998-02-27 07:54:42 +03:00
|
|
|
return errno;
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static void *
|
2003-11-13 11:29:37 +03:00
|
|
|
local_opendir (struct vfs_class *me, const char *dirname)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
DIR **local_info;
|
|
|
|
DIR *dir;
|
|
|
|
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
dir = opendir (dirname);
|
|
|
|
if (!dir)
|
|
|
|
return 0;
|
|
|
|
|
1999-01-21 01:01:11 +03:00
|
|
|
local_info = (DIR **) g_new (DIR *, 1);
|
1998-02-27 07:54:42 +03:00
|
|
|
*local_info = dir;
|
|
|
|
|
|
|
|
return local_info;
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static void *
|
|
|
|
local_readdir (void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
return readdir (*(DIR **) data);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
|
|
|
local_closedir (void *data)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = closedir (* (DIR **) data);
|
2009-02-06 01:27:37 +03:00
|
|
|
g_free (data);
|
1998-02-27 07:54:42 +03:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 00:26:42 +04:00
|
|
|
local_stat (struct vfs_class *me, const char *path, struct stat *buf)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return stat (path, buf);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 00:26:42 +04:00
|
|
|
local_lstat (struct vfs_class *me, const char *path, struct stat *buf)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
#ifndef HAVE_STATLSTAT
|
|
|
|
return lstat (path,buf);
|
|
|
|
#else
|
|
|
|
return statlstat (path, buf);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
int
|
|
|
|
local_fstat (void *data, struct stat *buf)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
/* FIXME: avoid type cast */
|
|
|
|
return fstat (*((int *) data), buf);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 01:36:39 +04:00
|
|
|
local_chmod (struct vfs_class *me, const char *path, int mode)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return chmod (path, mode);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 01:36:39 +04:00
|
|
|
local_chown (struct vfs_class *me, const char *path, int owner, int group)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return chown (path, owner, group);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 01:36:39 +04:00
|
|
|
local_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return utime (path, times);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-09-02 18:12:21 +04:00
|
|
|
local_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return readlink (path, buf, size);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
local_unlink (struct vfs_class *me, const char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return unlink (path);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
local_symlink (struct vfs_class *me, const char *n1, const char *n2)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return symlink (n1, n2);
|
|
|
|
}
|
|
|
|
|
2009-01-13 21:00:25 +03:00
|
|
|
static ssize_t
|
2004-08-17 01:16:54 +04:00
|
|
|
local_write (void *data, const char *buf, int nbyte)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
if (!data)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
fd = * (int *) data;
|
|
|
|
while ((n = write (fd, buf, nbyte)) == -1){
|
|
|
|
#ifdef EAGAIN
|
|
|
|
if (errno == EAGAIN) continue;
|
|
|
|
#endif
|
|
|
|
#ifdef EINTR
|
|
|
|
if (errno == EINTR) continue;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
local_rename (struct vfs_class *me, const char *a, const char *b)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return rename (a, b);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2003-11-13 11:29:37 +03:00
|
|
|
local_chdir (struct vfs_class *me, const char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return chdir (path);
|
|
|
|
}
|
|
|
|
|
2009-01-13 21:00:25 +03:00
|
|
|
off_t
|
1998-12-15 22:53:55 +03:00
|
|
|
local_lseek (void *data, off_t offset, int whence)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
|
|
|
int fd = * (int *) data;
|
|
|
|
|
|
|
|
return lseek (fd, offset, whence);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
local_mknod (struct vfs_class *me, const char *path, int mode, int dev)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return mknod (path, mode, dev);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
local_link (struct vfs_class *me, const char *p1, const char *p2)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return link (p1, p2);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
local_mkdir (struct vfs_class *me, const char *path, mode_t mode)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return mkdir (path, mode);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-17 02:15:28 +04:00
|
|
|
local_rmdir (struct vfs_class *me, const char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
1998-02-27 07:54:42 +03:00
|
|
|
return rmdir (path);
|
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static char *
|
2003-10-28 05:10:33 +03:00
|
|
|
local_getlocalcopy (struct vfs_class *me, const char *path)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
|
2009-02-06 01:40:32 +03:00
|
|
|
return g_strdup (path);
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1999-11-11 17:23:40 +03:00
|
|
|
static int
|
2003-10-29 00:52:06 +03:00
|
|
|
local_ungetlocalcopy (struct vfs_class *me, const char *path,
|
|
|
|
const char *local, int has_changed)
|
1998-02-27 07:54:42 +03:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
(void) path;
|
|
|
|
(void) local;
|
|
|
|
(void) has_changed;
|
|
|
|
|
1999-11-11 17:23:40 +03:00
|
|
|
return 0;
|
1998-02-27 07:54:42 +03:00
|
|
|
}
|
|
|
|
|
1998-12-15 22:53:55 +03:00
|
|
|
static int
|
2004-08-16 23:47:21 +04:00
|
|
|
local_which (struct vfs_class *me, const char *path)
|
1998-09-27 23:27:58 +04:00
|
|
|
{
|
2005-02-22 21:35:22 +03:00
|
|
|
(void) me;
|
|
|
|
(void) path;
|
|
|
|
|
1998-09-27 23:27:58 +04:00
|
|
|
return 0; /* Every path which other systems do not like is expected to be ours */
|
|
|
|
}
|
|
|
|
|
2003-10-12 23:57:27 +04:00
|
|
|
void
|
|
|
|
init_localfs (void)
|
|
|
|
{
|
|
|
|
vfs_local_ops.name = "localfs";
|
|
|
|
vfs_local_ops.flags = VFSF_LOCAL;
|
|
|
|
vfs_local_ops.which = local_which;
|
|
|
|
vfs_local_ops.open = local_open;
|
|
|
|
vfs_local_ops.close = local_close;
|
|
|
|
vfs_local_ops.read = local_read;
|
|
|
|
vfs_local_ops.write = local_write;
|
|
|
|
vfs_local_ops.opendir = local_opendir;
|
|
|
|
vfs_local_ops.readdir = local_readdir;
|
|
|
|
vfs_local_ops.closedir = local_closedir;
|
|
|
|
vfs_local_ops.stat = local_stat;
|
|
|
|
vfs_local_ops.lstat = local_lstat;
|
|
|
|
vfs_local_ops.fstat = local_fstat;
|
|
|
|
vfs_local_ops.chmod = local_chmod;
|
|
|
|
vfs_local_ops.chown = local_chown;
|
|
|
|
vfs_local_ops.utime = local_utime;
|
|
|
|
vfs_local_ops.readlink = local_readlink;
|
|
|
|
vfs_local_ops.symlink = local_symlink;
|
|
|
|
vfs_local_ops.link = local_link;
|
|
|
|
vfs_local_ops.unlink = local_unlink;
|
|
|
|
vfs_local_ops.rename = local_rename;
|
|
|
|
vfs_local_ops.chdir = local_chdir;
|
|
|
|
vfs_local_ops.ferrno = local_errno;
|
|
|
|
vfs_local_ops.lseek = local_lseek;
|
|
|
|
vfs_local_ops.mknod = local_mknod;
|
|
|
|
vfs_local_ops.getlocalcopy = local_getlocalcopy;
|
|
|
|
vfs_local_ops.ungetlocalcopy = local_ungetlocalcopy;
|
|
|
|
vfs_local_ops.mkdir = local_mkdir;
|
|
|
|
vfs_local_ops.rmdir = local_rmdir;
|
|
|
|
vfs_register_class (&vfs_local_ops);
|
|
|
|
}
|