Home | History | Annotate | Download | only in strace
      1 /*
      2  * Copyright (c) 2012 The Chromium OS Authors.
      3  * Written by Mike Frysinger <vapier (at) 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"
     29 
     30 #include <sys/ioctl.h>
     31 
     32 #include <linux/loop.h>
     33 
     34 #include "xlat/loop_flags_options.h"
     35 #include "xlat/loop_crypt_type_options.h"
     36 
     37 int loop_ioctl(struct tcb *tcp, long code, long arg)
     38 {
     39 	struct loop_info info;
     40 	struct loop_info64 info64;
     41 	char *s = alloca((LO_NAME_SIZE + LO_KEY_SIZE) * 4);
     42 
     43 	if (entering(tcp))
     44 		return 0;
     45 
     46 	switch (code) {
     47 
     48 	case LOOP_SET_STATUS:
     49 	case LOOP_GET_STATUS:
     50 		if (!verbose(tcp) || umove(tcp, arg, &info) < 0)
     51 			return 0;
     52 
     53 		tprintf(", {number=%d", info.lo_number);
     54 
     55 		if (!abbrev(tcp)) {
     56 			tprintf(", device=%#lx, inode=%lu, rdevice=%#lx",
     57 				(unsigned long) info.lo_device,
     58 				info.lo_inode,
     59 				(unsigned long) info.lo_rdevice);
     60 		}
     61 
     62 		tprintf(", offset=%#x", info.lo_offset);
     63 
     64 		if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
     65 			tprints(", encrypt_type=");
     66 			printxval(loop_crypt_type_options, info.lo_encrypt_type,
     67 				"LO_CRYPT_???");
     68 			tprintf(", encrypt_key_size=%d", info.lo_encrypt_key_size);
     69 		}
     70 
     71 		tprints(", flags=");
     72 		printflags(loop_flags_options, info.lo_flags, "LO_FLAGS_???");
     73 
     74 		string_quote(info.lo_name, s, -1, LO_NAME_SIZE);
     75 		tprintf(", name=%s", s);
     76 
     77 		if (!abbrev(tcp) || info.lo_encrypt_type != LO_CRYPT_NONE) {
     78 			string_quote((void *) info.lo_encrypt_key, s, 0, LO_KEY_SIZE);
     79 			tprintf(", encrypt_key=%s", s);
     80 		}
     81 
     82 		if (!abbrev(tcp))
     83 			tprintf(", init={%#lx, %#lx}"
     84 				", reserved={%#x, %#x, %#x, %#x}}",
     85 				info.lo_init[0], info.lo_init[1],
     86 				info.reserved[0], info.reserved[1],
     87 				info.reserved[2], info.reserved[3]);
     88 		else
     89 			tprints(", ...}");
     90 
     91 		return 1;
     92 
     93 	case LOOP_SET_STATUS64:
     94 	case LOOP_GET_STATUS64:
     95 		if (!verbose(tcp) || umove(tcp, arg, &info64) < 0)
     96 			return 0;
     97 
     98 		tprints(", {");
     99 
    100 		if (!abbrev(tcp)) {
    101 			tprintf("device=%" PRIu64 ", inode=%" PRIu64 ", "
    102 				"rdevice=%" PRIu64 ", offset=%#" PRIx64 ", "
    103 				"sizelimit=%" PRIu64 ", number=%" PRIu32,
    104 				(uint64_t) info64.lo_device,
    105 				(uint64_t) info64.lo_inode,
    106 				(uint64_t) info64.lo_rdevice,
    107 				(uint64_t) info64.lo_offset,
    108 				(uint64_t) info64.lo_sizelimit,
    109 				(uint32_t) info64.lo_number);
    110 		} else {
    111 			tprintf("offset=%#" PRIx64 ", number=%" PRIu32,
    112 				(uint64_t) info64.lo_offset,
    113 				(uint32_t) info64.lo_number);
    114 		}
    115 
    116 		if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
    117 			tprints(", encrypt_type=");
    118 			printxval(loop_crypt_type_options, info64.lo_encrypt_type,
    119 				"LO_CRYPT_???");
    120 			tprintf(", encrypt_key_size=%" PRIu32,
    121 				info64.lo_encrypt_key_size);
    122 		}
    123 
    124 		tprints(", flags=");
    125 		printflags(loop_flags_options, info64.lo_flags, "LO_FLAGS_???");
    126 
    127 		string_quote((void *) info64.lo_file_name, s, -1, LO_NAME_SIZE);
    128 		tprintf(", file_name=%s", s);
    129 
    130 		if (!abbrev(tcp) || info64.lo_encrypt_type != LO_CRYPT_NONE) {
    131 			string_quote((void *) info64.lo_crypt_name, s, -1, LO_NAME_SIZE);
    132 			tprintf(", crypt_name=%s", s);
    133 			string_quote((void *) info64.lo_encrypt_key, s, 0, LO_KEY_SIZE);
    134 			tprintf(", encrypt_key=%s", s);
    135 		}
    136 
    137 		if (!abbrev(tcp))
    138 			tprintf(", init={%#" PRIx64 ", %#" PRIx64 "}}",
    139 				(uint64_t) info64.lo_init[0],
    140 				(uint64_t) info64.lo_init[1]);
    141 		else
    142 			tprints(", ...}");
    143 
    144 		return 1;
    145 
    146 	case LOOP_CLR_FD:
    147 #ifdef LOOP_SET_CAPACITY
    148 	case LOOP_SET_CAPACITY:
    149 #endif
    150 #ifdef LOOP_CTL_GET_FREE
    151 	/* newer loop-control stuff */
    152 	case LOOP_CTL_GET_FREE:
    153 #endif
    154 		/* Takes no arguments */
    155 		return 1;
    156 
    157 	case LOOP_SET_FD:
    158 	case LOOP_CHANGE_FD:
    159 #ifdef LOOP_CTL_ADD
    160 	/* newer loop-control stuff */
    161 	case LOOP_CTL_ADD:
    162 	case LOOP_CTL_REMOVE:
    163 #endif
    164 		/* These take simple args, so let default printer handle it */
    165 
    166 	default:
    167 		return 0;
    168 	}
    169 }
    170