Makefile.am: Fixed incorrect variable name if maintainer mode is active.
[midnight-commander.git] / vfs / local.c
blobe136c073a73e498e83d83916808417f693f1fb2c
2 /**
3 * \file
4 * \brief Source: local FS
5 */
7 #include <config.h>
8 #include <errno.h>
9 #include <sys/types.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <string.h>
13 #include <fcntl.h>
15 #include "../src/global.h"
17 #include "../src/wtools.h" /* message() */
18 #include "../src/main.h" /* print_vfs_message */
20 #include "utilvfs.h"
21 #include "vfs.h"
22 #include "local.h"
24 /**
25 * Note: Some of this functions are not static. This has rather good
26 * reason: exactly same functions would have to appear in sfs.c. This
27 * saves both computer's memory and my work. <pavel@ucw.cz>
30 static struct vfs_class vfs_local_ops;
32 static void *
33 local_open (struct vfs_class *me, const char *file, int flags, int mode)
35 int *local_info;
36 int fd;
38 (void) me;
40 fd = open (file, NO_LINEAR (flags), mode);
41 if (fd == -1)
42 return 0;
44 local_info = g_new (int, 1);
45 *local_info = fd;
47 return local_info;
50 ssize_t
51 local_read (void *data, char *buffer, int count)
53 int n;
55 if (!data)
56 return -1;
58 while ((n = read (*((int *) data), buffer, count)) == -1){
59 #ifdef EAGAIN
60 if (errno == EAGAIN) continue;
61 #endif
62 #ifdef EINTR
63 if (errno == EINTR) continue;
64 #endif
65 return -1;
67 return n;
70 int
71 local_close (void *data)
73 int fd;
75 if (!data)
76 return -1;
78 fd = *(int *) data;
79 g_free (data);
80 return close (fd);
83 int
84 local_errno (struct vfs_class *me)
86 (void) me;
87 return errno;
90 static void *
91 local_opendir (struct vfs_class *me, const char *dirname)
93 DIR **local_info;
94 DIR *dir;
96 (void) me;
98 dir = opendir (dirname);
99 if (!dir)
100 return 0;
102 local_info = (DIR **) g_new (DIR *, 1);
103 *local_info = dir;
105 return local_info;
108 static void *
109 local_readdir (void *data)
111 return readdir (*(DIR **) data);
114 static int
115 local_closedir (void *data)
117 int i;
119 i = closedir (* (DIR **) data);
120 g_free (data);
121 return i;
124 static int
125 local_stat (struct vfs_class *me, const char *path, struct stat *buf)
127 (void) me;
129 return stat (path, buf);
132 static int
133 local_lstat (struct vfs_class *me, const char *path, struct stat *buf)
135 (void) me;
137 #ifndef HAVE_STATLSTAT
138 return lstat (path,buf);
139 #else
140 return statlstat (path, buf);
141 #endif
145 local_fstat (void *data, struct stat *buf)
147 /* FIXME: avoid type cast */
148 return fstat (*((int *) data), buf);
151 static int
152 local_chmod (struct vfs_class *me, const char *path, int mode)
154 (void) me;
156 return chmod (path, mode);
159 static int
160 local_chown (struct vfs_class *me, const char *path, int owner, int group)
162 (void) me;
164 return chown (path, owner, group);
167 static int
168 local_utime (struct vfs_class *me, const char *path, struct utimbuf *times)
170 (void) me;
172 return utime (path, times);
175 static int
176 local_readlink (struct vfs_class *me, const char *path, char *buf, size_t size)
178 (void) me;
180 return readlink (path, buf, size);
183 static int
184 local_unlink (struct vfs_class *me, const char *path)
186 (void) me;
188 return unlink (path);
191 static int
192 local_symlink (struct vfs_class *me, const char *n1, const char *n2)
194 (void) me;
196 return symlink (n1, n2);
199 static ssize_t
200 local_write (void *data, const char *buf, int nbyte)
202 int fd;
203 int n;
205 if (!data)
206 return -1;
208 fd = * (int *) data;
209 while ((n = write (fd, buf, nbyte)) == -1){
210 #ifdef EAGAIN
211 if (errno == EAGAIN) continue;
212 #endif
213 #ifdef EINTR
214 if (errno == EINTR) continue;
215 #endif
216 break;
218 return n;
221 static int
222 local_rename (struct vfs_class *me, const char *a, const char *b)
224 (void) me;
226 return rename (a, b);
229 static int
230 local_chdir (struct vfs_class *me, const char *path)
232 (void) me;
234 return chdir (path);
237 off_t
238 local_lseek (void *data, off_t offset, int whence)
240 int fd = * (int *) data;
242 return lseek (fd, offset, whence);
245 static int
246 local_mknod (struct vfs_class *me, const char *path, int mode, int dev)
248 (void) me;
250 return mknod (path, mode, dev);
253 static int
254 local_link (struct vfs_class *me, const char *p1, const char *p2)
256 (void) me;
258 return link (p1, p2);
261 static int
262 local_mkdir (struct vfs_class *me, const char *path, mode_t mode)
264 (void) me;
266 return mkdir (path, mode);
269 static int
270 local_rmdir (struct vfs_class *me, const char *path)
272 (void) me;
274 return rmdir (path);
277 static char *
278 local_getlocalcopy (struct vfs_class *me, const char *path)
280 (void) me;
282 return g_strdup (path);
285 static int
286 local_ungetlocalcopy (struct vfs_class *me, const char *path,
287 const char *local, int has_changed)
289 (void) me;
290 (void) path;
291 (void) local;
292 (void) has_changed;
294 return 0;
297 static int
298 local_which (struct vfs_class *me, const char *path)
300 (void) me;
301 (void) path;
303 return 0; /* Every path which other systems do not like is expected to be ours */
306 void
307 init_localfs (void)
309 vfs_local_ops.name = "localfs";
310 vfs_local_ops.flags = VFSF_LOCAL;
311 vfs_local_ops.which = local_which;
312 vfs_local_ops.open = local_open;
313 vfs_local_ops.close = local_close;
314 vfs_local_ops.read = local_read;
315 vfs_local_ops.write = local_write;
316 vfs_local_ops.opendir = local_opendir;
317 vfs_local_ops.readdir = local_readdir;
318 vfs_local_ops.closedir = local_closedir;
319 vfs_local_ops.stat = local_stat;
320 vfs_local_ops.lstat = local_lstat;
321 vfs_local_ops.fstat = local_fstat;
322 vfs_local_ops.chmod = local_chmod;
323 vfs_local_ops.chown = local_chown;
324 vfs_local_ops.utime = local_utime;
325 vfs_local_ops.readlink = local_readlink;
326 vfs_local_ops.symlink = local_symlink;
327 vfs_local_ops.link = local_link;
328 vfs_local_ops.unlink = local_unlink;
329 vfs_local_ops.rename = local_rename;
330 vfs_local_ops.chdir = local_chdir;
331 vfs_local_ops.ferrno = local_errno;
332 vfs_local_ops.lseek = local_lseek;
333 vfs_local_ops.mknod = local_mknod;
334 vfs_local_ops.getlocalcopy = local_getlocalcopy;
335 vfs_local_ops.ungetlocalcopy = local_ungetlocalcopy;
336 vfs_local_ops.mkdir = local_mkdir;
337 vfs_local_ops.rmdir = local_rmdir;
338 vfs_register_class (&vfs_local_ops);