Author: mmu_man Date: 2011-10-31 14:33:40 +0100 (Mon, 31 Oct 2011) New Revision: 43033 Changeset: https://dev.haiku-os.org/changeset/43033 Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.h Log: Add creation of a be:volume_id attribute on the root node as BeOS did, based on a patch by phcoder. Thanks! Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp 2011-10-31 13:32:22 UTC (rev 43032) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.cpp 2011-10-31 13:33:40 UTC (rev 43033) @@ -10,6 +10,7 @@ #include "Volume.h" #include "Journal.h" #include "Inode.h" +#include "Attribute.h" #include "Query.h" @@ -412,19 +413,28 @@ // 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); + if (attr.Get ("be:volume_id") == B_ENTRY_NOT_FOUND) + CreateVolumeID(); + } + + // all went fine + opener.Keep(); + return B_OK; } @@ -502,6 +512,33 @@ status_t +Volume::CreateVolumeID() +{ + Attribute attr(fRootNode); + status_t status; + attr_cookie* cookie; + status = attr.Create("be:volume_id", B_UINT64_TYPE, O_RDWR, &cookie); + if (status == B_OK) { + static bool seeded = false; + if (!seeded) { + // seed the random number generator for the be:volume_id attribute. + srand(time(NULL)); + seeded = true; + } + uint64_t id; + size_t len = sizeof (id); + id = ((uint64_t) rand () << 32) | rand (); + Transaction transaction(this, fRootNode->BlockNumber()); + fRootNode->WriteLockInTransaction(transaction); + attr.Write(transaction, cookie, 0, (uint8_t *) &id, &len, NULL); + transaction.Done(); + } + return status; +} + + + +status_t Volume::AllocateForInode(Transaction& transaction, const Inode* parent, mode_t type, block_run& run) { @@ -732,6 +769,8 @@ return status; } + CreateVolumeID(); + WriteSuperBlock(); transaction.Done(); Modified: haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.h 2011-10-31 13:32:22 UTC (rev 43032) +++ haiku/trunk/src/add-ons/kernel/file_systems/bfs/Volume.h 2011-10-31 13:33:40 UTC (rev 43033) @@ -92,6 +92,8 @@ status_t CreateIndicesRoot(Transaction& transaction); + status_t CreateVolumeID(); + InodeList& RemovedInodes() { return fRemovedInodes; } // This list is guarded by the transaction lock