From: Duy Nguyen Date: Tue, 20 Aug 2013 14:16:41 GMT Subject: Re: [PATCH v3 15/24] read-cache: read index-v5 Message-ID: In-Reply-To: <1376854933-31241-16-git-send-email-t.gummerer@gmail.com> On Mon, Aug 19, 2013 at 2:42 AM, Thomas Gummerer wrote: > +static int read_entry(struct cache_entry **ce, char *pathname, size_t pathlen, > + void *mmap, unsigned long mmap_size, > + unsigned int first_entry_offset, > + unsigned int foffsetblock) > +{ > + int len, offset_to_offset; > + char *name; > + uint32_t foffsetblockcrc, *filecrc, *beginning, *end, entry_offset; > + struct ondisk_cache_entry *disk_ce; > + > + beginning = ptr_add(mmap, foffsetblock); > + end = ptr_add(mmap, foffsetblock + 4); > + len = ntoh_l(*end) - ntoh_l(*beginning) - sizeof(struct ondisk_cache_entry) - 5; > + entry_offset = first_entry_offset + ntoh_l(*beginning); > + name = ptr_add(mmap, entry_offset); > + disk_ce = ptr_add(mmap, entry_offset + len + 1); > + *ce = cache_entry_from_ondisk(disk_ce, pathname, name, len, pathlen); > + filecrc = ptr_add(mmap, entry_offset + len + 1 + sizeof(*disk_ce)); > + offset_to_offset = htonl(foffsetblock); > + foffsetblockcrc = crc32(0, (Bytef*)&offset_to_offset, 4); > + if (!check_crc32(foffsetblockcrc, > + ptr_add(mmap, entry_offset), len + 1 + sizeof(*disk_ce), > + ntoh_l(*filecrc))) > + return -1; > + > + return 0; > +} Last thought before book+bed time. I wonder if moving the name part to the end of the entry (i.e. chaging on disk format) would simplify this code. The new ondisk_cache_entry would be something like this struct ondisk_cache_entry { uint16_t flags; uint16_t mode; struct cache_time mtime; uint32_t size; int stat_crc; unsigned char sha1[20]; char name[FLEX_ARRAY]; }; -- Duy