Home | History | Annotate | Line # | Download | only in arch
ews4800mips.c revision 1.2
      1 
      2 #if HAVE_NBTOOL_CONFIG_H
      3 #include "nbtool_config.h"
      4 #endif
      5 
      6 #include <sys/cdefs.h>
      7 #if !defined(__lint)
      8 __RCSID("$NetBSD: ews4800mips.c,v 1.2 2006/02/18 10:08:07 dsl Exp $");
      9 #endif	/* !__lint */
     10 
     11 #include <sys/param.h>
     12 #include <unistd.h>
     13 #include <err.h>
     14 #include <stdio.h>
     15 #include "installboot.h"
     16 
     17 static int ews4800mips_setboot(ib_params *);
     18 
     19 struct ib_mach ib_mach_ews4800mips =
     20 	{ "ews4800mips", ews4800mips_setboot, no_clearboot, no_editboot, 0};
     21 
     22 struct bbinfo_params ews4800mips_bbparams = {
     23 	EWS4800MIPS_BBINFO_MAGIC,
     24 	EWS4800MIPS_BOOT_BLOCK_OFFSET,
     25 	EWS4800MIPS_BOOT_BLOCK_BLOCKSIZE,
     26 	EWS4800MIPS_BOOT_BLOCK_MAX_SIZE,
     27 	0,
     28 	BBINFO_BIG_ENDIAN,
     29 };
     30 
     31 static int
     32 ews4800mips_setboot(ib_params *params)
     33 {
     34 	u_int8_t buf[EWS4800MIPS_BOOT_BLOCK_MAX_SIZE];
     35 	int rv;
     36 
     37 	rv = pread(params->s1fd, buf, sizeof buf, 0);
     38 	if (rv == -1) {
     39 		warn("Reading `%s'", params->stage1);
     40 		return 0;
     41 	} else if (rv != sizeof buf) {
     42 		warnx("Reading `%s' : short read", params->stage1);
     43 		return 0;
     44 	}
     45 
     46 	if (params->flags & IB_NOWRITE)
     47 		return 1;
     48 
     49 	if (params->flags & IB_VERBOSE)
     50 		printf("Writing boot block\n");
     51 
     52 	rv = pwrite(params->fsfd, buf, sizeof buf, 0);
     53 	if (rv == -1) {
     54 		warn("Writing `%s'", params->filesystem);
     55 		return 0;
     56 	} else if (rv != sizeof buf) {
     57 		warnx("Writing `%s': short write", params->filesystem);
     58 		return 0;
     59 	}
     60 
     61 	return 1;
     62 }
     63