mirror of
https://github.com/linux-apfs/apfstests.git
synced 2026-05-01 15:01:44 -07:00
c432589da3
Mostly scripted like all the others, manually added tags to Makefile, nsexec.c and t_mmap_writev.c. Manually touched up open_by_handle.c and t_encrypted_d_revalidate.c post script. Notes for future reference: - src/log-writes/ code has no explicit copyright or license tags, nor does the upstream repository, hence license is unknown. Need Josef to clarify the license and send a patch adding SPDX tags to those files. - src/perf code has no explicit copyright or license tags, but it was code submitted explictly for fstests so it is assumed to be GPLv2.0 and tagged as such. If this is incorrect, Josef will need to clarify copyright and the license and send patches to correct it. Signed-off-by: Dave Chinner <dchinner@redhat.com>
57 lines
1.0 KiB
C
57 lines
1.0 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (c) 2004 Silicon Graphics, Inc.
|
|
* All Rights Reserved.
|
|
*/
|
|
|
|
/*
|
|
* tests out if access checking is done on write path
|
|
* 1. opens with write perms
|
|
* 2. fchmod to turn off write perms
|
|
* 3. writes to file
|
|
*/
|
|
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <string.h>
|
|
#include <fcntl.h>
|
|
#include <stdio.h>
|
|
|
|
int
|
|
main(int argc, char* argv[])
|
|
{
|
|
char *path;
|
|
int fd;
|
|
char *buf = "hi there\n";
|
|
ssize_t x;
|
|
int sts;
|
|
|
|
if (argc != 2) {
|
|
fprintf(stderr, "%s: requires path argument\n", argv[0]);
|
|
return 1;
|
|
}
|
|
|
|
path = argv[1];
|
|
|
|
printf("open for write \"%s\" with 777\n", path);
|
|
fd = open(path, O_RDWR, 0777);
|
|
if (fd == -1) {
|
|
perror("open");
|
|
return 1;
|
|
}
|
|
printf("remove perms on file\n");
|
|
sts = fchmod(fd, 0);
|
|
if (sts == -1) {
|
|
perror("fchmod");
|
|
return 1;
|
|
}
|
|
printf("write to the file\n");
|
|
x = write(fd, buf, strlen(buf));
|
|
if (x == -1) {
|
|
perror("write");
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|