listview.c revision 19e8adccba16ff419f5675b1575358c2956dce83
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov/* Copyright (c) 2007-2008 Dovecot authors, see the included COPYING file */
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashovstatic struct mailbox_list_index_header hdr;
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashovstatic uint32_t mail_index_offset_to_uint32(uint32_t offset)
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov const unsigned char *buf = (const unsigned char *) &offset;
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov return (((uint32_t)buf[3] & 0x7f) << 2) |
c46dec3dfad9e83321cc9d3185d93f0e8c38f57eLukas Slebodnik i_fatal("file hdr read() %d != %ld\n", ret, sizeof(hdr));
c46dec3dfad9e83321cc9d3185d93f0e8c38f57eLukas Slebodnik printf("version = %u.%u\n", hdr.major_version, hdr.minor_version);
c46dec3dfad9e83321cc9d3185d93f0e8c38f57eLukas Slebodnik printf("header size = %u\n", hdr.header_size);
c46dec3dfad9e83321cc9d3185d93f0e8c38f57eLukas Slebodnik printf("uid validity = %u\n", hdr.uid_validity);
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov printf("used space = %u\n", hdr.used_space);
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov printf("deleted space = %u\n", hdr.deleted_space);
e1711a2b2cb904f7edc26cc68566e064896d4f8aLukas Slebodnikstatic void dump_dir(int fd, unsigned int show_offset, const char *path)
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov unsigned int i;
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov i_fatal("unexpected EOF when reading dir");
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov i_fatal("dir read() %d != %ld", ret, sizeof(dir));
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov dir.next_offset = mail_index_offset_to_uint32(dir.next_offset);
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov printf("%s: DIR: offset=%"PRIuUOFF_T" next_offset=%u count=%u dir_size=%u\n",
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov path, offset, dir.next_offset, dir.count, dir.dir_size);
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov if (dir.next_offset != 0 && dir.next_offset != show_offset) {
efdcf49660505e13607b99ba82eb504cf37b8794Nikolai Kondrashov i_fatal("unexpected EOF, %d/%d records", i, dir.count);
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov i_fatal("rec read() %d != %ld", ret, sizeof(rec));
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov rec.dir_offset = mail_index_offset_to_uint32(rec.dir_offset);
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov ret = pread(fd, name, sizeof(name)-1, rec.name_offset);
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov printf("%s%s: offset=%"PRIuUOFF_T" uid=%u "
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov "name_offset=%u name_hash=%u", path, name, offset,
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov rec.uid, rec.name_offset, rec.name_hash);
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov printf(" dir_offset=%u", rec.dir_offset);
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov printf("%s%s: - invalid name_offset", path, name);
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov printf("%s%s: - name missing NUL terminator",
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov printf("%s%s: - invalid name hash %u vs %u\n",
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov path, name, crc32_str(name), rec.name_hash);
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov new_path = t_strdup_printf("%s%s/", path, name);
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashovint main(int argc ATTR_UNUSED, const char *argv[])
9d453f1e8b28983b363b44c49b7cd701a994fd97Nikolai Kondrashov dump_dir(fd, argv[2] == NULL ? 0 : atoi(argv[2]), "");