示例#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
//move file from NT to our file system
int importfile(char *fname,char *ntfname)
{
    FILE *f;
    int len;
    char *buf;
    minifile_t file;
    if((f = fopen(ntfname,"rb")) == NULL) {
        printf("%s not found\n",ntfname);
        return -1;
    }
    fseek(f,0,SEEK_END);
    len = ftell(f);
    fseek(f,0,SEEK_SET);
    buf = malloc(len);
    assert(fread(buf,len,1,f) == 1);
    fclose(f);
    file = minifile_creat(fname);
    if(file == NULL) {
        printf("Couldn't create file %s in import!\n",fname);
        return -1;
    }
    if(minifile_write(file,buf,len) == -1) {
        printf("did not complete importing :(.\n");
        minifile_close(file);
        minifile_unlink(fname);
    } else minifile_close(file);
    free(buf);
    return 0;
}
示例#3
0
文件: shell.c 项目: jeherrera/cs4411
//input a file from stdin, input terminated with a "^D" input on a new blank line
//(not ctrl-D, but just two characters ^D.
int inputfile(char *fname) {
	char str[BUFFER_SIZE];
	minifile_t f = minifile_creat(fname);
	if(f == NULL) {printf("input: Error creating file %s\n",fname); return -1; }
	printf("---inputting %s: input \"ctrl-D,ENTER\" on a new line to exit---\n",fname);
	do {
		memset(str,'\0',BUFFER_SIZE);
		fgets(str, BUFFER_SIZE, stdin);
		if(str[0] == 4) //that's what ctrl-D puts in ((char)4)
			break;
		str[strlen(str)] = '\n';
		minifile_write(f,str,strlen(str));
	} while(1);
	minifile_close(f);
	return 0;
}
示例#4
0
文件: shell.c 项目: kentalabur/egs
//input a file from stdin, input terminated with a "^D" input on a new blank line
//(not ctrl-D, but just two characters ^D.
int inputfile(char *fname) {
	char str[BUFFER_SIZE];
	minifile_t f = minifile_creat(fname);
	if(f == NULL) {printf("input: Error creating file %s\n",fname); return -1; }
	printf("---inputting %s: input \"ctrl-D,ENTER\" on a new line to exit---\n",fname);
	do {
		memset(str,'\0',BUFFER_SIZE);
		gets(str);
		//if(str[0] == 4) //that's what ctrl-D puts in ((char)4)
    if(str[0] == 1 || str[0] == 4){// that's what ctrl-D puts in ((char)4) // BUG FIX updated this to ^A which is equal to 1
			break;
    }
		str[strlen(str)] = '\n';
		minifile_write(f,str,strlen(str));
	} while(1);
	minifile_close(f);
	return 0;
}
示例#5
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;
}