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]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <sys/types.h>
38 #include <sys/nsctl/nsc_gen.h>
39 #include <sys/nsctl/nsc_mem.h>
43 * Private functions from libsd.
45 extern int nsc_nvclean(int);
46 extern int nsc_gmem_data(char *);
47 extern int nsc_gmem_sizes(int *);
52 static int _nsc_gmem(void);
53 static void show_maps(char *, int);
59 (void) fprintf(stderr
, gettext("usage: nscadm [-h] command\n"));
60 (void) fprintf(stderr
, gettext("valid commands:\n"));
61 (void) fprintf(stderr
, gettext(" freeze <device>\n"));
62 (void) fprintf(stderr
, gettext(" unfreeze <device>\n"));
63 (void) fprintf(stderr
, gettext(" isfrozen <device>\n"));
67 is_chr_dev(char *dev
, char *op
)
70 if (stat(dev
, &sbuf
) < 0) {
71 (void) fprintf(stderr
, gettext("nscadm: "));
75 if (!S_ISCHR(sbuf
.st_mode
)) {
76 (void) fprintf(stderr
, gettext("nscadm: %s: not a valid device "
83 main(int argc
, char *argv
[])
85 extern int optind
, opterr
;
88 (void) setlocale(LC_ALL
, "");
89 (void) textdomain("nscadm");
94 while ((opt
= getopt(argc
, argv
, "h")) != -1) {
107 if (optind
== argc
) {
112 if (strcoll(argv
[optind
], gettext("freeze")) == 0 ||
113 strcmp(argv
[optind
], "freeze") == 0) {
114 if (argc
- optind
!= 2) {
119 is_chr_dev(argv
[optind
+1], "freeze");
120 rc
= nsc_isfrozen(argv
[optind
+1]);
122 perror(gettext("nscadm: freeze"));
124 } else if (rc
!= 0) {
125 rc
= nsc_freeze(argv
[optind
+1]);
127 perror(gettext("nscadm: freeze"));
131 (void) fprintf(stderr
, gettext("nscadm: device <%s> is "
132 "already frozen\n"), argv
[optind
+1]);
136 (void) printf(gettext("nscadm: device <%s> frozen\n"),
138 } else if (strcoll(argv
[optind
], gettext("unfreeze")) == 0 ||
139 strcmp(argv
[optind
], "unfreeze") == 0) {
140 if (argc
- optind
!= 2) {
145 is_chr_dev(argv
[optind
+1], "unfreeze");
146 rc
= nsc_isfrozen(argv
[optind
+1]);
148 perror(gettext("nscadm: unfreeze"));
150 } else if (rc
== 0) {
151 rc
= nsc_unfreeze(argv
[optind
+1]);
153 perror(gettext("nscadm: unfreeze"));
157 (void) fprintf(stderr
,
158 gettext("nscadm: device <%s> is not "
159 "frozen\n"), argv
[optind
+1]);
163 (void) printf(gettext("nscadm: device <%s> unfrozen\n"),
165 } else if (strcoll(argv
[optind
], gettext("isfrozen")) == 0 ||
166 strcmp(argv
[optind
], "isfrozen") == 0) {
167 if (argc
- optind
!= 2) {
172 is_chr_dev(argv
[optind
+1], "isfrozen");
173 rc
= nsc_isfrozen(argv
[optind
+1]);
175 perror(gettext("nscadm: isfrozen"));
179 (void) printf(gettext("nscadm: device <%s> is %sfrozen\n"),
180 argv
[optind
+1], rc
? gettext("not ") : "");
182 } else if (strcoll(argv
[optind
], gettext("nvclean")) == 0 ||
183 strcmp(argv
[optind
], "nvclean") == 0) {
186 perror(gettext("nscadm: nvclean"));
189 } else if (strcoll(argv
[optind
], gettext("nvclean_force")) == 0 ||
190 strcmp(argv
[optind
], "nvclean_force") == 0) {
193 perror(gettext("nscadm: nvclean_force"));
197 } else if (strcoll(argv
[optind
], gettext("gmem")) == 0 ||
198 strcmp(argv
[optind
], "gmem") == 0) {
201 perror(gettext("nscadm: gmem"));
220 rc
= nsc_gmem_sizes(&size
);
225 (void) printf(gettext("size %d\n"), size
);
227 if ((addr
= (char *)malloc(size
* 2)) == NULL
) {
232 rc
= nsc_gmem_data(addr
);
239 (void) printf(gettext("Global map entries:\n"));
240 show_maps(addr
, size
);
242 (void) printf(gettext("\nGlobal NVMEM map entries:\n"));
243 show_maps(addr
+ size
, size
);
251 show_maps(char *addr
, int len
)
253 /* LINTED alignment of cast ok */
254 nsc_rmhdr_t
*rhp
= (nsc_rmhdr_t
*)addr
;
256 char tname
[_NSC_MAXNAME
+ 1];
260 gettext("magic 0x%x ver %d size %d dirty (nvmem systems): %d\n"),
261 rhp
->magic
, rhp
->ver
, rhp
->size
, rhp
->rh_dirty
);
263 for (i
= 0, rmap
= rhp
->map
;
264 /* LINTED alignment of cast ok */
265 rmap
< (nsc_rmmap_t
*)(addr
+ len
); ++i
, ++rmap
) {
268 (void) strncpy(tname
, rmap
->name
, _NSC_MAXNAME
);
269 (void) strcpy(&tname
[strlen(tname
)], " ");
270 tname
[_NSC_MAXNAME
] = '\0';
271 (void) printf(gettext(
272 "%d:\tname %s\toffset 0x%x size 0x%x inuse 0x%x\n"),
273 i
, tname
, rmap
->offset
, rmap
->size
, rmap
->inuse
);