18c2aff776a775d34a4c9893a4c72e0434d68e36artem/***************************************************************************
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * CVSID: $Id$
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * util.c - Various utilities
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Copyright (C) 2004 David Zeuthen, <david@fubar.dk>
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Licensed under the Academic Free License version 2.1
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This program is free software; you can redistribute it and/or modify
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * it under the terms of the GNU General Public License as published by
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the Free Software Foundation; either version 2 of the License, or
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * (at your option) any later version.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * This program is distributed in the hope that it will be useful,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * but WITHOUT ANY WARRANTY; without even the implied warranty of
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * GNU General Public License for more details.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * You should have received a copy of the GNU General Public License
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * along with this program; if not, write to the Free Software
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18c2aff776a775d34a4c9893a4c72e0434d68e36artem **************************************************************************/
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China/** Determine whether the given character is valid as the first character
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China * in a name.
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China#define VALID_INITIAL_NAME_CHARACTER(c) \
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China (((c) >= 'A' && (c) <= 'Z') || \
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China ((c) >= 'a' && (c) <= 'z') || \
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China ((c) == '_'))
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China/** Determine whether the given character is valid as a second or later
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China * character in a name.
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China#define VALID_NAME_CHARACTER(c) \
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China (((c) >= '0' && (c) <= '9') || \
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China ((c) >= 'A' && (c) <= 'Z') || \
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China ((c) >= 'a' && (c) <= 'z') || \
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China ((c) == '_'))
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (c == NULL) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Given a path, /foo/bar/bat/foobar, return the last element, e.g.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param path Path
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @return Pointer into given string
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if ((*p) == '/')
18c2aff776a775d34a4c9893a4c72e0434d68e36artem return p + 1;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Given a path, this functions finds the path representing the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * parent directory by truncation.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param path Path
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @return Path for parent or NULL. Must be freed by caller
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* Find parent device by truncating our own path */
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_get_normalized_path (const gchar *path1, const gchar *path2)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem while (p2 < path2 + len2 && strncmp (p2, "../", 3) == 0) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_ERROR (("Could not normalize '%s' and '%s', return 'NULL'", path1, path2));
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_get_int_from_file (const gchar *directory, const gchar *file, gint *result, gint base)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_snprintf (path, sizeof (path), "%s/%s", directory, file);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (f == NULL) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* TODO: handle error condition */
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_set_int_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file, gint base)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_util_get_int_from_file (directory, file, &value, base))
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_get_uint64_from_file (const gchar *directory, const gchar *file, guint64 *result, gint base)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_snprintf (path, sizeof (path), "%s/%s", directory, file);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (f == NULL) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* TODO: handle error condition */
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_set_uint64_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file, gint base)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_util_get_uint64_from_file (directory, file, &value, base))
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_get_bcd2_from_file (const gchar *directory, const gchar *file, gint *result)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_snprintf (path, sizeof (path), "%s/%s", directory, file);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (f == NULL) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (; i < len; i++) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * of precision */
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_set_bcd2_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (hal_util_get_bcd2_from_file (directory, file, &value))
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_get_string_from_file (const gchar *directory, const gchar *file)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem g_snprintf (path, sizeof (path), "%s/%s", directory, file);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (f == NULL) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* Clear remaining whitespace */
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_set_string_from_file (HalDevice *d, const gchar *key, const gchar *directory, const gchar *file)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if ((buf = hal_util_get_string_from_file (directory, file)) != NULL)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_compute_udi (HalDeviceStore *store, gchar *dst, gsize dstsize, const gchar *format, ...)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem "abcdefghijklmnopqrstuvwxyz"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (i = 0; ; i++) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Given a directory and filename, open the file and search for the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * first line that starts with the given linestart string. Returns
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the rest of the line as a string if found.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param directory Directory, e.g. "/proc/acpi/battery/BAT0"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param file File, e.g. "info"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param linestart Start of line, e.g. "serial number"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param reuse Whether we should reuse the file contents
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * if the file is the same; can be cleared
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * with hal_util_grep_discard_existing_data()
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @return NULL if not found, otherwise the remainder
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * of the line, e.g. ": 21805" if
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * this line "serial number: 21805"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * The string is only valid until the next
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * invocation of this function.
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_grep_file (const gchar *directory, const gchar *file, const gchar *linestart, gboolean reuse)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* TODO: use reuse and _grep_can_reuse parameters to avoid loading
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the file again and again
18c2aff776a775d34a4c9893a4c72e0434d68e36artem snprintf (filename, sizeof (filename), "%s/%s", directory, file);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (_grep_can_reuse && reuse && strcmp (oldfilename, filename) == 0) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* just reuse old file; e.g. bufsize, buf */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /*HAL_INFO (("hal_util_grep_file: reusing buf for %s", filename));*/
18c2aff776a775d34a4c9893a4c72e0434d68e36artem bufsize = fread (buf, sizeof (char), sizeof (buf) - 1, f);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /*HAL_INFO (("hal_util_grep_file: read %s of %d bytes", filename, bufsize));*/
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* book keeping */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* analyze buf */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (linelen = 0; p[linelen] != '\n' && p[linelen] != '\0'; linelen++)
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_grep_string_elem_from_file (const gchar *directory, const gchar *file,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (((line = hal_util_grep_file (directory, file, linestart, reuse)) == NULL) || (strlen (line) == 0))
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (j == elem) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_grep_int_elem_from_file (const gchar *directory, const gchar *file,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const gchar *linestart, guint elem, guint base, gboolean reuse)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem strvalue = hal_util_grep_string_elem_from_file (directory, file, linestart, elem, reuse);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Get a string value from a formatted text file and assign it to
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * a property on a device object.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Example: Given that the file /proc/acpi/battery/BAT0/info contains
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * "design voltage: 10800 mV"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * then hal_util_set_string_elem_from_file (d, "battery.foo",
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * "/proc/acpi/battery/BAT0", "info", "design voltage", 1) will assign
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the string "mV" to the property "battery.foo" on d.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param d Device object
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param key Property name
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param directory Directory, e.g. "/proc/acpi/battery/BAT0"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param file File, e.g. "info"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param linestart Start of line, e.g. "design voltage"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param elem Element number after linestart to extract
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * excluding whitespace and ':' characters.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @return TRUE, if, and only if, the value could be
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * extracted and the property was set
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_set_string_elem_from_file (HalDevice *d, const gchar *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if ((value = hal_util_grep_string_elem_from_file (directory, file, linestart, elem, reuse)) == NULL)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Get an integer value from a formatted text file and assign it to
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * a property on a device object.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Example: Given that the file /proc/acpi/battery/BAT0/info contains
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * "design voltage: 10800 mV"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * then hal_util_set_int_elem_from_file (d, "battery.foo",
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * "/proc/acpi/battery/BAT0", "info", "design voltage", 0) will assign
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the integer 10800 to the property "battery.foo" on d.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param d Device object
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param key Property name
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param directory Directory, e.g. "/proc/acpi/battery/BAT0"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param file File, e.g. "info"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param linestart Start of line, e.g. "design voltage"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param elem Element number after linestart to extract
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * excluding whitespace and ':' characters.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @return TRUE, if, and only if, the value could be
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * extracted and the property was set
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_set_int_elem_from_file (HalDevice *d, const gchar *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const gchar *linestart, guint elem, guint base, gboolean reuse)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem strvalue = hal_util_grep_string_elem_from_file (directory, file, linestart, elem, reuse);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/** Get a value from a formatted text file, test it against a given
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * value, and set a boolean property on a device object with the
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * test result.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * Example: Given that the file /proc/acpi/battery/BAT0/info contains
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * "present: yes"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * then hal_util_set_bool_elem_from_file (d, "battery.baz",
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * "/proc/acpi/battery/BAT0", "info", "present", 0, "yes") will assign
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the boolean TRUE to the property "battery.baz" on d.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * If, instead, the line was
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * "present: no"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * the value assigned will be FALSE.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param d Device object
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param key Property name
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param directory Directory, e.g. "/proc/acpi/battery/BAT0"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param file File, e.g. "info"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param linestart Start of line, e.g. "design voltage"
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param elem Element number after linestart to extract
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * excluding whitespace and ':' characters.
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @param expected Value to test against
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * @return TRUE, if, and only if, the value could be
18c2aff776a775d34a4c9893a4c72e0434d68e36artem * extracted and the property was set
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_set_bool_elem_from_file (HalDevice *d, const gchar *key,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem const gchar *linestart, guint elem, const gchar *expected, gboolean reuse)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (((line = hal_util_grep_file (directory, file, linestart, reuse)) == NULL) || (strlen (line) == 0))
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if (j == elem) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem hal_device_property_set_bool (d, key, strcmp (tokens[i], expected) == 0);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (i = strlist, j = 0; i != NULL; i = g_slist_next (i), j++) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem/* -------------------------------------------------------------------------------------------------------------- */
18c2aff776a775d34a4c9893a4c72e0434d68e36artemtypedef struct {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* Check if we're done */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem hald_runner_run(c->d, c->programs[c->next_program], c->extra_env,
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_callout_device (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem c->programs = hal_util_dup_strv_from_g_slist (programs);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_callout_device_add (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if ((programs = hal_device_property_get_strlist (d, "info.callouts.add")) == NULL) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem hal_callout_device (d, callback, userdata1, userdata2, programs, extra_env);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_callout_device_remove (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if ((programs = hal_device_property_get_strlist (d, "info.callouts.remove")) == NULL) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem hal_callout_device (d, callback, userdata1, userdata2, programs, extra_env);
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_callout_device_preprobe (HalDevice *d, HalCalloutsDone callback, gpointer userdata1, gpointer userdata2)
18c2aff776a775d34a4c9893a4c72e0434d68e36artem if ((programs = hal_device_property_get_strlist (d, "info.callouts.preprobe")) == NULL) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem hal_callout_device (d, callback, userdata1, userdata2, programs, extra_env);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem while (!g_utf8_validate (newstr, -1, (const char **) &endchar)) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem unsigned int i;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem unsigned int j;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem unsigned int n;
18c2aff776a775d34a4c9893a4c72e0434d68e36artem while (n < size) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (i = 0; i < 16; i++) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for ( ; i < 16; i++) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem for (i = 0; i < 16; i++) {
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /*HAL_DEBUG (("examining /media/.hal-mtab for %s", mount_point));*/
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_ERROR (("Cannot seek to end of /media/.hal-mtab"));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_ERROR (("Cannot determine size of /media/.hal-mtab"));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem num_read = fread (hal_mtab_buf, 1, hal_mtab_len, hal_mtab);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /*HAL_DEBUG (("hal_mtab = '%s'\n", hal_mtab_buf));*/
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /* find the entry we're going to unmount */
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /*HAL_DEBUG ((" line = '%s'", lines[i]));*/
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_DEBUG ((" devfile = '%s'", line_elements[0]));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_DEBUG ((" uid = '%s'", line_elements[1]));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_DEBUG ((" session id = '%s'", line_elements[2]));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_DEBUG ((" fs = '%s'", line_elements[3]));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_DEBUG ((" options = '%s'", line_elements[4]));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_DEBUG ((" mount_point = '%s'", line_elements[5]));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem HAL_DEBUG ((" (comparing against '%s')", mount_point));
18c2aff776a775d34a4c9893a4c72e0434d68e36artem /*HAL_INFO (("device at '%s' is indeed mounted by HAL's Mount()", mount_point));*/
18c2aff776a775d34a4c9893a4c72e0434d68e36artemhal_util_branch_claim (HalDeviceStore *store, HalDevice *root, dbus_bool_t claimed,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem hal_device_property_set_bool (root, "info.claimed", claimed);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem hal_device_property_set_string (root, "info.claimed.service", service);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem hal_device_property_set_int (root, "info.claimed.uid", uid);
18c2aff776a775d34a4c9893a4c72e0434d68e36artem hal_device_property_remove (root, "info.claimed.service");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem hal_device_property_remove (root, "info.claimed.uid");
18c2aff776a775d34a4c9893a4c72e0434d68e36artem children = hal_device_store_match_multiple_key_value_string (store,
18c2aff776a775d34a4c9893a4c72e0434d68e36artem hal_util_branch_claim (store, d, claimed, service, uid);
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China/** Given an interface name, check if it is valid.
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China * @param name A given interface name
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China * @return TRUE if name is valid, otherwise FALSE
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing Chinais_valid_interface_name(const char *name) {
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China const char *end;
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China const char *last_dot;
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China last_dot = NULL;
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China if (strlen(name) == 0)
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China return FALSE;
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China end = name + strlen(name);
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China if (*name == '.') /* disallow starting with a . */
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China return FALSE;
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China else if (!VALID_INITIAL_NAME_CHARACTER (*name))
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China return FALSE;
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China while (name != end) {
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China if (*name == '.') {
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China if ((name + 1) == end)
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China return FALSE;
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China else if (!VALID_INITIAL_NAME_CHARACTER (*(name + 1)))
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China return FALSE;
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China last_dot = name;
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China name++; /* we just validated the next char, so skip two */
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China } else if (!VALID_NAME_CHARACTER (*name))
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China return FALSE;
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China if (last_dot == NULL)
97191cec6312a1c3a1b70c5f4a543c415c59edf7Xiaolin Zhang - Sun Microsystems - Beijing China return FALSE;