Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "LibFS.h"
  5.  
  6. void usage(char *prog)
  7. {
  8. printf("USAGE: %s <disk_image_file>\n", prog);
  9. exit(1);
  10. }
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14. if (argc != 2) usage(argv[0]);
  15.  
  16. if(FS_Boot(argv[1]) < 0) {
  17. printf("ERROR: can't boot file system from file '%s'\n", argv[1]);
  18. return -1;
  19. } else printf("file system booted from file '%s'\n", argv[1]);
  20.  
  21. char* fn;
  22.  
  23. printf("\nExpected output: SUCCESS\n");
  24. fn = "/dir-1";
  25. if(Dir_Create(fn) < 0) printf("ERROR: can't create dir '%s'\n", fn);
  26. else printf("dir '%s' created successfully\n", fn);
  27.  
  28. printf("\nExpected output: SUCCESS\n");
  29. fn = "/dir-1/file-1";
  30. if(File_Create(fn) < 0) printf("ERROR: can't create file '%s'\n", fn);
  31. else printf("file '%s' created successfully\n", fn);
  32.  
  33. printf("\nExpected output: SUCCESS\n");
  34. fn = "/dir-1/dir-2";
  35. if(Dir_Create(fn) < 0) printf("ERROR: can't create dir '%s'\n", fn);
  36. else printf("dir '%s' create successfully\n", fn);
  37.  
  38. printf("\nExpected output: SUCCESS\n");
  39. fn = "/dir-1/dir-2/file-2";
  40. if(File_Create(fn) < 0) printf("ERROR: can't create file '%s'\n", fn);
  41. else printf("file '%s' created successfully\n", fn);
  42.  
  43. printf("\nExpected output: ERROR\n");
  44. fn = "/dir-1/dir-2";
  45. if(Dir_Unlink(fn) < 0) printf("ERROR: can't unlink dir '%s'\n", fn);
  46. else printf("dir '%s' unlinked successfully\n", fn);
  47.  
  48. printf("\nExpected output: SUCCESS\n");
  49. fn = "/dir-1";
  50. int sz = Dir_Size(fn);
  51. printf("Directory size: %d\n", sz);
  52. char* buffer = malloc(sz);
  53. int entries = Dir_Read(fn, buffer, sz);
  54. printf("directory '%s':\n %-15s\t%-s\n", fn, "NAME", "INODE");
  55. int idx = 0;
  56. for(int i=0; i<entries; i++) {
  57. printf("%-4d %-15s\t%-d\n", i, &buffer[idx], *(int*)&buffer[idx+16]);
  58. idx += 20;
  59. }
  60. free(buffer);
  61.  
  62. printf("\nExpected output: SUCCESS\n");
  63. fn = "/dir-1/dir-2/file-2";
  64. if(File_Unlink(fn) < 0) printf("ERROR: can't unlink file '%s'\n", fn);
  65. else printf("file '%s' unlinked successfully\n", fn);
  66.  
  67. printf("\nExpected output: SUCCESS\n");
  68. fn = "/dir-1/dir-2";
  69. if(Dir_Unlink(fn) < 0) printf("ERROR: can't unlink dir '%s'\n", fn);
  70. else printf("dir '%s' unlinked successfully\n", fn);
  71.  
  72. printf("\nExpected output: SUCCESS\n");
  73. fn = "/dir-1/dir-2";
  74. if(Dir_Create(fn) < 0) printf("ERROR: can't create dir '%s'\n", fn);
  75. else printf("dir '%s' created successfully\n", fn);
  76.  
  77. printf("\nExpected output: SUCCESS\n");
  78. fn = "/dir-1";
  79. sz = Dir_Size(fn);
  80. printf("Directory size: %d\n", sz);
  81. char* buffer3 = malloc(sz);
  82. entries = Dir_Read(fn, buffer3, sz);
  83. printf("directory '%s':\n %-15s\t%-s\n", fn, "NAME", "INODE");
  84. idx = 0;
  85. for(int i=0; i<entries; i++) {
  86. printf("%-4d %-15s\t%-d\n", i, &buffer3[idx], *(int*)&buffer3[idx+16]);
  87. idx += 20;
  88. }
  89. free(buffer3);
  90.  
  91. printf("\nExpected output: SUCCESS\n");
  92. fn = "/dir-1/dir-2";
  93. if(Dir_Unlink(fn) < 0) printf("ERROR: can't unlink dir '%s'\n", fn);
  94. else printf("dir '%s' unlinked successfully\n", fn);
  95.  
  96. printf("\nExpected output: SUCCESS\n");
  97. fn = "/dir-1/file-1";
  98. if(File_Unlink(fn) < 0) printf("ERROR: can't unlink file '%s'\n", fn);
  99. else printf("file '%s' unlinked successfully\n", fn);
  100.  
  101. printf("\nExpected output: SUCCESS\n");
  102. fn = "/dir-3";
  103. if(Dir_Create(fn) < 0) printf("ERROR: can't create dir '%s'\n", fn);
  104. else printf("dir '%s' created successfully\n", fn);
  105.  
  106. printf("\nExpected output: SUCCESS\n");
  107. fn = "/dir-1";
  108. if(Dir_Unlink(fn) < 0) printf("ERROR: can't unlink dir '%s'\n", fn);
  109. else printf("dir '%s' unlinked successfully\n", fn);
  110.  
  111. printf("\nExpected output: SUCCESS\n");
  112. fn = "/dir-4";
  113. if(Dir_Create(fn) < 0) printf("ERROR: can't create dir '%s'\n", fn);
  114. else printf("dir '%s' created successfully\n", fn);
  115.  
  116. printf("\nExpected output: SUCCESS\n");
  117. fn = "/";
  118. sz = Dir_Size(fn);
  119. printf("Directory size: %d\n", sz);
  120. char* buffer2 = malloc(sz);
  121. entries = Dir_Read(fn, buffer2, sz);
  122. printf("directory '%s':\n %-15s\t%-s\n", fn, "NAME", "INODE");
  123. idx = 0;
  124. for(int i=0; i<entries; i++) {
  125. printf("%-4d %-15s\t%-d\n", i, &buffer2[idx], *(int*)&buffer2[idx+16]);
  126. idx += 20;
  127. }
  128. free(buffer2);
  129.  
  130. if(FS_Sync() < 0) {
  131. printf("ERROR: can't sync file system to file '%s'\n", argv[1]);
  132. return -1;
  133. } else printf("file system sync'd to file '%s'\n", argv[1]);
  134.  
  135. return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement