/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Creates and maintains a cache of mount points.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <synch.h>
#include <thread.h>
#include <unistd.h>
#include <fcntl.h>
#include "libdiskmgt.h"
#include "disks_private.h"
/*
*/
struct mntpnt_list {
char *special;
char *mountp;
};
static int initialized = 0;
struct mntpnt_list *secondp);
struct mntpnt_list *listp);
static int load_mnttab(int send_event);
static void watch_mnttab();
/*
* for the specified device.
*/
int
{
int found = 0;
*errp = 0;
return (found);
}
(void) mutex_lock(&init_lock);
if (!initialized) {
/* load the mntpnt cache */
if (*errp == 0) {
/* start a thread to monitor the mnttab */
}
if (*errp == 0) {
initialized = 1;
}
}
(void) mutex_unlock(&init_lock);
(void) rw_rdlock(&mntpoint_lock);
found = 1;
break;
}
}
(void) rw_unlock(&mntpoint_lock);
return (found);
}
/*
* Return true if the lists are different. Send an event for each different
* device.
*/
static boolean_t
struct mntpnt_list *secondp)
{
/* not in new list, so was mounted and now unmounted */
if (send_event) {
}
}
}
/* not in orig list, so this is a new mount */
if (send_event) {
}
}
}
return (different);
}
/*
* free_mnttab()
*
*/
static void
}
}
/*
* Return true if the element is in the list.
*/
static boolean_t
{
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* load_mnttab()
*
* return 1 if the list has changed, 0 if the list is still the same
*/
static int
{
int num;
int err;
int i;
/* get the mnttab entries */
/*
* Ignore entries that are incomplete or that are not
* devices (skips network mounts, automounter entries,
* /proc, etc.).
*/
continue;
}
(size_t)sizeof (struct mntpnt_list));
/*
* out of memory, free what we have and return
*/
return (ENOMEM);
}
} else {
}
/*
* out of memory, free what we have and return
*/
return (ENOMEM);
}
/*
* out of memory, free what we have and return
*/
return (ENOMEM);
}
}
}
/* get the swap entries */
if (num < 0) {
return (ENOMEM);
}
currp = (struct mntpnt_list *)
/* out of memory, free what we have and return */
return (ENOMEM);
}
} else {
}
} else {
sizeof (fullpath));
}
/* out of memory, free what we have and return */
return (ENOMEM);
}
/* out of memory, free what we have and return */
return (ENOMEM);
}
}
if (num)
/* note that we unlock the mutex in both paths of this if statement */
(void) rw_wrlock(&mntpoint_lock);
(void) rw_unlock(&mntpoint_lock);
/* free the old list */
} else {
(void) rw_unlock(&mntpoint_lock);
/* no change that we care about, so keep the current list */
}
return (0);
}
/*
* This is a thread that runs forever, watching for changes in the mnttab
* that would cause us to flush and reload the cache of mnt entries. Only
* changes to /dev devices will cause the cache to be flushed and reloaded.
*/
static void
{
int res;
/* do the initial read so we don't get the event right away */
if (res <= 0)
continue;
(void) load_mnttab(B_TRUE);
}
}
}