LLVM  4.0.0
MSFCommon.cpp
Go to the documentation of this file.
1 //===- MSFCommon.cpp - Common types and functions for MSF files -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
12 
13 using namespace llvm;
14 using namespace llvm::msf;
15 
17  // Check the magic bytes.
18  if (std::memcmp(SB.MagicBytes, Magic, sizeof(Magic)) != 0)
19  return make_error<MSFError>(msf_error_code::invalid_format,
20  "MSF magic header doesn't match");
21 
22  if (!isValidBlockSize(SB.BlockSize))
23  return make_error<MSFError>(msf_error_code::invalid_format,
24  "Unsupported block size.");
25 
26  // We don't support directories whose sizes aren't a multiple of four bytes.
27  if (SB.NumDirectoryBytes % sizeof(support::ulittle32_t) != 0)
28  return make_error<MSFError>(msf_error_code::invalid_format,
29  "Directory size is not multiple of 4.");
30 
31  // The number of blocks which comprise the directory is a simple function of
32  // the number of bytes it contains.
33  uint64_t NumDirectoryBlocks =
35 
36  // The directory, as we understand it, is a block which consists of a list of
37  // block numbers. It is unclear what would happen if the number of blocks
38  // couldn't fit on a single block.
39  if (NumDirectoryBlocks > SB.BlockSize / sizeof(support::ulittle32_t))
40  return make_error<MSFError>(msf_error_code::invalid_format,
41  "Too many directory blocks.");
42 
43  if (SB.BlockMapAddr == 0)
44  return make_error<MSFError>(msf_error_code::invalid_format,
45  "Block 0 is reserved");
46 
47  if (SB.BlockMapAddr >= SB.NumBlocks)
48  return make_error<MSFError>(msf_error_code::invalid_format,
49  "Block map address is invalid.");
50 
51  if (SB.FreeBlockMapBlock != 1 && SB.FreeBlockMapBlock != 2)
52  return make_error<MSFError>(
54  "The free block map isn't at block 1 or block 2.");
55 
56  return Error::success();
57 }
char MagicBytes[sizeof(Magic)]
Definition: MSFCommon.h:33
Error validateSuperBlock(const SuperBlock &SB)
Definition: MSFCommon.cpp:16
support::ulittle32_t BlockSize
Definition: MSFCommon.h:37
support::ulittle32_t BlockMapAddr
Definition: MSFCommon.h:49
INITIALIZE_PASS(HexagonEarlyIfConversion,"hexagon-eif","Hexagon early if conversion", false, false) bool HexagonEarlyIfConversion MachineBasicBlock * SB
static const char Magic[]
Definition: MSFCommon.h:24
static ErrorSuccess success()
Create a success value.
uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize)
Definition: MSFCommon.h:79
support::ulittle32_t FreeBlockMapBlock
Definition: MSFCommon.h:39
Lightweight error class with error context and mandatory checking.
bool isValidBlockSize(uint32_t Size)
Definition: MSFCommon.h:61
support::ulittle32_t NumDirectoryBytes
Definition: MSFCommon.h:45
support::ulittle32_t NumBlocks
Definition: MSFCommon.h:43