made boot/ into hierarchy of programs
work of Antoine Leca
This commit is contained in:
parent
e969b5e11b
commit
455b809b17
24 changed files with 157 additions and 1944 deletions
100
boot/Makefile
100
boot/Makefile
|
@ -1,97 +1,17 @@
|
|||
# Makefile for the boot monitor package.
|
||||
|
||||
# XXX: Can only be built with ACK currently
|
||||
CC:=${CC:C/^.*gcc/cc/}
|
||||
COMPILER_TYPE:=ack
|
||||
.include <bsd.own.mk>
|
||||
|
||||
PROGS= bootblock cdbootblock boot masterboot \
|
||||
jumpboot installboot edparams dosboot mkfile
|
||||
# 16-bit code; various boot blocks
|
||||
SUBDIR= masterboot bootblock cdbootblock
|
||||
|
||||
SRCS.bootblock= bootblock.s
|
||||
CPPFLAGS.bootblock.s= ${I86CPPFLAGS}
|
||||
LDFLAGS.bootblock= ${I86LDFLAGS}
|
||||
BINDIR.bootblock= /usr/mdec
|
||||
MAN.bootblock=
|
||||
# Supplementary MBR code (alternate to masterboot)
|
||||
SUBDIR+= jumpboot
|
||||
|
||||
SRCS.cdbootblock= cdbootblock.s
|
||||
CPPFLAGS.cdbootblock.s= ${I86CPPFLAGS} -DCDBOOT
|
||||
LDFLAGS.cdbootblock= ${I86LDFLAGS}
|
||||
BINDIR.cdbootblock= /usr/mdec
|
||||
MAN.cdbootblock=
|
||||
# 16-bit code; needs the i86 ACK library
|
||||
SUBDIR+= boot
|
||||
|
||||
SRCS.boot= boothead.s boot.c bootimage.c rawfs86.c
|
||||
CPPFLAGS.boothead.s= ${I86CPPFLAGS}
|
||||
CPPFLAGS.boot.c= ${I86CPPFLAGS}
|
||||
CPPFLAGS.bootimage.c= ${I86CPPFLAGS}
|
||||
CPPFLAGS.rawfs86.c= ${I86CPPFLAGS}
|
||||
LDFLAGS.boot= ${I86LDFLAGS}
|
||||
DPADD.boot= ${LIBSYS}
|
||||
LDADD.boot= -lsys
|
||||
BINDIR.boot= /usr/mdec
|
||||
MAN.boot=
|
||||
# Userland MINIX code
|
||||
SUBDIR+= installboot edparams
|
||||
|
||||
realall: .PHONY bootsize
|
||||
bootsize: boot
|
||||
${INSTALL} -S 22kb boot
|
||||
|
||||
SRCS.masterboot= masterboot.s
|
||||
CPPFLAGS.masterboot.s= ${I86CPPFLAGS}
|
||||
LDFLAGS.masterboot= ${I86LDFLAGS}
|
||||
BINDIR.masterboot= /usr/mdec
|
||||
MAN.masterboot=
|
||||
|
||||
SRCS.jumpboot= jumpboot.s
|
||||
CPPFLAGS.jumpboot.s= ${I86CPPFLAGS}
|
||||
LDFLAGS.jumpboot= ${I86LDFLAGS}
|
||||
BINDIR.jumpboot= /usr/mdec
|
||||
MAN.jumpboot=
|
||||
|
||||
SRCS.installboot= installboot.c rawfs.c
|
||||
BINDIR.installboot= /usr/bin
|
||||
MAN.installboot=
|
||||
|
||||
SRCS.edparams= edparams.c rawfs.c
|
||||
CPPFLAGS.edparams.c= -DUNIX
|
||||
BINDIR.edparams= /usr/bin
|
||||
MAN.edparams=
|
||||
|
||||
SRCS.dosboot= doshead.s dosboot.o bootimage.o rawfs86.o
|
||||
CPPFLAGS.dosboot.c= -DDOS $(I86CPPFLAGS)
|
||||
LDADD.dosboot= ${I86LDFLAGS} -lsys
|
||||
BINDIR.dosboot= /usr/mdec
|
||||
CPPFLAGS.doshead.s= -mi386
|
||||
MAN.dosboot=
|
||||
|
||||
SRCS.mkfile= mkfhead.s mkfile.c
|
||||
CPPFLAGS.mkfile.s= ${I86CPPFLAGS}
|
||||
LDADD.mkfile= ${I86LDFLAGS} -lsys
|
||||
BINDIR.mkfile= /usr/mdec
|
||||
MAN.mkfile=
|
||||
|
||||
rawfs86.c: rawfs.c
|
||||
ln -f rawfs.c rawfs86.c
|
||||
|
||||
edparams.c: boot.c
|
||||
ln -f boot.c edparams.c
|
||||
|
||||
dosboot.c: boot.c
|
||||
ln -f boot.c dosboot.c
|
||||
|
||||
cdbootblock.s: bootblock.s
|
||||
ln -f bootblock.s cdbootblock.s
|
||||
|
||||
mkfile.com: mkfile
|
||||
|
||||
boot.com: dosboot
|
||||
./a.out2com dosboot boot.com
|
||||
|
||||
CPPFLAGS= -I${MINIXSRCDIR}
|
||||
AFLAGS= -I${MINIXSRCDIR}
|
||||
I86CPPFLAGS= -mi86 -Was-ncc
|
||||
I86LDFLAGS= -mi86 -Was-ncc -.o -com
|
||||
|
||||
STRIPFLAG= -s
|
||||
|
||||
CLEANFILES+= rawfs86.c edparams.c cdbootblock.s dosboot.c
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
.include <bsd.subdir.mk>
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# a.out2com - Minix a.out to DOS .COM Author: Kees J. Bot
|
||||
# 17 Jun 1995
|
||||
# Transform a Minix a.out to the COM format of MS-DOS,
|
||||
# the executable must be common I&D with 256 scratch bytes at the start of
|
||||
# the text segment to make space for the Program Segment Prefix. The Minix
|
||||
# a.out header and these 256 bytes are removed to make a COM file.
|
||||
|
||||
case $# in
|
||||
2) aout="$1"
|
||||
com="$2"
|
||||
;;
|
||||
*) echo "Usage: $0 <a.out> <dos.com>" >&2
|
||||
exit 1
|
||||
esac
|
||||
|
||||
size "$aout" >/dev/null || exit
|
||||
set `size "$aout" | sed 1d`
|
||||
count=`expr \( $1 + $2 - 256 + 31 \) / 32`
|
||||
|
||||
exec dd if="$aout" of="$com" bs=32 skip=9 count=$count conv=silent
|
||||
|
||||
#
|
||||
# $PchId: a.out2com,v 1.3 1998/08/01 09:13:01 philip Exp $
|
128
boot/addaout.c
128
boot/addaout.c
|
@ -1,128 +0,0 @@
|
|||
/* A small utility to append an a.out header to an arbitrary file. This allows
|
||||
* inclusion of arbitrary data in the boot image, so that it is magically
|
||||
* loaded as a RAM disk. The a.out header is structured as follows:
|
||||
*
|
||||
* a_flags: A_IMG to indicate this is not an executable
|
||||
*
|
||||
* Created: April 2005, Jorrit N. Herder
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <a.out.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define INPUT_FILE 1
|
||||
#define OUTPUT_FILE 2
|
||||
|
||||
/* Report problems. */
|
||||
static void report(const char *problem, const char *message)
|
||||
{
|
||||
fprintf(stderr, "%s:\n", problem);
|
||||
fprintf(stderr, " %s\n\n", message);
|
||||
}
|
||||
|
||||
|
||||
static int copy_data(int srcfd, int dstfd)
|
||||
{
|
||||
char buf[8192];
|
||||
ssize_t n;
|
||||
int total=0;
|
||||
|
||||
/** FIXME: handle error from read() */
|
||||
|
||||
/* Copy the little bytes themselves. (Source from cp.c). */
|
||||
while ((n= read(srcfd, buf, sizeof(buf))) > 0) {
|
||||
char *bp = buf;
|
||||
ssize_t r = 0;
|
||||
|
||||
/** FIXME: handle error from write() */
|
||||
while (n > 0 && (r= write(dstfd, bp, n)) > 0) {
|
||||
bp += r;
|
||||
n -= r;
|
||||
total += r;
|
||||
}
|
||||
if (r == 0) {
|
||||
fprintf(stderr, "Warning: EOF writing to output file.\n");
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
return(total);
|
||||
}
|
||||
|
||||
|
||||
/* Main program. */
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct exec aout;
|
||||
struct stat stin;
|
||||
int fdin, fdout;
|
||||
char * bp;
|
||||
int n,r;
|
||||
int total_size;
|
||||
|
||||
/* Check if command line arguments are present, or print usage. */
|
||||
if (argc!=3) {
|
||||
printf("Invalid arguments. Usage:\n");
|
||||
printf(" %s <input_file> <output_file>\n",argv[0]);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* Check if we can open the input and output file. */
|
||||
if (stat(argv[INPUT_FILE], &stin) != 0) {
|
||||
report("Couldn't get status of input file", strerror(errno));
|
||||
return(1);
|
||||
}
|
||||
if ((fdin = open(argv[INPUT_FILE], O_RDONLY)) < 0) {
|
||||
report("Couldn't open input file", strerror(errno));
|
||||
return(1);
|
||||
}
|
||||
if ((fdout = open(argv[OUTPUT_FILE], O_WRONLY|O_CREAT|O_TRUNC,
|
||||
stin.st_mode & 0777)) < 0) {
|
||||
report("Couldn't open output file", strerror(errno));
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* Copy input file to output file, but leave space for a.out header. */
|
||||
lseek(fdout, sizeof(aout), SEEK_SET);
|
||||
total_size = copy_data(fdin, fdout);
|
||||
if (total_size < 0) {
|
||||
report("Aborted", "Output file may be truncated.");
|
||||
return(1);
|
||||
} else if (total_size == 0) {
|
||||
report("Aborted without prepending header", "No data in input file.");
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
/* Build a.out header and write to output file. */
|
||||
memset(&aout, 0, sizeof(struct exec));
|
||||
aout.a_magic[0] = A_MAGIC0;
|
||||
aout.a_magic[1] = A_MAGIC1;
|
||||
aout.a_flags |= A_IMG;
|
||||
aout.a_hdrlen = sizeof(aout);
|
||||
aout.a_text = 0;
|
||||
aout.a_data = total_size;
|
||||
aout.a_bss = 0;
|
||||
aout.a_total = aout.a_hdrlen + aout.a_data;
|
||||
|
||||
bp = (char *) &aout;
|
||||
n = sizeof(aout);
|
||||
lseek(fdout, 0L, SEEK_SET);
|
||||
while (n > 0 && (r= write(fdout, bp, n)) > 0) {
|
||||
bp += r;
|
||||
n -= r;
|
||||
}
|
||||
|
||||
printf("Prepended data file (%d bytes) with a.out header (%u bytes).\n",
|
||||
total_size, sizeof(aout));
|
||||
printf("Done.\n");
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
27
boot/boot/Makefile
Normal file
27
boot/boot/Makefile
Normal file
|
@ -0,0 +1,27 @@
|
|||
# boot monitor: runs in 16-bit mode
|
||||
.include <bsd.own.mk>
|
||||
|
||||
# XXX: Can only be built with ACK currently
|
||||
.include "${.CURDIR}/../minix.ack16.mk"
|
||||
AFLAGS+= -Was-ncc
|
||||
#LDFLAGS+= -stack 12kb
|
||||
STRIPFLAG= -s
|
||||
LIBDIR?= /usr/lib/i86
|
||||
|
||||
PROG= boot
|
||||
|
||||
SRCS= boothead.s boot.c bootimage.c rawfs.c
|
||||
.PATH: ${.CURDIR}/..
|
||||
CPPFLAGS+= -I${MINIXSRCDIR} -I${.CURDIR} -I${.CURDIR}/..
|
||||
|
||||
DPADD+= ${LIBSYS} # for kprintf, kmalloc
|
||||
LDADD+= -lsys
|
||||
|
||||
BINDIR= /usr/mdec
|
||||
MAN=
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
||||
realall: .PHONY bootsize
|
||||
bootsize: boot
|
||||
${INSTALL} -S 12kb boot
|
19
boot/bootblock/Makefile
Normal file
19
boot/bootblock/Makefile
Normal file
|
@ -0,0 +1,19 @@
|
|||
# bootblock: secondary boot code, still 16-bit mode
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
# XXX: Can only be built with ACK currently
|
||||
.include "${MINIXSRCDIR}/boot/minix.ack16.mk"
|
||||
AFLAGS+= -Was-ncc
|
||||
STRIPFLAG= -s
|
||||
|
||||
PROG= bootblock
|
||||
|
||||
SRCS= bootblock.s
|
||||
|
||||
BINDIR= /usr/mdec
|
||||
MAN=
|
||||
|
||||
LIBC= # defined, to silence bsd.*.mk
|
||||
|
||||
.include <bsd.prog.mk>
|
21
boot/cdbootblock/Makefile
Normal file
21
boot/cdbootblock/Makefile
Normal file
|
@ -0,0 +1,21 @@
|
|||
# cdbootblock: secondary boot code, when booting from cd-rom
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
# XXX: Can only be built with ACK currently
|
||||
.include "${MINIXSRCDIR}/boot/minix.ack16.mk"
|
||||
AFLAGS+= -Was-ncc
|
||||
STRIPFLAG= -s
|
||||
|
||||
PROG= cdbootblock
|
||||
|
||||
SRCS= bootblock.s
|
||||
.PATH: ${.CURDIR}/../bootblock
|
||||
CPPFLAGS+= -DCDBOOT
|
||||
|
||||
BINDIR= /usr/mdec
|
||||
MAN=
|
||||
|
||||
LIBC= # defined, to silence bsd.*.mk
|
||||
|
||||
.include <bsd.prog.mk>
|
1380
boot/doshead.s
1380
boot/doshead.s
File diff suppressed because it is too large
Load diff
12
boot/edparams/Makefile
Normal file
12
boot/edparams/Makefile
Normal file
|
@ -0,0 +1,12 @@
|
|||
# edparams: customize boot; runs on both installer's and user's machines
|
||||
|
||||
PROG= edparams
|
||||
BINDIR= /usr/bin
|
||||
|
||||
SRCS= boot.c rawfs.c
|
||||
.PATH: ${.CURDIR}/../boot ${.CURDIR}/..
|
||||
CPPFLAGS= -DUNIX -I${MINIXSRCDIR} -I${.CURDIR}/..
|
||||
|
||||
MAN= # monitor.8
|
||||
|
||||
.include <bsd.prog.mk>
|
12
boot/installboot/Makefile
Normal file
12
boot/installboot/Makefile
Normal file
|
@ -0,0 +1,12 @@
|
|||
# installboot: install the boot package; runs on the installer's machine
|
||||
|
||||
PROG= installboot
|
||||
BINDIR= /usr/bin
|
||||
|
||||
SRCS= installboot.c rawfs.c
|
||||
.PATH: ${.CURDIR}/..
|
||||
CPPFLAGS= -I${MINIXSRCDIR} -I${.CURDIR}/..
|
||||
|
||||
MAN= # installboot.8
|
||||
|
||||
.include <bsd.prog.mk>
|
19
boot/jumpboot/Makefile
Normal file
19
boot/jumpboot/Makefile
Normal file
|
@ -0,0 +1,19 @@
|
|||
# jumpboot: supplementary MBR code (alternate to masterboot)
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
# XXX: Can only be built with ACK currently
|
||||
.include "${MINIXSRCDIR}/boot/minix.ack16.mk"
|
||||
AFLAGS+= -Was-ncc
|
||||
STRIPFLAG= -s
|
||||
|
||||
PROG= jumpboot
|
||||
|
||||
SRCS= jumpboot.s
|
||||
|
||||
BINDIR= /usr/mdec
|
||||
MAN=
|
||||
|
||||
LIBC= # defined, to silence bsd.*.mk
|
||||
|
||||
.include <bsd.prog.mk>
|
20
boot/masterboot/Makefile
Normal file
20
boot/masterboot/Makefile
Normal file
|
@ -0,0 +1,20 @@
|
|||
# masterboot: MBR code, first to run, 16-bit mode
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
# XXX: Can only be built with ACK currently
|
||||
.include "${MINIXSRCDIR}/boot/minix.ack16.mk"
|
||||
AFLAGS+= -Was-ncc
|
||||
STRIPFLAG= -s
|
||||
|
||||
|
||||
PROG= masterboot
|
||||
|
||||
SRCS= masterboot.s
|
||||
|
||||
BINDIR= /usr/mdec
|
||||
MAN=
|
||||
|
||||
LIBC= # defined, to silence bsd.*.mk
|
||||
|
||||
.include <bsd.prog.mk>
|
11
boot/minix.ack16.mk
Normal file
11
boot/minix.ack16.mk
Normal file
|
@ -0,0 +1,11 @@
|
|||
# Makefile fragment to use Ack compiler (16-bit i86 target)
|
||||
ARCH= i86
|
||||
LIBDIR= /usr/lib/i86 # force
|
||||
|
||||
CC:=${CC:C/.*[gp]cc/cc/:C/clang/cc/}
|
||||
AR=aal
|
||||
COMPILER_TYPE=ack
|
||||
OBJECT_FMT=a.out
|
||||
CPPFLAGS+= -mi86
|
||||
AFLAGS+= -mi86
|
||||
LDFLAGS+= -mi86 -.o -com # no crtso, common I+D
|
137
boot/mkfhead.s
137
boot/mkfhead.s
|
@ -1,137 +0,0 @@
|
|||
! Mkfhead.s - DOS & BIOS support for mkfile.c Author: Kees J. Bot
|
||||
! 9 May 1998
|
||||
!
|
||||
! This file contains the startup and low level support for the MKFILE.COM
|
||||
! utility. See doshead.ack.s for more comments on .COM files.
|
||||
!
|
||||
.sect .text; .sect .rom; .sect .data; .sect .bss
|
||||
.sect .text
|
||||
|
||||
.define _PSP
|
||||
_PSP:
|
||||
.space 256 ! Program Segment Prefix
|
||||
|
||||
mkfile:
|
||||
cld ! C compiler wants UP
|
||||
xor ax, ax ! Zero
|
||||
mov di, _edata ! Start of bss is at end of data
|
||||
mov cx, _end ! End of bss (begin of heap)
|
||||
sub cx, di ! Number of bss bytes
|
||||
shr cx, 1 ! Number of words
|
||||
rep stos ! Clear bss
|
||||
|
||||
xor cx, cx ! cx = argc
|
||||
xor bx, bx
|
||||
push bx ! argv[argc] = NULL
|
||||
movb bl, (_PSP+0x80) ! Argument byte count
|
||||
0: movb _PSP+0x81(bx), ch ! Null terminate
|
||||
dec bx
|
||||
js 9f
|
||||
cmpb _PSP+0x81(bx), 0x20 ! Whitespace?
|
||||
jbe 0b
|
||||
1: dec bx ! One argument character
|
||||
js 2f
|
||||
cmpb _PSP+0x81(bx), 0x20 ! More argument characters?
|
||||
ja 1b
|
||||
2: lea ax, _PSP+0x81+1(bx) ! Address of argument
|
||||
push ax ! argv[n]
|
||||
inc cx ! argc++;
|
||||
test bx, bx
|
||||
jns 0b ! More arguments?
|
||||
9: movb _PSP+0x81(bx), ch ! Make a null string
|
||||
lea ax, _PSP+0x81(bx)
|
||||
push ax ! to use as argv[0]
|
||||
inc cx ! Final value of argc
|
||||
mov ax, sp
|
||||
push ax ! argv
|
||||
push cx ! argc
|
||||
call _main ! main(argc, argv)
|
||||
push ax
|
||||
call _exit ! exit(main(argc, argv))
|
||||
|
||||
! int creat(const char *path, mode_t mode)
|
||||
! Create a file with the old creat() call.
|
||||
.define _creat
|
||||
_creat:
|
||||
mov bx, sp
|
||||
mov dx, 2(bx) ! Filename
|
||||
xor cx, cx ! Ignore mode, always read-write
|
||||
movb ah, 0x3C ! "CREAT"
|
||||
dos: int 0x21 ! ax = creat(path, 0666);
|
||||
jc seterrno
|
||||
ret
|
||||
|
||||
seterrno:
|
||||
mov (_errno), ax ! Set errno to the DOS error code
|
||||
mov ax, -1
|
||||
cwd ! return -1L;
|
||||
ret
|
||||
|
||||
! int open(const char *path, int oflag)
|
||||
! Open a file with the oldfashioned two-argument open() call.
|
||||
.define _open
|
||||
_open:
|
||||
mov bx, sp
|
||||
mov dx, 2(bx) ! Filename
|
||||
movb al, 4(bx) ! O_RDONLY, O_WRONLY, O_RDWR
|
||||
movb ah, 0x3D ! "OPEN"
|
||||
jmp dos
|
||||
|
||||
! int close(int fd)
|
||||
! Close an open file.
|
||||
.define _close
|
||||
_close:
|
||||
mov bx, sp
|
||||
mov bx, 2(bx) ! bx = file handle
|
||||
movb ah, 0x3E ! "CLOSE"
|
||||
jmp dos
|
||||
|
||||
! void exit(int status)
|
||||
! void _exit(int status)
|
||||
! Return to DOS.
|
||||
.define _exit, __exit, ___exit
|
||||
_exit:
|
||||
__exit:
|
||||
___exit:
|
||||
pop ax
|
||||
pop ax ! al = status
|
||||
movb ah, 0x4C ! "EXIT"
|
||||
int 0x21
|
||||
hlt
|
||||
|
||||
! ssize_t read(int fd, void *buf, size_t n)
|
||||
! Read bytes from an open file.
|
||||
.define _read
|
||||
_read:
|
||||
mov bx, sp
|
||||
mov cx, 6(bx)
|
||||
mov dx, 4(bx)
|
||||
mov bx, 2(bx)
|
||||
movb ah, 0x3F ! "READ"
|
||||
jmp dos
|
||||
|
||||
! ssize_t write(int fd, const void *buf, size_t n)
|
||||
! Write bytes to an open file.
|
||||
.define _write
|
||||
_write:
|
||||
mov bx, sp
|
||||
mov cx, 6(bx)
|
||||
mov dx, 4(bx)
|
||||
mov bx, 2(bx)
|
||||
movb ah, 0x40 ! "WRITE"
|
||||
jmp dos
|
||||
|
||||
! off_t lseek(int fd, off_t offset, int whence)
|
||||
! Set file position for read or write.
|
||||
.define _lseek
|
||||
_lseek:
|
||||
mov bx, sp
|
||||
movb al, 8(bx) ! SEEK_SET, SEEK_CUR, SEEK_END
|
||||
mov dx, 4(bx)
|
||||
mov cx, 6(bx) ! cx:dx = offset
|
||||
mov bx, 2(bx)
|
||||
movb ah, 0x42 ! "LSEEK"
|
||||
jmp dos
|
||||
|
||||
!
|
||||
! $PchId: mkfhead.ack.s,v 1.3 1999/01/14 21:17:06 philip Exp $
|
179
boot/mkfile.c
179
boot/mkfile.c
|
@ -1,179 +0,0 @@
|
|||
/* mkfile 1.0 - create a file under DOS for use as a Minix "disk".
|
||||
* Author: Kees J. Bot
|
||||
* 9 May 1998
|
||||
*/
|
||||
#define nil 0
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* Stuff normally found in <unistd.h>, <errno.h>, etc. */
|
||||
extern int errno;
|
||||
int creat(const char *file, int mode);
|
||||
int open(const char *file, int oflag);
|
||||
off_t lseek(int fd, off_t offset, int whence);
|
||||
ssize_t write(int fd, const char *buf, size_t len);
|
||||
void exit(int status);
|
||||
int printf(const char *fmt, ...);
|
||||
|
||||
#define O_WRONLY 1
|
||||
#define SEEK_SET 0
|
||||
#define SEEK_END 2
|
||||
|
||||
/* Kernel printf requires a putk() function. */
|
||||
void putk(int c)
|
||||
{
|
||||
char ch = c;
|
||||
|
||||
if (c == 0) return;
|
||||
if (c == '\n') putk('\r');
|
||||
(void) write(2, &ch, 1);
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("Usage: mkfile <size>[gmk] <file>\n"
|
||||
"(Example sizes, all 50 meg: 52428800, 51200k, 50m)\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char *strerror(int err)
|
||||
/* Translate some DOS error numbers to text. */
|
||||
{
|
||||
static struct errlist {
|
||||
int err;
|
||||
char *what;
|
||||
} errlist[] = {
|
||||
{ 0, "No error" },
|
||||
{ 1, "Function number invalid" },
|
||||
{ 2, "File not found" },
|
||||
{ 3, "Path not found" },
|
||||
{ 4, "Too many open files" },
|
||||
{ 5, "Access denied" },
|
||||
{ 6, "Invalid handle" },
|
||||
{ 12, "Access code invalid" },
|
||||
{ 39, "Insufficient disk space" },
|
||||
};
|
||||
struct errlist *ep;
|
||||
static char unknown[]= "Error 65535";
|
||||
unsigned e;
|
||||
char *p;
|
||||
|
||||
for (ep= errlist; ep < errlist + sizeof(errlist)/sizeof(errlist[0]);
|
||||
ep++) {
|
||||
if (ep->err == err) return ep->what;
|
||||
}
|
||||
p= unknown + sizeof(unknown) - 1;
|
||||
e= err;
|
||||
do *--p= '0' + (e % 10); while ((e /= 10) > 0);
|
||||
strcpy(unknown + 6, p);
|
||||
return unknown;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
static char buf[512];
|
||||
unsigned long size, mul;
|
||||
off_t offset;
|
||||
char *cp;
|
||||
int fd;
|
||||
char *file;
|
||||
|
||||
if (argc != 3) usage();
|
||||
|
||||
cp= argv[1];
|
||||
size= 0;
|
||||
while ((unsigned) (*cp - '0') < 10) {
|
||||
unsigned d= *cp++ - '0';
|
||||
if (size <= (ULONG_MAX-9) / 10) {
|
||||
size= size * 10 + d;
|
||||
} else {
|
||||
size= ULONG_MAX;
|
||||
}
|
||||
}
|
||||
if (cp == argv[1]) usage();
|
||||
while (*cp != 0) {
|
||||
mul = 1;
|
||||
switch (*cp++) {
|
||||
case 'G':
|
||||
case 'g': mul *= 1024;
|
||||
case 'M':
|
||||
case 'm': mul *= 1024;
|
||||
case 'K':
|
||||
case 'k': mul *= 1024;
|
||||
case 'B':
|
||||
case 'b': break;
|
||||
default: usage();
|
||||
}
|
||||
if (size <= ULONG_MAX / mul) {
|
||||
size *= mul;
|
||||
} else {
|
||||
size= ULONG_MAX;
|
||||
}
|
||||
}
|
||||
|
||||
if (size > 1024L*1024*1024) {
|
||||
printf("mkfile: A file size over 1G is a bit too much\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Open existing file, or create a new file. */
|
||||
file= argv[2];
|
||||
if ((fd= open(file, O_WRONLY)) < 0) {
|
||||
if (errno == 2) {
|
||||
fd= creat(file, 0666);
|
||||
}
|
||||
}
|
||||
if (fd < 0) {
|
||||
printf("mkfile: Can't open %s: %s\n", file, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* How big is the file now? */
|
||||
if ((offset= lseek(fd, 0, SEEK_END)) == -1) {
|
||||
printf("mkfile: Can't seek in %s: %s\n", file, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (offset == 0 && size == 0) exit(0); /* Huh? */
|
||||
|
||||
/* Write the first bit if the file is zero length. This is necessary
|
||||
* to circumvent a DOS bug by extending a new file by lseek. We also
|
||||
* want to make sure there are zeros in the first sector.
|
||||
*/
|
||||
if (offset == 0) {
|
||||
if (write(fd, buf, sizeof(buf)) == -1) {
|
||||
printf("mkfile: Can't write to %s: %s\n",
|
||||
file, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Seek to the required size and write 0 bytes to extend/truncate the
|
||||
* file to that size.
|
||||
*/
|
||||
if (lseek(fd, size, SEEK_SET) == -1) {
|
||||
printf("mkfile: Can't seek in %s: %s\n", file, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (write(fd, buf, 0) == -1) {
|
||||
printf("mkfile: Can't write to %s: %s\n",
|
||||
file, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Did the file become the required size? */
|
||||
if ((offset= lseek(fd, 0, SEEK_END)) == -1) {
|
||||
printf("mkfile: Can't seek in %s: %s\n", file, strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
if (offset != size) {
|
||||
printf("mkfile: Failed to extend %s. Disk full?\n", file);
|
||||
exit(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* $PchId: mkfile.c,v 1.4 2000/08/13 22:06:40 philip Exp $
|
||||
*/
|
|
@ -1,6 +1,7 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
MDEC=/usr/mdec
|
||||
BOOT=/boot/boot
|
||||
ROOT=`printroot -r`
|
||||
|
||||
|
@ -20,8 +21,8 @@ fi
|
|||
make install || true
|
||||
|
||||
echo Installing boot monitor into $BOOT.
|
||||
cp boot $BOOT
|
||||
cp $MDEC/boot $BOOT
|
||||
|
||||
echo Patching position of $BOOT into $ROOT.
|
||||
installboot -d "$ROOT" /usr/mdec/bootblock $BOOT
|
||||
installboot -d "$ROOT" $MDEC/bootblock $BOOT
|
||||
sync
|
||||
|
|
|
@ -14,7 +14,7 @@ rm revision
|
|||
rm /boot/image/*
|
||||
make install
|
||||
cp /boot/image/* /boot/image_big # Make big image accessible by this name
|
||||
cp ../boot/boot /boot/boot
|
||||
cp ../boot/boot/boot /boot/boot
|
||||
cd /usr/src
|
||||
if [ $MAKEMAP -ne 0 ]; then
|
||||
find . -type f -perm 755 | xargs nm -n 2> /dev/null > symbols.txt
|
||||
|
|
|
@ -167,7 +167,7 @@ RELEASEDIR=/usr/r-staging
|
|||
RELEASEMNTDIR=/usr/r
|
||||
RELEASEPACKAGE=${RELEASEDIR}/usr/install/packages
|
||||
|
||||
IMAGE=../boot/cdbootblock
|
||||
IMAGE=../boot/cdbootblock/cdbootblock
|
||||
ROOTIMAGE=rootimage
|
||||
CDFILES=/usr/tmp/cdreleasefiles
|
||||
sh tell_config OS_RELEASE . OS_VERSION >/tmp/rel.$$
|
||||
|
@ -528,7 +528,7 @@ fi
|
|||
if [ "$USB" -ne 0 ]; then
|
||||
mv $bootimage $IMG
|
||||
else
|
||||
cp ../boot/boot $CDFILES
|
||||
cp ../boot/boot/boot $CDFILES
|
||||
writeisofs -s0x0 -l MINIX -a boot -b $bootimage $boottype $CDFILES $IMG || exit 1
|
||||
|
||||
if [ "$HDEMU" -eq 0 ]
|
||||
|
|
Loading…
Reference in a new issue