Advertisement
Guest User

Untitled

a guest
May 4th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. void cp_file (char* source, char* destination)
  2. {
  3. int sourceDev, destDev, sourceIno, destIno, n;
  4. char* ReadBuf[BLKSIZE];
  5. char * DestcpyBuf[BLKSIZE];
  6.  
  7.  
  8. sourceIno = getino(fd, source);
  9. if(sourceIno == 0)
  10. {
  11. printf("cannot find source file\n");
  12. return -1;
  13. }
  14. //open return fd
  15. //we only need to READ
  16. sourceDev = open_file(source,0);
  17. if(sourceDev == -1)
  18. {
  19. printf("cannot open source file\n");
  20. return -1;
  21. }
  22. //save it cause we're gonna change fd when we call getino
  23. int Origfd = fd;
  24. destIno = getino(fd, destination);
  25.  
  26. //if we dont have the destfile already the create one
  27. if(destIno == 0)
  28. {
  29. printf("creating a file for destination\n");
  30. strcpy(source, destination);
  31. creat_file();
  32. }
  33. //get fd from open dest
  34. //creat_file(destination);
  35. //why can't i write to it??
  36. destDev = open_file(destination, 1); // 1 bc we're going to write to it
  37. if(destDev == -1)
  38. {
  39. printf("cannot write to destination\nno device number\n");
  40. return -1;
  41. }
  42.  
  43. //myread returns n read bytes
  44. //n = myread1(sourceDev,ReadBuf,BLKSIZE);
  45. while(n = myread1(sourceDev,ReadBuf,BLKSIZE))
  46. {
  47. //mywrite1 write n bytes to readbuf
  48.  
  49. mywrite1(destDev,ReadBuf,n);
  50.  
  51. }
  52. close_file(sourceDev);
  53. close_file(destDev);
  54.  
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement