Newer
Older
ubixos / src / tools / format.c
@reddawg reddawg on 30 May 2002 1 KB Clean up
/**************************************************************************************
 Copyright (c) 2002 The UbixOS Project
 All rights reserved.

 Redistribution and use in source and binary forms, with or without modification,
 are prohibited.

 $Id$

**************************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include "ubixfs.h"

int main(int argc,char **argv) {
  FILE *fd,*fd2;
  int i=0,x=0,blocks=0,sb=9;
  struct fileTableEntry ft[128];
  fd = fopen("/dev/fd1","wb");
  for (i=1;i<128;i++) {
    ft[i].fileName[0] = '0';
    sprintf(ft[i].fileName,"File-%i",i);
    }
  fseek(fd,4096+(atoi(argv[1])*512),0);
  sb = atoi(argv[1])+8;
  for (i=2;i<argc;i++) {
    blocks = 0;
    x = 1;
    fd2 = fopen(argv[i],"rb");
    fseek(fd,(sb*512),0);
    while(!feof(fd2)) {
      fputc(fgetc(fd2),fd);
      x++;
      }
    ft[i-2].size = x-2;
    if ((x%512)!=0) {
      x--;
      for (;x%512!=0;x++) {
        fputc(0,fd);
        }
      }
    fclose(fd2);
    blocks = x/512;
    ft[i-2].start=sb;
    ft[i-2].length=blocks;
    sprintf(ft[i-2].fileName,"%s",argv[i]);
    printf("Blah: [%s]\n",ft[i-2].fileName);
    printf("Start: [%i], End: [%i]\n",sb,ft[i-2].length);
    sb += (blocks+1);
    }
  fseek(fd,0+(atoi(argv[1])*512),0);
  fwrite(ft,4096,1,fd);
  fclose(fd);
  return(0);
  }


/*
    for (x=0;x<24;x++) {
      ft[i].fileName[x] = 0;
      }
    sprintf(ft[i].fileName,"File-%i\0",i+1);
    ft[i].start = i+1;
    ft[i].length = i+2;
    ft[i].attributes = i+3;
    ft[i].reserved = i+4;
*/