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

📄 ubinize.c

📁 mtd-utils 是一套更改linux mtd設備的工具
💻 C
📖 第 1 页 / 共 2 页
字号:
		normsg("volume type was not specified in "		       "section \"%s\", assume \"dynamic\"\n", sname);		vi->type = UBI_VID_DYNAMIC;	} else {		if (!strcmp(p, "static"))			vi->type = UBI_VID_STATIC;		else if (!strcmp(p, "dynamic"))			vi->type = UBI_VID_DYNAMIC;		else			return errmsg("invalid volume type \"%s\" in section  \"%s\"",				      p, sname);	}	verbose(args.verbose, "volume type: %s",		vi->type == UBI_VID_DYNAMIC ? "dynamic" : "static");	/* Fetch the name of the volume image file */	sprintf(buf, "%s:image", sname);	p = iniparser_getstring(args.dict, buf, NULL);	if (p) {		*img = p;		if (stat(p, st))			return sys_errmsg("cannot stat \"%s\" referred from section \"%s\"",					  p, sname);		if (st->st_size == 0)			return errmsg("empty file \"%s\" referred from section \"%s\"",				       p, sname);	} else if (vi->type == UBI_VID_STATIC)		return errmsg("image is not specified for static volume in section \"%s\"",			      sname);	/* Fetch volume id */	sprintf(buf, "%s:vol_id", sname);	vi->id = iniparser_getint(args.dict, buf, -1);	if (vi->id == -1)		return errmsg("\"vol_id\" key not found in section  \"%s\"", sname);	if (vi->id < 0)		return errmsg("negative volume ID %d in section \"%s\"",			      vi->id, sname);	if (vi->id >= ui->max_volumes)		return errmsg("too high volume ID %d in section \"%s\", max. is %d",			      vi->id, sname, ui->max_volumes);	verbose(args.verbose, "volume ID: %d", vi->id);	/* Fetch volume size */	sprintf(buf, "%s:vol_size", sname);	p = iniparser_getstring(args.dict, buf, NULL);	if (p) {		vi->bytes = ubiutils_get_bytes(p);		if (vi->bytes <= 0)			return errmsg("bad \"vol_size\" key value \"%s\" (section \"%s\")",				      p, sname);		/* Make sure the image size is not larger than volume size */		if (*img && st->st_size > vi->bytes)			return errmsg("error in section \"%s\": size of the image file "				      "\"%s\" is %lld, which is larger than volume size %lld",				      sname, *img, (long long)st->st_size, vi->bytes);		verbose(args.verbose, "volume size: %lld bytes", vi->bytes);	} else {		struct stat st;		if (!*img)			return errmsg("neither image file (\"image=\") nor volume size "				      "(\"vol_size=\") specified in section \"%s\"", sname);		if (stat(*img, &st))			return sys_errmsg("cannot stat \"%s\"", *img);		vi->bytes = st.st_size;		if (vi->bytes == 0)			return errmsg("file \"%s\" referred from section \"%s\" is empty",				      *img, sname);		normsg_cont("volume size was not specified in section \"%s\", assume"			    " minimum to fit image \"%s\"", sname, *img);		ubiutils_print_bytes(vi->bytes, 1);		printf("\n");	}	/* Fetch volume name */	sprintf(buf, "%s:vol_name", sname);	p = iniparser_getstring(args.dict, buf, NULL);	if (!p)		return errmsg("\"vol_name\" key not found in section \"%s\"", sname);	vi->name = p;	vi->name_len = strlen(p);	if (vi->name_len > UBI_VOL_NAME_MAX)		return errmsg("too long volume name in section \"%s\", max. is %d characters",			      vi->name, UBI_VOL_NAME_MAX);	verbose(args.verbose, "volume name: %s", p);	/* Fetch volume alignment */	sprintf(buf, "%s:vol_alignment", sname);	vi->alignment = iniparser_getint(args.dict, buf, -1);	if (vi->alignment == -1)		vi->alignment = 1;	else if (vi->id < 0)		return errmsg("negative volume alignement %d in section \"%s\"",			      vi->alignment, sname);	verbose(args.verbose, "volume alignment: %d", vi->alignment);	/* Fetch volume flags */	sprintf(buf, "%s:vol_flags", sname);	p = iniparser_getstring(args.dict, buf, NULL);	if (p) {		if (!strcmp(p, "autoresize")) {			verbose(args.verbose, "autoresize flags found");			vi->flags |= UBI_VTBL_AUTORESIZE_FLG;		} else {			return errmsg("unknown flags \"%s\" in section \"%s\"",				      p, sname);		}	}	/* Initialize the rest of the volume information */	vi->data_pad = ui->leb_size % vi->alignment;	vi->usable_leb_size = ui->leb_size - vi->data_pad;	if (vi->type == UBI_VID_DYNAMIC)		vi->used_ebs = (vi->bytes + vi->usable_leb_size - 1) / vi->usable_leb_size;	else		vi->used_ebs = (st->st_size + vi->usable_leb_size - 1) / vi->usable_leb_size;	vi->compat = 0;	return 0;}int main(int argc, char * const argv[]){	int err = -1, sects, i, autoresize_was_already = 0;	struct ubigen_info ui;	struct ubi_vtbl_record *vtbl;	struct ubigen_vol_info *vi;	off_t seek;	err = parse_opt(argc, argv);	if (err)		return -1;	ubigen_info_init(&ui, args.peb_size, args.min_io_size,			 args.subpage_size, args.vid_hdr_offs,			 args.ubi_ver);	verbose(args.verbose, "LEB size:      %d", ui.leb_size);	verbose(args.verbose, "PEB size:      %d", ui.peb_size);	verbose(args.verbose, "min. I/O size: %d", ui.min_io_size);	verbose(args.verbose, "sub-page size: %d", ui.min_io_size);	verbose(args.verbose, "VID offset:    %d", ui.vid_hdr_offs);	verbose(args.verbose, "data offset:   %d", ui.data_offs);	vtbl = ubigen_create_empty_vtbl(&ui);	if (!vtbl)		goto out;	args.dict = iniparser_load(args.f_in);	if (!args.dict) {		errmsg("cannot load the input ini file \"%s\"", args.f_in);		goto out_vtbl;	}	verbose(args.verbose, "loaded the ini-file \"%s\"", args.f_in);	/* Each section describes one volume */	sects = iniparser_getnsec(args.dict);	if (sects == -1) {		errmsg("ini-file parsing error (iniparser_getnsec)");		goto out_dict;	}	verbose(args.verbose, "count of sections: %d", sects);	if (sects == 0) {		errmsg("no sections found the ini-file \"%s\"", args.f_in);		goto out_dict;	}	if (sects > ui.max_volumes) {		errmsg("too many sections (%d) in the ini-file \"%s\"",		       sects, args.f_in);		normsg("each section corresponds to an UBI volume, maximum "		       "count of volumes is %d", ui.max_volumes);		goto out_dict;	}	vi = malloc(sizeof(struct ubigen_vol_info) * sects);	if (!vi) {		errmsg("cannot allocate memory");		goto out_dict;	}	/*	 * Skip 2 PEBs at the beginning of the file for the volume table which	 * will be written later.	 */	seek = ui.peb_size * 2;	if (lseek(args.out_fd, seek, SEEK_SET) != seek) {		sys_errmsg("cannot seek file \"%s\"", args.f_out);		goto out_free;	}	for (i = 0; i < sects; i++) {		const char *sname = iniparser_getsecname(args.dict, i);		const char *img = NULL;		struct stat st;		int fd, j;		if (!sname) {			errmsg("ini-file parsing error (iniparser_getsecname)");			goto out_free;		}		if (args.verbose)			printf("\n");		verbose(args.verbose, "parsing section \"%s\"", sname);		err = read_section(&ui, sname, &vi[i], &img, &st);		if (err == -1)			goto out_free;		verbose(args.verbose, "adding volume %d", vi[i].id);		/*		 * Make sure that volume ID and name is unique and that only		 * one volume has auto-resize flag		 */		for (j = 0; j < i; j++) {			if (vi[i].id == vi[j].id) {				errmsg("volume IDs must be unique, but ID %d "				       "in section \"%s\" is not",				       vi[i].id, sname);				goto out_free;			}			if (!strcmp(vi[i].name, vi[j].name)) {				errmsg("volume name must be unique, but name "				       "\"%s\" in section \"%s\" is not",				       vi[i].name, sname);				goto out_free;			}		}		if (vi[i].flags & UBI_VTBL_AUTORESIZE_FLG) {			if (autoresize_was_already)				return errmsg("only one volume is allowed "					      "to have auto-resize flag");			autoresize_was_already = 1;		}		err = ubigen_add_volume(&ui, &vi[i], vtbl);		if (err) {			errmsg("cannot add volume for section \"%s\"", sname);			goto out_free;		}		fd = open(img, O_RDONLY);		if (fd == -1) {			sys_errmsg("cannot open \"%s\"", img);			goto out_free;		}		verbose(args.verbose, "writing volume %d", vi[i].id);		verbose(args.verbose, "image file: %s", img);		err = ubigen_write_volume(&ui, &vi[i], args.ec, st.st_size, fd, args.out_fd);		close(fd);		if (err) {			errmsg("cannot write volume for section \"%s\"", sname);			goto out_free;		}		if (args.verbose)			printf("\n");	}	verbose(args.verbose, "writing layout volume");	err = ubigen_write_layout_vol(&ui, 0, 1, args.ec, args.ec, vtbl, args.out_fd);	if (err) {		errmsg("cannot write layout volume");		goto out_free;	}	verbose(args.verbose, "done");	free(vi);	iniparser_freedict(args.dict);	free(vtbl);	close(args.out_fd);	return 0;out_free:	free(vi);out_dict:	iniparser_freedict(args.dict);out_vtbl:	free(vtbl);out:	close(args.out_fd);	remove(args.f_out);	return err;}

⌨️ 快捷键说明

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