res.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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
*/
/*
*
* res.c
*
* Implements routines to create a cache resource file.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Copyright (c) 1996, by Sun Microsystems, Inc.
* All rights reserved.
*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "res.h"
struct res {
int p_magic; /* magic number */
void *p_addrp; /* address of mapped file */
long p_size; /* size of mapped file */
int p_totentries; /* max number of rl entries */
};
#define MAGIC 8272
#define MININDEX 1
/* forward references */
long blks);
/*
*
* res_create
*
* Description:
* Creates a res object and returns a pointer to it.
* The specified file is used to store resource file data.
* Arguments:
* namep name of the resource file
* entries max number of rl entries in the file
* verbose 1 means print out error messages
* Returns:
* Returns a pointer to the object or NULL if an error occurred.
* Preconditions:
* precond(namep)
* precond(entries > 3)
* precond(strlen(namep) < MAXPATHLEN)
*/
res *
{
int xx;
long size;
int fd;
char buf[1024];
long cnt;
unsigned int amt;
void *addrp;
/* determine the size needed for the resource file */
if ((entries % CACHEFS_RLPMBS) != 0)
/* resource file will be <2GB */
/* remove the resource file */
return (NULL);
/* create and open the file */
if (fd == -1)
return (NULL);
/* fill the file with zeros */
if (result == -1) {
return (NULL);
}
}
}
/* else open the file */
else {
if (fd == -1)
return (NULL);
}
/* mmap the file into our address space */
if (addrp == (void *)-1) {
return (NULL);
}
/* close the file descriptor, we do not need it anymore */
/* allocate memory for the res object */
return (NULL);
}
/* initialize the object */
sizeof (struct cache_usage));
/* reset the resource file in preperation to rebuild it */
/* return the object */
return (resp);
}
/*
*
* res_destroy
*
* Description:
* Destroys the specifed res object.
* If res_done has not been called on the object or if res_done
* failed, then the resource file will be deleted.
* Arguments:
* resp object to destroy
* Returns:
* Preconditions:
* precond(resp is a valid res object)
*/
void
{
/* unmap the file */
/* if res_done not performed */
/* remove the resource file */
}
/* destroy the object */
}
{
window = (rl_entry_t *)
return (rlentp);
}
/*
*
* res_reset
*
* Description:
* Resets the resource file in preparation to rebuild it.
* Arguments:
* resp res object
* Returns:
* Preconditions:
* precond(resp is a valid res object)
*/
void
{
int index;
int ret;
/* clear out the non-pointer info */
}
/* verify validity of the various lists */
if (ret == 1) {
if (ret == 1) {
if (ret == 1) {
if (ret == 1) {
}
}
}
}
/* if an error occurred on one of the lists */
if (ret == 0) {
return;
}
/* zero out total sizes, they get fixed up as we add items */
/* null out the heads of the lists we do not want to preserve */
}
/*
*
* res_listcheck
*
* Description:
* Checks the specified list.
* Arguments:
* resp res object
* type list to check
* Returns:
* Returns 1 if the list is ok, 0 if there is a problem.
* Preconditions:
* precond(resp is a valid res object)
*/
int
{
int itemcnt = 0;
previndex = 0;
/* walk the list */
while (index != 0) {
itemcnt++;
/* make sure offset is in bounds */
return (0);
}
/* get pointer to rl_entry object */
/* check forward pointer */
/* bad back pointer in rl list */
return (0);
}
/* check for cycle */
/* cycle found in list */
index);
return (0);
}
/* check type */
/* entry doesn't belong here */
"bad entry %d type %d in list type %d"),
return (0);
}
/* indicate we have seen this pointer */
}
/* verify number of items match */
return (0);
}
return (1);
}
/*
*
* res_clear
*
* Description:
* Deletes all information from the resource file.
* Arguments:
* resp res object
* Returns:
* Preconditions:
* precond(resp is a valid res object)
*/
void
{
}
/*
*
* res_done
*
* Description:
* Called when through performing res_addfile and res_addident
* to complete the resource file and flush the contents to
* the disk file.
* Arguments:
* resp res object
* Returns:
* Returns 0 for success, -1 for an error with errno set
* appropriatly.
* Preconditions:
* precond(resp is a valid res object)
*/
int
{
int index;
int xx;
int ret;
/* scan the ident list to find the max allocated entry */
}
}
/* scan the ident list to fix up the free list */
/* if entry is not valid */
/* if entry should appear on the free list */
CACHEFS_RL_FREE, index, 0);
}
}
}
/*
* Sanity check that we do not have an internal error in
* fsck. Eventually turn this stuff off.
*/
#if 1
#endif
/* indicate the cache is clean */
/* sync the data to the file */
if (xx == -1)
return (-1);
/* return success */
return (0);
}
/*
*
* res_addfile
*
* Description:
* Increments the number of files and blocks resource counts.
* Arguments:
* resp res object
* nbytes number of bytes in the file
* Returns:
* Preconditions:
* precond(resp is a valid res object)
*/
void
{
/* update resource counts */
}
/*
*
* res_addident
*
* Description:
* Adds the specified file to the ident list.
* Updates resource counts.
* Arguments:
* resp res object
* dp ident information
* nbytes number of bytes of item
* file number of files of item
* Returns:
* Returns 0 for success or -1 if the index is already in use
* or is not valid.
* Preconditions:
* precond(resp is a valid res object)
* precond(dp)
*/
int
{
/* check index for sanity */
return (-1);
}
/* get pointer to ident */
/* if something already there */
return (-1);
}
/* if not on the right list, move it there */
/* update resource counts */
/* return success */
return (0);
}
/*
*
* res_clearident
*
* Description:
* Removes the specified file from the ident list.
* Updates resource counts.
* Arguments:
* resp res object
* nbytes number of bytes in the file
* file number of files
* Returns:
* Returns 0.
* Preconditions:
* precond(resp is a valid res object)
* precond(index is valid)
* precond(ident is in use)
*/
int
{
/* get pointer to ident */
/* clear the ident */
/* update resource counts */
}
/*
* This function moves an RL entry from whereever it currently is to
* the requested list.
*/
void
{
enum cachefs_rl_type otype;
/* remove entry from its previous list */
(otype <= CACHEFS_RL_END));
if (prev != 0) {
}
if (next != 0) {
}
lhp->rli_itemcnt--;
}
/* add entry to its new list */
rl_ent->rl_bkwd_idx = 0;
} else {
}
lhp->rli_itemcnt++;
}