dnix-traverse.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 dnix_daddr_t;
  11. typedef int dnix_time_t;
  12. #pragma pack(1)
  13. #define daddr_t dnix_daddr_t
  14. #define time_t dnix_time_t
  15. #include "../dnix-headers/diskpar.h"
  16. #include "../dnix-headers/inode.h"
  17. #include "../dnix-headers/sysfile.h"
  18. #include "../dnix-headers/dir.h"
  19. #undef daddr_t
  20. #undef time_t
  21. #define daddr_t daddr_t
  22. #define time_t time_t
  23. #define swap32(num) (((num>>24)&0xff) | ((num<<8)&0xff0000) | ((num>>8)&0xff00) | ((num<<24)&0xff000000))
  24. class DnixFs {
  25. struct sysfptr dnixPartitionInfo;
  26. FILE * image;
  27. public:
  28. DnixFs();
  29. void init( FILE * image );
  30. };
  31. void DnixFs::init(FILE * img) {
  32. char buffer[26];
  33. struct tm * tm_info;
  34. time_t tim;
  35. image = img;
  36. // Read the partition info
  37. fseek (image, 512, SEEK_SET);
  38. fread ( (void * ) &dnixPartitionInfo, 512, 1, image);
  39. tim = swap32(dnixPartitionInfo.timestamp);
  40. tm_info = localtime((time_t *) ( &tim));
  41. strftime(buffer, 26, "%Y-%m-%d %H:%M:%S", tm_info);
  42. printf ("Pointer to volume descriptor block: %08X\n", swap32(dnixPartitionInfo.vdsp));
  43. printf ("1:s complement of previous item: %08X\n", swap32(dnixPartitionInfo.vdspn));
  44. printf ("Volume clean flag: %08X\n", swap32(dnixPartitionInfo.cleanfl));
  45. printf ("Timestamp %s\n", buffer);
  46. }
  47. DnixFs::DnixFs() {
  48. }
  49. int main (int argc, char ** argv) {
  50. FILE * image_file;
  51. int opt;
  52. class DnixFs dnixFs;
  53. while ((opt = getopt(argc, argv, "d:")) != -1) {
  54. switch (opt) {
  55. case 'd':
  56. image_file = fopen (optarg, "r");
  57. if (image_file == NULL) {
  58. perror ("Failure opening file.");
  59. exit(EXIT_FAILURE);
  60. }
  61. break;
  62. default: /* '?' */
  63. fprintf(stderr, "Usage: %s [-d disk-image-file]\n", argv[0]);
  64. exit(EXIT_FAILURE);
  65. }
  66. }
  67. dnixFs.init(image_file);
  68. }