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

📄 volume.c

📁 创建一个符合iso-9660标准的iso文件系统
💻 C
📖 第 1 页 / 共 2 页
字号:
	/* store the current HFS directory ID */	if ((id = hfs_getcwd(vol)) == 0)		return (-1);	if (verbose > 1)		fprintf(stderr, "HFS scanning %s\n", node->whole_name);	/* loop through the ISO directory entries and process files */	for (s_entry = node->contents; s_entry; s_entry = s_entry->next) {		/* ignore directory and associated (rsrc) files */		if (s_entry->isorec.flags[0] & (ISO_DIRECTORY|ISO_ASSOCIATED))			continue;		/* ignore any non-Mac type file */		if (!s_entry->hfs_ent)			continue;		/*		 * ignore if from a previous session		 * - should be trapped above		 */		if (s_entry->starting_block < session_start)			continue;#ifdef DEBUG		fprintf(stderr, " Name = %s", s_entry->whole_name);		fprintf(stderr, "   Startb =  %d\n", s_entry->starting_block);#endif	/* DEBUG */		ent = s_entry->hfs_ent;		/* create file */		i = HFS_MAX_FLEN - strlen(ent->name);		new_name = 0;		tens = TEN;		digits = 1;		while (1) {			/*			 * try to open file - if it exists,			 * then append '_' to the name and try again			 */			errno = 0;			if ((hfs_create(vol, ent->name, ent->u.file.type,						ent->u.file.creator)) < 0) {				if (errno != EEXIST) {					/*					 * not an "exist" error, or we can't					 * append as the filename is already					 * HFS_MAX_FLEN chars					 */					sprintf(hce->error,						"can't HFS create file %s",						s_entry->whole_name);					return (-1);				} else if (i == 0) {					/*					 * File name at max HFS length					 * - make unique name					 */					if (!new_name)						new_name++;					sprintf(ent->name +						HFS_MAX_FLEN - digits - 1,						"%s%d", LCHAR, new_name);					new_name++;					if (new_name == tens) {						tens *= TEN;						digits++;					}				} else {					/* append '_' to get new name */					strcat(ent->name, LCHAR);					i--;					new_name = 1;				}			} else				break;		}		/* warn that we have a new name */		if (new_name && verbose > 0) {			fprintf(stderr, "Using HFS name: %s for %s\n",				ent->name,				s_entry->whole_name);		}		/* open file */		if ((hfp = hfs_open(vol, ent->name)) == 0) {			sprintf(hce->error, "can't HFS open %s",				s_entry->whole_name);			return (-1);		}		/* if it has a data fork, then "write" it out */		if (ent->u.file.dsize)			write_fork(hfp, ent->u.file.dsize);		/* if it has a resource fork, set the fork and "write" it out */		if (ent->u.file.rsize) {			if ((hfs_setfork(hfp, 1)) < 0)				return (-1);			write_fork(hfp, ent->u.file.rsize);		}		/* make file invisible if ISO9660 hidden */		if (s_entry->de_flags & HIDDEN_FILE)			ent->fdflags |= HFS_FNDR_ISINVISIBLE;		/* update any HFS file attributes */		if ((hfs_fsetattr(hfp, ent)) < 0) {			sprintf(hce->error, "can't HFS set attributes %s",				s_entry->whole_name);			return (-1);		}		/*		 * get the ISO starting block of data fork (may be zero)		 * and convert to the equivalent HFS block		 */		if (ent->u.file.dsize) {			dext = (s_entry->starting_block - session_start) *								HFS_BLK_CONV;		} else {			dext = 0;		}		/*		 * if the file has a resource fork (associated file),		 * get it's ISO starting block and convert as above		 */		if (s_entry->assoc && ent->u.file.rsize) {			rext =			    (s_entry->assoc->starting_block - session_start) *								HFS_BLK_CONV;		} else {			rext = 0;		}		/* close the file and update the starting blocks */		if (hfs_close(hfp, dext, rext) < 0) {			sprintf(hce->error, "can't HFS close file %s",				s_entry->whole_name);			return (-1);		}	}	/* set folder info and custom icon (if it exists) */	set_dir_info(vol, node);	/*	 * process sub-directories  - have a slight problem here,	 * if the directory had been relocated, then we need to find the	 * real directory - we do this by first finding the	 * real directory_entry, and then finding it's directory info	 */	 /* following code taken from joliet.c */	for (s_entry = node->contents; s_entry; s_entry = s_entry->next) {		if ((s_entry->de_flags & RELOCATED_DIRECTORY) != 0) {			/*			 * if the directory has been reloacted, then search the		   	 * relocated directory for the real entry			 */			for (s_entry1 = reloc_dir->contents; s_entry1;						s_entry1 = s_entry1->next) {				if (s_entry1->parent_rec == s_entry)					break;			}			/* have a problem - can't find the real directory */			if (s_entry1 == NULL) {				sprintf(hce->error,					"can't locate relocated directory %s",					s_entry->whole_name);				return (-1);			}		} else			s_entry1 = s_entry;		/* now have the correct entry - now find the actual directory */		if ((s_entry1->isorec.flags[0] & ISO_DIRECTORY) &&				strcmp(s_entry1->name, ".") &&				strcmp(s_entry1->name, "..")) {			if ((s_entry->de_flags & RELOCATED_DIRECTORY) != 0)				dpnt = reloc_dir->subdir;			else				dpnt = node->subdir;			while (1) {				if (dpnt->self == s_entry1)					break;				dpnt = dpnt->next;				if (!dpnt) {					sprintf(hce->error,					    "can't find directory location %s",							s_entry1->whole_name);					return (-1);				}			}			/*			 * now have the correct directory			 * - so do the HFS stuff			 */			ent = dpnt->hfs_ent;			/*			 * if we don't have hfs entries, then this is a "deep"			 * directory - this will be processed later			 */			if (!ent)				continue;			/* make sub-folder */			i = HFS_MAX_FLEN - strlen(ent->name);			new_name = 0;			tens = TEN;			digits = 1;			while (1) {				/*				 * try to create new directory				 * - if it exists, then append '_' to the name				 * and try again				 */				errno = 0;				if (hfs_mkdir(vol, ent->name) < 0) {					if (errno != EEXIST) {						/*						 * not an "exist" error,						 * or we can't append as the						 * filename is already						 * HFS_MAX_FLEN chars						 */						sprintf(hce->error,						   "can't HFS create folder %s",							s_entry->whole_name);						return (-1);					} else if (i == 0) {						/*						 * File name at max HFS length						 * - make unique name						 */						if (!new_name)							new_name++;						sprintf(ent->name +						    HFS_MAX_FLEN - digits - 1,						    "%s%d", LCHAR, new_name);						new_name++;						if (new_name == tens) {							tens *= TEN;							digits++;						}					} else {						/* append '_' to get new name */						strcat(ent->name, LCHAR);						i--;						new_name = 1;					}				} else					break;			}			/* warn that we have a new name */			if (new_name && verbose > 0) {				fprintf(stderr, "Using HFS name: %s for %s\n",							ent->name,							s_entry->whole_name);			}			/* change to sub-folder */			if (hfs_chdir(vol, ent->name) < 0)				return (-1);			/* recursively copy files ... */			ret = copy_to_mac_vol(vol, dpnt);			if (ret < 0)				return (ret);			/* change back to this folder */			if (hfs_setcwd(vol, id) < 0)				return (-1);		}	}	return (0);}/* *	set_dir_info:	Set directory info for a file - also use a custom *			Icon - if it exists. * *	Sets folder' layout (window layout, view, scroll bars etc) * *	Set the 'HFS_FNDR_HASCUSTOMICON' bit of the folder flags *	if a file called 'Icon\r' exists in the folder * *	Also makes sure the Icon file is invisible *	Don't worry if any of this fails ... * *	Thanks to Rob Leslie <rob@mars.org> for how to do this. */#define	ICON	"Icon"static voidset_dir_info(vol, de)	hfsvol			*vol;	struct directory	*de;{	hfsdirent	*ent = de->hfs_ent;	hfsdirent	ent1;	char		name[HFS_MAX_FLEN + 1];	unsigned short	flags = 0;	memset(&ent1, 0, sizeof(hfsdirent));	sprintf(name, "%s\r", ICON);	/* get the attributes for the Icon file */	if (hfs_stat(vol, name, &ent1) == 0) {		/* make sure it is invisible */		ent1.fdflags |= HFS_FNDR_ISINVISIBLE;		/* set the new attributes for the Icon file */		hfs_setattr(vol, name, &ent1);		/* flag the folder as having a custom icon */		flags |= HFS_FNDR_HASCUSTOMICON;	}	/* make the current folder invisible if ISO9660 hidden */	if (de->self->de_flags & HIDDEN_FILE) {		flags |= HFS_FNDR_ISINVISIBLE;	}	/* may not have an hfs_ent for this directory */	if (ent == NULL) {		ent = &ent1;		memset(ent, 0, sizeof(hfsdirent));		/* get the attributes for the folder */		if(hfs_stat(vol, ":", ent) < 0)			return;	}	/* set HFS_FNDR_HASCUSTOMICON/HFS_FNDR_ISINVISIBLE if needed */	ent->fdflags |= flags;	/* set the new attributes for the folder */	if (hfs_setattr(vol, ":", ent) < 0)	    return;}#endif	/* APPLE_HYB */

⌨️ 快捷键说明

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