diff -ur preload-0.4/src/readahead.c preload-0.4.new/src/readahead.c --- preload-0.4/src/readahead.c 2005-10-07 17:08:47.000000000 +0300 +++ preload-0.4.new/src/readahead.c 2006-09-29 09:10:50.000000000 +0300 @@ -25,24 +25,53 @@ #include "log.h" #include "conf.h" +#include +#include -/* Compare files by path. */ -static int -map_path_compare (const preload_map_t **pa, const preload_map_t **pb) + +static void +stat_file (preload_map_t *file) { - const preload_map_t *a = *pa, *b = *pb; - int i; + int fd; + struct stat buf; + + fd = open(file->path, O_RDONLY); + if (fd < 0) + return; - i = strcmp(a->path, a->path); - if (!i) /* same file */ - i = a->offset - b->offset; - if (!i) /* same offset?! */ - i = b->length - a->length; + if (fstat(fd, &buf) == 0) { + file->dev = buf.st_dev; + file->ino = buf.st_ino; + + file->block = 0; + ioctl(fd, FIBMAP, &(file->block)); + } - return i; + close(fd); } +static int +map_file_compare (const preload_map_t **pa, const preload_map_t **pb) +{ + const preload_map_t *a = *pa, *b = *pb; + + if (a->dev < b->dev) + return -1; + if (a->dev > b->dev) + return 1; + if (a->block < b->block) + return -1; + if (a->block > b->block) + return 1; + if (a->ino < b->ino) + return -1; + if (a->ino > b->ino) + return 1; + + return 0; +} + static void process_file(preload_map_t *file) @@ -63,8 +92,10 @@ { int i; - /* Sorting by path should offer least directory block seeking. */ - qsort(files, file_count, sizeof(*files), (GCompareFunc)map_path_compare); + for (i=0; ilength = length; map->refcount = 0; map->update_time = state->time; + + map->dev = 0; + map->ino = 0; + map->block = 0; return map; } diff -ur preload-0.4/src/state.h preload-0.4.new/src/state.h --- preload-0.4/src/state.h 2005-10-07 17:10:14.000000000 +0300 +++ preload-0.4.new/src/state.h 2006-09-29 08:56:19.000000000 +0300 @@ -17,6 +17,11 @@ double lnprob; /* log-probability of NOT being needed in next period. */ int seq; /* unique map sequence number. */ int priv; /* for private local use of functions. */ + + /* stat: */ + dev_t dev; /* ID of device containing file */ + ino_t ino; /* inode number */ + int block; /* block number */ } preload_map_t;