]>
git.proxmox.com Git - mirror_zfs.git/blob - cmd/zvol_id/zvol_id_main.c
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 http://www.opensolaris.org/os/licensing.
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 <linux/ioctl.h>
34 #include <sys/ioctl.h>
35 #include <sys/zfs_znode.h>
36 #include <sys/fs/zfs.h>
39 ioctl_get_msg(char *var
, int fd
)
42 char msg
[ZFS_MAX_DATASET_NAME_LEN
];
44 error
= ioctl(fd
, BLKZNAME
, msg
);
49 snprintf(var
, ZFS_MAX_DATASET_NAME_LEN
, "%s", msg
);
54 main(int argc
, char **argv
)
57 char zvol_name
[ZFS_MAX_DATASET_NAME_LEN
];
58 char zvol_name_part
[ZFS_MAX_DATASET_NAME_LEN
];
60 struct stat64 statbuf
;
61 int dev_minor
, dev_part
;
65 printf("Usage: %s /dev/zvol_device_node\n", argv
[0]);
70 error
= stat64(dev_name
, &statbuf
);
72 printf("Unable to access device file: %s\n", dev_name
);
76 dev_minor
= minor(statbuf
.st_rdev
);
77 dev_part
= dev_minor
% ZVOL_MINORS
;
79 fd
= open(dev_name
, O_RDONLY
);
81 printf("Unable to open device file: %s\n", dev_name
);
85 error
= ioctl_get_msg(zvol_name
, fd
);
87 printf("ioctl_get_msg failed:%s\n", strerror(errno
));
91 snprintf(zvol_name_part
, ZFS_MAX_DATASET_NAME_LEN
,
92 "%s-part%d", zvol_name
, dev_part
);
94 snprintf(zvol_name_part
, ZFS_MAX_DATASET_NAME_LEN
,
97 for (i
= 0; i
< strlen(zvol_name_part
); i
++) {
98 if (isblank(zvol_name_part
[i
]))
99 zvol_name_part
[i
] = '+';
102 printf("%s\n", zvol_name_part
);