1 /* Virtual File System: local file system.
2 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3 2006, 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License
7 as published by the Free Software Foundation; either version 2 of
8 the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 * \brief Source: local FS
27 #include <sys/types.h>
33 #include "lib/global.h"
35 #include "lib/vfs/utilvfs.h"
39 /*** global variables ****************************************************************************/
41 /*** file scope macro definitions ****************************************************************/
43 /*** file scope type declarations ****************************************************************/
45 /*** file scope variables ************************************************************************/
47 static struct vfs_class vfs_local_ops
;
49 /*** file scope functions ************************************************************************/
50 /* --------------------------------------------------------------------------------------------- */
53 * Note: Some of this functions are not static. This has rather good
54 * reason: exactly same functions would have to appear in sfs.c. This
55 * saves both computer's memory and my work. <pavel@ucw.cz>
59 /* --------------------------------------------------------------------------------------------- */
62 local_open (const vfs_path_t
* vpath
, int flags
, mode_t mode
)
67 fd
= open (vpath
->unparsed
, NO_LINEAR (flags
), mode
);
71 local_info
= g_new (int, 1);
77 /* --------------------------------------------------------------------------------------------- */
80 local_opendir (struct vfs_class
*me
, const char *dirname
)
87 dir
= opendir (dirname
);
91 local_info
= (DIR **) g_new (DIR *, 1);
97 /* --------------------------------------------------------------------------------------------- */
100 local_readdir (void *data
)
102 return readdir (*(DIR **) data
);
105 /* --------------------------------------------------------------------------------------------- */
108 local_closedir (void *data
)
112 i
= closedir (*(DIR **) data
);
117 /* --------------------------------------------------------------------------------------------- */
120 local_stat (struct vfs_class
*me
, const char *path
, struct stat
*buf
)
124 return stat (path
, buf
);
127 /* --------------------------------------------------------------------------------------------- */
130 local_lstat (struct vfs_class
*me
, const char *path
, struct stat
*buf
)
134 #ifndef HAVE_STATLSTAT
135 return lstat (path
, buf
);
137 return statlstat (path
, buf
);
141 /* --------------------------------------------------------------------------------------------- */
144 local_chmod (struct vfs_class
*me
, const char *path
, int mode
)
148 return chmod (path
, mode
);
151 /* --------------------------------------------------------------------------------------------- */
154 local_chown (struct vfs_class
*me
, const char *path
, uid_t owner
, gid_t group
)
158 return chown (path
, owner
, group
);
161 /* --------------------------------------------------------------------------------------------- */
164 local_utime (struct vfs_class
*me
, const char *path
, struct utimbuf
*times
)
168 return utime (path
, times
);
171 /* --------------------------------------------------------------------------------------------- */
174 local_readlink (struct vfs_class
*me
, const char *path
, char *buf
, size_t size
)
178 return readlink (path
, buf
, size
);
181 /* --------------------------------------------------------------------------------------------- */
184 local_unlink (struct vfs_class
*me
, const char *path
)
188 return unlink (path
);
191 /* --------------------------------------------------------------------------------------------- */
194 local_symlink (struct vfs_class
*me
, const char *n1
, const char *n2
)
198 return symlink (n1
, n2
);
201 /* --------------------------------------------------------------------------------------------- */
204 local_write (void *data
, const char *buf
, size_t nbyte
)
213 while ((n
= write (fd
, buf
, nbyte
)) == -1)
228 /* --------------------------------------------------------------------------------------------- */
231 local_rename (struct vfs_class
*me
, const char *a
, const char *b
)
235 return rename (a
, b
);
238 /* --------------------------------------------------------------------------------------------- */
241 local_chdir (struct vfs_class
*me
, const char *path
)
248 /* --------------------------------------------------------------------------------------------- */
251 local_mknod (struct vfs_class
*me
, const char *path
, mode_t mode
, dev_t dev
)
255 return mknod (path
, mode
, dev
);
258 /* --------------------------------------------------------------------------------------------- */
261 local_link (struct vfs_class
*me
, const char *p1
, const char *p2
)
265 return link (p1
, p2
);
268 /* --------------------------------------------------------------------------------------------- */
271 local_mkdir (struct vfs_class
*me
, const char *path
, mode_t mode
)
275 return mkdir (path
, mode
);
278 /* --------------------------------------------------------------------------------------------- */
281 local_rmdir (struct vfs_class
*me
, const char *path
)
288 /* --------------------------------------------------------------------------------------------- */
291 local_getlocalcopy (const vfs_path_t
* vpath
)
293 return g_strdup (vpath
->unparsed
);
296 /* --------------------------------------------------------------------------------------------- */
299 local_ungetlocalcopy (const vfs_path_t
* vpath
, const char *local
, int has_changed
)
308 /* --------------------------------------------------------------------------------------------- */
311 local_which (struct vfs_class
*me
, const char *path
)
316 return 0; /* Every path which other systems do not like is expected to be ours */
319 /* --------------------------------------------------------------------------------------------- */
320 /*** public functions ****************************************************************************/
321 /* --------------------------------------------------------------------------------------------- */
324 local_read (void *data
, char *buffer
, size_t count
)
331 while ((n
= read (*((int *) data
), buffer
, count
)) == -1)
346 /* --------------------------------------------------------------------------------------------- */
349 local_close (void *data
)
361 /* --------------------------------------------------------------------------------------------- */
364 local_errno (struct vfs_class
*me
)
370 /* --------------------------------------------------------------------------------------------- */
373 local_fstat (void *data
, struct stat
*buf
)
375 /* FIXME: avoid type cast */
376 return fstat (*((int *) data
), buf
);
379 /* --------------------------------------------------------------------------------------------- */
382 local_lseek (void *data
, off_t offset
, int whence
)
384 int fd
= *(int *) data
;
386 return lseek (fd
, offset
, whence
);
389 /* --------------------------------------------------------------------------------------------- */
394 vfs_local_ops
.name
= "localfs";
395 vfs_local_ops
.flags
= VFSF_LOCAL
;
396 vfs_local_ops
.which
= local_which
;
397 vfs_local_ops
.open
= local_open
;
398 vfs_local_ops
.close
= local_close
;
399 vfs_local_ops
.read
= local_read
;
400 vfs_local_ops
.write
= local_write
;
401 vfs_local_ops
.opendir
= local_opendir
;
402 vfs_local_ops
.readdir
= local_readdir
;
403 vfs_local_ops
.closedir
= local_closedir
;
404 vfs_local_ops
.stat
= local_stat
;
405 vfs_local_ops
.lstat
= local_lstat
;
406 vfs_local_ops
.fstat
= local_fstat
;
407 vfs_local_ops
.chmod
= local_chmod
;
408 vfs_local_ops
.chown
= local_chown
;
409 vfs_local_ops
.utime
= local_utime
;
410 vfs_local_ops
.readlink
= local_readlink
;
411 vfs_local_ops
.symlink
= local_symlink
;
412 vfs_local_ops
.link
= local_link
;
413 vfs_local_ops
.unlink
= local_unlink
;
414 vfs_local_ops
.rename
= local_rename
;
415 vfs_local_ops
.chdir
= local_chdir
;
416 vfs_local_ops
.ferrno
= local_errno
;
417 vfs_local_ops
.lseek
= local_lseek
;
418 vfs_local_ops
.mknod
= local_mknod
;
419 vfs_local_ops
.getlocalcopy
= local_getlocalcopy
;
420 vfs_local_ops
.ungetlocalcopy
= local_ungetlocalcopy
;
421 vfs_local_ops
.mkdir
= local_mkdir
;
422 vfs_local_ops
.rmdir
= local_rmdir
;
423 vfs_register_class (&vfs_local_ops
);
426 /* --------------------------------------------------------------------------------------------- */