Example #1
0
static ssize_t
zpl_read_common_iovec(struct inode *ip, const struct iovec *iovp, size_t count,
    unsigned long nr_segs, loff_t *ppos, uio_seg_t segment, int flags,
    cred_t *cr, size_t skip)
{
	ssize_t read;
	uio_t uio;
	int error;
	fstrans_cookie_t cookie;

	uio.uio_iov = iovp;
	uio.uio_skip = skip;
	uio.uio_resid = count;
	uio.uio_iovcnt = nr_segs;
	uio.uio_loffset = *ppos;
	uio.uio_limit = MAXOFFSET_T;
	uio.uio_segflg = segment;

	cookie = spl_fstrans_mark();
	error = -zfs_read(ip, &uio, flags, cr);
	spl_fstrans_unmark(cookie);
	if (error < 0)
		return (error);

	read = count - uio.uio_resid;
	*ppos += read;
	task_io_account_read(read);

	return (read);
}
Example #2
0
ssize_t
zpl_read_common(struct inode *ip, const char *buf, size_t len, loff_t pos,
    uio_seg_t segment, int flags, cred_t *cr)
{
	int error;
	ssize_t read;
	struct iovec iov;
	uio_t uio;

	iov.iov_base = (void *)buf;
	iov.iov_len = len;

	uio.uio_iov = &iov;
	uio.uio_resid = len;
	uio.uio_iovcnt = 1;
	uio.uio_loffset = pos;
	uio.uio_limit = MAXOFFSET_T;
	uio.uio_segflg = segment;

	error = -zfs_read(ip, &uio, flags, cr);
	if (error < 0)
		return (error);

	read = len - uio.uio_resid;
	task_io_account_read(read);

	return (read);
}
static int
fsi_zfs_read(fsi_file_t *ffi, char *buf, int len)
{
	uint64_t *fpos;
	int rc;

	zfs_ffi = ffi;
	fpos = fsig_filepos(ffi);
	filepos = *fpos;
	rc = zfs_read(buf, len);
	*fpos = filepos;

	return (rc);
}
Example #4
0
int
main(int argc, char** argv)
{
	int i, n, off;
	int fd[99];
	spa_t *spa;
	dnode_phys_t dn;
	char buf[512];

	zfs_init();
	if (argc == 1) {
		static char *av[] = {
			"zfstest", "/dev/da0p2", "/dev/da1p2", "/dev/da2p2",
			NULL,
		};
		argc = 4;
		argv = av;
	}
	for (i = 1; i < argc; i++) {
		fd[i] = open(argv[i], O_RDONLY);
		if (fd[i] < 0)
			continue;
		if (vdev_probe(vdev_read, &fd[i], NULL) != 0)
			close(fd[i]);
	}
	spa_all_status();

	spa = STAILQ_FIRST(&zfs_pools);
	if (!spa || zfs_mount_pool(spa))
		exit(1);

	if (zfs_lookup(spa, "zfs.c", &dn))
		exit(1);

	off = 0;
	do {
		n = zfs_read(spa, &dn, buf, 512, off);
		write(1, buf, n);
		off += n;
	} while (n == 512);
}
Example #5
0
static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	char *filename = NULL;
	int dev;
	int part;
	ulong addr = 0;
	disk_partition_t info;
	block_dev_desc_t *dev_desc;
	char buf[12];
	unsigned long count;
	const char *addr_str;
	struct zfs_file zfile;
	struct device_s vdev;

	if (argc < 3)
		return CMD_RET_USAGE;

	count = 0;
	addr = simple_strtoul(argv[3], NULL, 16);
	filename = getenv("bootfile");
	switch (argc) {
	case 3:
		addr_str = getenv("loadaddr");
		if (addr_str != NULL)
			addr = simple_strtoul(addr_str, NULL, 16);
		else
			addr = CONFIG_SYS_LOAD_ADDR;

		break;
	case 4:
		break;
	case 5:
		filename = argv[4];
		break;
	case 6:
		filename = argv[4];
		count = simple_strtoul(argv[5], NULL, 16);
		break;

	default:
		return cmd_usage(cmdtp);
	}

	if (!filename) {
		puts("** No boot file defined **\n");
		return 1;
	}

	part = get_device_and_partition(argv[1], argv[2], &dev_desc, &info, 1);
	if (part < 0)
		return 1;

	dev = dev_desc->dev;
	printf("Loading file \"%s\" from %s device %d%c%c\n",
		filename, argv[1], dev,
		part ? ':' : ' ', part ? part + '0' : ' ');

	zfs_set_blk_dev(dev_desc, &info);
	vdev.part_length = info.size;

	memset(&zfile, 0, sizeof(zfile));
	zfile.device = &vdev;
	if (zfs_open(&zfile, filename)) {
		printf("** File not found %s\n", filename);
		return 1;
	}

	if ((count < zfile.size) && (count != 0))
		zfile.size = (uint64_t)count;

	if (zfs_read(&zfile, (char *)addr, zfile.size) != zfile.size) {
		printf("** Unable to read \"%s\" from %s %d:%d **\n",
			   filename, argv[1], dev, part);
		zfs_close(&zfile);
		return 1;
	}

	zfs_close(&zfile);

	/* Loading ok, update default load address */
	load_addr = addr;

	printf("%llu bytes read\n", zfile.size);
	setenv_hex("filesize", zfile.size);

	return 0;
}
Example #6
0
static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
    char *filename = NULL;
    char *ep;
    int dev;
    unsigned long part = 1;
    ulong addr = 0;
    ulong part_length;
    disk_partition_t info;
    char buf[12];
    unsigned long count;
    const char *addr_str;
    struct zfs_file zfile;
    struct device_s vdev;

    if (argc < 3)
        return CMD_RET_USAGE;

    count = 0;
    addr = simple_strtoul(argv[3], NULL, 16);
    filename = getenv("bootfile");
    switch (argc) {
    case 3:
        addr_str = getenv("loadaddr");
        if (addr_str != NULL)
            addr = simple_strtoul(addr_str, NULL, 16);
        else
            addr = CONFIG_SYS_LOAD_ADDR;

        break;
    case 4:
        break;
    case 5:
        filename = argv[4];
        break;
    case 6:
        filename = argv[4];
        count = simple_strtoul(argv[5], NULL, 16);
        break;

    default:
        return cmd_usage(cmdtp);
    }

    if (!filename) {
        puts("** No boot file defined **\n");
        return 1;
    }

    dev = (int)simple_strtoul(argv[2], &ep, 16);
    zfs_dev_desc = get_dev(argv[1], dev);
    if (zfs_dev_desc == NULL) {
        printf("** Block device %s %d not supported\n", argv[1], dev);
        return 1;
    }

    if (*ep) {
        if (*ep != ':') {
            puts("** Invalid boot device, use `dev[:part]' **\n");
            return 1;
        }
        part = simple_strtoul(++ep, NULL, 16);
    }

    if (part != 0) {
        if (get_partition_info(zfs_dev_desc, part, &info)) {
            printf("** Bad partition %lu **\n", part);
            return 1;
        }

        if (strncmp((char *)info.type, BOOT_PART_TYPE,
                    strlen(BOOT_PART_TYPE)) != 0) {
            printf("** Invalid partition type \"%s\" (expect \"" BOOT_PART_TYPE "\")\n",
                   info.type);
            return 1;
        }
        printf("Loading file \"%s\" "
               "from %s device %d:%lu %s\n",
               filename, argv[1], dev, part, info.name);
    } else {
        printf("Loading file \"%s\" from %s device %d\n",
               filename, argv[1], dev);
    }

    part_length = zfs_set_blk_dev(zfs_dev_desc, part);
    if (part_length == 0) {
        printf("**Bad partition - %s %d:%lu **\n", argv[1], dev, part);
        return 1;
    }

    vdev.part_length = part_length;

    memset(&zfile, 0, sizeof(zfile));
    zfile.device = &vdev;
    if (zfs_open(&zfile, filename)) {
        printf("** File not found %s\n", filename);
        return 1;
    }

    if ((count < zfile.size) && (count != 0))
        zfile.size = (uint64_t)count;

    if (zfs_read(&zfile, (char *)addr, zfile.size) != zfile.size) {
        printf("** Unable to read \"%s\" from %s %d:%lu **\n",
               filename, argv[1], dev, part);
        zfs_close(&zfile);
        return 1;
    }

    zfs_close(&zfile);

    /* Loading ok, update default load address */
    load_addr = addr;

    printf("%llu bytes read\n", zfile.size);
    sprintf(buf, "%llX", zfile.size);
    setenv("filesize", buf);

    return 0;
}
Example #7
0
int
main(int argc, char** argv)
{
	char buf[512], hash[33];
	MD5_CTX ctx;
	struct stat sb;
	struct zfsmount zfsmnt;
	dnode_phys_t dn;
#if 0
	uint64_t rootobj;
#endif
	spa_t *spa;
	off_t off;
	ssize_t n;
	int i, failures, *fd;

	zfs_init();
	if (argc == 1) {
		static char *av[] = {
			"zfsboottest",
			"/dev/gpt/system0",
			"/dev/gpt/system1",
			"-",
			"/boot/zfsloader",
			"/boot/support.4th",
			"/boot/kernel/kernel",
			NULL,
		};
		argc = sizeof(av) / sizeof(av[0]) - 1;
		argv = av;
	}
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-") == 0)
			break;
	}
	fd = malloc(sizeof(fd[0]) * (i - 1));
	if (fd == NULL)
		errx(1, "Unable to allocate memory.");
	for (i = 1; i < argc; i++) {
		if (strcmp(argv[i], "-") == 0)
			break;
		fd[i - 1] = open(argv[i], O_RDONLY);
		if (fd[i - 1] == -1) {
			warn("open(%s) failed", argv[i]);
			continue;
		}
		if (vdev_probe(vdev_read, &fd[i - 1], NULL) != 0) {
			warnx("vdev_probe(%s) failed", argv[i]);
			close(fd[i - 1]);
		}
	}
	spa_all_status();

	spa = STAILQ_FIRST(&zfs_pools);
	if (spa == NULL) {
		fprintf(stderr, "no pools\n");
		exit(1);
	}

	if (zfs_spa_init(spa)) {
		fprintf(stderr, "can't init pool\n");
		exit(1);
	}

#if 0
	if (zfs_get_root(spa, &rootobj)) {
		fprintf(stderr, "can't get root\n");
		exit(1);
	}

	if (zfs_mount(spa, rootobj, &zfsmnt)) {
#else
	if (zfs_mount(spa, 0, &zfsmnt)) {
		fprintf(stderr, "can't mount\n");
		exit(1);
	}
#endif

	printf("\n");
	for (++i, failures = 0; i < argc; i++) {
		if (zfs_lookup(&zfsmnt, argv[i], &dn)) {
			fprintf(stderr, "%s: can't lookup\n", argv[i]);
			failures++;
			continue;
		}

		if (zfs_dnode_stat(spa, &dn, &sb)) {
			fprintf(stderr, "%s: can't stat\n", argv[i]);
			failures++;
			continue;
		}

		off = 0;
		MD5Init(&ctx);
		do {
			n = sb.st_size - off;
			n = n > sizeof(buf) ? sizeof(buf) : n;
			n = zfs_read(spa, &dn, buf, n, off);
			if (n < 0) {
				fprintf(stderr, "%s: zfs_read failed\n",
				    argv[i]);
				failures++;
				break;
			}
			MD5Update(&ctx, buf, n);
			off += n;
		} while (off < sb.st_size);
		if (off < sb.st_size)
			continue;
		MD5End(&ctx, hash);
		printf("%s %s\n", hash, argv[i]);
	}

	return (failures == 0 ? 0 : 1);
}
Example #8
0
int
main(int argc, char** argv)
{
	char buf[512];
	int fd[100];
	struct stat sb;
	dnode_phys_t dn;
	spa_t *spa;
	off_t off;
	ssize_t n;
	int i;

	zfs_init();
	if (argc == 1) {
		static char *av[] = {
			"zfstest", "COPYRIGHT",
			"/dev/da0p2", "/dev/da1p2", "/dev/da2p2",
			NULL,
		};
		argc = 5;
		argv = av;
	}
	for (i = 2; i < argc; i++) {
		fd[i] = open(argv[i], O_RDONLY);
		if (fd[i] < 0)
			continue;
		if (vdev_probe(vdev_read, &fd[i], NULL) != 0)
			close(fd[i]);
	}
	spa_all_status();

	spa = STAILQ_FIRST(&zfs_pools);
	if (spa == NULL) {
		fprintf(stderr, "no pools\n");
		exit(1);
	}

	if (zfs_mount_pool(spa)) {
		fprintf(stderr, "can't mount pool\n");
		exit(1);
	}

	if (zfs_lookup(spa, argv[1], &dn)) {
		fprintf(stderr, "can't lookup\n");
		exit(1);
	}

	if (zfs_dnode_stat(spa, &dn, &sb)) {
		fprintf(stderr, "can't stat\n");
		exit(1);
	}


	off = 0;
	do {
		n = sb.st_size - off;
		n = n > sizeof(buf) ? sizeof(buf) : n;
		n = zfs_read(spa, &dn, buf, n, off);
		if (n < 0) {
			fprintf(stderr, "zfs_read failed\n");
			exit(1);
		}
		write(1, buf, n);
		off += n;
	} while (off < sb.st_size);

	return (0);
}