#include <stdint.h>
#include <stddef.h>
#include <ulib.h>

struct {
  char *devname;
  char *fstype;
} FS_FMT_CONFIG = {0};

static Arg ARGS[] = {
  ARG("-dev", ARG_STRING, &FS_FMT_CONFIG.devname),
  ARG("-fs", ARG_STRING, &FS_FMT_CONFIG.fstype),
  ARG_END(),
};

void fs_fmt(void) {
  int32_t ret;
  if ((ret = parse_args(args()+1, argslen()-1, ARGS)) < 0) {
    uprintf("fs fmt: Could not parse args: %d\n", ret);
  }

  Dev_t dev;
  ret = dev_gethandle(&dev, FS_FMT_CONFIG.devname);
  if (ret != E_OK) {
    uprintf("fs: device %s not found\n", FS_FMT_CONFIG.devname);
    return;
  }

  ret = vfsmount("fmt-dummy", FS_FMT_CONFIG.fstype, &dev, true);
  if (ret != E_OK) {
    uprintf("fs: mount error %s\n", ERRSTRING(ret));
    return;
  }

  vfsunmount("fmt-dummy");
}
