| 1 | // -------------------------------------------------------------------------- |
|---|
| 2 | // |
|---|
| 3 | // File |
|---|
| 4 | // Name: StoreStructure.cpp |
|---|
| 5 | // Purpose: |
|---|
| 6 | // Created: 11/12/03 |
|---|
| 7 | // |
|---|
| 8 | // -------------------------------------------------------------------------- |
|---|
| 9 | |
|---|
| 10 | #include "Box.h" |
|---|
| 11 | |
|---|
| 12 | #include "StoreStructure.h" |
|---|
| 13 | #include "RaidFileRead.h" |
|---|
| 14 | #include "RaidFileWrite.h" |
|---|
| 15 | #include "RaidFileController.h" |
|---|
| 16 | |
|---|
| 17 | #include "MemLeakFindOn.h" |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | // -------------------------------------------------------------------------- |
|---|
| 21 | // |
|---|
| 22 | // Function |
|---|
| 23 | // Name: StoreStructure::MakeObjectFilename(int64_t, const std::string &, int, std::string &, bool) |
|---|
| 24 | // Purpose: Builds the object filename for a given object, given a root. Optionally ensure that the |
|---|
| 25 | // directory exists. |
|---|
| 26 | // Created: 11/12/03 |
|---|
| 27 | // |
|---|
| 28 | // -------------------------------------------------------------------------- |
|---|
| 29 | void StoreStructure::MakeObjectFilename(int64_t ObjectID, const std::string &rStoreRoot, int DiscSet, std::string &rFilenameOut, bool EnsureDirectoryExists) |
|---|
| 30 | { |
|---|
| 31 | const static char *hex = "0123456789abcdef"; |
|---|
| 32 | |
|---|
| 33 | // Set output to root string |
|---|
| 34 | rFilenameOut = rStoreRoot; |
|---|
| 35 | |
|---|
| 36 | // get the id value from the stored object ID so we can do |
|---|
| 37 | // bitwise operations on it. |
|---|
| 38 | uint64_t id = (uint64_t)ObjectID; |
|---|
| 39 | |
|---|
| 40 | // get leafname, shift the bits which make up the leafname off |
|---|
| 41 | unsigned int leafname(id & STORE_ID_SEGMENT_MASK); |
|---|
| 42 | id >>= STORE_ID_SEGMENT_LENGTH; |
|---|
| 43 | |
|---|
| 44 | // build pathname |
|---|
| 45 | while(id != 0) |
|---|
| 46 | { |
|---|
| 47 | // assumes that the segments are no bigger than 8 bits |
|---|
| 48 | int v = id & STORE_ID_SEGMENT_MASK; |
|---|
| 49 | rFilenameOut += hex[(v & 0xf0) >> 4]; |
|---|
| 50 | rFilenameOut += hex[v & 0xf]; |
|---|
| 51 | rFilenameOut += DIRECTORY_SEPARATOR_ASCHAR; |
|---|
| 52 | |
|---|
| 53 | // shift the bits we used off the pathname |
|---|
| 54 | id >>= STORE_ID_SEGMENT_LENGTH; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | // Want to make sure this exists? |
|---|
| 58 | if(EnsureDirectoryExists) |
|---|
| 59 | { |
|---|
| 60 | if(!RaidFileRead::DirectoryExists(DiscSet, rFilenameOut)) |
|---|
| 61 | { |
|---|
| 62 | // Create it |
|---|
| 63 | RaidFileWrite::CreateDirectory(DiscSet, rFilenameOut, true /* recusive */); |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | // append the filename |
|---|
| 68 | rFilenameOut += 'o'; |
|---|
| 69 | rFilenameOut += hex[(leafname & 0xf0) >> 4]; |
|---|
| 70 | rFilenameOut += hex[leafname & 0xf]; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | // -------------------------------------------------------------------------- |
|---|
| 75 | // |
|---|
| 76 | // Function |
|---|
| 77 | // Name: StoreStructure::MakeWriteLockFilename(const std::string &, int, std::string &) |
|---|
| 78 | // Purpose: Generate the on disc filename of the write lock file |
|---|
| 79 | // Created: 15/12/03 |
|---|
| 80 | // |
|---|
| 81 | // -------------------------------------------------------------------------- |
|---|
| 82 | void StoreStructure::MakeWriteLockFilename(const std::string &rStoreRoot, int DiscSet, std::string &rFilenameOut) |
|---|
| 83 | { |
|---|
| 84 | // Find the disc set |
|---|
| 85 | RaidFileController &rcontroller(RaidFileController::GetController()); |
|---|
| 86 | RaidFileDiscSet &rdiscSet(rcontroller.GetDiscSet(DiscSet)); |
|---|
| 87 | |
|---|
| 88 | // Make the filename |
|---|
| 89 | std::string writeLockFile(rdiscSet[0] + DIRECTORY_SEPARATOR + rStoreRoot + "write.lock"); |
|---|
| 90 | |
|---|
| 91 | // Return it to the caller |
|---|
| 92 | rFilenameOut = writeLockFile; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | |
|---|