Browse Source

update loopdev code.

Change-Id: I3e326ef5cf279969b4ab77870a871cd2d8238b14
Signed-off-by: QiaoChong <qiaochong@loongson.cn>
master
QiaoChong 7 years ago
parent
commit
9eb8c98020
  1. 42
      pmon/dev/loopdev.c
  2. 12
      pmon/dev/loopdev.h

42
pmon/dev/loopdev.c

@ -14,16 +14,10 @@
#if NGZIP > 0 #if NGZIP > 0
#include <gzipfs.h> #include <gzipfs.h>
#endif /* NGZIP */ #endif /* NGZIP */
struct loopdev_softc { #include <pmon/dev/loopdev.h>
/* General disk infos */
struct device sc_dev; static struct device *get_device(dev_t dev);
char dev[64];
int fd,bs,seek,count,access;
#if NGZIP > 0
int unzip;
#endif
};
#define loopdevlookup(dev) (struct loopdev_softc *)device_lookup(&loopdev_cd, minor(dev))
int loopdevmatch( struct device *parent, void *match, void *aux); int loopdevmatch( struct device *parent, void *match, void *aux);
void loopdevattach(struct device *parent, struct device *self, void *aux); void loopdevattach(struct device *parent, struct device *self, void *aux);
@ -41,7 +35,7 @@ void loopdevstrategy(struct buf *bp)
unsigned int blkno, blkcnt; unsigned int blkno, blkcnt;
int ret ; int ret ;
priv=loopdevlookup(bp->b_dev); priv=get_device(bp->b_dev);
blkno = bp->b_blkno; blkno = bp->b_blkno;
@ -80,6 +74,11 @@ void loopdevstrategy(struct buf *bp)
} }
else else
{ {
lseek(priv->fd,blkno*priv->bs,SEEK_SET);
ret = write(priv->fd,(unsigned long *)bp->b_data,bp->b_bcount);
if(ret != bp->b_bcount)
bp->b_flags |= B_ERROR;
dotik(30000, 0);
} }
done: done:
biodone(bp); biodone(bp);
@ -89,14 +88,17 @@ bad:
biodone(bp); biodone(bp);
} }
static int losetup(int argc,char **argv) static int losetup(int argc,char **argv)
{ {
int i; int i;
struct loopdev_softc *priv; struct loopdev_softc *priv;
int dev; int dev;
if(argc<3)return -1; if(argc<3)return -1;
dev=argv[1][7]-'0'; dev=find_device(&argv[1]);
priv=loopdevlookup(dev); priv=get_device(dev);
if(!priv)return -1; if(!priv)return -1;
strncpy(priv->dev,argv[2],63); strncpy(priv->dev,argv[2],63);
priv->bs=DEV_BSIZE; priv->bs=DEV_BSIZE;
@ -128,14 +130,15 @@ loopdevopen(
{ {
char loopdevcmd[0x200]; char loopdevcmd[0x200];
char *loopdevenv; char *loopdevenv;
struct loopdev_softc *priv=loopdevlookup(dev); struct loopdev_softc *priv=get_device(dev);
if(!priv)return -1; if(!priv)return -1;
if((loopdevenv=getenv("loopdev"))) if((loopdevenv=getenv(priv->sc_dev.dv_xname)))
{ {
sprintf(loopdevcmd,"losetup loopdev%d %s",minor(dev),loopdevenv); sprintf(loopdevcmd,"losetup %s %s",priv->sc_dev.dv_xname,loopdevenv);
do_cmd(loopdevcmd); do_cmd(loopdevcmd);
} }
priv->fd=open(priv->dev,priv->access); priv->fd=open(priv->dev,priv->access);
if(priv->fd==-1)return -1; if(priv->fd==-1)return -1;
#if NGZIP > 0 #if NGZIP > 0
@ -152,9 +155,7 @@ loopdevread(
struct uio *uio, struct uio *uio,
int flags) int flags)
{ {
int ret; return physio(loopdevstrategy, NULL, dev, B_READ, minphys, uio);
ret=physio(loopdevstrategy, NULL, dev, B_READ, minphys, uio);
return ret;
} }
int int
@ -172,7 +173,7 @@ loopdevclose( dev_t dev,
int flag, int fmt, int flag, int fmt,
struct proc *p) struct proc *p)
{ {
struct loopdev_softc *priv=loopdevlookup(dev); struct loopdev_softc *priv=get_device(dev);
#if NGZIP > 0 #if NGZIP > 0
if(priv->unzip)gz_close(priv->fd); if(priv->unzip)gz_close(priv->fd);
#endif #endif
@ -209,6 +210,7 @@ priv->unzip=0;
#endif #endif
} }
static const Cmd Cmds[] = static const Cmd Cmds[] =
{ {
{"MyCmds"}, {"MyCmds"},

12
pmon/dev/loopdev.h

@ -0,0 +1,12 @@
#include "autoconf.h"
#include <sys/device.h>
#include <sys/param.h>
struct loopdev_softc {
/* General disk infos */
struct device sc_dev;
char dev[64];
int fd,bs,seek,count,access;
#if NGZIP > 0
int unzip;
#endif
};
Loading…
Cancel
Save