Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 740c3d22 authored by Chris Mason's avatar Chris Mason
Browse files

Btrfs: fix the new inspection ioctls for 32 bit compat



The new ioctls to follow backrefs are not clean for 32/64 bit
compat.  This reworks them for u64s everywhere.  They are brand new, so
there are no problems with changing the interface now.

Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 806468f8
Loading
Loading
Loading
Loading
+4 −4
Original line number Original line Diff line number Diff line
@@ -676,14 +676,14 @@ static int inode_to_path(u64 inum, struct btrfs_inode_ref *iref,
	bytes_left = ipath->fspath->bytes_left > s_ptr ?
	bytes_left = ipath->fspath->bytes_left > s_ptr ?
					ipath->fspath->bytes_left - s_ptr : 0;
					ipath->fspath->bytes_left - s_ptr : 0;


	fspath_min = (char *)ipath->fspath->str + (i + 1) * s_ptr;
	fspath_min = (char *)ipath->fspath->val + (i + 1) * s_ptr;
	fspath = iref_to_path(ipath->fs_root, ipath->btrfs_path, iref, eb,
	fspath = iref_to_path(ipath->fs_root, ipath->btrfs_path, iref, eb,
				inum, fspath_min, bytes_left);
				inum, fspath_min, bytes_left);
	if (IS_ERR(fspath))
	if (IS_ERR(fspath))
		return PTR_ERR(fspath);
		return PTR_ERR(fspath);


	if (fspath > fspath_min) {
	if (fspath > fspath_min) {
		ipath->fspath->str[i] = fspath;
		ipath->fspath->val[i] = (u64)fspath;
		++ipath->fspath->elem_cnt;
		++ipath->fspath->elem_cnt;
		ipath->fspath->bytes_left = fspath - fspath_min;
		ipath->fspath->bytes_left = fspath - fspath_min;
	} else {
	} else {
@@ -698,9 +698,9 @@ static int inode_to_path(u64 inum, struct btrfs_inode_ref *iref,
/*
/*
 * this dumps all file system paths to the inode into the ipath struct, provided
 * this dumps all file system paths to the inode into the ipath struct, provided
 * is has been created large enough. each path is zero-terminated and accessed
 * is has been created large enough. each path is zero-terminated and accessed
 * from ipath->fspath->str[i].
 * from ipath->fspath->val[i].
 * when it returns, there are ipath->fspath->elem_cnt number of paths available
 * when it returns, there are ipath->fspath->elem_cnt number of paths available
 * in ipath->fspath->str[]. when the allocated space wasn't sufficient, the
 * in ipath->fspath->val[]. when the allocated space wasn't sufficient, the
 * number of missed paths in recored in ipath->fspath->elem_missed, otherwise,
 * number of missed paths in recored in ipath->fspath->elem_missed, otherwise,
 * it's zero. ipath->fspath->bytes_missing holds the number of bytes that would
 * it's zero. ipath->fspath->bytes_missing holds the number of bytes that would
 * have been needed to return all paths.
 * have been needed to return all paths.
+5 −5
Original line number Original line Diff line number Diff line
@@ -2895,7 +2895,7 @@ static long btrfs_ioctl_ino_to_path(struct btrfs_root *root, void __user *arg)
{
{
	int ret = 0;
	int ret = 0;
	int i;
	int i;
	unsigned long rel_ptr;
	u64 rel_ptr;
	int size;
	int size;
	struct btrfs_ioctl_ino_path_args *ipa = NULL;
	struct btrfs_ioctl_ino_path_args *ipa = NULL;
	struct inode_fs_paths *ipath = NULL;
	struct inode_fs_paths *ipath = NULL;
@@ -2930,11 +2930,11 @@ static long btrfs_ioctl_ino_to_path(struct btrfs_root *root, void __user *arg)
		goto out;
		goto out;


	for (i = 0; i < ipath->fspath->elem_cnt; ++i) {
	for (i = 0; i < ipath->fspath->elem_cnt; ++i) {
		rel_ptr = ipath->fspath->str[i] - (char *)ipath->fspath->str;
		rel_ptr = ipath->fspath->val[i] - (u64)ipath->fspath->val;
		ipath->fspath->str[i] = (void *)rel_ptr;
		ipath->fspath->val[i] = rel_ptr;
	}
	}


	ret = copy_to_user(ipa->fspath, ipath->fspath, size);
	ret = copy_to_user((void *)ipa->fspath, (void *)ipath->fspath, size);
	if (ret) {
	if (ret) {
		ret = -EFAULT;
		ret = -EFAULT;
		goto out;
		goto out;
@@ -3017,7 +3017,7 @@ static long btrfs_ioctl_logical_to_ino(struct btrfs_root *root,
	if (ret < 0)
	if (ret < 0)
		goto out;
		goto out;


	ret = copy_to_user(loi->inodes, inodes, size);
	ret = copy_to_user((void *)loi->inodes, (void *)inodes, size);
	if (ret)
	if (ret)
		ret = -EFAULT;
		ret = -EFAULT;


+5 −6
Original line number Original line Diff line number Diff line
@@ -198,24 +198,23 @@ struct btrfs_data_container {
	__u32	bytes_missing;	/* out -- additional bytes needed for result */
	__u32	bytes_missing;	/* out -- additional bytes needed for result */
	__u32	elem_cnt;	/* out */
	__u32	elem_cnt;	/* out */
	__u32	elem_missed;	/* out */
	__u32	elem_missed;	/* out */
	union {
		char	*str[0];	/* out */
	__u64	val[0];		/* out */
	__u64	val[0];		/* out */
};
};
};


struct btrfs_ioctl_ino_path_args {
struct btrfs_ioctl_ino_path_args {
	__u64				inum;		/* in */
	__u64				inum;		/* in */
	__u32				size;		/* in */
	__u32				size;		/* in */
	__u64				reserved[4];
	__u64				reserved[4];
	struct btrfs_data_container	*fspath;	/* out */
	/* struct btrfs_data_container	*fspath;	   out */
	__u64				fspath;		/* out */
};
};


struct btrfs_ioctl_logical_ino_args {
struct btrfs_ioctl_logical_ino_args {
	__u64				logical;	/* in */
	__u64				logical;	/* in */
	__u32				size;		/* in */
	__u32				size;		/* in */
	__u64				reserved[4];
	__u64				reserved[4];
	struct btrfs_data_container	*inodes;	/* out */
	/* struct btrfs_data_container	*inodes;	out   */
	__u64				inodes;
};
};


#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
+1 −1
Original line number Original line Diff line number Diff line
@@ -272,7 +272,7 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 root, void *ctx)
			swarn->logical, swarn->dev->name,
			swarn->logical, swarn->dev->name,
			(unsigned long long)swarn->sector, root, inum, offset,
			(unsigned long long)swarn->sector, root, inum, offset,
			min(isize - offset, (u64)PAGE_SIZE), nlink,
			min(isize - offset, (u64)PAGE_SIZE), nlink,
			ipath->fspath->str[i]);
			(char *)ipath->fspath->val[i]);


	free_ipath(ipath);
	free_ipath(ipath);
	return 0;
	return 0;