phatdbg.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (C) 2005 by egnite Software GmbH. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  25. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  27. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * For additional information see http://www.ethernut.de/
  31. */
  32. /*!
  33. * \file fs/phatdbg.c
  34. * \brief PHAT debugging support.
  35. *
  36. * \verbatim
  37. *
  38. * $Log$
  39. * Revision 1.2 2008/08/11 06:59:42 haraldkipp
  40. * BSD types replaced by stdint types (feature request #1282721).
  41. *
  42. * Revision 1.1 2006/01/05 16:31:27 haraldkipp
  43. * First check-in.
  44. *
  45. *
  46. * \endverbatim
  47. */
  48. #include <errno.h>
  49. #include <fs/fs.h>
  50. #include <fs/phatfs.h>
  51. #include <fs/phatvol.h>
  52. #include <dev/blockdev.h>
  53. #include <fs/phatio.h>
  54. #include <stdio.h>
  55. #include <fs/phatdbg.h>
  56. /*!
  57. * \addtogroup xgPhatDbg
  58. */
  59. /*@{*/
  60. void PhatDbgAttrList(FILE * fp, uint8_t attr)
  61. {
  62. if (attr & PHAT_FATTR_RDONLY) {
  63. fputc('R', fp);
  64. } else if (attr & PHAT_FATTR_HIDDEN) {
  65. fputc('H', fp);
  66. } else if (attr & PHAT_FATTR_SYSTEM) {
  67. fputc('S', fp);
  68. } else if (attr & PHAT_FATTR_VOLID) {
  69. fputc('V', fp);
  70. } else if (attr & PHAT_FATTR_DIR) {
  71. fputc('D', fp);
  72. } else if (attr & PHAT_FATTR_ARCHIV) {
  73. fputc('A', fp);
  74. }
  75. }
  76. void PhatDbgDirEntry(FILE * fp, const char *title, PHATDIRENT * dent)
  77. {
  78. if (title) {
  79. fprintf(fp, "--- %s ---\n", title);
  80. }
  81. fprintf(fp, "DentFName: '%.11s'\n", dent->dent_name);
  82. fputs("DentFAttr: ", fp);
  83. PhatDbgAttrList(fp, dent->dent_attr);
  84. fputc('\n', fp);
  85. fprintf(fp, "DentRsrvd: 0x%02X\n", dent->dent_rsvdnt);
  86. fprintf(fp, "DentCTime: 0x%04X 0x%04X 0x%02X\n", dent->dent_cdate, dent->dent_ctime, dent->dent_ctsecs);
  87. fprintf(fp, "DentADate: 0x%04X\n", dent->dent_adate);
  88. fprintf(fp, "DentMTime: 0x%04X 0x%04X\n", dent->dent_mdate, dent->dent_mtime);
  89. fprintf(fp, "DentClust: %lu\n", (uint32_t) dent->dent_clust + ((uint32_t) dent->dent_clusthi << 16));
  90. fprintf(fp, "DentFSize: %lu\n", dent->dent_fsize);
  91. }
  92. void PhatDbgFileInfo(FILE * fp, const char *title, PHATFILE * nfp)
  93. {
  94. if (title) {
  95. fprintf(fp, "--- %s ---\n", title);
  96. }
  97. fprintf(fp, "File Pos : %lu\n", nfp->f_pos);
  98. fprintf(fp, "Cluster : %lu Prev %lu\n", nfp->f_clust, nfp->f_clust_prv);
  99. fprintf(fp, "Cluster Pos: %lu\n", nfp->f_clust_pos);
  100. fprintf(fp, "Sector Pos : %lu\n", nfp->f_sect_pos);
  101. PhatDbgDirEntry(fp, NULL, &nfp->f_dirent);
  102. fprintf(fp, "Parent Clust: %lu\n", (uint32_t) nfp->f_pde_clust + ((uint32_t) nfp->f_pde_clusthi << 16));
  103. fprintf(fp, "DirEnt Sect : %lu\n", nfp->f_de_sect);
  104. fprintf(fp, "DirEnt Offs : %lu\n", nfp->f_de_offs);
  105. fprintf(fp, "DirEnt Dirty: %u\n", nfp->f_de_dirty);
  106. }
  107. void PhatDbgVbr(FILE * fp, const char *title, PHATVBR * vbr)
  108. {
  109. if (title) {
  110. fprintf(fp, "--- %s ---\n", title);
  111. }
  112. fprintf(fp, "Boot jump : %02X %02X %02X\n", vbr->boot_jump[0], vbr->boot_jump[1], vbr->boot_jump[2]);
  113. fprintf(fp, "OEM name : %.8s\n", vbr->boot_oem);
  114. fprintf(fp, "Bytes/sector : %u\n", vbr->bios_sectsz);
  115. fprintf(fp, "Sectors/cluster: %u\n", vbr->bios_clustsz);
  116. fprintf(fp, "Rsvd. sectors : %u\n", vbr->bios_rsvd_sects);
  117. fprintf(fp, "Alloc. tables : %u\n", vbr->bios_ntabs);
  118. fprintf(fp, "Root entries : %u\n", vbr->bios_rootsz);
  119. fprintf(fp, "Total sectors : %lu\n", vbr->bios_volsz ? (uint32_t) vbr->bios_volsz : vbr->bios_volsz_big);
  120. fprintf(fp, "Media type : 0x%02X\n", vbr->bios_media);
  121. fprintf(fp, "Sectors/table : %u %lu\n", vbr->bios_tabsz, vbr->bios_tabsz_big);
  122. fprintf(fp, "Sectors/track : %u\n", vbr->bios_sects_p_trk);
  123. fprintf(fp, "Heads : %u\n", vbr->bios_heads);
  124. fprintf(fp, "Hidden sectors : %lu\n", vbr->bios_sects_hidd);
  125. fprintf(fp, "Mirror flags : 0x%04u\n", vbr->bios_xflags);
  126. fprintf(fp, "File system ver: %u\n", vbr->bios_fsver);
  127. fprintf(fp, "Root dir clust : %lu\n", vbr->bios_root_clust);
  128. fprintf(fp, "FSInfo sector : %u\n", vbr->bios_fsinfo);
  129. fprintf(fp, "Boot back sect : %u\n", vbr->bios_boot_bak);
  130. fprintf(fp, "Logical drive : %u\n", vbr->boot_drive);
  131. fprintf(fp, "Rsvd NT(head) : %u\n", vbr->boot_rsvd_nt);
  132. fprintf(fp, "Ext. signature : 0x%02X\n", vbr->boot_xsig);
  133. if (vbr->boot_xsig == 0x28 || vbr->boot_xsig == 0x29) {
  134. fprintf(fp, "Volume ID : 0x%08lX\n", vbr->boot_vol_id);
  135. fprintf(fp, "Volume label : %.11s\n", vbr->boot_vol_lbl);
  136. fprintf(fp, "Filesystem : %.8s\n", vbr->boot_vol_fs);
  137. }
  138. }
  139. /*@}*/