예제 #1
0
char* guard_tests(){
    int stub_board[64] = {0};
    mu_assert("Should throw an error due to bad index of -1", insert_bit(stub_board, -1, 0, 1) == -1);
    mu_assert("should throw an error due to bad index of 17", insert_bit(stub_board, 17, 0, 1) == -1);
    mu_assert("should throw an error due to bad input of 3", insert_bit(stub_board, 0, 0, 3) == -1);
    mu_assert("should throw an error due to bad input of -1", insert_bit(stub_board, 0, 0, -1) == -1);
    return NULL;
}
예제 #2
0
	void hdlc16::insert( const bits::buffer & buf )
	{
	for( size_t i = 0; i < buf.size(); ++i )
		{
		insert_bit( buf[i] );
		}
	}
예제 #3
0
char* insertion_tests(){
    int stub_board[64] = {0};
    insert_bit(stub_board, 0, 0, 1);
    int output = stub_board[0];
    mu_assert("Insert did not equal 1 in position 0", output == 1);
    memset(stub_board, 0, 64 * sizeof(int));
    insert_bit(stub_board, 1, 0, 1);
    output = stub_board[1];
    mu_assert("Insert did not equal 1 in position 1", output == 1);

    memset(stub_board, 0, 64 * sizeof(int));
    insert_bit(stub_board, 1, 1, 1);
    output = stub_board[9];
    mu_assert("Insert did not equal 1 in position 9", output == 1);

    return NULL;
}
예제 #4
0
파일: mkfs.c 프로젝트: anuragpeshne/minix
/* Allocate a new zone */
static zone_t
alloc_zone(void)
{
  /* Works for zone > block */
  block_t b;
  int i;
  zone_t z;

  z = next_zone++;
  b = z << zone_shift;
  if (b > nrblocks - zone_per_block)
	pexit("File system not big enough for all the files");
  for (i = 0; i < zone_per_block; i++)
	put_block(b + i, zero);	/* give an empty zone */
  
  insert_bit(zone_map, z - zoff);
  return z;
}
예제 #5
0
파일: mkfs.c 프로젝트: anuragpeshne/minix
/*================================================================
 * 	 	     allocation assist group
 *===============================================================*/
static ino_t
alloc_inode(int mode, int usrid, int grpid)
{
  ino_t num;
  int off;
  block_t b;
  struct inode *inodes;

  num = next_inode++;
  if (num > nrinodes) {
  	pexit("File system does not have enough inodes (only %d)", nrinodes);
  }
  b = ((num - 1) / inodes_per_block) + inode_offset;
  off = (num - 1) % inodes_per_block;

  assert(inodes_per_block * sizeof(*inodes) == block_size);
  if(!(inodes = alloc_block()))
	err(1, "couldn't allocate a block of inodes");

  get_block(b, inodes);
  if (inodes[off].i_mode) {
	pexit("allocation new inode %d with non-zero mode - this cannot happen",
		num);
  }
  inodes[off].i_mode = mode;
  inodes[off].i_uid = usrid;
  inodes[off].i_gid = grpid;
  if (verbose && (inodes[off].i_uid != usrid || inodes[off].i_gid != grpid))
	fprintf(stderr, "Uid/gid %d.%d do not fit within inode, truncated\n", usrid, grpid);
  put_block(b, inodes);

  free(inodes);

  /* Set the bit in the bit map. */
  insert_bit((block_t) INODE_MAP, num);
  return(num);
}
예제 #6
0
파일: mkfs.c 프로젝트: anuragpeshne/minix
void
super(zone_t zones, ino_t inodes)
{
  block_t inodeblks, initblks, i;
  unsigned long nb;
  long long ind_per_zone, zo;
  void *buf;
  struct super_block *sup;

  sup = buf = alloc_block();

#ifdef MFSFLAG_CLEAN
  /* The assumption is that mkfs will create a clean FS. */
  sup->s_flags = MFSFLAG_CLEAN;
#endif

  sup->s_ninodes = inodes;
  /* Check for overflow; cannot happen on V3 file systems */
  if(inodes != sup->s_ninodes)
	errx(1, "Too much inodes for that version of Minix FS.");
  sup->s_nzones = 0;	/* not used in V2 - 0 forces errors early */
  sup->s_zones = zones;
  /* Check for overflow; can only happen on V1 file systems */
  if(zones != sup->s_zones)
	errx(1, "Too much zones (blocks) for that version of Minix FS.");
  
#ifndef MFS_STATIC_BLOCK_SIZE
#define BIGGERBLOCKS "Please try a larger block size for an FS of this size."
#else
#define BIGGERBLOCKS "Please use MinixFS V3 for an FS of this size."
#endif
  sup->s_imap_blocks = nb = bitmapsize(1 + inodes, block_size);
  /* Checks for an overflow: nb is uint32_t while s_imap_blocks is of type
   * int16_t */
  if(sup->s_imap_blocks != nb) {
	errx(1, "too many inode bitmap blocks.\n" BIGGERBLOCKS);
  }
  sup->s_zmap_blocks = nb = bitmapsize(zones, block_size);
  /* Idem here check for overflow */
  if(nb != sup->s_zmap_blocks) {
	errx(1, "too many block bitmap blocks.\n" BIGGERBLOCKS);
  }
  inode_offset = START_BLOCK + sup->s_imap_blocks + sup->s_zmap_blocks;
  inodeblks = (inodes + inodes_per_block - 1) / inodes_per_block;
  initblks = inode_offset + inodeblks;
  sup->s_firstdatazone_old = nb =
	(initblks + (1 << zone_shift) - 1) >> zone_shift;
  if(nb >= zones) errx(1, "bit maps too large");
  if(nb != sup->s_firstdatazone_old) {
	/* The field is too small to store the value. Fortunately, the value
	 * can be computed from other fields. We set the on-disk field to zero
	 * to indicate that it must not be used. Eventually, we can always set
	 * the on-disk field to zero, and stop using it.
	 */
	sup->s_firstdatazone_old = 0;
  }
  sup->s_firstdatazone = nb;
  zoff = sup->s_firstdatazone - 1;
  sup->s_log_zone_size = zone_shift;
  sup->s_magic = SUPER_MAGIC;
#ifdef MFS_SUPER_BLOCK_SIZE
  sup->s_block_size = block_size;
  /* Check for overflow */
  if(block_size != sup->MFS_SUPER_BLOCK_SIZE)
	errx(1, "block_size too large.");
  sup->s_disk_version = 0;
#endif

  ind_per_zone = (long long) indir_per_zone;
  zo = NR_DZONES + ind_per_zone + ind_per_zone*ind_per_zone;
#ifndef MAX_MAX_SIZE
#define MAX_MAX_SIZE 	(INT32_MAX)
#endif
  if(MAX_MAX_SIZE/block_size < zo) {
	sup->s_max_size = MAX_MAX_SIZE;
  }
  else {
	sup->s_max_size = zo * block_size;
  }

  if (verbose>1) {
	fprintf(stderr, "Super block values:\n"
	    "\tnumber of inodes\t%12d\n"
	    "\tnumber of zones \t%12d\n"
	    "\tinode bit map blocks\t%12d\n"
	    "\tzone bit map blocks\t%12d\n"
	    "\tfirst data zone \t%12d\n"
	    "\tblocks per zone shift\t%12d\n"
	    "\tmaximum file size\t%12d\n"
	    "\tmagic number\t\t%#12X\n",
	    sup->s_ninodes, sup->s_zones,
	    sup->s_imap_blocks, sup->s_zmap_blocks, sup->s_firstdatazone,
	    sup->s_log_zone_size, sup->s_max_size, sup->s_magic);
#ifdef MFS_SUPER_BLOCK_SIZE
	fprintf(stderr, "\tblock size\t\t%12d\n", sup->s_block_size);
#endif
  }

  mkfs_seek((off_t) SUPER_BLOCK_BYTES, SEEK_SET);
  mkfs_write(buf, SUPER_BLOCK_BYTES);

  /* Clear maps and inodes. */
  for (i = START_BLOCK; i < initblks; i++) put_block((block_t) i, zero);

  next_zone = sup->s_firstdatazone;
  next_inode = 1;

  zone_map = INODE_MAP + sup->s_imap_blocks;

  insert_bit(zone_map, 0);	/* bit zero must always be allocated */
  insert_bit((block_t) INODE_MAP, 0);	/* inode zero not used but
					 * must be allocated */

  free(buf);
}
예제 #7
0
/***************************************************************************
**  Name   : StartSCSICmd()
**  func   : 1. all commands passed through here are regular
**           2. fill in device structure bitmap && start RISC
**  Input  : risc srb structure, Index, ReqType
**  Output : none
****************************************************************************/
static void StartScsiCmd(PRISC_SRB rsrb)
{
	DevHdr *dev;
	u16 status;
	PAdapter pa;
	unsigned short val;
	u8 t, find_id, find_last, ch = 0;
	char *mptr;
/* Request sense CDB */
	char RequestSense[6] =
	{0x03, 0x00, 0x00, 0x00, 0x0e, 0};

	pa = (PAdapter) & HostAdapter[HANumber];
	pa->dev[TargetID].task[Index].CmdInProcess = 1;		/* command in process */
	dev = (DevHdr *) (devhdr_base + TargetID * sizeof(DevHdr));
	dev->Srb_loc = Index;
	dev->Request_type = ReqType;	/* set request type */
	dev->Updatedmap = insert_bit(dev->Updatedmap, Index);
	for (val = 0; val < 6; val++)
		dev->SenseCmd[val] = RequestSense[val];
	rsrb->Sense_Cmd_Ptr = virt_to_phys(&dev->SenseCmd[0]);

	if (ReqType >= 2)
	{
		if (ReqType & 0x2)
			dev->WideMsg = 0x1;
		else
		{
/*        printf("firing sync nego");
   //ravi 10/3/98 -ultra support in parse 

   if(fast_clk)
   dev->SyncPeriod =   period_tbl[(ultra[TargetID])].f_factor;
   else
   dev->SyncPeriod =   period_tbl[(ultra[TargetID])].s_factor;
 */

			if (pa->dev[TargetID].attrib & 0x1)
				dev->SyncOffset = W_MAX_OFFSET;
			else
				dev->SyncOffset = MAX_OFFSET;
		}
	}
	mptr = (char *) mbx_in_base;
	find_id = 0xff;
	find_last = 0xff;
	for (t = 0; t < 15; t++)
	{
		ch = *mptr++;
		if ((ch & 0xf) == TargetID)
		{
			find_id = t;
			break;
		}
	}

	mptr = (char *) mbx_in_base;
	for (t = 0; t < 15; t++)
	{
		ch = *mptr++;
		if (ch & 0x80)
		{
			find_last = t;
			break;
		}
	}
	val = inw(STATUS_INT_REG);
	mptr = (char *) mbx_in_base;
	if (find_id != 0xff && find_last != 0xff)
	{
		if (find_id < find_last)
			*(char *) (mptr + find_id) |= 0x10;
		else
		{
			*(char *) (mptr + find_last) &= 0x7f;
			*(char *) (mptr + find_id) |= 0x90;
		}
	} else if (find_last != 0xff && find_id == 0xff)
	{
		*(char *) (mptr + find_last) &= 0x7f;
		find_last = find_last + 1;
		*(char *) (mptr + find_last) = (0x90 | TargetID);
	} else if (find_last == 0xff)
		*(char *) mptr = (0x90 | TargetID);


	ReqType = 0;
	/*
	   //  restart the RISC if it is halted before
	 */

	rsrb->SRB_flag = SRB_READY;


	if (val & RISC_HALT)
	{
		outw(ucode_start, PC);	/* set pc counter */
		status = inw(CONTROL_REG);	/* clear halt status */
		outw((status & ~HALT_RISC), CONTROL_REG);
	}
#ifdef DEBUG
	printk(KERN_DEBUG " start scsi issued \n");
#endif

}