blob: dba48be9d26d1e278f36de4b4552e1309b647daa [file] [log] [blame]
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +00001/*
Dmitry V. Levinc83746a2016-01-06 16:01:46 +00002 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +00003 * 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
Dmitry V. Levin0c8853c2016-01-02 13:28:43 +000028#include "tests.h"
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000029#include <fcntl.h>
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000030
31#ifdef MAX_HANDLE_SZ
32
Dmitry V. Levinc83746a2016-01-06 16:01:46 +000033# include <alloca.h>
34# include <assert.h>
35# include <errno.h>
36# include <stdio.h>
37
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000038int
39main(void)
40{
41 struct file_handle *handle =
42 alloca(sizeof(struct file_handle) + MAX_HANDLE_SZ);
43 const int dirfd = AT_FDCWD;
44 const int flags = AT_SYMLINK_FOLLOW;
45 int mount_id;
46 unsigned int i;
47
48 handle->handle_bytes = 0;
49
Dmitry V. Levinc83746a2016-01-06 16:01:46 +000050 assert(name_to_handle_at(dirfd, ".", handle, &mount_id, flags | 1) == -1);
51 if (EINVAL != errno)
52 perror_msg_and_skip("name_to_handle_at");
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000053 printf("name_to_handle_at(AT_FDCWD, \".\", {handle_bytes=0}, %p"
Dmitry V. Levinc83746a2016-01-06 16:01:46 +000054 ", AT_SYMLINK_FOLLOW|0x1) = -1 EINVAL (%m)\n", &mount_id);
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000055
Dmitry V. Levinc83746a2016-01-06 16:01:46 +000056 assert(name_to_handle_at(dirfd, ".", handle, &mount_id, flags) == -1);
57 if (EOVERFLOW != errno)
58 perror_msg_and_skip("name_to_handle_at");
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000059 printf("name_to_handle_at(AT_FDCWD, \".\", {handle_bytes=0 => %u}"
Dmitry V. Levinc83746a2016-01-06 16:01:46 +000060 ", %p, AT_SYMLINK_FOLLOW) = -1 EOVERFLOW (%m)\n",
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000061 handle->handle_bytes, &mount_id);
62
Dmitry V. Levinc83746a2016-01-06 16:01:46 +000063 assert(name_to_handle_at(dirfd, ".", handle, &mount_id, flags) == 0);
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000064 printf("name_to_handle_at(AT_FDCWD, \".\", {handle_bytes=%u"
65 ", handle_type=%d, f_handle=0x",
66 handle->handle_bytes, handle->handle_type);
67 for (i = 0; i < handle->handle_bytes; ++i)
68 printf("%02x", handle->f_handle[i]);
69 printf("}, [%d], AT_SYMLINK_FOLLOW) = 0\n", mount_id);
70
Dmitry V. Levin4c65ff02015-11-26 16:48:23 +000071 printf("open_by_handle_at(-1, {handle_bytes=%u, handle_type=%d"
72 ", f_handle=0x", handle->handle_bytes, handle->handle_type);
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000073 for (i = 0; i < handle->handle_bytes; ++i)
74 printf("%02x", handle->f_handle[i]);
Dmitry V. Levinc83746a2016-01-06 16:01:46 +000075 printf("}, O_RDONLY|O_DIRECTORY) = -1 ");
76 assert(open_by_handle_at(-1, handle, O_RDONLY | O_DIRECTORY) == -1);
77 const char *errno_text;
78 switch (errno) {
79 case EPERM:
80 errno_text = "EPERM";
81 break;
82 case EINVAL:
83 errno_text = "EINVAL";
84 break;
85 default:
86 errno_text = "EBADF";
87 }
88 printf("%s (%m)\n", errno_text);
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000089
90 puts("+++ exited with 0 +++");
91 return 0;
92}
93
94#else
95
Dmitry V. Levinc83746a2016-01-06 16:01:46 +000096SKIP_MAIN_UNDEFINED("MAX_HANDLE_SZ")
Dmitry V. Levin4b3a1702015-11-22 21:29:32 +000097
98#endif