Ejemplo n.º 1
0
static int
init_dev(dev_info_t* dev)
{
	char buffer[BSD_LABEL_BUFFER];
	struct disklabel *dl;
	uint64_t bs;
	int ok;

	devinfo = dev;
	dmadat = &__dmadat;

	/*
	 * First try offset 0. This is the typical GPT case where we have no
	 * further partitioning (as well as the degenerate MBR case where
	 * the bsdlabel has a 0 offset).
	 */
	devinfo->partoff = 0;
	ok = fsread(0, NULL, 0);
	if (ok >= 0)
		return (ok);

	/*
	 * Next, we look for a bsdlabel. This is technically located in sector
	 * 1. For 4k sectors, this offset is 4096, for 512b sectors it's
	 * 512. However, we have to fall back to 512 here because we create
	 * images that assume 512 byte blocks, but these can be put on devices
	 * who have 4k (or other) block sizes. If there's a crazy block size, we
	 * skip the 'at one sector' and go stright to checking at 512 bytes.
	 * There are other offsets that are historic, but we don't probe those
	 * since they were never used for MBR disks on FreeBSD on systems that
	 * could boot UEFI. UEFI is little endian only, as are BSD labels. We
	 * will retry fsread(0) only if there's a label found with a non-zero
	 * offset.
	 */
	if (dskread(buffer, 0, BSD_LABEL_BUFFER / DEV_BSIZE) != 0)
		return (-1);
	dl = NULL;
	bs = devinfo->dev->Media->BlockSize;
	if (bs != 0 && bs <= BSD_LABEL_BUFFER / 2)
		dl = (struct disklabel *)&buffer[bs];
	if (dl == NULL || dl->d_magic != BSD_MAGIC || dl->d_magic2 != BSD_MAGIC)
		dl = (struct disklabel *)&buffer[BSD_LABEL_OFFSET];
	if (dl->d_magic != BSD_MAGIC || dl->d_magic2 != BSD_MAGIC ||
	    dl->d_partitions[0].p_offset == 0)
		return (-1);
	devinfo->partoff = dl->d_partitions[0].p_offset;
	return (fsread(0, NULL, 0));
}
Ejemplo n.º 2
0
/*
 *  this just proxies what the factotum tells it to.
 */
AuthInfo*
fsfauth_proxy(CFid *fid, AuthRpc *rpc, AuthGetkey *getkey, char *params)
{
	char *buf;
	int m, n, ret;
	AuthInfo *a;
	char oerr[ERRMAX];

	rerrstr(oerr, sizeof oerr);
	werrstr("UNKNOWN AUTH ERROR");

	if(dorpc(rpc, "start", params, strlen(params), getkey) != ARok){
		werrstr("fauth_proxy start: %r");
		return nil;
	}

	buf = malloc(AuthRpcMax);
	if(buf == nil)
		return nil;
	for(;;){
		switch(dorpc(rpc, "read", nil, 0, getkey)){
		case ARdone:
			free(buf);
			a = auth_getinfo(rpc);
			errstr(oerr, sizeof oerr);	/* no error, restore whatever was there */
			return a;
		case ARok:
			if(fswrite(fid, rpc->arg, rpc->narg) != rpc->narg){
				werrstr("auth_proxy write fid: %r");
				goto Error;
			}
			break;
		case ARphase:
			n = 0;
			memset(buf, 0, AuthRpcMax);
			while((ret = dorpc(rpc, "write", buf, n, getkey)) == ARtoosmall){
				if(atoi(rpc->arg) > AuthRpcMax)
					break;
				m = fsread(fid, buf+n, atoi(rpc->arg)-n);
				if(m <= 0){
					if(m == 0)
						werrstr("auth_proxy short read: %s", buf);
					goto Error;
				}
				n += m;
			}
			if(ret != ARok){
				werrstr("auth_proxy rpc write: %s: %r", buf);
				goto Error;
			}
			break;
		default:
			werrstr("auth_proxy rpc: %r");
			goto Error;
		}
	}
Error:
	free(buf);
	return nil;
}
Ejemplo n.º 3
0
Archivo: fs.c Proyecto: 8l/inferno
/*
 *  boot
 */
int
fsboot(Fs *fs, char *path, Boot *b)
{
	File file;
	long n;
	static char buf[8192];

	switch(fswalk(fs, path, &file)){
	case -1:
		print("error walking to %s\n", path);
		return -1;
	case 0:
		print("%s not found\n", path);
		return -1;
	case 1:
		print("found %s\n", path);
		break;
	}

	while((n = fsread(&file, buf, sizeof buf)) > 0) {
		if(bootpass(b, buf, n) != MORE)
			break;
	}

	bootpass(b, nil, 0);	/* tries boot */
	return -1;
}
Ejemplo n.º 4
0
Archivo: 9p.c Proyecto: 00001/plan9port
void
xrdwr(int argc, char **argv)
{
	char buf[4096];
	int n;
	CFid *fid;

	ARGBEGIN{
	default:
		usage();
	}ARGEND

	if(argc != 1)
		usage();

	fid = xopen(argv[0], ORDWR);
	for(;;){
		fsseek(fid, 0, 0);
		if((n = fsread(fid, buf, sizeof buf)) < 0)
			fprint(2, "read: %r\n");
		else{
			if(write(1, buf, n) < 0 || write(1, "\n", 1) < 0)
				sysfatal("write error: %r");
		}
		n = read(0, buf, sizeof buf);
		if(n <= 0)
			break;
		if(buf[n-1] == '\n')
			n--;
		if(fswrite(fid, buf, n) != n)
			fprint(2, "write: %r\n");
	}
	fsclose(fid);
	threadexitsall(0);	
}
Ejemplo n.º 5
0
static inline int
xfsread(ino_t inode, void *buf, size_t nbyte)
{
    if ((size_t)fsread(inode, buf, nbyte) != nbyte)
	return -1;
    return 0;
}
Ejemplo n.º 6
0
void main(void)
{
	clrscr();
	student s1;
	printf("enter Roll no:");
	scanf("%d",&s1.rno);
	flushall();
	printf("enter Name");
	scanf("%[^\n]", s1.name);

	flushall();
	printf("enter marks");
	scanf("%d", &s1.marks);
	flushall();
	printf("\nread from console: %d-%s-%d",s1.rno, s1.name, s1.marks);

	FILE *F;
	if ((F = fopen("d:\\duplicat.txt", "a+b")) == NULL)
		fprintf(stderr, "Cannot open input file.\n");

	fswrite(&s1,F);
	fclose(F);

	fsread();

	int roll;
	printf("\nEnter roll number to find student record: ");
	scanf("%d",&roll);

	seekNread(roll);

}
Ejemplo n.º 7
0
static long
rpcread(AuthRpc *rpc, void *buf, int buflen)
{
	if (rpc->afd >= 0)
		return read(rpc->afd, buf, buflen);
	else
		return fsread(rpc->afid, buf, buflen);
}
Ejemplo n.º 8
0
static int
xfsread(ino_t inode, void *buf, size_t nbyte)
{
    if ((size_t)fsread(inode, buf, nbyte) != nbyte) {
	printf("Invalid %s\n", "format");
	return -1;
    }
    return 0;
}
Ejemplo n.º 9
0
static int
init_dev(dev_info_t* dev)
{

	devinfo = dev;
	dmadat = &__dmadat;

	return fsread(0, NULL, 0);
}
Ejemplo n.º 10
0
static inline int
xfsread(ufs_ino_t inode, void *buf, size_t nbyte)
{

	if ((size_t)fsread(inode, buf, nbyte) != nbyte) {
		printf("Invalid %s\n", "format");
		return (-1);
	}
	return (0);
}
Ejemplo n.º 11
0
static EFI_STATUS
load(const char *filepath, dev_info_t *dev, void **bufp, size_t *bufsize)
{
	ufs_ino_t ino;
	EFI_STATUS status;
	size_t size;
	ssize_t read;
	void *buf;

#ifdef EFI_DEBUG
	{
		CHAR16 *text = efi_devpath_name(dev->devpath);
		DPRINTF("Loading '%s' from %S\n", filepath, text);
		efi_free_devpath_name(text);
	}
#endif
	if (init_dev(dev) < 0) {
		DPRINTF("Failed to init device\n");
		return (EFI_UNSUPPORTED);
	}

	if ((ino = lookup(filepath)) == 0) {
		DPRINTF("Failed to lookup '%s' (file not found?)\n", filepath);
		return (EFI_NOT_FOUND);
	}

	if (fsread_size(ino, NULL, 0, &size) < 0 || size <= 0) {
		printf("Failed to read size of '%s' ino: %d\n", filepath, ino);
		return (EFI_INVALID_PARAMETER);
	}

	if ((status = BS->AllocatePool(EfiLoaderData, size, &buf)) !=
	    EFI_SUCCESS) {
		printf("Failed to allocate read buffer %zu for '%s' (%lu)\n",
		    size, filepath, EFI_ERROR_CODE(status));
		return (status);
	}

	read = fsread(ino, buf, size);
	if ((size_t)read != size) {
		printf("Failed to read '%s' (%zd != %zu)\n", filepath, read,
		    size);
		(void)BS->FreePool(buf);
		return (EFI_INVALID_PARAMETER);
	}

	DPRINTF("Load complete\n");

	*bufp = buf;
	*bufsize = size;

	return (EFI_SUCCESS);
}
Ejemplo n.º 12
0
static int
domount(EFI_DEVICE_PATH *device, EFI_BLOCK_IO *blkio, int quiet)
{

	dmadat = &__dmadat;
	bootdev = blkio;
	bootdevpath = device;
	if (fsread(0, NULL, 0)) {
		if (!quiet)
			printf("domount: can't read superblock\n");
		return (-1);
	}
	if (!quiet)
		printf("Succesfully mounted UFS filesystem\n");
	return (0);
}
Ejemplo n.º 13
0
int
main(void)
{
    int autoboot, c = 0;
    ino_t ino;

    board_init();

    dmadat = (void *)(0x20000000 + (16 << 20));
    /* Process configuration file */

    autoboot = 1;

    if ((ino = lookup(PATH_CONFIG)))
	fsread(ino, cmd, sizeof(cmd));

    if (*cmd) {
	if (parse())
	    autoboot = 0;
	printf("%s: %s", PATH_CONFIG, cmd);
	/* Do not process this command twice */
	*cmd = 0;
    }

    /* Present the user with the boot2 prompt. */

    if (*kname == '\0')
	strcpy(kname, PATH_KERNEL);
    for (;;) {
	printf("\nDefault: %s\nboot: ", kname);
	if (!autoboot || (c = getc(2)) != -1)
	    getstr(c);
	xputchar('\n');
	autoboot = 0;
	c = 0;
	if (parse())
	    xputchar('\a');
#ifdef XMODEM_DL
	else if (*cmd == '*')
	    Update();
#endif
	else
	    load();
    }
}
Ejemplo n.º 14
0
int
main(void)
{
	int autoboot, c = 0;
	ufs_ino_t ino;

	dmadat = (void *)(0x20000000 + (16 << 20));
	board_init();

	autoboot = 1;

	/* Process configuration file */
	if ((ino = lookup(PATH_CONFIG)) ||
	    (ino = lookup(PATH_DOTCONFIG)))
		fsread(ino, cmd, sizeof(cmd));

	if (*cmd) {
		if (parse())
			autoboot = 0;
		printf("%s: %s\n", PATH_CONFIG, cmd);
		/* Do not process this command twice */
		*cmd = 0;
	}

	if (*kname == '\0')
		strcpy(kname, PATH_KERNEL);

	/* Present the user with the boot2 prompt. */
	for (;;) {
		printf("\nDefault: %s\nboot: ", kname);
		if (!autoboot ||
		    (OPT_CHECK(RBX_NOINTR) == 0 && (c = getc(2)) != 0))
			getstr(c);
		xputchar('\n');
		autoboot = 0;
		c = 0;
		if (parse())
			xputchar('\a');
		else
			load();
	}
	return (1);
}
Ejemplo n.º 15
0
static EFI_STATUS
try_load(dev_info_t *dev, const char *loader_path, void **bufp, size_t *bufsize)
{
	ufs_ino_t ino;
	EFI_STATUS status;
	size_t size;
	ssize_t read;
	void *buf;

	if (init_dev(dev) < 0)
		return (EFI_UNSUPPORTED);

	if ((ino = lookup(loader_path)) == 0)
		return (EFI_NOT_FOUND);

	if (fsread_size(ino, NULL, 0, &size) < 0 || size <= 0) {
		printf("Failed to read size of '%s' ino: %d\n", loader_path,
		    ino);
		return (EFI_INVALID_PARAMETER);
	}

	if ((status = bs->AllocatePool(EfiLoaderData, size, &buf)) !=
	    EFI_SUCCESS) {
		printf("Failed to allocate read buffer (%lu)\n",
		    EFI_ERROR_CODE(status));
		return (status);
	}

	read = fsread(ino, buf, size);
	if ((size_t)read != size) {
		printf("Failed to read '%s' (%zd != %zu)\n", loader_path, read,
		    size);
		(void)bs->FreePool(buf);
		return (EFI_INVALID_PARAMETER);
	}

	*bufp = buf;
	*bufsize = size;

	return (EFI_SUCCESS);
}
Ejemplo n.º 16
0
static void
load(const char *fname)
{
	ufs_ino_t ino;
	EFI_STATUS status;
	EFI_HANDLE loaderhandle;
	EFI_LOADED_IMAGE *loaded_image;
	void *buffer;
	size_t bufsize;

	if ((ino = lookup(fname)) == 0) {
		printf("File %s not found\n", fname);
		return;
	}

	bufsize = fsstat(ino);
	status = systab->BootServices->AllocatePool(EfiLoaderData,
	    bufsize, &buffer);
	fsread(ino, buffer, bufsize);

	/* XXX: For secure boot, we need our own loader here */
	status = systab->BootServices->LoadImage(TRUE, image, bootdevpath,
	    buffer, bufsize, &loaderhandle);
	if (EFI_ERROR(status))
		printf("LoadImage failed with error %lu\n",
		    EFI_ERROR_CODE(status));

	status = systab->BootServices->HandleProtocol(loaderhandle,
	    &LoadedImageGUID, (VOID**)&loaded_image);
	if (EFI_ERROR(status))
		printf("HandleProtocol failed with error %lu\n",
		    EFI_ERROR_CODE(status));

	loaded_image->DeviceHandle = bootdevhandle;

	status = systab->BootServices->StartImage(loaderhandle, NULL, NULL);
	if (EFI_ERROR(status))
		printf("StartImage failed with error %lu\n",
		    EFI_ERROR_CODE(status));
}
Ejemplo n.º 17
0
void *
load(const char *filepath, int *bufsize)
{
	ufs_ino_t ino;
	size_t size;
	ssize_t read;

	DPRINTF("Loading '%s'\n", filepath);

	if ((ino = lookup(filepath)) == 0) {
		DPRINTF("Failed to lookup '%s' (file not found?)\n", filepath);
		return NULL;
	}

	if (fsread_size(ino, NULL, 0, &size) < 0 || size <= 0) {
		printf("Failed to read size of '%s' ino: %d\n", filepath, ino);
		return NULL;
	}

	void * buf = kernel_calloc(size, 1);
	if (buf == NULL) {
		printf("Failed to allocate read buffer %zu for '%s'\n",
		    size, filepath);
		return NULL;
	}

	read = fsread(ino, buf, size);
	if ((size_t)read != size) {
		printf("Failed to read '%s' (%zd != %zu)\n", filepath, read,
		    size);
		//free(buf);
		return NULL;
	}

	DPRINTF("Load complete\n");

	*bufsize = (int)size;

	return buf;
}
Ejemplo n.º 18
0
Archivo: 9p.c Proyecto: 00001/plan9port
void
xcon(int argc, char **argv)
{
	char buf[4096], *r, *w, *e;
	int n, nocr;
	CFid *fid;
	
	nocr = 1;

	ARGBEGIN{
	case 'r':
		nocr = 0;
		break;
	default:
		usage();
	}ARGEND

	if(argc != 1)
		usage();

	fid = xopen(argv[0], ORDWR);
	proccreate(rdcon, fid, 32768);
	for(;;){
		n = fsread(fid, buf, sizeof buf);
		if(n <= 0)
			threadexitsall(0);
		if(nocr){
			for(r=w=buf, e=buf+n; r<e; r++)
				if(*r != '\r')
					*w++ = *r;
			n = w-buf;
		}
		if(write(1, buf, n) != n)
			threadexitsall(0);
	}
	fsclose(fid);
	threadexitsall(0);	
}
Ejemplo n.º 19
0
Archivo: 9p.c Proyecto: 00001/plan9port
void
xread(int argc, char **argv)
{
	char buf[4096];
	int n;
	CFid *fid;

	ARGBEGIN{
	default:
		usage();
	}ARGEND

	if(argc != 1)
		usage();

	fid = xopen(argv[0], OREAD);
	while((n = fsread(fid, buf, sizeof buf)) > 0)
		if(write(1, buf, n) < 0)
			sysfatal("write error: %r");
	fsclose(fid);
	if(n < 0)
		sysfatal("read error: %r");
	threadexitsall(0);	
}
Ejemplo n.º 20
0
int
main(void)
{
    int autoboot;
    ino_t ino;

    dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
    v86.ctl = V86_FLAGS;
    dsk.drive = *(uint8_t *)PTOV(ARGS);
    dsk.type = dsk.drive & DRV_HARD ? TYPE_AD : TYPE_FD;
    dsk.unit = dsk.drive & DRV_MASK;
    dsk.slice = *(uint8_t *)PTOV(ARGS + 1) + 1;
    bootinfo.bi_version = BOOTINFO_VERSION;
    bootinfo.bi_size = sizeof(bootinfo);
    bootinfo.bi_basemem = 0;	/* XXX will be filled by loader or kernel */
    bootinfo.bi_extmem = memsize();
    bootinfo.bi_memsizes_valid++;

    /* Process configuration file */

    autoboot = 1;

    if ((ino = lookup(PATH_CONFIG)))
	fsread(ino, cmd, sizeof(cmd));

    if (*cmd) {
	printf("%s: %s", PATH_CONFIG, cmd);
	if (parse())
	    autoboot = 0;
	/* Do not process this command twice */
	*cmd = 0;
    }

    /*
     * Try to exec stage 3 boot loader. If interrupted by a keypress,
     * or in case of failure, try to load a kernel directly instead.
     */

    if (autoboot && !*kname) {
	memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3));
	if (!keyhit(3*SECOND)) {
	    load();
	    memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL));
	}
    }

    /* Present the user with the boot2 prompt. */

    for (;;) {
	printf("\nFreeBSD/i386 boot\n"
	       "Default: %u:%s(%u,%c)%s\n"
	       "boot: ",
	       dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit,
	       'a' + dsk.part, kname);
	if (ioctrl & IO_SERIAL)
	    sio_flush();
	if (!autoboot || keyhit(5*SECOND))
	    getstr();
	else
	    putchar('\n');
	autoboot = 0;
	if (parse())
	    putchar('\a');
	else
	    load();
    }
}
Ejemplo n.º 21
0
Archivo: cpu.c Proyecto: 99years/plan9
void
notefs(int fd)
{
	uchar buf[IOHDRSZ+Maxfdata];
	int i, n, ncpunote;
	Fcall f;
	Qid wqid[MAXWELEM];
	Fid *fid, *nfid;
	int doreply;

	rfork(RFNOTEG);
	fmtinstall('F', fcallfmt);

	for(n = 0; n < Nfid; n++){
		fids[n].file = -1;
		fids[n].omode = -1;
	}

	ncpunote = 0;
	for(;;){
		n = read9pmsg(fd, buf, sizeof(buf));
		if(n <= 0){
			if(dbg)
				fprint(2, "read9pmsg(%d) returns %d: %r\n", fd, n);
			break;
		}
		if(convM2S(buf, n, &f) <= BIT16SZ)
			break;
		if(dbg)
			fprint(2, "notefs: ->%F\n", &f);
		doreply = 1;
		fid = getfid(f.fid);
		if(fid == nil){
nofids:
			f.type = Rerror;
			f.ename = Enofile;
			fsreply(fd, &f);
			continue;
		}
		switch(f.type++){
		default:
			f.type = Rerror;
			f.ename = "unknown type";
			break;
		case Tflush:
			flushreq(f.oldtag);
			break;
		case Tversion:
			if(f.msize > IOHDRSZ+Maxfdata)
				f.msize = IOHDRSZ+Maxfdata;
			break;
		case Tauth:
			f.type = Rerror;
			f.ename = "authentication not required";
			break;
		case Tattach:
			f.qid = fstab[Qdir].qid;
			fid->file = Qdir;
			break;
		case Twalk:
			nfid = nil;
			if(f.newfid != f.fid){
				nfid = getfid(f.newfid);
				if(nfid == nil)
					goto nofids;
				nfid->file = fid->file;
				fid = nfid;
			}
			for(i=0; i<f.nwname && i<MAXWELEM; i++){
				if(fid->file != Qdir){
					f.type = Rerror;
					f.ename = Enotdir;
					break;
				}
				if(strcmp(f.wname[i], "..") == 0){
					wqid[i] = fstab[Qdir].qid;
					continue;
				}
				if(strcmp(f.wname[i], "cpunote") != 0){
					if(i == 0){
						f.type = Rerror;
						f.ename = "file does not exist";
					}
					break;
				}
				fid->file = Qcpunote;
				wqid[i] = fstab[Qcpunote].qid;
			}
			if(nfid != nil && (f.type == Rerror || i < f.nwname))
				nfid ->file = -1;
			if(f.type != Rerror){
				f.nwqid = i;
				for(i=0; i<f.nwqid; i++)
					f.wqid[i] = wqid[i];
			}
			break;
		case Topen:
			if(f.mode != OREAD){
				f.type = Rerror;
				f.ename = Eperm;
				break;
			}
			fid->omode = f.mode;
			if(fid->file == Qcpunote)
				ncpunote++;
			f.qid = fstab[fid->file].qid;
			f.iounit = 0;
			break;
		case Tread:
			if(fsread(fd, fid, &f) < 0)
				goto err;
			doreply = 0;
			break;
		case Tclunk:
			if(fid->omode != -1 && fid->file == Qcpunote){
				ncpunote--;
				if(ncpunote == 0)	/* remote side is done */
					goto err;
			}
			fid->file = -1;
			fid->omode = -1;
			break;
		case Tstat:
			if(fsstat(fd, fid, &f) < 0)
				goto err;
			doreply = 0;
			break;
		case Tcreate:
		case Twrite:
		case Tremove:
		case Twstat:
			f.type = Rerror;
			f.ename = Eperm;
			break;
		}
		if(doreply)
			if(fsreply(fd, &f) < 0)
				break;
	}
err:
	if(dbg)
		fprint(2, "notefs exiting: %r\n");
	werrstr("success");
	postnote(PNGROUP, exportpid, "kill");
	if(dbg)
		fprint(2, "postnote PNGROUP %d: %r\n", exportpid);
	close(fd);
}
Ejemplo n.º 22
0
int
main(void)
{
    uint8_t autoboot;
    ufs_ino_t ino;
    size_t nbyte;

    dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
    v86.ctl = V86_FLAGS;
    v86.efl = PSL_RESERVED_DEFAULT | PSL_I;
    dsk.drive = *(uint8_t *)PTOV(ARGS);
    dsk.type = dsk.drive & DRV_HARD ? TYPE_AD : TYPE_FD;
    dsk.unit = dsk.drive & DRV_MASK;
    dsk.slice = *(uint8_t *)PTOV(ARGS + 1) + 1;
    bootinfo.bi_version = BOOTINFO_VERSION;
    bootinfo.bi_size = sizeof(bootinfo);

    /* Process configuration file */

    autoboot = 1;

    if ((ino = lookup(PATH_CONFIG)) ||
        (ino = lookup(PATH_DOTCONFIG))) {
	nbyte = fsread(ino, cmd, sizeof(cmd) - 1);
	cmd[nbyte] = '\0';
    }

    if (*cmd) {
	memcpy(cmddup, cmd, sizeof(cmd));
	if (parse())
	    autoboot = 0;
	if (!OPT_CHECK(RBX_QUIET))
	    printf("%s: %s", PATH_CONFIG, cmddup);
	/* Do not process this command twice */
	*cmd = 0;
    }

    /*
     * Try to exec stage 3 boot loader. If interrupted by a keypress,
     * or in case of failure, try to load a kernel directly instead.
     */

    if (!kname) {
	kname = PATH_BOOT3;
	if (autoboot && !keyhit(3*SECOND)) {
	    load();
	    kname = PATH_KERNEL;
	}
    }

    /* Present the user with the boot2 prompt. */

    for (;;) {
	if (!autoboot || !OPT_CHECK(RBX_QUIET))
	    printf("\nFreeBSD/x86 boot\n"
		   "Default: %u:%s(%u,%c)%s\n"
		   "boot: ",
		   dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit,
		   'a' + dsk.part, kname);
	if (DO_SIO)
	    sio_flush();
	if (!autoboot || keyhit(3*SECOND))
	    getstr();
	else if (!autoboot || !OPT_CHECK(RBX_QUIET))
	    putchar('\n');
	autoboot = 0;
	if (parse())
	    putchar('\a');
	else
	    load();
    }
}
Ejemplo n.º 23
0
int
main(void)
{
	char cmd[512], cmdtmp[512];
	int autoboot, dskupdated;
	ufs_ino_t ino;

	dmadat = (void *)(roundup2(__base + (int32_t)&_end, 0x10000) - __base);
	v86.ctl = V86_FLAGS;
	v86.efl = PSL_RESERVED_DEFAULT | PSL_I;
	dsk.drive = *(uint8_t *)PTOV(ARGS);
	dsk.type = dsk.drive & DRV_HARD ? TYPE_AD : TYPE_FD;
	dsk.unit = dsk.drive & DRV_MASK;
	dsk.part = -1;
	dsk.start = 0;
	bootinfo.bi_version = BOOTINFO_VERSION;
	bootinfo.bi_size = sizeof(bootinfo);
	bootinfo.bi_basemem = 0;	/* XXX will be filled by loader or kernel */
	bootinfo.bi_extmem = memsize();
	bootinfo.bi_memsizes_valid++;

	/* Process configuration file */

	if (gptinit() != 0)
		return (-1);

	autoboot = 1;
	*cmd = '\0';

	for (;;) {
		*kname = '\0';
		if ((ino = lookup(PATH_CONFIG)) ||
		    (ino = lookup(PATH_DOTCONFIG)))
			fsread(ino, cmd, sizeof(cmd));

		if (*cmd != '\0') {
			memcpy(cmdtmp, cmd, sizeof(cmdtmp));
			if (parse(cmdtmp, &dskupdated))
				break;
			if (dskupdated && gptinit() != 0)
				break;
			if (!OPT_CHECK(RBX_QUIET))
				printf("%s: %s", PATH_CONFIG, cmd);
			*cmd = '\0';
		}

		if (autoboot && keyhit(3)) {
			if (*kname == '\0')
				memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3));
			break;
		}
		autoboot = 0;

		/*
		 * Try to exec stage 3 boot loader. If interrupted by a
		 * keypress, or in case of failure, try to load a kernel
		 * directly instead.
		 */
		if (*kname != '\0')
			load();
		memcpy(kname, PATH_BOOT3, sizeof(PATH_BOOT3));
		load();
		memcpy(kname, PATH_KERNEL, sizeof(PATH_KERNEL));
		load();
		gptbootfailed(&dsk);
		if (gptfind(&freebsd_ufs_uuid, &dsk, -1) == -1)
			break;
		dsk_meta = 0;
	}

	/* Present the user with the boot2 prompt. */

	for (;;) {
		if (!OPT_CHECK(RBX_QUIET)) {
			printf("\nFreeBSD/x86 boot\n"
			    "Default: %u:%s(%up%u)%s\n"
			    "boot: ",
			    dsk.drive & DRV_MASK, dev_nm[dsk.type], dsk.unit,
			    dsk.part, kname);
		}
		if (ioctrl & IO_SERIAL)
			sio_flush();
		*cmd = '\0';
		if (keyhit(0))
			getstr(cmd, sizeof(cmd));
		else if (!OPT_CHECK(RBX_QUIET))
			putchar('\n');
		if (parse(cmd, &dskupdated)) {
			putchar('\a');
			continue;
		}
		if (dskupdated && gptinit() != 0)
			continue;
		load();
	}
	/* NOTREACHED */
}
Ejemplo n.º 24
0
int
main(u_int argc, const char *argv[], const char *envv[], uint64_t memsize)
{
    uint8_t autoboot;
    ufs_ino_t ino;
    size_t nbyte;

    /* Arguments from Miniboot. */
    beri_argc = argc;
    beri_argv = argv;
    beri_envv = envv;
    beri_memsize = memsize;

    dmadat = &__dmadat;
#if 0
    /* XXXRW: more here. */
    v86.ctl = V86_FLAGS;
    v86.efl = PSL_RESERVED_DEFAULT | PSL_I;
    dsk.drive = *(uint8_t *)PTOV(ARGS);
#endif
    dsk.type = TYPE_DEFAULT;
#if 0
    dsk.unit = dsk.drive & DRV_MASK;
    dsk.slice = *(uint8_t *)PTOV(ARGS + 1) + 1;
#endif
    bootinfo.bi_version = BOOTINFO_VERSION;
    bootinfo.bi_size = sizeof(bootinfo);

    /* Process configuration file */

    autoboot = 1;

    if ((ino = lookup(PATH_CONFIG)) ||
        (ino = lookup(PATH_DOTCONFIG))) {
	nbyte = fsread(ino, cmd, sizeof(cmd) - 1);
	cmd[nbyte] = '\0';
    }

    if (*cmd) {
	memcpy(cmddup, cmd, sizeof(cmd));
	if (parse())
	    autoboot = 0;
	if (!OPT_CHECK(RBX_QUIET))
	    printf("%s: %s", PATH_CONFIG, cmddup);
	/* Do not process this command twice */
	*cmd = 0;
    }

    /*
     * Try to exec stage 3 boot loader. If interrupted by a keypress,
     * or in case of failure, try to load a kernel directly instead.
     */

    if (!kname) {
	kname = PATH_LOADER;
	if (autoboot && !keyhit(3*SECOND)) {
	    boot_fromfs();
	    kname = PATH_KERNEL;
	}
    }

    /* Present the user with the boot2 prompt. */

    for (;;) {
	if (!autoboot || !OPT_CHECK(RBX_QUIET))
	    printf("\nFreeBSD/mips boot\n"
		   "Default: %s%ju:%s\n"
		   "boot: ",
		   dev_nm[dsk.type], dsk.unitptr, kname);
#if 0
	if (ioctrl & IO_SERIAL)
	    sio_flush();
#endif
	if (!autoboot || keyhit(3*SECOND))
	    getstr();
	else if (!autoboot || !OPT_CHECK(RBX_QUIET))
	    putchar('\n');
	autoboot = 0;
	if (parse())
	    putchar('\a');
	else
	    load();
    }
}
Ejemplo n.º 25
0
int
mboxcommand(Window *w, char *s)
{
	char *args[10], **targs, *save;
	Window *sbox;
	Message *m, *next;
	int ok, nargs, i, j;
	CFid *searchfd;
	char buf[128], *res;

	nargs = tokenize(s, args, nelem(args));
	if(nargs == 0)
		return 0;
	if(strcmp(args[0], "Mail") == 0){
		if(nargs == 1)
			mkreply(nil, "Mail", "", nil, nil);
		else
			mkreply(nil, "Mail", args[1], nil, nil);
		return 1;
	}
	if(strcmp(s, "Del") == 0){
		if(mbox.dirty){
			mbox.dirty = 0;
			fprint(2, "mail: mailbox not written\n");
			return 1;
		}
		if(w != mbox.w){
			windel(w, 1);
			return 1;
		}
		ok = 1;
		for(m=mbox.head; m!=nil; m=next){
			next = m->next;
			if(m->w){
				if(windel(m->w, 0))
					m->w = nil;
				else
					ok = 0;
			}
		}
		for(m=replies.head; m!=nil; m=next){
			next = m->next;
			if(m->w){
				if(windel(m->w, 0))
					m->w = nil;
				else
					ok = 0;
			}
		}
		if(ok){
			windel(w, 1);
			removeupasfs();
			threadexitsall(nil);
		}
		return 1;
	}
	if(strcmp(s, "Put") == 0){
		rewritembox(wbox, &mbox);
		return 1;
	}
	if(strcmp(s, "Get") == 0){
		fswrite(mbox.ctlfd, "refresh", 7);
		return 1;
	}
	if(strcmp(s, "Delmesg") == 0){
		save = nil;
		if(nargs > 1)
			save = args[1];
		s = winselection(w);
		if(s == nil)
			return 1;
		nargs = 1;
		for(i=0; s[i]; i++)
			if(s[i] == '\n')
				nargs++;
		targs = emalloc(nargs*sizeof(char*));	/* could be too many for a local array */
		nargs = getfields(s, targs, nargs, 1, "\n");
		for(i=0; i<nargs; i++){
			if(!isdigit(targs[i][0]))
				continue;
			j = atoi(targs[i]);	/* easy way to parse the number! */
			if(j == 0)
				continue;
			snprint(buf, sizeof buf, "%s%d", mbox.name, j);
			delmesg(buf, nil, 1, save);
		}
		free(s);
		free(targs);
		return 1;
	}
	if(strcmp(s, "Search") == 0){
		if(nargs <= 1)
			return 1;
		s = estrstrdup(mboxname, "/search");
		searchfd = fsopen(mailfs, s, ORDWR);
		if(searchfd == nil)
			return 1;
		save = estrdup(args[1]);
		for(i=2; i<nargs; i++)
			save = eappend(save, " ", args[i]);
		fswrite(searchfd, save, strlen(save));
		fsseek(searchfd, 0, 0);
		j = fsread(searchfd, buf, sizeof buf - 1);
 		if(j == 0){
			fprint(2, "[%s] search %s: no results found\n", mboxname, save);
			fsclose(searchfd);
			free(save);
			return 1;
		}
		free(save);
		buf[j] = '\0';
		res = estrdup(buf);
		j = fsread(searchfd, buf, sizeof buf - 1);
		for(; j != 0; j = fsread(searchfd, buf, sizeof buf - 1), buf[j] = '\0')
			res = eappend(res, "", buf);
		fsclose(searchfd);

		sbox = newwindow();
		winname(sbox, s);
		free(s);
		threadcreate(mainctl, sbox, STACK);
		winopenbody(sbox, OWRITE);

		/* show results in reverse order */
		m = mbox.tail;
		save = nil;
		for(s=strrchr(res, ' '); s!=nil || save!=res; s=strrchr(res, ' ')){
			if(s != nil){
				save = s+1;
				*s = '\0';
			}
			else save = res;
			save = estrstrdup(save, "/");
			for(; m && strcmp(save, m->name) != 0; m=m->prev);
			free(save);
			if(m == nil)
				break;
			fsprint(sbox->body, "%s%s\n", m->name, info(m, 0, 0));
			m = m->prev;
		}
		free(res);
		winclean(sbox);
		winclosebody(sbox);
		return 1;
	}
	return 0;
}