Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2951209lqz; Wed, 3 Apr 2024 13:23:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV5oUcyXl57RQGGKBealGG73iygToBBf+BuoPs58IEru3BQn9jWPr8ax+wOz7Wj8Oltnezcqxw1O8a6/ImfB8nK/wFpkmJhx/rQDtF+7w== X-Google-Smtp-Source: AGHT+IFE7UPLdrj1YEeeZIzNxo60B8G3I4I9ZPUlEAfHd86nlu6cnK8zFPlDZ/OfZJm/A6k0SntN X-Received: by 2002:a05:6a20:da85:b0:1a5:6be8:2d70 with SMTP id iy5-20020a056a20da8500b001a56be82d70mr945562pzb.21.1712175836899; Wed, 03 Apr 2024 13:23:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712175836; cv=pass; d=google.com; s=arc-20160816; b=gsJlFayDNBGkZnWlzUUttcNRwb84xL+oRvH5I7Fi3Pb35k7A0SWoBwWlWtSb3uPoS6 AAU+7+XFVATfBUeDJzecjMh09r1AjgxckcMcDiv/tQZTSHmNHlcscpySoLSCHy2YCfXa O/H7fV/k1k9TzwBpR0SMFX/aNEWTcAcwAWE69wgjPqGSWPMShHvq+6plCMt7NjM7VpyP W/fZ540aN+oYkdZT5Q9GL/HnfQd3mL5T7BtkaAGyT701wIcO8vyO1KYw2SiEBV9dvFH5 oWd6IRpPNDZqAU2Ow0Grxq/9mdT/YRyvJ4bc9D1abliYYTNcFY/jq/S/wwM5d393fRSI 2Nbw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:to:from:dkim-signature; bh=YIc4KfiR6liu8Si7AocJ/Ewyg82WwMQuQBXKzCZ5x/I=; fh=5xpXEVHA7ULft/JHqM87S8vqz30WiVdsBWxEbwY87G4=; b=C92KqkCxYIJg16wRTIfcFkLEnoIzyDpQAnyzHG86w39uRZ0Yldsy3O7kXmTS7pbxBM xj08q4ECaipOmfxtw321IRFSpHNnbzyxE7za/nm5p7bKUAXRBozmh/MkBUMtRXRmr/WX ecjw7coOCBWiEMHmrGwnE7iDBA9GxH1vbSGeR0PM0BLqepzwyE3QkgSwRqK0CrTymeeD 6566H/MS/w3w3M0xvN0X33cFu56HeDBf4uvd5tJvtYUrDToWQ9J33HqTe/299serDBQT KZHAo4KMd66pa9CiumTJhK4wfYJLG3stHSu/Uan/XjPvY8DlL/1JZl3TD6dD8gW356NT 1k8A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@dorminy.me header.s=mail header.b=duAbvHkd; arc=pass (i=1 spf=pass spfdomain=dorminy.me dkim=pass dkdomain=dorminy.me dmarc=pass fromdomain=dorminy.me); spf=pass (google.com: domain of linux-kernel+bounces-129170-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129170-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=dorminy.me Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id ka35-20020a056a0093a300b006eaa6766facsi14382886pfb.23.2024.04.03.13.23.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Apr 2024 13:23:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-129170-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@dorminy.me header.s=mail header.b=duAbvHkd; arc=pass (i=1 spf=pass spfdomain=dorminy.me dkim=pass dkdomain=dorminy.me dmarc=pass fromdomain=dorminy.me); spf=pass (google.com: domain of linux-kernel+bounces-129170-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-129170-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=dorminy.me Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 50B08285545 for ; Wed, 3 Apr 2024 07:33:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9901460B91; Wed, 3 Apr 2024 07:33:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dorminy.me header.i=@dorminy.me header.b="duAbvHkd" Received: from box.fidei.email (box.fidei.email [71.19.144.250]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 304405B68F; Wed, 3 Apr 2024 07:33:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=71.19.144.250 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712129587; cv=none; b=BnMd9NpwMx4sJWpOw5C9UHodNEKFKX3SK7cwmim+E8hcVYRlBv/IS9ItN33oDgfbGvuLKk79az1O3Gw+hQj7VXnOJIcRclfx3TREaAB4WoxMcjO0deoXYiDa/jz+ZL7Ls9TiN723SeuMcWwrvPp1D+Lzc+9b8Wmj+KUdCgaWRwI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712129587; c=relaxed/simple; bh=8hdRucriYr7TDeIc1Z7lCtD9oMQ64x6lsX9+VmwRajs=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hu4amzfH5J4b6+u0f00WKMpQlapFy+DDAvg4mCqnEdIahv3gxb3P83wZV8+XLFHVXgnupNulMynR2MTNKiVAITjz6X0AmgkB57TCf4hIOmXy3UARmhdZV2OWqRNiU7X0sL5Oz5hc80csBdAIsBpAS+2l4Hta4gLrdB5Iobpydb4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=dorminy.me; spf=pass smtp.mailfrom=dorminy.me; dkim=pass (2048-bit key) header.d=dorminy.me header.i=@dorminy.me header.b=duAbvHkd; arc=none smtp.client-ip=71.19.144.250 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=dorminy.me Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dorminy.me Received: from authenticated-user (box.fidei.email [71.19.144.250]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by box.fidei.email (Postfix) with ESMTPSA id 47146807A5; Wed, 3 Apr 2024 03:33:05 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1712129585; bh=8hdRucriYr7TDeIc1Z7lCtD9oMQ64x6lsX9+VmwRajs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=duAbvHkdgGafhhkA8hd0r625830aALZZQ8oxeANR/Kl8V2xZug5kmcP4vI1YapxFN A9LIDRTvjeSQOhcIpRDoLRTbG3NMyvM/72K1ifkS/Z9WVfqJVjWSBQ7y9OWOKItEFi P+IExaIGlJDtZ5Rx/+twB5qnULd5b1xw9JJmHoTUZK1CNmor9ry/3WJ5MlliuOXzge eoaW6DepcInBi/zwZ/15PRH144T5KOWel/2PH8M2LXhMM/YZG6q5hG/wxWX1eFQHXr y0rEkGXPrjhNC8NJHfsw4ypdhHDVDROcDUUlNXmuBJ6WY9PkwLnPjt68hBA1lQ7Eyb PKcWh0anOhPtA== From: Sweet Tea Dorminy To: Jonathan Corbet , Kent Overstreet , Brian Foster , Chris Mason , Josef Bacik , David Sterba , Jaegeuk Kim , Chao Yu , Alexander Viro , Christian Brauner , Jan Kara , =?UTF-8?q?Micka=C3=ABl=20Sala=C3=BCn?= , Sweet Tea Dorminy , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-bcachefs@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, kernel-team@meta.com Subject: [PATCH v3 01/13] fs: fiemap: add physical_length field to extents Date: Wed, 3 Apr 2024 03:22:42 -0400 Message-ID: <1ba5bfccccbf4ff792f178268badde056797d0c4.1712126039.git.sweettea-kernel@dorminy.me> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Some filesystems support compressed extents which have a larger logical size than physical, and for those filesystems, it can be useful for userspace to know how much space those extents actually use. For instance, the compsize [1] tool for btrfs currently uses btrfs-internal, root-only ioctl to find the actual disk space used by a file; it would be better and more useful for this information to require fewer privileges and to be usable on more filesystems. Therefore, use one of the padding u64s in the fiemap extent structure to return the actual physical length; and, for now, return this as equal to the logical length. [1] https://github.com/kilobyte/compsize Signed-off-by: Sweet Tea Dorminy --- Documentation/filesystems/fiemap.rst | 28 +++++++++++++++++------- fs/ioctl.c | 3 ++- include/uapi/linux/fiemap.h | 32 ++++++++++++++++++++++------ 3 files changed, 47 insertions(+), 16 deletions(-) diff --git a/Documentation/filesystems/fiemap.rst b/Documentation/filesystems/fiemap.rst index 93fc96f760aa..c2bfa107c8d7 100644 --- a/Documentation/filesystems/fiemap.rst +++ b/Documentation/filesystems/fiemap.rst @@ -80,14 +80,24 @@ Each extent is described by a single fiemap_extent structure as returned in fm_extents:: struct fiemap_extent { - __u64 fe_logical; /* logical offset in bytes for the start of - * the extent */ - __u64 fe_physical; /* physical offset in bytes for the start - * of the extent */ - __u64 fe_length; /* length in bytes for the extent */ - __u64 fe_reserved64[2]; - __u32 fe_flags; /* FIEMAP_EXTENT_* flags for this extent */ - __u32 fe_reserved[3]; + /* + * logical offset in bytes for the start of + * the extent from the beginning of the file + */ + __u64 fe_logical; + /* + * physical offset in bytes for the start + * of the extent from the beginning of the disk + */ + __u64 fe_physical; + /* logical length in bytes for this extent */ + __u64 fe_logical_length; + /* physical length in bytes for this extent */ + __u64 fe_physical_length; + __u64 fe_reserved64[1]; + /* FIEMAP_EXTENT_* flags for this extent */ + __u32 fe_flags; + __u32 fe_reserved[3]; }; All offsets and lengths are in bytes and mirror those on disk. It is valid @@ -175,6 +185,8 @@ FIEMAP_EXTENT_MERGED userspace would be highly inefficient, the kernel will try to merge most adjacent blocks into 'extents'. +FIEMAP_EXTENT_HAS_PHYS_LEN + This will be set if the file system populated the physical length field. VFS -> File System Implementation --------------------------------- diff --git a/fs/ioctl.c b/fs/ioctl.c index 661b46125669..8afd32e1a27a 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -138,7 +138,8 @@ int fiemap_fill_next_extent(struct fiemap_extent_info *fieinfo, u64 logical, memset(&extent, 0, sizeof(extent)); extent.fe_logical = logical; extent.fe_physical = phys; - extent.fe_length = len; + extent.fe_logical_length = len; + extent.fe_physical_length = len; extent.fe_flags = flags; dest += fieinfo->fi_extents_mapped; diff --git a/include/uapi/linux/fiemap.h b/include/uapi/linux/fiemap.h index 24ca0c00cae3..3079159b8e94 100644 --- a/include/uapi/linux/fiemap.h +++ b/include/uapi/linux/fiemap.h @@ -14,14 +14,30 @@ #include +/* + * For backward compatibility, where the member of the struct was called + * fe_length instead of fe_logical_length. + */ +#define fe_length fe_logical_length + struct fiemap_extent { - __u64 fe_logical; /* logical offset in bytes for the start of - * the extent from the beginning of the file */ - __u64 fe_physical; /* physical offset in bytes for the start - * of the extent from the beginning of the disk */ - __u64 fe_length; /* length in bytes for this extent */ - __u64 fe_reserved64[2]; - __u32 fe_flags; /* FIEMAP_EXTENT_* flags for this extent */ + /* + * logical offset in bytes for the start of + * the extent from the beginning of the file + */ + __u64 fe_logical; + /* + * physical offset in bytes for the start + * of the extent from the beginning of the disk + */ + __u64 fe_physical; + /* logical length in bytes for this extent */ + __u64 fe_logical_length; + /* physical length in bytes for this extent */ + __u64 fe_physical_length; + __u64 fe_reserved64[1]; + /* FIEMAP_EXTENT_* flags for this extent */ + __u32 fe_flags; __u32 fe_reserved[3]; }; @@ -66,5 +82,7 @@ struct fiemap { * merged for efficiency. */ #define FIEMAP_EXTENT_SHARED 0x00002000 /* Space shared with other * files. */ +#define FIEMAP_EXTENT_HAS_PHYS_LEN 0x00004000 /* Physical length is valid + * and set by FS. */ #endif /* _UAPI_LINUX_FIEMAP_H */ -- 2.43.0