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=1796456669; b=bbhM49UaqtgfLJn1F8BtqJ/ooguRP5v3wUj0ffDhaYH72lzSP2ZVaWVQNlZKRgGF8fog uwTddPMTPaNFkobXVtB/KAzXTmPcACFA2jCC1Cmfo8XaTiW5lmHtRj+cBIEF+Z6e2RIdN QiQnnZ+2mN497eMk+YrCPGFOlFWlzcvQ08Em1iySb+zoj0smuLqOzAr87+hcZO7zhElNl CaeHK6wo5EufhMvbRuPhIawPU451XtA0elJLtUJgZ7mpjcEJZsXCcj2gryqOzIP2gYlBA eWn5b85Vh8P48GB1oiNHbBz38+Y8Lnr2WuKALPTZH77SZHWugYmoWipHkRh6Ib1K1ng== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796456669; 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=ayqynQrs5DJL7e04zlRujXe/b9gi2bqagyyp+XS1kBY=; b=JSFd+2XVXavhkfc9gxRWYMH5giMorzj0GDojgXZ2gS/7S0fMbFXvXBbWMXA1gYOm5ZK2 T/iD/eLjqzlgSb6p6m8VdlOo+fsxQEta+B2wMQOXHuAj4fwfQSle2sWGLQKbXQ7ZDQMBN 53+r4uoUd6lssdFJcDwICYIvY/jp7+cY+WoHUhMl97421EarIjmGMW4ytawCj8vany1Ss iG7Lse6lJnJ1R52+CB6GfQmkE+kssG5djAKkjh4uQr/ogPaNGSITR9LAMb/EyrobMPoNy t3peek1Pm4rvzFhzxt8wUv5HJVO3t7VVqd+AQDXEkBhWD8pj9TBHQ5UBcva+gqhDYGg== 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=xTrb0BZp; dkim=pass header.d=parknet.co.jp header.i=@parknet.co.jp header.a=ed25519-sha256 header.s=20250114-ed25519 header.b="KHcC/s8f"; 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 1CCE2606A322; Sat, 5 Dec 2026 07:44:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1CCE2606A322 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=xTrb0BZp; dkim=pass header.d=parknet.co.jp header.i=@parknet.co.jp header.a=ed25519-sha256 header.s=20250114-ed25519 header.b=KHcC/s8f Received: from ibmpc.myhome.or.jp (server.parknet.ne.jp [210.171.168.39]) by mail.parknet.co.jp (Postfix) with ESMTPSA id AB08B20BD286; Sat, 5 Dec 2026 16:44:26 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=parknet.co.jp; s=20250114; t=1796456666; 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=ayqynQrs5DJL7e04zlRujXe/b9gi2bqagyyp+XS1kBY=; b=xTrb0BZpzKBjTp0uQ8Vnc++dVB/31wDczSyOsIhOAOrFtin9rcJdnZXmhsda+jbkqu7S8f H0bti7Z2dsrLyHWGe0Y6eqUx4cuXrVC8yqxvvJd/axvZGbJwavx0pbSQYCPW43XFlbgA6Y xpB58951X5F/+WE0ITJidKIbUxhdaOdPAbyr2aSEZ+uWZgdSJ0GCpFOl+rGpUoaRYSoS8h i1VaBQSLPkqbhLN3WwILeyzzcgg1wsDkJFf+GAya7EYNtB9oJQV/zXFp8gfAzh9xjtVsFd dhUOivmCbwkp89czpWiOzpvmYfgOFR5GHq0kom0D8XA8C2Vj4O0OCIksppysDQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=parknet.co.jp; s=20250114-ed25519; t=1796456666; 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=ayqynQrs5DJL7e04zlRujXe/b9gi2bqagyyp+XS1kBY=; b=KHcC/s8fZ78s8wOCPLzGcd3eOi8BGNxopNQxFXPnT40QXUCI8Mpj5vfE0CM6iNDE/7D+4A FU8H7Vl4KqIRGNDA== Received: from devron.myhome.or.jp (devron.myhome.or.jp [192.168.0.3]) by ibmpc.myhome.or.jp (Postfix) with ESMTPS id 36E42E00155; Sat, 05 Dec 2026 16:44:26 +0900 (JST) Received: by devron.myhome.or.jp (Postfix, from userid 1000) id 218D42200167; Sat, 05 Dec 2026 16:44:26 +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 6/6] selftests/filesystems: add FAT O_TMPFILE tests In-Reply-To: <20261130-work-fat-tmpfile-v2-6-99af97d95683@kernel.org> References: <20261130-work-fat-tmpfile-v2-0-99af97d95683@kernel.org> <20261130-work-fat-tmpfile-v2-6-99af97d95683@kernel.org> Date: Sat, 05 Dec 2026 16:44:26 +0900 Message-ID: <87se0c189x.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: > Add tests for O_TMPFILE on vfat and msdos. run_fat_tests.sh runs them > on a vfat mount and on an msdos mount with the dots option. This tests > that: > > - an O_TMPFILE can be linked into its own and into another directory > - data written before and after linkat() ends up in the named file > - O_EXCL keeps it from being linked > - it can't be linked twice, nor again after it was unlinked > - a failed linkat() leaves it linkable > - link(2) of a regular file still fails with EPERM > - linkat() to a temporary name plus rename() replaces a file > - closing an unnamed O_TMPFILE frees its clusters > - with dots a leading dot makes the linked file hidden > > After the tests the image is unmounted, checked with fsck.vfat -n and > mounted again to compare a linked O_TMPFILE with a regular copy. > > Reviewed-by: Alexander Mikhalitsyn > Signed-off-by: Christian Brauner (Amutable) Acked-by: OGAWA Hirofumi Thanks. > --- > tools/testing/selftests/filesystems/fat/.gitignore | 1 + > tools/testing/selftests/filesystems/fat/Makefile | 2 +- > tools/testing/selftests/filesystems/fat/config | 1 + > .../selftests/filesystems/fat/run_fat_tests.sh | 41 +++ > tools/testing/selftests/filesystems/fat/tmpfile.c | 324 +++++++++++++++++++++ > 5 files changed, 368 insertions(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/filesystems/fat/.gitignore b/tools/testing/selftests/filesystems/fat/.gitignore > index b89920ed841cc..b541a20590e3f 100644 > --- a/tools/testing/selftests/filesystems/fat/.gitignore > +++ b/tools/testing/selftests/filesystems/fat/.gitignore > @@ -1,2 +1,3 @@ > # SPDX-License-Identifier: GPL-2.0-only > rename_exchange > +tmpfile > diff --git a/tools/testing/selftests/filesystems/fat/Makefile b/tools/testing/selftests/filesystems/fat/Makefile > index 902033f6ef098..4f3fb279056a7 100644 > --- a/tools/testing/selftests/filesystems/fat/Makefile > +++ b/tools/testing/selftests/filesystems/fat/Makefile > @@ -1,7 +1,7 @@ > # SPDX-License-Identifier: GPL-2.0 > > TEST_PROGS := run_fat_tests.sh > -TEST_GEN_PROGS_EXTENDED := rename_exchange > +TEST_GEN_PROGS_EXTENDED := rename_exchange tmpfile > CFLAGS += -O2 -g -Wall $(KHDR_INCLUDES) > > include ../../lib.mk > diff --git a/tools/testing/selftests/filesystems/fat/config b/tools/testing/selftests/filesystems/fat/config > index 6cf95e787a17b..49ee111e2e379 100644 > --- a/tools/testing/selftests/filesystems/fat/config > +++ b/tools/testing/selftests/filesystems/fat/config > @@ -1,2 +1,3 @@ > CONFIG_BLK_DEV_LOOP=y > +CONFIG_MSDOS_FS=y > CONFIG_VFAT_FS=y > diff --git a/tools/testing/selftests/filesystems/fat/run_fat_tests.sh b/tools/testing/selftests/filesystems/fat/run_fat_tests.sh > index 0712c8d23fd7e..38be991a44db1 100755 > --- a/tools/testing/selftests/filesystems/fat/run_fat_tests.sh > +++ b/tools/testing/selftests/filesystems/fat/run_fat_tests.sh > @@ -51,6 +51,15 @@ mount_image() > sudo mount -o loop "${IMG_PATH}" "${MNT_PATH}" > } > > +mount_image_as() > +{ > + local fstype="$1" > + local opts="$2" > + > + mkdir -p "${MNT_PATH}" > + sudo mount -t "${fstype}" -o "loop${opts:+,${opts}}" "${IMG_PATH}" "${MNT_PATH}" > +} > + > rename_exchange_test() > { > local rename_exchange="${BASE_DIR}/rename_exchange" > @@ -86,11 +95,43 @@ unmount_image() > sudo umount "${MNT_PATH}" &> /dev/null > } > > +tmpfile_test() > +{ > + local tmpfile="${BASE_DIR}/tmpfile" > + local fstype="$1" > + local opts="$2" > + local dots=0 > + > + if [ "${opts}" = "dots" ]; then > + dots=1 > + fi > + > + create_loopback > + mount_image_as "${fstype}" "${opts}" > + sudo env FAT_MNT="${MNT_PATH}" FAT_DOTS="${dots}" "${tmpfile}" > + unmount_image > + > + # No clusters leaked by unnamed O_TMPFILEs, named ones are complete. > + fsck.vfat -n "${IMG_PATH}" >/dev/null 2>&1 > + > + mount_image_as "${fstype}" "${opts}" > + # Missing if the tests skipped because O_TMPFILE isn't supported. > + if [ -e "${MNT_PATH}/regular.txt" ]; then > + cmp "${MNT_PATH}/tmpfile.txt" "${MNT_PATH}/regular.txt" >/dev/null 2>&1 > + if [ "${dots}" -eq 1 ]; then > + test -f "${MNT_PATH}/.hidden" > + fi > + fi > + unmount_image > +} > + > check_prereqs > create_loopback > mount_image > rename_exchange_test > rename_exchange_subdir_test > unmount_image > +tmpfile_test vfat "" > +tmpfile_test msdos dots > > exit 0 > diff --git a/tools/testing/selftests/filesystems/fat/tmpfile.c b/tools/testing/selftests/filesystems/fat/tmpfile.c > new file mode 100644 > index 0000000000000..324660267d1b1 > --- /dev/null > +++ b/tools/testing/selftests/filesystems/fat/tmpfile.c > @@ -0,0 +1,324 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * O_TMPFILE on vfat and msdos. run_fat_tests.sh mounts the image, passes the > + * mount point in FAT_MNT and sets FAT_DOTS=1 for msdos mounted with "dots". > + */ > +#define _GNU_SOURCE > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "../../kselftest_harness.h" > + > +/* Left behind for run_fat_tests.sh to check after a remount. */ > +#define TMPFILE_NAME "tmpfile.txt" > +#define REGULAR_NAME "regular.txt" > +#define HIDDEN_NAME ".hidden" > + > +/* Clusters the space test writes. */ > +#define SPACE_CLUSTERS 8 > + > +/* Several clusters plus a partial one, a prime period so no two look alike. */ > +#define PERSIST_SIZE (3 * 4096 + 123) > +#define PERSIST_PERIOD 251 > + > +static const char data[] = "written through an O_TMPFILE\n"; > +static const char old_data[] = "old\n"; > + > +static int open_tmpfile(int dir_fd, int flags) > +{ > + return openat(dir_fd, ".", O_TMPFILE | O_RDWR | O_CLOEXEC | flags, 0600); > +} > + > +static int link_tmpfile(int fd, int dir_fd, const char *name) > +{ > + return linkat(fd, "", dir_fd, name, AT_EMPTY_PATH); > +} > + > +static ssize_t read_file(int dir_fd, const char *name, char *buf, size_t size) > +{ > + ssize_t ret; > + int fd; > + > + fd = openat(dir_fd, name, O_RDONLY | O_CLOEXEC); > + if (fd < 0) > + return -1; > + ret = read(fd, buf, size); > + close(fd); > + return ret; > +} > + > +FIXTURE(tmpfile) { > + int mnt_fd; > + int dir_fd; > +}; > + > +FIXTURE_SETUP(tmpfile) > +{ > + const char *mnt = getenv("FAT_MNT"); > + char name[16]; > + int fd; > + > + if (!mnt) > + SKIP(return, "FAT_MNT not set, run this from run_fat_tests.sh"); > + > + self->mnt_fd = open(mnt, O_DIRECTORY | O_RDONLY | O_CLOEXEC); > + ASSERT_GE(self->mnt_fd, 0); > + > + /* A fresh directory per test, short enough for an 8.3 name. */ > + snprintf(name, sizeof(name), "t%d", getpid()); > + ASSERT_EQ(mkdirat(self->mnt_fd, name, 0755), 0); > + self->dir_fd = openat(self->mnt_fd, name, > + O_DIRECTORY | O_RDONLY | O_CLOEXEC); > + ASSERT_GE(self->dir_fd, 0); > + > + fd = open_tmpfile(self->dir_fd, 0); > + if (fd < 0 && errno == EOPNOTSUPP) > + SKIP(return, "O_TMPFILE not supported"); > + ASSERT_GE(fd, 0); > + close(fd); > +} > + > +FIXTURE_TEARDOWN(tmpfile) > +{ > + close(self->dir_fd); > + close(self->mnt_fd); > +} > + > +/* An O_TMPFILE gets a name and keeps what was written to it. */ > +TEST_F(tmpfile, link) > +{ > + char buf[sizeof(data)]; > + struct stat st; > + int fd; > + > + fd = open_tmpfile(self->dir_fd, 0); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(fstat(fd, &st), 0); > + ASSERT_EQ(st.st_nlink, 0); > + ASSERT_EQ(write(fd, data, sizeof(data)), sizeof(data)); > + > + ASSERT_EQ(link_tmpfile(fd, self->dir_fd, "file"), 0); > + ASSERT_EQ(fstat(fd, &st), 0); > + ASSERT_EQ(st.st_nlink, 1); > + ASSERT_EQ(st.st_size, sizeof(data)); > + ASSERT_EQ(close(fd), 0); > + > + ASSERT_EQ(read_file(self->dir_fd, "file", buf, sizeof(buf)), sizeof(data)); > + ASSERT_EQ(memcmp(buf, data, sizeof(data)), 0); > +} > + > +/* The name can be in another directory than the one O_TMPFILE was given. */ > +TEST_F(tmpfile, link_other_dir) > +{ > + char buf[sizeof(data)]; > + int fd, sub_fd; > + > + ASSERT_EQ(mkdirat(self->dir_fd, "sub", 0755), 0); > + sub_fd = openat(self->dir_fd, "sub", O_DIRECTORY | O_RDONLY | O_CLOEXEC); > + ASSERT_GE(sub_fd, 0); > + > + fd = open_tmpfile(self->dir_fd, 0); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(write(fd, data, sizeof(data)), sizeof(data)); > + ASSERT_EQ(link_tmpfile(fd, sub_fd, "file"), 0); > + ASSERT_EQ(close(fd), 0); > + > + ASSERT_EQ(read_file(sub_fd, "file", buf, sizeof(buf)), sizeof(data)); > + ASSERT_EQ(memcmp(buf, data, sizeof(data)), 0); > + close(sub_fd); > +} > + > +/* Data written after linkat() ends up in the named file too. */ > +TEST_F(tmpfile, write_after_link) > +{ > + char buf[2 * sizeof(data)]; > + struct stat st; > + int fd; > + > + fd = open_tmpfile(self->dir_fd, 0); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(write(fd, data, sizeof(data)), sizeof(data)); > + ASSERT_EQ(link_tmpfile(fd, self->dir_fd, "file"), 0); > + ASSERT_EQ(write(fd, data, sizeof(data)), sizeof(data)); > + ASSERT_EQ(close(fd), 0); > + > + ASSERT_EQ(fstatat(self->dir_fd, "file", &st, 0), 0); > + ASSERT_EQ(st.st_size, sizeof(buf)); > + ASSERT_EQ(read_file(self->dir_fd, "file", buf, sizeof(buf)), sizeof(buf)); > + ASSERT_EQ(memcmp(buf, data, sizeof(data)), 0); > + ASSERT_EQ(memcmp(buf + sizeof(data), data, sizeof(data)), 0); > +} > + > +/* O_EXCL keeps an O_TMPFILE from ever getting a name. */ > +TEST_F(tmpfile, excl) > +{ > + int fd; > + > + fd = open_tmpfile(self->dir_fd, O_EXCL); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(link_tmpfile(fd, self->dir_fd, "file"), -1); > + ASSERT_EQ(errno, ENOENT); > + close(fd); > +} > + > +/* Only the first name sticks. */ > +TEST_F(tmpfile, link_twice) > +{ > + int fd; > + > + fd = open_tmpfile(self->dir_fd, 0); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(link_tmpfile(fd, self->dir_fd, "first"), 0); > + ASSERT_EQ(link_tmpfile(fd, self->dir_fd, "second"), -1); > + ASSERT_EQ(errno, EPERM); > + ASSERT_EQ(faccessat(self->dir_fd, "second", F_OK, 0), -1); > + ASSERT_EQ(errno, ENOENT); > + close(fd); > +} > + > +/* Once named and unlinked it is a plain unlinked file. */ > +TEST_F(tmpfile, relink_after_unlink) > +{ > + int fd; > + > + fd = open_tmpfile(self->dir_fd, 0); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(link_tmpfile(fd, self->dir_fd, "file"), 0); > + ASSERT_EQ(unlinkat(self->dir_fd, "file", 0), 0); > + ASSERT_EQ(link_tmpfile(fd, self->dir_fd, "file"), -1); > + ASSERT_EQ(errno, ENOENT); > + close(fd); > +} > + > +/* A failed linkat() leaves the O_TMPFILE linkable. */ > +TEST_F(tmpfile, link_invalid_name) > +{ > + int fd; > + > + fd = open_tmpfile(self->dir_fd, 0); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(link_tmpfile(fd, self->dir_fd, "bad*name"), -1); > + ASSERT_EQ(errno, EINVAL); > + ASSERT_EQ(link_tmpfile(fd, self->dir_fd, "file"), 0); > + close(fd); > +} > + > +/* FAT still has no hard links. */ > +TEST_F(tmpfile, hardlink) > +{ > + int fd; > + > + fd = openat(self->dir_fd, "file", O_CREAT | O_EXCL | O_RDWR | O_CLOEXEC, > + 0600); > + ASSERT_GE(fd, 0); > + close(fd); > + ASSERT_EQ(linkat(self->dir_fd, "file", self->dir_fd, "link", 0), -1); > + ASSERT_EQ(errno, EPERM); > +} > + > +/* Link under a temporary name and rename over the target, as systemd does. */ > +TEST_F(tmpfile, replace) > +{ > + char buf[sizeof(data)]; > + int fd; > + > + fd = openat(self->dir_fd, "target", O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC, > + 0600); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(write(fd, old_data, sizeof(old_data)), sizeof(old_data)); > + close(fd); > + > + fd = open_tmpfile(self->dir_fd, 0); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(write(fd, data, sizeof(data)), sizeof(data)); > + ASSERT_EQ(link_tmpfile(fd, self->dir_fd, "target.tmp"), 0); > + ASSERT_EQ(renameat(self->dir_fd, "target.tmp", self->dir_fd, "target"), 0); > + ASSERT_EQ(close(fd), 0); > + > + ASSERT_EQ(read_file(self->dir_fd, "target", buf, sizeof(buf)), sizeof(data)); > + ASSERT_EQ(memcmp(buf, data, sizeof(data)), 0); > +} > + > +/* Closing an unnamed O_TMPFILE gives its clusters back. */ > +TEST_F(tmpfile, space) > +{ > + struct statvfs before, during, after; > + size_t len; > + char *buf; > + int fd; > + > + ASSERT_EQ(fstatvfs(self->dir_fd, &before), 0); > + len = SPACE_CLUSTERS * before.f_bsize; > + buf = malloc(len); > + ASSERT_NE(buf, NULL); > + memset(buf, 'x', len); > + > + fd = open_tmpfile(self->dir_fd, 0); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(write(fd, buf, len), len); > + ASSERT_EQ(fstatvfs(fd, &during), 0); > + ASSERT_LE(during.f_bfree, before.f_bfree - SPACE_CLUSTERS); > + ASSERT_EQ(close(fd), 0); > + > + ASSERT_EQ(fstatvfs(self->dir_fd, &after), 0); > + ASSERT_EQ(after.f_bfree, before.f_bfree); > + free(buf); > +} > + > +/* A named O_TMPFILE and a regular copy, compared after a remount. */ > +TEST_F(tmpfile, persist) > +{ > + char buf[PERSIST_SIZE]; > + size_t half = sizeof(buf) / 2; > + size_t i; > + int fd; > + > + for (i = 0; i < sizeof(buf); i++) > + buf[i] = i % PERSIST_PERIOD; > + > + fd = openat(self->mnt_fd, REGULAR_NAME, > + O_CREAT | O_EXCL | O_WRONLY | O_CLOEXEC, 0644); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(write(fd, buf, sizeof(buf)), sizeof(buf)); > + ASSERT_EQ(fsync(fd), 0); > + ASSERT_EQ(close(fd), 0); > + > + fd = open_tmpfile(self->mnt_fd, 0); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(write(fd, buf, half), half); > + ASSERT_EQ(link_tmpfile(fd, self->mnt_fd, TMPFILE_NAME), 0); > + ASSERT_EQ(write(fd, buf + half, sizeof(buf) - half), sizeof(buf) - half); > + ASSERT_EQ(fsync(fd), 0); > + ASSERT_EQ(close(fd), 0); > + ASSERT_EQ(fsync(self->mnt_fd), 0); > +} > + > +/* On msdos with "dots" a leading dot makes the named O_TMPFILE hidden. */ > +TEST_F(tmpfile, hidden) > +{ > + const char *dots = getenv("FAT_DOTS"); > + __u32 attrs; > + int fd; > + > + if (!dots || strcmp(dots, "1")) > + SKIP(return, "needs msdos mounted with the dots option"); > + > + fd = open_tmpfile(self->mnt_fd, 0); > + ASSERT_GE(fd, 0); > + ASSERT_EQ(link_tmpfile(fd, self->mnt_fd, HIDDEN_NAME), 0); > + ASSERT_EQ(ioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &attrs), 0); > + ASSERT_TRUE(attrs & ATTR_HIDDEN); > + ASSERT_EQ(fsync(fd), 0); > + ASSERT_EQ(close(fd), 0); > + ASSERT_EQ(fsync(self->mnt_fd), 0); > +} > + > +TEST_HARNESS_MAIN -- OGAWA Hirofumi