source: patches/silo-1.4.14-fixes-3.patch@ 711fda6

clfs-2.1 clfs-3.0.0-systemd clfs-3.0.0-sysvinit systemd sysvinit
Last change on this file since 711fda6 was 711fda6, checked in by William Harrington <kb0iic@…>, 13 years ago

Update silo fixes patch and sparc64 and sparc64-64 final-system silo make command.

  • Property mode set to 100644
File size: 30.7 KB
RevLine 
[711fda6]1diff -Naur silo-1.4.14.orig/Rules.make silo-1.4.14/Rules.make
2--- silo-1.4.14.orig/Rules.make 2008-06-12 16:39:12.000000000 +0000
3+++ silo-1.4.14/Rules.make 2012-09-01 19:14:27.000000000 +0000
4@@ -1,4 +1,4 @@
5-VERSION=1.4.14
6+VERSION=1.4.14_git20120901
7 IMGVERSION=0.99
8 SHELL=/bin/bash
9 RM=rm -f
10@@ -18,8 +18,8 @@
11 > /dev/null 2>&1; then echo "y"; else echo "n"; fi;)
12
13 CFLAGS = -Os -Wall -I. -I../include -fomit-frame-pointer \
14- -fno-strict-aliasing -DSMALL_RELOC=$(SMALL_RELOC) \
15- -DLARGE_RELOC=$(LARGE_RELOC)
16+ -fno-strict-aliasing -U_FORTIFY_SOURCE \
17+ -DSMALL_RELOC=$(SMALL_RELOC) -DLARGE_RELOC=$(LARGE_RELOC)
18
19 ifeq ($(call cc-option-yn, -fno-stack-protector),y)
20 CFLAGS += -fno-stack-protector
21diff -Naur silo-1.4.14.orig/common/.gitignore silo-1.4.14/common/.gitignore
22--- silo-1.4.14.orig/common/.gitignore 1970-01-01 00:00:00.000000000 +0000
23+++ silo-1.4.14/common/.gitignore 2012-09-01 19:05:11.000000000 +0000
24@@ -0,0 +1,4 @@
25+#
26+# Generated files
27+#
28+bin2h
29diff -Naur silo-1.4.14.orig/common/divdi3.S silo-1.4.14/common/divdi3.S
30--- silo-1.4.14.orig/common/divdi3.S 2008-06-12 16:39:12.000000000 +0000
31+++ silo-1.4.14/common/divdi3.S 2012-09-01 19:06:01.000000000 +0000
32@@ -20,6 +20,8 @@
33 .data
34 .align 8
35 .globl __clz_tab
36+ .register %g2,#scratch
37+ .register %g3,#scratch
38 __clz_tab:
39 .byte 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5
40 .byte 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6
41diff -Naur silo-1.4.14.orig/common/malloc.c silo-1.4.14/common/malloc.c
42--- silo-1.4.14.orig/common/malloc.c 2008-06-12 16:39:12.000000000 +0000
43+++ silo-1.4.14/common/malloc.c 2012-09-01 19:05:11.000000000 +0000
44@@ -18,6 +18,8 @@
45 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
46 USA. */
47
48+#include <stringops.h>
49+
50 #ifndef MALLOC_BASE
51 extern unsigned long _start;
52 static char *malloc_ptr = ((char *)&_start) + 0x30000;
53@@ -27,6 +29,12 @@
54
55 static char *last_alloc = 0;
56
57+static char *align_ptr_to(char *ptr, unsigned long align)
58+{
59+ return (char *) ((((unsigned long) ptr) + (align - 1UL)) &
60+ ~(align - 1UL));
61+}
62+
63 void *malloc (int size)
64 {
65 char *caddr;
66@@ -34,10 +42,51 @@
67 caddr = malloc_ptr;
68 malloc_ptr += size;
69 last_alloc = caddr;
70- malloc_ptr = (char *) ((((unsigned long) malloc_ptr) + 7) & (~7));
71+ malloc_ptr = align_ptr_to(malloc_ptr, 8UL);
72 return caddr;
73 }
74
75+void *calloc (int nmemb, int memb_size)
76+{
77+ char *ret;
78+ int size;
79+
80+ if (!nmemb || !memb_size)
81+ return (void *) 0;
82+
83+ size = nmemb * memb_size;
84+ ret = malloc(size);
85+
86+ if (ret)
87+ memset(ret, 0, size);
88+
89+ return ret;
90+}
91+
92+int posix_memalign(void **memptr, unsigned long alignment, unsigned long size)
93+{
94+ char *caddr;
95+
96+ if (alignment & (alignment - 1UL))
97+ return -1;
98+ if (alignment & (sizeof(void *) - 1UL))
99+ return -1;
100+
101+ if (size == 0) {
102+ *memptr = (void *) 0;
103+ return 0;
104+ }
105+
106+ caddr = align_ptr_to(malloc_ptr, alignment);
107+ malloc_ptr = (caddr + size);
108+ last_alloc = caddr;
109+ malloc_ptr = align_ptr_to(malloc_ptr, 8UL);
110+
111+ *memptr = caddr;
112+
113+ return 0;
114+}
115+
116 void free (void *m)
117 {
118 if (m == last_alloc)
119diff -Naur silo-1.4.14.orig/common/printf.c silo-1.4.14/common/printf.c
120--- silo-1.4.14.orig/common/printf.c 2008-06-12 16:39:12.000000000 +0000
121+++ silo-1.4.14/common/printf.c 2012-09-01 19:05:11.000000000 +0000
122@@ -21,6 +21,7 @@
123 USA. */
124
125 #include "promlib.h"
126+#include <stringops.h>
127
128 /*
129 * This part is rewritten by Igor Timkin <ivt@msu.su>. Than I
130@@ -147,3 +148,91 @@
131 vprintf (fmt, x1);
132 va_end (x1);
133 }
134+
135+static int sprintn (char *str, long long n, int b)
136+{
137+ static char prbuf[33];
138+ register char *cp;
139+ int count = 0;
140+
141+ if (b == 10 && n < 0) {
142+ memset (str + count, '-', 1);
143+ count++;
144+ n = -n;
145+ }
146+ cp = prbuf;
147+ do
148+ *cp++ = "0123456789ABCDEF"[(unsigned int) (((unsigned long)n) % b)];
149+ while ((n = ((unsigned long long)n) / b & 0x0FFFFFFFFFFFFFFFULL));
150+ do {
151+ memset (str + count, *--cp, 1);
152+ count++;
153+ } while (cp > prbuf);
154+
155+ return count;
156+}
157+
158+int vsprintf (char *str, char *fmt, va_list adx)
159+{
160+ register int c;
161+ char *s;
162+ int count = 0;
163+
164+ for (;;) {
165+ while ((c = *fmt++) != '%') {
166+ memset (str + count, c, 1);
167+ if (c == '\0') {
168+ return count;
169+ }
170+ }
171+ c = *fmt++;
172+ if (c == 'd' || c == 'o' || c == 'x' || c == 'X') {
173+ count += sprintn (str + count, (long long) va_arg (adx, unsigned),
174+ c == 'o' ? 8 : (c == 'd' ? 10 : 16));
175+ } else if (c == 'c') {
176+ memset (str + count, va_arg (adx, unsigned), 1);
177+ count++;
178+ } else if (c == 's') {
179+ if ((s = va_arg (adx, char *)) == NULL)
180+ s = (char *)"(null)";
181+ while ((c = *s++)) {
182+ memset (str + count, c, 1);
183+ count++;
184+ }
185+ } else if (c == 'l' || c == 'O') {
186+ count += sprintn (str + count, (long long) va_arg (adx, long), c == 'l' ? 10 : 8);
187+ } else if (c == 'L') {
188+ int hex = 0;
189+ if (*fmt == 'x') {
190+ fmt++;
191+ hex = 1;
192+ }
193+ count += sprintn (str + count, (long long) va_arg (adx, long long), hex ? 16 : 10);
194+ } else {
195+ /* This is basically what libc's printf does */
196+ memset (str + count, '%', 1);
197+ count++;
198+ memset (str + count, c, 1);
199+ count++;
200+ }
201+ }
202+
203+ return count;
204+}
205+
206+/*
207+ * Scaled down version of C Library sprintf.
208+ * Only %c %s %d (==%u) %o %x %X %l %O are recognized.
209+ */
210+
211+int sprintf (char *s, char *format, ...)
212+{
213+ va_list arg;
214+ int done;
215+
216+ va_start (arg, format);
217+ done = vsprintf (s, format, arg);
218+ va_end (arg);
219+
220+ return done;
221+}
222diff -Naur silo-1.4.14.orig/common/udivdi3.S silo-1.4.14/common/udivdi3.S
223--- silo-1.4.14.orig/common/udivdi3.S 2008-06-12 16:39:12.000000000 +0000
224+++ silo-1.4.14/common/udivdi3.S 2012-09-01 19:09:16.000000000 +0000
225@@ -20,6 +20,8 @@
226 .text
227 .align 4
228 .globl __udivdi3
229+ .register %g2,#scratch
230+ .register %g3,#scratch
231 __udivdi3:
232 save %sp,-104,%sp
233 mov %i3,%o3
234diff -Naur silo-1.4.14.orig/first/.gitignore silo-1.4.14/first/.gitignore
235--- silo-1.4.14.orig/first/.gitignore 1970-01-01 00:00:00.000000000 +0000
236+++ silo-1.4.14/first/.gitignore 2012-09-01 19:05:11.000000000 +0000
237@@ -0,0 +1,16 @@
238+#
239+# Generated files
240+#
241+fd
242+fd.b
243+fd.h
244+first
245+first.b
246+first.h
247+generic
248+generic.b
249+generic.h
250+ieee32.b
251+ultra
252+ultra.b
253+ultra.h
254diff -Naur silo-1.4.14.orig/first-isofs/.gitignore silo-1.4.14/first-isofs/.gitignore
255--- silo-1.4.14.orig/first-isofs/.gitignore 1970-01-01 00:00:00.000000000 +0000
256+++ silo-1.4.14/first-isofs/.gitignore 2012-09-01 19:05:11.000000000 +0000
257@@ -0,0 +1,5 @@
258+#
259+# Generated files
260+#
261+isofs
262+isofs.b
263diff -Naur silo-1.4.14.orig/include/ext2fs/ext2fs.h silo-1.4.14/include/ext2fs/ext2fs.h
264--- silo-1.4.14.orig/include/ext2fs/ext2fs.h 2008-06-12 16:39:12.000000000 +0000
265+++ silo-1.4.14/include/ext2fs/ext2fs.h 2012-09-01 19:05:11.000000000 +0000
266@@ -39,7 +39,7 @@
267 */
268 #define EXT2_LIB_CURRENT_REV 0
269
270-#ifdef HAVE_SYS_TYPES_H
271+#if defined(HAVE_SYS_TYPES_H)
272 #include <sys/types.h>
273 #endif
274
275diff -Naur silo-1.4.14.orig/include/silo.h silo-1.4.14/include/silo.h
276--- silo-1.4.14.orig/include/silo.h 2008-06-12 16:39:12.000000000 +0000
277+++ silo-1.4.14/include/silo.h 2012-09-01 19:05:11.000000000 +0000
278@@ -87,6 +87,8 @@
279 void silo_disk_close(void);
280 /* printf.c */
281 int vprintf (char *, va_list);
282+int vsprintf (char *str, char *fmt, va_list adx);
283+int sprintf (char *s, char *format, ...);
284 int putchar (int);
285 /* malloc.c */
286 void *malloc (int);
287@@ -123,6 +125,7 @@
288 int decompress (char *, char *, unsigned char (*)(void), void (*)(void));
289 /* main.c */
290 extern enum arch architecture;
291+extern int sun4v_cpu;
292 /* timer.c */
293 int init_timer ();
294 void close_timer ();
295diff -Naur silo-1.4.14.orig/include/stringops.h silo-1.4.14/include/stringops.h
296--- silo-1.4.14.orig/include/stringops.h 2008-06-12 16:39:12.000000000 +0000
297+++ silo-1.4.14/include/stringops.h 2012-09-01 19:05:11.000000000 +0000
298@@ -2,14 +2,13 @@
299 #define __STRINGOPS_H
300
301 #include <silo.h>
302+#include <stddef.h>
303
304 /* common */
305 #ifndef __SIZE_TYPE__
306 #define __SIZE_TYPE__ long unsigned int
307 #endif
308-#ifndef _LINUX_TYPES_H
309 typedef __SIZE_TYPE__ size_t;
310-#endif
311
312 /* stringops1.c */
313 char *strcpy(char *, const char *);
314diff -Naur silo-1.4.14.orig/second/.gitignore silo-1.4.14/second/.gitignore
315--- silo-1.4.14.orig/second/.gitignore 1970-01-01 00:00:00.000000000 +0000
316+++ silo-1.4.14/second/.gitignore 2012-09-01 19:05:11.000000000 +0000
317@@ -0,0 +1,12 @@
318+#
319+# Generated files
320+#
321+second
322+second.b
323+second.b2
324+second2
325+silotftp
326+silotftp.b
327+silotftp.b2
328+silotftp2
329+util
330diff -Naur silo-1.4.14.orig/second/Makefile silo-1.4.14/second/Makefile
331--- silo-1.4.14.orig/second/Makefile 2008-06-12 16:39:12.000000000 +0000
332+++ silo-1.4.14/second/Makefile 2012-09-01 19:05:11.000000000 +0000
333@@ -58,13 +58,13 @@
334 $(AR) rc $@ $(FS_OBJS)
335
336 second: $(OBJS) mark.o
337- $(LD) $(LDFLAGS_SMALL) -Bstatic -o second $(OBJS) -lext2fs mark.o
338- $(LD) $(LDFLAGS_LARGE) -Bstatic -o second2 $(OBJS) -lext2fs mark.o
339+ $(LD) $(LDFLAGS_SMALL) -Bstatic -o second $(OBJS) mark.o `$(CC) -print-libgcc-file-name`
340+ $(LD) $(LDFLAGS_LARGE) -Bstatic -o second2 $(OBJS) mark.o `$(CC) -print-libgcc-file-name`
341 $(NM) second | grep -v '*ABS*' | sort > second.map
342
343 silotftp: $(OBJSNET) mark.o
344- $(LD) $(LDFLAGS_SMALL) -Bstatic -o silotftp $(OBJSNET) -lext2fs mark.o
345- $(LD) $(LDFLAGS_LARGE) -Bstatic -o silotftp2 $(OBJSNET) -lext2fs mark.o
346+ $(LD) $(LDFLAGS_SMALL) -Bstatic -o silotftp $(OBJSNET) mark.o `$(CC) -print-libgcc-file-name`
347+ $(LD) $(LDFLAGS_LARGE) -Bstatic -o silotftp2 $(OBJSNET) mark.o `$(CC) -print-libgcc-file-name`
348 $(NM) silotftp | grep -v '*ABS*' | sort > silotftp.map
349
350 second.l: second
351diff -Naur silo-1.4.14.orig/second/file.c silo-1.4.14/second/file.c
352--- silo-1.4.14.orig/second/file.c 2008-06-12 16:39:12.000000000 +0000
353+++ silo-1.4.14/second/file.c 2012-09-01 19:05:11.000000000 +0000
354@@ -19,6 +19,7 @@
355 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
356 USA. */
357
358+#include <sys/types.h>
359 #include <silo.h>
360 #include <file.h>
361 #include <stringops.h>
362diff -Naur silo-1.4.14.orig/second/fs/ext2.c silo-1.4.14/second/fs/ext2.c
363--- silo-1.4.14.orig/second/fs/ext2.c 2008-06-12 16:39:12.000000000 +0000
364+++ silo-1.4.14/second/fs/ext2.c 2012-09-01 19:05:11.000000000 +0000
365@@ -3,6 +3,7 @@
366 Copyright (C) 1996 Maurizio Plaza
367 1996,1997,1999 Jakub Jelinek
368 2001 Ben Collins
369+ 2012 David S. Miller
370
371 This program is free software; you can redistribute it and/or modify
372 it under the terms of the GNU General Public License as published by
373@@ -27,118 +28,654 @@
374 static ino_t inode = 0;
375 struct fs_ops ext2_fs_ops;
376
377-void com_err (const char *a, long i, const char *fmt,...)
378+#define EXT2_SUPER_MAGIC 0xEF53
379+
380+static __u32 ext2_to_cpu_32(__u32 v)
381 {
382- printf ((char *) fmt);
383+ const __u8 *p = (const __u8 *) &v;
384+
385+ return ((__u32)p[3] << 24 |
386+ (__u32)p[2] << 16 |
387+ (__u32)p[1] << 8 |
388+ (__u32)p[0]);
389 }
390
391-static void ext2fs_error (int errcode)
392+static __u16 ext2_to_cpu_16(__u16 v)
393 {
394-#if 0
395- int i;
396- for (i = 0; i < sizeof (ext2errors) / sizeof (ext2errors[0]); i++)
397- if (ext2errors[i].errnum == errcode) {
398- printf ("%s", ext2errors [i].desc);
399- return;
400- }
401-#endif
402- printf ("Unknown ext2 error: %d", errcode);
403+ const __u8 *p = (const __u8 *) &v;
404+
405+ return ((__u16)p[1] << 8) | ((__u16)p[0]);
406 }
407
408-static int open_ext2 (char *device)
409+struct silo_ext2_state {
410+ struct ext2_super_block *super;
411+
412+ void *scratch_block[4];
413+ __u32 scratch_block_blk[4];
414+
415+ __u32 inode_size;
416+ __u32 block_size;
417+ __u32 addr_per_block;
418+ __u32 addr_per_block_bits;
419+ __u32 desc_per_block;
420+ __u32 desc_per_block_bits;
421+};
422+static struct silo_ext2_state *sstate;
423+
424+static __u32 ext2_inode_size(struct silo_ext2_state *s)
425 {
426- int retval;
427+ __u32 rev = ext2_to_cpu_32(s->super->s_rev_level);
428
429- retval = ext2fs_open (device, EXT2_FLAG_DIRTY, 0, 0, silo_io_manager, &fs);
430- if (retval == EXT2_ET_BAD_MAGIC)
431- return 0;
432- if (retval) {
433- printf ("\n");
434- ext2fs_error (retval);
435- printf ("\n");
436- return 0;
437- }
438- root = EXT2_ROOT_INO;
439- return 1;
440+ if (rev == 0)
441+ return 128;
442+
443+ return ext2_to_cpu_16(s->super->s_inode_size);
444 }
445
446-static int dump_block_ext2 (ext2_filsys fs, blk_t *blocknr,
447- int blockcnt, void *private)
448+static __u32 ext2_block_size(struct silo_ext2_state *s)
449 {
450- return dump_block(blocknr, blockcnt);
451+ __u32 x = ext2_to_cpu_32(s->super->s_log_block_size);
452+
453+ x += 1;
454+
455+ return ((__u32) 1 << x) * 512;
456 }
457
458-static int dump_ext2 (void)
459+static void read_scratch_block(struct silo_ext2_state *s, __u32 block, int N)
460 {
461- if (ext2fs_block_iterate (fs, inode, 0, 0, dump_block_ext2, 0))
462+ if (s->scratch_block_blk[N] == block)
463+ return;
464+ io_channel_read_blk(fs->io, block, 1, s->scratch_block[N]);
465+ s->scratch_block_blk[N] = block;
466+}
467+
468+static void read_data(struct silo_ext2_state *s, __u32 block, __u32 off, __u32 len, void *buf)
469+{
470+ read_scratch_block(s, block, 0);
471+ memcpy(buf, s->scratch_block[0] + off, len);
472+}
473+
474+static int has_extents(struct ext2_inode *ip)
475+{
476+ if (ext2_to_cpu_32(ip->i_flags) & 0x80000)
477+ return 1;
478 return 0;
479+}
480+
481+#define EXT4_EXT_MAGIC 0xf30a
482+
483+struct ext4_extent_header {
484+ __u16 eh_magic;
485+ __u16 eh_entries;
486+ __u16 eh_max;
487+ __u16 eh_depth;
488+ __u32 eh_generation;
489+};
490+
491+struct ext4_extent_idx {
492+ __u32 ei_block;
493+ __u32 ei_leaf_lo;
494+ __u16 ei_leaf_hi;
495+ __u16 ei_unused;
496+};
497+
498+struct ext4_extent {
499+ __u32 ee_block;
500+ __u16 ee_len;
501+ __u16 ee_start_hi;
502+ __u32 ee_start_lo;
503+};
504+
505+static struct ext4_extent_header *search_leaf(struct silo_ext2_state *s,
506+ struct ext2_inode *ip,
507+ unsigned long long file_block)
508+{
509+ struct ext4_extent_header *ehp;
510+
511+ ehp = (struct ext4_extent_header *) &ip->i_block[0];
512+ for (;;) {
513+ unsigned long long ext_block, hi, lo;
514+ struct ext4_extent_idx *idxp;
515+ int i;
516+
517+ idxp = (struct ext4_extent_idx *) (ehp + 1);
518+
519+ if (ext2_to_cpu_16(ehp->eh_magic) != EXT4_EXT_MAGIC)
520+ return (struct ext4_extent_header *) 0;
521+
522+ if (ehp->eh_depth == ext2_to_cpu_16(0))
523+ return ehp;
524+
525+ for (i = 0; i < ext2_to_cpu_16(ehp->eh_entries); i++, idxp++)
526+ if (file_block < ext2_to_cpu_32(idxp->ei_block))
527+ break;
528+
529+ if (i == 0)
530+ return (struct ext4_extent_header *) 0;
531+
532+ idxp -= 1;
533+
534+ hi = ((unsigned long long)ext2_to_cpu_16(idxp->ei_leaf_hi)) << 32;
535+ lo = ext2_to_cpu_32(idxp->ei_leaf_lo);
536+ ext_block = hi | lo;
537+
538+ read_scratch_block(s, ext_block, 0);
539+ ehp = (struct ext4_extent_header *) s->scratch_block[0];
540+ }
541+}
542+
543+#define BLOCK_MAP_ERROR (~0ULL)
544+
545+static int block_to_path(struct silo_ext2_state *s, struct ext2_inode *ip,
546+ int offsets[4], long file_block)
547+{
548+ int ptrs_bits = s->addr_per_block_bits;
549+ int ptrs = s->addr_per_block;
550+ const long direct_blocks = EXT2_NDIR_BLOCKS,
551+ indirect_blocks = ptrs,
552+ double_blocks = (1 << (ptrs_bits * 2));
553+ int n = 0;
554+
555+ if (file_block < 0) {
556+ printf("EXT2: Illegal file block %ld\n", file_block);
557+ } else if (file_block < direct_blocks) {
558+ offsets[n++] = file_block;
559+ } else if ((file_block -= direct_blocks) < indirect_blocks) {
560+ offsets[n++] = EXT2_IND_BLOCK;
561+ offsets[n++] = file_block;
562+ } else if ((file_block -= indirect_blocks) < double_blocks) {
563+ offsets[n++] = EXT2_DIND_BLOCK;
564+ offsets[n++] = file_block >> ptrs_bits;
565+ offsets[n++] = file_block & (ptrs - 1);
566+ } else if (((file_block -= double_blocks) >> (ptrs_bits * 2)) < ptrs) {
567+ offsets[n++] = EXT2_TIND_BLOCK;
568+ offsets[n++] = file_block >> (ptrs_bits * 2);
569+ offsets[n++] = (file_block >> ptrs_bits) & (ptrs - 1);
570+ offsets[n++] = file_block & (ptrs - 1);
571+ } else {
572+ printf("EXT2: File block %ld is too big\n", file_block);
573+ }
574+
575+ return n;
576+}
577+
578+static unsigned long long resolve_path(struct silo_ext2_state *s,
579+ struct ext2_inode *ip,
580+ int *offsets, int depth)
581+{
582+ __u32 *p = ip->i_block + *offsets;
583+
584+ while (--depth) {
585+ __u32 block = ext2_to_cpu_32(*p);
586+
587+ read_scratch_block(s, block, depth);
588+ p = (__u32 *) s->scratch_block[depth] + *++offsets;
589+ }
590+
591+ return ext2_to_cpu_32(*p);
592+}
593+
594+static unsigned long long resolve_extent(struct silo_ext2_state *s,
595+ struct ext4_extent_header *ehp,
596+ unsigned long long file_block)
597+{
598+ unsigned long long hi, lo;
599+ struct ext4_extent *ep;
600+ int i;
601+
602+ ep = (struct ext4_extent *) (ehp + 1);
603+
604+ for (i = 0; i < ext2_to_cpu_16(ehp->eh_entries); i++, ep++)
605+ if (file_block < ext2_to_cpu_32(ep->ee_block))
606+ break;
607+
608+ if (i == 0)
609+ return BLOCK_MAP_ERROR;
610+
611+ ep -= 1;
612+ file_block -= ext2_to_cpu_32(ep->ee_block);
613+ if (file_block >= ext2_to_cpu_16(ep->ee_len))
614+ return BLOCK_MAP_ERROR;
615
616- return dump_finish ();
617+ hi = ((unsigned long long)ext2_to_cpu_16(ep->ee_start_hi)) << 32;
618+ lo = ext2_to_cpu_32(ep->ee_start_lo);
619+
620+ return (hi | lo) + file_block;
621 }
622
623-static int ls_ext2_proc(struct ext2_dir_entry *dirent, int offset,
624- int blocksize, char *buf, void *private)
625+static unsigned long long file_to_disk_block(struct silo_ext2_state *s,
626+ struct ext2_inode *ip,
627+ unsigned long long file_block)
628 {
629- struct ext2_inode ino;
630- int sl = 0, name_len = dirent->name_len & 0xFF;
631- char name[256], symlink[256];
632+ if (has_extents(ip)) {
633+ struct ext4_extent_header *ehp = search_leaf(s, ip, file_block);
634
635- strncpy(name, dirent->name, name_len);
636- name[name_len] = 0;
637+ if (ehp)
638+ return resolve_extent(s, ehp, file_block);
639
640- if (ext2fs_read_inode(fs, dirent->inode, &ino))
641- strcpy (name, "--- error ---");
642+ printf("EXT2: Extent leaf search for block %d failed\n",
643+ (int) file_block);
644
645- if (LINUX_S_ISLNK (ino.i_mode)) {
646- sl = 1;
647- if (ext2fs_inode_data_blocks(fs, &ino)) {
648- if (io_channel_read_blk(fs->io, ino.i_block[0], 1, symlink))
649- ino.i_size = 0;
650+ return BLOCK_MAP_ERROR;
651 } else {
652- strncpy (symlink, (char *)&(ino.i_block[0]),ino.i_size);
653+ int depth, offsets[4];
654+
655+ depth = block_to_path(s, ip, offsets, file_block);
656+ if (depth)
657+ return resolve_path(s, ip, offsets, depth);
658+
659+ printf("EXT2: block --> path on block %d failed\n",
660+ (int) file_block);
661+
662+ return BLOCK_MAP_ERROR;
663+ }
664+}
665+
666+static void read_file(struct silo_ext2_state *s, struct ext2_inode *ip,
667+ __u32 off, __u32 len, void *buf)
668+{
669+ unsigned long long disk_block;
670+
671+ disk_block = file_to_disk_block(s, ip, off / s->block_size);
672+
673+ read_scratch_block(s, disk_block, 0);
674+ memcpy(buf, s->scratch_block[0] + (off % s->block_size), len);
675+}
676+
677+static void read_group(struct silo_ext2_state *s, __u32 grp_no,
678+ struct ext2_group_desc *grp)
679+{
680+ __u32 first = ext2_to_cpu_32(s->super->s_first_data_block);
681+ __u32 blk, offset;
682+
683+ blk = first + 1 + (grp_no >> s->desc_per_block_bits);
684+ offset = (grp_no & (s->desc_per_block - 1)) * sizeof(*grp);
685+
686+ read_data(s, blk, offset, sizeof(*grp), grp);
687+}
688+
689+static void read_inode(struct silo_ext2_state *s, __u32 ino, struct ext2_inode *ip)
690+{
691+ __u32 grp_no, blk_no, inode_in_block, ipg, ipb;
692+ struct ext2_super_block *sb = s->super;
693+ struct ext2_group_desc gd;
694+
695+ ipg = ext2_to_cpu_32(sb->s_inodes_per_group);
696+
697+ grp_no = (ino - 1) / ipg;
698+ read_group(s, grp_no, &gd);
699+
700+ blk_no = (ino - 1) % ipg;
701+ inode_in_block = blk_no;
702+
703+ ipb = s->block_size / s->inode_size;
704+ blk_no /= ipb;
705+ inode_in_block %= ipb;
706+
707+ read_data(s,
708+ ext2_to_cpu_32(gd.bg_inode_table) + blk_no,
709+ inode_in_block * s->inode_size,
710+ sizeof(struct ext2_inode), ip);
711+}
712+
713+static int calc_ilog2(__u32 n)
714+{
715+ int i = 0;
716+
717+ while ((n >>= 1) != 0)
718+ i++;
719+
720+ return i;
721+}
722+
723+static int open_ext2(char *device)
724+{
725+ struct silo_ext2_state *s = malloc(sizeof(*s));
726+ struct ext2_super_block *sb;
727+ int err, i;
728+
729+ if (!s) {
730+ printf("Cannot allocate silo_ext2_state\n");
731+ return 0;
732+ }
733+ memset(s, 0, sizeof(*s));
734+
735+ fs = malloc(sizeof(*fs));
736+ if (!fs) {
737+ printf("Cannot allocate ext2_filsys\n");
738+ goto out_free_s;
739+ }
740+ memset(fs, 0, sizeof(*fs));
741+ err = silo_io_manager->open(device, 0, &fs->io);
742+ if (err) {
743+ printf("I/O manager open failed (err=%d)\n", err);
744+ goto out_free_fs;
745+ }
746+ fs->io->app_data = fs;
747+
748+ sb = s->super = malloc(1024);
749+ if (!sb) {
750+ printf("Cannot allocate ext2 super block\n");
751+ goto out_free_fs;
752+ }
753+
754+ io_channel_set_blksize(fs->io, 1024);
755+ err = io_channel_read_blk(fs->io, 1, -1024, sb);
756+
757+ if (ext2_to_cpu_16(sb->s_magic) != EXT2_SUPER_MAGIC) {
758+ printf("EXT2 superblock magic is wrong\n");
759+ goto out_free_super;
760+ }
761+
762+ s->inode_size = ext2_inode_size(s);
763+ s->block_size = ext2_block_size(s);
764+
765+ io_channel_set_blksize(fs->io, s->block_size);
766+
767+ s->addr_per_block = s->block_size / sizeof(__u32);
768+ s->addr_per_block_bits = calc_ilog2(s->addr_per_block);
769+ s->desc_per_block = s->block_size / sizeof(struct ext2_group_desc);
770+ s->desc_per_block_bits = calc_ilog2(s->desc_per_block);
771+
772+ s->scratch_block[0] = malloc(s->block_size * 4);
773+ if (!s->scratch_block[0]) {
774+ printf("Cannot allocate ext2 scratch blocks\n");
775+ goto out_free_super;
776+ }
777+ for (i = 1; i < 4; i++)
778+ s->scratch_block[i] =
779+ s->scratch_block[i - 1] + s->block_size;
780+ for (i = 0; i < 4; i++)
781+ s->scratch_block_blk[i] = ~(__u32)0;
782+
783+ root = EXT2_ROOT_INO;
784+
785+ sstate = s;
786+
787+ return 1;
788+
789+out_free_super:
790+ free(s->super);
791+
792+out_free_fs:
793+ free(fs);
794+ fs = NULL;
795+
796+out_free_s:
797+ free(s);
798+ return 0;
799+}
800+
801+void close_ext2 (void)
802+{
803+ struct silo_ext2_state *s = sstate;
804+
805+ if (s) {
806+ free(s->scratch_block[0]);
807+ free(s->super);
808+ free(s);
809+
810+ sstate = (struct silo_ext2_state *) 0;
811 }
812- symlink[ino.i_size] = 0;
813- }
814+}
815+
816+static int dump_ext2 (void)
817+{
818+ struct silo_ext2_state *s = sstate;
819+ struct ext2_inode ei;
820+ long file_offset;
821+ int sz, blk_sz;
822+ int blk_cnt;
823+
824+ read_inode(s, inode, &ei);
825+
826+ sz = ext2_to_cpu_32(ei.i_size);
827+ blk_sz = s->block_size;
828+
829+ blk_cnt = 0;
830+ for (file_offset = 0; file_offset < sz; file_offset += blk_sz) {
831+ blk_t disk_block;
832+
833+ disk_block = file_to_disk_block(s, &ei,
834+ file_offset / blk_sz);
835+ if (disk_block == BLOCK_MAP_ERROR)
836+ return 0;
837+
838+ if (disk_block)
839+ dump_block(&disk_block, blk_cnt);
840+
841+ blk_cnt++;
842+ }
843+
844+ return dump_finish ();
845+}
846+
847+static char *read_symlink(struct silo_ext2_state *s, struct ext2_inode *ip, char *namebuf)
848+{
849+ __u32 isize = ext2_to_cpu_32(ip->i_size);
850+
851+ if (isize <= 60)
852+ return (char *) &ip->i_block[0];
853+
854+ read_data(s, ext2_to_cpu_32(ip->i_block[0]), 0, isize, namebuf);
855+
856+ return namebuf;
857+}
858+
859+static int is_symlink(__u16 mode)
860+{
861+ if ((mode & 0xf000) == 0xa000)
862+ return 1;
863+ return 0;
864+}
865+
866+typedef int (*dir_callback_t)(struct silo_ext2_state *, struct ext2_dir_entry_2 *, void *);
867+
868+static int ls_callback(struct silo_ext2_state *s, struct ext2_dir_entry_2 *dirent, void *priv_data)
869+{
870+ struct ext2_inode e_ino;
871+ char *sym = (char *) 0;
872+ char symlink_buf[256];
873+
874+ read_inode(s, ext2_to_cpu_32(dirent->inode), &e_ino);
875+
876+ if (is_symlink(ext2_to_cpu_16(e_ino.i_mode)))
877+ sym = read_symlink(s, &e_ino, symlink_buf);
878+
879+ register_silo_inode(ext2_to_cpu_32(e_ino.i_mtime),
880+ ext2_to_cpu_32(e_ino.i_size),
881+ ext2_to_cpu_16(e_ino.i_mode),
882+ ext2_to_cpu_16(e_ino.i_uid),
883+ ext2_to_cpu_16(e_ino.i_gid),
884+ dirent->name, sym);
885+ return 0;
886+}
887+
888+static void iterate_dir(struct silo_ext2_state *s, __u32 ino, dir_callback_t cb, void *cb_arg)
889+{
890+ struct ext2_dir_entry_2 e;
891+ struct ext2_inode ei;
892+ __u32 off, size;
893
894- register_silo_inode(ino.i_mtime, ino.i_size, ino.i_mode, ino.i_uid,
895- ino.i_gid, name, sl ? symlink : NULL);
896+ read_inode(s, ino, &ei);
897+ size = ext2_to_cpu_32(ei.i_size);
898
899- return 0;
900+ for (off = 0; off < size; ) {
901+ read_file(s, &ei, off, 8, &e);
902+
903+ if (ext2_to_cpu_16(e.rec_len) == 0)
904+ break;
905+
906+ if (ext2_to_cpu_32(e.inode) == 0 ||
907+ e.name_len == 0) {
908+ off += ext2_to_cpu_16(e.rec_len);
909+ continue;
910+ }
911+
912+ read_file(s, &ei, off + 8, e.name_len, &e.name[0]);
913+ e.name[e.name_len] = 0;
914+
915+ if (cb(s, &e, cb_arg))
916+ break;
917+
918+ off += ext2_to_cpu_16(e.rec_len);
919+ }
920 }
921
922 static int ls_ext2 (void)
923 {
924- return ext2fs_dir_iterate (fs, inode, DIRENT_FLAG_INCLUDE_EMPTY,
925- 0, ls_ext2_proc, NULL);
926+ struct silo_ext2_state *s = sstate;
927+
928+ iterate_dir(s, inode, ls_callback, 0);
929+
930+ return 0;
931+}
932+
933+static int ino_size_ext2 (void)
934+{
935+ struct silo_ext2_state *s = sstate;
936+ struct ext2_inode ei = { };
937+
938+ read_inode(s, inode, &ei);
939+
940+ return ext2_to_cpu_32(ei.i_size);
941+}
942+
943+struct namei_cb_arg {
944+ const char *name;
945+ int len;
946+ ino_t *ino;
947+ int found;
948+};
949+
950+static int lookup_cb(struct silo_ext2_state *s, struct ext2_dir_entry_2 *dirent, void *priv_data)
951+{
952+ struct namei_cb_arg *p = priv_data;
953+
954+ if (p->len != dirent->name_len)
955+ return 0;
956+ if (strncmp(p->name, dirent->name, p->len))
957+ return 0;
958+ p->found = 1;
959+ *p->ino = ext2_to_cpu_32(dirent->inode);
960+ return 1;
961 }
962
963-static int ino_size_ext2 (void) {
964- struct ext2_inode ei;
965- int retval;
966+static int do_lookup(struct silo_ext2_state *s, __u32 dir_ino, const char *name,
967+ int namelen, ino_t *ret_ino)
968+{
969+ struct namei_cb_arg arg;
970+
971+ arg.name = name;
972+ arg.len = namelen;
973+ arg.ino = ret_ino;
974+ arg.found = 0;
975+
976+ iterate_dir(s, dir_ino, lookup_cb, &arg);
977
978- if ((retval = ext2fs_read_inode (fs, inode, &ei))) {
979- printf ("\n");
980- ext2fs_error (retval);
981- printf ("\n");
982+ return arg.found ? 0 : -1;
983+}
984+
985+static int open_namei(struct silo_ext2_state *s, const char *name,
986+ int namelen, ino_t root, ino_t base, ino_t *ret_ino);
987+
988+static int follow_link(struct silo_ext2_state *s, ino_t root, ino_t dir,
989+ ino_t inode, ino_t *res_inode)
990+{
991+ struct ext2_inode ei = { };
992+ char symlink_buf[256];
993+ char *sym;
994+
995+ read_inode(s, inode, &ei);
996+ if (!is_symlink(ext2_to_cpu_16(ei.i_mode))) {
997+ *res_inode = inode;
998+ return 0;
999+ }
1000+ sym = read_symlink(s, &ei, symlink_buf);
1001+ return open_namei(s, sym, ext2_to_cpu_32(ei.i_size), root, dir, res_inode);
1002+}
1003+
1004+static int dir_namei(struct silo_ext2_state *s, ino_t root, ino_t dir,
1005+ const char *pathname, int pathlen,
1006+ const char **name, int *namelen,
1007+ ino_t *res_inode)
1008+{
1009+ const char *thisname;
1010+ int len, retval;
1011+ ino_t inode;
1012+ char c;
1013+
1014+ if ((c = *pathname) == '/') {
1015+ dir = root;
1016+ pathname++;
1017+ pathlen--;
1018+ }
1019+ while (1) {
1020+ thisname = pathname;
1021+ for (len = 0; --pathlen >= 0; len++) {
1022+ c = *pathname++;
1023+ if (c == '/')
1024+ break;
1025+ }
1026+ if (pathlen < 0)
1027+ break;
1028+ retval = do_lookup(s, dir, thisname, len, &inode);
1029+ if (retval)
1030+ return retval;
1031+ retval = follow_link(s, root, dir, inode, &dir);
1032+ if (retval)
1033+ return retval;
1034+ }
1035+ *name = thisname;
1036+ *namelen = len;
1037+ *res_inode = dir;
1038 return 0;
1039- }
1040- return ei.i_size;
1041 }
1042
1043-static int namei_follow_ext2 (const char *filename) {
1044- int ret = ext2fs_namei_follow (fs, root, root, filename, &inode);
1045+static int open_namei(struct silo_ext2_state *s, const char *name,
1046+ int namelen, ino_t root, ino_t base, ino_t *ret_ino)
1047+{
1048+ const char *base_name;
1049+ ino_t dir_ino, inode;
1050+ int ret;
1051+
1052+ ret = dir_namei(s, root, base, name, namelen,
1053+ &base_name, &namelen, &dir_ino);
1054+ if (ret)
1055+ return ret;
1056+
1057+ if (!namelen) {
1058+ *ret_ino = dir_ino;
1059+ return 0;
1060+ }
1061
1062- ext2_fs_ops.have_inode = (inode) ? 1 : 0;
1063+ ret = do_lookup(s, dir_ino, base_name, namelen, &inode);
1064+ if (ret)
1065+ return ret;
1066+
1067+ ret = follow_link(s, root, dir_ino, inode, &inode);
1068+ if (ret)
1069+ return ret;
1070
1071- return ret;
1072+ *ret_ino = inode;
1073+ return 0;
1074 }
1075
1076-static void print_error_ext2 (int error_val) {
1077- ext2fs_error (error_val);
1078+static int namei_follow_ext2 (const char *filename)
1079+{
1080+ int ret;
1081+
1082+ ret = open_namei(sstate, filename, strlen(filename),
1083+ root, root, &inode);
1084+
1085+ ext2_fs_ops.have_inode = inode ? 1 : 0;
1086+
1087+ return ret;
1088 }
1089
1090-void close_ext2 (void) {
1091- ext2fs_close(fs);
1092+static void print_error_ext2 (int error_val)
1093+{
1094+ printf("error: %d", error_val);
1095 }
1096
1097 struct fs_ops ext2_fs_ops = {
1098@@ -152,14 +689,3 @@
1099 .namei_follow = namei_follow_ext2,
1100 .have_inode = 0,
1101 };
1102-
1103-/* These are silly stubs to satisfy libext2fs symbols */
1104-unsigned long time(void)
1105-{
1106- return 0;
1107-}
1108-
1109-void *realloc(void *p, int size)
1110-{
1111- return NULL;
1112-}
1113diff -Naur silo-1.4.14.orig/second/ls.c silo-1.4.14/second/ls.c
1114--- silo-1.4.14.orig/second/ls.c 2008-06-12 16:39:12.000000000 +0000
1115+++ silo-1.4.14/second/ls.c 2012-09-01 19:05:11.000000000 +0000
1116@@ -18,6 +18,7 @@
1117 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1118 USA. */
1119
1120+#include <sys/types.h>
1121 #include <silo.h>
1122 #include <stringops.h>
1123
1124diff -Naur silo-1.4.14.orig/second/main.c silo-1.4.14/second/main.c
1125--- silo-1.4.14.orig/second/main.c 2008-06-12 16:39:12.000000000 +0000
1126+++ silo-1.4.14/second/main.c 2012-09-01 19:05:11.000000000 +0000
1127@@ -25,8 +25,7 @@
1128 /* TODO: This file is a good candidate for rewrite from scratch. */
1129
1130 #include <silo.h>
1131-#include <asm/page.h>
1132-#include <linux/elf.h>
1133+#include <elf.h>
1134 #include <stringops.h>
1135
1136 #ifndef NULL
1137@@ -65,6 +64,7 @@
1138 CMD_LS
1139 } load_cmd;
1140 enum arch architecture;
1141+int sun4v_cpu;
1142 static int timer_status = 0;
1143 static char *initrd_start;
1144 static int initrd_size;
1145diff -Naur silo-1.4.14.orig/second/misc.c silo-1.4.14/second/misc.c
1146--- silo-1.4.14.orig/second/misc.c 2008-06-12 16:39:12.000000000 +0000
1147+++ silo-1.4.14/second/misc.c 2012-09-01 19:05:11.000000000 +0000
1148@@ -501,7 +501,7 @@
1149 if ((i = prom_searchsiblings(i, "MicroSPARC-IIep")) != 0) {
1150 return sun4p;
1151 }
1152- return sun4u;
1153+ buffer[4] = 'u';
1154 }
1155 i = prom_getproperty (prom_root_node, "compatability", buffer, 8);
1156
1157@@ -517,8 +517,10 @@
1158 return sun4d;
1159 case 'e':
1160 return sun4e;
1161- case 'u':
1162 case 'v':
1163+ sun4v_cpu = 1;
1164+ /* FALLTHRU */
1165+ case 'u':
1166 return sun4u;
1167 default:
1168 for(i = 0; i < NUM_SUN_MACHINES; i++)
1169diff -Naur silo-1.4.14.orig/second/muldi3.S silo-1.4.14/second/muldi3.S
1170--- silo-1.4.14.orig/second/muldi3.S 2008-06-12 16:39:12.000000000 +0000
1171+++ silo-1.4.14/second/muldi3.S 2012-09-01 19:11:45.000000000 +0000
1172@@ -20,6 +20,8 @@
1173 .text
1174 .align 4
1175 .globl __muldi3
1176+ .register %g2,#scratch
1177+ .register %g3,#scratch
1178 __muldi3:
1179 save %sp, -104, %sp
1180 wr %g0, %i1, %y
1181diff -Naur silo-1.4.14.orig/second/timer.c silo-1.4.14/second/timer.c
1182--- silo-1.4.14.orig/second/timer.c 2008-06-12 16:39:12.000000000 +0000
1183+++ silo-1.4.14/second/timer.c 2012-09-01 19:05:11.000000000 +0000
1184@@ -156,7 +156,7 @@
1185 }
1186 if (!foundcpu || !clock_frequency)
1187 clock_frequency = prom_getint(prom_root_node, "clock-frequency") / 100;
1188- if (notimer) {
1189+ if (notimer && !sun4v_cpu) {
1190 sun4u_notimer = 1;
1191 __asm__ __volatile__ ("\t"
1192 "rd %%tick_cmpr, %%g1\n\t"
1193diff -Naur silo-1.4.14.orig/silo/.gitignore silo-1.4.14/silo/.gitignore
1194--- silo-1.4.14.orig/silo/.gitignore 1970-01-01 00:00:00.000000000 +0000
1195+++ silo-1.4.14/silo/.gitignore 2012-09-01 19:05:11.000000000 +0000
1196@@ -0,0 +1,6 @@
1197+#
1198+# Generated files
1199+#
1200+floppy.h
1201+silo
1202+silocheck
1203diff -Naur silo-1.4.14.orig/tilo/.gitignore silo-1.4.14/tilo/.gitignore
1204--- silo-1.4.14.orig/tilo/.gitignore 1970-01-01 00:00:00.000000000 +0000
1205+++ silo-1.4.14/tilo/.gitignore 2012-09-01 19:05:11.000000000 +0000
1206@@ -0,0 +1,10 @@
1207+#
1208+# Generated files
1209+#
1210+b.h
1211+b.out
1212+b2.h
1213+b2.out
1214+boot
1215+boot2
1216+maketilo
Note: See TracBrowser for help on using the repository browser.