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.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
22 * Copyright (c) 2011, Fajar A. Nugraha. All rights reserved.
23 * Use is subject to license terms.
32 #include <sys/fs/zfs.h>
33 #include <sys/ioctl.h>
36 #if defined(ZFS_ASAN_ENABLED)
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
42 extern const char *__asan_default_options(void);
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");
52 main(int argc
, const char *const *argv
)
54 if (argc
!= 2 || strncmp(argv
[1], "/dev/zd", 7) != 0) {
55 fprintf(stderr
, "usage: %s /dev/zdX\n", argv
[0]);
58 const char *dev_name
= argv
[1];
63 if ((fd
= open(dev_name
, O_RDONLY
|O_CLOEXEC
)) == -1 ||
64 fstat(fd
, &sb
) != 0) {
65 fprintf(stderr
, "%s: %s\n", dev_name
, strerror(errno
));
69 char zvol_name
[MAXNAMELEN
+ strlen("-part") + 10];
70 if (ioctl(fd
, BLKZNAME
, zvol_name
) == -1) {
71 fprintf(stderr
, "%s: BLKZNAME: %s\n",
72 dev_name
, strerror(errno
));
76 const char *dev_part
= strrchr(dev_name
, 'p');
77 len
= strlen(zvol_name
);
78 if (dev_part
!= NULL
) {
79 sprintf(zvol_name
+ len
, "-part%s", dev_part
+ 1);
80 len
= strlen(zvol_name
);
83 for (i
= 0; i
< len
; ++i
)
84 if (isblank(zvol_name
[i
]))