forked from linux-test-project/ltp
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chmod02.c: Block mode changes of symlinks
Signed-off-by: Wei Gao <wegao@suse.com>
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/chmod01 | ||
/chmod02 | ||
/chmod03 | ||
/chmod05 | ||
/chmod06 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
/* | ||
* Copyright (c) 2024 Wei Gao <wegao@suse.com> | ||
*/ | ||
|
||
/*\ | ||
* [Description] | ||
* | ||
* Test for kernel commit 5d1f903f75a80daa4dfb3d84e114ec8ecbf29956 | ||
* "attr: block mode changes of symlinks". | ||
* | ||
*/ | ||
|
||
#include "lapi/fcntl.h" | ||
#include "tst_test.h" | ||
|
||
#define MODE 0644 | ||
#define TESTFILE "testfile" | ||
#define TESTFILE_SYMLINK "testfile_symlink" | ||
#define MNTPOINT "mntpoint" | ||
|
||
static void run(void) | ||
{ | ||
struct stat stat_file, stat_sym; | ||
int mode = 0; | ||
char fd_path[100]; | ||
|
||
int fd = SAFE_OPEN(TESTFILE_SYMLINK, O_PATH | O_NOFOLLOW); | ||
|
||
sprintf(fd_path, "/proc/self/fd/%d", fd); | ||
|
||
TST_EXP_FAIL(chmod(fd_path, mode), ENOTSUP, "chmod(%s, %04o)", | ||
TESTFILE_SYMLINK, mode); | ||
|
||
SAFE_STAT(TESTFILE, &stat_file); | ||
SAFE_LSTAT(TESTFILE_SYMLINK, &stat_sym); | ||
|
||
stat_file.st_mode &= ~S_IFREG; | ||
stat_sym.st_mode &= ~S_IFLNK; | ||
|
||
if (stat_file.st_mode == (unsigned int)mode) { | ||
tst_res(TFAIL, "stat(%s) mode=%04o", | ||
TESTFILE, stat_file.st_mode); | ||
} else { | ||
tst_res(TPASS, "stat(%s) mode=%04o", | ||
TESTFILE, stat_file.st_mode); | ||
} | ||
|
||
if (stat_sym.st_mode == (unsigned int)mode) { | ||
tst_res(TFAIL, "stat(%s) mode=%04o", | ||
TESTFILE_SYMLINK, stat_sym.st_mode); | ||
} else { | ||
tst_res(TPASS, "stat(%s) mode=%04o", | ||
TESTFILE_SYMLINK, stat_sym.st_mode); | ||
} | ||
|
||
SAFE_CLOSE(fd); | ||
} | ||
|
||
static void setup(void) | ||
{ | ||
SAFE_CHDIR(MNT_POINT); | ||
SAFE_TOUCH(TESTFILE, MODE, NULL); | ||
SAFE_SYMLINK(TESTFILE, TESTFILE_SYMLINK); | ||
} | ||
|
||
static struct tst_test test = { | ||
.setup = setup, | ||
.test_all = run, | ||
.needs_tmpdir = 1, | ||
.min_kver = "6.6", | ||
.mount_device = 1, | ||
.mntpoint = MNTPOINT, | ||
.all_filesystems = 1 | ||
}; |