Advertisement
Guest User

Untitled

a guest
Dec 11th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1.  
  2.  
  3. int bd_create(const char *pFilename) {
  4.  
  5. char bufferFI[BLOCK_SIZE] ;
  6. ReadBlock(FREE_INODE_BITMAP, bufferFI) ;
  7. UINT16 idFreeInode = -1 ;
  8. int i;
  9. for(i=BASE_BLOCK_INODE ; i<BASE_BLOCK_INODE+N_INODE_ON_DISK ; i++)
  10. {
  11. if(bufferFI[i] == 1)
  12. {
  13. idFreeInode = i - BASE_BLOCK_INODE ;
  14. break ;
  15. }
  16. }
  17. if(idFreeInode == -1)
  18. {
  19. return -1 ;
  20. }
  21.  
  22.  
  23. char bufferFB[BLOCK_SIZE] ;
  24. ReadBlock(FREE_BLOCK_BITMAP, bufferFB) ;
  25. UINT16 idFreeBlock = -1 ;
  26. int x;
  27. for(x=BASE_BLOCK_INODE+N_INODE_ON_DISK; i<N_BLOCK_ON_DISK; i++)
  28. {
  29. if(bufferFB[i] == 1)
  30. {
  31. idFreeBlock = i;
  32. break ;
  33. }
  34. }
  35. if(idFreeBlock == -1)
  36. {
  37. return -1 ;
  38. }
  39.  
  40. AttachFreeBlock(idFreeBlock);
  41. AttachFreeInode(idFreeInode + BASE_BLOCK_INODE);
  42.  
  43.  
  44.  
  45. char dirPath[FILENAME_SIZE*N_INODE_ON_DISK] ;
  46. char newFileName[FILENAME_SIZE] ;
  47.  
  48.  
  49. GetFilenameFromPath(pFilename, newFileName) ;
  50. GetDirFromPath(pFilename, dirPath);
  51.  
  52. printf("prefix %s , filename %s \n", dirPath, newFileName) ;
  53.  
  54. char bufferIno[BLOCK_SIZE];
  55. inode_path_help(dirPath, bufferIno);
  56.  
  57. iNodeEntry* inoE = (iNodeEntry*) bufferIno;
  58. inoE->iNodeStat.st_size += sizeof(DirEntry) ;
  59. WriteBlock(inoE->iNodeStat.st_ino+BASE_BLOCK_INODE, (char*) inoE) ;
  60.  
  61. char bufferDir[BLOCK_SIZE];
  62. ReadBlock(inoE->Block[0] , bufferDir) ;
  63. printiNode(*inoE);
  64. int numberOfDirs = NumberofDirEntry(inoE->iNodeStat.st_size)-1;
  65. //DirEntry* dirEntry = malloc((numberOfDirs+1)*sizeof(DirEntry));
  66. //memcpy(dirEntry, (DirEntry*) bufferDir, numberOfDirs* sizeof(DirEntry));
  67. DirEntry* dirEntry = (DirEntry*) bufferDir ;
  68. dirEntry[numberOfDirs].iNode = idFreeInode ;
  69. strcpy(dirEntry[numberOfDirs].Filename, newFileName);
  70. WriteBlock(inoE->Block[0], (char*) dirEntry);
  71.  
  72.  
  73. iNodeEntry* newInode = malloc(sizeof(iNodeEntry)) ;
  74. newInode->Block[0] = idFreeBlock ;
  75. newInode->iNodeStat.st_size = 0 ;
  76. newInode->iNodeStat.st_mode =0 ;
  77. newInode->iNodeStat.st_ino = idFreeInode +BASE_BLOCK_INODE;
  78. newInode->iNodeStat.st_nlink = 1 ;
  79.  
  80. WriteBlock(idFreeInode +BASE_BLOCK_INODE, (char*) newInode) ;
  81. return 1;
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement