nvram.c (160892) | nvram.c (239733) |
---|---|
1/* 2 * Copyright (c) 2006 Maxim Sobolev <sobomax@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 22 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 23 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * POSSIBILITY OF SUCH DAMAGE. 25 * | 1/* 2 * Copyright (c) 2006 Maxim Sobolev <sobomax@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 18 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 22 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 23 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * POSSIBILITY OF SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/usr.sbin/nvram/nvram.c 160892 2006-08-01 22:19:01Z sobomax $ | 26 * $FreeBSD: head/usr.sbin/nvram/nvram.c 239733 2012-08-27 14:51:26Z rdivacky $ |
27 */ 28 29#include <sys/types.h> 30#include <sys/uio.h> 31#include <err.h> 32#include <errno.h> 33#include <fcntl.h> 34#include <paths.h> --- 11 unchanged lines hidden (view full) --- 46static int append_var(uint8_t *, int, const char *, const char *); 47 48struct deletelist { 49 char *name; 50 struct deletelist *next; 51 struct deletelist *last; 52}; 53 | 27 */ 28 29#include <sys/types.h> 30#include <sys/uio.h> 31#include <err.h> 32#include <errno.h> 33#include <fcntl.h> 34#include <paths.h> --- 11 unchanged lines hidden (view full) --- 46static int append_var(uint8_t *, int, const char *, const char *); 47 48struct deletelist { 49 char *name; 50 struct deletelist *next; 51 struct deletelist *last; 52}; 53 |
54union { 55 uint8_t buf[sizeof(struct chrp_header)]; 56 struct chrp_header header; 57} conv; 58 |
|
54int 55main(int argc, char **argv) 56{ 57 int opt, dump, fd, res, i, size; 58 uint8_t buf[NVRAM_SIZE], *cp, *common; | 59int 60main(int argc, char **argv) 61{ 62 int opt, dump, fd, res, i, size; 63 uint8_t buf[NVRAM_SIZE], *cp, *common; |
59 struct chrp_header *header; | |
60 struct deletelist *dl; 61 62 dump = 0; 63 dl = NULL; 64 65 while((opt = getopt(argc, argv, "d:p")) != -1) { 66 switch(opt) { 67 case 'p': --- 43 unchanged lines hidden (view full) --- 111 i += res; 112 } 113 if (i != sizeof(buf)) 114 errx(1, "%s: short read", DEVICE_NAME); 115 116 /* Locate common block */ 117 size = 0; 118 for (cp = buf; cp < buf + sizeof(buf); cp += size) { | 64 struct deletelist *dl; 65 66 dump = 0; 67 dl = NULL; 68 69 while((opt = getopt(argc, argv, "d:p")) != -1) { 70 switch(opt) { 71 case 'p': --- 43 unchanged lines hidden (view full) --- 115 i += res; 116 } 117 if (i != sizeof(buf)) 118 errx(1, "%s: short read", DEVICE_NAME); 119 120 /* Locate common block */ 121 size = 0; 122 for (cp = buf; cp < buf + sizeof(buf); cp += size) { |
119 header = (struct chrp_header *)cp; 120 size = header->length * 0x10; 121 if (strncmp(header->name, "common", 7) == 0) | 123 memcpy(conv.buf, cp, sizeof(struct chrp_header)); 124 size = conv.header.length * 0x10; 125 if (strncmp(conv.header.name, "common", 7) == 0) |
122 break; 123 } 124 if (cp >= buf + sizeof(buf) || size <= (int)sizeof(struct chrp_header)) 125 errx(1, "%s: no common block", DEVICE_NAME); 126 common = cp + sizeof(struct chrp_header); 127 size -= sizeof(struct chrp_header); 128 129 if (dump != 0) { --- 93 unchanged lines hidden --- | 126 break; 127 } 128 if (cp >= buf + sizeof(buf) || size <= (int)sizeof(struct chrp_header)) 129 errx(1, "%s: no common block", DEVICE_NAME); 130 common = cp + sizeof(struct chrp_header); 131 size -= sizeof(struct chrp_header); 132 133 if (dump != 0) { --- 93 unchanged lines hidden --- |