This patch adds handling BFS UUID. However it has a problem of using bad random numbers. Can someone suggest a better RNG in Haiku? -- Regards Vladimir 'φ-coder/phcoder' Serbinenko
Index: src/add-ons/kernel/file_systems/bfs/Volume.cpp =================================================================== --- src/add-ons/kernel/file_systems/bfs/Volume.cpp (revision 42928) +++ src/add-ons/kernel/file_systems/bfs/Volume.cpp (working copy) @@ -10,6 +10,7 @@ #include "Volume.h" #include "Journal.h" #include "Inode.h" +#include "Attribute.h" #include "Query.h" @@ -412,19 +413,45 @@ // we don't use the vnode layer to access the indices node } - // all went fine - opener.Keep(); - return B_OK; } else + { FATAL(("could not create root node: publish_vnode() failed!\n")); + delete fRootNode; + return status; + } - delete fRootNode; } else { status = B_BAD_VALUE; FATAL(("could not create root node!\n")); + return status; } - return status; + if (!(fFlags & VOLUME_READ_ONLY)) { + Attribute attr(fRootNode); + status_t s; + s = attr.Get ("be:volume_id"); + if (s == B_ENTRY_NOT_FOUND) { + attr_cookie* cookie; + s = attr.Create("be:volume_id", 0x554c4c47, O_RDWR, + &cookie); + if (s == B_OK) { + uint64_t vid; + size_t len = sizeof (vid); + Transaction transaction(this, + fRootNode->BlockNumber()); + srand(time(NULL)); + vid = ((uint64_t) rand () << 32) | rand (); + fRootNode->WriteLockInTransaction(transaction); + attr.Write(transaction, cookie, 0, + (uint8_t *) &vid, &len, NULL); + transaction.Done(); + } + } + } + + // all went fine + opener.Keep(); + return B_OK; } @@ -732,6 +759,23 @@ return status; } + { + Attribute attr(fRootNode); + status_t s; + attr_cookie* cookie; + s = attr.Create("be:volume_id", 0x554c4c47, O_RDWR, + &cookie); + if (s == B_OK) { + uint64_t vid; + size_t len = sizeof (vid); + srand(time(NULL)); + vid = ((uint64_t) rand () << 32) | rand (); + attr.Write(transaction, cookie, 0, + (uint8_t *) &vid, &len, NULL); + } + } + + WriteSuperBlock(); transaction.Done();