#ifndef BITMAP_H
#define BITMAP_H
#define _WIN32_WINNT 0x600
#include "windows.h"
#include "winioctl.h"
#include <vector>
#include <map>
using namespace std;
class BitMap
{
public:
void getMapList(const VOLUME_BITMAP_BUFFER *pInBuff);
void dispalyMapListOfFree() const;
void showVecOfBit() const;
const map<ULONGLONG, ULONGLONG> & returnMaplist() const;
const vector<bool> & returnBitVec() const;
private:
map<ULONGLONG, ULONGLONG> mapListOfFree;
vector<bool> vecOfBit;
};
#endif
================================ ================
#include "bitmap.h"
#include <iostream>
#include <bitset>
#include <fstream>
void BitMap::getMapList(const VOLUME_BITMAP_BUFFER *pInBuff)
{
ULONGLONG count_size = 0;
ULONGLONG size_clusterarray = (pInBuff -> BitmapSize.QuadPart + 7) / 8;
while (count_size != size_clusterarray)
{
bitset<8> bit(*(pInBuff -> Buffer + count_size));
for (int i = 0; i != 8; ++i)
{
vecOfBit.push_back(bit[i]);
}
count_size++;
}
if (vecOfBit.size() != pInBuff -> BitmapSize.QuadPart)
{
ULONGLONG popnum = vecOfBit.size() - pInBuff -> BitmapSize.QuadPart;
for (ULONGLONG i = 0; i < popnum; ++i)
{
vecOfBit.pop_back();
}
}
ULONGLONG add = 0;
ULONGLONG size = 0;
for (ULONGLONG i = 0; i < vecOfBit.size();)
{
size = 0;
if (vecOfBit[i] == 0)
{
add = i;
ULONGLONG idx = i;
while ((idx < vecOfBit.size()) && !vecOfBit[idx]) //
{
size ++;
idx++;
}
i += size;
mapListOfFree.insert(make_pair(add, size));
}
else
{
i++;
continue;
}
}
}
void BitMap::showVecOfBit() const
{
fstream vecbit("bitmap.txt", ios_base::out);
if (!vecbit) return;
for (ULONGLONG i = 0; i < vecOfBit.size(); ++i)
{
if (i % 32 == 0)
{
vecbit << endl;
}
vecbit << (DWORD)vecOfBit[i] << " ";
}
vecbit.close();
}
void BitMap::dispalyMapListOfFree() const
{
cout << "Free Space List <start cluster number, free space size>" << endl;
for (map<ULONGLONG, ULONGLONG>::const_iterator cit = mapListOfFree.begin(); cit != mapListOfFree.end(); ++cit)
{
cout << "address: " << ULONG((*cit).first) << "/tsize: " << ULONG((*cit).second) << endl;
}
}
const map<ULONGLONG, ULONGLONG>& BitMap::returnMaplist() const
{
return mapListOfFree;
}
const vector<bool>& BitMap::returnBitVec() const
{
return vecOfBit;
}
=================================================
#ifndef MOVFLE_H
#define NOVFLE_H
#include <string>
#include <map>
using namespace std;
#define _WIN32_WINNT 0
#define BITMAP_H
#define _WIN32_WINNT 0x600
#include "windows.h"
#include "winioctl.h"
#include <vector>
#include <map>
using namespace std;
class BitMap
{
public:
void getMapList(const VOLUME_BITMAP_BUFFER *pInBuff);
void dispalyMapListOfFree() const;
void showVecOfBit() const;
const map<ULONGLONG, ULONGLONG> & returnMaplist() const;
const vector<bool> & returnBitVec() const;
private:
map<ULONGLONG, ULONGLONG> mapListOfFree;
vector<bool> vecOfBit;
};
#endif
================================ ================
#include "bitmap.h"
#include <iostream>
#include <bitset>
#include <fstream>
void BitMap::getMapList(const VOLUME_BITMAP_BUFFER *pInBuff)
{
ULONGLONG count_size = 0;
ULONGLONG size_clusterarray = (pInBuff -> BitmapSize.QuadPart + 7) / 8;
while (count_size != size_clusterarray)
{
bitset<8> bit(*(pInBuff -> Buffer + count_size));
for (int i = 0; i != 8; ++i)
{
vecOfBit.push_back(bit[i]);
}
count_size++;
}
if (vecOfBit.size() != pInBuff -> BitmapSize.QuadPart)
{
ULONGLONG popnum = vecOfBit.size() - pInBuff -> BitmapSize.QuadPart;
for (ULONGLONG i = 0; i < popnum; ++i)
{
vecOfBit.pop_back();
}
}
ULONGLONG add = 0;
ULONGLONG size = 0;
for (ULONGLONG i = 0; i < vecOfBit.size();)
{
size = 0;
if (vecOfBit[i] == 0)
{
add = i;
ULONGLONG idx = i;
while ((idx < vecOfBit.size()) && !vecOfBit[idx]) //
{
size ++;
idx++;
}
i += size;
mapListOfFree.insert(make_pair(add, size));
}
else
{
i++;
continue;
}
}
}
void BitMap::showVecOfBit() const
{
fstream vecbit("bitmap.txt", ios_base::out);
if (!vecbit) return;
for (ULONGLONG i = 0; i < vecOfBit.size(); ++i)
{
if (i % 32 == 0)
{
vecbit << endl;
}
vecbit << (DWORD)vecOfBit[i] << " ";
}
vecbit.close();
}
void BitMap::dispalyMapListOfFree() const
{
cout << "Free Space List <start cluster number, free space size>" << endl;
for (map<ULONGLONG, ULONGLONG>::const_iterator cit = mapListOfFree.begin(); cit != mapListOfFree.end(); ++cit)
{
cout << "address: " << ULONG((*cit).first) << "/tsize: " << ULONG((*cit).second) << endl;
}
}
const map<ULONGLONG, ULONGLONG>& BitMap::returnMaplist() const
{
return mapListOfFree;
}
const vector<bool>& BitMap::returnBitVec() const
{
return vecOfBit;
}
=================================================
#ifndef MOVFLE_H
#define NOVFLE_H
#include <string>
#include <map>
using namespace std;
#define _WIN32_WINNT 0