fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/stat.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <strings.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdlib.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <unistd.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <stdio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <locale.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define __NSC_GEN__
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsc_gen.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsc_mem.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Private functions from libsd.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int nsc_nvclean(int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int nsc_gmem_data(char *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int nsc_gmem_sizes(int *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Local functions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_gmem(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void show_maps(char *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteusage(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("usage: nscadm [-h] command\n"));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("valid commands:\n"));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext(" freeze <device>\n"));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext(" unfreeze <device>\n"));
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext(" isfrozen <device>\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteis_chr_dev(char *dev, char *op)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct stat sbuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (stat(dev, &sbuf) < 0) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("nscadm: "));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(op);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!S_ISCHR(sbuf.st_mode)) {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("nscadm: %s: not a valid device "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "<%s>\n"), op, dev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemain(int argc, char *argv[])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte extern int optind, opterr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int opt, rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) setlocale(LC_ALL, "");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) textdomain("nscadm");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte opterr = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((opt = getopt(argc, argv, "h")) != -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (opt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case 'h':
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (optind == argc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcoll(argv[optind], gettext("freeze")) == 0 ||
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strcmp(argv[optind], "freeze") == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc - optind != 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte is_chr_dev(argv[optind+1], "freeze");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_isfrozen(argv[optind+1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(gettext("nscadm: freeze"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (rc != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_freeze(argv[optind+1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(gettext("nscadm: freeze"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr, gettext("nscadm: device <%s> is "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "already frozen\n"), argv[optind+1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) printf(gettext("nscadm: device <%s> frozen\n"),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki argv[optind+1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strcoll(argv[optind], gettext("unfreeze")) == 0 ||
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strcmp(argv[optind], "unfreeze") == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc - optind != 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte is_chr_dev(argv[optind+1], "unfreeze");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_isfrozen(argv[optind+1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(gettext("nscadm: unfreeze"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_unfreeze(argv[optind+1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(gettext("nscadm: unfreeze"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) fprintf(stderr,
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("nscadm: device <%s> is not "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "frozen\n"), argv[optind+1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) printf(gettext("nscadm: device <%s> unfrozen\n"),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki argv[optind+1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strcoll(argv[optind], gettext("isfrozen")) == 0 ||
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strcmp(argv[optind], "isfrozen") == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (argc - optind != 2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte is_chr_dev(argv[optind+1], "isfrozen");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_isfrozen(argv[optind+1]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(gettext("nscadm: isfrozen"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) printf(gettext("nscadm: device <%s> is %sfrozen\n"),
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki argv[optind+1], rc ? gettext("not ") : "");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strcoll(argv[optind], gettext("nvclean")) == 0 ||
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strcmp(argv[optind], "nvclean") == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_nvclean(0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(gettext("nscadm: nvclean"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strcoll(argv[optind], gettext("nvclean_force")) == 0 ||
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strcmp(argv[optind], "nvclean_force") == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_nvclean(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(gettext("nscadm: nvclean_force"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* DEBUG */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (strcoll(argv[optind], gettext("gmem")) == 0 ||
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki strcmp(argv[optind], "gmem") == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _nsc_gmem();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte perror(gettext("nscadm: gmem"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte usage();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte exit(255);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_gmem(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_gmem_sizes(&size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) printf(gettext("size %d\n"), size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((addr = (char *)malloc(size * 2)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte errno = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_gmem_data(addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) printf(gettext("Global map entries:\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte show_maps(addr, size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) printf(gettext("\nGlobal NVMEM map entries:\n"));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte show_maps(addr + size, size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free(addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteshow_maps(char *addr, int len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED alignment of cast ok */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_rmhdr_t *rhp = (nsc_rmhdr_t *)addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_rmmap_t *rmap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char tname[_NSC_MAXNAME + 1];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) printf(
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki gettext("magic 0x%x ver %d size %d dirty (nvmem systems): %d\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rhp->magic, rhp->ver, rhp->size, rhp->rh_dirty);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0, rmap = rhp->map;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED alignment of cast ok */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rmap < (nsc_rmmap_t *)(addr + len); ++i, ++rmap) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rmap->name[0])
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strncpy(tname, rmap->name, _NSC_MAXNAME);
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) strcpy(&tname[strlen(tname)], " ");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tname[_NSC_MAXNAME] = '\0';
570de38f63910201fdd77246630b7aa8f9dc5661Surya Prakki (void) printf(gettext(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "%d:\tname %s\toffset 0x%x size 0x%x inuse 0x%x\n"),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i, tname, rmap->offset, rmap->size, rmap->inuse);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}