view cos/kernel/initrd.c @ 180:25a0753da4cf

Re-organized files
author Windel Bouwman
date Thu, 09 May 2013 17:35:19 +0200
parents e47bfef80baf
children
line wrap: on
line source

/*
 * Initial ramdisk filesystem driver.
 * */

#include "kernel.h"

// Global data struct:
//initrd_file_header_t *files;

/*
fs_node_t* initialize_initrd(uint64_t location)
{
   uint32_t *u32ptr;

   u32ptr = (uint32_t*)location;
   if (*u32ptr != 0x1337babe)
   {
      printf("Invalid ramdisk magic\n");
      return 0;
   }

   // Allocate root dir:
   fs_node_t *root = (fs_node_t*)kmalloc(sizeof(fs_node_t));
   memset(root, 0, sizeof(fs_node_t));
   root->flags = FS_DIRECTORY;
   root->readdir = initrd_readdir;
   
   u32ptr++;
   root->length = *u32ptr;
   
   // Allocate an node for each file.
   void *x = kmalloc(sizeof(fs_node_t) * root->length);
   memset(x, 0, sizeof(fs_node_t) * root->length);

   for (i = 0; i < root->length; i++)
   {
      
   }

   return root;
}

*/

void load_ramdisk()
{
   printf("Ramdisk location: %p\n", ramdisk_location);

   /*
   fs_node_t *root = initialize_initrd(ramdisk_location);

   if (root != 0)
   {
      fs_node_t *node = 0;
      int i = 0;
      while ( (node = readdir_fs(root, i)) != 0)
      {
         printf("File %s\n", node->name);
      }
   }
   */
}

/*
static uint64_t initrd_read(fs_node_t *node, uint64_t offset, uint64_t size, void *buffer)
{
   // TODO: check errors

   if (size > node->length)
   {
      return 0;
   }

   if (size + offset > node->length)
   {
      size = node->length - offset;
   }

   memcpy(buffer, node.data + offset, size);
   return size;
}

fs_node_t *readdir(fs_node_t *dir, int index)
{
   if (index >= dir->length)
   {
      return 0;
   }
}
*/