int main(void) { int x; while(TRUE) { x=menu(x); switch(x) { case 0: return 0; case 1: create_dir();break; case 2: find_dir();break; case 3: del_dir();break; case 4: modify_dir();break; case 5: insert_dir();break; case 6: num();break; case 7: all();break; default: exit(-1); } } return 0; }
static void fill_tree (char *path) { struct dirent *d; DIR *dir; int rc; if (!path) { path = "."; } dir = opendir(path); if (!dir) { eprintf("Couldn't opendir %s:", path); return; } for (;;) { d = readdir(dir); if (!d) break; pr_dirent(d); rc = insert_dir(d->d_name, d->d_ino, d->d_type); if (rc) { eprintf("insert_dir %d", rc); return; } } }
grub_err_t grub_initrd_load (struct grub_linux_initrd_context *initrd_ctx, char *argv[], void *target) { grub_uint8_t *ptr = target; int i; int newc = 0; struct dir *root = 0; grub_ssize_t cursize = 0; for (i = 0; i < initrd_ctx->nfiles; i++) { grub_memset (ptr, 0, ALIGN_UP_OVERHEAD (cursize, 4)); ptr += ALIGN_UP_OVERHEAD (cursize, 4); if (initrd_ctx->components[i].newc_name) { ptr += insert_dir (initrd_ctx->components[i].newc_name, &root, ptr); ptr = make_header (ptr, initrd_ctx->components[i].newc_name, grub_strlen (initrd_ctx->components[i].newc_name), 0100777, initrd_ctx->components[i].size); newc = 1; } else if (newc) { ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0); free_dir (root); root = 0; newc = 0; } cursize = initrd_ctx->components[i].size; if (grub_file_read (initrd_ctx->components[i].file, ptr, cursize) != cursize) { if (!grub_errno) grub_error (GRUB_ERR_FILE_READ_ERROR, N_("premature end of file %s"), argv[i]); grub_initrd_close (initrd_ctx); return grub_errno; } ptr += cursize; } if (newc) ptr = make_header (ptr, "TRAILER!!!", sizeof ("TRAILER!!!") - 1, 0, 0); free_dir (root); root = 0; return GRUB_ERR_NONE; }
int ip (int argc, char *argv[]) { int i; int rc; for (i = 1; i < argc; ++i) { rc = insert_dir(argv[i], 0, 0); if (rc != 0) { return rc; } } return 0; }
int fill (int n) { int i; int rc; char *name; for (i = 0; i < n; i++) { do { name = gen_name(); } while (find_dir(name) != qERR_NOT_FOUND); rc = insert_dir(name, 0, 0); if (rc != 0) { return rc; } } return 0; }
int mixp (int argc, char *argv[]) { int n; int i; int rc; int sum; char *name; int x; if (argc > 1) { n = atoi(argv[1]); } else { n = 10; } sum = num_recs(); for (i = 0; i < n; i++) { if (!sum || random_percent(51)) { do { name = gen_name(); } while (find_dir(name) != qERR_NOT_FOUND); rc = insert_dir(name, 0, 0); if (rc != 0) { return rc; } ++sum; x = num_recs(); assert(sum == x); } else { x = urand(sum); rc = del_ith(x);//urand(sum)); if (rc) { return rc; } --sum; x = num_recs(); assert(sum == x); } } return 0; }
int genp (int argc, char *argv[]) { int n; int i; int rc; char *name; if (argc > 1) { n = atoi(argv[1]); } else { n = 10; } for (i = 0; i < n; i++) { do { name = gen_name(); } while (find_dir(name) == 0); rc = insert_dir(name, 0, 0); if (rc != 0) { return rc; } } return 0; }
grub_err_t grub_initrd_init (int argc, char *argv[], struct grub_linux_initrd_context *initrd_ctx) { int i; int newc = 0; struct dir *root = 0; initrd_ctx->nfiles = 0; initrd_ctx->components = 0; initrd_ctx->components = grub_zalloc (argc * sizeof (initrd_ctx->components[0])); if (!initrd_ctx->components) return grub_errno; initrd_ctx->size = 0; for (i = 0; i < argc; i++) { const char *fname = argv[i]; initrd_ctx->size = ALIGN_UP (initrd_ctx->size, 4); if (grub_memcmp (argv[i], "newc:", 5) == 0) { const char *ptr, *eptr; ptr = argv[i] + 5; while (*ptr == '/') ptr++; eptr = grub_strchr (ptr, ':'); if (eptr) { grub_file_filter_disable_compression (); initrd_ctx->components[i].newc_name = grub_strndup (ptr, eptr - ptr); if (!initrd_ctx->components[i].newc_name) { grub_initrd_close (initrd_ctx); return grub_errno; } initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head) + grub_strlen (initrd_ctx->components[i].newc_name), 4); initrd_ctx->size += insert_dir (initrd_ctx->components[i].newc_name, &root, 0); newc = 1; fname = eptr + 1; } } else if (newc) { initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head) + sizeof ("TRAILER!!!") - 1, 4); free_dir (root); root = 0; newc = 0; } grub_file_filter_disable_compression (); initrd_ctx->components[i].file = grub_file_open (fname); if (!initrd_ctx->components[i].file) { grub_initrd_close (initrd_ctx); return grub_errno; } initrd_ctx->nfiles++; initrd_ctx->components[i].size = grub_file_size (initrd_ctx->components[i].file); initrd_ctx->size += initrd_ctx->components[i].size; } if (newc) { initrd_ctx->size += ALIGN_UP (sizeof (struct newc_head) + sizeof ("TRAILER!!!") - 1, 4); free_dir (root); root = 0; } return GRUB_ERR_NONE; }