LCOV - code coverage report
Current view: top level - strace - loop.c (source / functions) Hit Total Coverage
Test: strace-4.18.0.129.97bbb Code Coverage Lines: 74 74 100.0 %
Date: 2017-07-31 03:46:08 Functions: 4 5 80.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 41 41 100.0 %

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

Generated by: LCOV version 1.11