/* $Id$ * Client fuse interface handling of 'GnomeVFSFileInfo' for libcaptive * Copyright (C) 2005 Jan Kratochvil * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; exactly version 2 of June 1991 is required * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include #include #include #include #include #include #include #include "gnomevfsresult.h" /* self */ #include "main.h" static CaptiveVfsVolumeInfo volume_info; static gboolean volume_info_valid=FALSE; int gnomevfsfileinfo_to_stat(struct stat *stat,const GnomeVFSFileInfo *file_info) { g_return_val_if_fail(stat!=NULL,-EINVAL); g_return_val_if_fail(file_info!=NULL,-EINVAL); if (!volume_info_valid) { GnomeVFSResult errvfsresult; if (GNOME_VFS_OK!=(errvfsresult=captive_vfs_volume_info_get(capfuse_captive_vfs_object,&volume_info))) return -gnomevfsresult_to_errno(errvfsresult); volume_info_valid=TRUE; } stat->st_mode=0; if (file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_TYPE) switch (file_info->type) { case GNOME_VFS_FILE_TYPE_REGULAR: stat->st_mode|=S_IFREG; if (1 /* !private */) stat->st_mode|=0444; break; case GNOME_VFS_FILE_TYPE_DIRECTORY: stat->st_mode|=S_IFDIR; if (1 /* !private */) stat->st_mode|=0555; break; default: g_warning("Unknown GnomeVFSFileInfo.type=%d of: %s",(int)file_info->type,file_info->name); return -EINVAL; } if (file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS) stat->st_mode|=file_info->permissions & 0777; else stat->st_mode|=0600; if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT)) stat->st_nlink=1; else stat->st_nlink=file_info->link_count; stat->st_uid=0; /* we own the file */ stat->st_gid=0; /* we own the file */ if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SIZE)) stat->st_size=0; else stat->st_size=file_info->size; if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ATIME)) stat->st_atime=time(NULL); else stat->st_atime=file_info->atime; if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MTIME)) stat->st_mtime=time(NULL); else stat->st_mtime=file_info->mtime; if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_CTIME)) stat->st_ctime=time(NULL); else stat->st_ctime=file_info->ctime; stat->st_blksize=volume_info.block_size; if (!(file_info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT)) { /* Rounding? */ /* 0? */ stat->st_blocks=stat->st_size/volume_info.block_size; } else stat->st_blocks=file_info->block_count; stat->st_dev=0; stat->st_rdev=0; /* Never to be used. */ stat->st_ino=0; return 0; }