2 * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 #include "xlat/name_to_handle_at_flags.h"
33 # define MAX_HANDLE_SZ 128
37 unsigned int handle_bytes;
41 SYS_FUNC(name_to_handle_at)
44 const kernel_ulong_t addr = tcp->u_arg[2];
48 print_dirfd(tcp, tcp->u_arg[0]);
51 printpath(tcp, tcp->u_arg[1]);
55 if (umove_or_printaddr(tcp, addr, &h)) {
59 printaddr(tcp->u_arg[3]);
63 printflags(name_to_handle_at_flags, tcp->u_arg[4],
68 tprintf("{handle_bytes=%u", h.handle_bytes);
70 set_tcb_priv_ulong(tcp, h.handle_bytes);
74 unsigned int i = get_tcb_priv_ulong(tcp);
76 if ((!syserror(tcp) || EOVERFLOW == tcp->u_error)
77 && !umove(tcp, addr, &h)) {
78 unsigned char f_handle[MAX_HANDLE_SZ];
80 if (i != h.handle_bytes)
81 tprintf(" => %u", h.handle_bytes);
83 tprintf(", handle_type=%d", h.handle_type);
84 if (h.handle_bytes > MAX_HANDLE_SZ)
85 h.handle_bytes = MAX_HANDLE_SZ;
86 if (!umoven(tcp, addr + sizeof(h), h.handle_bytes,
88 tprints(", f_handle=0x");
89 for (i = 0; i < h.handle_bytes; ++i)
90 tprintf("%02x", f_handle[i]);
97 printnum_int(tcp, tcp->u_arg[3], "%d");
101 printflags(name_to_handle_at_flags, tcp->u_arg[4], "AT_???");
106 SYS_FUNC(open_by_handle_at)
108 file_handle_header h;
109 const kernel_ulong_t addr = tcp->u_arg[1];
112 printfd(tcp, tcp->u_arg[0]);
116 if (!umove_or_printaddr(tcp, addr, &h)) {
117 unsigned char f_handle[MAX_HANDLE_SZ];
119 tprintf("{handle_bytes=%u, handle_type=%d",
120 h.handle_bytes, h.handle_type);
121 if (h.handle_bytes > MAX_HANDLE_SZ)
122 h.handle_bytes = MAX_HANDLE_SZ;
123 if (!umoven(tcp, addr + sizeof(h), h.handle_bytes, &f_handle)) {
126 tprints(", f_handle=0x");
127 for (i = 0; i < h.handle_bytes; ++i)
128 tprintf("%02x", f_handle[i]);
135 tprint_open_modes(tcp->u_arg[2]);