Compare commits
3 commits
782d8db162
...
7c84b7bcee
Author | SHA1 | Date | |
---|---|---|---|
|
7c84b7bcee | ||
|
890c08c2ee | ||
|
ca02fd7338 |
3 changed files with 51 additions and 21 deletions
24
inode.c
24
inode.c
|
@ -1 +1,25 @@
|
||||||
#include "inode.h"
|
#include "inode.h"
|
||||||
|
|
||||||
|
Inode* find_inode(char filename[], struct inode_table* itable) {
|
||||||
|
for (uint32_t i = 0; i < itable->size; i++) {
|
||||||
|
if (strcmp(filename, itable->inodes[i]->name)) {
|
||||||
|
return itable->inodes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool inode_exists(struct inode_table* itable, char filename[]) {
|
||||||
|
for (uint32_t i = 0; i < itable->size; i++) {
|
||||||
|
if (strcmp(filename, itable->inodes[i]->name)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void delete_inode(struct inode_table* itable, char filename[]) {
|
||||||
|
Inode* wanted_inode = find_inode(filename, itable);
|
||||||
|
free(wanted_inode);
|
||||||
|
wanted_inode = NULL;
|
||||||
|
}
|
||||||
|
|
31
inode.h
31
inode.h
|
@ -3,31 +3,54 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
typedef struct Inode Inode;
|
typedef struct Inode Inode;
|
||||||
|
|
||||||
|
enum permissions {
|
||||||
|
R = 1,
|
||||||
|
W = 2,
|
||||||
|
X = 4
|
||||||
|
};
|
||||||
|
|
||||||
|
struct inode_table {
|
||||||
|
// the following keyword spam purely exist so I definitely see it with highlighting.
|
||||||
|
// NOTE, TODO, FIXME, DEPRECATED, HACK, IMPORTANT: always initialize all values to be null when the inode table is created!!!!
|
||||||
|
// TODO: Change currently hardcoded value to actually accurately describe the size of the filesystem, only for temporary purposes.
|
||||||
|
Inode* inodes[640000];
|
||||||
|
uint32_t size;
|
||||||
|
uint32_t used_inodes;
|
||||||
|
uint32_t free_inodes;
|
||||||
|
};
|
||||||
|
|
||||||
struct Inode {
|
struct Inode {
|
||||||
// file information
|
// file information
|
||||||
char name[64];
|
char name[64];
|
||||||
uint32_t filesize;
|
uint32_t filesize;
|
||||||
|
|
||||||
// ownership and permissions
|
// ownership and permissions
|
||||||
uint16_t permissions;
|
uint8_t user_permissions;
|
||||||
|
uint8_t group_permissions;
|
||||||
|
|
||||||
|
// UID
|
||||||
uint16_t owner;
|
uint16_t owner;
|
||||||
|
// GID
|
||||||
uint16_t group;
|
uint16_t group;
|
||||||
|
|
||||||
// timestamps
|
// timestamps
|
||||||
tm created;
|
tm created;
|
||||||
tm last_modified;
|
tm last_modified;
|
||||||
|
|
||||||
// fs attributes
|
|
||||||
uint32_t index;
|
|
||||||
uint16_t block_count;
|
uint16_t block_count;
|
||||||
block* data_block;
|
block* data_block;
|
||||||
};
|
};
|
||||||
|
|
||||||
Inode* create_inode(char name[64], uint16_t owner, uint16_t group, block* data_block);
|
Inode* create_inode(char name[64], uint8_t user_permissions, uint8_t group_permissions, uint16_t owner, uint16_t group, block* data_block);
|
||||||
|
Inode* find_inode(char filename[], struct inode_table* itable);
|
||||||
|
bool inode_exists(struct inode_table* itable, char filename[]);
|
||||||
|
void delete_inode(struct inode_table* itable, char filename[]);
|
||||||
|
|
||||||
#endif // INODE_H_
|
#endif // INODE_H_
|
||||||
|
|
17
super.c
17
super.c
|
@ -9,14 +9,6 @@
|
||||||
#define VERSION 0.0.0.1
|
#define VERSION 0.0.0.1
|
||||||
#define BLOCKSIZE 4096
|
#define BLOCKSIZE 4096
|
||||||
|
|
||||||
uint32_t free_blocks;
|
|
||||||
uint32_t inode_count;
|
|
||||||
|
|
||||||
struct inode_table {
|
|
||||||
// TODO: Change currently hardcoded value to actually accurately describe the size of the filesystem, only for temporary purposes.
|
|
||||||
Inode* inodes[640000];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct super_block {
|
struct super_block {
|
||||||
// fs info
|
// fs info
|
||||||
char version[8];
|
char version[8];
|
||||||
|
@ -35,13 +27,4 @@ struct super_block {
|
||||||
struct inode_table* inode_table;
|
struct inode_table* inode_table;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Do research on how the fuck to actually do this kind of Array operation
|
|
||||||
Inode* find_inode(char filename[], struct super_block sblock) {
|
|
||||||
struct inode_table* itable = sblock.inode_table;
|
|
||||||
// while (itable[inode] != NULL; inode++) {
|
|
||||||
// if (strcmp(filename, itable[inode]->filesize))
|
|
||||||
// }
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // SUPER_H_
|
#endif // SUPER_H_
|
||||||
|
|
Loading…
Reference in a new issue