/*
* 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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This module contains functions used for reading and writing the scratch zone
* translation files. These files are used by Live Upgrade to keep track of
* mappings between actual kernel zone names and the zones in an alternate boot
* environment.
*
* The functions are MT-safe.
*
* The file format looks like this:
*
* <zonename> <kernel-zonename> <alt-root>
*
* The expected usage model is:
*
* fp = zonecfg_open_scratch("", B_TRUE);
* zonecfg_lock_scratch(fp);
* if (zonecfg_find_scratch(fp, zonename, altroot, NULL, 0) == 0) {
* handle error; zone already mounted
* }
* mount zone here
* zonecfg_add_scratch(fp, zonename, kernname, altroot);
* zonecfg_close_scratch(fp);
* fp = zonecfg_open_scratch(zoneroot, B_TRUE);
* ftruncate(fileno(fp), 0);
* zonecfg_add_scratch(fp, zonename, kernname, "/");
* zonecfg_close_scratch(fp);
*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <libzonecfg.h>
static int
{
}
FILE *
{
rootpath);
if (createfile)
if (!createfile) {
goto failure;
}
goto failure;
goto failure;
}
if (fd == -1)
goto failure;
goto failure;
goto failure;
}
}
goto failure;
return (fp);
if (fd != -1)
return (NULL);
}
int
{
return (-1);
}
void
{
}
int
{
/* We always hold at least a read lock on the file */
for (;;) {
return (-1);
return (-1);
*cp = '\0';
else
*cp++ = '\0';
continue;
else
*cp2++ = '\0';
continue;
continue;
break;
}
return (0);
}
int
{
return (0);
}
return (-1);
}
int
{
return (0);
}
return (-1);
}
int
const char *altroot)
{
return (-1);
return (-1);
return (-1);
return (0);
}
int
{
/*
* The implementation here is intentionally quite simple. We could
* allocate a buffer that's big enough to hold the data up to
* stat.st_size and then write back out the part we need to, but there
* seems to be little point.
*/
roffs = 0;
do {
NULL, 0) != 0)
return (-1);
break;
break;
break;
}
return (0);
}
{
}