ng_mppc(4): Bring netgraph(3) MPPC compression support.
[freebsd-src.git] / usr.sbin / mfiutil / mfi_properties.c
blobb03d522c3b9b06f710759d92e70f0ed4c2865c83
1 /*-
2 * Copyright (c) 2013 Yahoo!, Inc.
3 * 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.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
27 * $FreeBSD$
30 #include <sys/errno.h>
31 #include <sys/ioctl.h>
32 #include <sys/param.h>
33 #include <sys/sysctl.h>
34 #include <sys/uio.h>
36 #include <err.h>
37 #include <fcntl.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <string.h>
41 #include <unistd.h>
43 #include "mfiutil.h"
44 #include <dev/mfi/mfi_ioctl.h>
46 MFI_TABLE(top, ctrlprop);
48 static int
49 mfi_ctrl_get_properties(int fd, struct mfi_ctrl_props *info)
52 return (mfi_dcmd_command(fd, MFI_DCMD_CTRL_GET_PROPS, info,
53 sizeof(struct mfi_ctrl_props), NULL, 0, NULL));
56 static int
57 mfi_ctrl_set_properties(int fd, struct mfi_ctrl_props *info)
60 return (mfi_dcmd_command(fd, MFI_DCMD_CTRL_SET_PROPS, info,
61 sizeof(struct mfi_ctrl_props), NULL, 0, NULL));
65 * aquite the controller properties data structure modify the
66 * rebuild rate if requested and then retun
68 static int
69 mfi_ctrl_rebuild_rate(int ac, char **av)
71 int error, fd;
72 struct mfi_ctrl_props ctrl_props;
74 if (ac > 2) {
75 warn("mfi_ctrl_set_rebuild_rate");
76 return(-1);
79 fd = mfi_open(mfi_unit, O_RDWR);
80 if (fd < 0) {
81 error = errno;
82 warn("mfi_open");
83 return (error);
86 error = mfi_ctrl_get_properties(fd, &ctrl_props);
87 if ( error < 0) {
88 error = errno;
89 warn("Failed to get controller properties");
90 close(fd);
91 return (error);
94 * User requested a change to the rebuild rate
96 if (ac > 1) {
97 ctrl_props.rebuild_rate = atoi(av[ac - 1]);
98 error = mfi_ctrl_set_properties(fd, &ctrl_props);
99 if ( error < 0) {
100 error = errno;
101 warn("Failed to set controller properties");
102 close(fd);
103 return (error);
106 error = mfi_ctrl_get_properties(fd, &ctrl_props);
107 if ( error < 0) {
108 error = errno;
109 warn("Failed to get controller properties");
110 close(fd);
111 return (error);
114 printf ("controller rebuild rate: %%%u \n",
115 ctrl_props.rebuild_rate);
116 return (0);
118 MFI_COMMAND(ctrlprop, rebuild, mfi_ctrl_rebuild_rate);
120 static int
121 mfi_ctrl_alarm_enable(int ac, char **av)
123 int error, fd;
124 struct mfi_ctrl_props ctrl_props;
126 if (ac > 2) {
127 warn("mfi_ctrl_alarm_enable");
128 return(-1);
131 fd = mfi_open(mfi_unit, O_RDWR);
132 if (fd < 0) {
133 error = errno;
134 warn("mfi_open");
135 return (error);
138 error = mfi_ctrl_get_properties(fd, &ctrl_props);
139 if ( error < 0) {
140 error = errno;
141 warn("Failed to get controller properties");
142 close(fd);
143 return (error);
145 printf ("controller alarm was : %s\n",
146 (ctrl_props.alarm_enable ? "enabled" : "disabled"));
148 if (ac > 1) {
149 ctrl_props.alarm_enable = atoi(av[ac - 1]);
150 error = mfi_ctrl_set_properties(fd, &ctrl_props);
151 if ( error < 0) {
152 error = errno;
153 warn("Failed to set controller properties");
154 close(fd);
155 return (error);
158 error = mfi_ctrl_get_properties(fd, &ctrl_props);
159 if ( error < 0) {
160 error = errno;
161 warn("Failed to get controller properties");
162 close(fd);
163 return (error);
166 printf ("controller alarm was : %s\n",
167 (ctrl_props.alarm_enable ? "enabled" : "disabled"));
168 return (0);
171 MFI_COMMAND(ctrlprop, alarm, mfi_ctrl_alarm_enable);