VirtualBox

Ignore:
Timestamp:
Aug 12, 2008 12:55:15 PM (17 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
34523
Message:

VBoxHDD-new: add new UUID parameter to image creation, specifying which UUID the new image should have.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/testcase/tstVD.cpp

    r10715 r11353  
    8383
    8484    rc = VDCreateBase(pVD, pszBackend, pszFilename, enmType, cbSize,
    85                       uFlags, "Test image", &PCHS, &LCHS, VD_OPEN_FLAGS_NORMAL,
    86                       NULL, NULL);
     85                      uFlags, "Test image", &PCHS, &LCHS, NULL,
     86                      VD_OPEN_FLAGS_NORMAL, NULL, NULL);
    8787    CHECK("VDCreateBase()");
    8888
     
    101101
    102102/**
    103  * The following code is based on the work of George Marsaglia 
    104  * taken from 
     103 * The following code is based on the work of George Marsaglia
     104 * taken from
    105105 * http://groups.google.ws/group/comp.sys.sun.admin/msg/7c667186f6cbf354
    106  * and 
    107  * http://groups.google.ws/group/comp.lang.c/msg/0e170777c6e79e8d 
     106 * and
     107 * http://groups.google.ws/group/comp.lang.c/msg/0e170777c6e79e8d
    108108 */
    109109
    110 /* 
    111 A C version of a very very good 64-bit RNG is given below. 
    112 You should be able to adapt it to your particular needs. 
    113 
    114 It is based on the complimentary-multiple-with-carry 
    115 sequence 
    116          x(n)=a*x(n-4)+carry mod 2^64-1, 
    117 which works as follows: 
    118 Assume a certain multiplier 'a' and a base 'b'. 
    119 Given a current x value and a current carry 'c', 
    120 form:               t=a*x+c 
    121 Then the new carry is     c=floor(t/b) 
    122 and the new x value is    x = b-1-(t mod b). 
    123 
    124 
    125 Ordinarily, for 32-bit mwc or cmwc sequences, the 
    126 value t=a*x+c can be formed in 64 bits, then the new c 
    127 is the top and the new x the bottom 32 bits (with a little 
    128 fiddling when b=2^32-1 and cmwc rather than mwc.) 
    129 
    130 
    131 To generate 64-bit x's, it is difficult to form 
    132 t=a*x+c in 128 bits then get the new c and new x 
    133 from the the top and bottom halves. 
    134 But if 'a' has a special form, for example, 
    135 a=2^62+2^47+2 and b=2^64-1, then the new c and 
    136 the new x can be formed with shifts, tests and +/-'s, 
    137 again with a little fiddling because b=2^64-1 rather 
    138 than 2^64.   (The latter is not an optimal choice because, 
    139 being a square, it cannot be a primitive root of the 
    140 prime a*b^k+1, where 'k' is the 'lag': 
    141         x(n)=a*x(n-k)+carry mod b.) 
    142 But the multiplier a=2^62+2^47+2 makes a*b^4+1 a prime for 
    143 which b=2^64-1 is a primitive root, and getting  the new x and 
    144 new c  can be done with arithmetic on integers the size of x. 
    145 */ 
     110/*
     111A C version of a very very good 64-bit RNG is given below.
     112You should be able to adapt it to your particular needs.
     113
     114It is based on the complimentary-multiple-with-carry
     115sequence
     116         x(n)=a*x(n-4)+carry mod 2^64-1,
     117which works as follows:
     118Assume a certain multiplier 'a' and a base 'b'.
     119Given a current x value and a current carry 'c',
     120form:               t=a*x+c
     121Then the new carry is     c=floor(t/b)
     122and the new x value is    x = b-1-(t mod b).
     123
     124
     125Ordinarily, for 32-bit mwc or cmwc sequences, the
     126value t=a*x+c can be formed in 64 bits, then the new c
     127is the top and the new x the bottom 32 bits (with a little
     128fiddling when b=2^32-1 and cmwc rather than mwc.)
     129
     130
     131To generate 64-bit x's, it is difficult to form
     132t=a*x+c in 128 bits then get the new c and new x
     133from the the top and bottom halves.
     134But if 'a' has a special form, for example,
     135a=2^62+2^47+2 and b=2^64-1, then the new c and
     136the new x can be formed with shifts, tests and +/-'s,
     137again with a little fiddling because b=2^64-1 rather
     138than 2^64.   (The latter is not an optimal choice because,
     139being a square, it cannot be a primitive root of the
     140prime a*b^k+1, where 'k' is the 'lag':
     141        x(n)=a*x(n-k)+carry mod b.)
     142But the multiplier a=2^62+2^47+2 makes a*b^4+1 a prime for
     143which b=2^64-1 is a primitive root, and getting  the new x and
     144new c  can be done with arithmetic on integers the size of x.
     145*/
    146146
    147147struct RndCtx
     
    159159
    160160/**
    161  * Initialize seeds. 
    162  * 
     161 * Initialize seeds.
     162 *
    163163 * @remarks You should choose ANY 4 random 64-bit
    164164 * seeds x,y,z,w < 2^64-1 and a random seed c in
     
    196196RTDECL(uint64_t) RTPRandU64(PRNDCTX pCtx)
    197197{
    198     uint64_t t; 
    199     t = (pCtx->x<<47) + (pCtx->x<<62) + (pCtx->x<<1); 
    200     t += pCtx->c; t+= (t < pCtx->c); 
    201     pCtx->c = (t<pCtx->c) + (pCtx->x>>17) + (pCtx->x>>2) + (pCtx->x>>63); 
    202     pCtx->x = pCtx->y;  pCtx->y = pCtx->z ; pCtx->z = pCtx->w; 
    203     return (pCtx->w = ~(t + pCtx->c)-1); 
    204 } 
     198    uint64_t t;
     199    t = (pCtx->x<<47) + (pCtx->x<<62) + (pCtx->x<<1);
     200    t += pCtx->c; t+= (t < pCtx->c);
     201    pCtx->c = (t<pCtx->c) + (pCtx->x>>17) + (pCtx->x>>2) + (pCtx->x>>63);
     202    pCtx->x = pCtx->y;  pCtx->y = pCtx->z ; pCtx->z = pCtx->w;
     203    return (pCtx->w = ~(t + pCtx->c)-1);
     204}
    205205
    206206/**
    207  * Generate a 64-bit unsigned pseudo random number in the set 
    208  * [u64First..u64Last]. 
     207 * Generate a 64-bit unsigned pseudo random number in the set
     208 * [u64First..u64Last].
    209209 *
    210210 * @returns The pseudo random number.
     
    240240             pCtx->u32y ^= pCtx->u32y<<5,
    241241             pCtx->u32x + pCtx->u32y );
    242 } 
     242}
    243243
    244244/**
    245  * Generate a 32-bit unsigned pseudo random number in the set 
    246  * [u32First..u32Last]. 
     245 * Generate a 32-bit unsigned pseudo random number in the set
     246 * [u32First..u32Last].
    247247 *
    248248 * @returns The pseudo random number.
     
    283283    else
    284284    {
    285         RTPrintf("INFO: Random generator seed used: %x\n", RTPRandGetSeedInfo(pCtx));   
    286         RTLogPrintf("INFO: Random generator seed used: %x\n", RTPRandGetSeedInfo(pCtx));   
     285        RTPrintf("INFO: Random generator seed used: %x\n", RTPRandGetSeedInfo(pCtx));
     286        RTLogPrintf("INFO: Random generator seed used: %x\n", RTPRandGetSeedInfo(pCtx));
    287287    }
    288288}
     
    481481                          VD_IMAGE_TYPE_NORMAL, u64DiskSize,
    482482                          VD_IMAGE_FLAGS_NONE, "Test image",
    483                           &PCHS, &LCHS, VD_OPEN_FLAGS_NORMAL,
     483                          &PCHS, &LCHS, NULL, VD_OPEN_FLAGS_NORMAL,
    484484                          NULL, NULL);
    485485        CHECK("VDCreateBase()");
     
    506506
    507507    rc = VDCreateDiff(pVD, pszBackend, pszDiffFilename,
    508                       VD_IMAGE_FLAGS_NONE, "Test diff image",
     508                      VD_IMAGE_FLAGS_NONE, "Test diff image", NULL,
    509509                      VD_OPEN_FLAGS_NORMAL, NULL, NULL);
    510510    CHECK("VDCreateDiff()");
     
    587587                      VD_IMAGE_TYPE_NORMAL, u64DiskSize,
    588588                      VD_IMAGE_FLAGS_NONE, "Test image",
    589                       &PCHS, &LCHS, VD_OPEN_FLAGS_NORMAL,
     589                      &PCHS, &LCHS, NULL, VD_OPEN_FLAGS_NORMAL,
    590590                      NULL, NULL);
    591591    CHECK("VDCreateBase()");
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette