geom_virstor.c (212554) | geom_virstor.c (213662) |
---|---|
1/*- 2 * Copyright (c) 2005 Ivan Voras <ivoras@freebsd.org> 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 10 unchanged lines hidden (view full) --- 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2005 Ivan Voras <ivoras@freebsd.org> 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 10 unchanged lines hidden (view full) --- 19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 * SUCH DAMAGE. 24 */ 25 26#include <sys/cdefs.h> |
27__FBSDID("$FreeBSD: head/sbin/geom/class/virstor/geom_virstor.c 212554 2010-09-13 13:48:18Z pjd $"); | 27__FBSDID("$FreeBSD: head/sbin/geom/class/virstor/geom_virstor.c 213662 2010-10-09 20:20:27Z ae $"); |
28 29#include <sys/param.h> 30#include <errno.h> 31#include <paths.h> 32#include <stdio.h> 33#include <stdlib.h> 34#include <stdint.h> 35#include <string.h> --- 103 unchanged lines hidden (view full) --- 139 CTASSERT(VIRSTOR_MAP_BLOCK_ENTRIES*VIRSTOR_MAP_ENTRY_SIZE == MAXPHYS); 140 */ 141} 142 143static void 144pathgen(const char *name, char *path, size_t size) 145{ 146 | 28 29#include <sys/param.h> 30#include <errno.h> 31#include <paths.h> 32#include <stdio.h> 33#include <stdlib.h> 34#include <stdint.h> 35#include <string.h> --- 103 unchanged lines hidden (view full) --- 139 CTASSERT(VIRSTOR_MAP_BLOCK_ENTRIES*VIRSTOR_MAP_ENTRY_SIZE == MAXPHYS); 140 */ 141} 142 143static void 144pathgen(const char *name, char *path, size_t size) 145{ 146 |
147 if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) != 0) | 147 if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) != 0) |
148 snprintf(path, size, "%s%s", _PATH_DEV, name); 149 else 150 strlcpy(path, name, size); 151} 152 153static int 154my_g_metadata_store(const char *name, u_char *md, size_t size) 155{ --- 214 unchanged lines hidden (view full) --- 370 map_chunks = map_size/md.md_chunk_size; 371 if (map_size % md.md_chunk_size != 0) 372 map_chunks++; 373 if (verbose) { 374 printf(" (%zu MB, %d chunks) ", map_size/(1024*1024), map_chunks); 375 fflush(stdout); 376 } 377 | 148 snprintf(path, size, "%s%s", _PATH_DEV, name); 149 else 150 strlcpy(path, name, size); 151} 152 153static int 154my_g_metadata_store(const char *name, u_char *md, size_t size) 155{ --- 214 unchanged lines hidden (view full) --- 370 map_chunks = map_size/md.md_chunk_size; 371 if (map_size % md.md_chunk_size != 0) 372 map_chunks++; 373 if (verbose) { 374 printf(" (%zu MB, %d chunks) ", map_size/(1024*1024), map_chunks); 375 fflush(stdout); 376 } 377 |
378 if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) | 378 if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0) |
379 fd = open(name, O_RDWR); 380 else { 381 sprintf(param, "%s%s", _PATH_DEV, name); 382 fd = open(param, O_RDWR); 383 } 384 if (fd < 0) 385 gctl_error(req, "Cannot open provider %s to write map", name); 386 --- 61 unchanged lines hidden (view full) --- 448 if (verbose) 449 printf("(%u reserved) ", md.chunk_reserved); 450 } 451 452 if (!hardcode) 453 bzero(md.provider, sizeof(md.provider)); 454 else { 455 /* convert "/dev/something" to "something" */ | 379 fd = open(name, O_RDWR); 380 else { 381 sprintf(param, "%s%s", _PATH_DEV, name); 382 fd = open(param, O_RDWR); 383 } 384 if (fd < 0) 385 gctl_error(req, "Cannot open provider %s to write map", name); 386 --- 61 unchanged lines hidden (view full) --- 448 if (verbose) 449 printf("(%u reserved) ", md.chunk_reserved); 450 } 451 452 if (!hardcode) 453 bzero(md.provider, sizeof(md.provider)); 454 else { 455 /* convert "/dev/something" to "something" */ |
456 if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) { 457 strlcpy(md.provider, name + strlen(_PATH_DEV), | 456 if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0) { 457 strlcpy(md.provider, name + sizeof(_PATH_DEV) - 1, |
458 sizeof(md.provider)); 459 } else 460 strlcpy(md.provider, name, sizeof(md.provider)); 461 } 462 sect = malloc(ssize); 463 if (sect == NULL) 464 err(1, "Cannot allocate sector of %zu bytes", ssize); 465 bzero(sect, ssize); --- 38 unchanged lines hidden (view full) --- 504 error = g_metadata_clear(name, G_VIRSTOR_MAGIC); 505 if (error != 0) { 506 fprintf(stderr, "Can't clear metadata on %s: %s " 507 "(do I own it?)\n", name, strerror(error)); 508 gctl_error(req, 509 "Not fully done (can't clear metadata)."); 510 continue; 511 } | 458 sizeof(md.provider)); 459 } else 460 strlcpy(md.provider, name, sizeof(md.provider)); 461 } 462 sect = malloc(ssize); 463 if (sect == NULL) 464 err(1, "Cannot allocate sector of %zu bytes", ssize); 465 bzero(sect, ssize); --- 38 unchanged lines hidden (view full) --- 504 error = g_metadata_clear(name, G_VIRSTOR_MAGIC); 505 if (error != 0) { 506 fprintf(stderr, "Can't clear metadata on %s: %s " 507 "(do I own it?)\n", name, strerror(error)); 508 gctl_error(req, 509 "Not fully done (can't clear metadata)."); 510 continue; 511 } |
512 if (strncmp(name, _PATH_DEV, strlen(_PATH_DEV)) == 0) | 512 if (strncmp(name, _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0) |
513 fd = open(name, O_RDWR); 514 else { 515 sprintf(param, "%s%s", _PATH_DEV, name); 516 fd = open(param, O_RDWR); 517 } 518 if (fd < 0) { 519 gctl_error(req, "Cannot clear header sector for %s", 520 name); --- 63 unchanged lines hidden --- | 513 fd = open(name, O_RDWR); 514 else { 515 sprintf(param, "%s%s", _PATH_DEV, name); 516 fd = open(param, O_RDWR); 517 } 518 if (fd < 0) { 519 gctl_error(req, "Cannot clear header sector for %s", 520 name); --- 63 unchanged lines hidden --- |