X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=namedev_parse.c;h=e360565950c71768975891c8264f76e21031e3b7;hb=915a12adc2ea28dc2391788c66b829caefefcfb4;hp=7190cdd1a8702a538f5f454d96e3ca84a00f7b6f;hpb=8b36cc0f179ee35176016ab67ae53078df4110fa;p=elogind.git diff --git a/namedev_parse.c b/namedev_parse.c index 7190cdd1a..e36056595 100644 --- a/namedev_parse.c +++ b/namedev_parse.c @@ -4,6 +4,7 @@ * Userspace devfs * * Copyright (C) 2003,2004 Greg Kroah-Hartman + * Copyright (C) 2003-2005 Kay Sievers * * * This program is free software; you can redistribute it and/or modify it @@ -97,7 +98,7 @@ static char *get_key_attribute(char *str) return NULL; } -static int namedev_parse(const char *filename, void *data) +static int namedev_parse(struct udevice *udev, const char *filename) { char line[LINE_SIZE]; char *bufline; @@ -126,14 +127,15 @@ static int namedev_parse(const char *filename, void *data) cur = 0; lineno = 0; while (cur < bufsize) { + unsigned int i, j; + count = buf_get_line(buf, bufsize, cur); bufline = &buf[cur]; cur += count+1; lineno++; if (count >= LINE_SIZE) { - info("line too long, rule skipped %s, line %d", - filename, lineno); + info("line too long, rule skipped %s, line %d", filename, lineno); continue; } @@ -149,8 +151,14 @@ static int namedev_parse(const char *filename, void *data) if (bufline[0] == COMMENT_CHARACTER) continue; - strncpy(line, bufline, count); - line[count] = '\0'; + /* skip backslash and newline from multi line rules */ + for (i = j = 0; i < count; i++) { + if (bufline[i] == '\\' && bufline[i+1] == '\n') + continue; + + line[j++] = bufline[i]; + } + line[j] = '\0'; dbg_parse("read '%s'", line); /* get all known keys */ @@ -163,6 +171,18 @@ static int namedev_parse(const char *filename, void *data) if (retval) break; + if (strcasecmp(temp2, FIELD_KERNEL) == 0) { + strfieldcpy(dev.kernel, temp3); + valid = 1; + continue; + } + + if (strcasecmp(temp2, FIELD_SUBSYSTEM) == 0) { + strfieldcpy(dev.subsystem, temp3); + valid = 1; + continue; + } + if (strcasecmp(temp2, FIELD_BUS) == 0) { strfieldcpy(dev.bus, temp3); valid = 1; @@ -207,18 +227,6 @@ static int namedev_parse(const char *filename, void *data) continue; } - if (strcasecmp(temp2, FIELD_KERNEL) == 0) { - strfieldcpy(dev.kernel, temp3); - valid = 1; - continue; - } - - if (strcasecmp(temp2, FIELD_SUBSYSTEM) == 0) { - strfieldcpy(dev.subsystem, temp3); - valid = 1; - continue; - } - if (strcasecmp(temp2, FIELD_DRIVER) == 0) { strfieldcpy(dev.driver, temp3); valid = 1; @@ -240,17 +248,21 @@ static int namedev_parse(const char *filename, void *data) if (strncasecmp(temp2, FIELD_NAME, sizeof(FIELD_NAME)-1) == 0) { attr = get_key_attribute(temp2 + sizeof(FIELD_NAME)-1); + /* FIXME: remove old style options and make OPTIONS= mandatory */ if (attr != NULL) { - if (strstr(attr, ATTR_PARTITIONS) != NULL) { + if (strstr(attr, OPTION_PARTITIONS) != NULL) { dbg_parse("creation of partition nodes requested"); - dev.partitions = PARTITIONS_COUNT; + dev.partitions = DEFAULT_PARTITIONS_COUNT; } - if (strstr(attr, ATTR_IGNORE_REMOVE) != NULL) { + if (strstr(attr, OPTION_IGNORE_REMOVE) != NULL) { dbg_parse("remove event should be ignored"); dev.ignore_remove = 1; } } - strfieldcpy(dev.name, temp3); + if (temp3[0] != '\0') + strfieldcpy(dev.name, temp3); + else + dev.ignore_device = 1; valid = 1; continue; } @@ -279,6 +291,23 @@ static int namedev_parse(const char *filename, void *data) continue; } + if (strcasecmp(temp2, FIELD_OPTIONS) == 0) { + if (strstr(temp3, OPTION_IGNORE_DEVICE) != NULL) { + dbg_parse("device should be ignored"); + dev.ignore_device = 1; + } + if (strstr(temp3, OPTION_IGNORE_REMOVE) != NULL) { + dbg_parse("remove event should be ignored"); + dev.ignore_remove = 1; + } + if (strstr(temp3, OPTION_PARTITIONS) != NULL) { + dbg_parse("creation of partition nodes requested"); + dev.partitions = DEFAULT_PARTITIONS_COUNT; + } + valid = 1; + continue; + } + dbg("unknown type of field '%s'", temp2); goto error; } @@ -325,9 +354,21 @@ int namedev_init(void) return -1; if ((stats.st_mode & S_IFMT) != S_IFDIR) - retval = namedev_parse(udev_rules_filename, NULL); + retval = namedev_parse(NULL, udev_rules_filename); else - retval = call_foreach_file(namedev_parse, udev_rules_filename, RULEFILE_SUFFIX, NULL); + retval = call_foreach_file(namedev_parse, NULL, udev_rules_filename, RULEFILE_SUFFIX); return retval; } + +void namedev_close(void) +{ + struct config_device *dev; + struct config_device *temp_dev; + + list_for_each_entry_safe(dev, temp_dev, &config_device_list, node) { + list_del(&dev->node); + free(dev); + } +} +