inst_sync.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
/*
* 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"
/*
* Syscall to write out the instance number data structures to
* stable storage.
*/
#include <sys/dditypes.h>
#include <sys/instance.h>
/*
* Userland sees:
*
* int inst_sync(pathname, flags);
*
* Returns zero if instance number information was successfully
* written to 'pathname', -1 plus error code in errno otherwise.
*
* POC notes:
*
* - This could be done as a case of the modctl(2) system call
* though the ability to have it load and unload would disappear.
*
* - Currently, flags are not interpreted.
*
* - Maybe we should pass through two filenames - one to create,
* and the other as the 'final' target i.e. do the rename of
* /etc/instance.new -> /etc/instance in the kernel.
*/
static struct sysent in_sync_sysent = {
2, /* number of arguments */
in_sync_sys, /* the handler */
};
};
#ifdef _SYSCALL32_IMPL
};
#endif
static struct modlinkage modlinkage = {
&modlsys,
#ifdef _SYSCALL32_IMPL
#endif
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
{
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}
/*ARGSUSED1*/
static int
{
int error;
/*
* We must have sufficient privilege to do this, since we lock critical
* data structures whilst we're doing it ..
*/
/*
* Only one process is allowed to get the state of the instance
* number assignments on the system at any given time.
*/
if (e_ddi_instance_is_clean()) {
goto end;
}
/*
* Create an instance file for writing, giving it a mode that
* will only permit reading. Note that we refuse to overwrite
* an existing file.
*/
goto end;
}
/*
* So far so good. We're singly threaded, the vnode is beckoning
* so let's get on with it. Any error, and we just give up and
* hand the first error we get back to userland.
*/
/*
* If there was any sort of error, we deliberately go and
* remove the file we just created so that any attempts to
* use it will quickly fail.
*/
if (error)
else
end:
}
/*
* At the risk of reinventing stdio ..
*/
#define FBUFSIZE 512
typedef struct _File {
char *ptr;
int count;
} File;
static int
{
int error;
return (error);
}
static File *
{
return (fp);
}
static int
{
int error;
return (error);
}
static int
{
int error = 0;
if (error == 0)
return (error);
}
static int
{
int error = 0;
while (*buf) {
if (error)
break;
}
}
return (error);
}
/*
* External linkage
*/
/*
* XXX what is the maximum length of the name of a driver? Must be maximum
* XXX file name length (find the correct constant and substitute for this one
*/
/*
* XXX Maybe we should just write 'in_fprintf' instead ..
*/
static int
{
char *next;
int error = 0;
else
np->in_unit_addr);
/*
* Flushing IN_PROVISIONAL could result in duplicate
* instances
* Flushing IN_UNKNOWN results in instance -1
*/
continue;
return (error);
}
break;
}
return (error);
}
/*
* Walk the instance tree, writing out what we find.
*
* There's some fairly nasty sharing of buffers in this
* bit of code, so be careful out there when you're
* rewriting it ..
*/
static int
{
int error;
char *cp;
/*
* Place a bossy comment at the beginning of the file.
*/
"#\n#\tCaution! This file contains critical kernel state\n#\n");
if (error == 0) {
cp = linebuffer;
*cp++ = '\"';
}
if (error == 0) {
} else
return (error);
}