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); if (devtable) parse_device_table(devtable); return 0; }
static int parse_devtable(FILE * devtable) { struct stat sb; if (lstat(rootdir, &sb)) { perror_msg_and_die("%s", rootdir); } if (chdir(rootdir)) perror_msg_and_die("%s", rootdir); if (devtable) parse_device_table(devtable); return 0; }
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; }
/* * Usage: * * mkcramfs directory-name outfile * * where "directory-name" is simply the root of the directory * tree that we want to generate a compressed filesystem out * of. */ int main(int argc, char **argv) { struct stat st; /* used twice... */ struct entry *root_entry; char *rom_image; ssize_t offset, written; int fd; /* initial guess (upper-bound) of required filesystem size */ off_t fslen_ub = sizeof(struct cramfs_super); char const *dirname, *outfile; u32 crc; int c; /* for getopt */ char *ep; /* for strtoul */ FILE *devtable = NULL; total_blocks = 0; if (argc) progname = argv[0]; /* command line options */ while ((c = getopt(argc, argv, "hEe:i:n:psvzD:q")) != EOF) { switch (c) { case 'h': usage(MKFS_OK); case 'E': opt_errors = 1; break; case 'e': errno = 0; opt_edition = strtoul(optarg, &ep, 10); if (errno || optarg[0] == '\0' || *ep != '\0') usage(MKFS_USAGE); break; case 'i': opt_image = optarg; if (lstat(opt_image, &st) < 0) { error_msg_and_die("lstat failed: %s", opt_image); } image_length = st.st_size; /* may be padded later */ fslen_ub += (image_length + 3); /* 3 is for padding */ break; case 'n': opt_name = optarg; break; case 'p': opt_pad = PAD_SIZE; fslen_ub += PAD_SIZE; break; case 's': /* old option, ignored */ break; case 'v': opt_verbose++; break; case 'z': opt_holes = 1; break; case 'q': opt_squash = 1; break; case 'D': devtable = xfopen(optarg, "r"); if (fstat(fileno(devtable), &st) < 0) perror_msg_and_die(optarg); if (st.st_size < 10) error_msg_and_die("%s: not a proper device table file\n", optarg); break; } } if ((argc - optind) != 2) usage(MKFS_USAGE); dirname = argv[optind]; outfile = argv[optind + 1]; if (stat(dirname, &st) < 0) { error_msg_and_die("stat failed: %s", dirname); } fd = xopen(outfile, O_WRONLY | O_CREAT | O_TRUNC, 0666); root_entry = xcalloc(1, sizeof(struct entry)); root_entry->mode = st.st_mode; root_entry->uid = st.st_uid; root_entry->gid = st.st_gid; root_entry->size = parse_directory(root_entry, dirname, &root_entry->child, &fslen_ub); if (devtable) { parse_device_table(devtable, root_entry, &fslen_ub); } /* always allocate a multiple of blksize bytes because that's what we're going to write later on */ fslen_ub = ((fslen_ub - 1) | (blksize - 1)) + 1; if (fslen_ub > MAXFSLEN) { fprintf(stderr, "warning: estimate of required size (upper bound) is %LdMB, but maximum image size is %uMB, we might die prematurely\n", fslen_ub >> 20, MAXFSLEN >> 20); fslen_ub = MAXFSLEN; }