From: Ben Gras Date: Thu, 19 Mar 2009 13:48:19 +0000 (+0000) Subject: multiple ram disks; also make release process use this X-Git-Tag: v3.1.4~97 X-Git-Url: http://zhaoyanbai.com/repos/man.isc-hmac-fixup.html?a=commitdiff_plain;h=e5079dfc02de55dd625e92429f6f7ec488394fb9;p=minix.git multiple ram disks; also make release process use this so temporary partitions aren't needed any more. --- diff --git a/commands/scripts/MAKEDEV.sh b/commands/scripts/MAKEDEV.sh index b433f90fb..d25c351ef 100755 --- a/commands/scripts/MAKEDEV.sh +++ b/commands/scripts/MAKEDEV.sh @@ -77,7 +77,10 @@ do $e mknod boot b 1 4; $e chmod 600 ram $e mknod zero c 1 5; $e chmod 644 zero $e mknod imgrd b 1 6; $e chmod 644 zero - $e chgrp kmem ram mem kmem null boot zero imgrd + for n in 0 1 2 3 4 5 + do $e mknod ram$n b 1 $((7+$n)); $e chmod 600 ram$n + done + $e chgrp kmem ram* mem kmem null boot zero imgrd ;; fd[0-3]) # Floppy disk drive n. diff --git a/commands/simple/ramdisk.c b/commands/simple/ramdisk.c index 3210f3201..560429f78 100644 --- a/commands/simple/ramdisk.c +++ b/commands/simple/ramdisk.c @@ -11,17 +11,22 @@ main(int argc, char *argv[]) { int fd; signed long size; - if((fd=open(_PATH_RAMDISK, O_RDONLY)) < 0) { - perror(_PATH_RAMDISK); + char *d; + + if(argc < 2 || argc > 3) { + fprintf(stderr, "usage: %s [device]\n", + argv[0]); return 1; } - if(argc != 2) { - fprintf(stderr, "usage: %s \n", argv[0]); + d = argc == 2 ? _PATH_RAMDISK : argv[2]; + if((fd=open(d, O_RDONLY)) < 0) { + perror(d); return 1; } - size = atol(argv[1]); +#define KFACTOR 1024 + size = atol(argv[1])*KFACTOR; if(size <= 0) { fprintf(stderr, "size should be positive.\n"); @@ -33,6 +38,8 @@ main(int argc, char *argv[]) return 1; } + fprintf(stderr, "size on %s set to %dkB\n", d, size/KFACTOR); + return 0; } diff --git a/drivers/memory/memory.c b/drivers/memory/memory.c index 388604317..560508744 100644 --- a/drivers/memory/memory.c +++ b/drivers/memory/memory.c @@ -32,7 +32,12 @@ #include "local.h" -#define NR_DEVS 7 /* number of minor devices */ +/* ramdisks (/dev/ram*) */ +#define RAMDISKS 6 + +#define RAM_DEV_LAST (RAM_DEV_FIRST+RAMDISKS-1) + +#define NR_DEVS (7+RAMDISKS) /* number of minor devices */ PRIVATE struct device m_geom[NR_DEVS]; /* base and size of each device */ PRIVATE vir_bytes m_vaddrs[NR_DEVS]; @@ -164,10 +169,15 @@ int safe; /* safe copies */ if (opcode == DEV_GATHER_S) return(OK); /* always at EOF */ break; - /* Virtual copying. For RAM disk, kernel memory and internal FS. */ + /* Virtual copying. For RAM disks, kernel memory and internal FS. */ + default: case KMEM_DEV: - case RAM_DEV: + case RAM_DEV_OLD: case IMGRD_DEV: + /* Bogus number. */ + if(m_device < 0 || m_device >= NR_DEVS) { + return(EINVAL); + } if(!dev_vaddr || dev_vaddr == (vir_bytes) MAP_FAILED) { printf("MEM: dev %d not initialized\n", m_device); return EIO; @@ -265,9 +275,6 @@ int safe; /* safe copies */ } break; - /* Unknown (illegal) minor device. */ - default: - return(EINVAL); } /* Book the number of bytes transferred. */ @@ -364,34 +371,47 @@ int safe; switch (m_ptr->REQUEST) { case MIOCRAMSIZE: { /* Someone wants to create a new RAM disk with the given size. */ - static int first_time= 1; - u32_t ramdev_size; - int s; + int s, dev; + void *mem; /* A ramdisk can be created only once, and only on RAM disk device. */ - if (!first_time) return(EPERM); - if (m_ptr->DEVICE != RAM_DEV) return(EINVAL); - if ((dv = m_prepare(m_ptr->DEVICE)) == NIL_DEV) return(ENXIO); + dev = m_ptr->DEVICE; + if(dev < 0 || dev >= NR_DEVS) { + printf("MEM: MIOCRAMSIZE: %d not a valid device\n", dev); + } + if((dev < RAM_DEV_FIRST || dev > RAM_DEV_LAST) && dev != RAM_DEV_OLD) { + printf("MEM: MIOCRAMSIZE: %d not a ramdisk\n", dev); + } + if ((dv = m_prepare(dev)) == NIL_DEV) return(ENXIO); /* Get request structure */ s= sys_safecopyfrom(m_ptr->IO_ENDPT, (vir_bytes)m_ptr->IO_GRANT, 0, (vir_bytes)&ramdev_size, sizeof(ramdev_size), D); if (s != OK) return s; + if(m_vaddrs[dev] && !cmp64(dv->dv_size, cvul64(ramdev_size))) { + return(OK); + } + if(m_vaddrs[dev]) { + printf("MEM: MIOCRAMSIZE: %d already has a ramdisk\n", dev); + return(EPERM); + } #if DEBUG - printf("allocating ramdisk of size 0x%x\n", ramdev_size); + printf("MEM:%d: allocating ramdisk of size 0x%x\n", dev, ramdev_size); #endif /* Try to allocate a piece of memory for the RAM disk. */ - if((m_vaddrs[RAM_DEV] = (vir_bytes) mmap(0, ramdev_size, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0)) == (vir_bytes) MAP_FAILED) { + if((mem = mmap(0, ramdev_size, PROT_READ|PROT_WRITE, MAP_ANON, -1, 0)) == MAP_FAILED) { printf("MEM: failed to get memory for ramdisk\n"); return(ENOMEM); } + m_vaddrs[dev] = (vir_bytes) mem; + dv->dv_size = cvul64(ramdev_size); - first_time= 0; + break; } diff --git a/include/minix/dmap.h b/include/minix/dmap.h index 4848df887..890050fa6 100644 --- a/include/minix/dmap.h +++ b/include/minix/dmap.h @@ -15,13 +15,14 @@ enum dev_style { STYLE_DEV, STYLE_NDEV, STYLE_TTY, STYLE_CLONE }; /* Major and minor device numbers for MEMORY driver. */ #define MEMORY_MAJOR 1 /* major device for memory devices */ -# define RAM_DEV 0 /* minor device for /dev/ram */ +# define RAM_DEV_OLD 0 /* minor device for /dev/ram */ # define MEM_DEV 1 /* minor device for /dev/mem */ # define KMEM_DEV 2 /* minor device for /dev/kmem */ # define NULL_DEV 3 /* minor device for /dev/null */ # define BOOT_DEV 4 /* minor device for /dev/boot */ # define ZERO_DEV 5 /* minor device for /dev/zero */ # define IMGRD_DEV 6 /* minor device for /dev/imgrd */ +# define RAM_DEV_FIRST 7 /* first minor device for /dev/ram* */ #define CTRLR(n) ((n)==0 ? 3 : (8 + 2*((n)-1))) /* magic formula */ diff --git a/tools/release.sh b/tools/release.sh index 41c1817f6..c1eedd14c 100755 --- a/tools/release.sh +++ b/tools/release.sh @@ -5,6 +5,9 @@ set -e XBIN=usr/xbin SRC=src +# size of /tmp during build +TMPKB=32000 + PACKAGEDIR=/usr/bigports/Packages PACKAGESOURCEDIR=/usr/bigports/Sources secs=`expr 32 '*' 64` @@ -12,7 +15,7 @@ export SHELL=/bin/sh make_hdimage() { - dd if=$TMPDISK of=usrimage bs=$BS count=$USRBLOCKS + dd if=$TMPDISK1 of=usrimage bs=$BS count=$USRBLOCKS rootsize=`stat -size rootimage` usrsize=`stat -size usrimage` @@ -133,87 +136,36 @@ do done USRMB=550 - -USRBLOCKS="`expr $USRMB \* 1024 \* 1024 / $BS`" -USRSECTS="`expr $USRMB \* 1024 \* 2`" +USRKB=$(($USRMB*1024)) +USRBLOCKS=$(($USRMB * 1024 * 1024 / $BS)) +USRSECTS=$(($USRMB * 1024 * 2)) ROOTKB=4096 -ROOTSECTS="`expr $ROOTKB \* 2`" -ROOTBLOCKS="`expr $ROOTKB \* 1024 / $BS`" +ROOTSECTS=$(($ROOTKB * 2)) +ROOTBLOCKS=$(($ROOTKB * 1024 / $BS)) if [ "$COPY" -ne 1 ] then echo "Note: this script wants to do svn operations." fi -TD1=.td1 -TD2=.td2 -TD3=.td3 - - -if [ -f $TD1 ] -then TMPDISK="`cat $TD1`" - echo " * Warning: I'm going to overwrite $TMPDISK!" -else - echo "Temporary (sub)partition to use to make the /usr FS image? " - echo "I need $USRMB MB. It will be mkfsed!" - echo -n "Device: /dev/" - read dev || exit 1 - TMPDISK=/dev/$dev -fi - -if [ -b $TMPDISK ] -then : -else echo "$TMPDISK is not a block device.." - exit 1 -fi - -echo $TMPDISK >$TD1 - -if [ -f $TD2 ] -then TMPDISK2="`cat $TD2`" - echo " * Warning: I'm going to overwrite $TMPDISK2!" -else - echo "Temporary (sub)partition to use for /tmp? " - echo "It will be mkfsed!" - echo -n "Device: /dev/" - read dev || exit 1 - TMPDISK2=/dev/$dev -fi - -if [ -b $TMPDISK2 ] -then : -else echo "$TMPDISK2 is not a block device.." - exit 1 -fi - -echo $TMPDISK2 >$TD2 - -if [ -f $TD3 ] -then TMPDISK3="`cat $TD3`" - echo " * Warning: I'm going to overwrite $TMPDISK3!" -else - echo "It has to be at least $ROOTKB KB." - echo "" - echo "Temporary (sub)partition to use to make the root FS image? " - echo "It will be mkfsed!" - echo -n "Device: /dev/" - read dev || exit 1 - TMPDISK3=/dev/$dev -fi +TMPDISK1=/dev/ram0 +TMPDISK2=/dev/ram1 +TMPDISK3=/dev/ram2 -if [ -b $TMPDISK3 ] -then : -else echo "$TMPDISK3 is not a block device.." +if [ ! -b $TMPDISK1 -o ! -b $TMPDISK2 -o ! $TMPDISK3 ] +then echo "$TMPDISK1, $TMPDISK2 or $TMPDISK3 is not a block device.." exit 1 fi -echo $TMPDISK3 >$TD3 +ramdisk $USRKB $TMPDISK1 +ramdisk $TMPKB $TMPDISK2 +ramdisk $ROOTKB $TMPDISK3 -umount $TMPDISK || true +umount $TMPDISK1 || true umount $TMPDISK2 || true umount $TMPDISK3 || true -if [ $TMPDISK = $TMPDISK2 -o $TMPDISK = $TMPDISK3 -o $TMPDISK2 = $TMPDISK3 ] +if [ $TMPDISK1 = $TMPDISK2 -o $TMPDISK1 = $TMPDISK3 -o $TMPDISK2 = $TMPDISK3 ] then echo "Temporary devices can't be equal." exit @@ -223,17 +175,17 @@ echo " * Cleanup old files" rm -rf $RELEASEDIR $IMG $IMAGE $ROOTIMAGE $CDFILES image* mkdir -p $CDFILES || exit mkdir -p $RELEASEDIR -mkfs -B $BS -b $ROOTBLOCKS $TMPDISK3 || exit -mkfs $TMPDISK2 || exit +mkfs -i 2000 -B $BS -b $ROOTBLOCKS $TMPDISK3 || exit +mkfs -B 1024 -b $TMPKB $TMPDISK2 || exit echo " * mounting $TMPDISK3 as $RELEASEDIR" mount $TMPDISK3 $RELEASEDIR || exit mkdir -m 755 $RELEASEDIR/usr mkdir -m 1777 $RELEASEDIR/tmp mount $TMPDISK2 $RELEASEDIR/tmp -mkfs -B $BS -b $USRBLOCKS $TMPDISK || exit -echo " * Mounting $TMPDISK as $RELEASEDIR/usr" -mount $TMPDISK $RELEASEDIR/usr || exit +mkfs -B $BS -b $USRBLOCKS $TMPDISK1 || exit +echo " * Mounting $TMPDISK1 as $RELEASEDIR/usr" +mount $TMPDISK1 $RELEASEDIR/usr || exit mkdir -p $RELEASEDIR/tmp mkdir -p $RELEASEDIR/usr/tmp mkdir -p $RELEASEDIR/$XBIN @@ -347,18 +299,18 @@ fi echo $version_pretty, SVN revision $SVNREV, generated `date` >$RELEASEDIR/etc/version echo " * Counting files" extrakb=`du -s $RELEASEDIR/usr/install | awk '{ print $1 }'` -expr `df $TMPDISK | tail -1 | awk '{ print $4 }'` - $extrakb >$RELEASEDIR/.usrkb +expr `df $TMPDISK1 | tail -1 | awk '{ print $4 }'` - $extrakb >$RELEASEDIR/.usrkb find $RELEASEDIR/usr | fgrep -v /install/ | wc -l >$RELEASEDIR/.usrfiles find $RELEASEDIR -xdev | wc -l >$RELEASEDIR/.rootfiles echo " * Zeroing remainder of temporary areas" -df $TMPDISK +df $TMPDISK1 df $TMPDISK3 cp /dev/zero $RELEASEDIR/usr/.x 2>/dev/null || true rm $RELEASEDIR/usr/.x cp /dev/zero $RELEASEDIR/.x 2>/dev/null || true rm $RELEASEDIR/.x -umount $TMPDISK || exit +umount $TMPDISK1 || exit umount $TMPDISK2 || exit umount $TMPDISK3 || exit @@ -393,7 +345,7 @@ else # number of sectors isosects=`expr $isosects + $isopad` ( cat $IMG $ROOTIMAGE ; - dd if=$TMPDISK bs=$BS count=$USRBLOCKS ) >m + dd if=$TMPDISK1 bs=$BS count=$USRBLOCKS ) >m mv m $IMG # Make CD partition table installboot -m $IMG /usr/mdec/masterboot