diff options
| author | Matt Kraai <kraai@debian.org> | 2001-12-17 15:26:36 +0000 |
|---|---|---|
| committer | Matt Kraai <kraai@debian.org> | 2001-12-17 15:26:36 +0000 |
| commit | ace02dc9cd3ca0c95db5b5ebe87b9d6cd6ca1733 (patch) | |
| tree | 1dec04901febc0fd63ac5b92bc2cca4333689477 /coreutils | |
| parent | 46ea0e4696456061ad7ce799658f737c24f781a6 (diff) | |
| download | busybox-w32-ace02dc9cd3ca0c95db5b5ebe87b9d6cd6ca1733.tar.gz busybox-w32-ace02dc9cd3ca0c95db5b5ebe87b9d6cd6ca1733.tar.bz2 busybox-w32-ace02dc9cd3ca0c95db5b5ebe87b9d6cd6ca1733.zip | |
Make cp and mv optionally preserve hard links.
Diffstat (limited to 'coreutils')
| -rw-r--r-- | coreutils/du.c | 74 |
1 files changed, 1 insertions, 73 deletions
diff --git a/coreutils/du.c b/coreutils/du.c index c378837d0..e34a7f46f 100644 --- a/coreutils/du.c +++ b/coreutils/du.c | |||
| @@ -59,78 +59,6 @@ static void print_summary(long size, char *filename) | |||
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | #define HASH_SIZE 311 /* Should be prime */ | ||
| 63 | #define hash_inode(i) ((i) % HASH_SIZE) | ||
| 64 | |||
| 65 | typedef struct ino_dev_hash_bucket_struct { | ||
| 66 | struct ino_dev_hash_bucket_struct *next; | ||
| 67 | ino_t ino; | ||
| 68 | dev_t dev; | ||
| 69 | char name[1]; | ||
| 70 | } ino_dev_hashtable_bucket_t; | ||
| 71 | |||
| 72 | static ino_dev_hashtable_bucket_t *ino_dev_hashtable[HASH_SIZE]; | ||
| 73 | |||
| 74 | /* | ||
| 75 | * Return 1 if statbuf->st_ino && statbuf->st_dev are recorded in | ||
| 76 | * `ino_dev_hashtable', else return 0 | ||
| 77 | * | ||
| 78 | * If NAME is a non-NULL pointer to a character pointer, and there is | ||
| 79 | * a match, then set *NAME to the value of the name slot in that | ||
| 80 | * bucket. | ||
| 81 | */ | ||
| 82 | static int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name) | ||
| 83 | { | ||
| 84 | ino_dev_hashtable_bucket_t *bucket; | ||
| 85 | |||
| 86 | bucket = ino_dev_hashtable[hash_inode(statbuf->st_ino)]; | ||
| 87 | while (bucket != NULL) { | ||
| 88 | if ((bucket->ino == statbuf->st_ino) && | ||
| 89 | (bucket->dev == statbuf->st_dev)) | ||
| 90 | { | ||
| 91 | if (name) *name = bucket->name; | ||
| 92 | return 1; | ||
| 93 | } | ||
| 94 | bucket = bucket->next; | ||
| 95 | } | ||
| 96 | return 0; | ||
| 97 | } | ||
| 98 | |||
| 99 | /* Add statbuf to statbuf hash table */ | ||
| 100 | static void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name) | ||
| 101 | { | ||
| 102 | int i; | ||
| 103 | size_t s; | ||
| 104 | ino_dev_hashtable_bucket_t *bucket; | ||
| 105 | |||
| 106 | i = hash_inode(statbuf->st_ino); | ||
| 107 | s = name ? strlen(name) : 0; | ||
| 108 | bucket = xmalloc(sizeof(ino_dev_hashtable_bucket_t) + s); | ||
| 109 | bucket->ino = statbuf->st_ino; | ||
| 110 | bucket->dev = statbuf->st_dev; | ||
| 111 | if (name) | ||
| 112 | strcpy(bucket->name, name); | ||
| 113 | else | ||
| 114 | bucket->name[0] = '\0'; | ||
| 115 | bucket->next = ino_dev_hashtable[i]; | ||
| 116 | ino_dev_hashtable[i] = bucket; | ||
| 117 | } | ||
| 118 | |||
| 119 | /* Clear statbuf hash table */ | ||
| 120 | static void reset_ino_dev_hashtable(void) | ||
| 121 | { | ||
| 122 | int i; | ||
| 123 | ino_dev_hashtable_bucket_t *bucket; | ||
| 124 | |||
| 125 | for (i = 0; i < HASH_SIZE; i++) { | ||
| 126 | while (ino_dev_hashtable[i] != NULL) { | ||
| 127 | bucket = ino_dev_hashtable[i]->next; | ||
| 128 | free(ino_dev_hashtable[i]); | ||
| 129 | ino_dev_hashtable[i] = bucket; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | /* tiny recursive du */ | 62 | /* tiny recursive du */ |
| 135 | static long du(char *filename) | 63 | static long du(char *filename) |
| 136 | { | 64 | { |
| @@ -246,7 +174,7 @@ int du_main(int argc, char **argv) | |||
| 246 | return status; | 174 | return status; |
| 247 | } | 175 | } |
| 248 | 176 | ||
| 249 | /* $Id: du.c,v 1.51 2001/10/24 04:59:27 andersen Exp $ */ | 177 | /* $Id: du.c,v 1.52 2001/12/17 15:26:25 kraai Exp $ */ |
| 250 | /* | 178 | /* |
| 251 | Local Variables: | 179 | Local Variables: |
| 252 | c-file-style: "linux" | 180 | c-file-style: "linux" |
