libzfs_util.c (185039) | libzfs_util.c (209962) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 5 unchanged lines hidden (view full) --- 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 5 unchanged lines hidden (view full) --- 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* |
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. | 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
23 * Use is subject to license terms. 24 */ 25 26/* 27 * Internal utility routines for the ZFS library. 28 */ 29 30#include <errno.h> --- 328 unchanged lines hidden (view full) --- 359 zfs_verror(hdl, EZFS_PERMRDONLY, fmt, ap); 360 break; 361 case ENAMETOOLONG: 362 zfs_verror(hdl, EZFS_NAMETOOLONG, fmt, ap); 363 break; 364 case ENOTSUP: 365 zfs_verror(hdl, EZFS_BADVERSION, fmt, ap); 366 break; | 23 * Use is subject to license terms. 24 */ 25 26/* 27 * Internal utility routines for the ZFS library. 28 */ 29 30#include <errno.h> --- 328 unchanged lines hidden (view full) --- 359 zfs_verror(hdl, EZFS_PERMRDONLY, fmt, ap); 360 break; 361 case ENAMETOOLONG: 362 zfs_verror(hdl, EZFS_NAMETOOLONG, fmt, ap); 363 break; 364 case ENOTSUP: 365 zfs_verror(hdl, EZFS_BADVERSION, fmt, ap); 366 break; |
367 case EAGAIN: 368 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, 369 "pool I/O is currently suspended")); 370 zfs_verror(hdl, EZFS_POOLUNAVAIL, fmt, ap); 371 break; |
|
367 default: 368 zfs_error_aux(hdl, strerror(errno)); 369 zfs_verror(hdl, EZFS_UNKNOWN, fmt, ap); 370 break; 371 } 372 373 va_end(ap); 374 return (-1); --- 57 unchanged lines hidden (view full) --- 432 case EINVAL: 433 zfs_verror(hdl, EZFS_POOL_INVALARG, fmt, ap); 434 break; 435 436 case ENOSPC: 437 case EDQUOT: 438 zfs_verror(hdl, EZFS_NOSPC, fmt, ap); 439 return (-1); | 372 default: 373 zfs_error_aux(hdl, strerror(errno)); 374 zfs_verror(hdl, EZFS_UNKNOWN, fmt, ap); 375 break; 376 } 377 378 va_end(ap); 379 return (-1); --- 57 unchanged lines hidden (view full) --- 437 case EINVAL: 438 zfs_verror(hdl, EZFS_POOL_INVALARG, fmt, ap); 439 break; 440 441 case ENOSPC: 442 case EDQUOT: 443 zfs_verror(hdl, EZFS_NOSPC, fmt, ap); 444 return (-1); |
445 case EAGAIN: 446 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, 447 "pool I/O is currently suspended")); 448 zfs_verror(hdl, EZFS_POOLUNAVAIL, fmt, ap); 449 break; |
|
440 441 default: 442 zfs_error_aux(hdl, strerror(error)); 443 zfs_verror(hdl, EZFS_UNKNOWN, fmt, ap); 444 } 445 446 va_end(ap); 447 return (-1); --- 27 unchanged lines hidden (view full) --- 475 */ 476void * 477zfs_realloc(libzfs_handle_t *hdl, void *ptr, size_t oldsize, size_t newsize) 478{ 479 void *ret; 480 481 if ((ret = realloc(ptr, newsize)) == NULL) { 482 (void) no_memory(hdl); | 450 451 default: 452 zfs_error_aux(hdl, strerror(error)); 453 zfs_verror(hdl, EZFS_UNKNOWN, fmt, ap); 454 } 455 456 va_end(ap); 457 return (-1); --- 27 unchanged lines hidden (view full) --- 485 */ 486void * 487zfs_realloc(libzfs_handle_t *hdl, void *ptr, size_t oldsize, size_t newsize) 488{ 489 void *ret; 490 491 if ((ret = realloc(ptr, newsize)) == NULL) { 492 (void) no_memory(hdl); |
483 free(ptr); | |
484 return (NULL); 485 } 486 487 bzero((char *)ret + oldsize, (newsize - oldsize)); 488 return (ret); 489} 490 491/* --- 98 unchanged lines hidden (view full) --- 590 free(hdl); 591 return (NULL); 592 } 593 594 hdl->libzfs_sharetab = fopen(ZFS_EXPORTS_PATH, "r"); 595 596 zfs_prop_init(); 597 zpool_prop_init(); | 493 return (NULL); 494 } 495 496 bzero((char *)ret + oldsize, (newsize - oldsize)); 497 return (ret); 498} 499 500/* --- 98 unchanged lines hidden (view full) --- 599 free(hdl); 600 return (NULL); 601 } 602 603 hdl->libzfs_sharetab = fopen(ZFS_EXPORTS_PATH, "r"); 604 605 zfs_prop_init(); 606 zpool_prop_init(); |
607 libzfs_mnttab_init(hdl); |
|
598 599 return (hdl); 600} 601 602void 603libzfs_fini(libzfs_handle_t *hdl) 604{ 605 (void) close(hdl->libzfs_fd); 606 if (hdl->libzfs_mnttab) 607 (void) fclose(hdl->libzfs_mnttab); 608 if (hdl->libzfs_sharetab) 609 (void) fclose(hdl->libzfs_sharetab); 610 zfs_uninit_libshare(hdl); 611 if (hdl->libzfs_log_str) 612 (void) free(hdl->libzfs_log_str); 613 zpool_free_handles(hdl); 614 namespace_clear(hdl); | 608 609 return (hdl); 610} 611 612void 613libzfs_fini(libzfs_handle_t *hdl) 614{ 615 (void) close(hdl->libzfs_fd); 616 if (hdl->libzfs_mnttab) 617 (void) fclose(hdl->libzfs_mnttab); 618 if (hdl->libzfs_sharetab) 619 (void) fclose(hdl->libzfs_sharetab); 620 zfs_uninit_libshare(hdl); 621 if (hdl->libzfs_log_str) 622 (void) free(hdl->libzfs_log_str); 623 zpool_free_handles(hdl); 624 namespace_clear(hdl); |
625 libzfs_mnttab_fini(hdl); |
|
615 free(hdl); 616} 617 618libzfs_handle_t * 619zpool_get_handle(zpool_handle_t *zhp) 620{ 621 return (zhp->zpool_hdl); 622} --- 174 unchanged lines hidden (view full) --- 797 cbp->cb_colwidths[GET_COL_NAME] = strlen(dgettext(TEXT_DOMAIN, "NAME")); 798 cbp->cb_colwidths[GET_COL_PROPERTY] = strlen(dgettext(TEXT_DOMAIN, 799 "PROPERTY")); 800 cbp->cb_colwidths[GET_COL_VALUE] = strlen(dgettext(TEXT_DOMAIN, 801 "VALUE")); 802 cbp->cb_colwidths[GET_COL_SOURCE] = strlen(dgettext(TEXT_DOMAIN, 803 "SOURCE")); 804 | 626 free(hdl); 627} 628 629libzfs_handle_t * 630zpool_get_handle(zpool_handle_t *zhp) 631{ 632 return (zhp->zpool_hdl); 633} --- 174 unchanged lines hidden (view full) --- 808 cbp->cb_colwidths[GET_COL_NAME] = strlen(dgettext(TEXT_DOMAIN, "NAME")); 809 cbp->cb_colwidths[GET_COL_PROPERTY] = strlen(dgettext(TEXT_DOMAIN, 810 "PROPERTY")); 811 cbp->cb_colwidths[GET_COL_VALUE] = strlen(dgettext(TEXT_DOMAIN, 812 "VALUE")); 813 cbp->cb_colwidths[GET_COL_SOURCE] = strlen(dgettext(TEXT_DOMAIN, 814 "SOURCE")); 815 |
816 /* first property is always NAME */ 817 assert(cbp->cb_proplist->pl_prop == 818 ((type == ZFS_TYPE_POOL) ? ZPOOL_PROP_NAME : ZFS_PROP_NAME)); 819 |
|
805 /* 806 * Go through and calculate the widths for each column. For the 807 * 'source' column, we kludge it up by taking the worst-case scenario of 808 * inheriting from the longest name. This is acceptable because in the 809 * majority of cases 'SOURCE' is the last column displayed, and we don't 810 * use the width anyway. Note that the 'VALUE' column can be oversized, 811 * if the name of the property is much longer the any values we find. 812 */ --- 11 unchanged lines hidden (view full) --- 824 cbp->cb_colwidths[GET_COL_PROPERTY] = len; 825 } else { 826 len = strlen(pl->pl_user_prop); 827 if (len > cbp->cb_colwidths[GET_COL_PROPERTY]) 828 cbp->cb_colwidths[GET_COL_PROPERTY] = len; 829 } 830 831 /* | 820 /* 821 * Go through and calculate the widths for each column. For the 822 * 'source' column, we kludge it up by taking the worst-case scenario of 823 * inheriting from the longest name. This is acceptable because in the 824 * majority of cases 'SOURCE' is the last column displayed, and we don't 825 * use the width anyway. Note that the 'VALUE' column can be oversized, 826 * if the name of the property is much longer the any values we find. 827 */ --- 11 unchanged lines hidden (view full) --- 839 cbp->cb_colwidths[GET_COL_PROPERTY] = len; 840 } else { 841 len = strlen(pl->pl_user_prop); 842 if (len > cbp->cb_colwidths[GET_COL_PROPERTY]) 843 cbp->cb_colwidths[GET_COL_PROPERTY] = len; 844 } 845 846 /* |
832 * 'VALUE' column | 847 * 'VALUE' column. The first property is always the 'name' 848 * property that was tacked on either by /sbin/zfs's 849 * zfs_do_get() or when calling zprop_expand_list(), so we 850 * ignore its width. If the user specified the name property 851 * to display, then it will be later in the list in any case. |
833 */ | 852 */ |
834 if ((pl->pl_prop != ZFS_PROP_NAME || !pl->pl_all) && | 853 if (pl != cbp->cb_proplist && |
835 pl->pl_width > cbp->cb_colwidths[GET_COL_VALUE]) 836 cbp->cb_colwidths[GET_COL_VALUE] = pl->pl_width; 837 838 /* 839 * 'NAME' and 'SOURCE' columns 840 */ 841 if (pl->pl_prop == (type == ZFS_TYPE_POOL ? ZPOOL_PROP_NAME : 842 ZFS_PROP_NAME) && --- 168 unchanged lines hidden (view full) --- 1011 /* Check to see if this looks like a number. */ 1012 if ((value[0] < '0' || value[0] > '9') && value[0] != '.') { 1013 if (hdl) 1014 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, 1015 "bad numeric value '%s'"), value); 1016 return (-1); 1017 } 1018 | 854 pl->pl_width > cbp->cb_colwidths[GET_COL_VALUE]) 855 cbp->cb_colwidths[GET_COL_VALUE] = pl->pl_width; 856 857 /* 858 * 'NAME' and 'SOURCE' columns 859 */ 860 if (pl->pl_prop == (type == ZFS_TYPE_POOL ? ZPOOL_PROP_NAME : 861 ZFS_PROP_NAME) && --- 168 unchanged lines hidden (view full) --- 1030 /* Check to see if this looks like a number. */ 1031 if ((value[0] < '0' || value[0] > '9') && value[0] != '.') { 1032 if (hdl) 1033 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, 1034 "bad numeric value '%s'"), value); 1035 return (-1); 1036 } 1037 |
1019 /* Rely on stroll() to process the numeric portion. */ | 1038 /* Rely on stroull() to process the numeric portion. */ |
1020 errno = 0; | 1039 errno = 0; |
1021 *num = strtoll(value, &end, 10); | 1040 *num = strtoull(value, &end, 10); |
1022 1023 /* 1024 * Check for ERANGE, which indicates that the value is too large to fit 1025 * in a 64-bit value. 1026 */ 1027 if (errno == ERANGE) { 1028 if (hdl) 1029 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, --- 173 unchanged lines hidden (view full) --- 1203 prop = ZPROP_INVAL; 1204 1205 /* 1206 * When no property table entry can be found, return failure if 1207 * this is a pool property or if this isn't a user-defined 1208 * dataset property, 1209 */ 1210 if (prop == ZPROP_INVAL && (type == ZFS_TYPE_POOL || | 1041 1042 /* 1043 * Check for ERANGE, which indicates that the value is too large to fit 1044 * in a 64-bit value. 1045 */ 1046 if (errno == ERANGE) { 1047 if (hdl) 1048 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, --- 173 unchanged lines hidden (view full) --- 1222 prop = ZPROP_INVAL; 1223 1224 /* 1225 * When no property table entry can be found, return failure if 1226 * this is a pool property or if this isn't a user-defined 1227 * dataset property, 1228 */ 1229 if (prop == ZPROP_INVAL && (type == ZFS_TYPE_POOL || |
1211 !zfs_prop_user(propname))) { | 1230 (!zfs_prop_user(propname) && !zfs_prop_userquota(propname)))) { |
1212 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, 1213 "invalid property '%s'"), propname); 1214 return (zfs_error(hdl, EZFS_BADPROP, 1215 dgettext(TEXT_DOMAIN, "bad property list"))); 1216 } 1217 1218 if ((entry = zfs_alloc(hdl, sizeof (zprop_list_t))) == NULL) 1219 return (-1); --- 190 unchanged lines hidden --- | 1231 zfs_error_aux(hdl, dgettext(TEXT_DOMAIN, 1232 "invalid property '%s'"), propname); 1233 return (zfs_error(hdl, EZFS_BADPROP, 1234 dgettext(TEXT_DOMAIN, "bad property list"))); 1235 } 1236 1237 if ((entry = zfs_alloc(hdl, sizeof (zprop_list_t))) == NULL) 1238 return (-1); --- 190 unchanged lines hidden --- |