• R/O
  • SSH
  • HTTPS

haribote: Commit


Commit MetaInfo

Revision197 (tree)
Time2010-03-04 23:59:53
Authortatsupc

Log Message

orbspace

Change Summary

Incremental Difference

--- haribote/trunk/orbspace/mkorbfs/mkorbfs.c (revision 196)
+++ haribote/trunk/orbspace/mkorbfs/mkorbfs.c (revision 197)
@@ -24,7 +24,8 @@
2424 "Syntax error",
2525 "Image file error",
2626 "IPL file error",
27- "File error"
27+ "File error",
28+ "Ball error"
2829 };
2930
3031 void print_error(int no)
@@ -38,10 +39,37 @@
3839 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
3940 };
4041
42+unsigned char *getcmd(unsigned char *arg)
43+{
44+ if (strncmp(arg, "+File", 4) == 0) {
45+ return "Type=File";
46+ } else if (strncmp(arg, "+Func", 4) == 0) {
47+ return "Type=Func";
48+ } else if (strncmp(arg, "+Ball", 4) == 0) {
49+ return "Type=Ball";
50+ }
51+ return 0;
52+}
53+
54+unsigned char *ballname_check(unsigned char **arg)
55+{
56+ unsigned char *p;
57+
58+ if (**arg != '[') {
59+ return 0;
60+ }
61+ for (p = ++*arg; **arg && **arg != ']'; ++*arg);
62+ if (**arg != ']') {
63+ print_error(0);
64+ }
65+ *(*arg)++ = 0;
66+ return p;
67+}
68+
4169 int main(int argc, char **argv)
4270 {
4371 FILE *fp;
44- unsigned char *buf, *name, *p;
72+ unsigned char *buf, *name, *bname, *p;
4573 int size, n, m, i;
4674
4775 if (argc < 4) {
@@ -66,36 +94,54 @@
6694 orbfs_init();
6795
6896 for (n = 4; n < argc;) {
69- if (strncmp(argv[n], "+File", 4) == 0 ||
70- strncmp(argv[n], "+Func", 4) == 0) {
97+ if (getcmd(argv[n]) != 0) {
7198 for (m = ++n; m < argc && argv[m][0] != '+'; m++);
72- if ((fp = fopen(argv[n], "rb")) == 0) {
73- print_error(3);
74- }
75- fseek(fp, 0, SEEK_END);
76- size = ftell(fp);
77- fseek(fp, 0, SEEK_SET);
78- buf = (unsigned char *) malloc(size);
79- fread(buf, 1, size, fp);
80- for (name = p = argv[n]; *p; p++) {
81- if (*p == '\\') {
82- name = p + 1;
99+ if (getcmd(argv[n - 1])[5] == 'B') {
100+ name = argv[n];
101+ size = 0;
102+ buf = 0;
103+ } else {
104+ if ((fp = fopen(argv[n], "rb")) == 0) {
105+ print_error(3);
83106 }
107+ fseek(fp, 0, SEEK_END);
108+ size = ftell(fp);
109+ fseek(fp, 0, SEEK_SET);
110+ buf = (unsigned char *) malloc(size);
111+ fread(buf, 1, size, fp);
112+ for (name = p = argv[n]; *p; p++) {
113+ if (*p == '\\') {
114+ name = p + 1;
115+ }
116+ }
84117 }
85118 if (orbfs_create(name, size, buf) != 0) {
86119 print_error(3);
87120 }
88- if (orbfs_meta_add(name,
89- strncmp(argv[n - 1], "+File", 4) == 0 ? "Type=File" : "Type=Func") != 0) {
121+ if (orbfs_meta_add(name, getcmd(argv[n - 1])) != 0) {
90122 print_error(3);
91123 }
92- for (i = n + 1; i < m; i++) {
124+ i = n + 1;
125+ if (argv[i][0] == '[') {
126+ if (!(getcmd(argv[n - 1])[6] == 'i')) {
127+ print_error(0);
128+ }
129+ p = argv[i];
130+ for (i++; (bname = ballname_check(&p)) != 0;) {
131+ if (orbfs_ball_add(bname, name) != 0) {
132+ print_error(4);
133+ }
134+ }
135+ }
136+ for (; i < m; i++) {
93137 if (orbfs_meta_add(name, argv[i]) != 0) {
94138 print_error(3);
95139 }
96140 }
97- free(buf);
98- fclose(fp);
141+ if (!(getcmd(argv[n - 1])[5] == 'B')) {
142+ free(buf);
143+ fclose(fp);
144+ }
99145 n = m;
100146 } else {
101147 print_error(0);
--- haribote/trunk/orbspace/orbspace.txt (revision 196)
+++ haribote/trunk/orbspace/orbspace.txt (revision 197)
@@ -50,8 +50,8 @@
5050 +File orbspace\orbspace.sys \
5151 +Ball orbspace Color=0xff0000 \
5252 +Ball orbfs Color=0x00ff00 \
53- +File [orbspace]orbspace\main.c Author=tatsu Keyword=orbspace \
54- +File [orbspace][orbfs]orbspace\orbfs.c Author=tatsu Keyword=orbspace \
53+ +File orbspace\main.c [orbspace] Author=tatsu Keyword=orbspace \
54+ +File orbspace\orbfs.c [orbspace][orbfs] Author=tatsu Keyword=orbspace \
5555 +Func search.orb Color=0x0000ff
5656 >
5757
--- haribote/trunk/orbspace/Makefile (revision 196)
+++ haribote/trunk/orbspace/Makefile (revision 197)
@@ -8,8 +8,11 @@
88 orbspace.img: $(MKORBFS) orbspace\ipl.bin Makefile
99 $(MKORBFS) orbspace.img 131072 orbspace\ipl.bin \
1010 +File orbspace\ipl.bin Author=tatsu Keyword=orbspace \
11- +File orbspace\ipl.nas Author=tatsu Keyword=orbspace \
12- +Func search.orb Color=0xff0000
11+ +Ball orbspace Color=0x00ff00 \
12+ +Ball orbfs Color=0xff0000 \
13+ +File orbspace\ipl.nas [orbspace] Author=tatsu Keyword=orbspace \
14+ +File mkorbfs\mkorbfs.c [orbspace][orbfs]Author=tatsu Keyword=orbspace \
15+ +Func search.orb Color=0x0000ff
1316
1417 clean:
1518 make -C mkorbfs clean
--- haribote/trunk/orbspace/orbspace/orbfs.h (revision 196)
+++ haribote/trunk/orbspace/orbspace/orbfs.h (revision 197)
@@ -8,3 +8,4 @@
88 void orbfs_init(void);
99 int orbfs_create(unsigned char *name, unsigned int size, unsigned char *fbuf);
1010 int orbfs_meta_add(unsigned char *name, unsigned char *str);
11+int orbfs_ball_add(unsigned char *bname, unsigned char *name);
--- haribote/trunk/orbspace/orbspace/orbfs.c (revision 196)
+++ haribote/trunk/orbspace/orbspace/orbfs.c (revision 197)
@@ -32,11 +32,13 @@
3232 p < (orbsat + 0x1c00) && *p && *p < no; p += 2);
3333 if (p == (orbsat + 0x1c00)) {
3434 return 0;
35+ } else if (*p == no && !*(p + 1)) {
36+ break;
3537 } else {
36- no = *(p + 1) ? *(p + 1) : no + 1;
38+ no = (*p == no) ? *(p + 1) : no + 1;
3739 }
3840 }
39- return no * 512 + 0x1e00;
41+ return (no - 1) * 512 + 0x1e00;
4042 }
4143
4244 unsigned int *orbsat_add(unsigned int no, unsigned int next)
@@ -48,9 +50,9 @@
4850 return 0;
4951 }
5052 if (*p) {
51- for (q = orbsat + 0x1c00; p < q; q -= 2) {
53+ for (q = orbsat + 0x1bfc / 4; p <= q; q -= 2) {
5254 *q = *(q - 2);
53- *(q - 1) = *(q - 3);
55+ *(q + 1) = *(q - 1);
5456 }
5557 }
5658 *p = no;
@@ -60,6 +62,7 @@
6062
6163 unsigned int orbfs_search(unsigned char *name)
6264 {
65+ struct entry *ent;
6366 #ifdef ORBSPACE
6467 #else
6568 unsigned char *buf = (unsigned char *) malloc(512);
@@ -69,19 +72,19 @@
6972 if (!*orbsat) {
7073 return 0;
7174 }
75+ ent = (struct entry *) buf;
7276 for (addr = 0x1e00;;){
7377 io_read(buf, addr, 512);
74- if (strncmp((unsigned char *) (buf + 4), name, 12) == 0) {
78+ if (strncmp((unsigned char *) ent->name, name, 12) == 0) {
7579 #ifdef ORBSPACE
7680 #else
7781 free(buf);
7882 #endif
7983 return addr;
80- } else if (!*(buf + 4)) {
84+ } else if (!ent->name[0]) {
8185 break;
8286 }
83- if ((addr = orbsat_getnext(addr,
84- ((unsigned int) *buf + 512 + 511) / 512 * 512)) == 0) {
87+ if ((addr = orbsat_getnext(addr, ent->size + 1024)) == 0) {
8588 break;
8689 }
8790 }
@@ -129,8 +132,8 @@
129132 strncpy(ent->name, name, 12);
130133 memset(ent->meta, 0, 496);
131134 io_write(buf, addr, 512);
132- for (addr += 512;; size -= 512) {
133- io_read(buf, addr, 512);
135+ for (addr += 512; size; size -= 512) {
136+ memset(buf, 0, 512);
134137 memcpy(buf, fbuf, size > 512 ? 512 : size);
135138 io_write(buf, addr, 512);
136139 if (size <= 512) {
@@ -173,3 +176,80 @@
173176 #endif
174177 return 0;
175178 }
179+
180+unsigned char *orbfs_meta_get(unsigned char *meta, unsigned char *key,
181+ unsigned char *buf, unsigned int size)
182+{
183+ unsigned char *base = meta;
184+ unsigned int len = strlen(key), i;
185+
186+ for (; *meta && (base - meta) < 496;) {
187+ if (strncmp(meta, key, len) == 0) {
188+ for (; *meta++ != '=';);
189+ for (i = 0; *meta != 0x0a && i < size; i++) {
190+ buf[i] = *meta++;
191+ }
192+ return buf;
193+ }
194+ for (; *meta++ != '=';);
195+ for (; *meta++ != 0x0a;);
196+ }
197+ return 0;
198+}
199+
200+int orbfs_ball_add(unsigned char *bname, unsigned char *name)
201+{
202+ struct entry *ent;
203+ unsigned char val[4], *buf;
204+ unsigned int *sat, addr, no, i, j;
205+
206+#ifdef ORBSPACE
207+#else
208+ buf = (unsigned char *) malloc(512);
209+#endif
210+ if ((no = (orbfs_search(name) - 0x1e00) / 512 + 1) == 0) {
211+ return 1;
212+ }
213+ if ((addr = orbfs_search(bname)) == 0) {
214+ return 1;
215+ }
216+ io_read(buf, addr, 512);
217+ ent = (struct entry *) buf;
218+ if (orbfs_meta_get(ent->meta, "Type", val, 4) != 0 &&
219+ strncmp(val, "Ball", 4) != 0) {
220+ return 1;
221+ }
222+ if (((ent->size + 511) / 512) != ((ent->size + 2 + 511) / 512)) {
223+ for (sat = orbsat; sat < (orbsat + 0x1c00) && *sat; sat++);
224+ if (sat == (orbsat + 0x1c00)) {
225+ return 1;
226+ } else if (sat-- == orbsat) {
227+ sat = orbsat;
228+ }
229+ i = (addr - 0x1e00) / 512 + 1;
230+ j = ++*sat - 1;
231+ if (orbsat_add(i, j) == 0) {
232+ return 1;
233+ }
234+ if (orbsat_add(j, i + 1) == 0) {
235+ return 1;
236+ }
237+ if (orbsat_add(j - 1, j + 1) == 0) {
238+ return 1;
239+ }
240+ io_write((unsigned char *) orbsat, 0x200, 7168);
241+ } else {
242+ j = (orbsat_getnext(addr, 513) - 0x1e00) / 512 + 1;
243+ }
244+ i = ent->size;
245+ ent->size += 4;
246+ io_write(buf, addr, 512);
247+ io_read(buf, (j - 1) * 512 + 0x1e00, 512);
248+ *((unsigned int *) (buf + i)) = no;
249+ io_write(buf, (j - 1) * 512 + 0x1e00, 512);
250+#ifdef ORBSPACE
251+#else
252+ free(buf);
253+#endif
254+ return 0;
255+}
Show on old repository browser