+
+ err("unknown key '%s' in %s:%u", key, filename, lineno);
+ }
+
+ if (physdev && rule->wait_for_sysfs.operation == KEY_OP_UNSET)
+ err("PHYSDEV* values are deprecated and will be removed from a future kernel, "
+ "please fix it in %s:%u", filename, lineno);
+
+ /* skip line if not any valid key was found */
+ if (!valid)
+ goto invalid;
+
+ /* grow buffer and add rule */
+ rule_size = sizeof(struct udev_rule) + rule->bufsize;
+ padding = (sizeof(size_t) - rule_size % sizeof(size_t)) % sizeof(size_t);
+ dbg("add %zi padding bytes", padding);
+ rule_size += padding;
+ rule->bufsize += padding;
+
+ rules->buf = realloc(rules->buf, rules->bufsize + rule_size);
+ if (!rules->buf) {
+ err("realloc failed");
+ goto exit;
+ }
+ dbg("adding rule to offset %zi", rules->bufsize);
+ memcpy(rules->buf + rules->bufsize, rule, rule_size);
+ rules->bufsize += rule_size;
+exit:
+ return 0;
+
+invalid:
+ err("invalid rule '%s:%u'", filename, lineno);
+ return -1;
+}
+
+static int parse_file(struct udev_rules *rules, const char *filename)
+{
+ char line[LINE_SIZE];
+ char *bufline;
+ unsigned int lineno;
+ char *buf;
+ size_t bufsize;
+ size_t cur;
+ size_t count;
+ int retval = 0;
+
+ if (file_map(filename, &buf, &bufsize) != 0) {
+ err("can't open '%s' as rules file: %s", filename, strerror(errno));
+ return -1;
+ }
+ info("reading '%s' as rules file", filename);
+
+ /* loop through the whole file */
+ 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++;
+
+ /* eat the whitespace */
+ while ((count > 0) && isspace(bufline[0])) {
+ bufline++;
+ count--;
+ }
+ if (count == 0)
+ continue;
+
+ /* see if this is a comment */
+ if (bufline[0] == COMMENT_CHARACTER)
+ continue;
+
+ if (count >= sizeof(line)) {
+ err("line too long, rule skipped '%s:%u'", filename, lineno);
+ continue;
+ }
+
+ /* skip backslash and newline from multiline rules */
+ for (i = j = 0; i < count; i++) {
+ if (bufline[i] == '\\' && bufline[i+1] == '\n')
+ continue;
+
+ line[j++] = bufline[i];
+ }
+ line[j] = '\0';
+
+ dbg("read '%s'", line);
+ add_to_rules(rules, line, filename, lineno);