blob: 21cf0f1811f1b9e7fcf42b3ee160a76dbcd92e6f [file] [log] [blame]
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +00001/*
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#ifndef MAX_HANDLE_SZ
31# define MAX_HANDLE_SZ 128
32#endif
33
34typedef struct {
35 unsigned int handle_bytes;
36 int handle_type;
37} file_handle_header;
38
39SYS_FUNC(name_to_handle_at)
40{
41 file_handle_header h;
42 const long addr = tcp->u_arg[2];
43
44 if (entering(tcp)) {
45 /* dirfd */
46 print_dirfd(tcp, tcp->u_arg[0]);
47
48 /* pathname */
49 printpath(tcp, tcp->u_arg[1]);
50 tprints(", ");
51
52 /* handle */
53 if (umove_or_printaddr(tcp, addr, &h)) {
54 tprints(", ");
55
56 /* mount_id */
57 printaddr(tcp->u_arg[3]);
58 tprints(", ");
59
60 /* flags */
61 printflags(at_flags, tcp->u_arg[4], "AT_???");
62
63 return RVAL_DECODED;
64 }
65 tprintf("{handle_bytes=%u", h.handle_bytes);
66
Dmitry V. Levinb759d272016-07-15 16:08:19 +000067 set_tcb_priv_ulong(tcp, h.handle_bytes);
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000068
69 return 0;
70 } else {
Dmitry V. Levinb759d272016-07-15 16:08:19 +000071 unsigned int i = get_tcb_priv_ulong(tcp);
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000072
73 if ((!syserror(tcp) || EOVERFLOW == tcp->u_error)
74 && !umove(tcp, addr, &h)) {
75 unsigned char f_handle[MAX_HANDLE_SZ];
76
77 if (i != h.handle_bytes)
78 tprintf(" => %u", h.handle_bytes);
79 if (!syserror(tcp)) {
80 tprintf(", handle_type=%d", h.handle_type);
81 if (h.handle_bytes > MAX_HANDLE_SZ)
82 h.handle_bytes = MAX_HANDLE_SZ;
83 if (!umoven(tcp, addr + sizeof(h), h.handle_bytes,
84 f_handle)) {
85 tprints(", f_handle=0x");
86 for (i = 0; i < h.handle_bytes; ++i)
87 tprintf("%02x", f_handle[i]);
88 }
89 }
90 }
91 tprints("}, ");
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000092
93 /* mount_id */
94 printnum_int(tcp, tcp->u_arg[3], "%d");
95 tprints(", ");
96
97 /* flags */
98 printflags(at_flags, tcp->u_arg[4], "AT_???");
99 }
100 return 0;
101}
102
103SYS_FUNC(open_by_handle_at)
104{
105 file_handle_header h;
106 const long addr = tcp->u_arg[1];
107
108 /* mount_fd */
109 printfd(tcp, tcp->u_arg[0]);
110 tprints(", ");
111
112 /* handle */
113 if (!umove_or_printaddr(tcp, addr, &h)) {
114 unsigned char f_handle[MAX_HANDLE_SZ];
115
116 tprintf("{handle_bytes=%u, handle_type=%d",
117 h.handle_bytes, h.handle_type);
118 if (h.handle_bytes > MAX_HANDLE_SZ)
119 h.handle_bytes = MAX_HANDLE_SZ;
120 if (!umoven(tcp, addr + sizeof(h), h.handle_bytes, &f_handle)) {
121 unsigned int i;
122
123 tprints(", f_handle=0x");
124 for (i = 0; i < h.handle_bytes; ++i)
125 tprintf("%02x", f_handle[i]);
126 }
127 tprints("}");
128 }
129 tprints(", ");
130
131 /* flags */
132 tprint_open_modes(tcp->u_arg[2]);
133
134 return RVAL_DECODED;
135}