handlelocalfs.c revision 2
2N/A/*
2N/A *
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A *
2N/A */
2N/A
2N/A/*
2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A *
2N/A*/
2N/A
2N/A
2N/A#include <stdlib.h>
2N/A#include <unistd.h>
2N/A#include <strings.h>
2N/A#include <libscf.h>
2N/A
2N/A#define MAX_TRY 15
2N/Astatic boolean_t fs_temporarily_enabled = B_FALSE;
2N/Achar svm_core_svcs[] = "system/filesystem/local:default";
2N/A
2N/A/*
2N/A * Name: enable_local_fs
2N/A * Description: If the SMF service system/filesystem/local:default is not
2N/A * enabled, then this function enables the service, so that,
2N/A * all the local filesystems are mounted.
2N/A * Arguments: None
2N/A * Returns: B_TRUE on success; B_FALSE on error.
2N/A */
2N/Aboolean_t
2N/Aenable_local_fs(void)
2N/A{
2N/A char *cur_smf_state;
2N/A int i;
2N/A boolean_t fs_enabled_here = B_FALSE;
2N/A
2N/A if (fs_temporarily_enabled) {
2N/A return (B_TRUE);
2N/A }
2N/A
2N/A if ((cur_smf_state = smf_get_state(svm_core_svcs)) != NULL) {
2N/A if (strcmp(cur_smf_state, SCF_STATE_STRING_DISABLED) == 0) {
2N/A if (smf_enable_instance(svm_core_svcs, SMF_TEMPORARY)
2N/A != 0) {
2N/A free(cur_smf_state);
2N/A return (B_FALSE);
2N/A }
2N/A
2N/A fs_enabled_here = B_TRUE;
2N/A
2N/A } else if (strcmp(cur_smf_state, SCF_STATE_STRING_ONLINE)
2N/A == 0) {
2N/A free(cur_smf_state);
2N/A return (B_TRUE);
2N/A } else if (strcmp(cur_smf_state, SCF_STATE_STRING_OFFLINE)
2N/A != 0) {
2N/A free(cur_smf_state);
2N/A return (B_FALSE);
2N/A }
2N/A
2N/A free(cur_smf_state);
2N/A
2N/A } else {
2N/A return (B_FALSE);
2N/A }
2N/A
2N/A for (i = 0; i < MAX_TRY; i++) {
2N/A if ((cur_smf_state = smf_get_state(svm_core_svcs)) != NULL) {
2N/A if (strcmp(cur_smf_state, SCF_STATE_STRING_ONLINE)
2N/A == 0) {
2N/A free(cur_smf_state);
2N/A if (fs_enabled_here) {
2N/A fs_temporarily_enabled = B_TRUE;
2N/A }
2N/A return (B_TRUE);
2N/A } else if ((strcmp(cur_smf_state,
2N/A SCF_STATE_STRING_OFFLINE) == 0) ||
2N/A (strcmp(cur_smf_state, SCF_STATE_STRING_DISABLED) == 0)) {
2N/A (void) sleep(1);
2N/A free(cur_smf_state);
2N/A } else {
2N/A free(cur_smf_state);
2N/A return (B_FALSE);
2N/A }
2N/A } else {
2N/A return (B_FALSE);
2N/A }
2N/A }
2N/A
2N/A return (B_FALSE);
2N/A}
2N/A
2N/A/*
2N/A * Name: restore_local_fs
2N/A * Description: If the SMF service system/filesystem/local:default was
2N/A * enabled using enable_local_fs(), then this function disables
2N/A * the service.
2N/A * Arguments: None
2N/A * Returns: B_TRUE on success; B_FALSE on error.
2N/A */
2N/Aboolean_t
2N/Arestore_local_fs(void)
2N/A{
2N/A int i;
2N/A char *cur_smf_state;
2N/A
2N/A if (!fs_temporarily_enabled) {
2N/A return (B_TRUE);
2N/A }
2N/A
2N/A if (smf_disable_instance(svm_core_svcs, SMF_TEMPORARY) != 0) {
2N/A return (B_FALSE);
2N/A }
2N/A
2N/A for (i = 0; i < MAX_TRY; i++) {
2N/A if ((cur_smf_state = smf_get_state(svm_core_svcs)) != NULL) {
2N/A if (strcmp(cur_smf_state, SCF_STATE_STRING_DISABLED)
2N/A == 0) {
2N/A fs_temporarily_enabled = B_FALSE;
2N/A free(cur_smf_state);
2N/A break;
2N/A }
2N/A (void) sleep(1);
2N/A
2N/A free(cur_smf_state);
2N/A } else {
2N/A return (B_FALSE);
2N/A }
2N/A }
2N/A
2N/A return (!fs_temporarily_enabled);
2N/A}