/*
* 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
*/
/*
* Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved
*
* module:
* base.c
*
* purpose:
* routines to create, traverse, read and write the baseline database
*
* contents:
* manipulation:
* add_base, add_file_to_base, add_file_to_dir
* (static) add_file_to_list
* reading baseline:
* read_baseline
* (static) gettype
* writing baseline:
* write_baseline
* (static) bw_header, bw_base, bw_file, showtype
*/
#ident "%W% %E% SMI"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "filesync.h"
#include "database.h"
#include "messages.h"
/*
* globals
*/
/*
* locals
*/
static char showtype(int);
static long gettype(int);
/*
* routine:
* add_base
*
* purpose:
* to find a base pair in the chain, adding it if necessary
*
* parameters:
* spec for source directory
* spec for dest directory
*
* returns:
* pointer to the base pair
*
*/
struct base *
/* first see if we already have it */
/* base must match on both src and dst */
continue;
continue;
return (bp);
}
/* no joy, so we have to allocate one */
if (bp == 0)
nomem("base structure");
/* initialize the new base */
/* names are expanded at run-time, and this is run-time */
}
}
/* chain it in */
return (bp);
}
/*
* routine:
* add_file_to_list
*
* purpose:
* to find a file on a list, or if necessary add it to the list
*
* this is an internal routine, used only by add_file_to_base
* and add_file_to_dir.
*
* parameters:
* pointer to the list head
*
* returns:
* pointer to a file structure
*
* notes:
*
* list is sorted to provide some search optimization
*
* most files are in the baseline, and so come in in alphabetical
* there is a better than even chance that this one should be
* added immediately onto the end of it ... and in so doing we
* can save ourselves the trouble of searching the lists most
* of the time.
*
* this win would be even better if the FTW traversal was sorted,
* but building the baseline is enough of a win to justify the
* feature ... but even without this we run a 60%-70% hit rate.
*/
static struct file *
int rslt;
/*
* start with the guess pointer, we hope to find that
* this request will be satisfied by the next file in
* the list. The two cases we are trying to optimize
* are:
* appending to the list, with appends in alphabetical order
* searches of the list, with searches in alphabetical order
*/
/* we like to think we belong farther down-list */
/* if we're at the end, we just won */
if (fp == 0) {
goto makeit;
}
/* or if the next one is what we want */
goto gotit;
}
}
}
/*
* our guess pointer failed, so it is exhaustive search time
*/
/* see if we got a match */
if (rslt == 0) {
goto gotit;
}
/* see if we should go no farther */
if (rslt < 0)
break;
}
/*
* we didn't find it:
* pp points at where our pointer should go
* fp points at the node after ours
*/
if (new == 0)
nomem("file structure");
/* initialize the new node */
/* chain it into the list */
gotit: /* remember this as our next guess pointer */
return (new);
}
/*
* routine:
* add_file_to_base
*
* purpose:
* to add a file-node to a baseline
*
* parameters:
* pointer to base
* name of file to be added
*
* returns:
* pointer to file structure
*/
struct file *
name);
return (fp);
}
/*
* routine:
* add_file_to_dir
*
* purpose:
* to add a file-node to a directory
*
* parameters:
* pointer to file entry for directory
* name of file to be added
*
* returns:
* pointer to file structure
*/
struct file *
name);
return (fp);
}
/*
* routine:
* read_baseline
*
* purpose:
* to read in the baseline file
*
* parameters:
* name of baseline file
*
* returns:
* error mask
*/
char *s;
char *s1 = 0;
char type;
unsigned long l;
int level;
name);
return (ERR_FILES);
}
lex_linenum = 0;
/* find the first token on the line */
/* skip blank lines and comments */
if (s == 0 || *s == 0 || *s == '#' || *s == '*')
continue;
field = "keyword";
/* see if the first token is a known keyword */
s = lex(0);
if (s == 0)
goto bad;
if (*s1 != '.')
goto bad;
}
s1 = 0;
continue;
}
if (strcmp(s, "BASE_SRC") == 0) {
s = lex(0);
field = "source directory";
if (s == 0)
goto bad;
bp = 0;
continue;
}
if (strcmp(s, "BASE_DST") == 0) {
s = lex(0);
field = "destination directory";
if (s == 0)
goto bad;
/* make sure we have a source too */
if (s1 == 0) {
field = "no source directory";
goto bad;
}
s1 = 0;
continue;
}
if (strcmp(s, "FILE") == 0) {
/* make sure we have a base to add to */
if (bp == 0) {
field = "missing base";
goto bad;
}
s = lex(0); /* level */
field = "level";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
level = l;
s = lex(0); /* type */
field = "file type";
if (s == 0 || *s == 0)
goto bad;
type = *s;
goto bad;
s = lex(0); /* name */
field = "file name";
if (s == 0 || *s == 0)
goto bad;
/* allocate a file structure for this entry */
if (level == 0)
else
/* maintain the directory stack */
}
/* get a pointer to the baseline file info structure */
s = lex(0); /* modes */
field = "file modes";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
s = lex(0); /* uid */
field = "file UID";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
s = lex(0); /* gid */
field = "file GID";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
s = lex(0); /* source inode */
field = "source i#";
if (s == 0 || *s == 0)
goto bad;
s = lex(0); /* source major */
field = "source major";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
s = lex(0); /* source minor */
field = "source minor";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
s = lex(0); /* source nlink */
field = "source nlink";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
s = lex(0); /* source mod */
field = "source modtime";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
fp->f_s_modtime = l;
s = lex(0); /* dest inode */
field = "destination i#";
if (s == 0 || *s == 0)
goto bad;
s = lex(0); /* dest major */
field = "destination major";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
s = lex(0); /* dest minor */
field = "destination minor";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
s = lex(0); /* dest nlink */
field = "dest nlink";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
s = lex(0); /* dest mod */
field = "dest modtime";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
fp->f_d_modtime = l;
s = lex(0); /* major or size */
field = "rdev major";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
s = lex(0); /* minor */
field = "rdev minor";
if (s == 0 || *s == 0)
goto bad;
l = strtoul(s, 0, 0);
} else {
field = "file size";
if (s == 0 || *s == 0)
goto bad;
}
/*
* all fields after this point were added to the
* 1.0 format and so should be considered optional
*/
s = lex(0); /* acl length ? */
field = "acl count";
if (s && *s) {
l = strtoul(s, 0, 0);
sizeof (aclent_t));
nomem("Access Control List");
}
continue;
}
if (strcmp(s, "ACL") == 0) {
/* make sure there is a place to put the ACL */
goto bad;
}
/* acl entry number */
s = lex(0);
field = "acl index";
if (s == 0)
goto bad;
l = strtoul(s, 0, 0);
goto bad;
else
/* acl entry type */
s = lex(0);
field = "acl type";
if (s == 0)
goto bad;
l = strtoul(s, 0, 0);
/* acl entry ID */
s = lex(0);
field = "acl id";
if (s == 0)
goto bad;
l = strtoul(s, 0, 0);
/* acl entry perms */
s = lex(0);
field = "acl perm";
if (s == 0)
goto bad;
l = strtoul(s, 0, 0);
continue;
}
bad: /* log the error and continue processing to find others */
}
return (errs);
}
/*
* routine:
* write_baseline
*
* purpose:
* to rewrite the baseline file
*
* parameters:
* name of the new baseline file
*
* returns:
* error mask
*/
/* if no-touch is specified, we don't update files */
if (opt_notouch)
return (0);
/* create a temporary output file */
/* create our output file */
tmpname);
return (ERR_FILES);
}
tmpname);
}
tmpname);
}
/* now switch the new file for the old one */
if (errs == 0)
}
return (errs);
}
/*
* routine:
* bw_header
*
* purpose:
* to write out a baseline header
*
* parameters:
* FILE* for the output file
*
* returns:
* error mask
*
* notes:
*/
static errmask_t
/* figure out what time it is */
return (0);
}
/*
* routine:
* bw_base
*
* purpose:
* to write out the summary for one base-pair
*
* parameters:
* FILE * for the output file
*
* returns:
* error mask
*
* notes:
*/
static errmask_t
/* see if this base is to be dropped from baseline */
return (0);
return (errs);
}
/*
* routine:
* bw_file
*
* purpose:
* to write a file description out to the baseline
*
* parameters:
* output FILE
* pointer to file description
* recursion depth
*
* returns:
* error mask
*
* notes:
* some of the information we write out is kept separately
* for source and destination files because the values should
*
* if a file has an unresolved conflict, we want to leave
* the old values in place so that we continue to compare
* files against the last time they agreed.
*/
static errmask_t
int i;
/* if this file is to be removed from baseline, skip it */
return (0);
/*
* if this node is in conflict, or if it has not been
* evaluated this time around, we should just leave the
* baseline file the way it was before. If there is a
* conflict, let the baseline reflect the last agreement.
* If the node wasn't evaluated, let the baseline reflect
* our last knowledge.
*/
}
/* write out the entry for this file */
ll,
ll,
/* last fields are file type specific */
else {
}
/* ACL count goes at the end because it was added */
/* if this file has ACLs, we have to write them out too */
/* then enumerate all of the children (if any) */
return (errs);
}
/*
* routines:
*
* purpose:
* to convert between a file type (as found in a mode word)
* and a single character representation
*
* mode word -> character
* character -> mode word
*/
{
}
{ int i;
for (i = 0; i < 16; i++)
return (i << 12);
return (-1);
}