1 | /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ |
---|
2 | /* gnome-vfs-file-info.h - Handling of file information for the GNOME |
---|
3 | Virtual File System. |
---|
4 | |
---|
5 | Copyright (C) 1999,2001 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 | Seth Nickell <snickell@stanford.edu> |
---|
24 | */ |
---|
25 | |
---|
26 | #ifndef GNOME_VFS_FILE_INFO_H |
---|
27 | #define GNOME_VFS_FILE_INFO_H |
---|
28 | |
---|
29 | #include <libgnomevfs/gnome-vfs-file-size.h> |
---|
30 | #include <libgnomevfs/gnome-vfs-result.h> |
---|
31 | #include <libgnomevfs/gnome-vfs-uri.h> |
---|
32 | #include <sys/stat.h> |
---|
33 | #include <sys/types.h> |
---|
34 | |
---|
35 | /* File flags. */ |
---|
36 | typedef enum { |
---|
37 | GNOME_VFS_FILE_FLAGS_NONE = 0, |
---|
38 | /* Whether the file is a symlink. */ |
---|
39 | GNOME_VFS_FILE_FLAGS_SYMLINK = 1 << 0, |
---|
40 | /* Whether the file is on a local file system. */ |
---|
41 | GNOME_VFS_FILE_FLAGS_LOCAL = 1 << 1, |
---|
42 | } GnomeVFSFileFlags; |
---|
43 | |
---|
44 | /* Flags indicating what fields in a GnomeVFSFileInfo struct are valid. |
---|
45 | Name is always assumed valid (how else would you have gotten a |
---|
46 | FileInfo struct otherwise?) |
---|
47 | */ |
---|
48 | |
---|
49 | /* The file type. */ |
---|
50 | typedef enum { |
---|
51 | GNOME_VFS_FILE_TYPE_UNKNOWN, |
---|
52 | GNOME_VFS_FILE_TYPE_REGULAR, |
---|
53 | GNOME_VFS_FILE_TYPE_DIRECTORY, |
---|
54 | GNOME_VFS_FILE_TYPE_FIFO, |
---|
55 | GNOME_VFS_FILE_TYPE_SOCKET, |
---|
56 | GNOME_VFS_FILE_TYPE_CHARACTER_DEVICE, |
---|
57 | GNOME_VFS_FILE_TYPE_BLOCK_DEVICE, |
---|
58 | GNOME_VFS_FILE_TYPE_SYMBOLIC_LINK |
---|
59 | } GnomeVFSFileType; |
---|
60 | |
---|
61 | typedef enum { |
---|
62 | GNOME_VFS_FILE_INFO_FIELDS_NONE = 0, |
---|
63 | GNOME_VFS_FILE_INFO_FIELDS_TYPE = 1 << 0, |
---|
64 | GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS = 1 << 1, |
---|
65 | GNOME_VFS_FILE_INFO_FIELDS_FLAGS = 1 << 2, |
---|
66 | GNOME_VFS_FILE_INFO_FIELDS_DEVICE = 1 << 3, |
---|
67 | GNOME_VFS_FILE_INFO_FIELDS_INODE = 1 << 4, |
---|
68 | GNOME_VFS_FILE_INFO_FIELDS_LINK_COUNT = 1 << 5, |
---|
69 | GNOME_VFS_FILE_INFO_FIELDS_SIZE = 1 << 6, |
---|
70 | GNOME_VFS_FILE_INFO_FIELDS_BLOCK_COUNT = 1 << 7, |
---|
71 | GNOME_VFS_FILE_INFO_FIELDS_IO_BLOCK_SIZE = 1 << 8, |
---|
72 | GNOME_VFS_FILE_INFO_FIELDS_ATIME = 1 << 9, |
---|
73 | GNOME_VFS_FILE_INFO_FIELDS_MTIME = 1 << 10, |
---|
74 | GNOME_VFS_FILE_INFO_FIELDS_CTIME = 1 << 11, |
---|
75 | GNOME_VFS_FILE_INFO_FIELDS_SYMLINK_NAME = 1 << 12, |
---|
76 | GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE = 1 << 13 |
---|
77 | } GnomeVFSFileInfoFields; |
---|
78 | |
---|
79 | /* File permissions. These are the same as the Unix ones, but we wrap them |
---|
80 | into a nicer VFS-like enum. */ |
---|
81 | /* FIXME: It's silly to use the symbolic constants for POSIX here. |
---|
82 | * This is supposed to be a virtual file system, so it makes no |
---|
83 | * sense to use the values of the POSIX-required constants on the |
---|
84 | * particular machine this code is compiled on. These should all be changed |
---|
85 | * to use numeric constants like GNOME_VFS_PERM_STICKY does now. However, |
---|
86 | * be careful in making such a change, since some existing code might |
---|
87 | * wrongly assume these equivalencies. |
---|
88 | */ |
---|
89 | typedef enum { |
---|
90 | GNOME_VFS_PERM_SUID = S_ISUID, |
---|
91 | GNOME_VFS_PERM_SGID = S_ISGID, |
---|
92 | GNOME_VFS_PERM_STICKY = 01000, /* S_ISVTX not defined on all systems */ |
---|
93 | GNOME_VFS_PERM_USER_READ = S_IRUSR, |
---|
94 | GNOME_VFS_PERM_USER_WRITE = S_IWUSR, |
---|
95 | GNOME_VFS_PERM_USER_EXEC = S_IXUSR, |
---|
96 | GNOME_VFS_PERM_USER_ALL = S_IRUSR | S_IWUSR | S_IXUSR, |
---|
97 | GNOME_VFS_PERM_GROUP_READ = S_IRGRP, |
---|
98 | GNOME_VFS_PERM_GROUP_WRITE = S_IWGRP, |
---|
99 | GNOME_VFS_PERM_GROUP_EXEC = S_IXGRP, |
---|
100 | GNOME_VFS_PERM_GROUP_ALL = S_IRGRP | S_IWGRP | S_IXGRP, |
---|
101 | GNOME_VFS_PERM_OTHER_READ = S_IROTH, |
---|
102 | GNOME_VFS_PERM_OTHER_WRITE = S_IWOTH, |
---|
103 | GNOME_VFS_PERM_OTHER_EXEC = S_IXOTH, |
---|
104 | GNOME_VFS_PERM_OTHER_ALL = S_IROTH | S_IWOTH | S_IXOTH |
---|
105 | } GnomeVFSFilePermissions; |
---|
106 | |
---|
107 | |
---|
108 | typedef struct { |
---|
109 | /* Base name of the file (no path). */ |
---|
110 | gchar *name; |
---|
111 | |
---|
112 | /* Fields which are actually valid in this strcture. */ |
---|
113 | GnomeVFSFileInfoFields valid_fields; |
---|
114 | |
---|
115 | /* File type (i.e. regular, directory, block device...). */ |
---|
116 | GnomeVFSFileType type; |
---|
117 | |
---|
118 | /* File permissions. */ |
---|
119 | GnomeVFSFilePermissions permissions; |
---|
120 | |
---|
121 | /* Flags for this file. */ |
---|
122 | GnomeVFSFileFlags flags; |
---|
123 | |
---|
124 | /* This is only valid if `is_local' is TRUE (see below). */ |
---|
125 | dev_t device; |
---|
126 | guint inode; |
---|
127 | |
---|
128 | /* Link count. */ |
---|
129 | guint link_count; |
---|
130 | |
---|
131 | /* UID, GID. */ |
---|
132 | guint uid; |
---|
133 | guint gid; |
---|
134 | |
---|
135 | /* Size in bytes. */ |
---|
136 | GnomeVFSFileSize size; |
---|
137 | |
---|
138 | /* Size measured in units of 512-byte blocks. */ |
---|
139 | GnomeVFSFileSize block_count; |
---|
140 | |
---|
141 | /* Optimal buffer size for reading/writing the file. */ |
---|
142 | guint io_block_size; |
---|
143 | |
---|
144 | /* Access, modification and change times. */ |
---|
145 | time_t atime; |
---|
146 | time_t mtime; |
---|
147 | time_t ctime; |
---|
148 | |
---|
149 | /* If the file is a symlink (see `flags'), this specifies the file the |
---|
150 | link points to. */ |
---|
151 | gchar *symlink_name; |
---|
152 | |
---|
153 | /* MIME type. */ |
---|
154 | gchar *mime_type; |
---|
155 | |
---|
156 | guint refcount; |
---|
157 | } GnomeVFSFileInfo; |
---|
158 | |
---|
159 | typedef enum { |
---|
160 | GNOME_VFS_FILE_INFO_DEFAULT = 0, /* FIXME bugzilla.eazel.com 1203: name sucks */ |
---|
161 | GNOME_VFS_FILE_INFO_GET_MIME_TYPE = 1 << 0, |
---|
162 | GNOME_VFS_FILE_INFO_FORCE_FAST_MIME_TYPE = 1 << 1, |
---|
163 | GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE = 1 << 2, |
---|
164 | GNOME_VFS_FILE_INFO_FOLLOW_LINKS = 1 << 3 |
---|
165 | } GnomeVFSFileInfoOptions; |
---|
166 | |
---|
167 | typedef enum { |
---|
168 | GNOME_VFS_SET_FILE_INFO_NONE = 0, |
---|
169 | GNOME_VFS_SET_FILE_INFO_NAME = 1 << 0, |
---|
170 | GNOME_VFS_SET_FILE_INFO_PERMISSIONS = 1 << 1, |
---|
171 | GNOME_VFS_SET_FILE_INFO_OWNER = 1 << 2, |
---|
172 | GNOME_VFS_SET_FILE_INFO_TIME = 1 << 3 |
---|
173 | } GnomeVFSSetFileInfoMask; |
---|
174 | |
---|
175 | typedef struct { |
---|
176 | GnomeVFSURI *uri; |
---|
177 | GnomeVFSResult result; |
---|
178 | GnomeVFSFileInfo *file_info; |
---|
179 | } GnomeVFSGetFileInfoResult; |
---|
180 | |
---|
181 | #define GNOME_VFS_FILE_INFO_SYMLINK(info) \ |
---|
182 | ((info)->flags & GNOME_VFS_FILE_FLAGS_SYMLINK) |
---|
183 | |
---|
184 | #define GNOME_VFS_FILE_INFO_SET_SYMLINK(info, value) \ |
---|
185 | (value ? ((info)->flags |= GNOME_VFS_FILE_FLAGS_SYMLINK) \ |
---|
186 | : ((info)->flags &= ~GNOME_VFS_FILE_FLAGS_SYMLINK)) |
---|
187 | |
---|
188 | #define GNOME_VFS_FILE_INFO_LOCAL(info) \ |
---|
189 | ((info)->flags & GNOME_VFS_FILE_FLAGS_LOCAL) |
---|
190 | |
---|
191 | #define GNOME_VFS_FILE_INFO_SET_LOCAL(info, value) \ |
---|
192 | (value ? ((info)->flags |= GNOME_VFS_FILE_FLAGS_LOCAL) \ |
---|
193 | : ((info)->flags &= ~GNOME_VFS_FILE_FLAGS_LOCAL)) |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | #define GNOME_VFS_FILE_INFO_SUID(info) \ |
---|
198 | ((info)->permissions & GNOME_VFS_PERM_SUID) |
---|
199 | |
---|
200 | #define GNOME_VFS_FILE_INFO_SGID(info) \ |
---|
201 | ((info)->permissions & GNOME_VFS_PERM_SGID) |
---|
202 | |
---|
203 | #define GNOME_VFS_FILE_INFO_STICKY(info) \ |
---|
204 | ((info)->permissions & GNOME_VFS_PERM_STICKY) |
---|
205 | |
---|
206 | |
---|
207 | #define GNOME_VFS_FILE_INFO_SET_SUID(info, value) \ |
---|
208 | (value ? ((info)->permissions |= GNOME_VFS_PERM_SUID) \ |
---|
209 | : ((info)->permissions &= ~GNOME_VFS_PERM_SUID)) |
---|
210 | |
---|
211 | #define GNOME_VFS_FILE_INFO_SET_SGID(info, value) \ |
---|
212 | (value ? ((info)->permissions |= GNOME_VFS_PERM_SGID) \ |
---|
213 | : ((info)->permissions &= ~GNOME_VFS_PERM_SGID)) |
---|
214 | |
---|
215 | #define GNOME_VFS_FILE_INFO_SET_STICKY(info, value) \ |
---|
216 | (value ? ((info)->permissions |= GNOME_VFS_PERM_STICKY) \ |
---|
217 | : ((info)->permissions &= ~GNOME_VFS_PERM_STICKY)) |
---|
218 | |
---|
219 | |
---|
220 | GnomeVFSFileInfo * |
---|
221 | gnome_vfs_file_info_new (void); |
---|
222 | void gnome_vfs_file_info_unref (GnomeVFSFileInfo *info); |
---|
223 | void gnome_vfs_file_info_ref (GnomeVFSFileInfo *info); |
---|
224 | void gnome_vfs_file_info_clear (GnomeVFSFileInfo *info); |
---|
225 | const gchar *gnome_vfs_file_info_get_mime_type |
---|
226 | (GnomeVFSFileInfo *info); |
---|
227 | |
---|
228 | void gnome_vfs_file_info_copy (GnomeVFSFileInfo *dest, |
---|
229 | const GnomeVFSFileInfo *src); |
---|
230 | |
---|
231 | GnomeVFSFileInfo * |
---|
232 | gnome_vfs_file_info_dup (const GnomeVFSFileInfo *orig); |
---|
233 | |
---|
234 | |
---|
235 | gboolean gnome_vfs_file_info_matches (const GnomeVFSFileInfo *a, |
---|
236 | const GnomeVFSFileInfo *b); |
---|
237 | |
---|
238 | GList *gnome_vfs_file_info_list_ref (GList *list); |
---|
239 | GList *gnome_vfs_file_info_list_unref (GList *list); |
---|
240 | GList *gnome_vfs_file_info_list_copy (GList *list); |
---|
241 | void gnome_vfs_file_info_list_free (GList *list); |
---|
242 | |
---|
243 | #endif /* GNOME_VFS_FILE_INFO_H */ |
---|