Deleted Added
full compact
tables.c (90110) tables.c (90113)
1/*-
2 * Copyright (c) 1992 Keith Muller.
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Keith Muller of the University of California, San Diego.
8 *

--- 26 unchanged lines hidden (view full) ---

35 * SUCH DAMAGE.
36 */
37
38#ifndef lint
39#if 0
40static char sccsid[] = "@(#)tables.c 8.1 (Berkeley) 5/31/93";
41#endif
42static const char rcsid[] =
1/*-
2 * Copyright (c) 1992 Keith Muller.
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Keith Muller of the University of California, San Diego.
8 *

--- 26 unchanged lines hidden (view full) ---

35 * SUCH DAMAGE.
36 */
37
38#ifndef lint
39#if 0
40static char sccsid[] = "@(#)tables.c 8.1 (Berkeley) 5/31/93";
41#endif
42static const char rcsid[] =
43 "$FreeBSD: head/bin/pax/tables.c 90110 2002-02-02 06:48:10Z imp $";
43 "$FreeBSD: head/bin/pax/tables.c 90113 2002-02-02 07:07:59Z imp $";
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/time.h>
48#include <sys/stat.h>
49#include <sys/fcntl.h>
50#include <errno.h>
51#include <stdio.h>

--- 73 unchanged lines hidden (view full) ---

125 * database. (We have seen all the links to this file). If not found,
126 * we add the file to the database if it has the potential for having
127 * hard links to other files we may process (it has a link count > 1)
128 * Return:
129 * if found returns 1; if not found returns 0; -1 on error
130 */
131
132int
44#endif /* not lint */
45
46#include <sys/types.h>
47#include <sys/time.h>
48#include <sys/stat.h>
49#include <sys/fcntl.h>
50#include <errno.h>
51#include <stdio.h>

--- 73 unchanged lines hidden (view full) ---

125 * database. (We have seen all the links to this file). If not found,
126 * we add the file to the database if it has the potential for having
127 * hard links to other files we may process (it has a link count > 1)
128 * Return:
129 * if found returns 1; if not found returns 0; -1 on error
130 */
131
132int
133chk_lnk(register ARCHD *arcn)
133chk_lnk(ARCHD *arcn)
134{
134{
135 register HRDLNK *pt;
136 register HRDLNK **ppt;
137 register u_int indx;
135 HRDLNK *pt;
136 HRDLNK **ppt;
137 u_int indx;
138
139 if (ltab == NULL)
140 return(-1);
141 /*
142 * ignore those nodes that cannot have hard links
143 */
144 if ((arcn->type == PAX_DIR) || (arcn->sb.st_nlink <= 1))
145 return(0);

--- 66 unchanged lines hidden (view full) ---

212/*
213 * purg_lnk
214 * remove reference for a file that we may have added to the data base as
215 * a potential source for hard links. We ended up not using the file, so
216 * we do not want to accidently point another file at it later on.
217 */
218
219void
138
139 if (ltab == NULL)
140 return(-1);
141 /*
142 * ignore those nodes that cannot have hard links
143 */
144 if ((arcn->type == PAX_DIR) || (arcn->sb.st_nlink <= 1))
145 return(0);

--- 66 unchanged lines hidden (view full) ---

212/*
213 * purg_lnk
214 * remove reference for a file that we may have added to the data base as
215 * a potential source for hard links. We ended up not using the file, so
216 * we do not want to accidently point another file at it later on.
217 */
218
219void
220purg_lnk(register ARCHD *arcn)
220purg_lnk(ARCHD *arcn)
221{
221{
222 register HRDLNK *pt;
223 register HRDLNK **ppt;
224 register u_int indx;
222 HRDLNK *pt;
223 HRDLNK **ppt;
224 u_int indx;
225
226 if (ltab == NULL)
227 return;
228 /*
229 * do not bother to look if it could not be in the database
230 */
231 if ((arcn->sb.st_nlink <= 1) || (arcn->type == PAX_DIR) ||
232 (arcn->type == PAX_HLK) || (arcn->type == PAX_HRG))

--- 35 unchanged lines hidden (view full) ---

268 * read and write phases of append with update. (The format may have
269 * used the link table, and we need to start with a fresh table for the
270 * write phase
271 */
272
273void
274lnk_end(void)
275{
225
226 if (ltab == NULL)
227 return;
228 /*
229 * do not bother to look if it could not be in the database
230 */
231 if ((arcn->sb.st_nlink <= 1) || (arcn->type == PAX_DIR) ||
232 (arcn->type == PAX_HLK) || (arcn->type == PAX_HRG))

--- 35 unchanged lines hidden (view full) ---

268 * read and write phases of append with update. (The format may have
269 * used the link table, and we need to start with a fresh table for the
270 * write phase
271 */
272
273void
274lnk_end(void)
275{
276 register int i;
277 register HRDLNK *pt;
278 register HRDLNK *ppt;
276 int i;
277 HRDLNK *pt;
278 HRDLNK *ppt;
279
280 if (ltab == NULL)
281 return;
282
283 for (i = 0; i < L_TAB_SZ; ++i) {
284 if (ltab[i] == NULL)
285 continue;
286 pt = ltab[i];

--- 77 unchanged lines hidden (view full) ---

364 * the most recent file time is retained. If the new file was younger (or
365 * was not in the database) the new file is selected for storage.
366 * Return:
367 * 0 if file should be added to the archive, 1 if it should be skipped,
368 * -1 on error
369 */
370
371int
279
280 if (ltab == NULL)
281 return;
282
283 for (i = 0; i < L_TAB_SZ; ++i) {
284 if (ltab[i] == NULL)
285 continue;
286 pt = ltab[i];

--- 77 unchanged lines hidden (view full) ---

364 * the most recent file time is retained. If the new file was younger (or
365 * was not in the database) the new file is selected for storage.
366 * Return:
367 * 0 if file should be added to the archive, 1 if it should be skipped,
368 * -1 on error
369 */
370
371int
372chk_ftime(register ARCHD *arcn)
372chk_ftime(ARCHD *arcn)
373{
373{
374 register FTM *pt;
375 register int namelen;
376 register u_int indx;
374 FTM *pt;
375 int namelen;
376 u_int indx;
377 char ckname[PAXPATHLEN+1];
378
379 /*
380 * no info, go ahead and add to archive
381 */
382 if (ftab == NULL)
383 return(0);
384

--- 119 unchanged lines hidden (view full) ---

504 * add the new name to old name mapping just created by the user.
505 * If an old name mapping is found (there may be duplicate names on an
506 * archive) only the most recent is kept.
507 * Return:
508 * 0 if added, -1 otherwise
509 */
510
511int
377 char ckname[PAXPATHLEN+1];
378
379 /*
380 * no info, go ahead and add to archive
381 */
382 if (ftab == NULL)
383 return(0);
384

--- 119 unchanged lines hidden (view full) ---

504 * add the new name to old name mapping just created by the user.
505 * If an old name mapping is found (there may be duplicate names on an
506 * archive) only the most recent is kept.
507 * Return:
508 * 0 if added, -1 otherwise
509 */
510
511int
512add_name(register char *oname, int onamelen, char *nname)
512add_name(char *oname, int onamelen, char *nname)
513{
513{
514 register NAMT *pt;
515 register u_int indx;
514 NAMT *pt;
515 u_int indx;
516
517 if (ntab == NULL) {
518 /*
519 * should never happen
520 */
521 paxwarn(0, "No interactive rename table, links may fail\n");
522 return(0);
523 }

--- 48 unchanged lines hidden (view full) ---

572/*
573 * sub_name()
574 * look up a link name to see if it points at a file that has been
575 * remapped by the user. If found, the link is adjusted to contain the
576 * new name (oname is the link to name)
577 */
578
579void
516
517 if (ntab == NULL) {
518 /*
519 * should never happen
520 */
521 paxwarn(0, "No interactive rename table, links may fail\n");
522 return(0);
523 }

--- 48 unchanged lines hidden (view full) ---

572/*
573 * sub_name()
574 * look up a link name to see if it points at a file that has been
575 * remapped by the user. If found, the link is adjusted to contain the
576 * new name (oname is the link to name)
577 */
578
579void
580sub_name(register char *oname, int *onamelen, size_t onamesize)
580sub_name(char *oname, int *onamelen, size_t onamesize)
581{
581{
582 register NAMT *pt;
583 register u_int indx;
582 NAMT *pt;
583 u_int indx;
584
585 if (ntab == NULL)
586 return;
587 /*
588 * look the name up in the hash table
589 */
590 indx = st_hash(oname, *onamelen, N_TAB_SZ);
591 if ((pt = ntab[indx]) == NULL)

--- 86 unchanged lines hidden (view full) ---

678 * remapped to a new value if it be used during a write phase. This
679 * function is called during the read phase of an append to prohibit the
680 * use of any device number already in the archive.
681 * Return:
682 * 0 if added ok, -1 otherwise
683 */
684
685int
584
585 if (ntab == NULL)
586 return;
587 /*
588 * look the name up in the hash table
589 */
590 indx = st_hash(oname, *onamelen, N_TAB_SZ);
591 if ((pt = ntab[indx]) == NULL)

--- 86 unchanged lines hidden (view full) ---

678 * remapped to a new value if it be used during a write phase. This
679 * function is called during the read phase of an append to prohibit the
680 * use of any device number already in the archive.
681 * Return:
682 * 0 if added ok, -1 otherwise
683 */
684
685int
686add_dev(register ARCHD *arcn)
686add_dev(ARCHD *arcn)
687{
688 if (chk_dev(arcn->sb.st_dev, 1) == NULL)
689 return(-1);
690 return(0);
691}
692
693/*
694 * chk_dev()

--- 6 unchanged lines hidden (view full) ---

701 * if the add flag is not set and the device is not in the table (it is
702 * not been seen yet). If add is set and the device cannot be added, null
703 * is returned (indicates an error).
704 */
705
706static DEVT *
707chk_dev(dev_t dev, int add)
708{
687{
688 if (chk_dev(arcn->sb.st_dev, 1) == NULL)
689 return(-1);
690 return(0);
691}
692
693/*
694 * chk_dev()

--- 6 unchanged lines hidden (view full) ---

701 * if the add flag is not set and the device is not in the table (it is
702 * not been seen yet). If add is set and the device cannot be added, null
703 * is returned (indicates an error).
704 */
705
706static DEVT *
707chk_dev(dev_t dev, int add)
708{
709 register DEVT *pt;
710 register u_int indx;
709 DEVT *pt;
710 u_int indx;
711
712 if (dtab == NULL)
713 return(NULL);
714 /*
715 * look to see if this device is already in the table
716 */
717 indx = ((unsigned)dev) % D_TAB_SZ;
718 if ((pt = dtab[indx]) != NULL) {

--- 38 unchanged lines hidden (view full) ---

757 * seen (and was marked as do not use during the write phase). WE ASSUME
758 * that unsigned longs are the same size or bigger than the fields used
759 * for ino_t and dev_t. If not the types will have to be changed.
760 * Return:
761 * 0 if all ok, -1 otherwise.
762 */
763
764int
711
712 if (dtab == NULL)
713 return(NULL);
714 /*
715 * look to see if this device is already in the table
716 */
717 indx = ((unsigned)dev) % D_TAB_SZ;
718 if ((pt = dtab[indx]) != NULL) {

--- 38 unchanged lines hidden (view full) ---

757 * seen (and was marked as do not use during the write phase). WE ASSUME
758 * that unsigned longs are the same size or bigger than the fields used
759 * for ino_t and dev_t. If not the types will have to be changed.
760 * Return:
761 * 0 if all ok, -1 otherwise.
762 */
763
764int
765map_dev(register ARCHD *arcn, u_long dev_mask, u_long ino_mask)
765map_dev(ARCHD *arcn, u_long dev_mask, u_long ino_mask)
766{
766{
767 register DEVT *pt;
768 register DLIST *dpt;
767 DEVT *pt;
768 DLIST *dpt;
769 static dev_t lastdev = 0; /* next device number to try */
770 int trc_ino = 0;
771 int trc_dev = 0;
772 ino_t trunc_bits = 0;
773 ino_t nino;
774
775 if (dtab == NULL)
776 return(0);

--- 144 unchanged lines hidden (view full) ---

921 * walk through the directory access time table and reset the access time
922 * of any directory who still has an entry left in the database. These
923 * entries are for directories READ by pax
924 */
925
926void
927atdir_end(void)
928{
769 static dev_t lastdev = 0; /* next device number to try */
770 int trc_ino = 0;
771 int trc_dev = 0;
772 ino_t trunc_bits = 0;
773 ino_t nino;
774
775 if (dtab == NULL)
776 return(0);

--- 144 unchanged lines hidden (view full) ---

921 * walk through the directory access time table and reset the access time
922 * of any directory who still has an entry left in the database. These
923 * entries are for directories READ by pax
924 */
925
926void
927atdir_end(void)
928{
929 register ATDIR *pt;
930 register int i;
929 ATDIR *pt;
930 int i;
931
932 if (atab == NULL)
933 return;
934 /*
935 * for each non-empty hash table entry reset all the directories
936 * chained there.
937 */
938 for (i = 0; i < A_TAB_SZ; ++i) {

--- 13 unchanged lines hidden (view full) ---

952 * add_atdir()
953 * add a directory to the directory access time table. Table is hashed
954 * and chained by inode number. This is for directories READ by pax
955 */
956
957void
958add_atdir(char *fname, dev_t dev, ino_t ino, time_t mtime, time_t atime)
959{
931
932 if (atab == NULL)
933 return;
934 /*
935 * for each non-empty hash table entry reset all the directories
936 * chained there.
937 */
938 for (i = 0; i < A_TAB_SZ; ++i) {

--- 13 unchanged lines hidden (view full) ---

952 * add_atdir()
953 * add a directory to the directory access time table. Table is hashed
954 * and chained by inode number. This is for directories READ by pax
955 */
956
957void
958add_atdir(char *fname, dev_t dev, ino_t ino, time_t mtime, time_t atime)
959{
960 register ATDIR *pt;
961 register u_int indx;
960 ATDIR *pt;
961 u_int indx;
962
963 if (atab == NULL)
964 return;
965
966 /*
967 * make sure this directory is not already in the table, if so just
968 * return (the older entry always has the correct time). The only
969 * way this will happen is when the same subtree can be traversed by

--- 44 unchanged lines hidden (view full) ---

1014 * pax
1015 * Return:
1016 * 0 if found, -1 if not found.
1017 */
1018
1019int
1020get_atdir(dev_t dev, ino_t ino, time_t *mtime, time_t *atime)
1021{
962
963 if (atab == NULL)
964 return;
965
966 /*
967 * make sure this directory is not already in the table, if so just
968 * return (the older entry always has the correct time). The only
969 * way this will happen is when the same subtree can be traversed by

--- 44 unchanged lines hidden (view full) ---

1014 * pax
1015 * Return:
1016 * 0 if found, -1 if not found.
1017 */
1018
1019int
1020get_atdir(dev_t dev, ino_t ino, time_t *mtime, time_t *atime)
1021{
1022 register ATDIR *pt;
1023 register ATDIR **ppt;
1024 register u_int indx;
1022 ATDIR *pt;
1023 ATDIR **ppt;
1024 u_int indx;
1025
1026 if (atab == NULL)
1027 return(-1);
1028 /*
1029 * hash by inode and search the chain for an inode and device match
1030 */
1031 indx = ((unsigned)ino) % A_TAB_SZ;
1032 if ((pt = atab[indx]) == NULL)

--- 193 unchanged lines hidden (view full) ---

1226 * chars at a time and pads with 0 for last addition.
1227 * Return:
1228 * the hash value of the string MOD (%) the table size.
1229 */
1230
1231u_int
1232st_hash(char *name, int len, int tabsz)
1233{
1025
1026 if (atab == NULL)
1027 return(-1);
1028 /*
1029 * hash by inode and search the chain for an inode and device match
1030 */
1031 indx = ((unsigned)ino) % A_TAB_SZ;
1032 if ((pt = atab[indx]) == NULL)

--- 193 unchanged lines hidden (view full) ---

1226 * chars at a time and pads with 0 for last addition.
1227 * Return:
1228 * the hash value of the string MOD (%) the table size.
1229 */
1230
1231u_int
1232st_hash(char *name, int len, int tabsz)
1233{
1234 register char *pt;
1235 register char *dest;
1236 register char *end;
1237 register int i;
1238 register u_int key = 0;
1239 register int steps;
1240 register int res;
1234 char *pt;
1235 char *dest;
1236 char *end;
1237 int i;
1238 u_int key = 0;
1239 int steps;
1240 int res;
1241 u_int val;
1242
1243 /*
1244 * only look at the tail up to MAXKEYLEN, we do not need to waste
1245 * time here (remember these are pathnames, the tail is what will
1246 * spread out the keys)
1247 */
1248 if (len > MAXKEYLEN) {

--- 42 unchanged lines hidden ---
1241 u_int val;
1242
1243 /*
1244 * only look at the tail up to MAXKEYLEN, we do not need to waste
1245 * time here (remember these are pathnames, the tail is what will
1246 * spread out the keys)
1247 */
1248 if (len > MAXKEYLEN) {

--- 42 unchanged lines hidden ---