2 * Client fuse interface handling of 'GnomeVFSFileInfo' for libcaptive
3 * Copyright (C) 2005 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 <libgnomevfs/gnome-vfs-result.h>
23 #include <glib/gmessages.h>
26 #include <libgnomevfs/gnome-vfs-file-info.h>
29 #include <captive/client-vfs.h>
31 #include "gnomevfsresult.h" /* self */
35 static CaptiveVfsVolumeInfo volume_info;
36 static gboolean volume_info_valid=FALSE;
39 int gnomevfsfileinfo_to_stat(struct stat *stat,const GnomeVFSFileInfo *file_info)
41 g_return_val_if_fail(stat!=NULL,-EINVAL);
42 g_return_val_if_fail(file_info!=NULL,-EINVAL);
44 if (!volume_info_valid) {
45 GnomeVFSResult errvfsresult;
47 if (GNOME_VFS_OK!=(errvfsresult=captive_vfs_volume_info_get(capfuse_captive_vfs_object,&volume_info)))
48 return -gnomevfsresult_to_errno(errvfsresult);
49 volume_info_valid=TRUE;
54 if (file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_TYPE)
55 switch (file_info->type) {
56 case GNOME_VFS_FILE_TYPE_REGULAR:
57 stat->st_mode|=S_IFREG;
61 case GNOME_VFS_FILE_TYPE_DIRECTORY:
62 stat->st_mode|=S_IFDIR;
67 g_warning("Unknown GnomeVFSFileInfo.type=%d of: %s",(int)file_info->type,file_info->name);
70 if (file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS)
71 stat->st_mode|=file_info->permissions & 0777;
75 if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT))
78 stat->st_nlink=file_info->link_count;
80 stat->st_uid=0; /* we own the file */
81 stat->st_gid=0; /* we own the file */
83 if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SIZE))
86 stat->st_size=file_info->size;
88 if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ATIME))
89 stat->st_atime=time(NULL);
91 stat->st_atime=file_info->atime;
93 if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MTIME))
94 stat->st_mtime=time(NULL);
96 stat->st_mtime=file_info->mtime;
98 if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_CTIME))
99 stat->st_ctime=time(NULL);
101 stat->st_ctime=file_info->ctime;
103 stat->st_blksize=volume_info.block_size;
105 if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT)) {
108 stat->st_blocks=stat->st_size/volume_info.block_size;
111 stat->st_blocks=file_info->block_count;
114 stat->st_rdev=0; /* Never to be used. */