FreeCalypso > hg > freecalypso-tools
annotate ffstools/tiffs-mkfs/main.c @ 705:12ae93940467
tiffs-mkfs program written, compiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 20 May 2020 06:55:58 +0000 |
parents | |
children | 178ed445021d |
rev | line source |
---|---|
705
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <sys/param.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <stdio.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <stdint.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdlib.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <string.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <strings.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "struct.h" |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include "globals.h" |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 void |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 process_cmdline(argc, argv) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 char **argv; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern int optind; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern char *optarg; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int c; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 while ((c = getopt(argc, argv, "c:f:m:")) != EOF) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 switch (c) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 case 'c': |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 chunk_size_max = strtoul(optarg, 0, 0); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 continue; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 case 'f': |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (*optarg != '/') { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 fprintf(stderr, |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 "error: format name must begin with \'/\'\n"); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 exit(1); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 format_name = optarg; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 continue; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 case 'm': |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 block_files_max = strtoul(optarg, 0, 0); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 continue; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 default: |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 usage: fprintf(stderr, |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 "usage: %s [options] <org> <srcdir> <outfile>\n", |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 argv[0]); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 exit(1); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (argc - optind != 3) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 goto usage; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 parse_org_arg(argv[optind]); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 input_host_dir = argv[optind+1]; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 output_filename = argv[optind+2]; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 main(argc, argv) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 char **argv; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 process_cmdline(argc, argv); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (!format_name) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 format_name = "/"; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 preen_chunk_size_max(); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 preen_block_files_max(); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 /* input phase */ |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 read_dir_level(&root, input_host_dir, 0); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 sort_dir_level(&root); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 /* output phase */ |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 prepare_output_buffers(); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 open_output_file(); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 create_root_dir(); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 process_dir_level(&root); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 finish_output(); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 close(output_fd); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 exit(0); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |