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

📄 disklabel.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 3 页
字号:
				}			v = atoi(tp);			if ((unsigned)v >= DKMAXTYPES)				fprintf(stderr, "line %d:%s %d\n", lineno,				    "Warning, unknown disk type", v);			lp->d_type = v;			continue;		}		if (streq(cp, "flags")) {			for (v = 0; (cp = tp) && *cp != '\0';) {				tp = word(cp);				if (streq(cp, "removeable"))					v |= D_REMOVABLE;				else if (streq(cp, "ecc"))					v |= D_ECC;				else if (streq(cp, "badsect"))					v |= D_BADSECT;				else {					fprintf(stderr,					    "line %d: %s: bad flag\n",					    lineno, cp);					errors++;				}			}			lp->d_flags = v;			continue;		}		if (streq(cp, "drivedata")) {			register int i;			for (i = 0; (cp = tp) && *cp != '\0' && i < NDDATA;) {				lp->d_drivedata[i++] = atoi(cp);				tp = word(cp);			}			continue;		}		if (sscanf(cp, "%d partitions", &v) == 1) {			if (v == 0 || (unsigned)v > MAXPARTITIONS) {				fprintf(stderr,				    "line %d: bad # of partitions\n", lineno);				lp->d_npartitions = MAXPARTITIONS;				errors++;			} else				lp->d_npartitions = v;			continue;		}		if (tp == NULL)			tp = "";		if (streq(cp, "disk")) {			strncpy(lp->d_typename, tp, sizeof (lp->d_typename));			continue;		}		if (streq(cp, "label")) {			strncpy(lp->d_packname, tp, sizeof (lp->d_packname));			continue;		}		if (streq(cp, "bytes/sector")) {			v = atoi(tp);			if (v <= 0 || (v % 512) != 0) {				fprintf(stderr,				    "line %d: %s: bad sector size\n",				    lineno, tp);				errors++;			} else				lp->d_secsize = v;			continue;		}		if (streq(cp, "sectors/track")) {			v = atoi(tp);			if (v <= 0) {				fprintf(stderr, "line %d: %s: bad %s\n",				    lineno, tp, cp);				errors++;			} else				lp->d_nsectors = v;			continue;		}		if (streq(cp, "sectors/cylinder")) {			v = atoi(tp);			if (v <= 0) {				fprintf(stderr, "line %d: %s: bad %s\n",				    lineno, tp, cp);				errors++;			} else				lp->d_secpercyl = v;			continue;		}		if (streq(cp, "tracks/cylinder")) {			v = atoi(tp);			if (v <= 0) {				fprintf(stderr, "line %d: %s: bad %s\n",				    lineno, tp, cp);				errors++;			} else				lp->d_ntracks = v;			continue;		}		if (streq(cp, "cylinders")) {			v = atoi(tp);			if (v <= 0) {				fprintf(stderr, "line %d: %s: bad %s\n",				    lineno, tp, cp);				errors++;			} else				lp->d_ncylinders = v;			continue;		}		if (streq(cp, "rpm")) {			v = atoi(tp);			if (v <= 0) {				fprintf(stderr, "line %d: %s: bad %s\n",				    lineno, tp, cp);				errors++;			} else				lp->d_rpm = v;			continue;		}		if (streq(cp, "interleave")) {			v = atoi(tp);			if (v <= 0) {				fprintf(stderr, "line %d: %s: bad %s\n",				    lineno, tp, cp);				errors++;			} else				lp->d_interleave = v;			continue;		}		if (streq(cp, "trackskew")) {			v = atoi(tp);			if (v < 0) {				fprintf(stderr, "line %d: %s: bad %s\n",				    lineno, tp, cp);				errors++;			} else				lp->d_trackskew = v;			continue;		}		if (streq(cp, "cylinderskew")) {			v = atoi(tp);			if (v < 0) {				fprintf(stderr, "line %d: %s: bad %s\n",				    lineno, tp, cp);				errors++;			} else				lp->d_cylskew = v;			continue;		}		if (streq(cp, "headswitch")) {			v = atoi(tp);			if (v < 0) {				fprintf(stderr, "line %d: %s: bad %s\n",				    lineno, tp, cp);				errors++;			} else				lp->d_headswitch = v;			continue;		}		if (streq(cp, "track-to-track seek")) {			v = atoi(tp);			if (v < 0) {				fprintf(stderr, "line %d: %s: bad %s\n",				    lineno, tp, cp);				errors++;			} else				lp->d_trkseek = v;			continue;		}		if ('a' <= *cp && *cp <= 'z' && cp[1] == '\0') {			unsigned part = *cp - 'a';			if (part > lp->d_npartitions) {				fprintf(stderr,				    "line %d: bad partition name\n", lineno);				errors++;				continue;			}			pp = &lp->d_partitions[part];#define NXTNUM(n) { \	cp = tp, tp = word(cp); \	if (tp == NULL) \		tp = cp; \	(n) = atoi(cp); \     }			NXTNUM(v);			if (v < 0) {				fprintf(stderr,				    "line %d: %s: bad partition size\n",				    lineno, cp);				errors++;			} else				pp->p_size = v;			NXTNUM(v);			if (v < 0) {				fprintf(stderr,				    "line %d: %s: bad partition offset\n",				    lineno, cp);				errors++;			} else				pp->p_offset = v;			cp = tp, tp = word(cp);			cpp = fstypenames;			for (; cpp < &fstypenames[FSMAXTYPES]; cpp++)				if ((s = *cpp) && streq(s, cp)) {					pp->p_fstype = cpp - fstypenames;					goto gottype;				}			if (isdigit(*cp))				v = atoi(cp);			else				v = FSMAXTYPES;			if ((unsigned)v >= FSMAXTYPES) {				fprintf(stderr, "line %d: %s %s\n", lineno,				    "Warning, unknown filesystem type", cp);				v = FS_UNUSED;			}			pp->p_fstype = v;	gottype:			switch (pp->p_fstype) {			case FS_UNUSED:				/* XXX */				NXTNUM(pp->p_fsize);				if (pp->p_fsize == 0)					break;				NXTNUM(v);				pp->p_frag = v / pp->p_fsize;				break;			case FS_BSDFFS:				NXTNUM(pp->p_fsize);				if (pp->p_fsize == 0)					break;				NXTNUM(v);				pp->p_frag = v / pp->p_fsize;				NXTNUM(pp->p_cpg);				break;			default:				break;			}			continue;		}		fprintf(stderr, "line %d: %s: Unknown disklabel field\n",		    lineno, cp);		errors++;	next:		;	}	errors += checklabel(lp);	return (errors == 0);}/* * Check disklabel for errors and fill in * derived fields according to supplied values. */checklabel(lp)	register struct disklabel *lp;{	register struct partition *pp;	int i, errors = 0;	char part;	if (lp->d_secsize == 0) {		fprintf(stderr, "sector size %d\n", lp->d_secsize);		return (1);	}	if (lp->d_nsectors == 0) {		fprintf(stderr, "sectors/track %d\n", lp->d_nsectors);		return (1);	}	if (lp->d_ntracks == 0) {		fprintf(stderr, "tracks/cylinder %d\n", lp->d_ntracks);		return (1);	}	if  (lp->d_ncylinders == 0) {		fprintf(stderr, "cylinders/unit %d\n", lp->d_ncylinders);		errors++;	}	if (lp->d_rpm == 0)		Warning("revolutions/minute %d", lp->d_rpm);	if (lp->d_secpercyl == 0)		lp->d_secpercyl = lp->d_nsectors * lp->d_ntracks;	if (lp->d_secperunit == 0)		lp->d_secperunit = lp->d_secpercyl * lp->d_ncylinders;	if (lp->d_bbsize == 0) {		fprintf(stderr, "boot block size %d\n", lp->d_bbsize);		errors++;	} else if (lp->d_bbsize % lp->d_secsize)		Warning("boot block size %% sector-size != 0");	if (lp->d_sbsize == 0) {		fprintf(stderr, "super block size %d\n", lp->d_sbsize);		errors++;	} else if (lp->d_sbsize % lp->d_secsize)		Warning("super block size %% sector-size != 0");	if (lp->d_npartitions > MAXPARTITIONS)		Warning("number of partitions (%d) > MAXPARTITIONS (%d)",		    lp->d_npartitions, MAXPARTITIONS);	for (i = 0; i < lp->d_npartitions; i++) {		part = 'a' + i;		pp = &lp->d_partitions[i];		if (pp->p_size == 0 && pp->p_offset != 0)			Warning("partition %c: size 0, but offset %d",			    part, pp->p_offset);#ifdef notdef		if (pp->p_size % lp->d_secpercyl)			Warning("partition %c: size %% cylinder-size != 0",			    part);		if (pp->p_offset % lp->d_secpercyl)			Warning("partition %c: offset %% cylinder-size != 0",			    part);#endif		if (pp->p_offset > lp->d_secperunit) {			fprintf(stderr,			    "partition %c: offset past end of unit\n", part);			errors++;		}		if (pp->p_offset + pp->p_size > lp->d_secperunit) {			fprintf(stderr,			    "partition %c: partition extends past end of unit\n",			    part);			errors++;		}	}	for (; i < MAXPARTITIONS; i++) {		part = 'a' + i;		pp = &lp->d_partitions[i];		if (pp->p_size || pp->p_offset)			Warning("unused partition %c: size %d offset %d",			    'a' + i, pp->p_size, pp->p_offset);	}	return (errors);}/* * If we are installing a boot program that doesn't fit in d_bbsize * we need to mark those partitions that the boot overflows into. * This allows newfs to prevent creation of a filesystem where it might * clobber bootstrap code. */setbootflag(lp)	register struct disklabel *lp;{	register struct partition *pp;	int i, errors = 0;	char part;	u_long boffset;	if (bootbuf == 0)		return;	boffset = bootsize / lp->d_secsize;	for (i = 0; i < lp->d_npartitions; i++) {		part = 'a' + i;		pp = &lp->d_partitions[i];		if (pp->p_size == 0)			continue;		if (boffset <= pp->p_offset) {			if (pp->p_fstype == FS_BOOT)				pp->p_fstype = FS_UNUSED;		} else if (pp->p_fstype != FS_BOOT) {			if (pp->p_fstype != FS_UNUSED) {				fprintf(stderr,					"boot overlaps used partition %c\n",					part);				errors++;			} else {				pp->p_fstype = FS_BOOT;				Warning("boot overlaps partition %c, %s",					part, "marked as FS_BOOT");			}		}	}	if (errors) {		fprintf(stderr, "Cannot install boot program\n");		exit(4);	}}/*VARARGS1*/Warning(fmt, a1, a2, a3, a4, a5)	char *fmt;{	fprintf(stderr, "Warning, ");	fprintf(stderr, fmt, a1, a2, a3, a4, a5);	fprintf(stderr, "\n");}Perror(str)	char *str;{	fputs("disklabel: ", stderr); perror(str);	exit(4);}usage(){#if NUMBOOT > 0	fprintf(stderr,"%s\n\t%s\n%s\n\t%s\n%s\n\t%s\n%s\n\t%s\n%s\n\t%s\n%s\n\t%s\n%s\n\t%s\n%s\n\t%s\n","usage: disklabel [-r] disk",		"(to read label)","or disklabel -w [-r] disk type [ packid ]",		"(to write label with existing boot program)","or disklabel -e [-r] disk",		"(to edit label)","or disklabel -R [-r] disk protofile",		"(to restore label with existing boot program)",#if NUMBOOT > 1"or disklabel -B [ -b boot1 [ -s boot2 ] ] disk [ type ]",		"(to install boot program with existing label)","or disklabel -w -B [ -b boot1 [ -s boot2 ] ] disk type [ packid ]",		"(to write label and boot program)","or disklabel -R -B [ -b boot1 [ -s boot2 ] ] disk protofile [ type ]",		"(to restore label and boot program)",#else"or disklabel -B [ -b bootprog ] disk [ type ]",		"(to install boot program with existing on-disk label)","or disklabel -w -B [ -b bootprog ] disk type [ packid ]",		"(to write label and install boot program)","or disklabel -R -B [ -b bootprog ] disk protofile [ type ]",		"(to restore label and install boot program)",#endif"or disklabel [-NW] disk",		"(to write disable/enable label)");#else	fprintf(stderr, "%-43s%s\n%-43s%s\n%-43s%s\n%-43s%s\n%-43s%s\n","usage: disklabel [-r] disk", "(to read label)","or disklabel -w [-r] disk type [ packid ]", "(to write label)","or disklabel -e [-r] disk", "(to edit label)","or disklabel -R [-r] disk protofile", "(to restore label)","or disklabel [-NW] disk", "(to write disable/enable label)");#endif	exit(1);}

⌨️ 快捷键说明

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