]>
Commit | Line | Data |
---|---|---|
4c0d8e50 FN |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
5 | * Common Development and Distribution License (the "License"). | |
6 | * You may not use this file except in compliance with the License. | |
7 | * | |
8 | * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
1d3ba0bf | 9 | * or https://opensource.org/licenses/CDDL-1.0. |
4c0d8e50 FN |
10 | * See the License for the specific language governing permissions |
11 | * and limitations under the License. | |
12 | * | |
13 | * When distributing Covered Code, include this CDDL HEADER in each | |
14 | * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 | * If applicable, add the following below this CDDL HEADER, with the | |
16 | * fields enclosed by brackets "[]" replaced with your own identifying | |
17 | * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 | * | |
19 | * CDDL HEADER END | |
20 | */ | |
21 | /* | |
22 | * Copyright (c) 2011, Fajar A. Nugraha. All rights reserved. | |
23 | * Use is subject to license terms. | |
24 | */ | |
25 | ||
5f91bd3d | 26 | #include <ctype.h> |
5a142533 | 27 | #include <errno.h> |
4c0d8e50 | 28 | #include <fcntl.h> |
5a142533 AZ |
29 | #include <stdio.h> |
30 | #include <string.h> | |
4c0d8e50 | 31 | #include <unistd.h> |
4c0d8e50 | 32 | #include <sys/fs/zfs.h> |
5a142533 AZ |
33 | #include <sys/ioctl.h> |
34 | #include <sys/stat.h> | |
4c0d8e50 | 35 | |
63652e15 DS |
36 | #if defined(ZFS_ASAN_ENABLED) |
37 | /* | |
38 | * zvol_id is invoked by udev with the help of ptrace() | |
39 | * making sanitized binary with leak detection croak | |
40 | * because of tracing mechanisms collision | |
41 | */ | |
42 | extern const char *__asan_default_options(void); | |
43 | ||
44 | const char *__asan_default_options(void) { | |
45 | return ("abort_on_error=true:halt_on_error=true:" | |
46 | "allocator_may_return_null=true:disable_coredump=false:" | |
47 | "detect_stack_use_after_return=true:detect_leaks=false"); | |
48 | } | |
49 | #endif | |
50 | ||
d1d7e268 | 51 | int |
5a142533 | 52 | main(int argc, const char *const *argv) |
4c0d8e50 | 53 | { |
5a142533 AZ |
54 | if (argc != 2) { |
55 | fprintf(stderr, "usage: %s /dev/zdX\n", argv[0]); | |
56 | return (1); | |
4c0d8e50 | 57 | } |
5a142533 AZ |
58 | const char *dev_name = argv[1]; |
59 | ||
60 | int fd; | |
61 | struct stat sb; | |
62 | if ((fd = open(dev_name, O_RDONLY|O_CLOEXEC)) == -1 || | |
63 | fstat(fd, &sb) != 0) { | |
64 | fprintf(stderr, "%s: %s\n", dev_name, strerror(errno)); | |
65 | return (1); | |
4c0d8e50 FN |
66 | } |
67 | ||
5a142533 AZ |
68 | char zvol_name[MAXNAMELEN + strlen("-part") + 10]; |
69 | if (ioctl(fd, BLKZNAME, zvol_name) == -1) { | |
70 | fprintf(stderr, "%s: BLKZNAME: %s\n", | |
71 | dev_name, strerror(errno)); | |
72 | return (1); | |
a5729f7b | 73 | } |
21a4f5cc | 74 | |
5a142533 AZ |
75 | unsigned int dev_part = minor(sb.st_rdev) % ZVOL_MINORS; |
76 | if (dev_part != 0) | |
77 | sprintf(zvol_name + strlen(zvol_name), "-part%u", dev_part); | |
5f91bd3d | 78 | |
5a142533 AZ |
79 | for (size_t i = 0; i < strlen(zvol_name); ++i) |
80 | if (isblank(zvol_name[i])) | |
81 | zvol_name[i] = '+'; | |
f24c7c35 | 82 | |
5a142533 | 83 | puts(zvol_name); |
f24c7c35 | 84 | |
5a142533 | 85 | return (0); |
4c0d8e50 | 86 | } |