Following prototypes of functions was changed in VFS-module API:
[midnight-commander.git] / src / vfs / local / local.c
blobf41246f5a4ac56cba23c35eb11076ab010a9fb6d
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. */
20 /**
21 * \file
22 * \brief Source: local FS
25 #include <config.h>
26 #include <errno.h>
27 #include <sys/types.h>
28 #include <unistd.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <fcntl.h>
33 #include "lib/global.h"
35 #include "lib/vfs/utilvfs.h"
37 #include "local.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 /* --------------------------------------------------------------------------------------------- */
52 /**
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 /* --------------------------------------------------------------------------------------------- */
61 static void *
62 local_open (const vfs_path_t * vpath, int flags, mode_t mode)
64 int *local_info;
65 int fd;
67 fd = open (vpath->unparsed, NO_LINEAR (flags), mode);
68 if (fd == -1)
69 return 0;
71 local_info = g_new (int, 1);
72 *local_info = fd;
74 return local_info;
77 /* --------------------------------------------------------------------------------------------- */
79 static void *
80 local_opendir (struct vfs_class *me, const char *dirname)
82 DIR **local_info;
83 DIR *dir;
85 (void) me;
87 dir = opendir (dirname);
88 if (!dir)
89 return 0;
91 local_info = (DIR **) g_new (DIR *, 1);
92 *local_info = dir;
94 return local_info;
97 /* --------------------------------------------------------------------------------------------- */
99 static void *
100 local_readdir (void *data)
102 return readdir (*(DIR **) data);
105 /* --------------------------------------------------------------------------------------------- */
107 static int
108 local_closedir (void *data)
110 int i;
112 i = closedir (*(DIR **) data);
113 g_free (data);
114 return i;
117 /* --------------------------------------------------------------------------------------------- */
119 static int
120 local_stat (struct vfs_class *me, const char *path, struct stat *buf)
122 (void) me;
124 return stat (path, buf);
127 /* --------------------------------------------------------------------------------------------- */
129 static int
130 local_lstat (struct vfs_class *me, const char *path, struct stat *buf)
132 (void) me;
134 #ifndef HAVE_STATLSTAT
135 return lstat (path, buf);
136 #else
137 return statlstat (path, buf);
138 #endif
141 /* --------------------------------------------------------------------------------------------- */
143 static int
144 local_chmod (struct vfs_class *me, const char *path, int mode)
146 (void) me;
148 return chmod (path, mode);
151 /* --------------------------------------------------------------------------------------------- */
153 static int
154 local_chown (struct vfs_class *me, const char *path, uid_t owner, gid_t group)
156 (void) me;
158 return chown (path, owner, group);
161 /* --------------------------------------------------------------------------------------------- */
163 static int
164 local_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
166 (void) me;
168 return utime (path, times);
171 /* --------------------------------------------------------------------------------------------- */
173 static int
174 local_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
176 (void) me;
178 return readlink (path, buf, size);
181 /* --------------------------------------------------------------------------------------------- */
183 static int
184 local_unlink (struct vfs_class *me, const char *path)
186 (void) me;
188 return unlink (path);
191 /* --------------------------------------------------------------------------------------------- */
193 static int
194 local_symlink (struct vfs_class *me, const char *n1, const char *n2)
196 (void) me;
198 return symlink (n1, n2);
201 /* --------------------------------------------------------------------------------------------- */
203 static ssize_t
204 local_write (void *data, const char *buf, size_t nbyte)
206 int fd;
207 int n;
209 if (!data)
210 return -1;
212 fd = *(int *) data;
213 while ((n = write (fd, buf, nbyte)) == -1)
215 #ifdef EAGAIN
216 if (errno == EAGAIN)
217 continue;
218 #endif
219 #ifdef EINTR
220 if (errno == EINTR)
221 continue;
222 #endif
223 break;
225 return n;
228 /* --------------------------------------------------------------------------------------------- */
230 static int
231 local_rename (struct vfs_class *me, const char *a, const char *b)
233 (void) me;
235 return rename (a, b);
238 /* --------------------------------------------------------------------------------------------- */
240 static int
241 local_chdir (struct vfs_class *me, const char *path)
243 (void) me;
245 return chdir (path);
248 /* --------------------------------------------------------------------------------------------- */
250 static int
251 local_mknod (struct vfs_class *me, const char *path, mode_t mode, dev_t dev)
253 (void) me;
255 return mknod (path, mode, dev);
258 /* --------------------------------------------------------------------------------------------- */
260 static int
261 local_link (struct vfs_class *me, const char *p1, const char *p2)
263 (void) me;
265 return link (p1, p2);
268 /* --------------------------------------------------------------------------------------------- */
270 static int
271 local_mkdir (struct vfs_class *me, const char *path, mode_t mode)
273 (void) me;
275 return mkdir (path, mode);
278 /* --------------------------------------------------------------------------------------------- */
280 static int
281 local_rmdir (struct vfs_class *me, const char *path)
283 (void) me;
285 return rmdir (path);
288 /* --------------------------------------------------------------------------------------------- */
290 static char *
291 local_getlocalcopy (const vfs_path_t * vpath)
293 return g_strdup (vpath->unparsed);
296 /* --------------------------------------------------------------------------------------------- */
298 static int
299 local_ungetlocalcopy (const vfs_path_t * vpath, const char *local, int has_changed)
301 (void) vpath;
302 (void) local;
303 (void) has_changed;
305 return 0;
308 /* --------------------------------------------------------------------------------------------- */
310 static int
311 local_which (struct vfs_class *me, const char *path)
313 (void) me;
314 (void) path;
316 return 0; /* Every path which other systems do not like is expected to be ours */
319 /* --------------------------------------------------------------------------------------------- */
320 /*** public functions ****************************************************************************/
321 /* --------------------------------------------------------------------------------------------- */
323 ssize_t
324 local_read (void *data, char *buffer, size_t count)
326 int n;
328 if (!data)
329 return -1;
331 while ((n = read (*((int *) data), buffer, count)) == -1)
333 #ifdef EAGAIN
334 if (errno == EAGAIN)
335 continue;
336 #endif
337 #ifdef EINTR
338 if (errno == EINTR)
339 continue;
340 #endif
341 return -1;
343 return n;
346 /* --------------------------------------------------------------------------------------------- */
349 local_close (void *data)
351 int fd;
353 if (!data)
354 return -1;
356 fd = *(int *) data;
357 g_free (data);
358 return close (fd);
361 /* --------------------------------------------------------------------------------------------- */
364 local_errno (struct vfs_class *me)
366 (void) me;
367 return errno;
370 /* --------------------------------------------------------------------------------------------- */
373 local_fstat (void *data, struct stat *buf)
375 /* FIXME: avoid type cast */
376 return fstat (*((int *) data), buf);
379 /* --------------------------------------------------------------------------------------------- */
381 off_t
382 local_lseek (void *data, off_t offset, int whence)
384 int fd = *(int *) data;
386 return lseek (fd, offset, whence);
389 /* --------------------------------------------------------------------------------------------- */
391 void
392 init_localfs (void)
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 /* --------------------------------------------------------------------------------------------- */