image.c (268236) | image.c (268646) |
---|---|
1/*- 2 * Copyright (c) 2014 Juniper Networks, Inc. 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 --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2014 Juniper Networks, Inc. 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 --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: head/usr.bin/mkimg/image.c 268236 2014-07-03 20:31:43Z marcel $"); | 28__FBSDID("$FreeBSD: head/usr.bin/mkimg/image.c 268646 2014-07-15 04:39:23Z marcel $"); |
29 30#include <sys/types.h> 31#include <assert.h> 32#include <errno.h> 33#include <limits.h> 34#include <paths.h> 35#include <stdio.h> 36#include <stdlib.h> --- 52 unchanged lines hidden (view full) --- 89 if (sizep != NULL) 90 *sizep = bytesize; 91 return (error); 92} 93 94int 95image_copyout(int fd) 96{ | 29 30#include <sys/types.h> 31#include <assert.h> 32#include <errno.h> 33#include <limits.h> 34#include <paths.h> 35#include <stdio.h> 36#include <stdlib.h> --- 52 unchanged lines hidden (view full) --- 89 if (sizep != NULL) 90 *sizep = bytesize; 91 return (error); 92} 93 94int 95image_copyout(int fd) 96{ |
97 off_t ofs; | |
98 int error; 99 100 error = image_copyout_region(fd, 0, image_size); | 97 int error; 98 99 error = image_copyout_region(fd, 0, image_size); |
101 if (error) 102 return (error); | 100 if (!error) 101 error = image_copyout_done(fd); 102 return (error); 103} |
103 | 104 |
105int 106image_copyout_done(int fd) 107{ 108 off_t ofs; 109 int error; 110 |
|
104 ofs = lseek(fd, 0L, SEEK_CUR); 105 if (ofs == -1) 106 return (0); 107 error = (ftruncate(fd, ofs) == -1) ? errno : 0; 108 return (error); 109} 110 111int --- 31 unchanged lines hidden (view full) --- 143 } 144 assert(wrsz == rdsz); 145 size -= rdsz; 146 } 147 free(buffer); 148 return (error); 149} 150 | 111 ofs = lseek(fd, 0L, SEEK_CUR); 112 if (ofs == -1) 113 return (0); 114 error = (ftruncate(fd, ofs) == -1) ? errno : 0; 115 return (error); 116} 117 118int --- 31 unchanged lines hidden (view full) --- 150 } 151 assert(wrsz == rdsz); 152 size -= rdsz; 153 } 154 free(buffer); 155 return (error); 156} 157 |
158int 159image_data(lba_t blk, lba_t size) 160{ 161 char *buffer, *p; 162 163 blk *= secsz; 164 if (lseek(image_fd, blk, SEEK_SET) != blk) 165 return (1); 166 167 size *= secsz; 168 buffer = malloc(size); 169 if (buffer == NULL) 170 return (1); 171 172 if (read(image_fd, buffer, size) != (ssize_t)size) { 173 free(buffer); 174 return (1); 175 } 176 177 p = buffer; 178 while (size > 0 && *p == '\0') 179 size--, p++; 180 181 free(buffer); 182 return ((size == 0) ? 0 : 1); 183} 184 |
|
151lba_t 152image_get_size(void) 153{ 154 155 return (image_size); 156} 157 158int --- 38 unchanged lines hidden --- | 185lba_t 186image_get_size(void) 187{ 188 189 return (image_size); 190} 191 192int --- 38 unchanged lines hidden --- |