1/*
2  This file contains the code that will call the initialization routine
3  for a file system (which in turn will initialize the file system). It
4  also has to do a few other housekeeping chores to make sure that the
5  file system is unmounted properly and all that.
6
7
8  THIS CODE COPYRIGHT DOMINIC GIAMPAOLO.  NO WARRANTY IS EXPRESSED
9  OR IMPLIED.  YOU MAY USE THIS CODE AND FREELY DISTRIBUTE IT FOR
10  NON-COMMERCIAL USE AS LONG AS THIS NOTICE REMAINS ATTACHED.
11
12  FOR COMMERCIAL USE, CONTACT DOMINIC GIAMPAOLO (dbg@be.com).
13
14  Dominic Giampaolo
15  dbg@be.com
16*/
17#include <stdio.h>
18#include <stdlib.h>
19#include <ctype.h>
20#include <string.h>
21#include <sys/types.h>
22#include <time.h>
23#include <fcntl.h>
24#include <unistd.h>
25
26#include "myfs.h"
27#include "kprotos.h"
28
29
30static int
31get_value(char *str)
32{
33    char buff[128];
34
35    printf("%s: ", str); fflush(stdout);
36    fgets(buff, sizeof(buff), stdin);
37
38    return strtol(buff, NULL, 0);
39}
40
41
42int
43main(int argc, char **argv)
44{
45    int        block_size = 1024, i;
46    char      *disk_name = "big_file";
47    char      *volume_name = "untitled";
48    myfs_info  *myfs;
49
50    for (i=1; i < argc; i++) {
51        if (isdigit(argv[i][0])) {
52            block_size = strtoul(argv[i], NULL, 0);
53        } else if (disk_name == NULL) {
54            disk_name = argv[i];
55        } else {
56            volume_name = argv[i];
57        }
58    }
59
60    if (disk_name == NULL) {
61        fprintf(stderr, "makefs error: you must specify a file name that\n");
62        fprintf(stderr, "              will contain the file systemn");
63        exit(5);
64    }
65
66    init_block_cache(256, 0);
67
68    myfs = myfs_create_fs(disk_name, volume_name, block_size, NULL);
69    if (myfs != NULL)
70        printf("MYFS w/%d byte blocks successfully created on %s as %s\n",
71               block_size, disk_name, volume_name);
72    else {
73        printf("!HOLA! FAILED to create a MYFS file system on %s\n", disk_name);
74        exit(5);
75    }
76
77    myfs_unmount(myfs);
78
79    shutdown_block_cache();
80
81    return 0;
82}
83