Daisuke Nojiri | a5ae62e | 2015-11-03 15:04:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The ChromiumOS Authors. All rights reserved. |
| 3 | * written by Daisuke Nojiri <dnojiri@chromium.org> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #ifndef __ARCHIVE_H |
| 16 | #define __ARCHIVE_H |
| 17 | |
| 18 | #include <stdint.h> |
| 19 | |
| 20 | /* |
| 21 | * Archive file layout: |
| 22 | * |
| 23 | * +----------------------------------+ |
| 24 | * | root header | |
| 25 | * +----------------------------------+ |
| 26 | * | file_header[0] | |
| 27 | * +----------------------------------+ |
| 28 | * | file_header[1] | |
| 29 | * +----------------------------------+ |
| 30 | * | ... | |
| 31 | * +----------------------------------+ |
| 32 | * | file_header[count-1] | |
| 33 | * +----------------------------------+ |
| 34 | * | file(0) content | |
| 35 | * +----------------------------------+ |
| 36 | * | file(1) content | |
| 37 | * +----------------------------------+ |
| 38 | * | ... | |
| 39 | * +----------------------------------+ |
| 40 | * | file(count-1) content | |
| 41 | * +----------------------------------+ |
| 42 | */ |
| 43 | |
| 44 | #define VERSION 0 |
| 45 | #define CBAR_MAGIC "CBAR" |
| 46 | #define NAME_LENGTH 32 |
| 47 | |
| 48 | /* Root header */ |
| 49 | struct directory { |
| 50 | char magic[4]; |
| 51 | uint32_t version; /* version of the header. little endian */ |
| 52 | uint32_t size; /* total size of archive. little endian */ |
| 53 | uint32_t count; /* number of files. little endian */ |
| 54 | }; |
| 55 | |
| 56 | /* File header */ |
| 57 | struct dentry { |
| 58 | /* file name. null-terminated if shorter than NAME_LENGTH */ |
| 59 | char name[NAME_LENGTH]; |
| 60 | /* file offset from the root header. little endian */ |
| 61 | uint32_t offset; |
| 62 | /* file size. little endian */ |
| 63 | uint32_t size; |
| 64 | }; |
| 65 | |
| 66 | static inline struct dentry *get_first_dentry(const struct directory *dir) |
| 67 | { |
| 68 | return (struct dentry *)(dir + 1); |
| 69 | } |
| 70 | |
| 71 | static inline uint32_t get_first_offset(const struct directory *dir) |
| 72 | { |
| 73 | return sizeof(struct directory) + sizeof(struct dentry) * dir->count; |
| 74 | } |
| 75 | |
| 76 | #endif |