kern

changeset 83:4ef83db5f4cd

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 06 Dec 2011 15:53:57 +0200
parents 8b92b0c1c220
children 4dd35ccceba1
files mkdiskimg src/ata.c
diffstat 2 files changed, 46 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mkdiskimg	Tue Dec 06 15:53:57 2011 +0200
     1.3 @@ -0,0 +1,39 @@
     1.4 +#!/bin/sh
     1.5 +
     1.6 +# mkdiskimg - prepare a disk image for the kernel
     1.7 +# usage: mkdiskimg [size in mb, default: 40]
     1.8 +
     1.9 +imgfile=disk.img
    1.10 +if [ -e $imgfile ]; then
    1.11 +	echo "file '$imgfile' exists, will not overwrite, delete it first" >&2
    1.12 +	exit 1
    1.13 +fi
    1.14 +
    1.15 +if [ -n "$1" ]; then
    1.16 +	sizemb=$1
    1.17 +else
    1.18 +	sizemb=40
    1.19 +fi
    1.20 +
    1.21 +# create the image file
    1.22 +echo 'creating image file ...'
    1.23 +dd if=/dev/zero of=$imgfile bs=1M count=$sizemb || exit 1
    1.24 +
    1.25 +# create partition table
    1.26 +if ! sfdisk --version | grep linux; then
    1.27 +	echo "failed to find the linux sfdisk program."
    1.28 +	echo "please install it, or create a partition on the disk image ($imgfile) manually."
    1.29 +	exit 0
    1.30 +fi
    1.31 +
    1.32 +echo 'creating partition table with a single partition ...'
    1.33 +sfdisk -q $imgfile <<EOF
    1.34 +,,cc
    1.35 +EOF
    1.36 +if [ $? != 0 ]; then
    1.37 +	echo 'failed to create partition' >&2
    1.38 +	exit 1
    1.39 +fi
    1.40 +
    1.41 +echo
    1.42 +echo 'done. happy hacking!'
     2.1 --- a/src/ata.c	Tue Dec 06 13:45:32 2011 +0200
     2.2 +++ b/src/ata.c	Tue Dec 06 15:53:57 2011 +0200
     2.3 @@ -1,6 +1,7 @@
     2.4  #include <stdio.h>
     2.5  #include <stdlib.h>
     2.6  #include <string.h>
     2.7 +#include <ctype.h>
     2.8  #include <inttypes.h>
     2.9  #include <assert.h>
    2.10  #include "ata.h"
    2.11 @@ -126,8 +127,8 @@
    2.12  	read_data(dev, info);
    2.13  
    2.14  	/* print model and serial */
    2.15 -	printf("- found ata drive (%d,%d): %s\n", dev->iface, dev->id, atastr(textbuf, info + 27, 40));
    2.16 -	printf("  s/n: %s\n", atastr(textbuf, info + 10, 20));
    2.17 +	printf("ata%d: %s", (dev->iface << 1) | dev->id, atastr(textbuf, info + 27, 40));
    2.18 +	printf(" [s/n: %s]", atastr(textbuf, info + 10, 20));
    2.19  
    2.20  	dev->nsect_lba = *(uint32_t*)(info + 60);
    2.21  	dev->nsect_lba48 = *(uint64_t*)(info + 100) & 0xffffffffffffull;
    2.22 @@ -143,7 +144,7 @@
    2.23  	} else {
    2.24  		size_str(dev->nsect_lba, textbuf);
    2.25  	}
    2.26 -	printf("  size: %s\n", textbuf);
    2.27 +	printf(" size: %s\n", textbuf);
    2.28  
    2.29  	free(info);
    2.30  	return 0;
    2.31 @@ -237,7 +238,9 @@
    2.32  		*dptr++ = (*sptr & 0xff00) >> 8;
    2.33  		*dptr++ = *sptr++ & 0xff;
    2.34  	}
    2.35 -	*dptr = 0;
    2.36 +
    2.37 +	while(isspace(*--dptr));
    2.38 +	*++dptr = 0;
    2.39  	return res;
    2.40  }
    2.41