static int go(char *dname, FILE * devtable) { struct stat sb; if (lstat(dname, &sb)) { perror_msg_and_die("%s", dname); } if (chdir(dname)) perror_msg_and_die("%s", dname); recursive_add_directory("."); if (devtable) parse_device_table(devtable); create_target_filesystem(); cleanup(); return 0; }
int main(int argc, char **argv) { int c, opt; char *cwd; struct stat sb; FILE *devtable = NULL; struct filesystem_entry *root; char *compr_name = NULL; int compr_prior = -1; jffs2_compressors_init(); while ((opt = getopt_long(argc, argv, "D:d:r:s:o:qUPfh?vVe:lbp::nc:m:x:X:Lty:i:", long_options, &c)) >= 0) { switch (opt) { case 'D': devtable = xfopen(optarg, "r"); if (fstat(fileno(devtable), &sb) < 0) perror_msg_and_die(optarg); if (sb.st_size < 10) error_msg_and_die("%s: not a proper device table file", optarg); break; case 'r': case 'd': /* for compatibility with mkfs.jffs, genext2fs, etc... */ if (rootdir != default_rootdir) { error_msg_and_die("root directory specified more than once"); } rootdir = xstrdup(optarg); break; case 's': page_size = strtol(optarg, NULL, 0); break; case 'o': if (out_fd != -1) { error_msg_and_die("output filename specified more than once"); } out_fd = open(optarg, O_CREAT | O_TRUNC | O_RDWR, 0644); if (out_fd == -1) { perror_msg_and_die("open output file"); } break; case 'q': squash_uids = 1; squash_perms = 1; break; case 'U': squash_uids = 1; break; case 'P': squash_perms = 1; break; case 'f': fake_times = 1; break; case 'h': case '?': error_msg_and_die(helptext); case 'v': verbose = 1; break; case 'V': error_msg_and_die("revision %.*s\n", (int) strlen(revtext) - 13, revtext + 11); case 'e': { char *next; unsigned units = 0; erase_block_size = strtol(optarg, &next, 0); if (!erase_block_size) error_msg_and_die("Unrecognisable erase size\n"); if (*next) { if (!strcmp(next, "KiB")) { units = 1024; } else if (!strcmp(next, "MiB")) { units = 1024 * 1024; } else { error_msg_and_die("Unknown units in erasesize\n"); } } else { if (erase_block_size < 0x1000) units = 1024; else units = 1; } erase_block_size *= units; /* If it's less than 8KiB, they're not allowed */ if (erase_block_size < 0x2000) { fprintf(stderr, "Erase size 0x%x too small. Increasing to 8KiB minimum\n", erase_block_size); erase_block_size = 0x2000; } break; } case 'l': target_endian = __LITTLE_ENDIAN; break; case 'b': target_endian = __BIG_ENDIAN; break; case 'p': if (optarg) pad_fs_size = strtol(optarg, NULL, 0); else pad_fs_size = -1; break; case 'n': add_cleanmarkers = 0; break; case 'c': cleanmarker_size = strtol(optarg, NULL, 0); if (cleanmarker_size < sizeof(cleanmarker)) { error_msg_and_die("cleanmarker size must be >= 12"); } if (cleanmarker_size >= erase_block_size) { error_msg_and_die("cleanmarker size must be < eraseblock size"); } break; case 'm': if (jffs2_set_compression_mode_name(optarg)) { error_msg_and_die("Unknown compression mode %s", optarg); } break; case 'x': if (jffs2_disable_compressor_name(optarg)) { error_msg_and_die("Unknown compressor name %s",optarg); } break; case 'X': if (jffs2_enable_compressor_name(optarg)) { error_msg_and_die("Unknown compressor name %s",optarg); } break; case 'L': error_msg_and_die("\n%s",jffs2_list_compressors()); break; case 't': jffs2_compression_check_set(1); break; case 'y': compr_name = malloc(strlen(optarg)); sscanf(optarg,"%d:%s",&compr_prior,compr_name); if ((compr_prior>=0)&&(compr_name)) { if (jffs2_set_compressor_priority(compr_name, compr_prior)) exit(EXIT_FAILURE); } else { error_msg_and_die("Cannot parse %s",optarg); } free(compr_name); break; case 'i': if (in_fd != -1) { error_msg_and_die("(incremental) filename specified more than once"); } in_fd = open(optarg, O_RDONLY); if (in_fd == -1) { perror_msg_and_die("cannot open (incremental) file"); } break; case 1000: /* --with-xattr */ enable_xattr |= (1 << JFFS2_XPREFIX_USER) | (1 << JFFS2_XPREFIX_SECURITY) | (1 << JFFS2_XPREFIX_ACL_ACCESS) | (1 << JFFS2_XPREFIX_ACL_DEFAULT) | (1 << JFFS2_XPREFIX_TRUSTED); break; case 1001: /* --with-selinux */ enable_xattr |= (1 << JFFS2_XPREFIX_SECURITY); break; case 1002: /* --with-posix-acl */ enable_xattr |= (1 << JFFS2_XPREFIX_ACL_ACCESS) | (1 << JFFS2_XPREFIX_ACL_DEFAULT); break; } } if (out_fd == -1) { if (isatty(1)) { error_msg_and_die(helptext); } out_fd = 1; } if (lstat(rootdir, &sb)) { perror_msg_and_die("%s", rootdir); } if (chdir(rootdir)) perror_msg_and_die("%s", rootdir); if (!(cwd = getcwd(0, GETCWD_SIZE))) perror_msg_and_die("getcwd failed"); if(in_fd != -1) parse_image(); root = recursive_add_host_directory(NULL, "/", cwd); if (devtable) parse_device_table(root, devtable); create_target_filesystem(root); cleanup(root); if (rootdir != default_rootdir) free(rootdir); close(out_fd); if (verbose) { char *s = jffs2_stats(); fprintf(stderr,"\n\n%s",s); free(s); } if ((verbose)||(jffs2_compression_check_get()&&(jffs2_compression_check_errorcnt_get()))) { fprintf(stderr,"Compression errors: %d\n",jffs2_compression_check_errorcnt_get()); } jffs2_compressors_exit(); return 0; }