LCOV - code coverage report
Current view: top level - strace_git - file_handle.c (source / functions) Hit Total Coverage
Test: strace-4.16.0.69.f1ea-dirty Code Coverage Lines: 48 49 98.0 %
Date: 2017-03-18 00:38:52 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 28 89.3 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
       3                 :            :  * All rights reserved.
       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 "xlat/name_to_handle_at_flags.h"
      31                 :            : 
      32                 :            : #ifndef MAX_HANDLE_SZ
      33                 :            : # define MAX_HANDLE_SZ 128
      34                 :            : #endif
      35                 :            : 
      36                 :            : typedef struct {
      37                 :            :         unsigned int handle_bytes;
      38                 :            :         int handle_type;
      39                 :            : } file_handle_header;
      40                 :            : 
      41                 :       5220 : SYS_FUNC(name_to_handle_at)
      42                 :            : {
      43                 :            :         file_handle_header h;
      44                 :       5220 :         const kernel_ulong_t addr = tcp->u_arg[2];
      45                 :            : 
      46         [ +  + ]:       5220 :         if (entering(tcp)) {
      47                 :            :                 /* dirfd */
      48                 :       2898 :                 print_dirfd(tcp, tcp->u_arg[0]);
      49                 :            : 
      50                 :            :                 /* pathname */
      51                 :       2898 :                 printpath(tcp, tcp->u_arg[1]);
      52                 :       2898 :                 tprints(", ");
      53                 :            : 
      54                 :            :                 /* handle */
      55         [ +  + ]:       2898 :                 if (umove_or_printaddr(tcp, addr, &h)) {
      56                 :        576 :                         tprints(", ");
      57                 :            : 
      58                 :            :                         /* mount_id */
      59                 :        576 :                         printaddr(tcp->u_arg[3]);
      60                 :        576 :                         tprints(", ");
      61                 :            : 
      62                 :            :                         /* flags */
      63                 :        576 :                         printflags(name_to_handle_at_flags, tcp->u_arg[4],
      64                 :            :                                    "AT_???");
      65                 :            : 
      66                 :        576 :                         return RVAL_DECODED;
      67                 :            :                 }
      68                 :       2322 :                 tprintf("{handle_bytes=%u", h.handle_bytes);
      69                 :            : 
      70                 :       2322 :                 set_tcb_priv_ulong(tcp, h.handle_bytes);
      71                 :            : 
      72                 :       2322 :                 return 0;
      73                 :            :         } else {
      74                 :       2322 :                 unsigned int i = get_tcb_priv_ulong(tcp);
      75                 :            : 
      76 [ +  + ][ +  + ]:       2322 :                 if ((!syserror(tcp) || EOVERFLOW == tcp->u_error)
      77         [ +  - ]:         12 :                     && !umove(tcp, addr, &h)) {
      78                 :            :                         unsigned char f_handle[MAX_HANDLE_SZ];
      79                 :            : 
      80         [ +  + ]:         12 :                         if (i != h.handle_bytes)
      81                 :          6 :                                 tprintf(" => %u", h.handle_bytes);
      82         [ +  + ]:         12 :                         if (!syserror(tcp)) {
      83                 :          6 :                                 tprintf(", handle_type=%d", h.handle_type);
      84         [ -  + ]:          6 :                                 if (h.handle_bytes > MAX_HANDLE_SZ)
      85                 :          0 :                                         h.handle_bytes = MAX_HANDLE_SZ;
      86         [ +  - ]:          6 :                                 if (!umoven(tcp, addr + sizeof(h), h.handle_bytes,
      87                 :            :                                             f_handle)) {
      88                 :          6 :                                         tprints(", f_handle=0x");
      89         [ +  + ]:         60 :                                         for (i = 0; i < h.handle_bytes; ++i)
      90                 :         48 :                                                 tprintf("%02x", f_handle[i]);
      91                 :            :                                 }
      92                 :            :                         }
      93                 :            :                 }
      94                 :       2322 :                 tprints("}, ");
      95                 :            : 
      96                 :            :                 /* mount_id */
      97                 :       2322 :                 printnum_int(tcp, tcp->u_arg[3], "%d");
      98                 :       2322 :                 tprints(", ");
      99                 :            : 
     100                 :            :                 /* flags */
     101                 :       2322 :                 printflags(name_to_handle_at_flags, tcp->u_arg[4], "AT_???");
     102                 :            :         }
     103                 :       5220 :         return 0;
     104                 :            : }
     105                 :            : 
     106                 :        174 : SYS_FUNC(open_by_handle_at)
     107                 :            : {
     108                 :            :         file_handle_header h;
     109                 :        174 :         const kernel_ulong_t addr = tcp->u_arg[1];
     110                 :            : 
     111                 :            :         /* mount_fd */
     112                 :        174 :         printfd(tcp, tcp->u_arg[0]);
     113                 :        174 :         tprints(", ");
     114                 :            : 
     115                 :            :         /* handle */
     116         [ +  + ]:        174 :         if (!umove_or_printaddr(tcp, addr, &h)) {
     117                 :            :                 unsigned char f_handle[MAX_HANDLE_SZ];
     118                 :            : 
     119                 :        102 :                 tprintf("{handle_bytes=%u, handle_type=%d",
     120                 :            :                         h.handle_bytes, h.handle_type);
     121         [ +  + ]:        102 :                 if (h.handle_bytes > MAX_HANDLE_SZ)
     122                 :         48 :                         h.handle_bytes = MAX_HANDLE_SZ;
     123         [ +  + ]:        102 :                 if (!umoven(tcp, addr + sizeof(h), h.handle_bytes, &f_handle)) {
     124                 :            :                         unsigned int i;
     125                 :            : 
     126                 :         78 :                         tprints(", f_handle=0x");
     127         [ +  + ]:       6270 :                         for (i = 0; i < h.handle_bytes; ++i)
     128                 :       6192 :                                 tprintf("%02x", f_handle[i]);
     129                 :            :                 }
     130                 :        102 :                 tprints("}");
     131                 :            :         }
     132                 :        174 :         tprints(", ");
     133                 :            : 
     134                 :            :         /* flags */
     135                 :        174 :         tprint_open_modes(tcp->u_arg[2]);
     136                 :            : 
     137                 :        174 :         return RVAL_DECODED;
     138                 :            : }

Generated by: LCOV version 1.12