2 * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
18 #define OWRT 0x4f575254
19 #define DATA 0x44415441
20 #define CONF 0x434f4e46
31 is_config(struct file_header *h)
33 return ((h->magic == OWRT) && (h->type == CONF));
37 valid_file_size(int fs)
39 if ((fs > 8 * 1024 * 1204) || (fs <= 0))
46 hdr_to_be32(struct file_header *hdr)
48 uint32_t *h = (uint32_t *) hdr;
51 for (i = 0; i < sizeof(struct file_header) / sizeof(uint32_t); i++)
52 h[i] = cpu_to_be32(h[i]);
56 be32_to_hdr(struct file_header *hdr)
58 uint32_t *h = (uint32_t *) hdr;
61 for (i = 0; i < sizeof(struct file_header) / sizeof(uint32_t); i++)
62 h[i] = be32_to_cpu(h[i]);
66 pad_file_size(struct volume *v, int size)
70 size += sizeof(struct file_header);
71 mod = size % v->block_size;
74 size += v->block_size;
80 int verify_file_hash(char *file, uint32_t *hash);
81 int snapshot_next_free(struct volume *v, uint32_t *seq);
82 int config_find(struct volume *v, struct file_header *conf, struct file_header *sentinel);
83 int snapshot_write_file(struct volume *v, int block, char *file, uint32_t seq, uint32_t type);
84 int snapshot_read_file(struct volume *v, int block, char *file, uint32_t type);
85 int sentinel_write(struct volume *v, uint32_t _seq);
86 int volatile_write(struct volume *v, uint32_t _seq);