⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mkisofs.c

📁 创建一个符合iso-9660标准的iso文件系统
💻 C
📖 第 1 页 / 共 5 页
字号:
	if (merge_image != NULL && apple_hyb) {#ifdef	USE_LIBSCHILY		errmsgno(EX_BAD,		"Warning: files from previous sessions will not be included in the HFS volume.\n");#else		fprintf(stderr,		"Warning: files from previous sessions will not be included in the HFS volume.\n");#endif	}#endif	/* APPLE_HYB */	/*	 * 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;	}	/* The first step is to scan the directory tree, and take some notes */	if ((arg = get_pnames(argc, argv, optind, pname,						sizeof(pname), pfp)) == NULL) {#ifdef	USE_LIBSCHILY		errmsgno(EX_BAD, "Missing pathspec.\n");#endif		usage(1);	}	/*	 * if we don't have a pathspec, then save the pathspec found	 * in the pathnames file (stored in pname) - we don't want	 * to skip this pathspec when we read the pathnames file again	 */	if (!have_cmd_line_pathspec) {		save_pname = 1;	}	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) {#ifdef	USE_LIBSCHILY			comerr("can't open logfile: %s\n", log_file);#else			fprintf(stderr, "can't open logfile: %s\n", log_file);			exit(1);#endif		}		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) {#ifdef	USE_LIBSCHILY			comerr("can't open logfile: %s\n", log_file);#else			fprintf(stderr, "can't open logfile: %s\n", log_file);			exit(1);#endif		}		if (verbose > 1) {			for (i = 0; i < argc; i++)				fprintf(stderr, "%s ", argv[i]);			fprintf(stderr, "\n%s (%s-%s-%s)\n",				version_string,				HOST_CPU, HOST_VENDOR, HOST_OS);		}	}	/* Find name of root directory. */	node = findequal(arg);	if (!use_graft_ptrs)		node = NULL;	if (node == NULL) {		node = arg;	} else {		/*		 * Remove '\\' escape chars which are located		 * before '\\' and '=' chars		 */		node = escstrcpy(nodename, ++node);	}	/*	 * See if boot catalog file exists in root directory, if not we will	 * create it.	 */	if (use_eltorito)		init_boot_catalog(node);	/*	 * 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(node, &statbuf);	add_directory_hash(statbuf.st_dev, STAT_INODE(statbuf));	memset(&de, 0, sizeof(de));	de.filedir = root;	/* We need this to bootstrap */	if (cdrecord_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. */#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);#ifdef APPLE_HYB	/* may need to set window layout of the volume */	if (root_info)		set_root_info(root_info);#endif /* APPLE_HYB */	/*	 * 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 = findequal(arg);		if (!use_graft_ptrs)			node = NULL;		/*		 * Remove '\\' escape chars which are located		 * before '\\' and '=' chars ---> below in escstrcpy()		 */		short_name = NULL;		if (node != NULL) {			char		*pnt;			char		*xpnt;			*node = '\0';			escstrcpy(graft_point, arg);			*node = '=';			node = escstrcpy(nodename, ++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++;					}				}#ifdef APPLE_HYB				if (!insert_file_entry(graft_dir, node,								short_name, 0))#else				if (!insert_file_entry(graft_dir, node,								short_name))#endif	/* APPLE_HYB */				{					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		}		close_merge_image();		/*		 * set up parent_dir and filedir in relocated entries which		 * were read from previous session so that		 * finish_cl_pl_entries can do its job		 */		match_cl_re_entries();	}#ifdef APPLE_HYB	/* free up any HFS filename mapping memory */	if (apple_both)		clean_hfs();#endif	/* APPLE_HYB */	/* 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();	/*	 * Free up any matching memory	 */	for (n=0;n<MAX_MAT;n++)		gen_del_match(n);#ifdef SORTING	del_sort();#endif /* SORTING */	/*	 * 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(__CYGWIN__) || 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.	 */#ifdef APPLE_HYB#ifdef PREP_BOOT	if (apple_hyb || use_prep_boot)#else	/* PREP_BOOT */	if (apple_hyb)#endif	/* PREP_BOOT */		outputlist_insert(&hfs_desc);#endif	/* APPLE_HYB */	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);	/* Insert the version desctiptor. */	outputlist_insert(&version_desc);	/* Now start with path tables and directory tree info. */	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 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -