From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=210.171.160.6 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796456644; b=40gWJfrxOZy7Y0VUfT8d00Voqa2Fo9DYRTQjp3vcgBsZ88evoUdzgWR/09keBL7c1ZO8 PlXKJ/vLXCEpInaaLu7eJbfTtyp8oJv9dSwQkQ1R7eSVPxg1Mg4tez9PCu8XCfanTm2pi U+HmfsJNqj/jvwW2EfzvXzpcvrqsUliepX/EU5A+3xbzTV0ZnhfOofVtD6QC5KuKToI7p iYFGnb2QXGy1QPKNpQn/UP+Z9VcIAdEEW1+EY3plO/BzWGhcm1XqsM1UrF1PSEdJhf9mL gdfdMAEOoYh4MmJgEoQfYWsj6pTC6TQiSI8eHDMMkKqT/1xZp0FkiRPl02+3VPmggDQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796456644; h=DMARC-Filter:Received:DKIM-Signature:DKIM-Signature:Received: Received:From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: User-Agent:MIME-Version:Content-Type; bh=f0z5/oXKlwGfJCNHOynTl1OaAzm3OIa6i96LguFxkv8=; b=4vkkccs3FmL73h2TYIb7dZqlfb6BQLC9ICVfeevBhYJwu07no9XI6CZDj2s/sUZS1Gd2 OiJx6ueIOGPEazkE+NGh1y8xPq3fFmXlbDAxnR4dj2L8dwDQAW0nzhtSSIOAM/sdcF5qT ZYh46X/O2TqpmtvV/U5jzc51YvQLPIrIB+kvwgOmKK8mrhsx/0TdUz9xvEtWt1eiXNVfJ w5h+hx0sNHrg3t0sIllharqpEjXJQcRcf0aeNy4pYumUgkH5eO8FY4dLNO42hp07POSer bDquFxmtOuD7mytLn5DnvI2aVYsSTcAQuef97AdJmR5hUPMH2Fewyf5D0dDLCO1a3ZA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=mail.parknet.co.jp; spf=pass smtp.mailfrom=parknet.co.jp; dkim=pass header.d=parknet.co.jp header.i=@parknet.co.jp header.a=rsa-sha256 header.s=20250114 header.b=4cZsBvu5; dkim=pass header.d=parknet.co.jp header.i=@parknet.co.jp header.a=ed25519-sha256 header.s=20250114-ed25519 header.b="MmchE/DY"; arc=none smtp.remote-ip=210.171.160.6 Received: from mail.parknet.co.jp (mail.parknet.co.jp [210.171.160.6]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 652DA606A32F; Sat, 5 Dec 2026 07:44:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 652DA606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mail.parknet.co.jp Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=parknet.co.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=parknet.co.jp header.i=@parknet.co.jp header.a=rsa-sha256 header.s=20250114 header.b=4cZsBvu5; dkim=pass header.d=parknet.co.jp header.i=@parknet.co.jp header.a=ed25519-sha256 header.s=20250114-ed25519 header.b=MmchE/DY Received: from ibmpc.myhome.or.jp (server.parknet.ne.jp [210.171.168.39]) by mail.parknet.co.jp (Postfix) with ESMTPSA id D569A209655A; Sat, 5 Dec 2026 16:44:01 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=parknet.co.jp; s=20250114; t=1796456641; 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: in-reply-to:in-reply-to:references:references; bh=f0z5/oXKlwGfJCNHOynTl1OaAzm3OIa6i96LguFxkv8=; b=4cZsBvu5LOOnmNGXUHWfT4i58K/Gor3/YNny4flmJnByRyek7AUg40HvlmAICrhgTey8Bg 5xzkRohljYp8w2sh6pwbCVVjxTr5VnQWwPaE3QywqoNJveZjOXpD3OX9bIplh54CfbRpq8 la97PFjKlM+qfkmpdpYUn/ZF0f9mpJjpr8QUu7g5f6J+sfWG9SglNa3yMm3a38xGIC4Izo b2AgK0KlVTnrGmphDlx9lU3IugUw9kJbw3ThhsObQEwoox4bSwiq1sF+u4byaFSfQCjMSu 7pMLTckwaSDmCVkM9jYUHkEr4bxdx1xMq7gb2Q5SOlnnRxpSVGQGlkiI7WQQBA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=parknet.co.jp; s=20250114-ed25519; t=1796456641; 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: in-reply-to:in-reply-to:references:references; bh=f0z5/oXKlwGfJCNHOynTl1OaAzm3OIa6i96LguFxkv8=; b=MmchE/DYQ/ZXBSiW9gVIDHXI8nZ8MzkqO236/OtI04RrsFOJEJq/jtCA1k8bOJZFBxPEEA da2Xcb/+HDsb6hBw== Received: from devron.myhome.or.jp (devron.myhome.or.jp [192.168.0.3]) by ibmpc.myhome.or.jp (Postfix) with ESMTPS id 6D6D8E00155; Sat, 05 Dec 2026 16:44:01 +0900 (JST) Received: by devron.myhome.or.jp (Postfix, from userid 1000) id 604D32200167; Sat, 05 Dec 2026 16:44:01 +0900 (JST) From: OGAWA Hirofumi To: Andrew Morton Cc: Christian Brauner , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Alexander Mikhalitsyn Subject: Re: [PATCH v2 4/6] fat: support O_TMPFILE on vfat In-Reply-To: <20261130-work-fat-tmpfile-v2-4-99af97d95683@kernel.org> References: <20261130-work-fat-tmpfile-v2-0-99af97d95683@kernel.org> <20261130-work-fat-tmpfile-v2-4-99af97d95683@kernel.org> Date: Sat, 05 Dec 2026 16:44:01 +0900 Message-ID: <871p7w2mv2.fsf@mail.parknet.co.jp> User-Agent: Gnus/5.13 (Gnus v5.13) X-Mailing-List: linux-kernel@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 Christian Brauner writes: > Currently, vfat doesn't implement ->link() since FAT has no hard links > and link(2) fails with EPERM. But O_TMPFILE is only half a feature > without linkat(). Worse, implementing just ->tmpfile() would break > userspace that works fine right now. systemd's > open_tmpfile_linkable_at() only falls back to a named temporary file if > opening with O_TMPFILE fails. If the open succeeds link_tmpfile_at() > calls linkat() and gives up if that fails. bootctl writes loader.conf, > entries.srel and the boot loader binaries to the ESP like that. > > So add a ->link() that only gives an O_TMPFILE its first name. > vfs_link() refuses to link an inode without links unless it is > I_LINKABLE and it checks that under the inode lock. So an inode without > links that makes it into vfat_link() is an O_TMPFILE that may be > linked. Everything else still gets EPERM. > > Linking does what vfat_rename() does for a new name: add the directory > entry, attach the inode at its position and let the inode write fill in > the start cluster and the size. > > If the system crashes while an O_TMPFILE is open its clusters stay > allocated but no directory entry refers to them. The same thing happens > to an open file that was unlinked. fsck.fat finds them as lost > clusters, with -a it saves them to FSCKnnnn.REC files. ext2, minix and > udf implement O_TMPFILE without orphan handling as well. > > Reviewed-by: Alexander Mikhalitsyn > Signed-off-by: Christian Brauner (Amutable) Acked-by: OGAWA Hirofumi Thanks. > --- > fs/fat/namei_vfat.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 47 insertions(+) > > diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c > index 791f2d7b85092..f17f5a2aaed99 100644 > --- a/fs/fat/namei_vfat.c > +++ b/fs/fat/namei_vfat.c > @@ -938,6 +938,51 @@ static void vfat_update_dir_metadata(struct inode *dir, struct timespec64 *ts) > (void)sync_inode_metadata(dir, 1); > } > > +static int vfat_link(struct dentry *old_dentry, struct inode *dir, > + struct dentry *dentry) > +{ > + struct inode *inode = d_inode(old_dentry); > + struct super_block *sb = dir->i_sb; > + struct fat_slot_info sinfo; > + struct timespec64 ts; > + int err, err2; > + > + /* No hard links on FAT, only give an O_TMPFILE its first name. */ > + if (inode->i_nlink) > + return -EPERM; > + > + mutex_lock(&MSDOS_SB(sb)->s_lock); > + > + ts = current_time(dir); > + err = vfat_add_entry(dir, &dentry->d_name, 0, 0, &ts, &sinfo); > + if (err) > + goto out; > + inode_inc_iversion(dir); > + > + fat_attach(inode, sinfo.i_pos); > + /* FIXME: this sync should be done within vfat_add_entry() */ > + err = vfat_sync_ipos(dir, inode); > + if (err) > + goto out_detach; > + brelse(sinfo.bh); > + > + inc_nlink(inode); > + ihold(inode); > + d_instantiate(dentry, inode); > + mutex_unlock(&MSDOS_SB(sb)->s_lock); > + return 0; > + > +out_detach: > + fat_detach(inode); > + err2 = fat_remove_entries(dir, &sinfo); /* and releases bh */ > + if (err2) > + fat_msg(sb, KERN_WARNING, > + "failed to roll back new entry (%d)", err2); > +out: > + mutex_unlock(&MSDOS_SB(sb)->s_lock); > + return err; > +} > + > static int vfat_rename(struct inode *old_dir, struct dentry *old_dentry, > struct inode *new_dir, struct dentry *new_dentry) > { > @@ -1190,10 +1235,12 @@ static int vfat_rename2(const struct mnt_idmap *idmap, struct inode *old_dir, > static const struct inode_operations vfat_dir_inode_operations = { > .create = vfat_create, > .lookup = vfat_lookup, > + .link = vfat_link, > .unlink = vfat_unlink, > .mkdir = vfat_mkdir, > .rmdir = vfat_rmdir, > .rename = vfat_rename2, > + .tmpfile = fat_tmpfile, > .setattr = fat_setattr, > .getattr = fat_getattr, > .fileattr_get = fat_fileattr_get, -- OGAWA Hirofumi