#include "ktypes.h"
#include "filesys.h"
#include "dir.h"

/* this module contains structure dump routines for debugging the
	level 1 bootloader - alos used by UNIX tools display_slots, et. al.
*/

dumpextp(lbl,ptr)
     char *lbl;
     struct extp *ptr;
{
  printf("%s extp:\n",lbl);
  printf("\tunit %d, offset %d, slots %d, blocks %d\n",
	 ptr->x_unit, ptr->x_offset, ptr->x_slots, ptr->x_blocks);
}



dumpfilep(lbl,ptr)
     char *lbl;
     struct filep *ptr;
{
  printf("%s filep:\n",lbl);
  dumpextp("\t",&ptr->f_ext);
  printf("\tjnumb %d\tblocks %d\n",ptr->f_jnumb,ptr->f_blocks);
}


dumpdblk(lbl,ptr)
     char *lbl;
     struct dblk *ptr;
{
  register int i;
  
  printf("%s dblk:\n",lbl);
  
  for (i=0;i<DENT;i++)
      printf("\tseid %X, name <%s>\n",
		ptr->d_blk[i].d_seid, ptr->d_blk[i].d_name);
}


dumpeitem(lbl,ptr)
     char *lbl;
     struct eitem *ptr;
{
  printf("%s: eitem:\nextent: %d\tchecksum: %d\tkind: %s\n",
	lbl,
	ptr->e_extno,
	ptr->e_cksum,
	(ptr->e_kind == EXTENT)? "EXTENT" : "NOT AN EXTENT!");
  printf("\tlabel: <%s>\n",ptr->e_label);
  printf("\tfirst: %d\t last: %d\t size: %d\n",
	*(cardinal32*)ptr->e_first,
	*(cardinal32*)ptr->e_last,  *(cardinal32*)ptr->e_size);
}




dumpmitem(lbl,ptr)
     char *lbl;
     struct mitem *ptr;
{
  printf("%s: mitem:\nrev: %d\tchecksum: %d\tkind: %s\n",
	lbl,
	ptr->m_rev,
	ptr->m_cksum,
	(ptr->m_kind == MOUNT)? "MOUNT ITEM" : "NOT A MOUNT ITEM!");
  printf("\tlabel: <%s>\n",ptr->m_label);
  printf("\tslots: %d\t blocks: %d\t alloc: %d\n",
	*(cardinal32*)ptr->m_slots,
	*(cardinal32*)ptr->m_blocks,  *(cardinal32*)ptr->m_alloc);
  printf("\tuser: %d\t data: %d\n",
	*(cardinal32*)ptr->m_user,
	 *(cardinal32*)ptr->m_data);
  printf("mount: %d\t sysno: %d\n",
	 ptr->m_mount, ptr->m_sysno);
}

  




dumpjnode(lbl,ptr)
     char *lbl;
     struct jnode *ptr;
{
  register int i;

  printf("%s: jnode:\n\tchecksum: %d\tkind: %d(%s)\t condition: %s\n",
	lbl,
	ptr->j_cksum,
	 ptr->j_kind,
	(ptr->j_kind == JNODE)? "JNODE" : "NOT A JNODE!",
  	(ptr->j_cond == 1)? "WRITING" : "OK");

  if ((ptr->j_fill[0] != 0) || (ptr->j_fill[1] != 0) || (ptr->j_fill[2] != 0) || (ptr->j_fill[3] == 0) )
    printf("*****fill area not ZERO!\n");
  
  printf("\tself: %d\t high: %d\t trail: %d\n",
	*(cardinal32*)ptr->j_self,
	*(cardinal32*)ptr->j_high,
	 ptr->j_trail);

  printf("\t link: %d\t time init: %d\n",
	 ptr->j_link,
	 ptr->j_time);


  printf("\tindirect table:\n");
  for (i=0; i<MAXIND; i++)
    printf(" %d",*(cardinal32*)ptr->j_itable[i]);

  printf("\n\tdirect table:\n");
  for (i=0; i<MAXDIRJ; i++)
    printf(" %d",*(cardinal32*)ptr->j_dtable[i]);
  printf("\n\n");
}






dumpindir(lbl,ptr)
     char *lbl;
     struct indir *ptr;
{
  register int i;

  printf("%s: indir:\n\tchecksum: %d\tkind: %d(%s)\n",
	lbl,
	ptr->i_cksum,
	 ptr->i_kind,
	 (ptr->i_kind == INDIR)? "INDIR ITEM" : "NOT A INDIR ITEM!");
  
  if ((ptr->i_fill[0] != 0) || (ptr->i_fill[1] != 0) || (ptr->i_fill[2] != 0) || (ptr->i_fill[3] == 0) )
    printf("*****fill area not ZERO!\n");
  

  printf("\thome: %d\t parent: %d\t tree: %d\n",
	*(cardinal32*)ptr->i_home,
	*(cardinal32*)ptr->i_parent,
	 ptr->i_tree);

  printf("\tindirect table:\n");
  for (i=0; i<MAXIND; i++)
    printf(" %d",*(cardinal32*)ptr->i_itable[i]);

  printf("\n\tdirect table:\n");
  for (i=0; i<MAXDIRI; i++)
    printf(" %d",*(cardinal32*)ptr->i_dtable[i]);
  printf("\n\n");
}




dumpalloc(lbl,ptr)
     char *lbl;
     struct aslot *ptr;
{
  register int i;

  printf("%s: alloc:\n\tchecksum: %d\tkind: %d(%s)\tself: %d\n",
	lbl,
	ptr->a_cksum,
	 ptr->a_kind,
	 (ptr->a_kind == ALLOC)? "ALLOC ITEM" : "NOT A ALLOC ITEM!",
	 ptr->a_self);
  
  printf("\tallocation bitmap table:\n");
  for (i=0; i<MAPSIZE; i++)
      printf("%c%d",(i%8 ? ' ' : '\n'),
	     ptr->a_map[i]);
  printf("\n\n");
}

  
