static void parse_device_table(FILE * file) { char *line; size_t length = 256; int len = 0; /* Looks ok so far. The general plan now is to read in one * line at a time, check for leading comment delimiters ('#'), * then try and parse the line as a device table. If we fail * to parse things, try and help the poor fool to fix their * device table with a useful error msg... */ if((line = (char *)malloc(length)) == NULL) { fclose(file); return; } while ((len = getline(&line, &length, file)) != -1) { /* First trim off any whitespace */ /* trim trailing whitespace */ while (len > 0 && isspace(line[len - 1])) line[--len] = '\0'; /* trim leading whitespace */ memmove(line, &line[strspn(line, " \n\r\t\v")], len + 1); /* If this is NOT a comment line, try to interpret it */ if (*line != '#') interpret_table_entry(line); } if (line) free(line); fclose(file); }
static int parse_device_table(struct filesystem_entry *root, FILE * file) { char *line; int status = 0; size_t length = 0; /* Turn off squash, since we must ensure that values * entered via the device table are not squashed */ squash_uids = 0; squash_perms = 0; /* Looks ok so far. The general plan now is to read in one * line at a time, check for leading comment delimiters ('#'), * then try and parse the line as a device table. If we fail * to parse things, try and help the poor fool to fix their * device table with a useful error msg... */ line = NULL; while (getline(&line, &length, file) != -1) { /* First trim off any whitespace */ int len = strlen(line); /* trim trailing whitespace */ while (len > 0 && isspace(line[len - 1])) line[--len] = '\0'; /* trim leading whitespace */ memmove(line, &line[strspn(line, " \n\r\t\v")], len); /* How long are we after trimming? */ len = strlen(line); /* If this is NOT a comment line, try to interpret it */ if (len && *line != '#') { if (interpret_table_entry(root, line)) status = 1; } free(line); line = NULL; } fclose(file); return status; }
/** * parse_devtable - parse the device table. * @tbl_file: device table file name * * This function parses the device table and prepare the hash table which will * later be used by mkfs.ubifs to create the specified files/device nodes. * Returns zero in case of success and a negative error code in case of * failure. */ int parse_devtable(const char *tbl_file) { FILE *f; char *line = NULL; struct stat st; size_t len; dbg_msg(1, "parsing device table file '%s'", tbl_file); path_htbl = create_hashtable(128, &r5_hash, &is_equivalent); if (!path_htbl) return err_msg("cannot create path hash table"); f = fopen(tbl_file, "r"); if (!f) return sys_err_msg("cannot open '%s'", tbl_file); if (fstat(fileno(f), &st) < 0) { sys_err_msg("cannot stat '%s'", tbl_file); goto out_close; } if (st.st_size < 10) { sys_err_msg("'%s' is too short", tbl_file); goto out_close; } /* * The general plan now is to read in one line at a time, check for * leading comment delimiters ('#'), then try and parse the line as a * device table */ while (getline(&line, &len, f) != -1) { /* First trim off any white-space */ len = strlen(line); /* Trim trailing white-space */ while (len > 0 && isspace(line[len - 1])) line[--len] = '\0'; /* Trim leading white-space */ memmove(line, &line[strspn(line, " \n\r\t\v")], len); /* How long are we after trimming? */ len = strlen(line); /* If this is not a comment line, try to interpret it */ if (len && *line != '#') { if (interpret_table_entry(line)) { err_msg("cannot parse '%s'", line); goto out_close; } } free(line); line = NULL; } dbg_msg(1, "finished parsing"); fclose(f); return 0; out_close: fclose(f); free_devtable_info(); return -1; }