From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0480C230277 for ; Fri, 21 Mar 2025 19:49:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742586563; cv=none; b=b0yCXmuEE42tWZIxQDK8i7Fue36UX6Zaja1EfKFwZP3//tHZnQmknPNc92WEMeLmE3tEMxW0D5Vvg+zkLr6q9RuSxGrxlVlMTSUaGBhg4QBd9ZbnpAz93LcBxiANYVBGGv2rucr+rOIZR7Plmg0qo1hpItGJWaY4h9SZe/8PU/4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742586563; c=relaxed/simple; bh=U65D6SohAEKFKir81pK5H51AE5x6/jUW8l5jaJk9nGM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oSB4Pn1NeAwrD/NIGJdijdxuJWTknXvdyrkyGcg4w9lfYSdha22rKNOeNwACeFIb2cXCfh4D1obfZeIY/uqTb7wMpgLrOgcWeMeUDgf7bgGXkOLeIFnMTSaGR3MLG63LBt4bs6++Yd5bqn9Gycr7FZurA8e/IZNUUzKHhqXsfU4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=I4hZrQ1U; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="I4hZrQ1U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1742586560; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=P+CKY6hYnggEy5gDUo8IBcPB4aoVwWaaXqwhjqRQh5c=; b=I4hZrQ1UlEDE2VDP/jbj8EGzsMe4ojHQ4H/gWaxNFVUPpphmZLq6tmHLfhIfyaBJnaPsR6 i4sMvpieWn6yXtOwkic1GhhSoDvoDTdYt1ck1uerR9cz44r/qNMormFnpMW4NV8UQ/2kCs dZaeOwm3jQf4d2FgFOF2QnD11/imwvU= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-108-0rZuH671PcSARJGjeczxzA-1; Fri, 21 Mar 2025 15:49:17 -0400 X-MC-Unique: 0rZuH671PcSARJGjeczxzA-1 X-Mimecast-MFC-AGG-ID: 0rZuH671PcSARJGjeczxzA_1742586556 Received: by mail-ej1-f70.google.com with SMTP id a640c23a62f3a-ab68fbe53a4so275794066b.2 for ; Fri, 21 Mar 2025 12:49:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742586556; x=1743191356; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=P+CKY6hYnggEy5gDUo8IBcPB4aoVwWaaXqwhjqRQh5c=; b=Cg9kBO6vuSUSnyRAd6SFtbrKOvxBt2TlO3V+4tbHm7WH+faw1/Hn6MwUsvl9O71wIA sRTczTMoXCJs03MtIhzS5ZcP1HNo1d2Ggq67w2uAuPkdWJ4sfcOP2WlgayuAQGqg7nqk VJpr9wCOn0f3IREPFjHN1/HoHTLMuzeqrJ8hlIFDMc0Vkq1nO5QOXGXHwxS71ZhmtgR2 E92vxY4R1OQdZ9lp7/b4kqjuGkZqHksB/IfON1QQ1Q++OrDj360bk1X2gTstX1xUy8aF UQN1E0fDagvxoceZyDXcK4xTuxbBmighBTMCZ1OCnYYSSVI2GgaSOLwEHq2W9NQPPD41 0IsA== X-Forwarded-Encrypted: i=1; AJvYcCU20xhipNXRoiMU5P7dT9VlXb15sajq/2kUD1RgFBlzbH9aCycoTg70n5CcUs/If4UXRZfRHYiY8ROVJPC6@vger.kernel.org X-Gm-Message-State: AOJu0YyWo3e1eyCsBZx3ZMAvt9+OWr7Xl7CdEuXdTaIOjbn3B5ichkCy hXzIvVrBXcDmSk7mMp/hqFIP2KXEK+Ml5eBwnsIOK4Aml7x9bqXpYwvJUipsmlknLGuq91cOcO9 +9EQBJSc1v/0RDtwBZmuDVQBwIJBpVv3WJV+qec4PJRIp9aFMh1VVRqsxJeJKhYihvyTd0qEF X-Gm-Gg: ASbGncs4EVJsn1RK2z0ZRJWq7qMsRuEzLiZCU3lafrnN0ejnUC3EfhLFU8qatVPh019 MzdQGxsh+jQfR2qNwTRBaL6Bucr3XYOFan8wFldKB5oxjVagZBzYQYXxcx6e2G6B7Od15EdLx4w CIU9sfZF0uFE87U0ougdzMvhFzx8sGOx47tSp7aglBL4jm3nMf+6Y0vCWxZfSlMFfoZ77nzLQuX 8/MhTBFBX8q1T88/etdU0pVQ4W3UrUSnCLxVFI0/VBe8jj1Whg3TeJLaUua6uD8gQHFDWMDHVdU EuRJ9E9T5s6GXgYUeRxDivmEOfLGAVvdS28uH/rOTg== X-Received: by 2002:a17:907:9482:b0:ac2:13f:338b with SMTP id a640c23a62f3a-ac3f2537a13mr417243266b.55.1742586555783; Fri, 21 Mar 2025 12:49:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE364/oBuyn+cE4ig5ONss+vPjSo5TWTy9RSOBlsLCFEbZLg0sVEvc8UiI6SNuN3e2vwFGwrA== X-Received: by 2002:a17:907:9482:b0:ac2:13f:338b with SMTP id a640c23a62f3a-ac3f2537a13mr417237066b.55.1742586555219; Fri, 21 Mar 2025 12:49:15 -0700 (PDT) Received: from [127.0.0.2] (ip-217-030-074-039.aim-net.cz. [217.30.74.39]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac3ef8d3d38sm204412266b.39.2025.03.21.12.49.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Mar 2025 12:49:13 -0700 (PDT) From: Andrey Albershteyn X-Google-Original-From: Andrey Albershteyn Date: Fri, 21 Mar 2025 20:48:41 +0100 Subject: [PATCH v4 2/3] fs: split fileattr/fsxattr converters into helpers Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20250321-xattrat-syscall-v4-2-3e82e6fb3264@kernel.org> References: <20250321-xattrat-syscall-v4-0-3e82e6fb3264@kernel.org> In-Reply-To: <20250321-xattrat-syscall-v4-0-3e82e6fb3264@kernel.org> To: Richard Henderson , Matt Turner , Russell King , Catalin Marinas , Will Deacon , Geert Uytterhoeven , Michal Simek , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Yoshinori Sato , Rich Felker , John Paul Adrian Glaubitz , "David S. Miller" , Andreas Larsson , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Chris Zankel , Max Filippov , Alexander Viro , Christian Brauner , Jan Kara , =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= , =?utf-8?q?G=C3=BCnther_Noack?= , Arnd Bergmann , =?utf-8?q?Pali_Roh=C3=A1r?= , Paul Moore , James Morris , "Serge E. Hallyn" Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-api@vger.kernel.org, linux-arch@vger.kernel.org, Andrey Albershteyn X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3102; i=aalbersh@kernel.org; h=from:subject:message-id; bh=U65D6SohAEKFKir81pK5H51AE5x6/jUW8l5jaJk9nGM=; b=owJ4nJvAy8zAJea2/JXEGuOHHIyn1ZIY0u8e2nhsqffE2qNHBdc56kpaBv10/G5zKMBMNU5Y1 7+08cOt3t6OUhYGMS4GWTFFlnXSWlOTiqTyjxjUyMPMYWUCGcLAxSkAF7Fl+MO39MOayUtjz0Xc Zf+S85RBZMPrQyk/IssaWQR3V917GlLI8D93Rvvtmb0TdxnrLdm5326CcYQxW4JKaaBU3XVFNfO V51kB1DlIeQ== X-Developer-Key: i=aalbersh@kernel.org; a=openpgp; fpr=AE1B2A9562721A6FC4307C1F46A7EA18AC33E108 This will be helpful for get/setfsxattrat syscalls to convert between fileattr and fsxattr. Signed-off-by: Andrey Albershteyn --- fs/ioctl.c | 32 +++++++++++++++++++++----------- include/linux/fileattr.h | 2 ++ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/fs/ioctl.c b/fs/ioctl.c index 4434c97bc5dff5a3e8635e28745cd99404ff353e..840283d8c406623d8d26790f89b62ebcbd39e2de 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c @@ -538,6 +538,16 @@ int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa) } EXPORT_SYMBOL(vfs_fileattr_get); +void fileattr_to_fsxattr(const struct fileattr *fa, struct fsxattr *fsx) +{ + memset(fsx, 0, sizeof(struct fsxattr)); + fsx->fsx_xflags = fa->fsx_xflags; + fsx->fsx_extsize = fa->fsx_extsize; + fsx->fsx_nextents = fa->fsx_nextents; + fsx->fsx_projid = fa->fsx_projid; + fsx->fsx_cowextsize = fa->fsx_cowextsize; +} + /** * copy_fsxattr_to_user - copy fsxattr to userspace. * @fa: fileattr pointer @@ -549,12 +559,7 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa) { struct fsxattr xfa; - memset(&xfa, 0, sizeof(xfa)); - xfa.fsx_xflags = fa->fsx_xflags; - xfa.fsx_extsize = fa->fsx_extsize; - xfa.fsx_nextents = fa->fsx_nextents; - xfa.fsx_projid = fa->fsx_projid; - xfa.fsx_cowextsize = fa->fsx_cowextsize; + fileattr_to_fsxattr(fa, &xfa); if (copy_to_user(ufa, &xfa, sizeof(xfa))) return -EFAULT; @@ -563,6 +568,15 @@ int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa) } EXPORT_SYMBOL(copy_fsxattr_to_user); +void fsxattr_to_fileattr(const struct fsxattr *fsx, struct fileattr *fa) +{ + fileattr_fill_xflags(fa, fsx->fsx_xflags); + fa->fsx_extsize = fsx->fsx_extsize; + fa->fsx_nextents = fsx->fsx_nextents; + fa->fsx_projid = fsx->fsx_projid; + fa->fsx_cowextsize = fsx->fsx_cowextsize; +} + static int copy_fsxattr_from_user(struct fileattr *fa, struct fsxattr __user *ufa) { @@ -571,11 +585,7 @@ static int copy_fsxattr_from_user(struct fileattr *fa, if (copy_from_user(&xfa, ufa, sizeof(xfa))) return -EFAULT; - fileattr_fill_xflags(fa, xfa.fsx_xflags); - fa->fsx_extsize = xfa.fsx_extsize; - fa->fsx_nextents = xfa.fsx_nextents; - fa->fsx_projid = xfa.fsx_projid; - fa->fsx_cowextsize = xfa.fsx_cowextsize; + fsxattr_to_fileattr(&xfa, fa); return 0; } diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h index 47c05a9851d0600964b644c9c7218faacfd865f8..31888fa2edf10050be134f587299256088344365 100644 --- a/include/linux/fileattr.h +++ b/include/linux/fileattr.h @@ -33,7 +33,9 @@ struct fileattr { bool fsx_valid:1; }; +void fileattr_to_fsxattr(const struct fileattr *fa, struct fsxattr *fsx); int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa); +void fsxattr_to_fileattr(const struct fsxattr *fsx, struct fileattr *fa); void fileattr_fill_xflags(struct fileattr *fa, u32 xflags); void fileattr_fill_flags(struct fileattr *fa, u32 flags); -- 2.47.2