Nut/OS  4.10.3
API Reference
phatdbg.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  */
00032 
00050 #include <errno.h>
00051 
00052 #include <fs/fs.h>
00053 
00054 #include <fs/phatfs.h>
00055 #include <fs/phatvol.h>
00056 #include <dev/blockdev.h>
00057 #include <fs/phatio.h>
00058 
00059 #include <stdio.h>
00060 
00061 #include <fs/phatdbg.h>
00062 
00067 
00068 void PhatDbgAttrList(FILE * fp, uint8_t attr)
00069 {
00070     if (attr & PHAT_FATTR_RDONLY) {
00071         fputc('R', fp);
00072     } else if (attr & PHAT_FATTR_HIDDEN) {
00073         fputc('H', fp);
00074     } else if (attr & PHAT_FATTR_SYSTEM) {
00075         fputc('S', fp);
00076     } else if (attr & PHAT_FATTR_VOLID) {
00077         fputc('V', fp);
00078     } else if (attr & PHAT_FATTR_DIR) {
00079         fputc('D', fp);
00080     } else if (attr & PHAT_FATTR_ARCHIV) {
00081         fputc('A', fp);
00082     }
00083 }
00084 
00085 void PhatDbgDirEntry(FILE * fp, CONST char *title, PHATDIRENT * dent)
00086 {
00087     if (title) {
00088         fprintf(fp, "--- %s ---\n", title);
00089     }
00090     fprintf(fp, "DentFName: '%.11s'\n", dent->dent_name);
00091     fputs("DentFAttr: ", fp);
00092     PhatDbgAttrList(fp, dent->dent_attr);
00093     fputc('\n', fp);
00094     fprintf(fp, "DentRsrvd: 0x%02X\n", dent->dent_rsvdnt);
00095     fprintf(fp, "DentCTime: 0x%04X 0x%04X 0x%02X\n", dent->dent_cdate, dent->dent_ctime, dent->dent_ctsecs);
00096     fprintf(fp, "DentADate: 0x%04X\n", dent->dent_adate);
00097     fprintf(fp, "DentMTime: 0x%04X 0x%04X\n", dent->dent_mdate, dent->dent_mtime);
00098     fprintf(fp, "DentClust: %lu\n", (uint32_t) dent->dent_clust + ((uint32_t) dent->dent_clusthi << 16));
00099     fprintf(fp, "DentFSize: %lu\n", dent->dent_fsize);
00100 }
00101 
00102 void PhatDbgFileInfo(FILE * fp, CONST char *title, PHATFILE * nfp)
00103 {
00104     if (title) {
00105         fprintf(fp, "--- %s ---\n", title);
00106     }
00107     fprintf(fp, "File Pos   : %lu\n", nfp->f_pos);
00108     fprintf(fp, "Cluster    : %lu  Prev %lu\n", nfp->f_clust, nfp->f_clust_prv);
00109     fprintf(fp, "Cluster Pos: %lu\n", nfp->f_clust_pos);
00110     fprintf(fp, "Sector Pos : %lu\n", nfp->f_sect_pos);
00111     PhatDbgDirEntry(fp, NULL, &nfp->f_dirent);
00112     fprintf(fp, "Parent Clust: %lu\n", (uint32_t) nfp->f_pde_clust + ((uint32_t) nfp->f_pde_clusthi << 16));
00113     fprintf(fp, "DirEnt Sect : %lu\n", nfp->f_de_sect);
00114     fprintf(fp, "DirEnt Offs : %lu\n", nfp->f_de_offs);
00115     fprintf(fp, "DirEnt Dirty: %u\n", nfp->f_de_dirty);
00116 }
00117 
00118 void PhatDbgVbr(FILE * fp, CONST char *title, PHATVBR * vbr)
00119 {
00120     if (title) {
00121         fprintf(fp, "--- %s ---\n", title);
00122     }
00123     fprintf(fp, "Boot jump      : %02X %02X %02X\n", vbr->boot_jump[0], vbr->boot_jump[1], vbr->boot_jump[2]);
00124     fprintf(fp, "OEM name       : %.8s\n", vbr->boot_oem);
00125     fprintf(fp, "Bytes/sector   : %u\n", vbr->bios_sectsz);
00126     fprintf(fp, "Sectors/cluster: %u\n", vbr->bios_clustsz);
00127     fprintf(fp, "Rsvd. sectors  : %u\n", vbr->bios_rsvd_sects);
00128     fprintf(fp, "Alloc. tables  : %u\n", vbr->bios_ntabs);
00129     fprintf(fp, "Root entries   : %u\n", vbr->bios_rootsz);
00130     fprintf(fp, "Total sectors  : %lu\n", vbr->bios_volsz ? (uint32_t) vbr->bios_volsz : vbr->bios_volsz_big);
00131     fprintf(fp, "Media type     : 0x%02X\n", vbr->bios_media);
00132     fprintf(fp, "Sectors/table  : %u %lu\n", vbr->bios_tabsz, vbr->bios_tabsz_big);
00133     fprintf(fp, "Sectors/track  : %u\n", vbr->bios_sects_p_trk);
00134     fprintf(fp, "Heads          : %u\n", vbr->bios_heads);
00135     fprintf(fp, "Hidden sectors : %lu\n", vbr->bios_sects_hidd);
00136     fprintf(fp, "Mirror flags   : 0x%04u\n", vbr->bios_xflags);
00137     fprintf(fp, "File system ver: %u\n", vbr->bios_fsver);
00138     fprintf(fp, "Root dir clust : %lu\n", vbr->bios_root_clust);
00139     fprintf(fp, "FSInfo sector  : %u\n", vbr->bios_fsinfo);
00140     fprintf(fp, "Boot back sect : %u\n", vbr->bios_boot_bak);
00141     fprintf(fp, "Logical drive  : %u\n", vbr->boot_drive);
00142     fprintf(fp, "Rsvd NT(head)  : %u\n", vbr->boot_rsvd_nt);
00143     fprintf(fp, "Ext. signature : 0x%02X\n", vbr->boot_xsig);
00144     if (vbr->boot_xsig == 0x28 || vbr->boot_xsig == 0x29) {
00145         fprintf(fp, "Volume ID      : 0x%08lX\n", vbr->boot_vol_id);
00146         fprintf(fp, "Volume label   : %.11s\n", vbr->boot_vol_lbl);
00147         fprintf(fp, "Filesystem     : %.8s\n", vbr->boot_vol_fs);
00148     }
00149 }
00150