walk.c (185222) | walk.c (186256) |
---|---|
1/* $NetBSD: walk.c,v 1.17 2004/06/20 22:20:18 jmc Exp $ */ 2 3/* 4 * Copyright (c) 2001 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Luke Mewburn for Wasabi Systems, Inc. 8 * --- 78 unchanged lines hidden (view full) --- 87#include <fcntl.h> 88#include <stdio.h> 89#include <dirent.h> 90#include <stdlib.h> 91#include <string.h> 92#include <unistd.h> 93 94#include "makefs.h" | 1/* $NetBSD: walk.c,v 1.17 2004/06/20 22:20:18 jmc Exp $ */ 2 3/* 4 * Copyright (c) 2001 Wasabi Systems, Inc. 5 * All rights reserved. 6 * 7 * Written by Luke Mewburn for Wasabi Systems, Inc. 8 * --- 78 unchanged lines hidden (view full) --- 87#include <fcntl.h> 88#include <stdio.h> 89#include <dirent.h> 90#include <stdlib.h> 91#include <string.h> 92#include <unistd.h> 93 94#include "makefs.h" |
95 |
|
95#include "mtree.h" | 96#include "mtree.h" |
97#include "extern.h" /* NB: mtree */ |
|
96 97static void apply_specdir(const char *, NODE *, fsnode *); 98static void apply_specentry(const char *, NODE *, fsnode *); 99static fsnode *create_fsnode(const char *, struct stat *); 100static fsinode *link_check(fsinode *); 101 102 103/* --- 119 unchanged lines hidden (view full) --- 223 224 if (debug & DEBUG_APPLY_SPECFILE) 225 printf("apply_specfile: %s, %s %p\n", specfile, dir, parent); 226 227 /* read in the specfile */ 228 if ((fp = fopen(specfile, "r")) == NULL) 229 err(1, "Can't open `%s'", specfile); 230 TIMER_START(start); | 98 99static void apply_specdir(const char *, NODE *, fsnode *); 100static void apply_specentry(const char *, NODE *, fsnode *); 101static fsnode *create_fsnode(const char *, struct stat *); 102static fsinode *link_check(fsinode *); 103 104 105/* --- 119 unchanged lines hidden (view full) --- 225 226 if (debug & DEBUG_APPLY_SPECFILE) 227 printf("apply_specfile: %s, %s %p\n", specfile, dir, parent); 228 229 /* read in the specfile */ 230 if ((fp = fopen(specfile, "r")) == NULL) 231 err(1, "Can't open `%s'", specfile); 232 TIMER_START(start); |
231 root = spec(fp); | 233 root = mtree_readspec(fp); |
232 TIMER_RESULTS(start, "spec"); 233 if (fclose(fp) == EOF) 234 err(1, "Can't close `%s'", specfile); 235 236 /* perform some sanity checks */ 237 if (root == NULL) 238 errx(1, "Specfile `%s' did not contain a tree", specfile); 239 assert(strcmp(root->name, ".") == 0); 240 assert(root->type == F_DIR); 241 242 /* merge in the changes */ 243 apply_specdir(dir, root, parent); 244} 245 | 234 TIMER_RESULTS(start, "spec"); 235 if (fclose(fp) == EOF) 236 err(1, "Can't close `%s'", specfile); 237 238 /* perform some sanity checks */ 239 if (root == NULL) 240 errx(1, "Specfile `%s' did not contain a tree", specfile); 241 assert(strcmp(root->name, ".") == 0); 242 assert(root->type == F_DIR); 243 244 /* merge in the changes */ 245 apply_specdir(dir, root, parent); 246} 247 |
248static u_int 249nodetoino(u_int type) 250{ 251 252 switch (type) { 253 case F_BLOCK: 254 return S_IFBLK; 255 case F_CHAR: 256 return S_IFCHR; 257 case F_DIR: 258 return S_IFDIR; 259 case F_FIFO: 260 return S_IFIFO; 261 case F_FILE: 262 return S_IFREG; 263 case F_LINK: 264 return S_IFLNK; 265 case F_SOCK: 266 return S_IFSOCK; 267 default: 268 printf("unknown type %d", type); 269 abort(); 270 } 271 /* NOTREACHED */ 272} 273 |
|
246static void 247apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode) 248{ 249 char path[MAXPATHLEN + 1]; 250 NODE *curnode; 251 fsnode *curfsnode; 252 253 assert(specnode != NULL); --- 47 unchanged lines hidden (view full) --- 301 errx(1, "`%s': %s not provided", path, m) 302 NODETEST(curnode->flags & F_TYPE, "type"); 303 NODETEST(curnode->flags & F_MODE, "mode"); 304 /* XXX: require F_TIME ? */ 305 NODETEST(curnode->flags & F_GID || 306 curnode->flags & F_GNAME, "group"); 307 NODETEST(curnode->flags & F_UID || 308 curnode->flags & F_UNAME, "user"); | 274static void 275apply_specdir(const char *dir, NODE *specnode, fsnode *dirnode) 276{ 277 char path[MAXPATHLEN + 1]; 278 NODE *curnode; 279 fsnode *curfsnode; 280 281 assert(specnode != NULL); --- 47 unchanged lines hidden (view full) --- 329 errx(1, "`%s': %s not provided", path, m) 330 NODETEST(curnode->flags & F_TYPE, "type"); 331 NODETEST(curnode->flags & F_MODE, "mode"); 332 /* XXX: require F_TIME ? */ 333 NODETEST(curnode->flags & F_GID || 334 curnode->flags & F_GNAME, "group"); 335 NODETEST(curnode->flags & F_UID || 336 curnode->flags & F_UNAME, "user"); |
309 if (curnode->type == F_BLOCK || curnode->type == F_CHAR) 310 NODETEST(curnode->flags & F_DEV, 311 "device number"); | |
312#undef NODETEST 313 314 if (debug & DEBUG_APPLY_SPECFILE) 315 printf("apply_specdir: adding %s\n", 316 curnode->name); 317 /* build minimal fsnode */ 318 memset(&stbuf, 0, sizeof(stbuf)); 319 stbuf.st_mode = nodetoino(curnode->type); --- 100 unchanged lines hidden (view full) --- 420#if HAVE_STRUCT_STAT_ST_FLAGS 421 if (specnode->flags & F_FLAGS) { 422 ASEPRINT("flags", "%#lX", 423 (unsigned long)dirnode->inode->st.st_flags, 424 (unsigned long)specnode->st_flags); 425 dirnode->inode->st.st_flags = specnode->st_flags; 426 } 427#endif | 337#undef NODETEST 338 339 if (debug & DEBUG_APPLY_SPECFILE) 340 printf("apply_specdir: adding %s\n", 341 curnode->name); 342 /* build minimal fsnode */ 343 memset(&stbuf, 0, sizeof(stbuf)); 344 stbuf.st_mode = nodetoino(curnode->type); --- 100 unchanged lines hidden (view full) --- 445#if HAVE_STRUCT_STAT_ST_FLAGS 446 if (specnode->flags & F_FLAGS) { 447 ASEPRINT("flags", "%#lX", 448 (unsigned long)dirnode->inode->st.st_flags, 449 (unsigned long)specnode->st_flags); 450 dirnode->inode->st.st_flags = specnode->st_flags; 451 } 452#endif |
428 if (specnode->flags & F_DEV) { 429 ASEPRINT("rdev", "%#x", 430 dirnode->inode->st.st_rdev, specnode->st_rdev); 431 dirnode->inode->st.st_rdev = specnode->st_rdev; 432 } | |
433#undef ASEPRINT 434 435 dirnode->flags |= FSNODE_F_HASSPEC; 436} 437 438 439/* 440 * dump_fsnodes -- --- 33 unchanged lines hidden (view full) --- 474 } 475 printf("dump_fsnodes: finished %s\n", dir); 476} 477 478 479/* 480 * inode_type -- 481 * for a given inode type `mode', return a descriptive string. | 453#undef ASEPRINT 454 455 dirnode->flags |= FSNODE_F_HASSPEC; 456} 457 458 459/* 460 * dump_fsnodes -- --- 33 unchanged lines hidden (view full) --- 494 } 495 printf("dump_fsnodes: finished %s\n", dir); 496} 497 498 499/* 500 * inode_type -- 501 * for a given inode type `mode', return a descriptive string. |
482 * for most cases, uses inotype() from mtree/misc.c | |
483 */ 484const char * 485inode_type(mode_t mode) 486{ 487 | 502 */ 503const char * 504inode_type(mode_t mode) 505{ 506 |
507 if (S_ISREG(mode)) 508 return ("file"); |
|
488 if (S_ISLNK(mode)) | 509 if (S_ISLNK(mode)) |
489 return ("symlink"); /* inotype() returns "link"... */ 490 return (inotype(mode)); | 510 return ("symlink"); 511 if (S_ISDIR(mode)) 512 return ("dir"); 513 if (S_ISLNK(mode)) 514 return ("link"); 515 if (S_ISFIFO(mode)) 516 return ("fifo"); 517 if (S_ISSOCK(mode)) 518 return ("socket"); 519 /* XXX should not happen but handle them */ 520 if (S_ISCHR(mode)) 521 return ("char"); 522 if (S_ISBLK(mode)) 523 return ("block"); 524 return ("unknown"); |
491} 492 493 494/* 495 * link_check -- 496 * return pointer to fsnode matching `entry's st_ino & st_dev if it exists, 497 * otherwise add `entry' to table and return NULL 498 */ --- 42 unchanged lines hidden --- | 525} 526 527 528/* 529 * link_check -- 530 * return pointer to fsnode matching `entry's st_ino & st_dev if it exists, 531 * otherwise add `entry' to table and return NULL 532 */ --- 42 unchanged lines hidden --- |