From 2dd5cf430edaae01594d566c9f27d780c3ffb4ef Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 26 Apr 2015 21:43:42 -0300 Subject: Initial commit --- mkfs.md/Makefile | 14 +++++++++ mkfs.md/disk.mdfs | Bin 0 -> 33554432 bytes mkfs.md/mkfs.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ mkfs.md/mkfs.md | Bin 0 -> 10016 bytes mkfs.md/out | 2 ++ 5 files changed, 106 insertions(+) create mode 100644 mkfs.md/Makefile create mode 100644 mkfs.md/disk.mdfs create mode 100644 mkfs.md/mkfs.c create mode 100644 mkfs.md/mkfs.md create mode 100644 mkfs.md/out (limited to 'mkfs.md') diff --git a/mkfs.md/Makefile b/mkfs.md/Makefile new file mode 100644 index 0000000..e91a5e5 --- /dev/null +++ b/mkfs.md/Makefile @@ -0,0 +1,14 @@ +FILES=mkfs.c +TARGET=mkfs.md +CFLAGS=-Wall -Werror -Wextra -g + +all: $(FILES) + clang $(CFLAGS) -o $(TARGET) $(FILES) + +with-inode: $(FILES) + clang $(CFLAGS) -D_HAS_TRACKED_INODE -o $(TARGET) $(FILES) + +clean: + rm -f $(TARGET) *.o + +.PHONY: clean diff --git a/mkfs.md/disk.mdfs b/mkfs.md/disk.mdfs new file mode 100644 index 0000000..0dae906 Binary files /dev/null and b/mkfs.md/disk.mdfs differ diff --git a/mkfs.md/mkfs.c b/mkfs.md/mkfs.c new file mode 100644 index 0000000..37c6e6e --- /dev/null +++ b/mkfs.md/mkfs.c @@ -0,0 +1,90 @@ +#include "../defs.h" +#include "../inode.h" + +#include + +#include +#include +#include +#include +#include + +#include +#include + +struct PACKED superblock { + uint16_t magic; + uint32_t free_size; + uint32_t max_size; +}; + +int main(int argc, char *argv[]) +{ + char *fs = NULL; + int fd = 0; + struct superblock *sb= NULL; + inode *rootdir = NULL; +#ifdef _HAS_TRACKED_INODE + direntry *dentry = NULL; +#endif + + if (argc != 2){ + printf("Uso: %s [file]\n" + "Necesita proveer un nombre para el filesystem", + argv[0]); + return -2; + } + + fd = open(argv[1], O_WRONLY | O_CREAT, 0777); + + fs = calloc (BLOCKS*BLOCK_SIZE, sizeof(char)); + if (!fs){ + fprintf(stderr, "No hay suficiente memoria para alocar el filesystem\n"); + return (1); + } + sb = (struct superblock *) fs; + + sb->magic = 0xF514; /* No hay ganas de hacer aritmetica con lo que esta en el defs.h */ + sb->max_size = BLOCK_SIZE * BLOCKPOOL_BLOCKS; + sb->free_size = BLOCK_SIZE * BLOCKPOOL_BLOCKS; + SET_BIT_1((char *)sb + FBB_OFFSET, 0); + /* El primer elemento del inodepool es el rootdir */ + SET_BIT_1((char*) sb + FIB_OFFSET, 1); + + + rootdir = (inode *) sb + INODEPOOL_OFFSET + sizeof(inode); + + rootdir->type = I_DIR; + rootdir->mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IXGRP | S_IRGRP | S_IROTH | S_IXOTH | S_IFDIR; + rootdir->uid = getuid(); + rootdir->gid = getgid(); + rootdir->indirect=2; + rootdir->atime = (uint32_t) time(NULL); + rootdir->ctime = (uint32_t) time(NULL); + rootdir->mtime = (uint32_t) time(NULL); + + rootdir->nlinks = 1; + +#ifndef _HAS_TRACKED_INODE + rootdir->size = 0; +#else + rootdir->size = sizeof(direntry); + /* Primer bloque */ + /*SET_BIT_1((char *)sb + FBB_OFFSET, 0); */ + dentry = (direntry *) sb + BLOCKPOOL_OFFSET; + dentry->inode = 0; + dentry->name[0] = '/'; + dentry->name[1] = '\0'; + dentry->symlink = 0; +#endif + + if ((write(fd, (void *) fs, BLOCKS*BLOCK_SIZE)) == -1){ + perror("write"); + close(fd); + return -1; + } + close(fd); + free(fs); + + return (0); +} diff --git a/mkfs.md/mkfs.md b/mkfs.md/mkfs.md new file mode 100644 index 0000000..90a9507 Binary files /dev/null and b/mkfs.md/mkfs.md differ diff --git a/mkfs.md/out b/mkfs.md/out new file mode 100644 index 0000000..ad97aa8 --- /dev/null +++ b/mkfs.md/out @@ -0,0 +1,2 @@ +clang -Wall -Werror -Wextra -g -std=c99 -o mkfs.md mkfs.c +Makefile:6: recipe for target 'all' failed -- cgit v1.2.3-70-g09d2