/***************************************************************************
*
* addon-storage.c : watch removable media state changes
*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Licensed under the Academic Free License version 2.1
*
**************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <priv.h>
#include <libsysevent.h>
#include <libhal.h>
static char *udi;
static char *devfs_path;
static void sysevent_dev_handler(sysevent_t *);
static void
{
if (dbus_error_is_set(error)) {
}
}
static void
{
return;
}
subcl[0] = ESC_DEV_EJECT_REQUEST;
return;
}
}
static void
{
}
}
static void
{
char *class;
char *subclass;
char *p;
int len;
return;
return;
return;
return;
goto out;
}
/* see if event belongs to our LUN (ignore slice and "/devices" ) */
else
goto out;
goto out;
/* we got it, tell the world */
dbus_error_init (&error);
dbus_error_free (&error);
out:
}
static void
{
unsigned int num_options = 0;
char *device_file;
dbus_error_init (&error);
"org.freedesktop.Hal.Device.Volume",
"Unmount");
goto out;
}
HAL_DEBUG (("Could not allocate options array"));
goto out;
}
if (device_file != NULL) {
}
dbus_error_free (&error);
if (!dbus_message_append_args (msg,
goto out;
}
goto out;
}
if (dbus_error_is_set (&error)) {
goto out;
}
out:
dbus_error_free (&error);
}
static void
{
int num_volumes;
char **volumes;
dbus_error_init (&error);
/* need to force unmount all partitions */
dbus_error_free (&error);
int i;
for (i = 0; i < num_volumes; i++) {
char *vol_udi;
dbus_error_free (&error);
dbus_error_free (&error);
}
}
}
}
}
/** Check if a filesystem on a special device file is mounted
*
* @return TRUE iff there is a filesystem system mounted
* on the special device file
*/
static dbus_bool_t
{
FILE *f;
return rc;
}
fclose (f);
return rc;
}
void
{
if (*fd > 0) {
*fd = -1;
}
}
void
{
/*
* Start with the 'basic' privilege set and then remove any
* of the 'basic' privileges that will not be needed.
*/
return;
}
/* Clear privileges we will not need from the 'basic' set */
/* to open logindevperm'd devices */
/* to receive sysevents */
/* Set the permitted privilege set. */
return;
}
/* Clear the limit set. */
return;
}
return;
}
}
int
{
char *bus;
char *drive_type;
char *support_media_changed_str;
goto out;
goto out;
goto out;
goto out;
goto out;
goto out;
drop_privileges ();
setup_logger ();
sysevent_init ();
else
dbus_error_init (&error);
goto out;
}
goto out;
}
printf ("Doing addon-storage for %s (bus %s) (drive_type %s) (udi %s)\n", device_file, bus, drive_type, udi);
/* Linux version of this addon attempts to re-open the device O_EXCL
* every 2 seconds, trying to figure out if some other app,
* like a cd burner, is using the device. Aside from questionable
* keeps media constantly spun up. All this needs more thought.
*/
for (;;) {
if (is_mounted (device_file)) {
close_device (&fd);
} else {
/* Check if a disc is in the drive */
/* XXX initial call always returns inserted
* causing unnecessary rescan - optimize?
*/
if (state == last_state) {
continue;
} else {
}
switch (state) {
case DKIO_EJECTED:
last_state = state;
/* attempt to unmount all childs */
/* could have a fs on the main block device; do a rescan to remove it */
break;
case DKIO_INSERTED:
last_state = state;
/* could have a fs on the main block device; do a rescan to add it */
break;
case DKIO_DEV_GONE:
last_state = state;
close_device (&fd);
goto out;
case DKIO_NONE:
default:
break;
}
} else {
}
}
}
out:
sysevent_fini ();
}
return 0;
}