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

systemd
Last change on this file since d5d6614 was a3e5d4f, checked in by William Harrington <kb0iic@…>, 12 years ago

Add header information to silo-1.4.14-fixes-3.patch

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