You are on page 1of 3

/*

* Blood sacrifice to bypass the Scribd paywall.


* Feel free to use any bits or pieces you may want of this, but know it's just
toy code and
* there's no support or warrenty with this.
*
* Daniel Korczak
*/
#include <ctime>
#include <cstring>
#include <stdint.h>

//Timestamps
//Memcpy requires this, and object names
//unsigned ints of variable length

#define _INODE_NAME_LENGTH 25
// FOR THE LOVE OF GOD, BE CAREFUL WITH BINARY WRITE() AND WRITING CLASSES.
// ANY (AND ALL) POINTER VALUES WILL NOT BE WRITEN. DO NOT WANT.
class Inode{
public:
Inode();
Inode( char name[], bool isDir, uint32_t size, uint8_t blocksAll
ocated, int32_t diskPointers[32]);
char
name[_INODE_NAME_LENGTH];
//25 spots for n
ow. Sorry.
bool
isDir;
//Flag is used to indicate that the object represents a directory.
//If true, the diskPointer array holds Inode #'s of other objects stored in it.
First cell is the parent dir.
uint32_t
size;
//size of file in BYTES
time_t
creationTime;
//Time o
f creation
time_t
lastModifiedTime;
//Time o
f last modification
uint8_t
linkCount;
//Total number of things that link to this. 0 = nothing, therefore usable space.
uint8_t
blocksAllocated;
//The nu
mber of data blocks that are allocated for this file
int32_t
diskPointers[32];
//The in
dex of the disks used. Use these numbers to reference the dataBlocks in use.
//Value of "-1" indicates this block and all later blocks are not used.
/*
*
Updates the last modified time with the current time. This epoch
time must be converted to readable format.
*/
void setLastModified(){
this->lastModifiedTime = getCurTime();
}
/*
* Used when another directory links hard to this file. (OR FILE CREATION
)
*/

bool increaseLinkCount(){
this->linkCount++;
return true;
}
/*
* Used when another directory removes a hard link to this file (IE FILE
DELETION)
*/
bool decreaseLinkCount(){
if( this->linkCount == 0 ){
return false;
//Protect against negative linkCount.
}
else{
this->linkCount = this->linkCount--;
return true;
}
}
/*
* Debug feature that just prints a node to stdout.
*/
void printInode(){
std::cout << "name is: "
<< this>name << "\n";
std::cout << "size is: "
<< this>size << "\n";
std::cout << "creationTime is: "
<< this->creatio
nTime << "\n";
std::cout << "lastModifiedTime is: "
<< this->lastModifiedTim
e << "\n";
std::cout << "linkCount is: "
<< (int) this->l
inkCount << "\n";
std::cout << "blocks allocated is: "
<< (int) this->blocksAll
ocated << "\n";
for(int i = 0; i < 32; i++){
//
std::cout << "this diskPointer is: "<< this->diskPointer
s[i] << "\n";
}
}
private:
/*
*
Returns current local time from std C lib time.h
*/
time_t getCurTime(){
time_t curTime;
time ( &curTime );
return curTime;
}
};
/*
*
Dud constructor, but will be used to fill arrays up. All values set to 0
.
*/
Inode::Inode(){

memcpy(this->name, "null", 5);


this->isDir
this->size
this->creationTime
= 0;
probably need to be commented out.
this->lastModifiedTime
= 0;
y need to be commented out.
this->linkCount
= 0;
this->blocksAllocated
= 0;
for(int i = 0; i < 32; i++){
thing is set to -1 (not used).
this->diskPointers[i] = -1;
}
}

= false;
= 0;
//May bomb. Will
//May bomb. Will probabl

//Just making sure every

/*
*
The actually useful constructor. This construtor is used when we create
a file.
*/
Inode::Inode( char name[], bool isDir, uint32_t size, uint8_t blocksAllocated, i
nt32_t diskPointers[32]){
//std::cout << "Sizeof time_t is: " << sizeof(time_t) << "\n";
memcpy(this->name, name, (sizeof(name)/sizeof(name[0])) );
//may need to be strcpy'd or memcpy'd. I forget those rules.
this->isDir
= isDir;
this->size
= size;
this->creationTime
= getCurTime();
this->lastModifiedTime = getCurTime();
this->linkCount
= 1;
//On cre
ation, this is only linked to one(1).
this->blocksAllocated = blocksAllocated;
//Amount of data blocks
used to create this file.
for(int i = 0; i < (sizeof(this->diskPointers)/sizeof(diskPointers[0]));
i++ ){
this->diskPointers[i] = diskPointers[i];
}
}

You might also like