mc.sh & mc.csh creation fixed...
[midnight-commander.git] / vfs / local.c
blob96c9f0dc4c14689470922075b18dc39dd5f5f11c
1 #include <config.h>
2 #include <errno.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include <stdio.h>
6 #include <string.h>
9 #include "utilvfs.h"
11 #include "vfs.h"
12 #include "local.h"
14 /* Note: Some of this functions are not static. This has rather good
15 * reason: exactly same functions would have to appear in sfs.c. This
16 * saves both computer's memory and my work. <pavel@ucw.cz>
17 * */
19 static void *
20 local_open (vfs *me, char *file, int flags, int mode)
22 int *local_info;
23 int fd;
25 fd = open (file, NO_LINEAR(flags), mode);
26 if (fd == -1)
27 return 0;
29 local_info = g_new (int, 1);
30 *local_info = fd;
32 return local_info;
35 int
36 local_read (void *data, char *buffer, int count)
38 int n;
40 if (!data)
41 return -1;
43 while ((n = read (*((int *) data), buffer, count)) == -1){
44 #ifdef EAGAIN
45 if (errno == EAGAIN) continue;
46 #endif
47 #ifdef EINTR
48 if (errno == EINTR) continue;
49 #endif
50 return -1;
52 return n;
55 int
56 local_close (void *data)
58 int fd;
60 if (!data)
61 return -1;
63 fd = *(int *) data;
64 g_free (data);
65 return close (fd);
68 int
69 local_errno (vfs *me)
71 return errno;
74 static void *
75 local_opendir (vfs *me, char *dirname)
77 DIR **local_info;
78 DIR *dir;
80 dir = opendir (dirname);
81 if (!dir)
82 return 0;
84 local_info = (DIR **) g_new (DIR *, 1);
85 *local_info = dir;
87 return local_info;
90 static int
91 local_telldir (void *data)
93 #ifdef HAVE_TELLDIR
94 return telldir( *(DIR **) data );
95 #else
96 #warning "Native telldir() not available, emulation not implemented"
97 abort();
98 return 0; /* for dumb compilers */
99 #endif /* !HAVE_TELLDIR */
102 static void
103 local_seekdir (void *data, int offset)
105 #ifdef HAVE_SEEKDIR
106 seekdir( *(DIR **) data, offset );
107 #else
108 #warning "Native seekdir() not available, emulation not implemented"
109 abort();
110 #endif /* !HAVE_SEEKDIR */
113 static void *
114 local_readdir (void *data)
116 return readdir (*(DIR **) data);
119 static int
120 local_closedir (void *data)
122 int i;
124 i = closedir (* (DIR **) data);
125 if (data)
126 g_free (data);
127 return i;
130 static int
131 local_stat (vfs *me, char *path, struct stat *buf)
133 return stat (path, buf);
136 static int
137 local_lstat (vfs *me, char *path, struct stat *buf)
139 #ifndef HAVE_STATLSTAT
140 return lstat (path,buf);
141 #else
142 return statlstat (path, buf);
143 #endif
147 local_fstat (void *data, struct stat *buf)
149 return fstat (*((int *) data), buf);
152 static int
153 local_chmod (vfs *me, char *path, int mode)
155 return chmod (path, mode);
158 static int
159 local_chown (vfs *me, char *path, int owner, int group)
161 return chown (path, owner, group);
164 static int
165 local_utime (vfs *me, char *path, struct utimbuf *times)
167 return utime (path, times);
170 static int
171 local_readlink (vfs *me, char *path, char *buf, int size)
173 return readlink (path, buf, size);
176 static int
177 local_unlink (vfs *me, char *path)
179 return unlink (path);
182 static int
183 local_symlink (vfs *me, char *n1, char *n2)
185 return symlink (n1, n2);
188 static int
189 local_write (void *data, char *buf, int nbyte)
191 int fd;
192 int n;
194 if (!data)
195 return -1;
197 fd = * (int *) data;
198 while ((n = write (fd, buf, nbyte)) == -1){
199 #ifdef EAGAIN
200 if (errno == EAGAIN) continue;
201 #endif
202 #ifdef EINTR
203 if (errno == EINTR) continue;
204 #endif
205 break;
207 return n;
210 static int
211 local_rename (vfs *me, char *a, char *b)
213 return rename (a, b);
216 static int
217 local_chdir (vfs *me, char *path)
219 return chdir (path);
223 local_lseek (void *data, off_t offset, int whence)
225 int fd = * (int *) data;
227 return lseek (fd, offset, whence);
230 static int
231 local_mknod (vfs *me, char *path, int mode, int dev)
233 return mknod (path, mode, dev);
236 static int
237 local_link (vfs *me, char *p1, char *p2)
239 return link (p1, p2);
242 static int
243 local_mkdir (vfs *me, char *path, mode_t mode)
245 return mkdir (path, mode);
248 static int
249 local_rmdir (vfs *me, char *path)
251 return rmdir (path);
254 static vfsid
255 local_getid (vfs *me, char *path, struct vfs_stamping **parent)
257 *parent = NULL;
258 return (vfsid) -1; /* We do not free local fs stuff at all */
261 static int
262 local_nothingisopen (vfsid id)
264 return 0;
267 static void
268 local_free (vfsid id)
272 static char *
273 local_getlocalcopy (vfs *me, char *path)
275 return g_strdup (path);
278 static int
279 local_ungetlocalcopy (vfs *me, char *path, char *local, int has_changed)
281 return 0;
284 #ifdef HAVE_MMAP
285 caddr_t
286 local_mmap (vfs *me, caddr_t addr, size_t len, int prot, int flags, void *data, off_t offset)
288 int fd = * (int *)data;
290 return mmap (addr, len, prot, flags, fd, offset);
294 local_munmap (vfs *me, caddr_t addr, size_t len, void *data)
296 return munmap (addr, len);
298 #endif
300 static int
301 local_which (vfs *me, char *path)
303 return 0; /* Every path which other systems do not like is expected to be ours */
306 vfs vfs_local_ops = {
307 NULL, /* This is place of next pointer */
308 "localfs",
309 0, /* flags */
310 NULL, /* prefix */
311 NULL, /* data */
312 0, /* errno */
313 NULL,
314 NULL,
315 NULL,
316 local_which,
318 local_open,
319 local_close,
320 local_read,
321 local_write,
323 local_opendir,
324 local_readdir,
325 local_closedir,
326 local_telldir,
327 local_seekdir,
329 local_stat,
330 local_lstat,
331 local_fstat,
333 local_chmod,
334 local_chown,
335 local_utime,
337 local_readlink,
338 local_symlink,
339 local_link,
340 local_unlink,
342 local_rename,
343 local_chdir,
344 local_errno,
345 local_lseek,
346 local_mknod,
348 local_getid,
349 local_nothingisopen,
350 local_free,
352 local_getlocalcopy,
353 local_ungetlocalcopy,
355 local_mkdir,
356 local_rmdir,
358 NULL,
359 NULL
360 #ifdef HAVE_MMAP
361 ,local_mmap,
362 local_munmap
363 #endif
366 vfs vfs_nil_ops = {
367 NULL, /* This is place of next pointer */
368 "nullfs",
369 0, /* flags */
370 NULL, /* prefix */
371 NULL, /* data */
372 0, /* errno */
373 NULL,
374 NULL,
375 NULL,
376 NULL,
378 NULL,
379 NULL,
380 NULL,
381 NULL,
383 NULL,
384 NULL,
385 NULL,
386 NULL,
387 NULL,
389 NULL,
390 NULL,
391 NULL,
393 NULL,
394 NULL,
395 NULL,
397 NULL,
398 NULL,
399 NULL,
400 NULL,
402 NULL,
403 NULL,
404 NULL,
405 NULL,
406 NULL,
408 local_getid,
409 local_nothingisopen,
410 local_free,
412 NULL,
413 NULL,
415 NULL,
416 NULL,
418 NULL,
419 NULL
420 #ifdef HAVE_MMAP
421 , NULL,
422 NULL
423 #endif