1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
/*
* Check decoding of quotactl_fd syscall.
*
* Copyright (c) 2015-2021 Dmitry V. Levin <ldv@strace.io>
* All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "tests.h"
#include "scno.h"
#include "xmalloc.h"
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/quota.h>
#include "xlat.h"
#include "xlat/quota_formats.h"
#ifndef DECODE_FDS
# define DECODE_FDS 0
#endif
#ifndef SKIP_IF_PROC_IS_UNAVAILABLE
# define SKIP_IF_PROC_IS_UNAVAILABLE
#endif
static const char *errstr;
static long
k_quotactl_fd(const unsigned int fd,
const unsigned int cmd,
const uint32_t id,
const void *const ptr)
{
const kernel_ulong_t fill = (kernel_ulong_t) 0xdefaced00000000ULL;
const kernel_ulong_t bad = (kernel_ulong_t) 0xbadc0dedbadc0dedULL;
const kernel_ulong_t arg1 = fill | fd;
const kernel_ulong_t arg2 = fill | cmd;
const kernel_ulong_t arg3 = fill | id;
const kernel_ulong_t arg4 = (uintptr_t) ptr;
const long rc = syscall(__NR_quotactl_fd,
arg1, arg2, arg3, arg4, bad, bad);
errstr = sprintrc(rc);
return rc;
}
int
main(void)
{
SKIP_IF_PROC_IS_UNAVAILABLE;
static const char fd_path[] = "/dev/full";
int fd = open(fd_path, O_WRONLY);
if (fd < 0)
perror_msg_and_fail("open: %s", fd_path);
char *fd_str = xasprintf("%d%s%s%s", fd,
DECODE_FDS ? "<" : "",
DECODE_FDS ? fd_path : "",
DECODE_FDS ? ">" : "");
TAIL_ALLOC_OBJECT_CONST_PTR(uint32_t, fmt);
k_quotactl_fd(-1, QCMD(Q_GETFMT, GRPQUOTA), -2, fmt);
#ifndef PATH_TRACING
printf("quotactl_fd(-1, QCMD(Q_GETFMT, GRPQUOTA), %p) = %s\n",
fmt, errstr);
#endif
long rc = k_quotactl_fd(fd, QCMD(Q_GETFMT, USRQUOTA), -3, fmt);
printf("quotactl_fd(%s, QCMD(Q_GETFMT, USRQUOTA), ", fd_str);
if (rc) {
printf("%p", fmt);
} else {
printf("[");
printxval(quota_formats, *fmt, "QFMT_VFS_???");
printf("]");
}
printf(") = %s\n", errstr);
puts("+++ exited with 0 +++");
return 0;
}
|