home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / vfs / local.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  4.4 KB  |  278 lines

  1. #include <config.h>
  2. #include <errno.h>
  3. #include <sys/types.h>
  4. #include <malloc.h>
  5. #include <unistd.h>
  6. #include <stdio.h>
  7. #include <string.h>
  8. #include "../src/mad.h"
  9. #include "../src/fs.h"
  10.  
  11. #include <fcntl.h>
  12. #include "../src/util.h"
  13.  
  14. #include "vfs.h"
  15.  
  16.     
  17. static void *local_open (char *file, int flags, int mode)
  18. {
  19.     int *local_info;
  20.     int fd;
  21.  
  22.     fd = open (file, flags, mode);
  23.     if (fd == -1)
  24.     return 0;
  25.  
  26.     local_info = (int *) xmalloc (sizeof (int), "Local fs");
  27.     *local_info = fd;
  28.     
  29.     return local_info;
  30. }
  31.  
  32. static int local_read (void *data, char *buffer, int count)
  33. {
  34.     int n;
  35.  
  36.     if (!data)
  37.     return -1;
  38.     
  39.     while ((n = read (*((int *) data), buffer, count)) == -1){
  40. #ifdef EAGAIN
  41.     if (errno == EAGAIN) continue;
  42. #endif
  43. #ifdef EINTR
  44.     if (errno == EINTR) continue;
  45. #endif
  46.     }
  47.     return n;
  48. }
  49.  
  50. static int local_close (void *data)
  51. {
  52.     int fd;
  53.  
  54.     if (!data)
  55.     return -1;
  56.     
  57.     fd =  *(int *) data;
  58.     free (data);
  59.     return close (fd);
  60. }
  61.  
  62. static int local_errno (void)
  63. {
  64.     return errno;
  65. }
  66.  
  67. static void *local_opendir (char *dirname)
  68. {
  69.     DIR **local_info;
  70.     DIR *dir;
  71.  
  72.     dir = opendir (dirname);
  73.     if (!dir)
  74.     return 0;
  75.  
  76.     local_info = (DIR **) xmalloc (sizeof (DIR *), "Local fs");
  77.     *local_info = dir;
  78.     
  79.     return local_info;
  80. }
  81.  
  82. static void *local_readdir (void *data)
  83. {
  84.     return readdir (*(DIR **) data);
  85. }
  86.  
  87. static int local_closedir (void *data)
  88. {
  89.     int i;
  90.  
  91.     i = closedir (* (DIR **) data);
  92.     if (data)
  93.     free (data);
  94.     return i;
  95. }
  96.  
  97. static int local_stat (char *path, struct stat *buf)
  98. {
  99.     return stat (path, buf);
  100. }
  101.  
  102. static int local_lstat (char *path, struct stat *buf)
  103. {
  104.     return lstat (path, buf);
  105. }
  106.  
  107. static int local_fstat (void *data, struct stat *buf)
  108. {
  109.     return fstat (*((int *) data), buf);    
  110. }
  111.  
  112. static int local_chmod (char *path, int mode)
  113. {
  114.     return chmod (path, mode);
  115. }
  116.  
  117. static int local_chown (char *path, int owner, int group)
  118. {
  119.     return chown (path, owner, group);
  120. }
  121.  
  122. static int local_readlink (char *path, char *buf, int size)
  123. {
  124.     return readlink (path, buf, size);
  125. }
  126.  
  127. static int local_unlink (char *path)
  128. {
  129.     return unlink (path);
  130. }
  131.  
  132. static int local_symlink (char *n1, char *n2)
  133. {
  134.     return symlink (n1, n2);
  135. }
  136.  
  137. static int local_write (void *data, char *buf, int nbyte)
  138. {
  139.     int fd;
  140.     int n;
  141.  
  142.     if (!data)
  143.     return -1;
  144.     
  145.     fd = * (int *) data;
  146.     while ((n = write (fd, buf, nbyte)) == -1){
  147. #ifdef EAGAIN
  148.     if (errno == EAGAIN) continue;
  149. #endif
  150. #ifdef EINTR
  151.     if (errno == EINTR) continue;
  152. #endif
  153.     break;
  154.     }
  155.     return n;
  156. }
  157.  
  158. static int local_rename (char *a, char *b)
  159. {
  160.     return rename (a, b);
  161. }
  162.  
  163. static int local_chdir (char *path)
  164. {
  165.     return chdir (path);
  166. }
  167.  
  168. static int local_lseek (void *data, off_t offset, int whence)
  169. {
  170.     int fd = * (int *) data;
  171.  
  172.     return lseek (fd, offset, whence);
  173. }
  174.  
  175. static int local_mknod (char *path, int mode, int dev)
  176. {
  177.     return mknod (path, mode, dev);
  178. }
  179.  
  180. static int local_link (char *p1, char *p2)
  181. {
  182.     return link (p1, p2);
  183. }
  184.  
  185. static int local_mkdir (char *path, mode_t mode)
  186. {
  187.     return mkdir (path, mode);
  188. }
  189.  
  190. static int local_rmdir (char *path)
  191. {
  192.     return rmdir (path);
  193. }
  194.  
  195. static vfsid local_getid (char *path, struct vfs_stamping **parent)
  196. {
  197.     *parent = NULL;
  198.     return (vfsid) -1; /* We do not free local fs stuff at all */
  199. }
  200.  
  201. static int local_nothingisopen (vfsid id)
  202. {
  203.     return 0;
  204. }
  205.  
  206. static void local_free (vfsid id)
  207. {
  208. }
  209.  
  210. static char *local_getlocalcopy (char *path)
  211. {
  212.     return strdup (path);
  213. }
  214.  
  215. static void local_ungetlocalcopy (char *path, char *local, int has_changed)
  216. {
  217. }
  218.  
  219. #ifdef HAVE_MMAP
  220. static caddr_t local_mmap (caddr_t addr, size_t len, int prot, int flags, void *data, off_t offset)
  221. {
  222.     int fd = * (int *)data;
  223.  
  224.     return mmap (addr, len, prot, flags, fd, offset);
  225. }
  226.  
  227. static int local_munmap (caddr_t addr, size_t len, void *data)
  228. {
  229.     return munmap (addr, len);
  230. }
  231. #endif
  232.  
  233. vfs local_vfs_ops = {
  234.     local_open,
  235.     local_close,
  236.     local_read,
  237.     local_write,
  238.     
  239.     local_opendir,
  240.     local_readdir,
  241.     local_closedir,
  242.  
  243.     local_stat,
  244.     local_lstat,
  245.     local_fstat,
  246.  
  247.     local_chmod,
  248.     local_chown,
  249.  
  250.     local_readlink,
  251.     local_symlink,
  252.     local_link,
  253.     local_unlink,
  254.  
  255.     local_rename,
  256.     local_chdir,
  257.     local_errno,
  258.     local_lseek,
  259.     local_mknod,
  260.     
  261.     local_getid,
  262.     local_nothingisopen,
  263.     local_free,
  264.     
  265.     local_getlocalcopy,
  266.     local_ungetlocalcopy,
  267.     
  268.     local_mkdir,
  269.     local_rmdir,
  270.     
  271.     NULL,
  272.     NULL
  273. #ifdef HAVE_MMAP
  274.     ,local_mmap,
  275.     local_munmap
  276. #endif
  277. };
  278.