1 /* 2 * Copyright (C) 2014 John Crispin <blogic@openwrt.org> 3 * 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 7 * 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. 12 */ 13 14 #ifndef _SNAPSHOT_H__ 15 #define _SNAPSHOT_H__ 16 17 #define OWRT 0x4f575254 18 #define DATA 0x44415441 19 #define CONF 0x434f4e46 20 21 struct file_header { 22 uint32_t magic; 23 uint32_t type; 24 uint32_t seq; 25 uint32_t length; 26 uint32_t md5[4]; 27 }; 28 29 static inline int 30 is_config(struct file_header *h) 31 { 32 return ((h->magic == OWRT) && (h->type == CONF)); 33 } 34 35 static inline int 36 valid_file_size(int fs) 37 { 38 if ((fs > 8 * 1024 * 1204) || (fs <= 0)) 39 return -1; 40 41 return 0; 42 } 43 44 static inline void 45 hdr_to_be32(struct file_header *hdr) 46 { 47 uint32_t *h = (uint32_t *) hdr; 48 int i; 49 50 for (i = 0; i < sizeof(struct file_header) / sizeof(uint32_t); i++) 51 h[i] = cpu_to_be32(h[i]); 52 } 53 54 static inline void 55 be32_to_hdr(struct file_header *hdr) 56 { 57 uint32_t *h = (uint32_t *) hdr; 58 int i; 59 60 for (i = 0; i < sizeof(struct file_header) / sizeof(uint32_t); i++) 61 h[i] = be32_to_cpu(h[i]); 62 } 63 64 static inline int 65 pad_file_size(struct volume *v, int size) 66 { 67 int mod; 68 69 size += sizeof(struct file_header); 70 mod = size % v->block_size; 71 if (mod) { 72 size -= mod; 73 size += v->block_size; 74 } 75 76 return size; 77 } 78 79 int verify_file_hash(char *file, uint32_t *hash); 80 int snapshot_next_free(struct volume *v, uint32_t *seq); 81 int config_find(struct volume *v, struct file_header *conf, struct file_header *sentinel); 82 int snapshot_write_file(struct volume *v, int block, char *file, uint32_t seq, uint32_t type); 83 int snapshot_read_file(struct volume *v, int block, char *file, uint32_t type); 84 int sentinel_write(struct volume *v, uint32_t _seq); 85 int volatile_write(struct volume *v, uint32_t _seq); 86 87 #endif 88
This page was automatically generated by LXR 0.3.1. • OpenWrt