-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkfs.vc.c
78 lines (70 loc) · 1.95 KB
/
mkfs.vc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include "utils.h"
#include "store.h"
#include "blocktree.h"
#include "vcfs.h"
int main(int argc, char **argv)
{
struct store *st;
struct inode root;
struct revrec frev;
struct dentry dots;
time_t now;
int fd;
char tbuf[1024];
if(argc < 2) {
fprintf(stderr, "usage; mkfs.vc DIR\n");
exit(1);
}
if(mkfstore(argv[1]))
exit(1);
if((st = newfstore(argv[1])) == NULL)
exit(1);
now = time(NULL);
memset(&dots, 0, sizeof(dots));
dots.inode = 0;
root.mode = S_IFDIR | 0755;
root.mtime = root.ctime = now;
root.size = 2;
root.uid = getuid();
root.gid = getgid();
root.links = 2;
root.data.d = 0;
root.xattr.d = 0;
strcpy(dots.name, ".");
if(btput(st, &root.data, 0, &dots, sizeof(dots) - sizeof(dots.name) + 2, DIRBLSIZE)) {
fprintf(stderr, "mkfs.vc: could not create root directory entries: %s\n", strerror(errno));
exit(1);
}
strcpy(dots.name, "..");
if(btput(st, &root.data, 1, &dots, sizeof(dots) - sizeof(dots.name) + 3, DIRBLSIZE)) {
fprintf(stderr, "mkfs.vc: could not create root directory entries: %s\n", strerror(errno));
exit(1);
}
frev.ct = now;
frev.root.d = 0;
if(btput(st, &frev.root, 0, &root, sizeof(root), INOBLSIZE)) {
fprintf(stderr, "mkfs.vc: could not store root directory inode: %s\n", strerror(errno));
exit(1);
}
releasestore(st);
snprintf(tbuf, sizeof(tbuf), "%s/revs", argv[1]);
if((fd = open(tbuf, O_WRONLY | O_CREAT | O_EXCL, 0600)) < 0) {
fprintf(stderr, "mkfs.vc: could not create revision database: %s\n", strerror(errno));
exit(1);
}
if(writeall(fd, &frev, sizeof(frev), 0)) {
fprintf(stderr, "mkfs.vc: could not write initial revision: %s\n", strerror(errno));
exit(1);
}
fsync(fd);
close(fd);
return(0);
}