2 Virtual File System: local file system.
4 Copyright (C) 1995, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
6 The Free Software Foundation, Inc.
8 This file is part of the Midnight Commander.
10 The Midnight Commander is free software: you can redistribute it
11 and/or modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation, either version 3 of the License,
13 or (at your option) any later version.
15 The Midnight Commander is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 * \brief Source: local FS
31 #include <sys/types.h>
37 #include "lib/global.h"
39 #include "lib/vfs/utilvfs.h"
43 /*** global variables ****************************************************************************/
45 /*** file scope macro definitions ****************************************************************/
47 /*** file scope type declarations ****************************************************************/
49 /*** file scope variables ************************************************************************/
51 static struct vfs_class vfs_local_ops
;
53 /*** file scope functions ************************************************************************/
54 /* --------------------------------------------------------------------------------------------- */
57 * Note: Some of this functions are not static. This has rather good
58 * reason: exactly same functions would have to appear in sfs.c. This
59 * saves both computer's memory and my work. <pavel@ucw.cz>
63 /* --------------------------------------------------------------------------------------------- */
66 local_open (const vfs_path_t
* vpath
, int flags
, mode_t mode
)
70 const vfs_path_element_t
*path_element
;
72 path_element
= vfs_path_get_by_index (vpath
, -1);
73 fd
= open (path_element
->path
, NO_LINEAR (flags
), mode
);
77 local_info
= g_new (int, 1);
83 /* --------------------------------------------------------------------------------------------- */
86 local_opendir (const vfs_path_t
* vpath
)
90 const vfs_path_element_t
*path_element
;
92 path_element
= vfs_path_get_by_index (vpath
, -1);
93 dir
= opendir (path_element
->path
);
97 local_info
= (DIR **) g_new (DIR *, 1);
103 /* --------------------------------------------------------------------------------------------- */
106 local_readdir (void *data
)
108 return readdir (*(DIR **) data
);
111 /* --------------------------------------------------------------------------------------------- */
114 local_closedir (void *data
)
118 i
= closedir (*(DIR **) data
);
123 /* --------------------------------------------------------------------------------------------- */
126 local_stat (const vfs_path_t
* vpath
, struct stat
*buf
)
128 const vfs_path_element_t
*path_element
;
130 path_element
= vfs_path_get_by_index (vpath
, -1);
131 return stat (path_element
->path
, buf
);
134 /* --------------------------------------------------------------------------------------------- */
137 local_lstat (const vfs_path_t
* vpath
, struct stat
*buf
)
139 const vfs_path_element_t
*path_element
;
141 path_element
= vfs_path_get_by_index (vpath
, -1);
142 #ifndef HAVE_STATLSTAT
143 return lstat (path_element
->path
, buf
);
145 return statlstat (path_element
->path
, buf
);
149 /* --------------------------------------------------------------------------------------------- */
152 local_chmod (const vfs_path_t
* vpath
, mode_t mode
)
154 const vfs_path_element_t
*path_element
;
156 path_element
= vfs_path_get_by_index (vpath
, -1);
157 return chmod (path_element
->path
, mode
);
160 /* --------------------------------------------------------------------------------------------- */
163 local_chown (const vfs_path_t
* vpath
, uid_t owner
, gid_t group
)
165 const vfs_path_element_t
*path_element
;
167 path_element
= vfs_path_get_by_index (vpath
, -1);
168 return chown (path_element
->path
, owner
, group
);
171 /* --------------------------------------------------------------------------------------------- */
174 local_utime (const vfs_path_t
* vpath
, struct utimbuf
*times
)
176 const vfs_path_element_t
*path_element
;
178 path_element
= vfs_path_get_by_index (vpath
, -1);
179 return utime (path_element
->path
, times
);
182 /* --------------------------------------------------------------------------------------------- */
185 local_readlink (const vfs_path_t
* vpath
, char *buf
, size_t size
)
187 const vfs_path_element_t
*path_element
;
189 path_element
= vfs_path_get_by_index (vpath
, -1);
190 return readlink (path_element
->path
, buf
, size
);
193 /* --------------------------------------------------------------------------------------------- */
196 local_unlink (const vfs_path_t
* vpath
)
198 const vfs_path_element_t
*path_element
;
200 path_element
= vfs_path_get_by_index (vpath
, -1);
201 return unlink (path_element
->path
);
204 /* --------------------------------------------------------------------------------------------- */
207 local_symlink (const vfs_path_t
* vpath1
, const vfs_path_t
* vpath2
)
209 const vfs_path_element_t
*path_element1
;
210 const vfs_path_element_t
*path_element2
;
212 path_element1
= vfs_path_get_by_index (vpath1
, -1);
213 path_element2
= vfs_path_get_by_index (vpath2
, -1);
214 return symlink (path_element1
->path
, path_element2
->path
);
217 /* --------------------------------------------------------------------------------------------- */
220 local_write (void *data
, const char *buf
, size_t nbyte
)
229 while ((n
= write (fd
, buf
, nbyte
)) == -1)
244 /* --------------------------------------------------------------------------------------------- */
247 local_rename (const vfs_path_t
* vpath1
, const vfs_path_t
* vpath2
)
249 const vfs_path_element_t
*path_element1
;
250 const vfs_path_element_t
*path_element2
;
252 path_element1
= vfs_path_get_by_index (vpath1
, -1);
253 path_element2
= vfs_path_get_by_index (vpath2
, -1);
254 return rename (path_element1
->path
, path_element2
->path
);
257 /* --------------------------------------------------------------------------------------------- */
260 local_chdir (const vfs_path_t
* vpath
)
262 const vfs_path_element_t
*path_element
;
264 path_element
= vfs_path_get_by_index (vpath
, -1);
265 return chdir (path_element
->path
);
268 /* --------------------------------------------------------------------------------------------- */
271 local_mknod (const vfs_path_t
* vpath
, mode_t mode
, dev_t dev
)
273 const vfs_path_element_t
*path_element
;
275 path_element
= vfs_path_get_by_index (vpath
, -1);
276 return mknod (path_element
->path
, mode
, dev
);
279 /* --------------------------------------------------------------------------------------------- */
282 local_link (const vfs_path_t
* vpath1
, const vfs_path_t
* vpath2
)
284 const vfs_path_element_t
*path_element1
;
285 const vfs_path_element_t
*path_element2
;
287 path_element1
= vfs_path_get_by_index (vpath1
, -1);
288 path_element2
= vfs_path_get_by_index (vpath2
, -1);
289 return link (path_element1
->path
, path_element2
->path
);
292 /* --------------------------------------------------------------------------------------------- */
295 local_mkdir (const vfs_path_t
* vpath
, mode_t mode
)
297 const vfs_path_element_t
*path_element
;
299 path_element
= vfs_path_get_by_index (vpath
, -1);
300 return mkdir (path_element
->path
, mode
);
303 /* --------------------------------------------------------------------------------------------- */
306 local_rmdir (const vfs_path_t
* vpath
)
308 const vfs_path_element_t
*path_element
;
310 path_element
= vfs_path_get_by_index (vpath
, -1);
311 return rmdir (path_element
->path
);
314 /* --------------------------------------------------------------------------------------------- */
317 local_getlocalcopy (const vfs_path_t
* vpath
)
319 return vfs_path_clone (vpath
);
322 /* --------------------------------------------------------------------------------------------- */
325 local_ungetlocalcopy (const vfs_path_t
* vpath
, const vfs_path_t
* local
, gboolean has_changed
)
334 /* --------------------------------------------------------------------------------------------- */
337 local_which (struct vfs_class
*me
, const char *path
)
342 return 0; /* Every path which other systems do not like is expected to be ours */
345 /* --------------------------------------------------------------------------------------------- */
346 /*** public functions ****************************************************************************/
347 /* --------------------------------------------------------------------------------------------- */
350 local_read (void *data
, char *buffer
, size_t count
)
357 while ((n
= read (*((int *) data
), buffer
, count
)) == -1)
372 /* --------------------------------------------------------------------------------------------- */
375 local_close (void *data
)
387 /* --------------------------------------------------------------------------------------------- */
390 local_errno (struct vfs_class
*me
)
396 /* --------------------------------------------------------------------------------------------- */
399 local_fstat (void *data
, struct stat
*buf
)
401 /* FIXME: avoid type cast */
402 return fstat (*((int *) data
), buf
);
405 /* --------------------------------------------------------------------------------------------- */
408 local_lseek (void *data
, off_t offset
, int whence
)
410 int fd
= *(int *) data
;
412 return lseek (fd
, offset
, whence
);
415 /* --------------------------------------------------------------------------------------------- */
420 vfs_local_ops
.name
= "localfs";
421 vfs_local_ops
.flags
= VFSF_LOCAL
;
422 vfs_local_ops
.which
= local_which
;
423 vfs_local_ops
.open
= local_open
;
424 vfs_local_ops
.close
= local_close
;
425 vfs_local_ops
.read
= local_read
;
426 vfs_local_ops
.write
= local_write
;
427 vfs_local_ops
.opendir
= local_opendir
;
428 vfs_local_ops
.readdir
= local_readdir
;
429 vfs_local_ops
.closedir
= local_closedir
;
430 vfs_local_ops
.stat
= local_stat
;
431 vfs_local_ops
.lstat
= local_lstat
;
432 vfs_local_ops
.fstat
= local_fstat
;
433 vfs_local_ops
.chmod
= local_chmod
;
434 vfs_local_ops
.chown
= local_chown
;
435 vfs_local_ops
.utime
= local_utime
;
436 vfs_local_ops
.readlink
= local_readlink
;
437 vfs_local_ops
.symlink
= local_symlink
;
438 vfs_local_ops
.link
= local_link
;
439 vfs_local_ops
.unlink
= local_unlink
;
440 vfs_local_ops
.rename
= local_rename
;
441 vfs_local_ops
.chdir
= local_chdir
;
442 vfs_local_ops
.ferrno
= local_errno
;
443 vfs_local_ops
.lseek
= local_lseek
;
444 vfs_local_ops
.mknod
= local_mknod
;
445 vfs_local_ops
.getlocalcopy
= local_getlocalcopy
;
446 vfs_local_ops
.ungetlocalcopy
= local_ungetlocalcopy
;
447 vfs_local_ops
.mkdir
= local_mkdir
;
448 vfs_local_ops
.rmdir
= local_rmdir
;
449 vfs_register_class (&vfs_local_ops
);
452 /* --------------------------------------------------------------------------------------------- */