symtab.c (85746) | symtab.c (92806) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)symtab.c 8.3 (Berkeley) 4/28/95"; 37#endif 38static const char rcsid[] = | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 22 unchanged lines hidden (view full) --- 31 * SUCH DAMAGE. 32 */ 33 34#ifndef lint 35#if 0 36static char sccsid[] = "@(#)symtab.c 8.3 (Berkeley) 4/28/95"; 37#endif 38static const char rcsid[] = |
39 "$FreeBSD: head/sbin/restore/symtab.c 85746 2001-10-30 20:06:59Z tobez $"; | 39 "$FreeBSD: head/sbin/restore/symtab.c 92806 2002-03-20 17:55:10Z obrien $"; |
40#endif /* not lint */ 41 42/* 43 * These routines maintain the symbol table which tracks the state 44 * of the file system being restored. They provide lookup by either 45 * name or inode number. They also provide for creation, deletion, 46 * and renaming of entries. Because of the dynamic nature of pathnames, 47 * names should not be saved, but always constructed just before they --- 32 unchanged lines hidden (view full) --- 80 81/* 82 * Look up an entry by inode number 83 */ 84struct entry * 85lookupino(inum) 86 ino_t inum; 87{ | 40#endif /* not lint */ 41 42/* 43 * These routines maintain the symbol table which tracks the state 44 * of the file system being restored. They provide lookup by either 45 * name or inode number. They also provide for creation, deletion, 46 * and renaming of entries. Because of the dynamic nature of pathnames, 47 * names should not be saved, but always constructed just before they --- 32 unchanged lines hidden (view full) --- 80 81/* 82 * Look up an entry by inode number 83 */ 84struct entry * 85lookupino(inum) 86 ino_t inum; 87{ |
88 register struct entry *ep; | 88 struct entry *ep; |
89 90 if (inum < WINO || inum >= maxino) 91 return (NULL); 92 for (ep = entry[inum % entrytblsize]; ep != NULL; ep = ep->e_next) 93 if (ep->e_ino == inum) 94 return (ep); 95 return (NULL); 96} --- 22 unchanged lines hidden (view full) --- 119 120/* 121 * Delete an entry from the entry table 122 */ 123void 124deleteino(inum) 125 ino_t inum; 126{ | 89 90 if (inum < WINO || inum >= maxino) 91 return (NULL); 92 for (ep = entry[inum % entrytblsize]; ep != NULL; ep = ep->e_next) 93 if (ep->e_ino == inum) 94 return (ep); 95 return (NULL); 96} --- 22 unchanged lines hidden (view full) --- 119 120/* 121 * Delete an entry from the entry table 122 */ 123void 124deleteino(inum) 125 ino_t inum; 126{ |
127 register struct entry *next; | 127 struct entry *next; |
128 struct entry **prev; 129 130 if (inum < WINO || inum >= maxino) 131 panic("deleteino: out of range %d\n", inum); 132 prev = &entry[inum % entrytblsize]; 133 for (next = *prev; next != NULL; next = next->e_next) { 134 if (next->e_ino == inum) { 135 next->e_ino = 0; --- 7 unchanged lines hidden (view full) --- 143 144/* 145 * Look up an entry by name 146 */ 147struct entry * 148lookupname(name) 149 char *name; 150{ | 128 struct entry **prev; 129 130 if (inum < WINO || inum >= maxino) 131 panic("deleteino: out of range %d\n", inum); 132 prev = &entry[inum % entrytblsize]; 133 for (next = *prev; next != NULL; next = next->e_next) { 134 if (next->e_ino == inum) { 135 next->e_ino = 0; --- 7 unchanged lines hidden (view full) --- 143 144/* 145 * Look up an entry by name 146 */ 147struct entry * 148lookupname(name) 149 char *name; 150{ |
151 register struct entry *ep; 152 register char *np, *cp; | 151 struct entry *ep; 152 char *np, *cp; |
153 char buf[MAXPATHLEN]; 154 155 cp = name; 156 for (ep = lookupino(ROOTINO); ep != NULL; ep = ep->e_entries) { 157 for (np = buf; *cp != '/' && *cp != '\0' && 158 np < &buf[sizeof(buf)]; ) 159 *np++ = *cp++; 160 if (np == &buf[sizeof(buf)]) --- 33 unchanged lines hidden (view full) --- 194 return (ep); 195} 196 197/* 198 * Determine the current pathname of a node or leaf 199 */ 200char * 201myname(ep) | 153 char buf[MAXPATHLEN]; 154 155 cp = name; 156 for (ep = lookupino(ROOTINO); ep != NULL; ep = ep->e_entries) { 157 for (np = buf; *cp != '/' && *cp != '\0' && 158 np < &buf[sizeof(buf)]; ) 159 *np++ = *cp++; 160 if (np == &buf[sizeof(buf)]) --- 33 unchanged lines hidden (view full) --- 194 return (ep); 195} 196 197/* 198 * Determine the current pathname of a node or leaf 199 */ 200char * 201myname(ep) |
202 register struct entry *ep; | 202 struct entry *ep; |
203{ | 203{ |
204 register char *cp; | 204 char *cp; |
205 static char namebuf[MAXPATHLEN]; 206 207 for (cp = &namebuf[MAXPATHLEN - 2]; cp > &namebuf[ep->e_namlen]; ) { 208 cp -= ep->e_namlen; 209 memmove(cp, ep->e_name, (long)ep->e_namlen); 210 if (ep == lookupino(ROOTINO)) 211 return (cp); 212 *(--cp) = '/'; --- 13 unchanged lines hidden (view full) --- 226 * add an entry to the symbol table 227 */ 228struct entry * 229addentry(name, inum, type) 230 char *name; 231 ino_t inum; 232 int type; 233{ | 205 static char namebuf[MAXPATHLEN]; 206 207 for (cp = &namebuf[MAXPATHLEN - 2]; cp > &namebuf[ep->e_namlen]; ) { 208 cp -= ep->e_namlen; 209 memmove(cp, ep->e_name, (long)ep->e_namlen); 210 if (ep == lookupino(ROOTINO)) 211 return (cp); 212 *(--cp) = '/'; --- 13 unchanged lines hidden (view full) --- 226 * add an entry to the symbol table 227 */ 228struct entry * 229addentry(name, inum, type) 230 char *name; 231 ino_t inum; 232 int type; 233{ |
234 register struct entry *np, *ep; | 234 struct entry *np, *ep; |
235 236 if (freelist != NULL) { 237 np = freelist; 238 freelist = np->e_next; 239 memset(np, 0, (long)sizeof(struct entry)); 240 } else { 241 np = (struct entry *)calloc(1, sizeof(struct entry)); 242 if (np == NULL) --- 30 unchanged lines hidden (view full) --- 273 return (np); 274} 275 276/* 277 * delete an entry from the symbol table 278 */ 279void 280freeentry(ep) | 235 236 if (freelist != NULL) { 237 np = freelist; 238 freelist = np->e_next; 239 memset(np, 0, (long)sizeof(struct entry)); 240 } else { 241 np = (struct entry *)calloc(1, sizeof(struct entry)); 242 if (np == NULL) --- 30 unchanged lines hidden (view full) --- 273 return (np); 274} 275 276/* 277 * delete an entry from the symbol table 278 */ 279void 280freeentry(ep) |
281 register struct entry *ep; | 281 struct entry *ep; |
282{ | 282{ |
283 register struct entry *np; | 283 struct entry *np; |
284 ino_t inum; 285 286 if (ep->e_flags != REMOVED) 287 badentry(ep, "not marked REMOVED"); 288 if (ep->e_type == NODE) { 289 if (ep->e_links != NULL) 290 badentry(ep, "freeing referenced directory"); 291 if (ep->e_entries != NULL) --- 25 unchanged lines hidden (view full) --- 317 freelist = ep; 318} 319 320/* 321 * Relocate an entry in the tree structure 322 */ 323void 324moveentry(ep, newname) | 284 ino_t inum; 285 286 if (ep->e_flags != REMOVED) 287 badentry(ep, "not marked REMOVED"); 288 if (ep->e_type == NODE) { 289 if (ep->e_links != NULL) 290 badentry(ep, "freeing referenced directory"); 291 if (ep->e_entries != NULL) --- 25 unchanged lines hidden (view full) --- 317 freelist = ep; 318} 319 320/* 321 * Relocate an entry in the tree structure 322 */ 323void 324moveentry(ep, newname) |
325 register struct entry *ep; | 325 struct entry *ep; |
326 char *newname; 327{ 328 struct entry *np; 329 char *cp; 330 331 np = lookupparent(newname); 332 if (np == NULL) 333 badentry(ep, "cannot move ROOT"); --- 13 unchanged lines hidden (view full) --- 347 ep->e_flags &= ~TMPNAME; 348} 349 350/* 351 * Remove an entry in the tree structure 352 */ 353static void 354removeentry(ep) | 326 char *newname; 327{ 328 struct entry *np; 329 char *cp; 330 331 np = lookupparent(newname); 332 if (np == NULL) 333 badentry(ep, "cannot move ROOT"); --- 13 unchanged lines hidden (view full) --- 347 ep->e_flags &= ~TMPNAME; 348} 349 350/* 351 * Remove an entry in the tree structure 352 */ 353static void 354removeentry(ep) |
355 register struct entry *ep; | 355 struct entry *ep; |
356{ | 356{ |
357 register struct entry *np; | 357 struct entry *np; |
358 359 np = ep->e_parent; 360 if (np->e_entries == ep) { 361 np->e_entries = ep->e_sibling; 362 } else { 363 for (np = np->e_entries; np != NULL; np = np->e_sibling) { 364 if (np->e_sibling == ep) { 365 np->e_sibling = ep->e_sibling; --- 86 unchanged lines hidden (view full) --- 452/* 453 * dump a snapshot of the symbol table 454 */ 455void 456dumpsymtable(filename, checkpt) 457 char *filename; 458 long checkpt; 459{ | 358 359 np = ep->e_parent; 360 if (np->e_entries == ep) { 361 np->e_entries = ep->e_sibling; 362 } else { 363 for (np = np->e_entries; np != NULL; np = np->e_sibling) { 364 if (np->e_sibling == ep) { 365 np->e_sibling = ep->e_sibling; --- 86 unchanged lines hidden (view full) --- 452/* 453 * dump a snapshot of the symbol table 454 */ 455void 456dumpsymtable(filename, checkpt) 457 char *filename; 458 long checkpt; 459{ |
460 register struct entry *ep, *tep; 461 register ino_t i; | 460 struct entry *ep, *tep; 461 ino_t i; |
462 struct entry temp, *tentry; 463 long mynum = 1, stroff = 0; 464 FILE *fd; 465 struct symtableheader hdr; 466 467 vprintf(stdout, "Check pointing the restore\n"); 468 if (Nflag) 469 return; --- 71 unchanged lines hidden (view full) --- 541 * Initialize a symbol table from a file 542 */ 543void 544initsymtable(filename) 545 char *filename; 546{ 547 char *base; 548 long tblsize; | 462 struct entry temp, *tentry; 463 long mynum = 1, stroff = 0; 464 FILE *fd; 465 struct symtableheader hdr; 466 467 vprintf(stdout, "Check pointing the restore\n"); 468 if (Nflag) 469 return; --- 71 unchanged lines hidden (view full) --- 541 * Initialize a symbol table from a file 542 */ 543void 544initsymtable(filename) 545 char *filename; 546{ 547 char *base; 548 long tblsize; |
549 register struct entry *ep; | 549 struct entry *ep; |
550 struct entry *baseep, *lep; 551 struct symtableheader hdr; 552 struct stat stbuf; | 550 struct entry *baseep, *lep; 551 struct symtableheader hdr; 552 struct stat stbuf; |
553 register long i; | 553 long i; |
554 int fd; 555 556 vprintf(stdout, "Initialize symbol table.\n"); 557 if (filename == NULL) { 558 entrytblsize = maxino / HASHFACTOR; 559 entry = (struct entry **) 560 calloc((unsigned)entrytblsize, sizeof(struct entry *)); 561 if (entry == (struct entry **)NULL) --- 75 unchanged lines hidden --- | 554 int fd; 555 556 vprintf(stdout, "Initialize symbol table.\n"); 557 if (filename == NULL) { 558 entrytblsize = maxino / HASHFACTOR; 559 entry = (struct entry **) 560 calloc((unsigned)entrytblsize, sizeof(struct entry *)); 561 if (entry == (struct entry **)NULL) --- 75 unchanged lines hidden --- |