Skip to content

Commit 35a730f

Browse files
author
Junio C Hamano
committed
fsck-objects: support platforms without d_ino in struct dirent.
The d_ino field is only used for performance reasons in fsck-objects. On a typical filesystem, i-number tends to have a strong correlation with where the actual bits sit on the disk platter, and we sort the entries to allow us scan things that ought to be close together together. If the platform lacks support for it, it is not a big deal. Just do not use d_ino for sorting, and scan them unsorted. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent bdc37f5 commit 35a730f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ all:
1919
# Define NO_EXPAT if you do not have expat installed. git-http-push is
2020
# not built, and you cannot push using http:// and https:// transports.
2121
#
22+
# Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent.
23+
#
2224
# Define NO_STRCASESTR if you don't have strcasestr.
2325
#
2426
# Define NO_SETENV if you don't have setenv in the C library.
@@ -234,6 +236,7 @@ ifeq ($(uname_S),SunOS)
234236
ALL_CFLAGS += -D__EXTENSIONS__
235237
endif
236238
ifeq ($(uname_O),Cygwin)
239+
NO_D_INO_IN_DIRENT = YesPlease
237240
NO_STRCASESTR = YesPlease
238241
NEEDS_LIBICONV = YesPlease
239242
# There are conflicting reports about this.
@@ -334,6 +337,9 @@ ifdef NEEDS_NSL
334337
LIBS += -lnsl
335338
SIMPLE_LIB += -lnsl
336339
endif
340+
ifdef NO_D_INO_IN_DIRENT
341+
ALL_CFLAGS += -DNO_D_INO_IN_DIRENT
342+
endif
337343
ifdef NO_STRCASESTR
338344
COMPAT_CFLAGS += -DNO_STRCASESTR
339345
COMPAT_OBJS += compat/strcasestr.o

fsck-objects.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ static int check_strict = 0;
2020
static int keep_cache_objects = 0;
2121
static unsigned char head_sha1[20];
2222

23+
#if NO_D_INO_IN_DIRENT
24+
#define SORT_DIRENT 0
25+
#define DIRENT_SORT_HINT(de) 0
26+
#else
27+
#define SORT_DIRENT 1
28+
#define DIRENT_SORT_HINT(de) ((de)->d_ino)
29+
#endif
2330

2431
static void objreport(struct object *obj, const char *severity,
2532
const char *err, va_list params)
@@ -307,7 +314,9 @@ static void fsck_sha1_list(void)
307314
{
308315
int i, nr = sha1_list.nr;
309316

310-
qsort(sha1_list.entry, nr, sizeof(struct sha1_entry *), ino_compare);
317+
if (SORT_DIRENT)
318+
qsort(sha1_list.entry, nr,
319+
sizeof(struct sha1_entry *), ino_compare);
311320
for (i = 0; i < nr; i++) {
312321
struct sha1_entry *entry = sha1_list.entry[i];
313322
unsigned char *sha1 = entry->sha1;
@@ -361,7 +370,7 @@ static int fsck_dir(int i, char *path)
361370
memcpy(name+2, de->d_name, len+1);
362371
if (get_sha1_hex(name, sha1) < 0)
363372
break;
364-
add_sha1_list(sha1, de->d_ino);
373+
add_sha1_list(sha1, DIRENT_SORT_HINT(de));
365374
continue;
366375
}
367376
fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);

0 commit comments

Comments
 (0)