[Prev][Next][Index][Thread]

linux_fs + freebsd_c



I have OSKit's linux_fs + freebsd_c working in MzScheme, sortof.  Some
things that I've tried work fine, such as testing for the existence of
files/directories (via stat()), creating directories (via mkdir()),
and reading files (via fopen()). But I've encountered a few things
that don't work for me:

 * After sucessfully reading the content of a directory, closedir()
   triggers an assert failure in lmm_free.c, line 61.

 * fopen("new-file", "w") always returns NULL; errno contains
   OSKIT_E_INVALIDARG. stat() immediately after reports that the file
   exists.

 * Creating a directory works, but the directory doesn't survive
   reboots. Neither do the files that are apparently created by
   fopen(). Is there some sort of sync() function I need to call?
   (The obvious one, sync(), doesn't seem to be there.)

I get the same successes and failures for vfat and ext2 filesystems.

Any advice? I've included source code below to demonstrate the
problems I'm having.

Thanks,
Matthew

----------------------------------------

# include <oskit/fs/bmodfs.h> 
# include <oskit/dev/clock.h> 
# include <oskit/c/sys/time.h> 
# include <oskit/x86/pc/dev.h>

# include <errno.h>
# include <stdio.h>
# include <dirent.h>
# include <unistd.h>

/********** BEGIN fairly standard fs setup *********/

void start_clock()
{
  oskit_timespec_t time;
  /* use fdev's default clock device */
  oskit_clock_t *clock = oskit_clock_init();
  
  oskit_rtc_get(&time);   /* read rtc */
  oskit_clock_settime(clock, &time); /* set time */
  
  set_system_clock(clock);
}

#  include <oskit/dev/dev.h>
#  include <oskit/fs/filesystem.h> 
#  include <oskit/fs/dir.h> 
#  include <oskit/diskpart/diskpart.h> 
#  include <oskit/fs/linux.h> 
#  include <oskit/dev/linux.h> 
#  include <oskit/principal.h>
static oskit_principal_t *cur_principal;
int start_linux_fs(char *diskname, char *partname)
{
  int err;
  oskit_identity_t id;
  oskit_blkio_t *disk;
  oskit_blkio_t *part;
  oskit_filesystem_t *fs;
  oskit_statfs_t sfs;
  oskit_dir_t *root;
# define MAX_PARTS 30
  diskpart_t part_array[MAX_PARTS];
  int num_parts;

# define CHECK(what, f) \
  if ((err = f)) \
   { printf("filesystem init error at " what ": %d\n", err); return 0; }

  printf(">> Initializing devices\n");
  oskit_dev_init();
  oskit_linux_init_ide();
  /* oskit_linux_init_scsi(); */
  printf(">> Probing devices\n");
  oskit_dev_probe();
  printf(">> Filesystem initialization\n");
  CHECK("fsinit", fs_linux_init());

  id.uid = 0;
  id.gid = 0;
  id.ngroups = 0;
  id.groups = 0;
  printf(">> Making principal\n");
  CHECK("makeprincipal", oskit_principal_create(&id, &cur_principal));

  printf(">> Opening disk %s\n", diskname);
  CHECK("diskopen", 
        oskit_linux_block_open(diskname, OSKIT_DEV_OPEN_ALL, &disk));

  printf(">> Reading partitions\n");
  num_parts = diskpart_blkio_get_partition(disk, part_array, MAX_PARTS);
  printf(">> Found %d partitions, looking for %s\n", num_parts, partname);
  if (diskpart_blkio_lookup_bsd_string(part_array, partname, disk, &part)==0){
    printf("can't find partition %s\n", partname);
    return 0;
  }

  printf(">> Mounting filesystem\n");
  CHECK("mount", fs_linux_mount(part, 0, &fs));
  printf(">> Getting root\n");
  CHECK("getroot", oskit_filesystem_getroot(fs, &root));

  fs_init(root);

  return 1;
}

oskit_error_t
oskit_get_call_context(const struct oskit_guid *iid, void **out_if)
{
  if (memcmp(iid, &oskit_iunknown_iid, sizeof(*iid)) == 0 ||
      memcmp(iid, &oskit_principal_iid, sizeof(*iid)) == 0) {
    *out_if = cur_principal;
    oskit_principal_addref(cur_principal);
    return 0;
  }
  
  *out_if = 0;
  return OSKIT_E_NOINTERFACE;
}

/********** BEGIN problem-demo program *********/

int main(int argc, char **argv)
{
  FILE *f;
  DIR *dir;
  char *name;
  struct dirent *e;

  start_clock();
  oskit_init_libc();
  start_linux_fs("hda", "a");

  name = "new-file2";
  printf("trying to open `%s' for writing:\n", name);
  f = fopen(name, "w");
  if (!f) {
    printf("fopen failed: %x (expected %x; is the file there, anyway?)\n", 
       errno, OSKIT_E_INVALIDARG);
  } else {
    printf("huh? it worked unexpectedly\n");
    fclose(f);
  }

  printf("opening directory...\n");
  dir = opendir(".");
  if (!dir) {
    printf("open failed (unexpected)\n");
  } else {
    printf("open ok\n");
    printf("read until nothing's there...\n");
    while ((e = readdir(dir))) {
      printf("%s,", e->d_name);
    }
    printf("\nclosing, expect a crash (assert failure)...\n");
    closedir(dir);
    printf("huh? it worked unexpectedly\n");
  }
}


Follow-Ups: