1 /* GIO - GLib Input, Output and Streaming Library
3 * Copyright (C) 2006-2007 Red Hat, Inc.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Alexander Larsson <alexl@redhat.com>
27 #include "gfileattribute.h"
28 #include "gfileattribute-priv.h"
29 #include <glib-object.h>
35 * SECTION:gfileattribute
36 * @short_description: Key-Value Paired File Attributes
37 * @see_also: #GFile, #GFileInfo
39 * File attributes in GIO consist of a list of key-value pairs.
41 * Keys are strings that contain a key namespace and a key name, separated
42 * by a colon, e.g. "namespace:keyname". Namespaces are included to sort
43 * key-value pairs by namespaces for relevance. Keys can be retrived
44 * using wildcards, e.g. "std:*" will return all of the keys in the
47 * Values are stored within the list in #GFileAttributeValue structures.
48 * Values can store different types, listed in the enum #GFileAttributeType.
49 * Upon creation of a #GFileAttributeValue, the type will be set to
50 * %G_FILE_ATTRIBUTE_TYPE_INVALID.
52 * The list of possible attributes for a filesystem (pointed to by a #GFile) is
53 * availible as a #GFileAttributeInfoList. This list is queryable by key names
54 * as indicated earlier.
56 * Classes that implement #GFileIface will create a #GFileAttributeInfoList and
57 * install default keys and values for their given file system, architecture,
58 * and other possible implementation details (e.g., on a UNIX system, a file
59 * attribute key will be registered for the user id for a given file).
63 * <title>GFileAttributes Default Namespaces</title>
64 * <tgroup cols='2' align='left'><thead>
65 * <row><entry>Namspace</entry><entry>Description</entry></row>
68 * <row><entry>"std"</entry><entry>The "Standard" namespace. General file
69 * information that any application may need should be put in this namespace.
70 * Examples include the file's name, type, and size.</entry></row>
71 * <row><entry>"etag"</entry><entry>The <link linkend="gfile-etag">"Entity Tag"</link>
72 * namespace. Currently, the only key in this namespace is "value", which contains
73 * the value of the current entity tag.</entry></row>
74 * <row><entry>"id"</entry><entry>The "Identification" namespace. This
75 * namespace is used by file managers and applications that list directories
76 * to check for loops and to uniquely identify files.</entry></row>
77 * <row><entry>"access"</entry><entry>The "Access" namespace. Used to check
78 * if a user has the proper privilidges to access files and perform
79 * file operations. Keys in this namespace are made to be generic
80 * and easily understood, e.g. the "can_read" key is %TRUE if
81 * the current user has permission to read the file. UNIX permissions and
82 * NTFS ACLs in Windows should be mapped to these values.</entry></row>
83 * <row><entry>"mountable"</entry><entry>The "Mountable" namespace. Includes
84 * simple boolean keys for checking if a file or path supports mount operations, e.g.
85 * mount, unmount, eject. These are used for files of type %G_FILE_TYPE_MOUNTABLE.</entry></row>
86 * <row><entry>"time"</entry><entry>The "Time" namespace. Includes file
87 * access, changed, created times. </entry></row>
88 * <row><entry>"unix"</entry><entry>The "Unix" namespace. Includes UNIX-specific
89 * information and may not be available for all files. Examples include
90 * the UNIX "UID", "GID", etc.</entry></row>
91 * <row><entry>"dos"</entry><entry>The "DOS" namespace. Includes DOS-specific
92 * information and may not be available for all files. Examples include
93 * "is_system" for checking if a file is marked as a system file, and "is_archive"
94 * for checking if a file is marked as an archive file.</entry></row>
95 * <row><entry>"owner"</entry><entry>The "Owner" namespace. Includes information
96 * about who owns a file. May not be available for all file systems. Examples include
97 * "user" for getting the user name of the file owner. This information is often mapped from
98 * some backend specific data such as a unix UID.</entry></row>
99 * <row><entry>"thumbnail"</entry><entry>The "Thumbnail" namespace. Includes
100 * information about file thumbnails and their location within the file system. Exaples of
101 * keys in this namespace include "path" to get the location of a thumbnail, and "failed"
102 * to check if thumbnailing of the file failed.</entry></row>
103 * <row><entry>"fs"</entry><entry>The "Filesystem" namespace. Gets information
104 * about the file system where a file is located, such as its type, how much
105 * space is left available, and the overall size of the file system.</entry></row>
106 * <row><entry>"gvfs"</entry><entry>The "GVFS" namespace. Keys in this namespace
107 * contain information about the current GVFS backend in use. </entry></row>
113 * Please note that these are not all of the possible namespaces.
114 * More namespaces can be added from GIO modules or by individual applications.
115 * For more information about writing GIO modules, see #GIOModule.
117 * <!-- TODO: Implementation note about using extended attributes on supported
121 * <title>GFileAttributes Built-in Keys and Value Types</title>
122 * <tgroup cols='3' align='left'><thead>
123 * <row><entry>Enum Value</entry><entry>Namespace:Key</entry><entry>Value Type</entry></row>
125 * <row><entry>%G_FILE_ATTRIBUTE_STD_TYPE</entry><entry>std::type</entry><entry>uint32 (#GFileType)</entry></row>
126 * <row><entry>%G_FILE_ATTRIBUTE_STD_IS_HIDDEN</entry><entry>std::is-hidden</entry><entry>boolean</entry></row>
127 * <row><entry>%G_FILE_ATTRIBUTE_STD_IS_BACKUP</entry><entry>std::is-backup</entry><entry>boolean</entry></row>
128 * <row><entry>%G_FILE_ATTRIBUTE_STD_IS_SYMLINK</entry><entry>std::is-symlink</entry><entry>boolean</entry></row>
129 * <row><entry>%G_FILE_ATTRIBUTE_STD_IS_VIRTUAL</entry><entry>std::is-virtual</entry><entry>boolean</entry></row>
130 * <row><entry>%G_FILE_ATTRIBUTE_STD_NAME</entry><entry>std::name</entry><entry>byte string</entry></row>
131 * <row><entry>%G_FILE_ATTRIBUTE_STD_DISPLAY_NAME</entry><entry>std::display-name</entry><entry>string</entry></row>
132 * <row><entry>%G_FILE_ATTRIBUTE_STD_EDIT_NAME</entry><entry>std::edit-name</entry><entry>string</entry></row>
133 * <row><entry>%G_FILE_ATTRIBUTE_STD_ICON</entry><entry>std::icon</entry><entry>object (#GIcon)</entry></row>
134 * <row><entry>%G_FILE_ATTRIBUTE_STD_CONTENT_TYPE</entry><entry>std::content-type</entry><entry>string</entry></row>
135 * <row><entry>%G_FILE_ATTRIBUTE_STD_FAST_CONTENT_TYPE</entry><entry>std::fast-content-type</entry><entry>string</entry></row>
136 * <row><entry>%G_FILE_ATTRIBUTE_STD_SIZE</entry><entry>std::size</entry><entry>uint64</entry></row>
137 * <row><entry>%G_FILE_ATTRIBUTE_STD_SYMLINK_TARGET</entry><entry>std::symlink-target</entry><entry>byte string</entry></row>
138 * <row><entry>%G_FILE_ATTRIBUTE_STD_TARGET_URI</entry><entry>std::target-uri</entry><entry>string</entry></row>
139 * <row><entry>%G_FILE_ATTRIBUTE_STD_SORT_ORDER</entry><entry>std::sort-order</entry><entry>int32</entry></row>
140 * <row><entry>%G_FILE_ATTRIBUTE_ETAG_VALUE</entry><entry>etag::value</entry><entry>string</entry></row>
141 * <row><entry>%G_FILE_ATTRIBUTE_ID_FILE</entry><entry>id::file</entry><entry>string</entry></row>
142 * <row><entry>%G_FILE_ATTRIBUTE_ID_FS</entry><entry>id::fs</entry><entry>string</entry></row>
143 * <row><entry>%G_FILE_ATTRIBUTE_ACCESS_CAN_READ</entry><entry>access::can-read</entry><entry>boolean</entry></row>
144 * <row><entry>%G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE</entry><entry>access::can-write</entry><entry>boolean</entry></row>
145 * <row><entry>%G_FILE_ATTRIBUTE_ACCESS_CAN_EXECUTE</entry><entry>access::can-execute</entry><entry>boolean</entry></row>
146 * <row><entry>%G_FILE_ATTRIBUTE_ACCESS_CAN_DELETE</entry><entry>access::can-delete</entry><entry>boolean</entry></row>
147 * <row><entry>%G_FILE_ATTRIBUTE_ACCESS_CAN_TRASH</entry><entry>access::can-trash</entry><entry>boolean</entry></row>
148 * <row><entry>%G_FILE_ATTRIBUTE_ACCESS_CAN_RENAME</entry><entry>access::can-rename</entry><entry>boolean</entry></row>
149 * <row><entry>%G_FILE_ATTRIBUTE_MOUNTABLE_CAN_MOUNT</entry><entry>mountable::can-mount</entry><entry>boolean</entry></row>
150 * <row><entry>%G_FILE_ATTRIBUTE_MOUNTABLE_CAN_UNMOUNT</entry><entry>mountable::can-unmount</entry><entry>boolean</entry></row>
151 * <row><entry>%G_FILE_ATTRIBUTE_MOUNTABLE_CAN_EJECT</entry><entry>mountable::can-eject</entry><entry>boolean</entry></row>
152 * <row><entry>%G_FILE_ATTRIBUTE_MOUNTABLE_UNIX_DEVICE</entry><entry>mountable::unix-device</entry><entry>uint32</entry></row>
153 * <row><entry>%G_FILE_ATTRIBUTE_MOUNTABLE_HAL_UDI</entry><entry>mountable::hal-udi</entry><entry>string</entry></row>
154 * <row><entry>%G_FILE_ATTRIBUTE_TIME_MODIFIED</entry><entry>time::modified</entry><entry>uint64</entry></row>
155 * <row><entry>%G_FILE_ATTRIBUTE_TIME_MODIFIED_USEC</entry><entry>time::modified-usec</entry><entry>uint32</entry></row>
156 * <row><entry>%G_FILE_ATTRIBUTE_TIME_ACCESS</entry><entry>time::access</entry><entry>uint64</entry></row>
157 * <row><entry>%G_FILE_ATTRIBUTE_TIME_ACCESS_USEC</entry><entry>time::access-usec</entry><entry>uint32</entry></row>
158 * <row><entry>%G_FILE_ATTRIBUTE_TIME_CHANGED</entry><entry>time::changed</entry><entry>uint64</entry></row>
159 * <row><entry>%G_FILE_ATTRIBUTE_TIME_CHANGED_USEC</entry><entry>time::changed-usec</entry><entry>uint32</entry></row>
160 * <row><entry>%G_FILE_ATTRIBUTE_TIME_CREATED</entry><entry>time::created</entry><entry>uint64</entry></row>
161 * <row><entry>%G_FILE_ATTRIBUTE_TIME_CREATED_USEC</entry><entry>time::created-usec</entry><entry>uint32</entry></row>
162 * <row><entry>%G_FILE_ATTRIBUTE_UNIX_DEVICE</entry><entry>unix::device</entry><entry>uint32</entry></row>
163 * <row><entry>%G_FILE_ATTRIBUTE_UNIX_INODE</entry><entry>unix::inode</entry><entry>uint64</entry></row>
164 * <row><entry>%G_FILE_ATTRIBUTE_UNIX_MODE</entry><entry>unix::mode</entry><entry>uint32</entry></row>
165 * <row><entry>%G_FILE_ATTRIBUTE_UNIX_NLINK</entry><entry>unix::nlink</entry><entry>uint32</entry></row>
166 * <row><entry>%G_FILE_ATTRIBUTE_UNIX_UID</entry><entry>unix::uid</entry><entry>uint32</entry></row>
167 * <row><entry>%G_FILE_ATTRIBUTE_UNIX_GID</entry><entry>unix::gid</entry><entry>uint32</entry></row>
168 * <row><entry>%G_FILE_ATTRIBUTE_UNIX_RDEV</entry><entry>unix::rdev</entry><entry>uint32</entry></row>
169 * <row><entry>%G_FILE_ATTRIBUTE_UNIX_BLOCK_SIZE</entry><entry>unix::block-size</entry><entry>uint32</entry></row>
170 * <row><entry>%G_FILE_ATTRIBUTE_UNIX_BLOCKS</entry><entry>unix::blocks</entry><entry>uint64</entry></row>
171 * <row><entry>%G_FILE_ATTRIBUTE_UNIX_IS_MOUNTPOINT</entry><entry>unix::is-mountpoint</entry><entry>boolean</entry></row>
172 * <row><entry>%G_FILE_ATTRIBUTE_DOS_IS_ARCHIVE</entry><entry>dos::is-archive</entry><entry>boolean</entry></row>
173 * <row><entry>%G_FILE_ATTRIBUTE_DOS_IS_SYSTEM</entry><entry>dos::is-system</entry><entry>boolean</entry></row>
174 * <row><entry>%G_FILE_ATTRIBUTE_OWNER_USER</entry><entry>owner::user</entry><entry>string</entry></row>
175 * <row><entry>%G_FILE_ATTRIBUTE_OWNER_USER_REAL</entry><entry>owner::user-real</entry><entry>string</entry></row>
176 * <row><entry>%G_FILE_ATTRIBUTE_OWNER_GROUP</entry><entry>owner::group</entry><entry>string</entry></row>
177 * <row><entry>%G_FILE_ATTRIBUTE_THUMBNAIL_PATH</entry><entry>thumbnail::path</entry><entry>bytestring</entry></row>
178 * <row><entry>%G_FILE_ATTRIBUTE_THUMBNAILING_FAILED</entry><entry>thumbnail::failed</entry><entry>boolean</entry></row>
179 * <row><entry>%G_FILE_ATTRIBUTE_FS_SIZE</entry><entry>fs::size</entry><entry>uint64</entry></row>
180 * <row><entry>%G_FILE_ATTRIBUTE_FS_FREE</entry><entry>fs::free</entry><entry>uint64</entry></row>
181 * <row><entry>%G_FILE_ATTRIBUTE_FS_TYPE</entry><entry>fs::type</entry><entry>string</entry></row>
182 * <row><entry>%G_FILE_ATTRIBUTE_FS_READONLY</entry><entry>fs::readonly</entry><entry>boolean</entry></row>
183 * <row><entry>%G_FILE_ATTRIBUTE_GVFS_BACKEND</entry><entry>gvfs::backend</entry><entry>string</entry></row>
184 * </tbody></tgroup></table></para>
189 * _g_file_attribute_value_free:
190 * @attr: a #GFileAttributeValue.
192 * Frees the memory used by @attr.
196 _g_file_attribute_value_free (GFileAttributeValue *attr)
198 g_return_if_fail (attr != NULL);
200 _g_file_attribute_value_clear (attr);
205 * _g_file_attribute_value_clear:
206 * @attr: a #GFileAttributeValue.
208 * Clears the value of @attr and sets its type to
209 * %G_FILE_ATTRIBUTE_TYPE_INVALID.
213 _g_file_attribute_value_clear (GFileAttributeValue *attr)
215 g_return_if_fail (attr != NULL);
217 if (attr->type == G_FILE_ATTRIBUTE_TYPE_STRING ||
218 attr->type == G_FILE_ATTRIBUTE_TYPE_BYTE_STRING)
219 g_free (attr->u.string);
221 if (attr->type == G_FILE_ATTRIBUTE_TYPE_OBJECT &&
223 g_object_unref (attr->u.obj);
225 attr->type = G_FILE_ATTRIBUTE_TYPE_INVALID;
229 * g_file_attribute_value_set:
230 * @attr: a #GFileAttributeValue to set the value in.
231 * @new_value: a #GFileAttributeValue to get the value from.
233 * Sets an attribute's value from another attribute.
236 _g_file_attribute_value_set (GFileAttributeValue *attr,
237 const GFileAttributeValue *new_value)
239 g_return_if_fail (attr != NULL);
240 g_return_if_fail (new_value != NULL);
242 _g_file_attribute_value_clear (attr);
245 if (attr->type == G_FILE_ATTRIBUTE_TYPE_STRING ||
246 attr->type == G_FILE_ATTRIBUTE_TYPE_BYTE_STRING)
247 attr->u.string = g_strdup (attr->u.string);
249 if (attr->type == G_FILE_ATTRIBUTE_TYPE_OBJECT &&
251 g_object_ref (attr->u.obj);
255 * _g_file_attribute_value_new:
257 * Creates a new file attribute.
259 * Returns: a #GFileAttributeValue.
261 GFileAttributeValue *
262 _g_file_attribute_value_new (void)
264 GFileAttributeValue *attr;
266 attr = g_new (GFileAttributeValue, 1);
267 attr->type = G_FILE_ATTRIBUTE_TYPE_INVALID;
272 _g_file_attribute_value_peek_as_pointer (GFileAttributeValue *attr)
274 switch (attr->type) {
275 case G_FILE_ATTRIBUTE_TYPE_STRING:
276 case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING:
277 return attr->u.string;
278 case G_FILE_ATTRIBUTE_TYPE_OBJECT:
281 return (gpointer) &attr->u;
286 * g_file_attribute_value_dup:
287 * @other: a #GFileAttributeValue to duplicate.
289 * Duplicates a file attribute.
291 * Returns: a duplicate of the @other.
293 GFileAttributeValue *
294 _g_file_attribute_value_dup (const GFileAttributeValue *other)
296 GFileAttributeValue *attr;
298 g_return_val_if_fail (other != NULL, NULL);
300 attr = g_new (GFileAttributeValue, 1);
301 attr->type = G_FILE_ATTRIBUTE_TYPE_INVALID;
302 _g_file_attribute_value_set (attr, other);
309 return c >= 32 && c <= 126 && c != '\\';
313 escape_byte_string (const char *str)
317 char *escaped_val, *p;
319 char *hex_digits = "0123456789abcdef";
324 for (i = 0; i < len; i++)
326 if (!valid_char (str[i]))
330 if (num_invalid == 0)
331 return g_strdup (str);
334 escaped_val = g_malloc (len + num_invalid*3 + 1);
337 for (i = 0; i < len; i++)
346 *p++ = hex_digits[(c >> 8) & 0xf];
347 *p++ = hex_digits[c & 0xf];
356 * g_file_attribute_value_as_string:
357 * @attr: a #GFileAttributeValue.
359 * Converts a #GFileAttributeValue to a string for display.
360 * The returned string should be freed when no longer needed.
362 * Returns: a string from the @attr, %NULL on error, or "<invalid>"
363 * if @attr is of type %G_FILE_ATTRIBUTE_TYPE_INVALID.
366 _g_file_attribute_value_as_string (const GFileAttributeValue *attr)
370 g_return_val_if_fail (attr != NULL, NULL);
374 case G_FILE_ATTRIBUTE_TYPE_STRING:
375 str = g_strdup (attr->u.string);
377 case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING:
378 str = escape_byte_string (attr->u.string);
380 case G_FILE_ATTRIBUTE_TYPE_BOOLEAN:
381 str = g_strdup_printf ("%s", attr->u.boolean?"TRUE":"FALSE");
383 case G_FILE_ATTRIBUTE_TYPE_UINT32:
384 str = g_strdup_printf ("%u", (unsigned int)attr->u.uint32);
386 case G_FILE_ATTRIBUTE_TYPE_INT32:
387 str = g_strdup_printf ("%i", (int)attr->u.int32);
389 case G_FILE_ATTRIBUTE_TYPE_UINT64:
390 str = g_strdup_printf ("%"G_GUINT64_FORMAT, attr->u.uint64);
392 case G_FILE_ATTRIBUTE_TYPE_INT64:
393 str = g_strdup_printf ("%"G_GINT64_FORMAT, attr->u.int64);
395 case G_FILE_ATTRIBUTE_TYPE_OBJECT:
396 str = g_strdup_printf ("%s:%p", g_type_name_from_instance
397 ((GTypeInstance *) attr->u.obj),
401 g_warning ("Invalid type in GFileInfo attribute");
402 str = g_strdup ("<invalid>");
410 * g_file_attribute_value_get_string:
411 * @attr: a #GFileAttributeValue.
413 * Gets the string from a file attribute value. If the value is not the
414 * right type then %NULL will be returned.
416 * Returns: the string value contained within the attribute, or %NULL.
419 _g_file_attribute_value_get_string (const GFileAttributeValue *attr)
424 g_return_val_if_fail (attr->type == G_FILE_ATTRIBUTE_TYPE_STRING, NULL);
426 return attr->u.string;
430 * g_file_attribute_value_get_byte_string:
431 * @attr: a #GFileAttributeValue.
433 * Gets the byte string from a file attribute value. If the value is not the
434 * right type then %NULL will be returned.
436 * Returns: the byte string contained within the attribute or %NULL.
439 _g_file_attribute_value_get_byte_string (const GFileAttributeValue *attr)
444 g_return_val_if_fail (attr->type == G_FILE_ATTRIBUTE_TYPE_BYTE_STRING, NULL);
446 return attr->u.string;
450 * g_file_attribute_value_get_boolean:
451 * @attr: a #GFileAttributeValue.
453 * Gets the boolean value from a file attribute value. If the value is not the
454 * right type then %FALSE will be returned.
456 * Returns: the boolean value contained within the attribute, or %FALSE.
459 _g_file_attribute_value_get_boolean (const GFileAttributeValue *attr)
464 g_return_val_if_fail (attr->type == G_FILE_ATTRIBUTE_TYPE_BOOLEAN, FALSE);
466 return attr->u.boolean;
470 * g_file_attribute_value_get_uint32:
471 * @attr: a #GFileAttributeValue.
473 * Gets the unsigned 32-bit integer from a file attribute value. If the value
474 * is not the right type then %0 will be returned.
476 * Returns: the unsigned 32-bit integer from the attribute, or %0.
479 _g_file_attribute_value_get_uint32 (const GFileAttributeValue *attr)
484 g_return_val_if_fail (attr->type == G_FILE_ATTRIBUTE_TYPE_UINT32, 0);
486 return attr->u.uint32;
490 * g_file_attribute_value_get_int32:
491 * @attr: a #GFileAttributeValue.
493 * Gets the signed 32-bit integer from a file attribute value. If the value
494 * is not the right type then %0 will be returned.
496 * Returns: the signed 32-bit integer from the attribute, or %0.
499 _g_file_attribute_value_get_int32 (const GFileAttributeValue *attr)
504 g_return_val_if_fail (attr->type == G_FILE_ATTRIBUTE_TYPE_INT32, 0);
506 return attr->u.int32;
510 * g_file_attribute_value_get_uint64:
511 * @attr: a #GFileAttributeValue.
513 * Gets the unsigned 64-bit integer from a file attribute value. If the value
514 * is not the right type then %0 will be returned.
516 * Returns: the unsigned 64-bit integer from the attribute, or %0.
519 _g_file_attribute_value_get_uint64 (const GFileAttributeValue *attr)
524 g_return_val_if_fail (attr->type == G_FILE_ATTRIBUTE_TYPE_UINT64, 0);
526 return attr->u.uint64;
530 * g_file_attribute_value_get_int64:
531 * @attr: a #GFileAttributeValue.
533 * Gets the signed 64-bit integer from a file attribute value. If the value
534 * is not the right type then %0 will be returned.
536 * Returns: the signed 64-bit integer from the attribute, or %0.
539 _g_file_attribute_value_get_int64 (const GFileAttributeValue *attr)
544 g_return_val_if_fail (attr->type == G_FILE_ATTRIBUTE_TYPE_INT64, 0);
546 return attr->u.int64;
550 * g_file_attribute_value_get_object:
551 * @attr: a #GFileAttributeValue.
553 * Gets the GObject from a file attribute value. If the value
554 * is not the right type then %NULL will be returned.
556 * Returns: the GObject from the attribute, or %0.
559 _g_file_attribute_value_get_object (const GFileAttributeValue *attr)
564 g_return_val_if_fail (attr->type == G_FILE_ATTRIBUTE_TYPE_OBJECT, NULL);
571 _g_file_attribute_value_set_from_pointer (GFileAttributeValue *value,
572 GFileAttributeType type,
576 _g_file_attribute_value_clear (value);
580 case G_FILE_ATTRIBUTE_TYPE_STRING:
581 case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING:
583 value->u.string = g_strdup (value_p);
585 value->u.string = value_p;
588 case G_FILE_ATTRIBUTE_TYPE_OBJECT:
590 value->u.obj = g_object_ref (value_p);
592 value->u.obj = value_p;
595 case G_FILE_ATTRIBUTE_TYPE_BOOLEAN:
596 value->u.boolean = *(gboolean *)value_p;
599 case G_FILE_ATTRIBUTE_TYPE_UINT32:
600 value->u.uint32 = *(guint32 *)value_p;
603 case G_FILE_ATTRIBUTE_TYPE_INT32:
604 value->u.int32 = *(gint32 *)value_p;
607 case G_FILE_ATTRIBUTE_TYPE_UINT64:
608 value->u.uint64 = *(guint64 *)value_p;
611 case G_FILE_ATTRIBUTE_TYPE_INT64:
612 value->u.int64 = *(gint64 *)value_p;
615 g_warning ("Unknown type specified in g_file_info_set_attribute\n");
621 * g_file_attribute_value_set_string:
622 * @attr: a #GFileAttributeValue.
623 * @string: a string to set within the type.
625 * Sets the attribute value to a given string.
629 _g_file_attribute_value_set_string (GFileAttributeValue *attr,
632 g_return_if_fail (attr != NULL);
633 g_return_if_fail (string != NULL);
635 _g_file_attribute_value_clear (attr);
636 attr->type = G_FILE_ATTRIBUTE_TYPE_STRING;
637 attr->u.string = g_strdup (string);
641 * g_file_attribute_value_set_byte_string:
642 * @attr: a #GFileAttributeValue.
643 * @string: a byte string to set within the type.
645 * Sets the attribute value to a given byte string.
649 _g_file_attribute_value_set_byte_string (GFileAttributeValue *attr,
652 g_return_if_fail (attr != NULL);
653 g_return_if_fail (string != NULL);
655 _g_file_attribute_value_clear (attr);
656 attr->type = G_FILE_ATTRIBUTE_TYPE_BYTE_STRING;
657 attr->u.string = g_strdup (string);
661 * g_file_attribute_value_set_boolean:
662 * @attr: a #GFileAttributeValue.
663 * @value: a #gboolean to set within the type.
665 * Sets the attribute value to the given boolean value.
669 _g_file_attribute_value_set_boolean (GFileAttributeValue *attr,
672 g_return_if_fail (attr != NULL);
674 _g_file_attribute_value_clear (attr);
675 attr->type = G_FILE_ATTRIBUTE_TYPE_BOOLEAN;
676 attr->u.boolean = !!value;
680 * g_file_attribute_value_set_uint32:
681 * @attr: a #GFileAttributeValue.
682 * @value: a #guint32 to set within the type.
684 * Sets the attribute value to the given unsigned 32-bit integer.
688 _g_file_attribute_value_set_uint32 (GFileAttributeValue *attr,
691 g_return_if_fail (attr != NULL);
693 _g_file_attribute_value_clear (attr);
694 attr->type = G_FILE_ATTRIBUTE_TYPE_UINT32;
695 attr->u.uint32 = value;
699 * g_file_attribute_value_set_int32:
700 * @attr: a #GFileAttributeValue.
701 * @value: a #gint32 to set within the type.
703 * Sets the attribute value to the given signed 32-bit integer.
707 _g_file_attribute_value_set_int32 (GFileAttributeValue *attr,
710 g_return_if_fail (attr != NULL);
712 _g_file_attribute_value_clear (attr);
713 attr->type = G_FILE_ATTRIBUTE_TYPE_INT32;
714 attr->u.int32 = value;
718 * g_file_attribute_value_set_uint64:
719 * @attr: a #GFileAttributeValue.
720 * @value: a #guint64 to set within the type.
722 * Sets the attribute value to a given unsigned 64-bit integer.
726 _g_file_attribute_value_set_uint64 (GFileAttributeValue *attr,
729 g_return_if_fail (attr != NULL);
731 _g_file_attribute_value_clear (attr);
732 attr->type = G_FILE_ATTRIBUTE_TYPE_UINT64;
733 attr->u.uint64 = value;
737 * g_file_attribute_value_set_int64:
738 * @attr: a #GFileAttributeValue.
739 * @value: a #gint64 to set within the type.
741 * Sets the attribute value to a given signed 64-bit integer.
745 _g_file_attribute_value_set_int64 (GFileAttributeValue *attr,
748 g_return_if_fail (attr != NULL);
750 _g_file_attribute_value_clear (attr);
751 attr->type = G_FILE_ATTRIBUTE_TYPE_INT64;
752 attr->u.int64 = value;
756 * g_file_attribute_value_set_object:
757 * @attr: a #GFileAttributeValue.
760 * Sets the attribute to contain the value @obj.
761 * The @attr references the GObject internally.
765 _g_file_attribute_value_set_object (GFileAttributeValue *attr,
768 g_return_if_fail (attr != NULL);
769 g_return_if_fail (obj != NULL);
771 _g_file_attribute_value_clear (attr);
772 attr->type = G_FILE_ATTRIBUTE_TYPE_OBJECT;
773 attr->u.obj = g_object_ref (obj);
777 GFileAttributeInfoList public;
780 } GFileAttributeInfoListPriv;
783 list_update_public (GFileAttributeInfoListPriv *priv)
785 priv->public.infos = (GFileAttributeInfo *)priv->array->data;
786 priv->public.n_infos = priv->array->len;
790 * g_file_attribute_info_list_new:
792 * Creates a new file attribute info list.
794 * Returns: a #GFileAttributeInfoList.
796 GFileAttributeInfoList *
797 g_file_attribute_info_list_new (void)
799 GFileAttributeInfoListPriv *priv;
801 priv = g_new0 (GFileAttributeInfoListPriv, 1);
804 priv->array = g_array_new (TRUE, FALSE, sizeof (GFileAttributeInfo));
806 list_update_public (priv);
808 return (GFileAttributeInfoList *)priv;
812 * g_file_attribute_info_list_dup:
813 * @list: a #GFileAttributeInfoList to duplicate.
815 * Makes a duplicate of a file attribute info list.
817 * Returns: a copy of the given @list.
819 GFileAttributeInfoList *
820 g_file_attribute_info_list_dup (GFileAttributeInfoList *list)
822 GFileAttributeInfoListPriv *new;
825 g_return_val_if_fail (list != NULL, NULL);
827 new = g_new0 (GFileAttributeInfoListPriv, 1);
829 new->array = g_array_new (TRUE, FALSE, sizeof (GFileAttributeInfo));
831 g_array_set_size (new->array, list->n_infos);
832 list_update_public (new);
833 for (i = 0; i < list->n_infos; i++)
835 new->public.infos[i].name = g_strdup (list->infos[i].name);
836 new->public.infos[i].type = list->infos[i].type;
837 new->public.infos[i].flags = list->infos[i].flags;
840 return (GFileAttributeInfoList *)new;
844 * g_file_attribute_info_list_ref:
845 * @list: a #GFileAttributeInfoList to reference.
847 * References a file attribute info list.
849 * Returns: #GFileAttributeInfoList or %NULL on error.
851 GFileAttributeInfoList *
852 g_file_attribute_info_list_ref (GFileAttributeInfoList *list)
854 GFileAttributeInfoListPriv *priv = (GFileAttributeInfoListPriv *)list;
856 g_return_val_if_fail (list != NULL, NULL);
857 g_return_val_if_fail (priv->ref_count > 0, NULL);
859 g_atomic_int_inc (&priv->ref_count);
865 * g_file_attribute_info_list_unref:
866 * @list: The #GFileAttributeInfoList to unreference.
868 * Removes a reference from the given @list. If the reference count
869 * falls to zero, the @list is deleted.
872 g_file_attribute_info_list_unref (GFileAttributeInfoList *list)
874 GFileAttributeInfoListPriv *priv = (GFileAttributeInfoListPriv *)list;
877 g_return_if_fail (list != NULL);
878 g_return_if_fail (priv->ref_count > 0);
880 if (g_atomic_int_dec_and_test (&priv->ref_count))
882 for (i = 0; i < list->n_infos; i++)
883 g_free (list->infos[i].name);
884 g_array_free (priv->array, TRUE);
889 g_file_attribute_info_list_bsearch (GFileAttributeInfoList *list,
899 mid = start + (end - start) / 2;
901 if (strcmp (name, list->infos[mid].name) < 0)
903 else if (strcmp (name, list->infos[mid].name) > 0)
912 * g_file_attribute_info_list_lookup:
913 * @list: a #GFileAttributeInfoList.
914 * @name: the name of the attribute to lookup.
916 * Gets the file attribute with the name @name from @list.
918 * Returns: a #GFileAttributeInfo for the @name, or %NULL if an
919 * attribute isn't found.
921 const GFileAttributeInfo *
922 g_file_attribute_info_list_lookup (GFileAttributeInfoList *list,
927 g_return_val_if_fail (list != NULL, NULL);
928 g_return_val_if_fail (name != NULL, NULL);
930 i = g_file_attribute_info_list_bsearch (list, name);
932 if (i < list->n_infos && strcmp (list->infos[i].name, name) == 0)
933 return &list->infos[i];
939 * g_file_attribute_info_list_add:
940 * @list: a #GFileAttributeInfoList.
941 * @name: the name of the attribute to add.
942 * @type: the #GFileAttributeType for the attribute.
943 * @flags: #GFileAttributeInfoFlags for the attribute.
945 * Adds a new attribute with @name to the @list, setting
946 * its @type and @flags.
949 g_file_attribute_info_list_add (GFileAttributeInfoList *list,
951 GFileAttributeType type,
952 GFileAttributeInfoFlags flags)
954 GFileAttributeInfoListPriv *priv = (GFileAttributeInfoListPriv *)list;
955 GFileAttributeInfo info;
958 g_return_if_fail (list != NULL);
959 g_return_if_fail (name != NULL);
961 i = g_file_attribute_info_list_bsearch (list, name);
963 if (i < list->n_infos && strcmp (list->infos[i].name, name) == 0)
965 list->infos[i].type = type;
969 info.name = g_strdup (name);
972 g_array_insert_vals (priv->array, i, &info, 1);
974 list_update_public (priv);
977 #define __G_FILE_ATTRIBUTE_C__
978 #include "gioaliasdef.c"