Ejemplo n.º 1
0
static void mkfs(){
    MESSAGE message;
    
    HD_PART_INFO part_info;
    message.type=INFO_FS_IOCTL;
    message.subtype=DIOCTL_GET_PART_INFO;
    message.device=ROOT_DEVICE;//-------------需要指定到具体分区--------------------
    message.arg_pointer=(void*)&part_info;
    message.source_pid=TASK_FS;
    assert(dd_map[DRIVER(message.device)].driver_pid!=PID_INVALID,"driver not exist!");
    send_receive(BOTH,dd_map[DRIVER(message.device)].driver_pid,&message);
    
#ifdef DEBUG_FS
    printl("device=%d base=%d size=%d (in sector)\n",DEVICE(message.device),part_info.base,part_info.size);
#endif

    SUPER_BLOCK sb;
    //super block
    int super_block_first_index=get_super_block_first_index();
    init_super_block(&sb,super_block_first_index,part_info.size);
#ifdef DEBUG_FS
    printl("init_super_block ok(start_sector=%d)\n",super_block_first_index);
#endif
    //imap
    /* int imap_first_index=super_block_first_index+SUPER_SECTORS_LENGTH; */
    int imap_first_index=get_imap_first_index(sb);
    int imap_sectors_length=get_imap_length(sb)/* sb.imap_sectors_length */;
    init_imap(imap_first_index,imap_sectors_length);
#ifdef DEBUG_FS
    printl("init_imap ok(start_sector=%d)\n",imap_first_index);
#endif
    //smap
    /* int smap_first_index=imap_first_index+imap_sectors_length; */
    int smap_first_index=get_smap_first_index(sb);
    int smap_sectors_length=get_smap_length(sb)/* sb.smap_sectors_length */;
    init_smap(smap_first_index,smap_sectors_length);
#ifdef DEBUG_FS
    printl("init_smap ok(start_sector=%d)\n",smap_first_index);
#endif
    //inode
    /* int inode_first_index=smap_first_index+smap_sectors_length; */
    int inode_first_index=get_inode_first_index(sb);
    /* int inode_sectors_length=get_inode_length(sb)/\* sb.inodes_sectors_length *\/; */
    int root_dir_start_index=get_data_block_first_index(sb)/* sb.data_first_sector_index */;
    init_inode(inode_first_index,root_dir_start_index);    
#ifdef DEBUG_FS
    printl("init_inode ok(start_sector=%d)\n",inode_first_index);
#endif
    //data
    /* int data_block_first_index=inode_first_index+inode_sectors_length; */
    int data_block_first_index=get_data_block_first_index(sb);
    init_data_block(data_block_first_index);
#ifdef DEBUG_FS
    printl("init_data_block ok(start_sector=%d)\n",data_block_first_index);
#endif
}
/*===========================================================================*
 *				sef_cb_init_fresh			     *
 *===========================================================================*/
static int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *info)
{
/* Initialize the virtual file server. */
  int s, i;
  struct fproc *rfp;
  message mess;
  struct rprocpub rprocpub[NR_BOOT_PROCS];

  self = NULL;
  verbose = 0;

  /* Initialize proc endpoints to NONE */
  for (rfp = &fproc[0]; rfp < &fproc[NR_PROCS]; rfp++) {
	rfp->fp_endpoint = NONE;
	rfp->fp_pid = PID_FREE;
  }

  /* Initialize the process table with help of the process manager messages.
   * Expect one message for each system process with its slot number and pid.
   * When no more processes follow, the magic process number NONE is sent.
   * Then, stop and synchronize with the PM.
   */
  do {
	if ((s = sef_receive(PM_PROC_NR, &mess)) != OK)
		panic("VFS: couldn't receive from PM: %d", s);

	if (mess.m_type != VFS_PM_INIT)
		panic("unexpected message from PM: %d", mess.m_type);

	if (NONE == mess.VFS_PM_ENDPT) break;

	rfp = &fproc[mess.VFS_PM_SLOT];
	rfp->fp_flags = FP_NOFLAGS;
	rfp->fp_pid = mess.VFS_PM_PID;
	rfp->fp_endpoint = mess.VFS_PM_ENDPT;
	rfp->fp_blocked_on = FP_BLOCKED_ON_NONE;
	rfp->fp_realuid = (uid_t) SYS_UID;
	rfp->fp_effuid = (uid_t) SYS_UID;
	rfp->fp_realgid = (gid_t) SYS_GID;
	rfp->fp_effgid = (gid_t) SYS_GID;
	rfp->fp_umask = ~0;
  } while (TRUE);			/* continue until process NONE */
  mess.m_type = OK;			/* tell PM that we succeeded */
  s = ipc_send(PM_PROC_NR, &mess);		/* send synchronization message */

  system_hz = sys_hz();

  /* Subscribe to block and character driver events. */
  s = ds_subscribe("drv\\.[bc]..\\..*", DSF_INITIAL | DSF_OVERWRITE);
  if (s != OK) panic("VFS: can't subscribe to driver events (%d)", s);

  /* Initialize worker threads */
  worker_init();

  /* Initialize global locks */
  if (mthread_mutex_init(&bsf_lock, NULL) != 0)
	panic("VFS: couldn't initialize block special file lock");

  init_dmap();			/* Initialize device table. */
  init_smap();			/* Initialize socket table. */

  /* Map all the services in the boot image. */
  if ((s = sys_safecopyfrom(RS_PROC_NR, info->rproctab_gid, 0,
			    (vir_bytes) rprocpub, sizeof(rprocpub))) != OK){
	panic("sys_safecopyfrom failed: %d", s);
  }
  for (i = 0; i < NR_BOOT_PROCS; i++) {
	if (rprocpub[i].in_use) {
		if ((s = map_service(&rprocpub[i])) != OK) {
			panic("VFS: unable to map service: %d", s);
		}
	}
  }

  /* Initialize locks and initial values for all processes. */
  for (rfp = &fproc[0]; rfp < &fproc[NR_PROCS]; rfp++) {
	if (mutex_init(&rfp->fp_lock, NULL) != 0)
		panic("unable to initialize fproc lock");
	rfp->fp_worker = NULL;
#if LOCK_DEBUG
	rfp->fp_vp_rdlocks = 0;
	rfp->fp_vmnt_rdlocks = 0;
#endif

	/* Initialize process directories. mount_fs will set them to the
	 * correct values.
	 */
	for (i = 0; i < OPEN_MAX; i++)
		rfp->fp_filp[i] = NULL;
	rfp->fp_rd = NULL;
	rfp->fp_wd = NULL;
  }

  init_vnodes();		/* init vnodes */
  init_vmnts();			/* init vmnt structures */
  init_select();		/* init select() structures */
  init_filps();			/* Init filp structures */

  /* Mount PFS and initial file system root. */
  worker_start(fproc_addr(VFS_PROC_NR), do_init_root, &mess /*unused*/,
	FALSE /*use_spare*/);

  return(OK);
}