コード例 #1
0
ファイル: fsck.cramfs.c プロジェクト: bneijt/util-linux
static void do_uncompress(char *path, int fd, unsigned long offset,
			  unsigned long size)
{
	unsigned long curr = offset + 4 * ((size + blksize - 1) / blksize);

	do {
		unsigned long out = blksize;
		unsigned long next = u32_toggle_endianness(cramfs_is_big_endian,
							   *(uint32_t *)
							   romfs_read(offset));

		if (next > end_data)
			end_data = next;

		offset += 4;
		if (curr == next) {
			if (opt_verbose > 1)
				printf(_("  hole at %ld (%zd)\n"), curr,
				       blksize);
			if (size < blksize)
				out = size;
			memset(outbuffer, 0x00, out);
		} else {
			if (opt_verbose > 1)
				printf(_("  uncompressing block at %ld to %ld (%ld)\n"),
				       curr, next, next - curr);
			out = uncompress_block(romfs_read(curr), next - curr);
		}
		if (size >= blksize) {
			if (out != blksize)
				errx(FSCK_EX_UNCORRECTED,
				     _("non-block (%ld) bytes"), out);
		} else {
			if (out != size)
				errx(FSCK_EX_UNCORRECTED,
				     _("non-size (%ld vs %ld) bytes"), out,
				     size);
		}
		size -= out;
		if (*extract_dir != '\0')
			if (write(fd, outbuffer, out) < 0)
				err(FSCK_EX_ERROR, _("write failed: %s"),
				    path);
		curr = next;
	} while (size);
}
コード例 #2
0
ファイル: cramfsck.c プロジェクト: 4ft35t/firmware-mod-kit
static void do_uncompress(char *path, int fd, unsigned long offset, unsigned long size)
{
	unsigned long curr = offset + 4 * ((size + PAGE_CACHE_SIZE - 1) / PAGE_CACHE_SIZE);

	do {
		unsigned long out = PAGE_CACHE_SIZE;
		unsigned long next = *(u32 *) romfs_read(offset);

		if (next > end_data) {
			end_data = next;
		}

		offset += 4;
		if (curr == next) {
			if (opt_verbose > 1) {
				printf("  hole at %ld (%d)\n", curr, PAGE_CACHE_SIZE);
			}
			if (size < PAGE_CACHE_SIZE)
				out = size;
			memset(outbuffer, 0x00, out);
		}
		else {
			if (opt_verbose > 1) {
				printf("  uncompressing block at %ld to %ld (%ld)\n", curr, next, next - curr);
			}
			out = uncompress_block(romfs_read(curr), next - curr);
		}
		if (size >= PAGE_CACHE_SIZE) {
			if (out != PAGE_CACHE_SIZE) {
				die(FSCK_UNCORRECTED, 0, "non-block (%ld) bytes", out);
			}
		} else {
			if (out != size) {
				die(FSCK_UNCORRECTED, 0, "non-size (%ld vs %ld) bytes", out, size);
			}
		}
		size -= out;
		if (opt_extract) {
			if (write(fd, outbuffer, out) < 0) {
				die(FSCK_ERROR, 1, "write failed: %s", path);
			}
		}
		curr = next;
	} while (size);
}
コード例 #3
0
ファイル: cramfsck.c プロジェクト: OPSF/uClinux
static void do_uncompress(int fd, unsigned long offset, unsigned long size)
{
	unsigned long curr = offset + 4 * ((size + PAGE_CACHE_SIZE - 1) / PAGE_CACHE_SIZE);

	do {
		unsigned long out = PAGE_CACHE_SIZE;
		unsigned long next = *(unsigned long *) romfs_read(offset);

		if (next > end_data) {
			end_data = next;
		}

		offset += 4;
		if (curr == next) {
			if (opt_verbose > 1) {
				printf("  hole at %ld (%d)\n", curr, PAGE_CACHE_SIZE);
			}
			if (size < PAGE_CACHE_SIZE)
				out = size;
			memset(outbuffer, 0x00, out);
		}
		else {
			if (opt_verbose > 1) {
				printf("  uncompressing block at %ld to %ld (%ld)\n", curr, next, next - curr);
			}
			out = uncompress_block(romfs_read(curr), next - curr);
		}
		if (size >= PAGE_CACHE_SIZE) {
			if (out != PAGE_CACHE_SIZE) {
				fprintf(stderr, "%s: Non-block (%ld) bytes\n", filename, out);
				exit(4);
			}
		} else {
			if (out != size) {
				fprintf(stderr, "%s: Non-size (%ld vs %ld) bytes\n", filename, out, size);
				exit(4);
			}
		}
		size -= out;
		if (opt_extract) {
			write(fd, outbuffer, out);
		}
		curr = next;
	} while (size);
}
コード例 #4
0
ファイル: cramfsck.c プロジェクト: 4ft35t/firmware-mod-kit
static void do_symlink(char *path, struct cramfs_inode *i)
{
	unsigned long offset = i->offset << 2;
	unsigned long curr = offset + 4;
	unsigned long next = *(u32 *) romfs_read(offset);
	unsigned long size;

	if (offset == 0) {
		die(FSCK_UNCORRECTED, 0, "symbolic link has zero offset");
	}
	if (i->size == 0) {
		die(FSCK_UNCORRECTED, 0, "symbolic link has zero size");
	}

	if (offset < start_data) {
		start_data = offset;
	}
	if (next > end_data) {
		end_data = next;
	}

	size = uncompress_block(romfs_read(curr), next - curr);
	if (size != i->size) {
		die(FSCK_UNCORRECTED, 0, "size error in symlink: %s", path);
	}
	outbuffer[size] = 0;
	if (opt_verbose) {
		char *str;

		asprintf(&str, "%s -> %s", path, outbuffer);
		print_node('l', i, str);
		if (opt_verbose > 1) {
			printf("  uncompressing block at %ld to %ld (%ld)\n", curr, next, next - curr);
		}
		free(str);
	}
	if (opt_extract) {
		if (symlink(outbuffer, path) < 0) {
			die(FSCK_ERROR, 1, "symlink failed: %s", path);
		}
		change_file_status(path, i);
	}
}
コード例 #5
0
ファイル: fsck.cramfs.c プロジェクト: bneijt/util-linux
static void do_symlink(char *path, struct cramfs_inode *i)
{
	unsigned long offset = i->offset << 2;
	unsigned long curr = offset + 4;
	unsigned long next =
	    u32_toggle_endianness(cramfs_is_big_endian,
				  *(uint32_t *) romfs_read(offset));
	unsigned long size;

	if (offset == 0)
		errx(FSCK_EX_UNCORRECTED, _("symbolic link has zero offset"));
	if (i->size == 0)
		errx(FSCK_EX_UNCORRECTED, _("symbolic link has zero size"));

	if (offset < start_data)
		start_data = offset;
	if (next > end_data)
		end_data = next;

	size = uncompress_block(romfs_read(curr), next - curr);
	if (size != i->size)
		errx(FSCK_EX_UNCORRECTED, _("size error in symlink: %s"), path);
	outbuffer[size] = 0;
	if (opt_verbose) {
		char *str;

		xasprintf(&str, "%s -> %s", path, outbuffer);
		print_node('l', i, str);
		if (opt_verbose > 1)
			printf(_("  uncompressing block at %ld to %ld (%ld)\n"),
			       curr, next, next - curr);
		free(str);
	}
	if (*extract_dir != '\0') {
		if (symlink(outbuffer, path) < 0)
			err(FSCK_EX_ERROR, _("symlink failed: %s"), path);
		change_file_status(path, i);
	}
}
コード例 #6
0
ファイル: cramfsck.c プロジェクト: OPSF/uClinux
static void do_symlink(char *path, struct cramfs_inode *i)
{
	unsigned long offset = i->offset << 2;
	unsigned long curr = offset + 4;
	unsigned long next = *(unsigned long *) romfs_read(offset);
	unsigned long size;

	if (next > end_data) {
		end_data = next;
	}

	size = uncompress_block(romfs_read(curr), next - curr);
	if (size != i->size) {
		fprintf(stderr, "%s: size error in symlink `%s'\n",
			filename, path);
		exit(4);
	}
	outbuffer[size] = 0;
	if (opt_verbose) {
		char *str;

		str = malloc(strlen(outbuffer) + strlen(path) + 5);
		strcpy(str, path);
		strncat(str, " -> ", 4);
		strncat(str, outbuffer, size);

		print_node('l', i, str);
		if (opt_verbose > 1) {
			printf("  uncompressing block at %ld to %ld (%ld)\n", curr, next, next - curr);
		}
	}
	if (opt_extract) {
		symlink(outbuffer, path);
		change_file_status(path, i);
	}
}