du.c (128772) | du.c (128806) |
---|---|
1/* 2 * Copyright (c) 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Chris Newcomb. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 32 unchanged lines hidden (view full) --- 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static const char sccsid[] = "@(#)du.c 8.5 (Berkeley) 5/4/95"; 46#endif 47#endif /* not lint */ 48#include <sys/cdefs.h> | 1/* 2 * Copyright (c) 1989, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Chris Newcomb. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 32 unchanged lines hidden (view full) --- 41#endif /* not lint */ 42 43#ifndef lint 44#if 0 45static const char sccsid[] = "@(#)du.c 8.5 (Berkeley) 5/4/95"; 46#endif 47#endif /* not lint */ 48#include <sys/cdefs.h> |
49__FBSDID("$FreeBSD: head/usr.bin/du/du.c 128772 2004-04-30 18:17:51Z kientzle $"); | 49__FBSDID("$FreeBSD: head/usr.bin/du/du.c 128806 2004-05-01 21:47:31Z kientzle $"); |
50 51#include <sys/param.h> 52#include <sys/queue.h> 53#include <sys/stat.h> 54 55#include <err.h> 56#include <errno.h> 57#include <fnmatch.h> --- 247 unchanged lines hidden (view full) --- 305 306 ignoreclean(); 307 exit(rval); 308} 309 310static int 311linkchk(FTSENT *p) 312{ | 50 51#include <sys/param.h> 52#include <sys/queue.h> 53#include <sys/stat.h> 54 55#include <err.h> 56#include <errno.h> 57#include <fnmatch.h> --- 247 unchanged lines hidden (view full) --- 305 306 ignoreclean(); 307 exit(rval); 308} 309 310static int 311linkchk(FTSENT *p) 312{ |
313 static const size_t links_hash_initial_size = 8192; | |
314 struct links_entry { | 313 struct links_entry { |
315 struct links_entry *next; 316 struct links_entry *previous; 317 int links; 318 dev_t dev; 319 ino_t ino; | 314 struct links_entry *next; 315 struct links_entry *previous; 316 int links; 317 dev_t dev; 318 ino_t ino; |
320 }; | 319 }; |
321 static unsigned long number_entries; 322 static size_t number_buckets; 323 static struct links_entry **buckets; 324 static struct links_entry *free_list; 325 static char stop_allocating; | 320 static const size_t links_hash_initial_size = 8192; 321 static struct links_entry **buckets; 322 static struct links_entry *free_list; 323 static size_t number_buckets; 324 static unsigned long number_entries; 325 static char stop_allocating; 326 struct links_entry *le, **new_buckets; 327 struct stat *st; 328 size_t i, new_size; 329 int count; 330 int hash; |
326 | 331 |
327 struct links_entry *le, **new_buckets; 328 struct stat *st; 329 int hash; 330 size_t i, new_size; 331 | |
332 st = p->fts_statp; 333 334 /* If necessary, initialize the hash table. */ 335 if (buckets == NULL) { 336 number_buckets = links_hash_initial_size; 337 buckets = malloc(number_buckets * sizeof(buckets[0])); 338 if (buckets == NULL) | 332 st = p->fts_statp; 333 334 /* If necessary, initialize the hash table. */ 335 if (buckets == NULL) { 336 number_buckets = links_hash_initial_size; 337 buckets = malloc(number_buckets * sizeof(buckets[0])); 338 if (buckets == NULL) |
339 err(1, "No memory for hardlink detection."); | 339 errx(1, "No memory for hardlink detection."); |
340 for (i = 0; i < number_buckets; i++) 341 buckets[i] = NULL; 342 } 343 344 /* If the hash table is getting too full, enlarge it. */ 345 if (number_entries > number_buckets * 10 && !stop_allocating) { | 340 for (i = 0; i < number_buckets; i++) 341 buckets[i] = NULL; 342 } 343 344 /* If the hash table is getting too full, enlarge it. */ 345 if (number_entries > number_buckets * 10 && !stop_allocating) { |
346 int count; | |
347 348 new_size = number_buckets * 2; 349 new_buckets = malloc(new_size * sizeof(struct links_entry *)); 350 count = 0; 351 352 /* Try releasing the free list to see if that helps. */ 353 if (new_buckets == NULL && free_list != NULL) { 354 while (free_list != NULL) { 355 le = free_list; 356 free_list = le->next; 357 free(le); 358 } 359 new_buckets = malloc(new_size * sizeof(new_buckets[0])); 360 } 361 362 if (new_buckets == NULL) { 363 stop_allocating = 1; | 346 347 new_size = number_buckets * 2; 348 new_buckets = malloc(new_size * sizeof(struct links_entry *)); 349 count = 0; 350 351 /* Try releasing the free list to see if that helps. */ 352 if (new_buckets == NULL && free_list != NULL) { 353 while (free_list != NULL) { 354 le = free_list; 355 free_list = le->next; 356 free(le); 357 } 358 new_buckets = malloc(new_size * sizeof(new_buckets[0])); 359 } 360 361 if (new_buckets == NULL) { 362 stop_allocating = 1; |
364 warnc(ENOMEM, "No more memory for recording " 365 "hard links; Remaining hard links will be " 366 "counted as separate files."); | 363 warnx("No more memory for tracking hard links."); |
367 } else { 368 memset(new_buckets, 0, 369 new_size * sizeof(struct links_entry *)); 370 for (i = 0; i < number_buckets; i++) { 371 while (buckets[i] != NULL) { 372 /* Remove entry from old bucket. */ 373 le = buckets[i]; 374 buckets[i] = le->next; --- 51 unchanged lines hidden (view full) --- 426 /* Pull a node from the free list if we can. */ 427 le = free_list; 428 free_list = le->next; 429 } else 430 /* Malloc one if we have to. */ 431 le = malloc(sizeof(struct links_entry)); 432 if (le == NULL) { 433 stop_allocating = 1; | 364 } else { 365 memset(new_buckets, 0, 366 new_size * sizeof(struct links_entry *)); 367 for (i = 0; i < number_buckets; i++) { 368 while (buckets[i] != NULL) { 369 /* Remove entry from old bucket. */ 370 le = buckets[i]; 371 buckets[i] = le->next; --- 51 unchanged lines hidden (view full) --- 423 /* Pull a node from the free list if we can. */ 424 le = free_list; 425 free_list = le->next; 426 } else 427 /* Malloc one if we have to. */ 428 le = malloc(sizeof(struct links_entry)); 429 if (le == NULL) { 430 stop_allocating = 1; |
434 warnc(ENOMEM, "No more memory for recording " 435 "hard links; Remaining hard links will be counted " 436 "as separate files."); | 431 warnx("No more memory for tracking hard links."); |
437 return (0); 438 } 439 le->dev = st->st_dev; 440 le->ino = st->st_ino; 441 le->links = st->st_nlink - 1; 442 number_entries++; 443 le->next = buckets[hash]; 444 le->previous = NULL; --- 94 unchanged lines hidden --- | 432 return (0); 433 } 434 le->dev = st->st_dev; 435 le->ino = st->st_ino; 436 le->links = st->st_nlink - 1; 437 number_entries++; 438 le->next = buckets[hash]; 439 le->previous = NULL; --- 94 unchanged lines hidden --- |