コード例 #1
0
ファイル: rdisk.c プロジェクト: ashumeow/retrobsd
dev_t get_swap_device()
{
// If a swap device has been specified, then we can short cut all this and just
// use that device.
#ifdef SWAP
	return SWAP;
#else

	dev_t bd = -1;
	int i,j,e;
	unsigned int max_size = 0;
	struct buf *bp;
	struct mbr *mbr;

	// First we look for the first active swap device

	for(i=0; i<NRDSK; i++)
	{
		e = rdopen(makedev(i,0),0,S_SILENT);
		if(e==0)
		{
			bp = read_mbr(i);
			if(bp)
			{
				mbr = (struct mbr *)bp->b_addr;

				for(j=0; j<4; j++)
				{
					if(mbr->partitions[j].type==RDISK_SWAP)
					{
						// If this partition is the biggest so far
						// then store it.  We'll use this if
						// there is no active partition.
						if(mbr->partitions[j].lbalength>max_size)
						{
							max_size = mbr->partitions[j].lbalength;
							bd = makedev(i,j+1);
						}

						// If it is active, then use it.
						if(mbr->partitions[j].status & P_ACTIVE)
						{
							brelse(bp);
							rdclose(makedev(i,0),0,0);
							return makedev(i,j+1);
						}
					}
				}
				brelse(bp);
			}
			rdclose(makedev(i,0),0,0);
		}
	}

	// There is no active partition, so we'll use the biggest one we found.
	return bd;
#endif
}
コード例 #2
0
ファイル: rdisk.c プロジェクト: ashumeow/retrobsd
dev_t get_boot_device()
{
// If a root device has been specified, then we can short cut all this and just
// use that device.
#ifdef ROOT
	return ROOT;
#else
	dev_t bd = -1;
	int i,j,e;
	struct buf *bp;
	struct mbr *mbr;

	for(i=0; i<NRDSK; i++)
	{
		e = rdopen(makedev(i,0),0,S_SILENT);
		if(e==0)
		{
			bp = read_mbr(i);
			if(bp)
			{
				mbr = (struct mbr *)bp->b_addr;

				for(j=0; j<4; j++)
				{
					if(mbr->partitions[j].type==RDISK_FS)
					{
						if(mbr->partitions[j].status & P_ACTIVE)
						{
							brelse(bp);
							rdclose(makedev(i,0),0,0);
							return makedev(i,j+1);
						}
					}
				}
				brelse(bp);
			}
			rdclose(makedev(i,0),0,0);
		}
	}
	
	return bd;
#endif
}
コード例 #3
0
ファイル: rdisk.c プロジェクト: ashumeow/retrobsd
daddr_t rdsize(dev_t dev)
{
	int root = major(dev);
	if(root>MAXDEV) return ENODEV;

	int part = minor(dev);
	int unit = disks[root].unit;
	unsigned int blocks;

	if(part==0)
	{
		return disks[root].size(unit);
	} else {
		if(rdopen(dev,0,S_SILENT)!=0)
			return 0;
		blocks=dflags[root].len[part-1];
		rdclose(dev,0,0);
		DEBUG3("rd%d%c: get partition size: %d\n",root,part+'a'-1,blocks);
		return blocks;
	}
}
コード例 #4
0
ファイル: rdisk.c プロジェクト: sinetek/retrobsd
unsigned char partition_type(dev_t dev)
{
    struct buf *bp;
    struct mbr *mbr;
    unsigned char pt;

    if (minor(dev)<1 || minor(dev)>4)
        return 0;

    if (rdopen(dev,0,S_SILENT) == 0) {
        bp = read_mbr(major(dev));
        rdclose(dev, 0, 0);
        if (! bp) {
            brelse(bp);
            return 0;
        }
        mbr = (struct mbr *)bp->b_addr;
        pt = mbr->partitions[minor(dev)-1].type;
        brelse(bp);
        return pt;
    }
    return 0;
}