From 9b7ff360a0be19bb16d926df971e802ea7d5c742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Mon, 31 Oct 2011 13:33:40 +0000 Subject: [PATCH] Add creation of a be:volume_id attribute on the root node as BeOS did, based on a patch by phcoder. Thanks! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43033 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/bfs/Volume.cpp | 49 +++++++++++++++++-- src/add-ons/kernel/file_systems/bfs/Volume.h | 2 + 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Volume.cpp b/src/add-ons/kernel/file_systems/bfs/Volume.cpp index a7166947f3..22619861d4 100644 --- a/src/add-ons/kernel/file_systems/bfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Volume.cpp @@ -10,6 +10,7 @@ #include "Volume.h" #include "Journal.h" #include "Inode.h" +#include "Attribute.h" #include "Query.h" @@ -412,19 +413,28 @@ Volume::Mount(const char* deviceName, uint32 flags) // 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; } @@ -501,6 +511,33 @@ Volume::CreateIndicesRoot(Transaction& transaction) } +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 @@ Volume::Initialize(int fd, const char* name, uint32 blockSize, return status; } + CreateVolumeID(); + WriteSuperBlock(); transaction.Done(); diff --git a/src/add-ons/kernel/file_systems/bfs/Volume.h b/src/add-ons/kernel/file_systems/bfs/Volume.h index 562ea21375..500a00f682 100644 --- a/src/add-ons/kernel/file_systems/bfs/Volume.h +++ b/src/add-ons/kernel/file_systems/bfs/Volume.h @@ -92,6 +92,8 @@ public: status_t CreateIndicesRoot(Transaction& transaction); + status_t CreateVolumeID(); + InodeList& RemovedInodes() { return fRemovedInodes; } // This list is guarded by the transaction lock