2 * Common definitions for Linux and XFS quota tests.
4 * Copyright (c) 2016 Eugene Syromyatnikov <evgsyr@gmail.com>
5 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef STRACE_TESTS_QUOTACTL_H
32 #define STRACE_TESTS_QUOTACTL_H
34 # include <inttypes.h>
37 # include "print_fields.h"
39 # ifdef HAVE_LINUX_QUOTA_H
40 /* Broken in CentOS 5: has extern spinlock_t dq_data_lock; declaration */
41 # include <linux/quota.h>
43 # include <linux/types.h>
44 /* Broken in some new glibc versions: have Q_GETNEXTQUOTA definition but no
45 * struct nextdqblk defined. Fixed in glibc-2.24-106-g4d72808. */
46 # include <sys/quota.h>
50 # define QCMD_CMD(_val) ((unsigned) (_val) >> SUBCMDSHIFT)
51 # endif /* !QCMD_CMD */
54 # define QCMD_TYPE(_val) ((unsigned) (_val) & SUBCMDMASK)
55 # endif /* !QCMD_TYPE */
61 typedef void (*print_cb)(long rc, void *addr, void *arg);
63 enum check_quotactl_flag_bits {
71 enum check_quotactl_flags {
73 CQF_ID_SKIP = 1 << CQF_ID_SKIP_BIT,
74 CQF_ID_STR = 1 << CQF_ID_STR_BIT,
75 CQF_ADDR_SKIP = 1 << CQF_ADDR_SKIP_BIT,
76 CQF_ADDR_STR = 1 << CQF_ADDR_STR_BIT,
77 CQF_ADDR_CB = 1 << CQF_ADDR_CB_BIT,
82 check_quota(uint32_t flags, int cmd, const char *cmd_str,
83 const char *special, const char *special_str, ...)
86 const char *addr_str = NULL;
87 const char *id_str = NULL;
89 print_cb addr_cb = NULL;
90 void *addr_cb_arg = NULL;
95 va_start(ap, special_str);
97 if (!(flags & CQF_ID_SKIP)) {
98 id = va_arg(ap, uint32_t);
100 if (flags & CQF_ID_STR)
101 id_str = va_arg(ap, const char *);
104 if (!(flags & CQF_ADDR_SKIP)) {
105 addr = va_arg(ap, void *);
107 if (flags & CQF_ADDR_CB) {
108 addr_cb = va_arg(ap, print_cb);
109 addr_cb_arg = va_arg(ap, void *);
110 } else if (flags & CQF_ADDR_STR) {
111 addr_str = va_arg(ap, const char *);
117 rc = syscall(__NR_quotactl, cmd, special, id, addr);
118 printf("quotactl(%s, %s", cmd_str, special_str);
120 if (!(flags & CQF_ID_SKIP)) {
121 if (flags & CQF_ID_STR) {
122 printf(", %s", id_str);
124 if (id == (uint32_t)-1)
131 if (!(flags & CQF_ADDR_SKIP)) {
132 if (flags & CQF_ADDR_CB) {
134 addr_cb(rc, addr, addr_cb_arg);
135 } else if (flags & CQF_ADDR_STR) {
136 printf(", %s", addr_str);
138 printf(", %p", addr);
142 printf(") = %s\n", sprintrc(rc));
146 static const int bogus_cmd = 0xbadc0ded;
147 static const int bogus_id = 0xca7faced;
149 /* It is invalid anyway due to the slash in the end */
150 static const char *bogus_dev = "/dev/bogus/";
151 static const char *bogus_dev_str = "\"/dev/bogus/\"";
153 static const char unterminated_data[] = { '\1', '\2', '\3' };
155 #endif /* !STRACE_TESTS_QUOTACTL_H */