mc/vfs/local.c

426 lines
6.3 KiB
C
Raw Normal View History

1998-02-27 07:54:42 +03:00
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include "utilvfs.h"
1998-02-27 07:54:42 +03:00
#include "vfs.h"
#include <config.h>
1998-12-15 22:53:55 +03:00
#include "local.h"
1998-02-27 07:54:42 +03:00
/* Note: Some of this functions are not static. This has rather good
* reason: exactly same functions would have to appear in sfs.c. This
* saves both computer's memory and my work. <pavel@ucw.cz>
* */
1998-02-27 07:54:42 +03:00
1998-12-15 22:53:55 +03:00
static void *
local_open (vfs *me, char *file, int flags, int mode)
1998-02-27 07:54:42 +03:00
{
int *local_info;
int fd;
fd = open (file, NO_LINEAR(flags), mode);
1998-02-27 07:54:42 +03:00
if (fd == -1)
return 0;
local_info = g_new (int, 1);
1998-02-27 07:54:42 +03:00
*local_info = fd;
return local_info;
}
1998-12-15 22:53:55 +03:00
int
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;
g_free (data);
1998-02-27 07:54:42 +03:00
return close (fd);
}
1998-12-15 22:53:55 +03:00
int
local_errno (vfs *me)
1998-02-27 07:54:42 +03:00
{
return errno;
}
1998-12-15 22:53:55 +03:00
static void *
local_opendir (vfs *me, char *dirname)
1998-02-27 07:54:42 +03:00
{
DIR **local_info;
DIR *dir;
dir = opendir (dirname);
if (!dir)
return 0;
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 int
local_telldir (void *data)
{
#ifdef HAVE_TELLDIR
return telldir( *(DIR **) data );
#else
#warning "Native telldir() not available, emulation not implemented"
abort();
return 0; /* for dumb compilers */
#endif /* !HAVE_TELLDIR */
}
1998-12-15 22:53:55 +03:00
static void
local_seekdir (void *data, int offset)
{
#ifdef HAVE_SEEKDIR
seekdir( *(DIR **) data, offset );
#else
#warning "Native seekdir() not available, emulation not implemented"
abort();
#endif /* !HAVE_SEEKDIR */
}
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);
if (data)
g_free (data);
1998-02-27 07:54:42 +03:00
return i;
}
1998-12-15 22:53:55 +03:00
static int
local_stat (vfs *me, char *path, struct stat *buf)
1998-02-27 07:54:42 +03:00
{
return stat (path, buf);
}
1998-12-15 22:53:55 +03:00
static int
local_lstat (vfs *me, char *path, struct stat *buf)
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
{
return fstat (*((int *) data), buf);
}
1998-12-15 22:53:55 +03:00
static int
local_chmod (vfs *me, char *path, int mode)
1998-02-27 07:54:42 +03:00
{
return chmod (path, mode);
}
1998-12-15 22:53:55 +03:00
static int
local_chown (vfs *me, char *path, int owner, int group)
1998-02-27 07:54:42 +03:00
{
return chown (path, owner, group);
}
1998-12-15 22:53:55 +03:00
static int
local_utime (vfs *me, char *path, struct utimbuf *times)
1998-02-27 07:54:42 +03:00
{
return utime (path, times);
}
1998-12-15 22:53:55 +03:00
static int
local_readlink (vfs *me, char *path, char *buf, int size)
1998-02-27 07:54:42 +03:00
{
return readlink (path, buf, size);
}
1998-12-15 22:53:55 +03:00
static int
local_unlink (vfs *me, char *path)
1998-02-27 07:54:42 +03:00
{
return unlink (path);
}
1998-12-15 22:53:55 +03:00
static int
local_symlink (vfs *me, char *n1, char *n2)
1998-02-27 07:54:42 +03:00
{
return symlink (n1, n2);
}
1998-12-15 22:53:55 +03:00
static int
local_write (void *data, 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
local_rename (vfs *me, char *a, char *b)
1998-02-27 07:54:42 +03:00
{
return rename (a, b);
}
1998-12-15 22:53:55 +03:00
static int
local_chdir (vfs *me, char *path)
1998-02-27 07:54:42 +03:00
{
return chdir (path);
}
1998-12-15 22:53:55 +03:00
int
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
local_mknod (vfs *me, char *path, int mode, int dev)
1998-02-27 07:54:42 +03:00
{
return mknod (path, mode, dev);
}
1998-12-15 22:53:55 +03:00
static int
local_link (vfs *me, char *p1, char *p2)
1998-02-27 07:54:42 +03:00
{
return link (p1, p2);
}
1998-12-15 22:53:55 +03:00
static int
local_mkdir (vfs *me, char *path, mode_t mode)
1998-02-27 07:54:42 +03:00
{
return mkdir (path, mode);
}
1998-12-15 22:53:55 +03:00
static int
local_rmdir (vfs *me, char *path)
1998-02-27 07:54:42 +03:00
{
return rmdir (path);
}
1998-12-15 22:53:55 +03:00
static vfsid
local_getid (vfs *me, char *path, struct vfs_stamping **parent)
1998-02-27 07:54:42 +03:00
{
*parent = NULL;
return (vfsid) -1; /* We do not free local fs stuff at all */
}
1998-12-15 22:53:55 +03:00
static int
local_nothingisopen (vfsid id)
1998-02-27 07:54:42 +03:00
{
return 0;
}
1998-12-15 22:53:55 +03:00
static void
local_free (vfsid id)
1998-02-27 07:54:42 +03:00
{
}
1998-12-15 22:53:55 +03:00
static char *
local_getlocalcopy (vfs *me, char *path)
1998-02-27 07:54:42 +03:00
{
return g_strdup (path);
1998-02-27 07:54:42 +03:00
}
static int
1998-12-15 22:53:55 +03:00
local_ungetlocalcopy (vfs *me, char *path, char *local, int has_changed)
1998-02-27 07:54:42 +03:00
{
return 0;
1998-02-27 07:54:42 +03:00
}
#ifdef HAVE_MMAP
1998-12-15 22:53:55 +03:00
caddr_t
local_mmap (vfs *me, caddr_t addr, size_t len, int prot, int flags, void *data, off_t offset)
1998-02-27 07:54:42 +03:00
{
int fd = * (int *)data;
return mmap (addr, len, prot, flags, fd, offset);
}
1998-12-15 22:53:55 +03:00
int
local_munmap (vfs *me, caddr_t addr, size_t len, void *data)
1998-02-27 07:54:42 +03:00
{
return munmap (addr, len);
}
#endif
1998-12-15 22:53:55 +03:00
static int
local_which (vfs *me, char *path)
{
return 0; /* Every path which other systems do not like is expected to be ours */
}
1998-10-13 02:07:53 +04:00
vfs vfs_local_ops = {
NULL, /* This is place of next pointer */
"localfs",
0, /* flags */
NULL, /* prefix */
NULL, /* data */
0, /* errno */
NULL,
NULL,
NULL,
local_which,
1998-02-27 07:54:42 +03:00
local_open,
local_close,
local_read,
local_write,
local_opendir,
local_readdir,
local_closedir,
local_telldir,
local_seekdir,
1998-02-27 07:54:42 +03:00
local_stat,
local_lstat,
local_fstat,
local_chmod,
local_chown,
local_utime,
local_readlink,
local_symlink,
local_link,
local_unlink,
local_rename,
local_chdir,
local_errno,
local_lseek,
local_mknod,
local_getid,
local_nothingisopen,
local_free,
local_getlocalcopy,
local_ungetlocalcopy,
local_mkdir,
local_rmdir,
NULL,
NULL
#ifdef HAVE_MMAP
,local_mmap,
local_munmap
#endif
};
vfs vfs_nil_ops = {
NULL, /* This is place of next pointer */
"nullfs",
0, /* flags */
NULL, /* prefix */
NULL, /* data */
0, /* errno */
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
local_getid,
local_nothingisopen,
local_free,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
#ifdef HAVE_MMAP
, NULL,
NULL
#endif
};