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