mirror of
https://github.com/versity/scoutfs.git
synced 2025-12-23 05:25:18 +00:00
Add testing of O_TMPFILE umask
There were kernels that didn't apply the current umask to inode modes created with O_TMPFILE without acls. Let's have a test running to make sure that we're not surprised if we come across one. Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
1
tests/.gitignore
vendored
1
tests/.gitignore
vendored
@@ -8,3 +8,4 @@ src/bulk_create_paths
|
|||||||
src/find_xattrs
|
src/find_xattrs
|
||||||
src/stage_tmpfile
|
src/stage_tmpfile
|
||||||
src/create_xattr_loop
|
src/create_xattr_loop
|
||||||
|
src/o_tmpfile_umask
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ BIN := src/createmany \
|
|||||||
src/stage_tmpfile \
|
src/stage_tmpfile \
|
||||||
src/find_xattrs \
|
src/find_xattrs \
|
||||||
src/create_xattr_loop \
|
src/create_xattr_loop \
|
||||||
src/fragmented_data_extents
|
src/fragmented_data_extents \
|
||||||
|
src/o_tmpfile_umask
|
||||||
|
|
||||||
DEPS := $(wildcard src/*.d)
|
DEPS := $(wildcard src/*.d)
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,10 @@
|
|||||||
|
== non-acl O_TMPFILE creation honors umask
|
||||||
|
umask 022
|
||||||
|
fstat after open(0777): 0100755
|
||||||
|
stat after linkat: 0100755
|
||||||
|
umask 077
|
||||||
|
fstat after open(0777): 0100700
|
||||||
|
stat after linkat: 0100700
|
||||||
== stage from tmpfile
|
== stage from tmpfile
|
||||||
total file size 33669120
|
total file size 33669120
|
||||||
00000000 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAAAAAAAA|
|
00000000 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAAAAAAAA|
|
||||||
|
|||||||
97
tests/src/o_tmpfile_umask.c
Normal file
97
tests/src/o_tmpfile_umask.c
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Show the modes of files as we create them with O_TMPFILE and link
|
||||||
|
* them into the namespace.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2022 Versity Software, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public
|
||||||
|
* License v2 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _GNU_SOURCE
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#endif
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
static void linkat_tmpfile_modes(char *dir, char *lpath, mode_t mode)
|
||||||
|
{
|
||||||
|
char proc_self[PATH_MAX];
|
||||||
|
struct stat st;
|
||||||
|
int ret;
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
umask(mode);
|
||||||
|
printf("umask 0%o\n", mode);
|
||||||
|
|
||||||
|
fd = open(dir, O_RDWR | O_TMPFILE, 0777);
|
||||||
|
if (fd < 0) {
|
||||||
|
perror("open(O_TMPFILE)");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = fstat(fd, &st);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("fstat");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("fstat after open(0777): 0%o\n", st.st_mode);
|
||||||
|
|
||||||
|
snprintf(proc_self, sizeof(proc_self), "/proc/self/fd/%d", fd);
|
||||||
|
|
||||||
|
ret = linkat(AT_FDCWD, proc_self, AT_FDCWD, lpath, AT_SYMLINK_FOLLOW);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("linkat");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
ret = stat(lpath, &st);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("fstat");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("stat after linkat: 0%o\n", st.st_mode);
|
||||||
|
|
||||||
|
ret = unlink(lpath);
|
||||||
|
if (ret < 0) {
|
||||||
|
perror("unlink");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
char *lpath;
|
||||||
|
char *dir;
|
||||||
|
|
||||||
|
if (argc < 3) {
|
||||||
|
printf("%s <open_dir> <linkat_path>\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = argv[1];
|
||||||
|
lpath = argv[2];
|
||||||
|
|
||||||
|
linkat_tmpfile_modes(dir, lpath, 022);
|
||||||
|
linkat_tmpfile_modes(dir, lpath, 077);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -4,6 +4,9 @@
|
|||||||
|
|
||||||
t_require_commands stage_tmpfile hexdump
|
t_require_commands stage_tmpfile hexdump
|
||||||
|
|
||||||
|
echo "== non-acl O_TMPFILE creation honors umask"
|
||||||
|
o_tmpfile_umask "$T_D0" "$T_D0/umask-file"
|
||||||
|
|
||||||
echo "== stage from tmpfile"
|
echo "== stage from tmpfile"
|
||||||
DEST_FILE="$T_D0/dest_file"
|
DEST_FILE="$T_D0/dest_file"
|
||||||
stage_tmpfile $T_D0 $DEST_FILE
|
stage_tmpfile $T_D0 $DEST_FILE
|
||||||
|
|||||||
Reference in New Issue
Block a user