Changeset 14780 in vbox
- Timestamp:
- Nov 28, 2008 2:36:22 PM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 40098
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/VBoxHDD-new.h
r14526 r14780 600 600 } 601 601 602 /** Configuration node for configuration information interface. */603 typedef struct VDCFGNODE *PVDCFGNODE;604 605 /**606 * Configuration value type for configuration information interface.607 */608 typedef enum VDCFGVALUETYPE609 {610 /** Integer value. */611 VDCFGVALUETYPE_INTEGER = 1,612 /** String value. */613 VDCFGVALUETYPE_STRING,614 /** Bytestring value. */615 VDCFGVALUETYPE_BYTES616 } VDCFGVALUETYPE;617 /** Pointer to configuration value type for configuration information interface. */618 typedef VDCFGVALUETYPE *PVDCFGVALUETYPE;619 620 /**621 * Configuration value. This is not identical to CFGMVALUE.622 */623 typedef union VDCFGVALUE624 {625 /** Integer value. */626 struct VDCFGVALUE_INTEGER627 {628 /** The integer represented as 64-bit unsigned. */629 uint64_t u64;630 } Integer;631 632 /** String value. (UTF-8 of course) */633 struct VDCFGVALUE_STRING634 {635 /** Pointer to the string. */636 char *psz;637 } String;638 639 /** Byte string value. */640 struct VDCFGVALUE_BYTES641 {642 /** Length of byte string. (in bytes) */643 RTUINT cb;644 /** Pointer to the byte string. */645 void *pv;646 } Bytes;647 } VDCFGVALUE, *PVDCFGVALUE;648 602 649 603 /** … … 666 620 667 621 /** 668 * Validates that the values are within a set of valid names.669 * 670 * @return true if all names are found in pszzAllowed.622 * Validates that the keys are within a set of valid names. 623 * 624 * @return true if all key names are found in pszzAllowed. 671 625 * @return false if not. 672 * @param p Node The node which values should be examined.673 * @param pszzValid List of valid names separated by '\\0' and ending with626 * @param pvUser The opaque user data associated with this interface. 627 * @param pszzValid List of valid key names separated by '\\0' and ending with 674 628 * a double '\\0'. 675 629 */ 676 DECLR3CALLBACKMEMBER(bool, pfnAreValuesValid, (PVDCFGNODE pNode, const char *pszzValid)); 677 DECLR3CALLBACKMEMBER(int, pfnQueryType, (PVDCFGNODE pNode, const char *pszName, PVDCFGVALUETYPE penmType)); 678 DECLR3CALLBACKMEMBER(int, pfnQuerySize, (PVDCFGNODE pNode, const char *pszName, size_t *pcb)); 679 DECLR3CALLBACKMEMBER(int, pfnQueryInteger, (PVDCFGNODE pNode, const char *pszName, uint64_t *pu64)); 680 DECLR3CALLBACKMEMBER(int, pfnQueryIntegerDef, (PVDCFGNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def)); 681 DECLR3CALLBACKMEMBER(int, pfnQueryString, (PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString)); 682 DECLR3CALLBACKMEMBER(int, pfnQueryStringDef, (PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef)); 683 DECLR3CALLBACKMEMBER(int, pfnQueryBytes, (PVDCFGNODE pNode, const char *pszName, void *pvData, size_t cbData)); 630 DECLR3CALLBACKMEMBER(bool, pfnAreKeysValid, (void *pvUser, const char *pszzValid)); 631 632 /** 633 * Retrieves the length of the string value associated with a key. 634 * 635 * @return VBox status code. 636 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known. 637 * @param pvUser The opaque user data associated with this interface. 638 * @param pszName Name of the key to query. 639 * @param pcbValue Where to store the value length. Non-NULL. 640 */ 641 DECLR3CALLBACKMEMBER(int, pfnQuerySize, (void *pvUser, const char *pszName, size_t *pcbValue)); 642 643 /** 644 * Query the string value associated with a key. 645 * 646 * @return VBox status code. 647 * VERR_CFGM_VALUE_NOT_FOUND means that the key is not known. 648 * VERR_CFGM_NOT_ENOUGH_SPACE means that the buffer is not big enough. 649 * @param pvUser The opaque user data associated with this interface. 650 * @param pszName Name of the key to query. 651 * @param pszValue Pointer to buffer where to store value. 652 * @param cchValue Length of value buffer. 653 */ 654 DECLR3CALLBACKMEMBER(int, pfnQuery, (void *pvUser, const char *pszName, char *pszValue, size_t cchValue)); 684 655 } VDINTERFACECONFIG, *PVDINTERFACECONFIG; 685 656 … … 708 679 709 680 /** 710 * Query configuration, validates that the values are within a set of valid names.711 * 712 * @return true if all names are found in pszzAllowed.681 * Query configuration, validates that the keys are within a set of valid names. 682 * 683 * @return true if all key names are found in pszzAllowed. 713 684 * @return false if not. 714 685 * @param pCfgIf Pointer to configuration callback table. 715 * @param p Node The node which values should be examined.686 * @param pvUser The opaque user data associated with this interface. 716 687 * @param pszzValid List of valid names separated by '\\0' and ending with 717 688 * a double '\\0'. 718 689 */ 719 DECLINLINE(bool) VDCFGAreValuesValid(PVDINTERFACECONFIG pCfgIf, 720 PVDCFGNODE pNode, 721 const char *pszzValid) 722 { 723 return pCfgIf->pfnAreValuesValid(pNode, pszzValid); 690 DECLINLINE(bool) VDCFGAreKeysValid(PVDINTERFACECONFIG pCfgIf, void *pvUser, 691 const char *pszzValid) 692 { 693 return pCfgIf->pfnAreKeysValid(pvUser, pszzValid); 724 694 } 725 695 … … 729 699 * @return VBox status code. 730 700 * @param pCfgIf Pointer to configuration callback table. 731 * @param p Node Which node to search for pszName in.701 * @param pvUser The opaque user data associated with this interface. 732 702 * @param pszName Name of an integer value 733 703 * @param pu64 Where to store the value. Set to default on failure. 734 704 * @param u64Def The default value. 735 705 */ 736 DECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf, PVDCFGNODE pNode,706 DECLINLINE(int) VDCFGQueryU64Def(PVDINTERFACECONFIG pCfgIf, void *pvUser, 737 707 const char *pszName, uint64_t *pu64, 738 708 uint64_t u64Def) 739 709 { 740 return pCfgIf->pfnQueryIntegerDef(pNode, pszName, pu64, u64Def); 710 char aszBuf[32]; 711 int rc = pCfgIf->pfnQuery(pvUser, pszName, aszBuf, sizeof(aszBuf)); 712 if (RT_SUCCESS(rc)) 713 { 714 rc = RTStrToUInt64Full(aszBuf, 0, pu64); 715 } 716 else if (rc == VERR_CFGM_VALUE_NOT_FOUND) 717 { 718 rc = VINF_SUCCESS; 719 *pu64 = u64Def; 720 } 721 return rc; 741 722 } 742 723 … … 746 727 * @return VBox status code. 747 728 * @param pCfgIf Pointer to configuration callback table. 748 * @param p Node Which node to search for pszName in.729 * @param pvUser The opaque user data associated with this interface. 749 730 * @param pszName Name of an integer value 750 731 * @param pu32 Where to store the value. Set to default on failure. 751 732 * @param u32Def The default value. 752 733 */ 753 DECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf, PVDCFGNODE pNode,734 DECLINLINE(int) VDCFGQueryU32Def(PVDINTERFACECONFIG pCfgIf, void *pvUser, 754 735 const char *pszName, uint32_t *pu32, 755 736 uint32_t u32Def) 756 737 { 757 738 uint64_t u64; 758 int rc = pCfgIf->pfnQueryIntegerDef(pNode, pszName, &u64, u32Def);759 if ( VBOX_SUCCESS(rc))739 int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, u32Def); 740 if (RT_SUCCESS(rc)) 760 741 { 761 742 if (!(u64 & UINT64_C(0xffffffff00000000))) … … 772 753 * @return VBox status code. 773 754 * @param pCfgIf Pointer to configuration callback table. 774 * @param p Node Which node to search for pszName in.755 * @param pvUser The opaque user data associated with this interface. 775 756 * @param pszName Name of an integer value 776 757 * @param pf Where to store the value. Set to default on failure. 777 758 * @param fDef The default value. 778 759 */ 779 DECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf, PVDCFGNODE pNode,760 DECLINLINE(int) VDCFGQueryBoolDef(PVDINTERFACECONFIG pCfgIf, void *pvUser, 780 761 const char *pszName, bool *pf, 781 762 bool fDef) 782 763 { 783 764 uint64_t u64; 784 int rc = pCfgIf->pfnQueryIntegerDef(pNode, pszName, &u64, fDef);785 if ( VBOX_SUCCESS(rc))765 int rc = VDCFGQueryU64Def(pCfgIf, pvUser, pszName, &u64, fDef); 766 if (RT_SUCCESS(rc)) 786 767 *pf = u64 ? true : false; 787 768 return rc; … … 794 775 * @return VBox status code. 795 776 * @param pCfgIf Pointer to configuration callback table. 796 * @param p Node Which node to search for pszName in.777 * @param pvUser The opaque user data associated with this interface. 797 778 * @param pszName Name of an zero terminated character value 798 779 * @param ppszString Where to store the string pointer. Not set on failure. … … 800 781 */ 801 782 DECLINLINE(int) VDCFGQueryStringAlloc(PVDINTERFACECONFIG pCfgIf, 802 PVDCFGNODE pNode, 803 const char *pszName, 783 void *pvUser, const char *pszName, 804 784 char **ppszString) 805 785 { 806 786 size_t cch; 807 int rc = pCfgIf->pfnQuerySize(p Node, pszName, &cch);808 if ( VBOX_SUCCESS(rc))787 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cch); 788 if (RT_SUCCESS(rc)) 809 789 { 810 790 char *pszString = (char *)RTMemAlloc(cch); 811 791 if (pszString) 812 792 { 813 rc = pCfgIf->pfnQuery String(pNode, pszName, pszString, cch);814 if ( VBOX_SUCCESS(rc))793 rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cch); 794 if (RT_SUCCESS(rc)) 815 795 *ppszString = pszString; 816 796 else … … 829 809 * @return VBox status code. 830 810 * @param pCfgIf Pointer to configuration callback table. 831 * @param p Node Which node to search for pszName in.811 * @param pvUser The opaque user data associated with this interface. 832 812 * @param pszName Name of an zero terminated character value 833 813 * @param ppszString Where to store the string pointer. Not set on failure. … … 836 816 */ 837 817 DECLINLINE(int) VDCFGQueryStringAllocDef(PVDINTERFACECONFIG pCfgIf, 838 PVDCFGNODE pNode, 839 const char *pszName, 818 void *pvUser, const char *pszName, 840 819 char **ppszString, 841 820 const char *pszDef) 842 821 { 843 822 size_t cch; 844 int rc = pCfgIf->pfnQuerySize(p Node, pszName, &cch);823 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cch); 845 824 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT) 846 825 { … … 848 827 rc = VINF_SUCCESS; 849 828 } 850 if ( VBOX_SUCCESS(rc))829 if (RT_SUCCESS(rc)) 851 830 { 852 831 char *pszString = (char *)RTMemAlloc(cch); 853 832 if (pszString) 854 833 { 855 rc = pCfgIf->pfnQueryStringDef(pNode, pszName, pszString, cch, pszDef); 856 if (VBOX_SUCCESS(rc)) 834 rc = pCfgIf->pfnQuery(pvUser, pszName, pszString, cch); 835 if (rc == VERR_CFGM_VALUE_NOT_FOUND) 836 { 837 memcpy(pszString, pszDef, cch); 838 rc = VINF_SUCCESS; 839 } 840 if (RT_SUCCESS(rc)) 857 841 *ppszString = pszString; 858 842 else … … 870 854 * @return VBox status code. 871 855 * @param pCfgIf Pointer to configuration callback table. 872 * @param p Node Which node to search for pszName in.856 * @param pvUser The opaque user data associated with this interface. 873 857 * @param pszName Name of an zero terminated character value 874 858 * @param ppvData Where to store the byte string pointer. Not set on failure. … … 877 861 */ 878 862 DECLINLINE(int) VDCFGQueryBytesAlloc(PVDINTERFACECONFIG pCfgIf, 879 PVDCFGNODE pNode, const char *pszName,863 void *pvUser, const char *pszName, 880 864 void **ppvData, size_t *pcbData) 881 865 { 882 866 size_t cb; 883 int rc = pCfgIf->pfnQuerySize(p Node, pszName, &cb);884 if ( VBOX_SUCCESS(rc))867 int rc = pCfgIf->pfnQuerySize(pvUser, pszName, &cb); 868 if (RT_SUCCESS(rc)) 885 869 { 886 870 char *pvData = (char *)RTMemAlloc(cb); 887 871 if (pvData) 888 872 { 889 rc = pCfgIf->pfnQuery Bytes(pNode, pszName, pvData, cb);890 if ( VBOX_SUCCESS(rc))873 rc = pCfgIf->pfnQuery(pvUser, pszName, pvData, cb); 874 if (RT_SUCCESS(rc)) 891 875 { 892 876 *ppvData = pvData; … … 1020 1004 /** @}*/ 1021 1005 1006 1007 /** 1008 * Configuration value type for configuration information interface. 1009 */ 1010 typedef enum VDCFGVALUETYPE 1011 { 1012 /** Integer value. */ 1013 VDCFGVALUETYPE_INTEGER = 1, 1014 /** String value. */ 1015 VDCFGVALUETYPE_STRING, 1016 /** Bytestring value. */ 1017 VDCFGVALUETYPE_BYTES 1018 } VDCFGVALUETYPE; 1019 1020 1022 1021 /** 1023 1022 * Structure describing configuration keys required/supported by a backend … … 1030 1029 /** Pointer to default value (descriptor). NULL if no useful default value 1031 1030 * can be specified. */ 1032 const PVDCFGVALUE pDefaultValue;1031 const char *pszDefaultValue; 1033 1032 /** Value type for this key. */ 1034 1033 VDCFGVALUETYPE enmValueType; -
trunk/src/VBox/Devices/Storage/DrvVD.cpp
r14538 r14780 289 289 *******************************************************************************/ 290 290 291 static bool drvvdCfgAreValuesValid(PVDCFGNODE pNode, const char *pszzValid) 292 { 293 return CFGMR3AreValuesValid((PCFGMNODE)pNode, pszzValid); 294 } 295 296 static int drvvdCfgQueryType(PVDCFGNODE pNode, const char *pszName, PVDCFGVALUETYPE penmType) 297 { 298 Assert(VDCFGVALUETYPE_INTEGER == (VDCFGVALUETYPE)CFGMVALUETYPE_INTEGER); 299 Assert(VDCFGVALUETYPE_STRING == (VDCFGVALUETYPE)CFGMVALUETYPE_STRING); 300 Assert(VDCFGVALUETYPE_BYTES == (VDCFGVALUETYPE)CFGMVALUETYPE_BYTES); 301 return CFGMR3QueryType((PCFGMNODE)pNode, pszName, (PCFGMVALUETYPE)penmType); 302 } 303 304 static int drvvdCfgQuerySize(PVDCFGNODE pNode, const char *pszName, size_t *pcb) 305 { 306 return CFGMR3QuerySize((PCFGMNODE)pNode, pszName, pcb); 307 } 308 309 static int drvvdCfgQueryInteger(PVDCFGNODE pNode, const char *pszName, uint64_t *pu64) 310 { 311 return CFGMR3QueryInteger((PCFGMNODE)pNode, pszName, pu64); 312 } 313 314 static int drvvdCfgQueryIntegerDef(PVDCFGNODE pNode, const char *pszName, uint64_t *pu64, uint64_t u64Def) 315 { 316 return CFGMR3QueryInteger((PCFGMNODE)pNode, pszName, pu64); 317 } 318 319 static int drvvdCfgQueryString(PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString) 320 { 321 return CFGMR3QueryString((PCFGMNODE)pNode, pszName, pszString, cchString); 322 } 323 324 static int drvvdCfgQueryStringDef(PVDCFGNODE pNode, const char *pszName, char *pszString, size_t cchString, const char *pszDef) 325 { 326 return CFGMR3QueryStringDef((PCFGMNODE)pNode, pszName, pszString, cchString, pszDef); 327 } 328 329 static int drvvdCfgQueryBytes(PVDCFGNODE pNode, const char *pszName, void *pvData, size_t cbData) 330 { 331 return CFGMR3QueryBytes((PCFGMNODE)pNode, pszName, pvData, cbData); 291 static bool drvvdCfgAreKeysValid(void *pvUser, const char *pszzValid) 292 { 293 return CFGMR3AreValuesValid((PCFGMNODE)pvUser, pszzValid); 294 } 295 296 static int drvvdCfgQuerySize(void *pvUser, const char *pszName, size_t *pcb) 297 { 298 return CFGMR3QuerySize((PCFGMNODE)pvUser, pszName, pcb); 299 } 300 301 static int drvvdCfgQuery(void *pvUser, const char *pszName, char *pszString, size_t cchString) 302 { 303 return CFGMR3QueryString((PCFGMNODE)pvUser, pszName, pszString, cchString); 332 304 } 333 305 … … 790 762 pThis->VDIConfigCallbacks.cbSize = sizeof(VDINTERFACECONFIG); 791 763 pThis->VDIConfigCallbacks.enmInterface = VDINTERFACETYPE_CONFIG; 792 pThis->VDIConfigCallbacks.pfnAreValuesValid = drvvdCfgAreValuesValid; 793 pThis->VDIConfigCallbacks.pfnQueryType = drvvdCfgQueryType; 764 pThis->VDIConfigCallbacks.pfnAreKeysValid = drvvdCfgAreKeysValid; 794 765 pThis->VDIConfigCallbacks.pfnQuerySize = drvvdCfgQuerySize; 795 pThis->VDIConfigCallbacks.pfnQueryInteger = drvvdCfgQueryInteger; 796 pThis->VDIConfigCallbacks.pfnQueryIntegerDef = drvvdCfgQueryIntegerDef; 797 pThis->VDIConfigCallbacks.pfnQueryString = drvvdCfgQueryString; 798 pThis->VDIConfigCallbacks.pfnQueryStringDef = drvvdCfgQueryStringDef; 799 pThis->VDIConfigCallbacks.pfnQueryBytes = drvvdCfgQueryBytes; 766 pThis->VDIConfigCallbacks.pfnQuery = drvvdCfgQuery; 800 767 801 768 /* List of images is empty now. */ -
trunk/src/VBox/Devices/Storage/testcase/tstVD-2.cpp
r13837 r14780 87 87 { 88 88 case VDCFGVALUETYPE_INTEGER: 89 RTPrintf("integer default="); 90 if (pa->pDefaultValue) 91 RTPrintf("%RU64", pa->pDefaultValue->Integer.u64); 92 else 93 RTPrintf("<NONE>"); 89 RTPrintf("integer"); 94 90 break; 95 91 case VDCFGVALUETYPE_STRING: 96 RTPrintf("string default="); 97 if (pa->pDefaultValue) 98 RTPrintf("%s", pa->pDefaultValue->String.psz); 99 else 100 RTPrintf("<NONE>"); 92 RTPrintf("string"); 101 93 break; 102 94 case VDCFGVALUETYPE_BYTES: 103 RTPrintf("bytes default="); 104 if (pa->pDefaultValue) 105 RTPrintf("length=%RTuint %.*Rhxs", 106 pa->pDefaultValue->Bytes.cb, 107 pa->pDefaultValue->Bytes.cb, 108 pa->pDefaultValue->Bytes.pv); 109 else 110 RTPrintf("<NONE>"); 95 RTPrintf("bytes"); 111 96 break; 112 97 default: 113 98 RTPrintf("INVALID!"); 114 99 } 100 if (pa->pszDefaultValue) 101 RTPrintf("%s", pa->pszDefaultValue); 102 else 103 RTPrintf("<NONE>"); 115 104 RTPrintf(" flags="); 116 105 if (!pa->uKeyFlags) -
trunk/src/VBox/Main/HardDiskFormatImpl.cpp
r14772 r14780 95 95 dt = DataType_Int32; 96 96 /* If there is a default value get them in the right format */ 97 if (pa->pDefaultValue) 98 defaultValue = 99 Utf8StrFmt ("%d", pa->pDefaultValue->Integer.u64); 97 if (pa->pszDefaultValue) 98 defaultValue = pa->pszDefaultValue; 100 99 break; 101 100 } … … 104 103 dt = DataType_Int8; 105 104 /* If there is a default value get them in the right format */ 106 if (pa->p DefaultValue)105 if (pa->pszDefaultValue) 107 106 { 108 /* Copy the bytes over */ 109 defaultValue.alloc (pa->pDefaultValue->Bytes.cb + 1); 110 memcpy (defaultValue.mutableRaw(), pa->pDefaultValue->Bytes.pv, 111 pa->pDefaultValue->Bytes.cb); 112 defaultValue.mutableRaw() [defaultValue.length()] = 0; 107 /* Copy the bytes over - treated simply as a string */ 108 defaultValue = pa->pszDefaultValue; 113 109 flags |= DataFlags_Array; 114 110 } … … 119 115 dt = DataType_String; 120 116 /* If there is a default value get them in the right format */ 121 if (pa->p DefaultValue)122 defaultValue = pa->p DefaultValue->String.psz;117 if (pa->pszDefaultValue) 118 defaultValue = pa->pszDefaultValue; 123 119 break; 124 120 }
Note:
See TracChangeset
for help on using the changeset viewer.