[U-Boot] [PATCH v6 1/2] Loop block device for sandbox

Marek Vasut marex at denx.de
Fri Sep 28 20:22:14 CEST 2012


Dear Pavel Herrmann,

> This driver uses files as block devices, can be used for testing disk
> operations on sandbox.
> A new command "sata_loop" is introduced to load files in runtime.

The description might use a little bit of caressing here :)

[...]

> +	if (os_lseek(fd, start_byte, OS_SEEK_SET) != start_byte)
> +		return -1;

Use errno consistently ... so -EINVAL ? Or something else?

> +	retval = os_read(fd, buffer, length_byte);
> +
> +	return retval / ATA_SECT_SIZE;
> +}

[...]
> +		if (!strncmp(argv[1], "load", 4)) {

if (strncmp())
 return CMD_USAGE;

one indent less here ;-)

> +			dev = simple_strtoul(argv[2], NULL, 10);
> +			/*
> +			 * init_sata() and scan_sata() do their own range
> +			 * check, however we need to explicitly do it here
> +			 * as well.
> +			 */
> +			if (range_check(dev)) {
> +				printf("File index %d is out of range.\n", dev);
> +				return -EINVAL;
> +			}
> +			free(filenames[dev]);
> +			filenames[dev] = strdup(argv[3]);
> +			init_sata(dev);
> +			scan_sata(dev);
> +			/*
> +			 * Scan the partition table if we succeeded in loading
> +			 * the new loop file.
> +			 */
> +			if (sata_dev_desc[dev].lba > 0)
> +				init_part(&sata_dev_desc[dev]);
> +
> +			return 0;
> +		}
> +		return CMD_RET_USAGE;
> +	}
> +	return CMD_RET_USAGE;
> +}
> +
> +U_BOOT_CMD(
> +	sata_loop, 4, 1, do_loop,
> +	"SATA loopback",
> +	"info - show info about all loop devices\n"
> +	"sata_loop info devnum - show info about loop devnum\n"
> +	"sata_loop load devnum file - load file from host FS into loop devnum"
> +);


More information about the U-Boot mailing list