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

clfs-3.0.0-systemdsystemd
Last change on this file since a072c79 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
  • Rules.make

    Submitted By: William Harrington <kb0iic at gmail dot com>
    Date: 2012-09-01
    Initial Package Version: 1.4.14
    Upstream Status: Unknown
    Origin: git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/davem/silo
    Description:  Fixes for current silo.1.4.14 not yet released.
    
    diff -Naur silo-1.4.14.orig/Rules.make silo-1.4.14/Rules.make
    old new  
    1 VERSION=1.4.14
     1VERSION=1.4.14_git20120901
    22IMGVERSION=0.99
    33SHELL=/bin/bash
    44RM=rm -f
     
    1818                > /dev/null 2>&1; then echo "y"; else echo "n"; fi;)
    1919
    2020CFLAGS = -Os -Wall -I. -I../include -fomit-frame-pointer \
    21         -fno-strict-aliasing -DSMALL_RELOC=$(SMALL_RELOC) \
    22         -DLARGE_RELOC=$(LARGE_RELOC)
     21        -fno-strict-aliasing -U_FORTIFY_SOURCE \
     22        -DSMALL_RELOC=$(SMALL_RELOC) -DLARGE_RELOC=$(LARGE_RELOC)
    2323
    2424ifeq ($(call cc-option-yn, -fno-stack-protector),y)
    2525CFLAGS += -fno-stack-protector
  • common/.gitignore

    diff -Naur silo-1.4.14.orig/common/.gitignore silo-1.4.14/common/.gitignore
    old new  
     1#
     2# Generated files
     3#
     4bin2h
  • common/divdi3.S

    diff -Naur silo-1.4.14.orig/common/divdi3.S silo-1.4.14/common/divdi3.S
    old new  
    2020        .data
    2121        .align 8
    2222        .globl  __clz_tab
     23        .register %g2,#scratch
     24        .register %g3,#scratch
    2325__clz_tab:
    2426        .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
    2527        .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
  • common/malloc.c

    diff -Naur silo-1.4.14.orig/common/malloc.c silo-1.4.14/common/malloc.c
    old new  
    1818   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    1919   USA.  */
    2020
     21#include <stringops.h>
     22
    2123#ifndef MALLOC_BASE
    2224extern unsigned long _start;
    2325static char *malloc_ptr = ((char *)&_start) + 0x30000;
     
    2729
    2830static char *last_alloc = 0;
    2931
     32static char *align_ptr_to(char *ptr, unsigned long align)
     33{
     34    return (char *) ((((unsigned long) ptr) + (align - 1UL)) &
     35                     ~(align - 1UL));
     36}
     37
    3038void *malloc (int size)
    3139{
    3240    char *caddr;
     
    3442    caddr = malloc_ptr;
    3543    malloc_ptr += size;
    3644    last_alloc = caddr;
    37     malloc_ptr = (char *) ((((unsigned long) malloc_ptr) + 7) & (~7));
     45    malloc_ptr = align_ptr_to(malloc_ptr, 8UL);
    3846    return caddr;
    3947}
    4048
     49void *calloc (int nmemb, int memb_size)
     50{
     51    char *ret;
     52    int size;
     53
     54    if (!nmemb || !memb_size)
     55        return (void *) 0;
     56
     57    size = nmemb * memb_size;
     58    ret = malloc(size);
     59
     60    if (ret)
     61        memset(ret, 0, size);
     62
     63    return ret;
     64}
     65
     66int posix_memalign(void **memptr, unsigned long alignment, unsigned long size)
     67{
     68    char *caddr;
     69
     70    if (alignment & (alignment - 1UL))
     71        return -1;
     72    if (alignment & (sizeof(void *) - 1UL))
     73        return -1;
     74
     75    if (size == 0) {
     76      *memptr = (void *) 0;
     77      return 0;
     78    }
     79
     80    caddr = align_ptr_to(malloc_ptr, alignment);
     81    malloc_ptr = (caddr + size);
     82    last_alloc = caddr;
     83    malloc_ptr = align_ptr_to(malloc_ptr, 8UL);
     84
     85    *memptr = caddr;
     86
     87    return 0;
     88}
     89
    4190void free (void *m)
    4291{
    4392    if (m == last_alloc)
  • common/printf.c

    diff -Naur silo-1.4.14.orig/common/printf.c silo-1.4.14/common/printf.c
    old new  
    2121   USA.  */
    2222
    2323#include "promlib.h"
     24#include <stringops.h>
    2425
    2526/*
    2627 * This part is rewritten by Igor Timkin <ivt@msu.su>. Than I
     
    147148    vprintf (fmt, x1);
    148149    va_end (x1);
    149150}
     151
     152static int sprintn (char *str, long long n, int b)
     153{
     154    static char prbuf[33];
     155    register char *cp;
     156    int count = 0;
     157
     158    if (b == 10 && n < 0) {
     159        memset (str + count, '-', 1);
     160        count++;
     161        n = -n;
     162    }
     163    cp = prbuf;
     164    do
     165        *cp++ = "0123456789ABCDEF"[(unsigned int) (((unsigned long)n) % b)];
     166    while ((n = ((unsigned long long)n) / b & 0x0FFFFFFFFFFFFFFFULL));
     167    do {
     168        memset (str + count, *--cp, 1);
     169        count++;
     170    } while (cp > prbuf);
     171
     172    return count;
     173}
     174
     175int vsprintf (char *str, char *fmt, va_list adx)
     176{
     177    register int c;
     178    char *s;
     179    int count = 0;
     180
     181    for (;;) {
     182        while ((c = *fmt++) != '%') {
     183            memset (str + count, c, 1);
     184            if (c == '\0') {
     185                return count;
     186            }
     187        }
     188        c = *fmt++;
     189        if (c == 'd' || c == 'o' || c == 'x' || c == 'X') {
     190            count += sprintn (str + count, (long long) va_arg (adx, unsigned),
     191                             c == 'o' ? 8 : (c == 'd' ? 10 : 16));
     192        } else if (c == 'c') {
     193            memset (str + count, va_arg (adx, unsigned), 1);
     194            count++;
     195        } else if (c == 's') {
     196            if ((s = va_arg (adx, char *)) == NULL)
     197                s = (char *)"(null)";
     198            while ((c = *s++)) {
     199                memset (str + count, c, 1);
     200                count++;
     201            }
     202        } else if (c == 'l' || c == 'O') {
     203            count += sprintn (str + count, (long long) va_arg (adx, long), c == 'l' ? 10 : 8);
     204        } else if (c == 'L') {
     205            int hex = 0;
     206            if (*fmt == 'x') {
     207                fmt++;
     208                hex = 1;
     209            }
     210            count += sprintn (str + count, (long long) va_arg (adx, long long), hex ? 16 : 10);
     211        } else {
     212            /* This is basically what libc's printf does */
     213            memset (str + count, '%', 1);
     214            count++;
     215            memset (str + count, c, 1);
     216            count++;
     217        }
     218    }
     219
     220    return count;
     221}
     222
     223/*
     224 * Scaled down version of C Library sprintf.
     225 * Only %c %s %d (==%u) %o %x %X %l %O are recognized.
     226 */
     227
     228int sprintf (char *s, char *format, ...)
     229{
     230    va_list arg;
     231    int done;
     232
     233    va_start (arg, format);
     234    done = vsprintf (s, format, arg);
     235    va_end (arg);
     236
     237    return done;
     238}
  • common/udivdi3.S

    diff -Naur silo-1.4.14.orig/common/udivdi3.S silo-1.4.14/common/udivdi3.S
    old new  
    2020        .text
    2121        .align 4
    2222        .globl __udivdi3
     23        .register %g2,#scratch
     24        .register %g3,#scratch
    2325__udivdi3:
    2426        save %sp,-104,%sp
    2527        mov %i3,%o3
  • first/.gitignore

    diff -Naur silo-1.4.14.orig/first/.gitignore silo-1.4.14/first/.gitignore
    old new  
     1#
     2# Generated files
     3#
     4fd
     5fd.b
     6fd.h
     7first
     8first.b
     9first.h
     10generic
     11generic.b
     12generic.h
     13ieee32.b
     14ultra
     15ultra.b
     16ultra.h
  • first-isofs/.gitignore

    diff -Naur silo-1.4.14.orig/first-isofs/.gitignore silo-1.4.14/first-isofs/.gitignore
    old new  
     1#
     2# Generated files
     3#
     4isofs
     5isofs.b
  • include/ext2fs/ext2fs.h

    diff -Naur silo-1.4.14.orig/include/ext2fs/ext2fs.h silo-1.4.14/include/ext2fs/ext2fs.h
    old new  
    3939 */
    4040#define EXT2_LIB_CURRENT_REV    0
    4141
    42 #ifdef HAVE_SYS_TYPES_H
     42#if defined(HAVE_SYS_TYPES_H)
    4343#include <sys/types.h>
    4444#endif
    4545
  • include/silo.h

    diff -Naur silo-1.4.14.orig/include/silo.h silo-1.4.14/include/silo.h
    old new  
    8787void silo_disk_close(void);
    8888/* printf.c */
    8989int vprintf (char *, va_list);
     90int vsprintf (char *str, char *fmt, va_list adx);
     91int sprintf (char *s, char *format, ...);
    9092int putchar (int);
    9193/* malloc.c */
    9294void *malloc (int);
     
    123125int decompress (char *, char *, unsigned char (*)(void), void (*)(void));
    124126/* main.c */
    125127extern enum arch architecture;
     128extern int sun4v_cpu;
    126129/* timer.c */
    127130int init_timer ();
    128131void close_timer ();
  • include/stringops.h

    diff -Naur silo-1.4.14.orig/include/stringops.h silo-1.4.14/include/stringops.h
    old new  
    22#define __STRINGOPS_H
    33
    44#include <silo.h>
     5#include <stddef.h>
    56
    67/* common */
    78#ifndef __SIZE_TYPE__
    89#define __SIZE_TYPE__ long unsigned int
    910#endif
    10 #ifndef _LINUX_TYPES_H
    1111typedef __SIZE_TYPE__ size_t;
    12 #endif
    1312
    1413/* stringops1.c */
    1514char *strcpy(char *, const char *);
  • second/.gitignore

    diff -Naur silo-1.4.14.orig/second/.gitignore silo-1.4.14/second/.gitignore
    old new  
     1#
     2# Generated files
     3#
     4second
     5second.b
     6second.b2
     7second2
     8silotftp
     9silotftp.b
     10silotftp.b2
     11silotftp2
     12util
  • second/Makefile

    diff -Naur silo-1.4.14.orig/second/Makefile silo-1.4.14/second/Makefile
    old new  
    5858        $(AR) rc $@ $(FS_OBJS)
    5959
    6060second: $(OBJS) mark.o
    61         $(LD) $(LDFLAGS_SMALL) -Bstatic -o second $(OBJS) -lext2fs mark.o
    62         $(LD) $(LDFLAGS_LARGE) -Bstatic -o second2 $(OBJS) -lext2fs mark.o
     61        $(LD) $(LDFLAGS_SMALL) -Bstatic -o second $(OBJS) mark.o `$(CC) -print-libgcc-file-name`
     62        $(LD) $(LDFLAGS_LARGE) -Bstatic -o second2 $(OBJS) mark.o `$(CC) -print-libgcc-file-name`
    6363        $(NM) second | grep -v '*ABS*' | sort > second.map
    6464
    6565silotftp: $(OBJSNET) mark.o
    66         $(LD) $(LDFLAGS_SMALL) -Bstatic -o silotftp $(OBJSNET) -lext2fs mark.o
    67         $(LD) $(LDFLAGS_LARGE) -Bstatic -o silotftp2 $(OBJSNET) -lext2fs mark.o
     66        $(LD) $(LDFLAGS_SMALL) -Bstatic -o silotftp $(OBJSNET) mark.o `$(CC) -print-libgcc-file-name`
     67        $(LD) $(LDFLAGS_LARGE) -Bstatic -o silotftp2 $(OBJSNET) mark.o `$(CC) -print-libgcc-file-name`
    6868        $(NM) silotftp | grep -v '*ABS*' | sort > silotftp.map
    6969
    7070second.l: second
  • second/file.c

    diff -Naur silo-1.4.14.orig/second/file.c silo-1.4.14/second/file.c
    old new  
    1919   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    2020   USA.  */
    2121
     22#include <sys/types.h>
    2223#include <silo.h>
    2324#include <file.h>
    2425#include <stringops.h>
  • second/fs/ext2.c

    diff -Naur silo-1.4.14.orig/second/fs/ext2.c silo-1.4.14/second/fs/ext2.c
    old new  
    33   Copyright (C) 1996 Maurizio Plaza
    44                 1996,1997,1999 Jakub Jelinek
    55                 2001 Ben Collins
     6                 2012 David S. Miller
    67   
    78   This program is free software; you can redistribute it and/or modify
    89   it under the terms of the GNU General Public License as published by
     
    2728static ino_t inode = 0;
    2829struct fs_ops ext2_fs_ops;
    2930
    30 void com_err (const char *a, long i, const char *fmt,...)
     31#define EXT2_SUPER_MAGIC        0xEF53
     32
     33static __u32 ext2_to_cpu_32(__u32 v)
    3134{
    32     printf ((char *) fmt);
     35        const __u8 *p = (const __u8 *) &v;
     36
     37        return ((__u32)p[3] << 24 |
     38                (__u32)p[2] << 16 |
     39                (__u32)p[1] <<  8 |
     40                (__u32)p[0]);
    3341}
    3442
    35 static void ext2fs_error (int errcode)
     43static __u16 ext2_to_cpu_16(__u16 v)
    3644{
    37 #if 0
    38     int i;
    39     for (i = 0; i < sizeof (ext2errors) / sizeof (ext2errors[0]); i++)
    40         if (ext2errors[i].errnum == errcode) {
    41             printf ("%s", ext2errors [i].desc);
    42             return;
    43         }
    44 #endif
    45     printf ("Unknown ext2 error: %d", errcode);
     45        const __u8 *p = (const __u8 *) &v;
     46
     47        return ((__u16)p[1] << 8) | ((__u16)p[0]);
    4648}
    4749
    48 static int open_ext2 (char *device)
     50struct silo_ext2_state {
     51        struct ext2_super_block *super;
     52
     53        void                    *scratch_block[4];
     54        __u32                   scratch_block_blk[4];
     55
     56        __u32                   inode_size;
     57        __u32                   block_size;
     58        __u32                   addr_per_block;
     59        __u32                   addr_per_block_bits;
     60        __u32                   desc_per_block;
     61        __u32                   desc_per_block_bits;
     62};
     63static struct silo_ext2_state *sstate;
     64
     65static __u32 ext2_inode_size(struct silo_ext2_state *s)
    4966{
    50     int retval;
     67        __u32 rev = ext2_to_cpu_32(s->super->s_rev_level);
    5168
    52     retval = ext2fs_open (device, EXT2_FLAG_DIRTY, 0, 0, silo_io_manager, &fs);
    53     if (retval == EXT2_ET_BAD_MAGIC)
    54         return 0;
    55     if (retval) {
    56         printf ("\n");
    57         ext2fs_error (retval);
    58         printf ("\n");
    59         return 0;
    60     }
    61     root = EXT2_ROOT_INO;
    62     return 1;
     69        if (rev == 0)
     70                return 128;
     71
     72        return ext2_to_cpu_16(s->super->s_inode_size);
    6373}
    6474
    65 static int dump_block_ext2 (ext2_filsys fs, blk_t *blocknr,
    66                             int blockcnt, void *private)
     75static __u32 ext2_block_size(struct silo_ext2_state *s)
    6776{
    68     return dump_block(blocknr, blockcnt);
     77        __u32 x = ext2_to_cpu_32(s->super->s_log_block_size);
     78
     79        x += 1;
     80
     81        return ((__u32) 1 << x) * 512;
    6982}
    7083
    71 static int dump_ext2 (void)
     84static void read_scratch_block(struct silo_ext2_state *s, __u32 block, int N)
    7285{
    73     if (ext2fs_block_iterate (fs, inode, 0, 0, dump_block_ext2, 0))
     86        if (s->scratch_block_blk[N] == block)
     87                return;
     88        io_channel_read_blk(fs->io, block, 1, s->scratch_block[N]);
     89        s->scratch_block_blk[N] = block;
     90}
     91
     92static void read_data(struct silo_ext2_state *s, __u32 block, __u32 off, __u32 len, void *buf)
     93{
     94        read_scratch_block(s, block, 0);
     95        memcpy(buf, s->scratch_block[0] + off, len);
     96}
     97
     98static int has_extents(struct ext2_inode *ip)
     99{
     100        if (ext2_to_cpu_32(ip->i_flags) & 0x80000)
     101                return 1;
    74102        return 0;
     103}
     104
     105#define EXT4_EXT_MAGIC          0xf30a
     106
     107struct ext4_extent_header {
     108        __u16   eh_magic;
     109        __u16   eh_entries;
     110        __u16   eh_max;
     111        __u16   eh_depth;
     112        __u32   eh_generation;
     113};
     114
     115struct ext4_extent_idx {
     116        __u32   ei_block;
     117        __u32   ei_leaf_lo;
     118        __u16   ei_leaf_hi;
     119        __u16   ei_unused;
     120};
     121
     122struct ext4_extent {
     123        __u32   ee_block;
     124        __u16   ee_len;
     125        __u16   ee_start_hi;
     126        __u32   ee_start_lo;
     127};
     128
     129static struct ext4_extent_header *search_leaf(struct silo_ext2_state *s,
     130                                              struct ext2_inode *ip,
     131                                              unsigned long long file_block)
     132{
     133        struct ext4_extent_header *ehp;
     134
     135        ehp = (struct ext4_extent_header *) &ip->i_block[0];
     136        for (;;) {
     137                unsigned long long ext_block, hi, lo;
     138                struct ext4_extent_idx *idxp;
     139                int i;
     140
     141                idxp = (struct ext4_extent_idx *) (ehp + 1);
     142
     143                if (ext2_to_cpu_16(ehp->eh_magic) != EXT4_EXT_MAGIC)
     144                        return (struct ext4_extent_header *) 0;
     145
     146                if (ehp->eh_depth == ext2_to_cpu_16(0))
     147                        return ehp;
     148
     149                for (i = 0; i < ext2_to_cpu_16(ehp->eh_entries); i++, idxp++)
     150                        if (file_block < ext2_to_cpu_32(idxp->ei_block))
     151                                break;
     152
     153                if (i == 0)
     154                        return (struct ext4_extent_header *) 0;
     155
     156                idxp -= 1;
     157
     158                hi = ((unsigned long long)ext2_to_cpu_16(idxp->ei_leaf_hi)) << 32;
     159                lo = ext2_to_cpu_32(idxp->ei_leaf_lo);
     160                ext_block = hi | lo;
     161
     162                read_scratch_block(s, ext_block, 0);
     163                ehp = (struct ext4_extent_header *) s->scratch_block[0];
     164        }
     165}
     166
     167#define BLOCK_MAP_ERROR (~0ULL)
     168
     169static int block_to_path(struct silo_ext2_state *s, struct ext2_inode *ip,
     170                         int offsets[4], long file_block)
     171{
     172        int ptrs_bits = s->addr_per_block_bits;
     173        int ptrs = s->addr_per_block;
     174        const long direct_blocks = EXT2_NDIR_BLOCKS,
     175                indirect_blocks = ptrs,
     176                double_blocks = (1 << (ptrs_bits * 2));
     177        int n = 0;
     178
     179        if (file_block < 0) {
     180                printf("EXT2: Illegal file block %ld\n", file_block);
     181        } else if (file_block < direct_blocks) {
     182                offsets[n++] = file_block;
     183        } else if ((file_block -= direct_blocks) < indirect_blocks) {
     184                offsets[n++] = EXT2_IND_BLOCK;
     185                offsets[n++] = file_block;
     186        } else if ((file_block -= indirect_blocks) < double_blocks) {
     187                offsets[n++] = EXT2_DIND_BLOCK;
     188                offsets[n++] = file_block >> ptrs_bits;
     189                offsets[n++] = file_block & (ptrs - 1);
     190        } else if (((file_block -= double_blocks) >> (ptrs_bits * 2)) < ptrs) {
     191                offsets[n++] = EXT2_TIND_BLOCK;
     192                offsets[n++] = file_block >> (ptrs_bits * 2);
     193                offsets[n++] = (file_block >> ptrs_bits) & (ptrs - 1);
     194                offsets[n++] = file_block & (ptrs - 1);
     195        } else {
     196                printf("EXT2: File block %ld is too big\n", file_block);
     197        }
     198
     199        return n;
     200}
     201
     202static unsigned long long resolve_path(struct silo_ext2_state *s,
     203                                       struct ext2_inode *ip,
     204                                       int *offsets, int depth)
     205{
     206        __u32 *p = ip->i_block + *offsets;
     207
     208        while (--depth) {
     209                __u32 block = ext2_to_cpu_32(*p);
     210
     211                read_scratch_block(s, block, depth);
     212                p = (__u32 *) s->scratch_block[depth] + *++offsets;
     213        }
     214
     215        return ext2_to_cpu_32(*p);
     216}
     217
     218static unsigned long long resolve_extent(struct silo_ext2_state *s,
     219                                         struct ext4_extent_header *ehp,
     220                                         unsigned long long file_block)
     221{
     222        unsigned long long hi, lo;
     223        struct ext4_extent *ep;
     224        int i;
     225
     226        ep = (struct ext4_extent *) (ehp + 1);
     227
     228        for (i = 0; i < ext2_to_cpu_16(ehp->eh_entries); i++, ep++)
     229                if (file_block < ext2_to_cpu_32(ep->ee_block))
     230                        break;
     231
     232        if (i == 0)
     233                return BLOCK_MAP_ERROR;
     234
     235        ep -= 1;
     236        file_block -= ext2_to_cpu_32(ep->ee_block);
     237        if (file_block >= ext2_to_cpu_16(ep->ee_len))
     238                return BLOCK_MAP_ERROR;
    75239
    76     return dump_finish ();
     240        hi = ((unsigned long long)ext2_to_cpu_16(ep->ee_start_hi)) << 32;
     241        lo = ext2_to_cpu_32(ep->ee_start_lo);
     242
     243        return (hi | lo) + file_block;
    77244}
    78245
    79 static int ls_ext2_proc(struct ext2_dir_entry *dirent, int offset,
    80                         int blocksize, char *buf, void *private)
     246static unsigned long long file_to_disk_block(struct silo_ext2_state *s,
     247                                             struct ext2_inode *ip,
     248                                             unsigned long long file_block)
    81249{
    82     struct ext2_inode ino;
    83     int sl = 0, name_len = dirent->name_len & 0xFF;
    84     char name[256], symlink[256];
     250        if (has_extents(ip)) {
     251                struct ext4_extent_header *ehp = search_leaf(s, ip, file_block);
    85252
    86     strncpy(name, dirent->name, name_len);
    87     name[name_len] = 0;
     253                if (ehp)
     254                        return resolve_extent(s, ehp, file_block);
    88255
    89     if (ext2fs_read_inode(fs, dirent->inode, &ino))
    90         strcpy (name, "--- error ---");
     256                printf("EXT2: Extent leaf search for block %d failed\n",
     257                       (int) file_block);
    91258
    92     if (LINUX_S_ISLNK (ino.i_mode)) {
    93         sl = 1;
    94         if (ext2fs_inode_data_blocks(fs, &ino)) {
    95             if (io_channel_read_blk(fs->io, ino.i_block[0], 1, symlink))
    96                 ino.i_size = 0;
     259                return BLOCK_MAP_ERROR;
    97260        } else {
    98             strncpy (symlink, (char *)&(ino.i_block[0]),ino.i_size);
     261                int depth, offsets[4];
     262
     263                depth = block_to_path(s, ip, offsets, file_block);
     264                if (depth)
     265                        return resolve_path(s, ip, offsets, depth);
     266
     267                printf("EXT2: block --> path on block %d failed\n",
     268                       (int) file_block);
     269
     270                return BLOCK_MAP_ERROR;
     271        }
     272}
     273
     274static void read_file(struct silo_ext2_state *s, struct ext2_inode *ip,
     275                      __u32 off, __u32 len, void *buf)
     276{
     277        unsigned long long disk_block;
     278
     279        disk_block = file_to_disk_block(s, ip, off / s->block_size);
     280
     281        read_scratch_block(s, disk_block, 0);
     282        memcpy(buf, s->scratch_block[0] + (off % s->block_size), len);
     283}
     284
     285static void read_group(struct silo_ext2_state *s, __u32 grp_no,
     286                       struct ext2_group_desc *grp)
     287{
     288        __u32 first = ext2_to_cpu_32(s->super->s_first_data_block);
     289        __u32 blk, offset;
     290
     291        blk = first + 1 + (grp_no >> s->desc_per_block_bits);
     292        offset = (grp_no & (s->desc_per_block - 1)) * sizeof(*grp);
     293
     294        read_data(s, blk, offset, sizeof(*grp), grp);
     295}
     296
     297static void read_inode(struct silo_ext2_state *s, __u32 ino, struct ext2_inode *ip)
     298{
     299        __u32 grp_no, blk_no, inode_in_block, ipg, ipb;
     300        struct ext2_super_block *sb = s->super;
     301        struct ext2_group_desc gd;
     302
     303        ipg = ext2_to_cpu_32(sb->s_inodes_per_group);
     304
     305        grp_no = (ino - 1) / ipg;
     306        read_group(s, grp_no, &gd);
     307
     308        blk_no = (ino - 1) % ipg;
     309        inode_in_block = blk_no;
     310
     311        ipb = s->block_size / s->inode_size;
     312        blk_no /= ipb;
     313        inode_in_block %= ipb;
     314
     315        read_data(s,
     316                  ext2_to_cpu_32(gd.bg_inode_table) + blk_no,
     317                  inode_in_block * s->inode_size,
     318                  sizeof(struct ext2_inode), ip);
     319}
     320
     321static int calc_ilog2(__u32 n)
     322{
     323        int i = 0;
     324
     325        while ((n >>= 1) != 0)
     326                i++;
     327
     328        return i;
     329}
     330
     331static int open_ext2(char *device)
     332{
     333        struct silo_ext2_state *s = malloc(sizeof(*s));
     334        struct ext2_super_block *sb;
     335        int err, i;
     336
     337        if (!s) {
     338                printf("Cannot allocate silo_ext2_state\n");
     339                return 0;
     340        }
     341        memset(s, 0, sizeof(*s));
     342
     343        fs = malloc(sizeof(*fs));
     344        if (!fs) {
     345                printf("Cannot allocate ext2_filsys\n");
     346                goto out_free_s;
     347        }
     348        memset(fs, 0, sizeof(*fs));
     349        err = silo_io_manager->open(device, 0, &fs->io);
     350        if (err) {
     351                printf("I/O manager open failed (err=%d)\n", err);
     352                goto out_free_fs;
     353        }
     354        fs->io->app_data = fs;
     355
     356        sb = s->super = malloc(1024);
     357        if (!sb) {
     358                printf("Cannot allocate ext2 super block\n");
     359                goto out_free_fs;
     360        }
     361
     362        io_channel_set_blksize(fs->io, 1024);
     363        err = io_channel_read_blk(fs->io, 1, -1024, sb);
     364
     365        if (ext2_to_cpu_16(sb->s_magic) != EXT2_SUPER_MAGIC) {
     366                printf("EXT2 superblock magic is wrong\n");
     367                goto out_free_super;
     368        }
     369
     370        s->inode_size = ext2_inode_size(s);
     371        s->block_size = ext2_block_size(s);
     372
     373        io_channel_set_blksize(fs->io, s->block_size);
     374
     375        s->addr_per_block = s->block_size / sizeof(__u32);
     376        s->addr_per_block_bits = calc_ilog2(s->addr_per_block);
     377        s->desc_per_block = s->block_size / sizeof(struct ext2_group_desc);
     378        s->desc_per_block_bits = calc_ilog2(s->desc_per_block);
     379
     380        s->scratch_block[0] = malloc(s->block_size * 4);
     381        if (!s->scratch_block[0]) {
     382                printf("Cannot allocate ext2 scratch blocks\n");
     383                goto out_free_super;
     384        }
     385        for (i = 1; i < 4; i++)
     386                s->scratch_block[i] =
     387                        s->scratch_block[i - 1] + s->block_size;
     388        for (i = 0; i < 4; i++)
     389                s->scratch_block_blk[i] = ~(__u32)0;
     390
     391        root = EXT2_ROOT_INO;
     392
     393        sstate = s;
     394
     395        return 1;
     396
     397out_free_super:
     398        free(s->super);
     399
     400out_free_fs:
     401        free(fs);
     402        fs = NULL;
     403
     404out_free_s:
     405        free(s);
     406        return 0;
     407}
     408
     409void close_ext2 (void)
     410{
     411        struct silo_ext2_state *s = sstate;
     412
     413        if (s) {
     414                free(s->scratch_block[0]);
     415                free(s->super);
     416                free(s);
     417
     418                sstate = (struct silo_ext2_state *) 0;
    99419        }
    100         symlink[ino.i_size] = 0;
    101     }
     420}
     421
     422static int dump_ext2 (void)
     423{
     424        struct silo_ext2_state *s = sstate;
     425        struct ext2_inode ei;
     426        long file_offset;
     427        int sz, blk_sz;
     428        int blk_cnt;
     429
     430        read_inode(s, inode, &ei);
     431
     432        sz = ext2_to_cpu_32(ei.i_size);
     433        blk_sz = s->block_size;
     434
     435        blk_cnt = 0;
     436        for (file_offset = 0; file_offset < sz; file_offset += blk_sz) {
     437                blk_t disk_block;
     438
     439                disk_block = file_to_disk_block(s, &ei,
     440                                                file_offset / blk_sz);
     441                if (disk_block == BLOCK_MAP_ERROR)
     442                        return 0;
     443
     444                if (disk_block)
     445                        dump_block(&disk_block, blk_cnt);
     446
     447                blk_cnt++;
     448        }
     449
     450        return dump_finish ();
     451}
     452
     453static char *read_symlink(struct silo_ext2_state *s, struct ext2_inode *ip, char *namebuf)
     454{
     455        __u32 isize = ext2_to_cpu_32(ip->i_size);
     456
     457        if (isize <= 60)
     458                return (char *) &ip->i_block[0];
     459
     460        read_data(s, ext2_to_cpu_32(ip->i_block[0]), 0, isize, namebuf);
     461
     462        return namebuf;
     463}
     464
     465static int is_symlink(__u16 mode)
     466{
     467        if ((mode & 0xf000) == 0xa000)
     468                return 1;
     469        return 0;
     470}
     471
     472typedef int (*dir_callback_t)(struct silo_ext2_state *, struct ext2_dir_entry_2 *, void *);
     473
     474static int ls_callback(struct silo_ext2_state *s, struct ext2_dir_entry_2 *dirent, void *priv_data)
     475{
     476        struct ext2_inode e_ino;
     477        char *sym = (char *) 0;
     478        char symlink_buf[256];
     479
     480        read_inode(s, ext2_to_cpu_32(dirent->inode), &e_ino);
     481
     482        if (is_symlink(ext2_to_cpu_16(e_ino.i_mode)))
     483                sym = read_symlink(s, &e_ino, symlink_buf);
     484
     485        register_silo_inode(ext2_to_cpu_32(e_ino.i_mtime),
     486                            ext2_to_cpu_32(e_ino.i_size),
     487                            ext2_to_cpu_16(e_ino.i_mode),
     488                            ext2_to_cpu_16(e_ino.i_uid),
     489                            ext2_to_cpu_16(e_ino.i_gid),
     490                            dirent->name, sym);
     491        return 0;
     492}
     493
     494static void iterate_dir(struct silo_ext2_state *s, __u32 ino, dir_callback_t cb, void *cb_arg)
     495{
     496        struct ext2_dir_entry_2 e;
     497        struct ext2_inode ei;
     498        __u32 off, size;
    102499
    103     register_silo_inode(ino.i_mtime, ino.i_size, ino.i_mode, ino.i_uid,
    104                         ino.i_gid, name, sl ? symlink : NULL);
     500        read_inode(s, ino, &ei);
     501        size = ext2_to_cpu_32(ei.i_size);
    105502
    106     return 0;
     503        for (off = 0; off < size; ) {
     504                read_file(s, &ei, off, 8, &e);
     505
     506                if (ext2_to_cpu_16(e.rec_len) == 0)
     507                        break;
     508
     509                if (ext2_to_cpu_32(e.inode) == 0 ||
     510                    e.name_len == 0) {
     511                        off += ext2_to_cpu_16(e.rec_len);
     512                        continue;
     513                }
     514
     515                read_file(s, &ei, off + 8, e.name_len, &e.name[0]);
     516                e.name[e.name_len] = 0;
     517
     518                if (cb(s, &e, cb_arg))
     519                        break;
     520
     521                off += ext2_to_cpu_16(e.rec_len);
     522        }
    107523}
    108524
    109525static int ls_ext2 (void)
    110526{
    111     return ext2fs_dir_iterate (fs, inode, DIRENT_FLAG_INCLUDE_EMPTY,
    112                                  0, ls_ext2_proc, NULL);
     527        struct silo_ext2_state *s = sstate;
     528
     529        iterate_dir(s, inode, ls_callback, 0);
     530
     531        return 0;
     532}
     533
     534static int ino_size_ext2 (void)
     535{
     536        struct silo_ext2_state *s = sstate;
     537        struct ext2_inode ei = { };
     538
     539        read_inode(s, inode, &ei);
     540
     541        return ext2_to_cpu_32(ei.i_size);
     542}
     543
     544struct namei_cb_arg {
     545        const char      *name;
     546        int             len;
     547        ino_t           *ino;
     548        int             found;
     549};
     550
     551static int lookup_cb(struct silo_ext2_state *s, struct ext2_dir_entry_2 *dirent, void *priv_data)
     552{
     553        struct namei_cb_arg *p = priv_data;
     554
     555        if (p->len != dirent->name_len)
     556                return 0;
     557        if (strncmp(p->name, dirent->name, p->len))
     558                return 0;
     559        p->found = 1;
     560        *p->ino = ext2_to_cpu_32(dirent->inode);
     561        return 1;
    113562}
    114563
    115 static int ino_size_ext2 (void) {
    116     struct ext2_inode ei;
    117     int retval;
     564static int do_lookup(struct silo_ext2_state *s, __u32 dir_ino, const char *name,
     565                     int namelen, ino_t *ret_ino)
     566{
     567        struct namei_cb_arg arg;
     568
     569        arg.name = name;
     570        arg.len = namelen;
     571        arg.ino = ret_ino;
     572        arg.found = 0;
     573
     574        iterate_dir(s, dir_ino, lookup_cb, &arg);
    118575
    119     if ((retval = ext2fs_read_inode (fs, inode, &ei))) {
    120         printf ("\n");
    121         ext2fs_error (retval);
    122         printf ("\n");
     576        return arg.found ? 0 : -1;
     577}
     578
     579static int open_namei(struct silo_ext2_state *s, const char *name,
     580                      int namelen, ino_t root, ino_t base, ino_t *ret_ino);
     581
     582static int follow_link(struct silo_ext2_state *s, ino_t root, ino_t dir,
     583                       ino_t inode, ino_t *res_inode)
     584{
     585        struct ext2_inode ei = { };
     586        char symlink_buf[256];
     587        char *sym;
     588
     589        read_inode(s, inode, &ei);
     590        if (!is_symlink(ext2_to_cpu_16(ei.i_mode))) {
     591                *res_inode = inode;
     592                return 0;
     593        }
     594        sym = read_symlink(s, &ei, symlink_buf);
     595        return open_namei(s, sym, ext2_to_cpu_32(ei.i_size), root, dir, res_inode);
     596}
     597
     598static int dir_namei(struct silo_ext2_state *s, ino_t root, ino_t dir,
     599                     const char *pathname, int pathlen,
     600                     const char **name, int *namelen,
     601                     ino_t *res_inode)
     602{
     603        const char *thisname;
     604        int len, retval;
     605        ino_t inode;
     606        char c;
     607
     608        if ((c = *pathname) == '/') {
     609                dir = root;
     610                pathname++;
     611                pathlen--;
     612        }
     613        while (1) {
     614                thisname = pathname;
     615                for (len = 0; --pathlen >= 0; len++) {
     616                        c = *pathname++;
     617                        if (c == '/')
     618                                break;
     619                }
     620                if (pathlen < 0)
     621                        break;
     622                retval = do_lookup(s, dir, thisname, len, &inode);
     623                if (retval)
     624                        return retval;
     625                retval = follow_link(s, root, dir, inode, &dir);
     626                if (retval)
     627                        return retval;
     628        }
     629        *name = thisname;
     630        *namelen = len;
     631        *res_inode = dir;
    123632        return 0;
    124     }
    125     return ei.i_size;
    126633}
    127634
    128 static int namei_follow_ext2 (const char *filename) {
    129     int ret = ext2fs_namei_follow (fs, root, root, filename, &inode);
     635static int open_namei(struct silo_ext2_state *s, const char *name,
     636                      int namelen, ino_t root, ino_t base, ino_t *ret_ino)
     637{
     638        const char *base_name;
     639        ino_t dir_ino, inode;
     640        int ret;
     641
     642        ret = dir_namei(s, root, base, name, namelen,
     643                        &base_name, &namelen, &dir_ino);
     644        if (ret)
     645                return ret;
     646
     647        if (!namelen) {
     648                *ret_ino = dir_ino;
     649                return 0;
     650        }
    130651
    131     ext2_fs_ops.have_inode = (inode) ? 1 : 0;
     652        ret = do_lookup(s, dir_ino, base_name, namelen, &inode);
     653        if (ret)
     654                return ret;
     655
     656        ret = follow_link(s, root, dir_ino, inode, &inode);
     657        if (ret)
     658                return ret;
    132659
    133     return ret;
     660        *ret_ino = inode;
     661        return 0;
    134662}
    135663
    136 static void print_error_ext2 (int error_val) {
    137     ext2fs_error (error_val);
     664static int namei_follow_ext2 (const char *filename)
     665{
     666        int ret;
     667
     668        ret = open_namei(sstate, filename, strlen(filename),
     669                         root, root, &inode);
     670
     671        ext2_fs_ops.have_inode = inode ? 1 : 0;
     672
     673        return ret;
    138674}
    139675
    140 void close_ext2 (void) {
    141     ext2fs_close(fs);
     676static void print_error_ext2 (int error_val)
     677{
     678        printf("error: %d", error_val);
    142679}
    143680
    144681struct fs_ops ext2_fs_ops = {
     
    152689    .namei_follow       = namei_follow_ext2,
    153690    .have_inode         = 0,
    154691};
    155 
    156 /* These are silly stubs to satisfy libext2fs symbols */
    157 unsigned long time(void)
    158 {
    159         return 0;
    160 }
    161 
    162 void *realloc(void *p, int size)
    163 {
    164         return NULL;
    165 }
  • second/ls.c

    diff -Naur silo-1.4.14.orig/second/ls.c silo-1.4.14/second/ls.c
    old new  
    1818   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
    1919   USA.  */
    2020
     21#include <sys/types.h>
    2122#include <silo.h>
    2223#include <stringops.h>
    2324
  • second/main.c

    diff -Naur silo-1.4.14.orig/second/main.c silo-1.4.14/second/main.c
    old new  
    2525/* TODO: This file is a good candidate for rewrite from scratch.  */
    2626
    2727#include <silo.h>
    28 #include <asm/page.h>
    29 #include <linux/elf.h>
     28#include <elf.h>
    3029#include <stringops.h>
    3130
    3231#ifndef NULL
     
    6564    CMD_LS
    6665} load_cmd;
    6766enum arch architecture;
     67int sun4v_cpu;
    6868static int timer_status = 0;
    6969static char *initrd_start;
    7070static int initrd_size;
  • second/misc.c

    diff -Naur silo-1.4.14.orig/second/misc.c silo-1.4.14/second/misc.c
    old new  
    501501        if ((i = prom_searchsiblings(i, "MicroSPARC-IIep")) != 0) {
    502502            return sun4p;
    503503        }
    504         return sun4u;
     504        buffer[4] = 'u';
    505505    }
    506506    i = prom_getproperty (prom_root_node, "compatability", buffer, 8);
    507507
     
    517517        return sun4d;
    518518    case 'e':
    519519        return sun4e;
    520     case 'u':
    521520    case 'v':
     521        sun4v_cpu = 1;
     522        /* FALLTHRU */
     523    case 'u':
    522524        return sun4u;
    523525    default:
    524526        for(i = 0; i < NUM_SUN_MACHINES; i++)
  • second/muldi3.S

    diff -Naur silo-1.4.14.orig/second/muldi3.S silo-1.4.14/second/muldi3.S
    old new  
    2020        .text
    2121        .align 4
    2222        .globl __muldi3
     23        .register %g2,#scratch
     24        .register %g3,#scratch
    2325__muldi3:
    2426        save  %sp, -104, %sp
    2527        wr  %g0, %i1, %y
  • second/timer.c

    diff -Naur silo-1.4.14.orig/second/timer.c silo-1.4.14/second/timer.c
    old new  
    156156    }
    157157    if (!foundcpu || !clock_frequency)
    158158        clock_frequency = prom_getint(prom_root_node, "clock-frequency") / 100;
    159     if (notimer) {
     159    if (notimer && !sun4v_cpu) {
    160160        sun4u_notimer = 1;
    161161        __asm__ __volatile__ ("\t"
    162162                "rd     %%tick_cmpr, %%g1\n\t"
  • silo/.gitignore

    diff -Naur silo-1.4.14.orig/silo/.gitignore silo-1.4.14/silo/.gitignore
    old new  
     1#
     2# Generated files
     3#
     4floppy.h
     5silo
     6silocheck
  • tilo/.gitignore

    diff -Naur silo-1.4.14.orig/tilo/.gitignore silo-1.4.14/tilo/.gitignore
    old new  
     1#
     2# Generated files
     3#
     4b.h
     5b.out
     6b2.h
     7b2.out
     8boot
     9boot2
     10maketilo
Note: See TracBrowser for help on using the repository browser.