LCOV - code coverage report
Current view: top level - edit - struct_print.c (source / functions) Coverage Total Hit
Test: gfs2-utils.info Lines: 43.3 % 210 91
Test Date: 2024-03-07 16:24:06 Functions: 46.7 % 15 7

            Line data    Source code
       1              : #include <stddef.h>
       2              : #include <stdarg.h>
       3              : #include <string.h>
       4              : #include <inttypes.h>
       5              : #include <uuid.h>
       6              : #include <libgfs2.h>
       7              : 
       8              : #include "hexedit.h"
       9              : #include "gfs2hex.h"
      10              : #include "struct_print.h"
      11              : 
      12       224052 : static void check_highlight(int highlight)
      13              : {
      14       224052 :         if (!termlines || line >= termlines) /* If printing or out of bounds */
      15       224052 :                 return;
      16            0 :         if (dmode == HEX_MODE) {
      17            0 :                 if (line == (edit_row[dmode] * lines_per_row[dmode]) + 4) {
      18            0 :                         if (highlight) {
      19            0 :                                 COLORS_HIGHLIGHT;
      20            0 :                                 last_entry_onscreen[dmode] = print_entry_ndx;
      21              :                         } else
      22            0 :                                 COLORS_NORMAL;
      23              :                 }
      24              :         } else {
      25            0 :                 if ((line * lines_per_row[dmode]) - 4 ==
      26            0 :                         (edit_row[dmode] - start_row[dmode]) * lines_per_row[dmode]) {
      27            0 :                         if (highlight) {
      28            0 :                                 COLORS_HIGHLIGHT;
      29            0 :                                 last_entry_onscreen[dmode] = print_entry_ndx;
      30              :                         }
      31              :                         else
      32            0 :                                 COLORS_NORMAL;
      33              :                 }
      34              :         }
      35              : }
      36              : 
      37              : __attribute__((format(printf,2,4)))
      38        58242 : static void print_it(const char *label, const char *fmt, const char *fmt2, ...)
      39              : {
      40              :         va_list args;
      41              :         char tmp_string[NAME_MAX];
      42              :         const char *fmtstring;
      43              :         int decimalsize;
      44              : 
      45        58242 :         if (!termlines || line < termlines) {
      46        58242 :                 va_start(args, fmt2);
      47        58242 :                 check_highlight(TRUE);
      48        58242 :                 if (termlines) {
      49            0 :                         move(line,0);
      50            0 :                         printw("%s", label);
      51            0 :                         move(line,24);
      52              :                 } else {
      53        58242 :                         if (!strcmp(label, "  "))
      54            0 :                                 printf("%-11s", label);
      55              :                         else
      56        58242 :                                 printf("%-24s", label);
      57              :                 }
      58        58242 :                 vsprintf(tmp_string, fmt, args);
      59              : 
      60        58242 :                 if (termlines)
      61            0 :                         printw("%s", tmp_string);
      62              :                 else
      63        58242 :                         printf("%s", tmp_string);
      64        58242 :                 check_highlight(FALSE);
      65              : 
      66        58242 :                 if (fmt2) {
      67        53784 :                         decimalsize = strlen(tmp_string);
      68        53784 :                         va_end(args);
      69        53784 :                         va_start(args, fmt2);
      70        53784 :                         vsprintf(tmp_string, fmt2, args);
      71        53784 :                         check_highlight(TRUE);
      72        53784 :                         if (termlines) {
      73            0 :                                 move(line, 50);
      74            0 :                                 printw("%s", tmp_string);
      75              :                         } else {
      76              :                                 int i;
      77       925473 :                                 for (i=20 - decimalsize; i > 0; i--)
      78       871689 :                                         printf(" ");
      79        53784 :                                 printf("%s", tmp_string);
      80              :                         }
      81        53784 :                         check_highlight(FALSE);
      82              :                 } else {
      83         4458 :                         if (strstr(fmt,"X") || strstr(fmt,"x"))
      84         4451 :                                 fmtstring="(hex)";
      85            7 :                         else if (strstr(fmt,"s"))
      86            0 :                                 fmtstring="";
      87              :                         else
      88            7 :                                 fmtstring="(decimal)";
      89         4458 :                         if (termlines) {
      90            0 :                                 move(line, 50);
      91            0 :                                 printw("%s", fmtstring);
      92              :                         }
      93              :                         else
      94         4458 :                                 printf("%s", fmtstring);
      95              :                 }
      96        58242 :                 if (termlines) {
      97            0 :                         refresh();
      98            0 :                         if (line == (edit_row[dmode] * lines_per_row[dmode]) + 4) {
      99            0 :                                 strncpy(efield, label + 2, 63); /* it's indented */
     100            0 :                                 efield[63] = '\0';
     101            0 :                                 strcpy(estring, tmp_string);
     102            0 :                                 strncpy(edit_fmt, fmt, 79);
     103            0 :                                 edit_fmt[79] = '\0';
     104            0 :                                 edit_size[dmode] = strlen(estring);
     105            0 :                                 COLORS_NORMAL;
     106              :                         }
     107            0 :                         last_entry_onscreen[dmode] = (line / lines_per_row[dmode]) - 4;
     108              :                 }
     109        58242 :                 eol(0);
     110        58242 :                 va_end(args);
     111              :         }
     112        58242 : }
     113              : 
     114              : #define printbe16(struct, member) do { \
     115              :                 print_it("  "#member, "%"PRIu16, "0x%"PRIx16, be16_to_cpu(struct->member)); \
     116              :         } while(0)
     117              : #define printbe32(struct, member) do { \
     118              :                 print_it("  "#member, "%"PRIu32, "0x%"PRIx32, be32_to_cpu(struct->member)); \
     119              :         } while(0)
     120              : #define printbe64(struct, member) do { \
     121              :                 print_it("  "#member, "%"PRIu64, "0x%"PRIx64, be64_to_cpu(struct->member)); \
     122              :         } while(0)
     123              : #define print8(struct, member) do { \
     124              :                 print_it("  "#member, "%"PRIu8, "0x%"PRIx8, struct->member); \
     125              :         } while(0)
     126              : 
     127            7 : void inum_print(void *nop)
     128              : {
     129            7 :         struct gfs2_inum *no = nop;
     130              : 
     131            7 :         printbe64(no, no_formal_ino);
     132            7 :         printbe64(no, no_addr);
     133            7 : }
     134              : 
     135         4444 : void meta_header_print(void *mhp)
     136              : {
     137         4444 :         struct gfs2_meta_header *mh = mhp;
     138              : 
     139         4444 :         print_it("  mh_magic", "0x%08"PRIX32, NULL, be32_to_cpu(mh->mh_magic));
     140         4444 :         printbe32(mh, mh_type);
     141         4444 :         printbe32(mh, mh_format);
     142         4444 : }
     143              : 
     144            0 : void sb_print(void *sbp)
     145              : {
     146            0 :         struct gfs2_sb *sb = sbp;
     147              :         char readable_uuid[36+1];
     148              : 
     149            0 :         meta_header_print(&sb->sb_header);
     150            0 :         printbe32(sb, sb_fs_format);
     151            0 :         printbe32(sb, sb_multihost_format);
     152            0 :         printbe32(sb, sb_bsize);
     153            0 :         printbe32(sb, sb_bsize_shift);
     154            0 :         inum_print(&sb->sb_master_dir);
     155            0 :         inum_print(&sb->sb_root_dir);
     156            0 :         print_it("  sb_lockproto", "%.64s", NULL, sb->sb_lockproto);
     157            0 :         print_it("  sb_locktable", "%.64s", NULL, sb->sb_locktable);
     158            0 :         uuid_unparse(sb->sb_uuid, readable_uuid);
     159            0 :         print_it("  uuid", "%36s", NULL, readable_uuid);
     160            0 : }
     161              : 
     162          966 : void rindex_print(void *rip)
     163              : {
     164          966 :         struct gfs2_rindex *ri = rip;
     165              : 
     166          966 :         printbe64(ri, ri_addr);
     167          966 :         printbe32(ri, ri_length);
     168          966 :         printbe64(ri, ri_data0);
     169          966 :         printbe32(ri, ri_data);
     170          966 :         printbe32(ri, ri_bitbytes);
     171          966 : }
     172              : 
     173         4437 : void rgrp_print(void *rgp)
     174              : {
     175         4437 :         struct gfs2_rgrp *rg = rgp;
     176              : 
     177         4437 :         meta_header_print(&rg->rg_header);
     178         4437 :         printbe32(rg, rg_flags);
     179         4437 :         printbe32(rg, rg_free);
     180         4437 :         printbe32(rg, rg_dinodes);
     181         4437 :         printbe32(rg, rg_skip);
     182         4437 :         printbe64(rg, rg_igeneration);
     183         4437 :         printbe64(rg, rg_data0);
     184         4437 :         printbe32(rg, rg_data);
     185         4437 :         printbe32(rg, rg_bitbytes);
     186         4437 :         printbe32(rg, rg_crc);
     187         4437 : }
     188              : 
     189            0 : void quota_print(void *qp)
     190              : {
     191            0 :         struct gfs2_quota *q = qp;
     192              : 
     193            0 :         printbe64(q, qu_limit);
     194            0 :         printbe64(q, qu_warn);
     195            0 :         printbe64(q, qu_value);
     196            0 : }
     197              : 
     198            7 : void dinode_print(void *dip)
     199              : {
     200            7 :         struct gfs2_dinode *_di = dip;
     201              : 
     202            7 :         meta_header_print(&_di->di_header);
     203            7 :         inum_print(&_di->di_num);
     204              : 
     205            7 :         print_it("  di_mode", "0%"PRIo32, NULL, be32_to_cpu(di->di_mode));
     206            7 :         printbe32(_di, di_uid);
     207            7 :         printbe32(_di, di_gid);
     208            7 :         printbe32(_di, di_nlink);
     209            7 :         printbe64(_di, di_size);
     210            7 :         printbe64(_di, di_blocks);
     211            7 :         printbe64(_di, di_atime);
     212            7 :         printbe64(_di, di_mtime);
     213            7 :         printbe64(_di, di_ctime);
     214            7 :         printbe32(_di, di_major);
     215            7 :         printbe32(_di, di_minor);
     216            7 :         printbe64(_di, di_goal_meta);
     217            7 :         printbe64(_di, di_goal_data);
     218            7 :         print_it("  di_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(_di->di_flags));
     219            7 :         printbe32(_di, di_payload_format);
     220            7 :         printbe16(_di, di_height);
     221            7 :         printbe16(_di, di_depth);
     222            7 :         printbe32(_di, di_entries);
     223            7 :         printbe64(_di, di_eattr);
     224            7 : }
     225              : 
     226            0 : void leaf_print(void *lfp)
     227              : {
     228            0 :         struct gfs2_leaf *lf = lfp;
     229              : 
     230            0 :         meta_header_print(&lf->lf_header);
     231            0 :         printbe16(lf, lf_depth);
     232            0 :         printbe16(lf, lf_entries);
     233            0 :         printbe32(lf, lf_dirent_format);
     234            0 :         printbe64(lf, lf_next);
     235            0 :         printbe64(lf, lf_inode);
     236            0 :         printbe32(lf, lf_dist);
     237            0 :         printbe32(lf, lf_nsec);
     238            0 :         printbe64(lf, lf_sec);
     239            0 : }
     240              : 
     241              : /**
     242              :  * Print an extended attribute.
     243              :  * eap: Pointer to the start of the extended attribute.
     244              :  * lim: Record length limit. Used to check ea_name_len.
     245              :  */
     246            0 : void ea_header_print(void *eap, unsigned lim)
     247              : {
     248              :         char buf[GFS2_EA_MAX_NAME_LEN + 1];
     249            0 :         struct gfs2_ea_header *ea = eap;
     250            0 :         unsigned len = ea->ea_name_len;
     251              : 
     252            0 :         printbe32(ea, ea_rec_len);
     253            0 :         printbe32(ea, ea_data_len);
     254            0 :         print8(ea, ea_name_len);
     255            0 :         print8(ea, ea_type);
     256            0 :         print8(ea, ea_flags);
     257            0 :         print8(ea, ea_num_ptrs);
     258              : 
     259            0 :         if (sizeof(*ea) + len >= lim)
     260            0 :                 return;
     261              : 
     262            0 :         if (len > GFS2_EA_MAX_NAME_LEN)
     263            0 :                 len = GFS2_EA_MAX_NAME_LEN;
     264            0 :         memcpy(buf, ea + 1, len);
     265            0 :         buf[len] = '\0';
     266            0 :         print_it("  name", "%s", NULL, buf);
     267              : }
     268              : 
     269            0 : void log_header_print(void *lhp)
     270              : {
     271            0 :         struct gfs2_log_header *lh = lhp;
     272              : 
     273            0 :         meta_header_print(&lh->lh_header);
     274            0 :         printbe64(lh, lh_sequence);
     275            0 :         print_it("  lh_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_flags));
     276            0 :         printbe32(lh, lh_tail);
     277            0 :         printbe32(lh, lh_blkno);
     278            0 :         print_it("  lh_hash", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_hash));
     279            0 :         print_it("  lh_crc", "0x%.8"PRIX32, NULL, be32_to_cpu(lh->lh_crc));
     280            0 :         printbe32(lh, lh_nsec);
     281            0 :         printbe64(lh, lh_sec);
     282            0 :         printbe64(lh, lh_addr);
     283            0 :         printbe64(lh, lh_jinode);
     284            0 :         printbe64(lh, lh_statfs_addr);
     285            0 :         printbe64(lh, lh_quota_addr);
     286            0 :         print_it("  lh_local_total", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_total));
     287            0 :         print_it("  lh_local_free", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_free));
     288            0 :         print_it("  lh_local_dinodes", "%"PRId64, "0x%"PRIx64, be64_to_cpu(lh->lh_local_dinodes));
     289            0 : }
     290              : 
     291            0 : void log_descriptor_print(void *ldp)
     292              : {
     293            0 :         struct gfs2_log_descriptor *ld = ldp;
     294              : 
     295            0 :         meta_header_print(&ld->ld_header);
     296            0 :         printbe32(ld, ld_type);
     297            0 :         printbe32(ld, ld_length);
     298            0 :         printbe32(ld, ld_data1);
     299            0 :         printbe32(ld, ld_data2);
     300            0 : }
     301              : 
     302            0 : void statfs_change_print(void *scp)
     303              : {
     304            0 :         struct gfs2_statfs_change *sc = scp;
     305              : 
     306            0 :         print_it("  sc_total", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_total));
     307            0 :         print_it("  sc_free", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_free));
     308            0 :         print_it("  sc_dinodes", "%"PRId64, "0x%"PRIx64, be64_to_cpu(sc->sc_dinodes));
     309            0 : }
     310              : 
     311            0 : void quota_change_print(void *qcp)
     312              : {
     313            0 :         struct gfs2_quota_change *qc = qcp;
     314              : 
     315            0 :         print_it("  qc_change", "%"PRId64, "0x%"PRIx64, be64_to_cpu(qc->qc_change));
     316            0 :         print_it("  qc_flags", "0x%.8"PRIX32, NULL, be32_to_cpu(qc->qc_flags));
     317            0 :         printbe32(qc, qc_id);
     318            0 : }
        

Generated by: LCOV version 2.0-1