Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The Chromium OS Authors. |
| 3 | * Written by Mike Frysinger <vapier@gentoo.org>. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "defs.h" |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 29 | #include <linux/ioctl.h> |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 30 | #include <linux/loop.h> |
| 31 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 32 | #include "xlat/loop_flags_options.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 33 | #include "xlat/loop_crypt_type_options.h" |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 34 | |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 35 | static void |
| 36 | decode_loop_info(struct tcb *tcp, const long addr) |
| 37 | { |
| 38 | struct loop_info info; |
| 39 | |
| 40 | tprints(", "); |
| 41 | if (umove_or_printaddr(tcp, addr, &info)) |
| 42 | return; |
| 43 | |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 44 | tprintf("{lo_number=%d", info.lo_number); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 45 | |
| 46 | if (!abbrev(tcp)) { |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 47 | tprintf(", lo_device=%#lx, lo_inode=%lu, lo_rdevice=%#lx", |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 48 | (unsigned long) info.lo_device, |
| 49 | info.lo_inode, |
| 50 | (unsigned long) info.lo_rdevice); |
| 51 | } |
| 52 | |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 53 | tprintf(", lo_offset=%#x", info.lo_offset); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 54 | |
| 55 | if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) { |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 56 | tprints(", lo_encrypt_type="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 57 | printxval(loop_crypt_type_options, info.lo_encrypt_type, |
| 58 | "LO_CRYPT_???"); |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 59 | tprintf(", lo_encrypt_key_size=%d", info.lo_encrypt_key_size); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 60 | } |
| 61 | |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 62 | tprints(", lo_flags="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 63 | printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???"); |
| 64 | |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 65 | tprints(", lo_name="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 66 | print_quoted_string(info.lo_name, LO_NAME_SIZE, |
| 67 | QUOTE_0_TERMINATED); |
| 68 | |
| 69 | if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) { |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 70 | tprints(", lo_encrypt_key="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 71 | print_quoted_string((void *) info.lo_encrypt_key, |
| 72 | LO_KEY_SIZE, 0); |
| 73 | } |
| 74 | |
| 75 | if (!abbrev(tcp)) |
Dmitry V. Levin | b7166a6 | 2016-05-29 22:34:30 +0000 | [diff] [blame^] | 76 | tprintf(", lo_init=[%#lx, %#lx]" |
| 77 | ", reserved=[%#x, %#x, %#x, %#x]}", |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 78 | info.lo_init[0], info.lo_init[1], |
| 79 | info.reserved[0], info.reserved[1], |
| 80 | info.reserved[2], info.reserved[3]); |
| 81 | else |
| 82 | tprints(", ...}"); |
| 83 | } |
| 84 | |
| 85 | static void |
| 86 | decode_loop_info64(struct tcb *tcp, const long addr) |
| 87 | { |
| 88 | struct loop_info64 info64; |
| 89 | |
| 90 | tprints(", "); |
| 91 | if (umove_or_printaddr(tcp, addr, &info64)) |
| 92 | return; |
| 93 | |
| 94 | if (!abbrev(tcp)) { |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 95 | tprintf("{lo_device=%" PRIu64 ", lo_inode=%" PRIu64 |
| 96 | ", lo_rdevice=%" PRIu64 ", lo_offset=%#" PRIx64 |
| 97 | ", lo_sizelimit=%" PRIu64 ", lo_number=%" PRIu32, |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 98 | (uint64_t) info64.lo_device, |
| 99 | (uint64_t) info64.lo_inode, |
| 100 | (uint64_t) info64.lo_rdevice, |
| 101 | (uint64_t) info64.lo_offset, |
| 102 | (uint64_t) info64.lo_sizelimit, |
| 103 | (uint32_t) info64.lo_number); |
| 104 | } else { |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 105 | tprintf("{lo_offset=%#" PRIx64 ", lo_number=%" PRIu32, |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 106 | (uint64_t) info64.lo_offset, |
| 107 | (uint32_t) info64.lo_number); |
| 108 | } |
| 109 | |
| 110 | if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) { |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 111 | tprints(", lo_encrypt_type="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 112 | printxval(loop_crypt_type_options, info64.lo_encrypt_type, |
| 113 | "LO_CRYPT_???"); |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 114 | tprintf(", lo_encrypt_key_size=%" PRIu32, |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 115 | info64.lo_encrypt_key_size); |
| 116 | } |
| 117 | |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 118 | tprints(", lo_flags="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 119 | printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???"); |
| 120 | |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 121 | tprints(", lo_file_name="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 122 | print_quoted_string((void *) info64.lo_file_name, |
| 123 | LO_NAME_SIZE, QUOTE_0_TERMINATED); |
| 124 | |
| 125 | if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) { |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 126 | tprints(", lo_crypt_name="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 127 | print_quoted_string((void *) info64.lo_crypt_name, |
| 128 | LO_NAME_SIZE, QUOTE_0_TERMINATED); |
Dmitry V. Levin | 25129ac | 2016-05-29 22:28:28 +0000 | [diff] [blame] | 129 | tprints(", lo_encrypt_key="); |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 130 | print_quoted_string((void *) info64.lo_encrypt_key, |
| 131 | LO_KEY_SIZE, 0); |
| 132 | } |
| 133 | |
| 134 | if (!abbrev(tcp)) |
Dmitry V. Levin | b7166a6 | 2016-05-29 22:34:30 +0000 | [diff] [blame^] | 135 | tprintf(", lo_init=[%#" PRIx64 ", %#" PRIx64 "]}", |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 136 | (uint64_t) info64.lo_init[0], |
| 137 | (uint64_t) info64.lo_init[1]); |
| 138 | else |
| 139 | tprints(", ...}"); |
| 140 | } |
| 141 | |
Dmitry V. Levin | c7afb48 | 2015-01-19 18:44:21 +0000 | [diff] [blame] | 142 | int |
| 143 | loop_ioctl(struct tcb *tcp, const unsigned int code, long arg) |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 144 | { |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 145 | if (!verbose(tcp)) |
| 146 | return RVAL_DECODED; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 147 | |
| 148 | switch (code) { |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 149 | case LOOP_GET_STATUS: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 150 | if (entering(tcp)) |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 151 | return 0; |
Dmitry V. Levin | bece24d | 2016-05-29 22:15:53 +0000 | [diff] [blame] | 152 | /* fall through */ |
| 153 | case LOOP_SET_STATUS: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 154 | decode_loop_info(tcp, arg); |
| 155 | break; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 156 | |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 157 | case LOOP_GET_STATUS64: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 158 | if (entering(tcp)) |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 159 | return 0; |
Dmitry V. Levin | bece24d | 2016-05-29 22:15:53 +0000 | [diff] [blame] | 160 | /* fall through */ |
| 161 | case LOOP_SET_STATUS64: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 162 | decode_loop_info64(tcp, arg); |
| 163 | break; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 164 | |
| 165 | case LOOP_CLR_FD: |
Dmitry V. Levin | cf050db | 2012-05-02 10:21:49 +0000 | [diff] [blame] | 166 | #ifdef LOOP_SET_CAPACITY |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 167 | case LOOP_SET_CAPACITY: |
Dmitry V. Levin | cf050db | 2012-05-02 10:21:49 +0000 | [diff] [blame] | 168 | #endif |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 169 | #ifdef LOOP_CTL_GET_FREE |
| 170 | /* newer loop-control stuff */ |
| 171 | case LOOP_CTL_GET_FREE: |
| 172 | #endif |
| 173 | /* Takes no arguments */ |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 174 | break; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 175 | |
| 176 | case LOOP_SET_FD: |
| 177 | case LOOP_CHANGE_FD: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 178 | tprints(", "); |
| 179 | printfd(tcp, arg); |
| 180 | break; |
| 181 | |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 182 | #ifdef LOOP_CTL_ADD |
| 183 | /* newer loop-control stuff */ |
| 184 | case LOOP_CTL_ADD: |
| 185 | case LOOP_CTL_REMOVE: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 186 | tprintf(", %d", (int) arg); |
| 187 | break; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 188 | #endif |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 189 | |
| 190 | default: |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 191 | return RVAL_DECODED; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 192 | } |
Dmitry V. Levin | 3cfabeb | 2015-07-04 17:40:02 +0300 | [diff] [blame] | 193 | |
| 194 | return RVAL_DECODED | 1; |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 195 | } |