-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathinit.c
45 lines (36 loc) · 1.06 KB
/
init.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
//
// Initialize build data. Run this on a new system before anything else.
#define USAGE "usage: plash init\n"
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <plash.h>
void ensuredir(char *pathname, mode_t mode) {
if (mkdir(pathname, mode) == -1 && errno != EEXIST)
pl_fatal("mkdir %s", pathname);
}
int init_main(int argc, char *argv[]) {
char *plash_data = plash("data");
ensuredir(plash_data, 0700);
if (chdir(plash_data) == -1)
pl_fatal("chdir %s", plash_data);
ensuredir("index", 0775);
ensuredir("map", 0775);
ensuredir("tmp", 0775);
ensuredir("mnt", 0775);
ensuredir("layer", 0775);
ensuredir("layer/0", 0775);
ensuredir("layer/0/_data", 0775);
ensuredir("layer/0/_data/root", 0775);
int fd = open("id_counter", O_CREAT | O_WRONLY | O_EXCL, 0775);
if (fd == -1 && errno != EEXIST)
pl_fatal("open");
close(fd);
if (symlink("../layer/0", "index/0") == -1 && errno != EEXIST)
pl_fatal("symlink");
return EXIT_SUCCESS;
}