Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "LibFS.h"
- void usage(char *prog)
- {
- printf("USAGE: %s <disk_image_file>\n", prog);
- exit(1);
- }
- int main(int argc, char *argv[])
- {
- if (argc != 2) usage(argv[0]);
- if(FS_Boot(argv[1]) < 0) {
- printf("ERROR: can't boot file system from file '%s'\n", argv[1]);
- return -1;
- } else printf("file system booted from file '%s'\n", argv[1]);
- char* fn;
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1";
- if(Dir_Create(fn) < 0) printf("ERROR: can't create dir '%s'\n", fn);
- else printf("dir '%s' created successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1/file-1";
- if(File_Create(fn) < 0) printf("ERROR: can't create file '%s'\n", fn);
- else printf("file '%s' created successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1/dir-2";
- if(Dir_Create(fn) < 0) printf("ERROR: can't create dir '%s'\n", fn);
- else printf("dir '%s' create successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1/dir-2/file-2";
- if(File_Create(fn) < 0) printf("ERROR: can't create file '%s'\n", fn);
- else printf("file '%s' created successfully\n", fn);
- printf("\nExpected output: ERROR\n");
- fn = "/dir-1/dir-2";
- if(Dir_Unlink(fn) < 0) printf("ERROR: can't unlink dir '%s'\n", fn);
- else printf("dir '%s' unlinked successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1";
- int sz = Dir_Size(fn);
- printf("Directory size: %d\n", sz);
- char* buffer = malloc(sz);
- int entries = Dir_Read(fn, buffer, sz);
- printf("directory '%s':\n %-15s\t%-s\n", fn, "NAME", "INODE");
- int idx = 0;
- for(int i=0; i<entries; i++) {
- printf("%-4d %-15s\t%-d\n", i, &buffer[idx], *(int*)&buffer[idx+16]);
- idx += 20;
- }
- free(buffer);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1/dir-2/file-2";
- if(File_Unlink(fn) < 0) printf("ERROR: can't unlink file '%s'\n", fn);
- else printf("file '%s' unlinked successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1/dir-2";
- if(Dir_Unlink(fn) < 0) printf("ERROR: can't unlink dir '%s'\n", fn);
- else printf("dir '%s' unlinked successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1/dir-2";
- if(Dir_Create(fn) < 0) printf("ERROR: can't create dir '%s'\n", fn);
- else printf("dir '%s' created successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1";
- sz = Dir_Size(fn);
- printf("Directory size: %d\n", sz);
- char* buffer3 = malloc(sz);
- entries = Dir_Read(fn, buffer3, sz);
- printf("directory '%s':\n %-15s\t%-s\n", fn, "NAME", "INODE");
- idx = 0;
- for(int i=0; i<entries; i++) {
- printf("%-4d %-15s\t%-d\n", i, &buffer3[idx], *(int*)&buffer3[idx+16]);
- idx += 20;
- }
- free(buffer3);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1/dir-2";
- if(Dir_Unlink(fn) < 0) printf("ERROR: can't unlink dir '%s'\n", fn);
- else printf("dir '%s' unlinked successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1/file-1";
- if(File_Unlink(fn) < 0) printf("ERROR: can't unlink file '%s'\n", fn);
- else printf("file '%s' unlinked successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-3";
- if(Dir_Create(fn) < 0) printf("ERROR: can't create dir '%s'\n", fn);
- else printf("dir '%s' created successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-1";
- if(Dir_Unlink(fn) < 0) printf("ERROR: can't unlink dir '%s'\n", fn);
- else printf("dir '%s' unlinked successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/dir-4";
- if(Dir_Create(fn) < 0) printf("ERROR: can't create dir '%s'\n", fn);
- else printf("dir '%s' created successfully\n", fn);
- printf("\nExpected output: SUCCESS\n");
- fn = "/";
- sz = Dir_Size(fn);
- printf("Directory size: %d\n", sz);
- char* buffer2 = malloc(sz);
- entries = Dir_Read(fn, buffer2, sz);
- printf("directory '%s':\n %-15s\t%-s\n", fn, "NAME", "INODE");
- idx = 0;
- for(int i=0; i<entries; i++) {
- printf("%-4d %-15s\t%-d\n", i, &buffer2[idx], *(int*)&buffer2[idx+16]);
- idx += 20;
- }
- free(buffer2);
- if(FS_Sync() < 0) {
- printf("ERROR: can't sync file system to file '%s'\n", argv[1]);
- return -1;
- } else printf("file system sync'd to file '%s'\n", argv[1]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement