Ejemplo n.º 1
0
/*
 * Initializes the file system manager.
 */
PUBLIC void fs_init(void)
{
	binit();
	inode_init();
	superblock_init();
	
	/* Sanity check. */
	CHKSIZE(sizeof(struct d_dirent), sizeof(struct dirent));

	rootdev = superblock_read(ROOT_DEV);
	
	/* Failed to read root super block. */
	if (rootdev == NULL)
		kpanic("failed to mount root file system");
		
	superblock_unlock(rootdev);
	
	root = inode_get(ROOT_DEV, 1);
	
	/* Failed to read root inode. */
	if (root == NULL)
		kpanic("failed to read root inode");
	
	kprintf("fs: root file system mounted");
	
	/* Hand craft idle process. */
	IDLE->pwd = root;
	IDLE->root = root;
	root->count += 2;
	
	inode_unlock(root);
}
Ejemplo n.º 2
0
int8_t cnmkfs(void)
{
	superblock_init();
	block_bitmap_init();
	inode_bitmap_init();
	write_root_dir();
	return 0;
}
Ejemplo n.º 3
0
void runKernel()
{
    // Initializing the GDT
    gdt_init();

    // Initializing the screen
    init_display();

    // Initializing the interruption controler (PIC)
    pic_init();

    // Initializing the IDT
    idt_init();

    // Initializing timer @ 100Hz
    timer_init(100);

    // Initializing the keyboard);
    keyboard_init();

    // Init the file system superblock
    superblock_init();

    // Enables hardware interruptions
    sti();

    #ifdef TEST

    // Runs the test procedure if test mode is enabled
    runFileSystemTests();

    #else

    // Executing the Shell
    exec_task("shell");

    #endif

    halt();
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
  int dev, i;
  char *zeros;
  unsigned long size;
  superblock_t *sb, *sb_dup;
  inode_t *rootdir;

  openlog("GNORDOFS", LOG_PID, LOG_LOCAL0);

  // Size = 10Mib
  size = 1024*1024*10;

  dev = open("gnordofs.img", O_RDWR | O_CREAT, 0666);
  if (dev < 0)
    {
      perror(NULL);
      exit(1);
    }

  /* Inicializar superbloque y zona de inodos. */
  sb = superblock_init(size);
  inode_list_init(dev, sb);
  //superblock_print_dump(sb);

  /* Poner cero toda la zona de bloques, por si acaso. */
  if (lseek(dev, sb->block_zone_base, SEEK_SET) < 0)
    {
      printf("Dude, WTF???\n");
      exit(1);
    }
  zeros = malloc(BLOCK_SIZE);
  memset(zeros, 0, BLOCK_SIZE);
  for (i=sb->block_zone_base;
       i < size - BLOCK_SIZE;
       i += BLOCK_SIZE)
    {
      write(dev, zeros, BLOCK_SIZE);
    }
  if (size > i)
    write(dev, zeros, size - i);

  /* Inicializar lista de bloques libres. */
  free_block_list_init(dev, sb);

  /* ¡Que no se me olvide salvar el maldito superbloque! */
  superblock_write(dev, sb);

  /* A partir de aquí se maneja casi como si estuviese inicializado. */

  /* Reservar el primer inodo libre, marcarlo como directorio,
     añadir las entradas . y .., salvarlo en disco y hacer que
     first_directory del superbloque apunte a dicho inodo.
  */
  rootdir = ialloc(dev, sb);
  // Modificar rootdir con entradas . y ..
  rootdir->type = I_DIR;
  rootdir->perms = S_IFDIR | 0755;
  add_dir_entry(dev, sb, rootdir, rootdir, ".");
  add_dir_entry(dev, sb, rootdir, rootdir, "..");
  rootdir->atime = rootdir->ctime = rootdir->mtime = time(NULL);
  iput(dev, sb, rootdir);

  sb->first_inode = rootdir->n;
  superblock_write(dev, sb);

  printf("rootdir->type = %d\n", rootdir->type);
  printf("rootdir->size = %d\n", rootdir->size);
  printf("rootdir->link_counter = %d\n", rootdir->link_counter);
  printf("rootdir->owner = %d\n", rootdir->owner);
  printf("rootdir->group = %d\n", rootdir->group);
  printf("rootdir->perms = %o\n", rootdir->perms);
  printf("rootdir->n = %d\n", rootdir->n);
  printf("rootdir->offset_ptr = %d\n", rootdir->offset_ptr);

  /* Comprobar que se puede leer el superbloque. */
  sb_dup = superblock_read(dev);
  if (!sb_dup
      || memcmp(sb, sb_dup, sizeof(struct persistent_superblock) != 0))
    {
      printf("WTF?\n");
      exit(1);
    }
  superblock_print_dump(sb_dup);
  print_free_block_list(dev, sb);

  free(sb);
  free(sb_dup);

  close(dev);

  return 0;
}