From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796029057; b=5Ri/4w5dU7TRRAN3D7GnaerIWSMHvBt8oXP2bfNTUoYjiCXUE3zQW+S2O1O+65Y21ZrJ VwNOnkoKc4/8YmRiDjKz1YQIYnWd/C2dIYxmN9wbk91kUC0XAg6WXW2zhfSogf9vDe11I /N+l8InG9qXWxyZRlWRGV23nhxaUK+PYDl4xlRMTj39Fa7Vf7no5fioUZRjeWo29IJziW hh3XRjWI+KMi+7KWBemUJR8Lg4p0ydpUFWPVHzCZM4hlXNPqMONqc3B/+mIRqVKFKQdSL 2TyWcp+iV+AYpQyGic6zkU9lPW6i67UjolHWoKM9b6eFqb9LZqsgaVyls8BqDLOETBw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796029057; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=bsoUT+MgEMWgInougHxafbGZW85onyyx9ifUCQUXgNA=; b=qcLZlYdu7bXQSrIuob/U9l0qQWQBL5ljaR9H+ni2pUpnpsQ2g4YcX0e+TivhBuRwMCqE WkCLqXF2giZAh3MpNNYh2klptB2kJuVSuoO7CRA+CnOorSL59XvRooVOJER+7GTxgI8JM DjC1nuegk1wU1rQPPoSXMx9jIfZTjib9QwYQHAVZRj66F3MAx3iTu+kREJ1+nE6lJtTNT XWinWeoQSkAdmEm1LhpdRA91857FF17RQd2cKZPPKyeH7tQgufFT74ni5NOfdL4thxIjK plyUD6sIXSpLUziABq03rMZF82U2kWRcKwYSNdbaUe8pcjc+LWQfNk55msTItODWABQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YqYbwaY9; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51886606A327; Mon, 30 Nov 2026 08:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=YqYbwaY9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 391671F00919; Mon, 30 Nov 2026 08:57:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796029056; bh=bsoUT+MgEMWgInougHxafbGZW85onyyx9ifUCQUXgNA=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=YqYbwaY9ooHDhH3PnvD3iiaBhIIaxBCTreQuGKLkGgGR5w0UGsV4Y+K0pKytUJQMp 7h5xi9W219BoWqKAOIDzYZ4uylhhdsLh84RI9MJtR9a/hlr56jdaKVRUr0mFopPRaa +H//3pAlmQkt6Z+RLeoPAvw9YZJil3YtgfuKN6yRrvuhTWbMhSAkDrBQ2jvfPUcONF 6nhwUo1klQoIdnC1g3XauU6uLzRZ7uBKHlPDqOypQ/CpwdZuSfzzbegCxmW66yYA+q Rm9/gbxQMbNKO1xGO2YxfBxfFgEpanLePF1Caz+y+LKVG95ENn4FczdGLDn/herX3S xP+zMyaxwdW4w== From: Christian Brauner Date: Mon, 30 Nov 2026 09:57:08 +0100 Subject: [PATCH v2 3/6] fat: add fat_tmpfile() X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-work-fat-tmpfile-v2-3-99af97d95683@kernel.org> References: <20261130-work-fat-tmpfile-v2-0-99af97d95683@kernel.org> In-Reply-To: <20261130-work-fat-tmpfile-v2-0-99af97d95683@kernel.org> To: OGAWA Hirofumi Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, "Christian Brauner (Amutable)" , Alexander Mikhalitsyn X-Mailer: b4 0.17-dev-04696 X-Developer-Signature: v=1; a=openpgp-sha256; l=2900; i=brauner@kernel.org; h=from:subject:message-id; bh=wsbibk7us4JuuY7d6BW9FazxGyQc5yOoXlxGF0szphs=; b=owGbwMvMwCU28Zj0gdSKO4sYT6slMWTzWhV1JQQ7tfzkeOFZKKayeGYva/2K+RvMK215azj+P wvQCFHqKGVhEONikBVTZHFoNwmXW85TsdkoUwNmDisTyBAGLk4BmMj1j4wML5InTlCID+D98f6N t8AJvsYOK+nFDGLm7xS2r01lbmHNYfhfHf3zyozAei0OnYO6/+93+245Xd1e/J9HKFN153P7QEt mAA== X-Developer-Key: i=brauner@kernel.org; a=openpgp; fpr=4880B8C9BD0E5106FC070F4F7B3C391EFEA93624 FAT already knows how to deal with a file that is open but has no directory entry. When an open file is unlinked fat_detach() resets i_pos to 0. From then on __fat_write_inode() has nothing to write, the data still goes to the file's cluster chain, and fat_evict_inode() frees the chain when the last reference is put. An O_TMPFILE is a file that starts out in that state. So build the inode like fat_build_inode() does, from a directory entry that only exists in memory, but don't attach it. fat_build_inode() itself can't be used for this. It would attach the inode at i_pos 0 and the next O_TMPFILE would find it through fat_iget(). The mode is ignored, just like in vfat_create() and msdos_create(). On FAT it's derived from the mount options. Nothing uses fat_tmpfile() yet. vfat and msdos need a ->link() method first and wire it up in the following patches. Reviewed-by: Alexander Mikhalitsyn Signed-off-by: Christian Brauner (Amutable) --- fs/fat/fat.h | 2 ++ fs/fat/inode.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/fs/fat/fat.h b/fs/fat/fat.h index a8a3ca4f465bf..cc706d89d1b96 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h @@ -423,6 +423,8 @@ extern void fat_detach(struct inode *inode); extern struct inode *fat_iget(struct super_block *sb, loff_t i_pos); extern struct inode *fat_build_inode(struct super_block *sb, struct msdos_dir_entry *de, loff_t i_pos); +int fat_tmpfile(const struct mnt_idmap *idmap, struct inode *dir, + struct file *file, umode_t mode); extern int fat_fill_super(struct super_block *sb, struct fs_context *fc, void (*setup)(struct super_block *)); extern int fat_fill_inode(struct inode *inode, struct msdos_dir_entry *de); diff --git a/fs/fat/inode.c b/fs/fat/inode.c index 25b9d8e3bb7de..b5ad61b004613 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -635,6 +635,29 @@ struct inode *fat_build_inode(struct super_block *sb, EXPORT_SYMBOL_GPL(fat_build_inode); +/* Like an open file that got unlinked: no directory entry, i_pos is 0. */ +int fat_tmpfile(const struct mnt_idmap *idmap, struct inode *dir, + struct file *file, umode_t mode) +{ + struct super_block *sb = dir->i_sb; + struct msdos_dir_entry de = { .attr = ATTR_ARCH }; + struct timespec64 ts = current_time(dir); + struct inode *inode; + + fat_time_unix2fat(MSDOS_SB(sb), &ts, &de.time, &de.date, &de.ctime_cs); + de.ctime = de.time; + de.cdate = de.date; + de.adate = de.date; + + inode = fat_new_inode(sb, &de); + if (IS_ERR(inode)) + return PTR_ERR(inode); + insert_inode_hash(inode); + d_tmpfile(file, inode); + return finish_open_simple(file, 0); +} +EXPORT_SYMBOL_GPL(fat_tmpfile); + static int __fat_write_inode(struct inode *inode); static int fat_sync_inode_metadata(struct inode *inode, -- 2.53.0