[LTP] [PATCH] syscalls/fallocate[4, 5]: Fix failure when using old mkfs.btrfs

Cyril Hrubis chrubis@suse.cz
Wed Nov 22 15:58:22 CET 2017


Hi!
>  static int attach_device(const char *dev, const char *file)
>  {
>  	int dev_fd, file_fd;
> +	struct loop_info loopinfo;
>  
>  	dev_fd = open(dev, O_RDWR);
>  	if (dev_fd < 0) {
> @@ -156,6 +157,21 @@ static int attach_device(const char *dev, const char *file)
>  		return 1;
>  	}
>  
> +	/* Old mkfs.btrfs use LOOP_GET_STATUS instead of backing_file to get
> +	 * associated filename, so we need to set up the device by calling
> +	 * LOOP_SET_FD and LOOP_SET_STATUS.
> +	 */
> +	memset(&loopinfo, 0, sizeof(loopinfo));
> +	strcpy((char *)loopinfo.lo_name, file);
                 ^
		 Why the cast here, as far as I can tell the lo_name is
		 just array of chars which should be char * pointer
		 compatible.

> +	if (ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo)) {
> +		close(dev_fd);
> +		close(file_fd);
> +		tst_resm(TWARN | TERRNO,
> +			 "ioctl(%s, LOOP_SET_STATUS, %s) failed", dev, file);
> +		return 1;
> +	}
> +
>  	close(dev_fd);
>  	close(file_fd);
>  	return 0;

Otherwise it looks good.

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list