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. |
---|
4 | |
---|
5 | Copyright (C) 1999 Free Software Foundation |
---|
6 | |
---|
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. |
---|
11 | |
---|
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. |
---|
16 | |
---|
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. |
---|
21 | |
---|
22 | Author: Ettore Perazzoli <ettore@comm2000.it> */ |
---|
23 | |
---|
24 | |
---|
25 | #include <config.h> |
---|
26 | |
---|
27 | #include <glib/gmessages.h> |
---|
28 | #include <libgnomevfs/gnome-vfs-init.h> |
---|
29 | #include <libgnomevfs/gnome-vfs-ops.h> |
---|
30 | #include <stdio.h> |
---|
31 | #include <time.h> |
---|
32 | |
---|
33 | static const gchar * |
---|
34 | type_to_string (GnomeVFSFileType type) |
---|
35 | { |
---|
36 | switch (type) { |
---|
37 | case GNOME_VFS_FILE_TYPE_UNKNOWN: |
---|
38 | return "Unknown"; |
---|
39 | case GNOME_VFS_FILE_TYPE_REGULAR: |
---|
40 | return "Regular"; |
---|
41 | case GNOME_VFS_FILE_TYPE_DIRECTORY: |
---|
42 | return "Directory"; |
---|
43 | case GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK: |
---|
44 | return "Symbolic Link"; |
---|
45 | case GNOME_VFS_FILE_TYPE_FIFO: |
---|
46 | return "FIFO"; |
---|
47 | case GNOME_VFS_FILE_TYPE_SOCKET: |
---|
48 | return "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"; |
---|
53 | default: |
---|
54 | return "???"; |
---|
55 | } |
---|
56 | } |
---|
57 | |
---|
58 | |
---|
59 | static void |
---|
60 | print_file_info (const GnomeVFSFileInfo *info) |
---|
61 | { |
---|
62 | #define FLAG_STRING(info, which) \ |
---|
63 | (GNOME_VFS_FILE_INFO_##which (info) ? "YES" : "NO") |
---|
64 | |
---|
65 | printf ("Name : %s\n", info->name); |
---|
66 | |
---|
67 | if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_TYPE) |
---|
68 | printf ("Type : %s\n", type_to_string (info->type)); |
---|
69 | |
---|
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); |
---|
72 | |
---|
73 | if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE) |
---|
74 | printf ("MIME type : %s\n", info->mime_type); |
---|
75 | |
---|
76 | if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_SIZE) |
---|
77 | printf ("Size : %" GNOME_VFS_SIZE_FORMAT_STR "\n", |
---|
78 | info->size); |
---|
79 | |
---|
80 | if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT) |
---|
81 | printf ("Blocks : %" GNOME_VFS_SIZE_FORMAT_STR "\n", |
---|
82 | info->block_count); |
---|
83 | |
---|
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); |
---|
86 | |
---|
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)); |
---|
92 | } |
---|
93 | |
---|
94 | if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS) |
---|
95 | printf ("Permissions : %04o\n", info->permissions); |
---|
96 | |
---|
97 | |
---|
98 | if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT) |
---|
99 | printf ("Link count : %d\n", info->link_count); |
---|
100 | |
---|
101 | printf ("UID : %d\n", info->uid); |
---|
102 | printf ("GID : %d\n", info->gid); |
---|
103 | |
---|
104 | if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_ATIME) |
---|
105 | printf ("Access time : %s", ctime (&info->atime)); |
---|
106 | |
---|
107 | if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_MTIME) |
---|
108 | printf ("Modification time : %s", ctime (&info->mtime)); |
---|
109 | |
---|
110 | if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_CTIME) |
---|
111 | printf ("Change time : %s", ctime (&info->ctime)); |
---|
112 | |
---|
113 | if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_DEVICE) |
---|
114 | printf ("Device # : %ld\n", (gulong) info->device); |
---|
115 | |
---|
116 | if(info->valid_fields&GNOME_VFS_FILE_INFO_FIELDS_INODE) |
---|
117 | printf ("Inode # : %ld\n", (gulong) info->inode); |
---|
118 | |
---|
119 | |
---|
120 | #undef FLAG_STRING |
---|
121 | } |
---|
122 | |
---|
123 | int |
---|
124 | main (int argc, |
---|
125 | char **argv) |
---|
126 | { |
---|
127 | GnomeVFSFileInfo *info; |
---|
128 | GnomeVFSURI *vfs_uri; |
---|
129 | GnomeVFSResult result; |
---|
130 | gchar *uri; |
---|
131 | int i=1; |
---|
132 | |
---|
133 | if (argc < 2) { |
---|
134 | fprintf (stderr, "Usage: %s <uri> [<uri>...]\n", argv[0]); |
---|
135 | return 1; |
---|
136 | } |
---|
137 | |
---|
138 | if (!gnome_vfs_init ()) { |
---|
139 | fprintf (stderr, "%s: Cannot initialize the GNOME Virtual File System.\n", |
---|
140 | argv[0]); |
---|
141 | return 1; |
---|
142 | } |
---|
143 | |
---|
144 | while (i < argc) { |
---|
145 | |
---|
146 | uri = argv[i]; |
---|
147 | |
---|
148 | g_print("Getting info for \"%s\".\n", uri); |
---|
149 | |
---|
150 | info = gnome_vfs_file_info_new (); |
---|
151 | result = gnome_vfs_get_file_info (uri, |
---|
152 | info, |
---|
153 | (GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
---|
154 | | GNOME_VFS_FILE_INFO_FOLLOW_LINKS)); |
---|
155 | if (result != GNOME_VFS_OK) { |
---|
156 | fprintf (stderr, "%s: %s: %s\n", |
---|
157 | argv[0], uri, gnome_vfs_result_to_string (result)); |
---|
158 | i++; |
---|
159 | return result; |
---|
160 | } |
---|
161 | |
---|
162 | print_file_info (info); |
---|
163 | |
---|
164 | gnome_vfs_file_info_unref (info); |
---|
165 | |
---|
166 | vfs_uri = gnome_vfs_uri_new (uri); |
---|
167 | printf (gnome_vfs_uri_is_local (vfs_uri) |
---|
168 | ? "File is local\n" : "File is not local\n"); |
---|
169 | gnome_vfs_uri_unref (vfs_uri); |
---|
170 | |
---|
171 | i++; |
---|
172 | } |
---|
173 | |
---|
174 | return 0; |
---|
175 | } |
---|