FreeCalypso > hg > freecalypso-tools
annotate ffstools/tiffs-mkfs/output.c @ 738:f19d12f5756f
doc/Target-boot-control: updated for DUART28C
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 16 Sep 2020 06:49:31 +0000 |
parents | 178ed445021d |
children |
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 <sys/file.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <stdio.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdint.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <endian.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <unistd.h> |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "struct.h" |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "globals.h" |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 u_char tiffs_header[6] = {'F', 'f', 's', '#', 0x10, 0x02}; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 void |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 prepare_output_buffers() |
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 inode_block = malloc(ffs_sector_size); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (!inode_block) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 perror("malloc of inode block buffer"); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 exit(1); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 memset(inode_block, 0xFF, ffs_sector_size); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 bcopy(tiffs_header, inode_block, 6); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 inode_block[8] = 0xAB; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 inode_array = (struct tiffs_inode *) inode_block; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 inode_fill_level = 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 data_block = malloc(ffs_sector_size); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (!data_block) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 perror("malloc of data block buffer"); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 exit(1); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 memset(data_block, 0xFF, ffs_sector_size); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 bcopy(tiffs_header, data_block, 6); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 data_block[8] = 0xBD; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 data_fill_level = 0x10; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 objects_in_block = 0; |
708
e2e4aed24522
tiffs-mkfs: malloc file chunk buffer only once
Mychaela Falconia <falcon@freecalypso.org>
parents:
707
diff
changeset
|
40 |
e2e4aed24522
tiffs-mkfs: malloc file chunk buffer only once
Mychaela Falconia <falcon@freecalypso.org>
parents:
707
diff
changeset
|
41 chunk_buffer = malloc(chunk_size_max); |
e2e4aed24522
tiffs-mkfs: malloc file chunk buffer only once
Mychaela Falconia <falcon@freecalypso.org>
parents:
707
diff
changeset
|
42 if (!chunk_buffer) { |
e2e4aed24522
tiffs-mkfs: malloc file chunk buffer only once
Mychaela Falconia <falcon@freecalypso.org>
parents:
707
diff
changeset
|
43 perror("malloc of file chunk buffer"); |
e2e4aed24522
tiffs-mkfs: malloc file chunk buffer only once
Mychaela Falconia <falcon@freecalypso.org>
parents:
707
diff
changeset
|
44 exit(1); |
e2e4aed24522
tiffs-mkfs: malloc file chunk buffer only once
Mychaela Falconia <falcon@freecalypso.org>
parents:
707
diff
changeset
|
45 } |
705
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 void |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 open_output_file() |
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 output_fd = open(output_filename, O_WRONLY|O_CREAT|O_TRUNC, 0666); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (output_fd < 0) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 perror(output_filename); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 exit(1); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 lseek(output_fd, (off_t) ffs_sector_size, SEEK_SET); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 void |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 write_out_block(buf) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 u_char *buf; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (write(output_fd, buf, ffs_sector_size) != ffs_sector_size) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 perror("write of sector bits to output file"); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 exit(1); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 void |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 flush_data_block() |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 write_out_block(data_block); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 blocks_written++; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 memset(data_block + 0x10, 0xFF, ffs_sector_size - 0x10); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 data_fill_level = 0x10; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 objects_in_block = 0; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 create_object(name, type, data, datalen) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 char *name; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 u_char *data; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 unsigned datalen; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 int ino; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 struct tiffs_inode *inp; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 unsigned size, location; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 u_char *dp; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 if (inode_fill_level >= (ffs_sector_size >> 4)) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 fprintf(stderr, "error: inode block is full\n"); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 exit(1); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 ino = inode_fill_level++; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 inp = inode_array + ino; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 if (name) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 size = strlen(name) + 1; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 else |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 size = 0; |
717
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
99 if (datalen) |
705
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 size += datalen + 1; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 size = (size + 15) & ~15; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 if (ffs_sector_size - data_fill_level < size || |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 objects_in_block >= block_files_max) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 flush_data_block(); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 if (blocks_written >= ffs_nsectors - 2) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 fprintf(stderr, "error: wrote max number of data blocks\n"); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 exit(1); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 location = (blocks_written + 1) * ffs_sector_size + data_fill_level; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 /* write the data */ |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 dp = data_block + data_fill_level; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 if (name) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 strcpy(dp, name); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 dp += strlen(name) + 1; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 } |
717
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
116 if (datalen) { |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
117 if (data) |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
118 bcopy(data, dp, datalen); |
705
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 dp += datalen; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 *dp++ = 0; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 /* fill the inode */ |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 inp->size = htole16(size); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 inp->type = type; |
707
805885936f62
tiffs-mkfs: fixed bug in location inode field
Mychaela Falconia <falcon@freecalypso.org>
parents:
705
diff
changeset
|
125 inp->location = htole32(location >> 4); |
705
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 inp->sequence = htole16(ino - 1); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 inp->updates = 0; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 /* accounting */ |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 data_fill_level += size; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 objects_in_block++; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 return ino; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 void |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 create_root_dir() |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 int rootino; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 rootino = create_object(format_name, OBJTYPE_DIR, (u_char *) 0, 0); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 root.u.d.ffs_link_ptr = &inode_array[rootino].child; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 create_file_object(to) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 struct tree_object *to; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 int fd, cc; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 int head, seg; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 struct tiffs_inode *inp; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 fd = open(to->u.f.host_pathname, O_RDONLY); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 if (fd < 0) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 perror(to->u.f.host_pathname); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 exit(1); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 } |
708
e2e4aed24522
tiffs-mkfs: malloc file chunk buffer only once
Mychaela Falconia <falcon@freecalypso.org>
parents:
707
diff
changeset
|
155 cc = read(fd, chunk_buffer, chunk_size_max); |
705
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 if (cc < 0) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 read_err: perror("error reading file content"); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 exit(1); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 if (cc == 0) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 /* zero length file */ |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 close(fd); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 return create_object(to->name, OBJTYPE_FILE, (u_char *) 0, 0); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 } |
708
e2e4aed24522
tiffs-mkfs: malloc file chunk buffer only once
Mychaela Falconia <falcon@freecalypso.org>
parents:
707
diff
changeset
|
165 head = create_object(to->name, OBJTYPE_FILE, chunk_buffer, cc); |
705
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 inp = inode_array + head; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 for (;;) { |
708
e2e4aed24522
tiffs-mkfs: malloc file chunk buffer only once
Mychaela Falconia <falcon@freecalypso.org>
parents:
707
diff
changeset
|
168 cc = read(fd, chunk_buffer, chunk_size_max); |
705
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 if (cc < 0) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 goto read_err; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 if (cc == 0) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 break; |
708
e2e4aed24522
tiffs-mkfs: malloc file chunk buffer only once
Mychaela Falconia <falcon@freecalypso.org>
parents:
707
diff
changeset
|
173 seg = create_object((char *) 0, OBJTYPE_SEGMENT, chunk_buffer, |
e2e4aed24522
tiffs-mkfs: malloc file chunk buffer only once
Mychaela Falconia <falcon@freecalypso.org>
parents:
707
diff
changeset
|
174 cc); |
705
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 inp->child = htole16(seg); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 inp = inode_array + seg; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 close(fd); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 return head; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 create_subdir(to) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 struct tree_object *to; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 int ino; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 ino = create_object(to->name, OBJTYPE_DIR, (u_char *) 0, 0); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 to->u.d.ffs_link_ptr = &inode_array[ino].child; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 return ino; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 void |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 process_dir_level(dto) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 struct tree_object *dto; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 unsigned n; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 struct tree_object *cto; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 int child_ino; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 for (n = 0; n < dto->u.d.nchildren; n++) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 cto = dto->u.d.children[n]; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 if (cto->is_dir) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 child_ino = create_subdir(cto); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 process_dir_level(cto); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 } else |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 child_ino = create_file_object(cto); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 *dto->u.d.ffs_link_ptr = htole16(child_ino); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 dto->u.d.ffs_link_ptr = &inode_array[child_ino].sibling; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 void |
717
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
213 create_journal() |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
214 { |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
215 int ino; |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
216 |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
217 ino = create_object(".journal", OBJTYPE_FILE_RO, (u_char *) 0, |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
218 journal_size); |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
219 *root.u.d.ffs_link_ptr = htole16(ino); |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
220 root.u.d.ffs_link_ptr = &inode_array[ino].sibling; |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
221 } |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
222 |
178ed445021d
tiffs-mkfs: journal creation implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
708
diff
changeset
|
223 void |
705
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 finish_output() |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 if (objects_in_block) |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 flush_data_block(); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 while (blocks_written < ffs_nsectors - 2) { |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 write_out_block(data_block); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 blocks_written++; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 } |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 /* free block at the end */ |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 data_block[8] = 0xBF; |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 write_out_block(data_block); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 /* write out the inode block */ |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 lseek(output_fd, (off_t) 0, SEEK_SET); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 write_out_block(inode_block); |
12ae93940467
tiffs-mkfs program written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 } |