📄 mkisofs.c
字号:
if(!scan_tree){ usage(); exit(1); };#ifndef VMS if(scan_tree[strlen(scan_tree)-1] != '/') { scan_tree = (char *) e_malloc(strlen(argv[optind])+2); strcpy(scan_tree, argv[optind]); strcat(scan_tree, "/"); };#endif if(use_RockRidge){#if 1 extension_record = generate_rr_extension_record("RRIP_1991A", "THE ROCK RIDGE INTERCHANGE PROTOCOL PROVIDES SUPPORT FOR POSIX FILE SYSTEM SEMANTICS", "PLEASE CONTACT DISC PUBLISHER FOR SPECIFICATION SOURCE. SEE PUBLISHER IDENTIFIER IN PRIMARY VOLUME DESCRIPTOR FOR CONTACT INFORMATION.", &extension_record_size);#else extension_record = generate_rr_extension_record("IEEE_P1282", "THE IEEE P1282 PROTOCOL PROVIDES SUPPORT FOR POSIX FILE SYSTEM SEMANTICS", "PLEASE CONTACT THE IEEE STANDARDS DEPARTMENT, PISCATAWAY, NJ, USA FOR THE P1282 SPECIFICATION.", &extension_record_size);#endif } if (log_file) { FILE *lfp; int i; /* open log file - test that we can open OK */ if ((lfp = fopen(log_file, "w")) == NULL) { fprintf(stderr,"can't open logfile: %s\n", log_file); exit (1); } fclose(lfp); /* redirect all stderr message to log_file */ fprintf(stderr, "re-directing all messages to %s\n", log_file); fflush(stderr); /* associate stderr with the log file */ if (freopen(log_file, "w", stderr) == NULL) { fprintf(stderr,"can't open logfile: %s\n", log_file); exit (1); } if(verbose > 1) { for (i=0;i<argc;i++) fprintf(stderr,"%s ", argv[i]); fprintf(stderr,"\n%s\n", version_string); } } /* * See if boot catalog file exists in root directory, if not * we will create it. */ if (use_eltorito) init_boot_catalog(argv[optind]); /* * Find the device and inode number of the root directory. * Record this in the hash table so we don't scan it more than * once. */ stat_filter(argv[optind], &statbuf); add_directory_hash(statbuf.st_dev, STAT_INODE(statbuf)); memset(&de, 0, sizeof(de)); de.filedir = root; /* We need this to bootstrap */ if (cdwrite_data != NULL && merge_image == NULL) { /* 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. */ fprintf(stderr,"Unable to open previous session image %s\n", merge_image); exit(1); } 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); /* * 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(optind < argc) { char * node; 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(argv[optind], '='); short_name = NULL; if( node != NULL ) { char * pnt; char * xpnt; *node = '\0'; strcpy(graft_point, argv[optind]); *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 = argv[optind]; } /* * 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. */ fprintf(stderr, "Invalid node - %s\n", node); exit(1); } 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++; } /* * 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 ) { merge_previous_session(root, mrootp); } /* hide "./rr_moved" if all its contents have been hidden */ if (reloc_dir && i_ishidden()) hide_reloc_dir(); /* * 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( use_Joliet ) { goof += joliet_sort_tree(root); } if (goof) { fprintf(stderr, "Joliet tree sort failed.\n"); exit(1); } /* * 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){ fprintf(stderr,"Unable to open /dev/null\n"); exit(1); } } else if (outfile){ discimage = fopen(outfile, "wb"); if (!discimage){ fprintf(stderr,"Unable to open disc image file\n"); exit(1); }; } else { discimage = stdout;#if defined(__CYGWIN32__) setmode(fileno(stdout), O_BINARY);#endif } if (do_fileopt) { /* init two hash tables */ md5_hash = htNewTable(5000); if (!md5_hash) { fprintf(stderr,"Error init hash table for file optimization\n"); exit(1); } printf("Start duplicate file check,this may take a while\n"); } /* 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. */ 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)(); } } if( in_image != NULL ) { fclose(in_image); } /* * 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); } if (do_fileopt) { /* free the hash tables */ htFreeHashTable(md5_hash); }#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) ) { fprintf(stderr, "Not enough memory\n"); exit (1); }return pt;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -