4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * This program provides a command line interface to the
31 * three new ioctls for the emul64 driver - EMUL64_WRITE_OFF,
32 * EMUL64_WRITE_ON and EMUL64_ZERO_RANGE. All three of these
33 * ioctls require the range of blocks to be specified. The
34 * range is specified by starting block number and block count
35 * both of which are 64 bit.
37 * Returns 0 on success, >0 on failure.
47 #include <sys/types.h>
48 #include <sys/emul64.h>
51 #define ADMIN_DIR "/dev/cfg/"
55 static int get_disk_addr(char *path
, emul64_tgt_range_t
*tr
, char **admin
);
60 (void) fprintf(stderr
, "Usage: emul64ioctl -s start_block "
61 "-b block_count -c write_off | write_on | zero emul64_dev\n");
66 main(int argc
, char **argv
)
77 emul64_tgt_range_t tr
;
79 Pname
= strrchr(argv
[0], '/');
85 while ((retval
= getopt(argc
, argv
, "s:b:c:")) != -1) {
89 tr
.emul64_blkrange
.emul64_sb
= atoll(optarg
);
93 tr
.emul64_blkrange
.emul64_blkcnt
= atoll(optarg
);
96 if (strncmp(optarg
, "write_off",
97 strlen("write_off")) == 0) {
98 cmd
= EMUL64_WRITE_OFF
;
99 } else if (strncmp(optarg
, "write_on",
100 strlen("write_on")) == 0) {
101 cmd
= EMUL64_WRITE_ON
;
102 } else if (strncmp(optarg
, "zero",
103 strlen("zero")) == 0) {
104 cmd
= EMUL64_ZERO_RANGE
;
114 if (do_usage
|| (optind
!= argc
- 1)) {
117 if ((sb_seen
== 0) || (count_seen
== 0) || (cmd
== -1))
120 slice
= argv
[optind
];
123 * Get admin device, target and lun
125 if (get_disk_addr(slice
, &tr
, &admin
) != 0)
129 * open the specified emul64_dev.
131 if ((fd
= open(admin
, O_RDONLY
, 0444)) != -1) {
133 retval
= ioctl(fd
, cmd
, &tr
);
140 (void) printf("emul64ioctl: %s: ioctl %s\n",
141 admin
, strerror(errno
));
143 (void) printf("emul64ioctl: %s: open %s\n",
144 admin
, strerror(errno
));
150 #define TOK_CHECK(s) if (token == NULL) {\
156 get_disk_addr(char *path
, emul64_tgt_range_t
*tr
, char **admin
)
164 ctds
= strrchr(path
, '/');
169 conversions
= sscanf(ctds
, "c%dt%hud%hu", &ctlr_num
,
170 &tr
->emul64_target
, &tr
->emul64_lun
);
171 if (conversions
!= 3) {
172 (void) fprintf(stderr
, "%s: \"%s\" is invalid disk name. "
173 "%d conversions\n", Pname
, ctds
, conversions
);
177 /* Build controller name */
178 admin_size
= strlen(ADMIN_DIR
) +
179 10 + /* enough digits for an int */
181 1; /* Null terminator */
182 *admin
= malloc(admin_size
);
183 if (*admin
== NULL
) {
184 (void) fprintf(stderr
, "%s: out of memory\n", Pname
);
187 (void) snprintf(*admin
, admin_size
, "%sc%d", ADMIN_DIR
, ctlr_num
);