Skip to content
Permalink
Browse files

Used CLion to format everything so pretty

  • Loading branch information
joshspicer committed Dec 3, 2017
1 parent 11263dd commit 3b6959d1639427837a0cdb454ed1a4e117d28ab1
Showing with 314 additions and 334 deletions.
  1. +20 −12 hints/directory.h
  2. +64 −85 nufs.c
  3. +107 −113 pages.c
  4. +23 −13 pages.h
  5. +8 −12 slist.c
  6. +8 −6 slist.h
  7. +73 −81 storage.c
  8. +7 −4 storage.h
  9. +4 −8 util.h
@@ -8,25 +8,33 @@
#include "pages.h"

typedef struct dirent {
char name[48];
int pnum;
pnode* node;
char name[48];
int pnum;
pnode *node;
} dirent;

typedef struct directory {
int pnum;
dirent* ents;
pnode* node;
int pnum;
dirent *ents;
pnode *node;
} directory;

void directory_init();

directory directory_from_pnum(int pnum);
int directory_lookup_pnum(directory dd, const char* name);
int tree_lookup_pnum(const char* path);
directory directory_from_path(const char* path);
int directory_put_ent(directory dd, const char* name, int pnum);
int directory_delete(directory dd, const char* name);
slist* directory_list(const char* path);

int directory_lookup_pnum(directory dd, const char *name);

int tree_lookup_pnum(const char *path);

directory directory_from_path(const char *path);

int directory_put_ent(directory dd, const char *name, int pnum);

int directory_delete(directory dd, const char *name);

slist *directory_list(const char *path);

void print_directory(directory dd);

#endif
149 nufs.c
@@ -1,43 +1,36 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/stat.h>
#include <dirent.h>
#include <bsd/string.h>
#include <assert.h>
#include <stdlib.h>

#define FUSE_USE_VERSION 26

#include <fuse.h>

#include "storage.h"
// Josh added this
#include "pages.h"
#include "util.h"

// implementation for: man 2 access
// Checks if a file exists.
int
nufs_access(const char *path, int mask)
{
nufs_access(const char *path, int mask) {
printf("access(%s, %04o)\n", path, mask);
return 0;
}

// implementation for: man 2 stat
// gets an object's attributes (type, permissions, size, etc)
int
nufs_getattr(const char *path, struct stat *st)
{
nufs_getattr(const char *path, struct stat *st) {
printf("getattr(%s)\n", path);

int rv = get_stat(path, st);
if (rv == -1) {
return -ENOENT;
}
else {
} else {
return 0;
}

@@ -48,8 +41,7 @@ nufs_getattr(const char *path, struct stat *st)
// lists the contents of a directory
int
nufs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
off_t offset, struct fuse_file_info *fi)
{
off_t offset, struct fuse_file_info *fi) {
struct stat st;
printf("readdir(%s)\n", path);

@@ -64,20 +56,20 @@ nufs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,

for (int i = 0; i < GET_NUMBER_OF_INODES(); i++) {

//TODO: Once we implement directories, this has to change!!
//TODO: Once we implement directories, this has to change!!

// check inode bitmap. If value isn't one, then that inode isn't active.
if(*((int*)(GET_ptr_start_iNode_bitMap() + sizeof(int)*i)) != 1) {
continue;
}
// There must be an associated iNode. Calculate address.
void* currentPtr = ((void*)(GET_ptr_start_iNode_Table() + sizeof(pnode)*i));
pnode* current = ((pnode*)currentPtr);
// check inode bitmap. If value isn't one, then that inode isn't active.
if (*((int *) (GET_ptr_start_iNode_bitMap() + sizeof(int) * i)) != 1) {
continue;
}
// There must be an associated iNode. Calculate address.
void *currentPtr = ((void *) (GET_ptr_start_iNode_Table() + sizeof(pnode) * i));
pnode *current = ((pnode *) currentPtr);

if (!(streq(current->path, "/"))) {
get_stat(current->path, &st);
filler(buf, current->name, &st, 0);
}
if (!(streq(current->path, "/"))) {
get_stat(current->path, &st);
filler(buf, current->name, &st, 0);
}
}

// get_stat("/hello.txt", &st);
@@ -89,8 +81,7 @@ nufs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
// mknod makes a filesystem object like a file or directory
// called for: man 2 open, man 2 link
int
nufs_mknod(const char *path, mode_t mode, dev_t rdev)
{
nufs_mknod(const char *path, mode_t mode, dev_t rdev) {

//open(path, O_CREAT, mode); --- maybe for mode do S_IRWXU | mode
//link()
@@ -101,36 +92,34 @@ nufs_mknod(const char *path, mode_t mode, dev_t rdev)

// If there's no free iNodes, return -1
if (index == -1) {
printf("%s\n","ERROR: No free iNode slots. Cannot mknod");
return -1;
printf("%s\n", "ERROR: No free iNode slots. Cannot mknod");
return -1;
}

flip_iNode_bit(index, 1);
add_node(path, mode, 0, index);

print_node((pnode*)(GET_ptr_start_iNode_Table() + sizeof(pnode)*index));
print_node((pnode *) (GET_ptr_start_iNode_Table() + sizeof(pnode) * index));

return 0; // was -1
}

// most of the following callbacks implement
// another system call; see section 2 of the manual
int
nufs_mkdir(const char *path, mode_t mode)
{
nufs_mkdir(const char *path, mode_t mode) {
printf("mkdir(%s)\n", path);
return -1;
}

int
nufs_unlink(const char *path)
{
nufs_unlink(const char *path) {
printf("unlink(%s)\n", path);

pnode* node = get_file_data(path);
pnode *node = get_file_data(path);

if (!node) {
printf("Cannot remove path because path does not exist.\n");
printf("Cannot remove path because path does not exist.\n");
}

flip_iNode_bit(node->nodeID, 0);
@@ -140,8 +129,7 @@ nufs_unlink(const char *path)
}

int
nufs_rmdir(const char *path)
{
nufs_rmdir(const char *path) {
printf("rmdir(%s)\n", path);

// pnode* node = get_file_data(path);
@@ -160,33 +148,30 @@ nufs_rmdir(const char *path)
// implements: man 2 rename
// called to move a file within the same filesystem
int
nufs_rename(const char *from, const char *to)
{
nufs_rename(const char *from, const char *to) {
printf("rename(%s => %s)\n", from, to);

pnode* node = get_file_data(from);
pnode *node = get_file_data(from);

if (!node) {
printf("Cannot rename file or directory because it does not exist.\n");
printf("Cannot rename file or directory because it does not exist.\n");
}

name_node(node, to);

return 0;
}

int
nufs_chmod(const char *path, mode_t mode)
{
nufs_chmod(const char *path, mode_t mode) {
printf("chmod(%s, %04o)\n", path, mode);
return -1;
}

int
nufs_truncate(const char *path, off_t size)
{
nufs_truncate(const char *path, off_t size) {

// VERY BIG TODO: implement this
// VERY BIG TODO: implement this


//
@@ -201,18 +186,16 @@ nufs_truncate(const char *path, off_t size)
// since FUSE doesn't assume you maintain state for
// open files.
int
nufs_open(const char *path, struct fuse_file_info *fi)
{
nufs_open(const char *path, struct fuse_file_info *fi) {
printf("open(%s)\n", path);
return 0;
}

// Actually read data
int
nufs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
{
nufs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {
printf("read(%s, %ld bytes, @%ld)\n", path, size, offset);
const char* data = get_data(path);
const char *data = get_data(path);

int len = strlen(data) + 1; // strlen(data) + 1
if (size < len) {
@@ -226,27 +209,26 @@ nufs_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_fi
// Actually write data
int
nufs_write(const char *path, const char *buf, size_t size, off_t offset,
struct fuse_file_info *fi)
{
printf("write(%s, %ld bytes, %ld)\n", path, size, offset);
struct fuse_file_info *fi) {
printf("write(%s, %ld bytes, %ld)\n", path, size, offset);

// Get the node associated with this path.
pnode* node = get_file_data(path);
pnode *node = get_file_data(path);

if (!node) {
printf("%s\n","YOU CAN'T WRITE TO A FILE THAT DOESN'T EXIST!");
return -1; //TODO return error code.
printf("%s\n", "YOU CAN'T WRITE TO A FILE THAT DOESN'T EXIST!");
return -1; //TODO return error code.
}

// We definitely want a positive blockID
assert(node->blockID != -1);

// Calculate the memory address of this block's data.
void* ptr = data_block_ptr_at_index(node->blockID);
void *ptr = data_block_ptr_at_index(node->blockID);

// Write to that memory location (using the given buffer/size/offset)
//ptr = buf;
memcpy(ptr,buf,size);
memcpy(ptr, buf, size);
//int fd = fi->direct_io;

// TODO Change stat somehow??? (I don't get stat.)
@@ -260,42 +242,39 @@ nufs_write(const char *path, const char *buf, size_t size, off_t offset,

// Update the timestamps on a file or directory.
int
nufs_utimens(const char* path, const struct timespec ts[2])
{
// //int rv = storage_set_time(path, ts);
int rv = -1;
printf("utimens(%s, [%ld, %ld; %ld %ld]) -> %d\n",
nufs_utimens(const char *path, const struct timespec ts[2]) {
// //int rv = storage_set_time(path, ts);
int rv = -1;
printf("utimens(%s, [%ld, %ld; %ld %ld]) -> %d\n",
path, ts[0].tv_sec, ts[0].tv_nsec, ts[1].tv_sec, ts[1].tv_nsec, rv);

// return rv;
return 0;
// return rv;
return 0;
}

void
nufs_init_ops(struct fuse_operations* ops)
{
nufs_init_ops(struct fuse_operations *ops) {
memset(ops, 0, sizeof(struct fuse_operations));
ops->access = nufs_access;
ops->getattr = nufs_getattr;
ops->readdir = nufs_readdir;
ops->mknod = nufs_mknod;
ops->mkdir = nufs_mkdir;
ops->unlink = nufs_unlink;
ops->rmdir = nufs_rmdir;
ops->rename = nufs_rename;
ops->chmod = nufs_chmod;
ops->access = nufs_access;
ops->getattr = nufs_getattr;
ops->readdir = nufs_readdir;
ops->mknod = nufs_mknod;
ops->mkdir = nufs_mkdir;
ops->unlink = nufs_unlink;
ops->rmdir = nufs_rmdir;
ops->rename = nufs_rename;
ops->chmod = nufs_chmod;
ops->truncate = nufs_truncate;
ops->open = nufs_open;
ops->read = nufs_read;
ops->write = nufs_write;
ops->utimens = nufs_utimens;
ops->open = nufs_open;
ops->read = nufs_read;
ops->write = nufs_write;
ops->utimens = nufs_utimens;
};

struct fuse_operations nufs_ops;

int
main(int argc, char *argv[])
{
main(int argc, char *argv[]) {
assert(argc > 2 && argc < 1000); //1000 was 6
storage_init(argv[--argc]);
nufs_init_ops(&nufs_ops);

0 comments on commit 3b6959d

Please sign in to comment.
You can’t perform that action at this time.