1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /* test-info.c - Test program for the `get_file_info()' functionality of the
3 GNOME Virtual File System.
5 Copyright (C) 1999 Free Software Foundation
7 The Gnome Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The Gnome Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the Gnome Library; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.
22 Author: Ettore Perazzoli <ettore@comm2000.it> */
27 #include <glib/gmessages.h>
28 #include <libgnomevfs/gnome-vfs-init.h>
29 #include <libgnomevfs/gnome-vfs-ops.h>
34 type_to_string (GnomeVFSFileType type)
37 case GNOME_VFS_FILE_TYPE_UNKNOWN:
39 case GNOME_VFS_FILE_TYPE_REGULAR:
41 case GNOME_VFS_FILE_TYPE_DIRECTORY:
43 case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK:
44 return "Symbolic Link";
45 case GNOME_VFS_FILE_TYPE_FIFO:
47 case GNOME_VFS_FILE_TYPE_SOCKET:
49 case GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE:
50 return "Character device";
51 case GNOME_VFS_FILE_TYPE_BLOCK_DEVICE:
52 return "Block device";
60 print_file_info (const GnomeVFSFileInfo *info)
62 #define FLAG_STRING(info, which) \
63 (GNOME_VFS_FILE_INFO_##which (info) ? "YES" : "NO")
65 printf ("Name : %s\n", info->name);
67 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_TYPE)
68 printf ("Type : %s\n", type_to_string (info->type));
70 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SYMLINK_NAME && info->symlink_name != NULL)
71 printf ("Symlink to : %s\n", info->symlink_name);
73 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE)
74 printf ("MIME type : %s\n", info->mime_type);
76 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SIZE)
77 printf ("Size : %" GNOME_VFS_SIZE_FORMAT_STR "\n",
80 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT)
81 printf ("Blocks : %" GNOME_VFS_SIZE_FORMAT_STR "\n",
84 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE)
85 printf ("I/O block size : %d\n", info->io_block_size);
87 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_FLAGS) {
88 printf ("Local : %s\n", FLAG_STRING (info, LOCAL));
89 printf ("SUID : %s\n", FLAG_STRING (info, SUID));
90 printf ("SGID : %s\n", FLAG_STRING (info, SGID));
91 printf ("Sticky : %s\n", FLAG_STRING (info, STICKY));
94 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS)
95 printf ("Permissions : %04o\n", info->permissions);
98 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT)
99 printf ("Link count : %d\n", info->link_count);
101 printf ("UID : %d\n", info->uid);
102 printf ("GID : %d\n", info->gid);
104 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ATIME)
105 printf ("Access time : %s", ctime (&info->atime));
107 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MTIME)
108 printf ("Modification time : %s", ctime (&info->mtime));
110 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_CTIME)
111 printf ("Change time : %s", ctime (&info->ctime));
113 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_DEVICE)
114 printf ("Device # : %ld\n", (gulong) info->device);
116 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_INODE)
117 printf ("Inode # : %ld\n", (gulong) info->inode);
119 if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ACCESS) {
120 printf ("Readable : %s\n",
121 (info->permissions&GNOME_VFS_PERM_ACCESS_READABLE?"YES":"NO"));
122 printf ("Writable : %s\n",
123 (info->permissions&GNOME_VFS_PERM_ACCESS_WRITABLE?"YES":"NO"));
124 printf ("Executable : %s\n",
125 (info->permissions&GNOME_VFS_PERM_ACCESS_EXECUTABLE?"YES":"NO"));
136 GnomeVFSFileInfo *info;
137 GnomeVFSURI *vfs_uri;
138 GnomeVFSResult result;
143 fprintf (stderr, "Usage: %s <uri> [<uri>...]\n", argv[0]);
147 if (!gnome_vfs_init ()) {
148 fprintf (stderr, "%s: Cannot initialize the GNOME Virtual File System.\n",
158 g_print("Getting info for \"%s\".\n", uri);
160 info = gnome_vfs_file_info_new ();
161 result = gnome_vfs_get_file_info (uri,
163 (GNOME_VFS_FILE_INFO_GET_MIME_TYPE
164 | GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS
165 | GNOME_VFS_FILE_INFO_FOLLOW_LINKS));
166 if (result != GNOME_VFS_OK) {
167 fprintf (stderr, "%s: %s: %s\n",
168 argv[0], uri, gnome_vfs_result_to_string (result));
173 print_file_info (info);
175 gnome_vfs_file_info_unref (info);
177 vfs_uri = gnome_vfs_uri_new (uri);
178 path = gnome_vfs_uri_get_path (vfs_uri);
179 printf ("Path: %s\n", path ? path : "<null>");
180 printf (gnome_vfs_uri_is_local (vfs_uri)
181 ? "File is local\n" : "File is not local\n");
182 gnome_vfs_uri_unref (vfs_uri);