2 * lufs interface module directory objects implementation for libcaptive
3 * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <glib/gmessages.h>
23 #include "captivefs-misc.h"
24 #include "captivefs-attr.h"
25 #include "captivefs-vfs.h"
27 #include <captive/client-vfs.h>
28 #include <captive/client-directory.h>
31 #include <lufs/proto.h>
34 /* Read a directory's content
35 * For each directory entry, call
36 * lu_cache_add2dir(struct directory *dir, char *name, char *link, struct lufs_fattr *fattr)
37 * to add its information.
38 * The link is optional(NULL) and applicable only if the entry is a
39 * (sym)link and we have the target info at hand.
42 * dir_name is an absolute path. However, it is generally a good idea
43 * to either change to that directory here or at least keep track of what
44 * directory was being called on, for function calls that might not get
46 * If your filesystem doesn't natively support '.' or '..', don't forget
47 * to add them to the cache first-thing here.
49 int captivefs_readdir(struct captivefs_vfs *captivefs_vfs,const char *dir_name,struct directory *ddir)
51 struct lufs_fattr fattr;
52 GnomeVFSResult errvfsresult;
53 CaptiveDirectoryObject *captive_directory_object;
54 GnomeVFSFileInfo file_info;
55 const char *dots[]={".","..",NULL},**csp;
57 g_return_val_if_fail(captivefs_vfs_validate(captivefs_vfs),-1);
58 g_return_val_if_fail(dir_name!=NULL,-1);
59 g_return_val_if_fail(ddir!=NULL,-1);
61 if (captivefs_vfs->options.debug_messages)
62 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_readdir: dir_name=%s",dir_name);
65 errvfsresult=captive_directory_new_open(&captive_directory_object,captivefs_vfs->captive_vfs_object,dir_name);
67 if (errvfsresult!=GNOME_VFS_OK)
70 file_info.valid_fields=GNOME_VFS_FILE_INFO_FIELDS_TYPE;
71 file_info.type=GNOME_VFS_FILE_TYPE_DIRECTORY;
72 if (!captivefs_GnomeVFSFileInfo_to_lufs_fattr(captivefs_vfs,&fattr,&file_info))
74 for (csp=dots;*csp;csp++)
75 if (0>lu_cache_add2dir(ddir,(/* de-const */ char *)*csp,NULL,&fattr)) {
76 g_warning("Failed lu_cache_add2dir() for: %s",*csp);
82 errvfsresult=captive_directory_read(captive_directory_object,&file_info);
84 if (errvfsresult==GNOME_VFS_ERROR_EOF) {
85 /* 'captive_directory_object' is now stuck at EOF - GnomeVFS behaves that way. */
88 if (errvfsresult!=GNOME_VFS_OK)
91 if (!captivefs_GnomeVFSFileInfo_to_lufs_fattr(captivefs_vfs,&fattr,&file_info))
94 if (0>lu_cache_add2dir(ddir,file_info.name,NULL,&fattr)) {
95 g_warning("Failed lu_cache_add2dir() for: %s",file_info.name);
99 if (captivefs_vfs->options.debug_messages)
100 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_readdir: got: %s",file_info.name);
104 g_object_unref(captive_directory_object);
105 G_UNLOCK(libcaptive);
111 g_object_unref(captive_directory_object);
112 G_UNLOCK(libcaptive);
118 /* Create a directory
120 int captivefs_mkdir(struct captivefs_vfs *captivefs_vfs,const char *dir,int mode)
122 CaptiveDirectoryObject *captive_directory_object;
123 GnomeVFSResult errvfsresult;
125 g_return_val_if_fail(captivefs_vfs_validate(captivefs_vfs),-1);
126 g_return_val_if_fail(dir!=NULL,-1);
128 if (captivefs_vfs->options.debug_messages)
129 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_mkdir: dir=%s,mode=0x%X",dir,mode);
132 errvfsresult=captive_directory_new_make(&captive_directory_object,captivefs_vfs->captive_vfs_object,dir,mode);
133 G_UNLOCK(libcaptive);
134 if (errvfsresult!=GNOME_VFS_OK)
138 g_object_unref(captive_directory_object);
139 G_UNLOCK(libcaptive);
145 /* Delete a directory
147 int captivefs_rmdir(struct captivefs_vfs *captivefs_vfs,const char *dir)
149 CaptiveDirectoryObject *captive_directory_object;
150 GnomeVFSResult errvfsresult;
152 g_return_val_if_fail(captivefs_vfs_validate(captivefs_vfs),-1);
153 g_return_val_if_fail(dir!=NULL,-1);
155 if (captivefs_vfs->options.debug_messages)
156 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_rmdir: dir=%s",dir);
159 errvfsresult=captive_directory_new_open(&captive_directory_object,captivefs_vfs->captive_vfs_object,dir);
160 G_UNLOCK(libcaptive);
161 if (errvfsresult!=GNOME_VFS_OK)
165 errvfsresult=captive_directory_remove(captive_directory_object);
166 G_UNLOCK(libcaptive);
169 g_object_unref(captive_directory_object);
170 G_UNLOCK(libcaptive);
172 if (errvfsresult!=GNOME_VFS_OK)