📄 mkisofs.c
字号:
/* in case we want to add a new session, but don't want to merge old one */ get_session_start(NULL); } if( merge_image != NULL ) { mrootp = merge_isofs(merge_image); if( mrootp == NULL ) { /* * Complain and die. */#ifdef USE_LIBSCHILY comerr("Unable to find previous session image %s\n", merge_image);#else fprintf(stderr,"Unable to find previous session image %s\n", merge_image); exit(1);#endif } memcpy(de.isorec.extent, mrootp->extent, 8); } /* * Create an empty root directory. If we ever scan it for real, we will fill in the * contents. */ find_or_create_directory(NULL, "", &de, TRUE); /* see if we have a list of pathnames to process */ if (pathnames) { /* "-" means take list from the standard input */ if (strcmp(pathnames, "-")) { if ((pfp = fopen(pathnames, "r")) == NULL) {#ifdef USE_LIBSCHILY comerr("Unable to open pathname list %s.\n", pathnames);#else fprintf(stderr, "Unable to open pathname list %s.\n", pathnames); exit (1);#endif } } else pfp = stdin; } /* * Scan the actual directory (and any we find below it) * for files to write out to the output image. Note - we * take multiple source directories and keep merging them * onto the image. */ while((arg = get_pnames(argc, argv, optind, pname, sizeof(pname), pfp)) != NULL) { struct directory * graft_dir; struct stat st; char * short_name; int status; char graft_point[1024]; /* * We would like a syntax like: * * /tmp=/usr/tmp/xxx * * where the user can specify a place to graft each * component of the tree. To do this, we may have to create * directories along the way, of course. * Secondly, I would like to allow the user to do something * like: * * /home/baz/RMAIL=/u3/users/baz/RMAIL * * so that normal files could also be injected into the tree * at an arbitrary point. * * The idea is that the last component of whatever is being * entered would take the name from the last component of * whatever the user specifies. * * The default will be that the file is injected at the * root of the image tree. */ node = strchr(arg, '='); short_name = NULL; if( node != NULL ) { char * pnt; char * xpnt; *node = '\0'; strcpy(graft_point, arg); *node = '='; node++; graft_dir = root; xpnt = graft_point; if( *xpnt == PATH_SEPARATOR ) { xpnt++; } /* * Loop down deeper and deeper until we * find the correct insertion spot. */ while(1==1) { pnt = strchr(xpnt, PATH_SEPARATOR); if( pnt == NULL ) { if( *xpnt != '\0' ) { short_name = xpnt; } break; } *pnt = '\0'; graft_dir = find_or_create_directory(graft_dir, graft_point, NULL, TRUE); *pnt = PATH_SEPARATOR; xpnt = pnt + 1; } } else { graft_dir = root; node = arg; } /* * Now see whether the user wants to add a regular file, * or a directory at this point. */ status = stat_filter(node, &st); if( status != 0 ) { /* * This is a fatal error - the user won't be getting what * they want if we were to proceed. */#ifdef USE_LIBSCHILY comerr("Invalid node - %s\n", node);#else fprintf(stderr, "Invalid node - %s\n", node); exit(1);#endif } else { if( S_ISDIR(st.st_mode) ) { if (!scan_directory_tree(graft_dir, node, &de)) { exit(1); } } else { if( short_name == NULL ) { short_name = strrchr(node, PATH_SEPARATOR); if( short_name == NULL || short_name < node ) { short_name = node; } else { short_name++; } } if( !insert_file_entry(graft_dir, node, short_name) ) { exit(1); } } } optind++; no_path_names = 0; } if (pfp && pfp != stdin) fclose(pfp); /* * exit if we don't have any pathnames to process - not going to happen * at the moment as we have to have at least one path on the command line */ if (no_path_names) {#ifdef USE_LIBSCHILY errmsgno(EX_BAD, "No pathnames found.\n");#endif usage(1); } /* * Now merge in any previous sessions. This is driven on the source * side, since we may need to create some additional directories. */ if( merge_image != NULL ) { if (merge_previous_session(root, mrootp) < 0) {#ifdef USE_LIBSCHILY comerrno(EX_BAD, "Cannot merge previous session.\n");#else fprintf(stderr, "Cannot merge previous session.\n"); exit(1);#endif } } /* hide "./rr_moved" if all its contents have been hidden */ if (reloc_dir && i_ishidden()) hide_reloc_dir(); /* insert the boot catalog if required */ if (use_eltorito) insert_boot_cat(); /* * Sort the directories in the required order (by ISO9660). Also, * choose the names for the 8.3 filesystem if required, and do * any other post-scan work. */ goof += sort_tree(root); if (goof) {#ifdef USE_LIBSCHILY comerrno(EX_BAD, "ISO9660/Rock Ridge tree sort failed.\n");#else fprintf(stderr, "ISO9660/Rock Ridge tree sort failed.\n"); exit(1);#endif } if( use_Joliet ) { goof += joliet_sort_tree(root); } if (goof) {#ifdef USE_LIBSCHILY comerrno(EX_BAD, "Joliet tree sort failed.\n");#else fprintf(stderr, "Joliet tree sort failed.\n"); exit(1);#endif } /* * Fix a couple of things in the root directory so that everything * is self consistent. */ root->self = root->contents; /* Fix this up so that the path tables get done right */ /* * OK, ready to write the file. Open it up, and generate the thing. */ if (print_size){ discimage = fopen("/dev/null", "wb"); if (!discimage){#ifdef USE_LIBSCHILY comerr("Unable to open /dev/null\n");#else fprintf(stderr,"Unable to open /dev/null\n"); exit(1);#endif } } else if (outfile){ discimage = fopen(outfile, "wb"); if (!discimage){#ifdef USE_LIBSCHILY comerr("Unable to open disc image file\n");#else fprintf(stderr,"Unable to open disc image file\n"); exit(1);#endif }; } else { discimage = stdout;#if defined(__CYGWIN32__) || defined(__EMX__) setmode(fileno(stdout), O_BINARY);#endif } /* Now assign addresses on the disc for the path table. */ path_blocks = (path_table_size + (SECTOR_SIZE - 1)) >> 11; if (path_blocks & 1) path_blocks++; jpath_blocks = (jpath_table_size + (SECTOR_SIZE - 1)) >> 11; if (jpath_blocks & 1) jpath_blocks++; /* * Start to set up the linked list that we use to track the * contents of the disc. */ if (use_sparcboot) outputlist_insert(&sunlabel_desc); if (use_genboot) outputlist_insert(&genboot_desc); outputlist_insert(&padblock_desc); /* * PVD for disc. */ outputlist_insert(&voldesc_desc); /* * SVD for El Torito. MUST be immediately after the PVD! */ if( use_eltorito) { outputlist_insert(&torito_desc); } /* * SVD for Joliet. */ if( use_Joliet) { outputlist_insert(&joliet_desc); } /* * Finally the last volume desctiptor. */ outputlist_insert(&end_vol); outputlist_insert(&pathtable_desc); if( use_Joliet) { outputlist_insert(&jpathtable_desc); } outputlist_insert(&dirtree_desc); if( use_Joliet) { outputlist_insert(&jdirtree_desc); } outputlist_insert(&dirtree_clean); if(extension_record) { outputlist_insert(&extension_desc); } outputlist_insert(&files_desc); /* * Allow room for the various headers we will be writing. There * will always be a primary and an end volume descriptor. */ last_extent = session_start; /* * Calculate the size of all of the components of the disc, and assign * extent numbers. */ for(opnt = out_list; opnt; opnt = opnt->of_next ) { if( opnt->of_size != NULL ) { (*opnt->of_size)(last_extent); } } /* * Generate the contents of any of the sections that we want to generate. * Not all of the fragments will do anything here - most will generate the * data on the fly when we get to the write pass. */ for(opnt = out_list; opnt; opnt = opnt->of_next ) { if( opnt->of_generate != NULL ) { (*opnt->of_generate)(); } } c = 0; if (use_sparcboot) { c = make_sun_label(); outputlist_insert(&sunboot_desc); } if( in_image != NULL ) { fclose(in_image); } if( print_size > 0 ) { fprintf(stderr,"Total extents scheduled to be written = %d\n", (last_extent - session_start) + c); exit(0); } /* * Now go through the list of fragments and write the data that corresponds to * each one. */ for(opnt = out_list; opnt; opnt = opnt->of_next ) { if( opnt->of_write != NULL ) { (*opnt->of_write)(discimage); } } if( verbose > 0 ) {#ifdef HAVE_SBRK fprintf(stderr,"Max brk space used %x\n", (unsigned int)(((unsigned long)sbrk(0)) - mem_start));#endif fprintf(stderr,"%d extents written (%d Mb)\n", last_extent, last_extent >> 9); }#ifdef VMS return 1;#else return 0;#endif}void *FDECL1(e_malloc, size_t, size){void* pt = 0; if( (size > 0) && ((pt=malloc(size))==NULL) ) {#ifdef USE_LIBSCHILY comerr("Not enough memory\n");#else fprintf(stderr, "Not enough memory\n"); exit (1);#endif }return pt;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -