dnix-traverse.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. compile using : c++ dnix-traverse.cpp -o dnix-traverse
  3. Program to list and extract files from a DNIX FS. Should also be able to write to a DNIX file system. Possibly even add boot code and other things.
  4. */
  5. #include <stdio.h>
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8. #include <stdio.h>
  9. #include <time.h>
  10. typedef unsigned int daddr_t;
  11. typedef unsigned int dnix_time_t;
  12. #pragma pack(1)
  13. #include "../dnix-headers/diskpar.h"
  14. #include "../dnix-headers/inode.h"
  15. #include "../dnix-headers/sysfile.h"
  16. #include "../dnix-headers/dir.h"
  17. #define swap32(num) (((num>>24)&0xff) | ((num<<8)&0xff0000) | ((num>>8)&0xff00) | ((num<<24)&0xff000000))
  18. class DnixFs {
  19. struct sysfptr dnixPartitionInfo;
  20. FILE * image;
  21. public:
  22. DnixFs();
  23. void init( FILE * image );
  24. };
  25. void DnixFs::init(FILE * img) {
  26. char buffer[26];
  27. struct tm * tm_info;
  28. time_t tim;
  29. image = img;
  30. // Read the partition info
  31. fseek (image, 512, SEEK_SET);
  32. fread ( (void * ) &dnixPartitionInfo, 512, 1, image);
  33. tim = swap32(dnixPartitionInfo.timestamp);
  34. tm_info = localtime((time_t *) ( &tim));
  35. strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", tm_info);
  36. printf ("Pointer to volume descriptor block: %08X\n", swap32(dnixPartitionInfo.vdsp));
  37. printf ("1:s complement of previous item: %08X\n", swap32(dnixPartitionInfo.vdspn));
  38. printf ("Volume clean flag: %08X\n", swap32(dnixPartitionInfo.cleanfl));
  39. printf ("Timestamp %s\n", buffer);
  40. }
  41. DnixFs::DnixFs() {
  42. }
  43. int main (int argc, char ** argv) {
  44. FILE * image_file;
  45. int opt;
  46. class DnixFs dnixFs;
  47. while ((opt = getopt(argc, argv, "d:")) != -1) {
  48. switch (opt) {
  49. case 'd':
  50. image_file = fopen (optarg, "r");
  51. if (image_file == NULL) {
  52. perror ("Failure opening file.");
  53. exit(EXIT_FAILURE);
  54. }
  55. break;
  56. default: /* '?' */
  57. fprintf(stderr, "Usage: %s [-d disk-image-file]\n", argv[0]);
  58. exit(EXIT_FAILURE);
  59. }
  60. }
  61. dnixFs.init(image_file);
  62. }