Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Daisuke Nojiri | a5ae62e | 2015-11-03 15:04:59 -0800 | [diff] [blame] | 2 | |
| 3 | #ifndef __ARCHIVE_H |
| 4 | #define __ARCHIVE_H |
| 5 | |
| 6 | #include <stdint.h> |
| 7 | |
| 8 | /* |
| 9 | * Archive file layout: |
| 10 | * |
| 11 | * +----------------------------------+ |
| 12 | * | root header | |
| 13 | * +----------------------------------+ |
| 14 | * | file_header[0] | |
| 15 | * +----------------------------------+ |
| 16 | * | file_header[1] | |
| 17 | * +----------------------------------+ |
| 18 | * | ... | |
| 19 | * +----------------------------------+ |
| 20 | * | file_header[count-1] | |
| 21 | * +----------------------------------+ |
| 22 | * | file(0) content | |
| 23 | * +----------------------------------+ |
| 24 | * | file(1) content | |
| 25 | * +----------------------------------+ |
| 26 | * | ... | |
| 27 | * +----------------------------------+ |
| 28 | * | file(count-1) content | |
| 29 | * +----------------------------------+ |
| 30 | */ |
| 31 | |
| 32 | #define VERSION 0 |
| 33 | #define CBAR_MAGIC "CBAR" |
| 34 | #define NAME_LENGTH 32 |
| 35 | |
| 36 | /* Root header */ |
| 37 | struct directory { |
| 38 | char magic[4]; |
| 39 | uint32_t version; /* version of the header. little endian */ |
| 40 | uint32_t size; /* total size of archive. little endian */ |
| 41 | uint32_t count; /* number of files. little endian */ |
| 42 | }; |
| 43 | |
| 44 | /* File header */ |
| 45 | struct dentry { |
| 46 | /* file name. null-terminated if shorter than NAME_LENGTH */ |
| 47 | char name[NAME_LENGTH]; |
| 48 | /* file offset from the root header. little endian */ |
| 49 | uint32_t offset; |
| 50 | /* file size. little endian */ |
| 51 | uint32_t size; |
| 52 | }; |
| 53 | |
| 54 | static inline struct dentry *get_first_dentry(const struct directory *dir) |
| 55 | { |
| 56 | return (struct dentry *)(dir + 1); |
| 57 | } |
| 58 | |
| 59 | static inline uint32_t get_first_offset(const struct directory *dir) |
| 60 | { |
| 61 | return sizeof(struct directory) + sizeof(struct dentry) * dir->count; |
| 62 | } |
| 63 | |
| 64 | #endif |