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

📄 rock.c

📁 创建一个符合iso-9660标准的iso文件系统
💻 C
📖 第 1 页 / 共 2 页
字号:
			int             sl_bytes = 0;			for (cpnt1 = cpnt; *cpnt1 != '\0'; cpnt1++) {				if (*cpnt1 == '/') {					sl_bytes += 4;				} else {					sl_bytes += 1;				}			}			if (sl_bytes > 250) {				/*				 * the symbolic link won't fit into one				 * SL System Use Field print an error message				 * and continue with splited one				 */				fprintf(stderr,				"symbolic link ``%s'' to long for one SL System Use Field, splitting",								cpnt);			}			if (MAYBE_ADD_CE_ENTRY(SL_SIZE + sl_bytes))				add_CE_entry();		}		while (nchar) {			if (MAYBE_ADD_CE_ENTRY(SL_SIZE))				add_CE_entry();			Rock[ipnt++] = 'S';			Rock[ipnt++] = 'L';			lenpos = ipnt;			Rock[ipnt++] = SL_SIZE;			Rock[ipnt++] = SU_VERSION;			Rock[ipnt++] = 0;	/* Flags */			lenval = 5;			while (*cpnt) {				cpnt1 = (unsigned char *)						strchr((char *)cpnt, '/');				if (cpnt1) {					nchar--;					*cpnt1 = 0;				};				/*				 * We treat certain components in a special				 * way.				 */				if (cpnt[0] == '.' && cpnt[1] == '.' &&								cpnt[2] == 0) {					if (MAYBE_ADD_CE_ENTRY(2))						add_CE_entry();					Rock[ipnt++] = SL_PARENT;					Rock[ipnt++] = 0; /* length is zero */					lenval += 2;					nchar -= 2;				} else if (cpnt[0] == '.' && cpnt[1] == 0) {					if (MAYBE_ADD_CE_ENTRY(2))						add_CE_entry();					Rock[ipnt++] = SL_CURRENT;					Rock[ipnt++] = 0; /* length is zero */					lenval += 2;					nchar -= 1;				} else if (cpnt[0] == 0) {					if (MAYBE_ADD_CE_ENTRY(2))						add_CE_entry();					Rock[ipnt++] = SL_ROOT;					Rock[ipnt++] = 0; /* length is zero */					lenval += 2;				} else {					/*					 * If we do not have enough room for a					 * component, start a new continuations					 * segment now					 */					if (split_SL_component ?						MAYBE_ADD_CE_ENTRY(6) :						MAYBE_ADD_CE_ENTRY(6 + strlen((char *) cpnt))) {						add_CE_entry();						if (cpnt1) {							*cpnt1 = '/';							nchar++;							/*							 * A kluge so that we							 * can restart properly							 */							cpnt1 = NULL;						}						break;					}					j0 = strlen((char *) cpnt);					while (j0) {						j1 = j0;						if (j1 > 0xf8)							j1 = 0xf8;						need_ce = 0;						if (j1 + currlen + CE_SIZE +						   (ipnt - recstart) >								reclimit) {							j1 = reclimit -								currlen -								CE_SIZE -							     (ipnt - recstart);							need_ce++;						}						Rock[ipnt++] =							(j1 != j0 ?							 SL_CONTINUE : 0);						Rock[ipnt++] = j1;						strncpy((char *)Rock + ipnt,							(char *) cpnt, j1);						ipnt += j1;						lenval += j1 + 2;						cpnt += j1;						/*						 * Number we processed						 * this time						 */						nchar -= j1;						j0 -= j1;						if (need_ce) {							add_CE_entry();							if (cpnt1) {								*cpnt1 = '/';								nchar++;								/*								 * A kluge so								 * that we can								 * restart								 * properly								 */								cpnt1 = NULL;							}							break;						}					}				};				if (cpnt1) {					cpnt = cpnt1 + 1;				} else					break;			}			Rock[lenpos] = lenval;			if (nchar) {				/* We need another SL entry */				Rock[lenpos + 2] = SL_CONTINUE;			}		}	/* while nchar */	}	/* Is a symbolic link */#endif	/* S_IFLNK */	/* Add in the Rock Ridge TF time field */	if (MAYBE_ADD_CE_ENTRY(TF_SIZE))		add_CE_entry();	Rock[ipnt++] = 'T';	Rock[ipnt++] = 'F';	Rock[ipnt++] = TF_SIZE;	Rock[ipnt++] = SU_VERSION;#ifdef __QNX__	Rock[ipnt++] = 0x0f;#else	Rock[ipnt++] = 0x0e;#endif	flagval |= (1 << 7);#ifdef __QNX__	iso9660_date((char *) &Rock[ipnt], lstatbuf->st_ftime);	ipnt += 7;#endif	iso9660_date((char *) &Rock[ipnt], lstatbuf->st_mtime);	ipnt += 7;	iso9660_date((char *) &Rock[ipnt], lstatbuf->st_atime);	ipnt += 7;	iso9660_date((char *) &Rock[ipnt], lstatbuf->st_ctime);	ipnt += 7;	/* Add in the Rock Ridge RE time field */	if (deep_opt & NEED_RE) {		if (MAYBE_ADD_CE_ENTRY(RE_SIZE))			add_CE_entry();		Rock[ipnt++] = 'R';		Rock[ipnt++] = 'E';		Rock[ipnt++] = RE_SIZE;		Rock[ipnt++] = SU_VERSION;		flagval |= (1 << 6);	};	/* Add in the Rock Ridge PL record, if required. */	if (deep_opt & NEED_PL) {		if (MAYBE_ADD_CE_ENTRY(PL_SIZE))			add_CE_entry();		Rock[ipnt++] = 'P';		Rock[ipnt++] = 'L';		Rock[ipnt++] = PL_SIZE;		Rock[ipnt++] = SU_VERSION;		set_733((char *) Rock + ipnt, 0);		ipnt += 8;		flagval |= (1 << 5);	};	/* Add in the Rock Ridge CL field, if required. */	if (deep_opt & NEED_CL) {		if (MAYBE_ADD_CE_ENTRY(CL_SIZE))			add_CE_entry();		Rock[ipnt++] = 'C';		Rock[ipnt++] = 'L';		Rock[ipnt++] = CL_SIZE;		Rock[ipnt++] = SU_VERSION;		set_733((char *) Rock + ipnt, 0);		ipnt += 8;		flagval |= (1 << 4);	};#ifndef VMS	/*	 * If transparent compression was requested, fill in the correct field	 * for this file	 */	if (transparent_compression &&		S_ISREG(lstatbuf->st_mode) &&		strlen(name) > 3 &&		strcmp(name + strlen(name) - 3, ".gZ") == 0) {		FILE           *zipfile;		char           *checkname;		unsigned int    file_size;		unsigned char   header[8];		int             OK_flag;		/*		 * First open file and verify that the correct algorithm was		 * used		 */		file_size = 0;		OK_flag = 1;		zipfile = fopen(whole_name, "rb");		fread(header, 1, sizeof(header), zipfile);		/* Check some magic numbers from gzip. */		if (header[0] != 0x1f || header[1] != 0x8b || header[2] != 8)			OK_flag = 0;		/* Make sure file was blocksized. */		if (((header[3] & 0x40) == 0))			OK_flag = 0;		/* OK, now go to the end of the file and get some more info */		if (OK_flag) {			int	status;			status = (long) lseek(fileno(zipfile), (off_t)(-8),								SEEK_END);			if (status == -1)				OK_flag = 0;		}		if (OK_flag) {			if (read(fileno(zipfile), (char *) header,					sizeof(header)) != sizeof(header)) {				OK_flag = 0;			} else {				int             blocksize;				blocksize = (header[3] << 8) | header[2];				file_size = ((unsigned int) header[7] << 24) |					((unsigned int) header[6] << 16) |					((unsigned int) header[5] << 8) |							header[4];#if 0				fprintf(stderr, "Blocksize = %d %d\n",						blocksize, file_size);#endif				if (blocksize != SECTOR_SIZE)					OK_flag = 0;			}		}		fclose(zipfile);		checkname = strdup(whole_name);		checkname[strlen(whole_name) - 3] = 0;		zipfile = fopen(checkname, "rb");		if (zipfile) {			OK_flag = 0;#ifdef	USE_LIBSCHILY			errmsg(			"Unable to insert transparent compressed file - name conflict\n");#else			fprintf(stderr,			"Unable to insert transparent compressed file - name conflict\n");#endif			fclose(zipfile);		}		free(checkname);		if (OK_flag) {			if (MAYBE_ADD_CE_ENTRY(ZZ_SIZE))				add_CE_entry();			Rock[ipnt++] = 'Z';			Rock[ipnt++] = 'Z';			Rock[ipnt++] = ZZ_SIZE;			Rock[ipnt++] = SU_VERSION;			Rock[ipnt++] = 'g';	/* Identify compression						   technique used */			Rock[ipnt++] = 'z';			Rock[ipnt++] = 3;			set_733((char *) Rock + ipnt, file_size); /* Real file size */			ipnt += 8;		};	}#endif	/*	 * Add in the Rock Ridge CE field, if required.  We use  this for the	 * extension record that is stored in the root directory.	 */	if (deep_opt & NEED_CE)		add_CE_entry();	/*	 * Done filling in all of the fields.  Now copy it back to a buffer	 * for the file in question.	 */	/* Now copy this back to the buffer for the file */	Rock[flagpos] = flagval;	/* If there was a CE, fill in the size field */	if (recstart)		set_733((char *) Rock + recstart - 8, ipnt - recstart);	s_entry->rr_attributes = (unsigned char *) e_malloc(ipnt);	s_entry->total_rr_attr_size = ipnt;	s_entry->rr_attr_size = (mainrec ? mainrec : ipnt);	memcpy(s_entry->rr_attributes, Rock, ipnt);	return ipnt;}/* * Guaranteed to  return a single sector with the relevant info */char *generate_rr_extension_record(id, descriptor, source, size)	char	*id;	char	*descriptor;	char	*source;	int	*size;{	int             lipnt = 0;	char           *pnt;	int             len_id,	                len_des,	                len_src;	len_id = strlen(id);	len_des = strlen(descriptor);	len_src = strlen(source);	Rock[lipnt++] = 'E';	Rock[lipnt++] = 'R';	Rock[lipnt++] = ER_SIZE + len_id + len_des + len_src;	Rock[lipnt++] = 1;	Rock[lipnt++] = len_id;	Rock[lipnt++] = len_des;	Rock[lipnt++] = len_src;	Rock[lipnt++] = 1;	memcpy(Rock + lipnt, id, len_id);	lipnt += len_id;	memcpy(Rock + lipnt, descriptor, len_des);	lipnt += len_des;	memcpy(Rock + lipnt, source, len_src);	lipnt += len_src;	if (lipnt > SECTOR_SIZE) {#ifdef	USE_LIBSCHILY		comerrno(EX_BAD, "Extension record too long\n");#else		fprintf(stderr, "Extension record too long\n");		exit(1);#endif	};	pnt = (char *) e_malloc(SECTOR_SIZE);	memset(pnt, 0, SECTOR_SIZE);	memcpy(pnt, Rock, lipnt);	*size = lipnt;	return pnt;}

⌨️ 快捷键说明

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