diff options
-rw-r--r-- | sys/boot/common/ufsread.c | 14 | ||||
-rw-r--r-- | sys/boot/sparc64/boot1/Makefile | 2 | ||||
-rw-r--r-- | sys/boot/sparc64/boot1/boot1.c | 136 |
3 files changed, 22 insertions, 130 deletions
diff --git a/sys/boot/common/ufsread.c b/sys/boot/common/ufsread.c index b478c25..053dbe0 100644 --- a/sys/boot/common/ufsread.c +++ b/sys/boot/common/ufsread.c @@ -37,12 +37,13 @@ #define FS_TO_VBO(fs, fsb, off) ((off) & VBLKMASK) /* Buffers that must not span a 64k boundary. */ -static struct dmadat { +struct dmadat { char blkbuf[VBLKSIZE]; /* filesystem blocks */ ufs_daddr_t indbuf[VBLKSIZE / sizeof(ufs_daddr_t)]; /* indir blocks */ char sbbuf[SBSIZE]; /* superblock */ char secbuf[DEV_BSIZE]; /* for MBR/disklabel */ -} *dmadat; +}; +static struct dmadat *dmadat; static ino_t lookup(const char *); static ssize_t fsread(ino_t, void *, size_t); @@ -71,7 +72,7 @@ fsfind(const char *name, ino_t * ino) s += d->d_reclen; } if (n != -1 && ls) - putchar('\n'); + printf("\n"); return 0; } @@ -86,6 +87,8 @@ lookup(const char *path) ino = ROOTINO; dt = DT_DIR; + name[0] = '/'; + name[1] = '\0'; for (;;) { if (*path == '/') path++; @@ -97,6 +100,10 @@ lookup(const char *path) ls = *path == '?' && n == 1 && !*s; memcpy(name, path, n); name[n] = 0; + if (dt != DT_DIR) { + printf("%s: not a directory.\n", name); + return (0); + } if ((dt = fsfind(name, &ino)) <= 0) break; path = s; @@ -180,4 +187,3 @@ fsread(ino_t inode, void *buf, size_t nbyte) } return nbyte; } - diff --git a/sys/boot/sparc64/boot1/Makefile b/sys/boot/sparc64/boot1/Makefile index ab012f7..ec41072 100644 --- a/sys/boot/sparc64/boot1/Makefile +++ b/sys/boot/sparc64/boot1/Makefile @@ -9,7 +9,7 @@ BINMODE= 444 BOOTBLOCKBASE= 0x4000 -CFLAGS= -ffreestanding -mcmodel=medlow -Os -I../.. -I../../common +CFLAGS= -ffreestanding -mcmodel=medlow -Os -I../.. -I../../common -I${.CURDIR}/../../common boot1.elf: _start.o boot1.o ${LD} -N -Ttext ${BOOTBLOCKBASE} -o ${.TARGET} ${.ALLSRC} diff --git a/sys/boot/sparc64/boot1/boot1.c b/sys/boot/sparc64/boot1/boot1.c index 872af75..692de65 100644 --- a/sys/boot/sparc64/boot1/boot1.c +++ b/sys/boot/sparc64/boot1/boot1.c @@ -62,8 +62,6 @@ int main(int ac, char **av); static void exit(int) __dead2; static void load(const char *); -static ino_t lookup(const char *); -static ssize_t fsread(ino_t, void *, size_t); static int dskread(void *, u_int64_t, int); static void usage(void); @@ -306,6 +304,12 @@ bcopy(const void *src, void *dst, size_t len) } static void +memcpy(void *dst, const void *src, size_t len) +{ + bcopy(src, dst, len); +} + +static void bzero(void *b, size_t len) { char *p = b; @@ -322,27 +326,7 @@ strcmp(const char *s1, const char *s2) return ((u_char)*s1 - (u_char)*s2); } -static int -fsfind(const char *name, ino_t * ino) -{ - char buf[DEV_BSIZE]; - struct dirent *d; - char *s; - ssize_t n; - - fs_off = 0; - while ((n = fsread(*ino, buf, DEV_BSIZE)) > 0) { - for (s = buf; s < buf + DEV_BSIZE;) { - d = (void *)s; - if (!strcmp(name, d->d_name)) { - *ino = d->d_fileno; - return (d->d_type); - } - s += d->d_reclen; - } - } - return (0); -} +#include "ufsread.c" int main(int ac, char **av) @@ -391,25 +375,21 @@ exit(int code) ofw_exit(); } +static struct dmadat __dmadat; + static int mount(const char *device) { + dmadat = &__dmadat; if ((bootdev = ofw_open(device)) == -1) { printf("mount: can't open device\n"); return (-1); } - if (dskread(blkbuf, SBOFF / DEV_BSIZE, SBSIZE / DEV_BSIZE)) { + if (fsread(0, NULL, 0)) { printf("mount: can't read superblock\n"); return (-1); } - inomap = 0; - bcopy(blkbuf, &fs, sizeof(fs)); - if (fs.fs_magic != FS_MAGIC) { - printf("mount: not ufs\n"); - return (-1); - } - fsblks = fs.fs_bsize >> DEV_BSHIFT; return (0); } @@ -455,100 +435,6 @@ load(const char *fname) (*(void (*)(int, int, int, int, ofwfp_t))eh.e_entry)(0, 0, 0, 0, ofw); } -static ino_t -lookup(const char *path) -{ - char name[MAXNAMLEN + 1]; - const char *s; - ino_t ino; - ssize_t n; - int dt; - - ino = ROOTINO; - dt = DT_DIR; - name[0] = '/'; - name[1] = '\0'; - for (;;) { - if (*path == '/') - path++; - if (!*path) - break; - for (s = path; *s && *s != '/'; s++) - ; - if ((n = s - path) > MAXNAMLEN) - return (0); - bcopy(path, name, n); - name[n] = 0; - if (dt != DT_DIR) { - printf("%s: not a directory.\n", name); - return (0); - } - if ((dt = fsfind(name, &ino)) <= 0) - break; - path = s; - } - return (dt == DT_REG ? ino : 0); -} - -static ssize_t -fsread(ino_t inode, void *buf, size_t nbyte) -{ - static struct dinode din; - static ufs_daddr_t indbuf[BSIZEMAX / sizeof(ufs_daddr_t)]; - static ufs_daddr_t blkmap, indmap; - char *s; - ufs_daddr_t lbn, addr; - size_t n, nb, off; - - if (!inode) - return (0); - if (inomap != inode) { - if (dskread(blkbuf, fsbtodb(&fs, ino_to_fsba(&fs, inode)), - fsblks)) - return (-1); - bcopy(blkbuf + ((inode % INOPB(&fs)) * sizeof(din)), &din, - sizeof(din)); - inomap = inode; - fs_off = 0; - blkmap = indmap = 0; - } - s = buf; - if (nbyte > (n = din.di_size - fs_off)) - nbyte = n; - nb = nbyte; - while (nb) { - lbn = lblkno(&fs, fs_off); - if (lbn < NDADDR) - addr = din.di_db[lbn]; - else { - if (indmap != din.di_ib[0]) { - if (dskread(indbuf, fsbtodb(&fs, din.di_ib[0]), - fsblks)) - return (-1); - indmap = din.di_ib[0]; - } - addr = indbuf[(lbn - NDADDR) % NINDIR(&fs)]; - } - n = dblksize(&fs, &din, lbn); - if (blkmap != addr) { - if (dskread(blkbuf, fsbtodb(&fs, addr), - n >> DEV_BSHIFT)) { - return (-1); - } - blkmap = addr; - } - off = blkoff(&fs, fs_off); - n -= off; - if (n > nb) - n = nb; - bcopy(blkbuf + off, s, n); - s += n; - fs_off += n; - nb -= n; - } - return (nbyte); -} - static int dskread(void *buf, u_int64_t lba, int nblk) { |