Пример #1
0
//copy a file within our FS
int copy(char *fname,char *fname2)
{
    minifile_t src, dest;
    char buf[COPY_BUFFER_SIZE];
    int i,len;
    if(strcmp(fname,"")==0||strcmp(fname2,"")==0) {
        printf("Usage: cp [source_path] [dest_path]\n");
        return -1;
    }
    src = minifile_open(fname,"r");
    if(src == NULL) {
        printf("cp: couldn't open source %s!\n",fname);
        return -1;
    }
    dest = minifile_creat(fname2);
    if(dest == NULL) {
        printf("cp: couldn't create destination %s!\n",fname2);
        return -1;
    }
    len = minifile_stat(fname);
    for(i=COPY_BUFFER_SIZE; i<len; i+=COPY_BUFFER_SIZE) {
        minifile_read(src,buf,COPY_BUFFER_SIZE);
        minifile_write(dest,buf,COPY_BUFFER_SIZE);
    }
    if(i>len) {
        minifile_read(src,buf,COPY_BUFFER_SIZE-i+len);
        minifile_write(dest,buf,COPY_BUFFER_SIZE-i+len);
    }
    printf("\n");
    minifile_close(src);
    minifile_close(dest);
    return 0;
}
Пример #2
0
//print a file on the screen
int typefile(char *fname)
{
    minifile_t file;
    char buf[COPY_BUFFER_SIZE+1];
    int i,len;
    buf[COPY_BUFFER_SIZE] = '\0';
    file = minifile_open(fname,"r");
    if(file == NULL) {
        printf("type: couldn't open %s!\n",fname);
        return -1;
    }
    len = minifile_stat(fname);
    for(i=COPY_BUFFER_SIZE; i<len; i+=COPY_BUFFER_SIZE) {
        minifile_read(file,buf,COPY_BUFFER_SIZE);
        printf("%s",buf);
    }
    if(i>len) {
        minifile_read(file,buf,COPY_BUFFER_SIZE-i+len);
        memset(buf+COPY_BUFFER_SIZE-i+len,'\0',i-len);
        printf("%s",buf);
    }

    printf("\nEOF\n");
    minifile_close(file);
    return 0;
}
Пример #3
0
//move file from our file system to NT
int exportfile(char *fname,char *ntfname) {
	FILE *f;
	char *buf;
	minifile_t file;
	file = minifile_open(fname,"r");
	if(file == NULL) { printf("export: cannot open %s\n",fname); return -1; }
	buf = malloc(minifile_stat(fname));
	minifile_read(file,buf,minifile_stat(fname));
	minifile_close(file);
	if((f = fopen(ntfname,"wb")) == NULL) {	printf("export: cannot open %s\n",ntfname); return -1; }
	fwrite(buf,minifile_stat(fname),1,f);
	fclose(f);
	free(buf);
	return 0;
}
Пример #4
0
int test(int* arg) {
  minifile_t file;
  char** file_list;
  char* data;
  char buff[10];

  data = "hello"; 

  file = minifile_creat("foo.txt");
  if (!file) {
    printf("minifile_creat failed\n");
    return -1;
  }

  file_list = minifile_ls("/foo.txt");
  if (!file_list) {
    printf("ls failed\n");
    return -1;
  }

  if (!strcmp(file_list[0], "foo.txt")) {
    printf("ls failed\n");
    return -1;
  }

  if (minifile_write(file, data, 6) == -1) {
    printf("write failed\n");
    return -1;
  }
 
  if (minifile_close(file) == -1) {
    printf("minifile_close failed\n");
    return -1;
  }

  file = minifile_open("foo.txt", "r");
  if (!file) {
    printf("minifile_open failed\n");
    return -1;
  }
    
  if (minifile_read(file, buff, 6) == -1) {
    printf("minifile_read failed\n");
    return -1;
  }

  if (strcmp(buff, data)) {
    printf("minifile_read failed\n");
    return -1;
  }

  if (minifile_close(file) == -1) {
    printf("minifile_close failed\n");
    return -1;
  }

  if (minifile_unlink("foo.txt") == -1) {
    printf("minifile_unlink failed\n");
    return -1;
  }

  printf("all tests pass\n");
  return 0;
}