]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - logprint/log_redo.c
xfs_logprint: Add log item printing for ATTRI and ATTRD
[thirdparty/xfsprogs-dev.git] / logprint / log_redo.c
index 297e203d097609ccba590363c2d9ef50fbc1c890..1974382d2da3d9225673140202c86604a3df5191 100644 (file)
@@ -653,3 +653,197 @@ xlog_recover_print_bud(
        f = item->ri_buf[0].i_addr;
        xlog_print_trans_bud(&f, sizeof(struct xfs_bud_log_format));
 }
+
+/* Attr Items */
+
+static int
+xfs_attri_copy_log_format(
+       char                            *buf,
+       uint                            len,
+       struct xfs_attri_log_format     *dst_attri_fmt)
+{
+       uint dst_len = sizeof(struct xfs_attri_log_format);
+
+       if (len == dst_len) {
+               memcpy((char *)dst_attri_fmt, buf, len);
+               return 0;
+       }
+
+       fprintf(stderr, _("%s: bad size of attri format: %u; expected %u\n"),
+               progname, len, dst_len);
+       return 1;
+}
+
+int
+xlog_print_trans_attri(
+       char                            **ptr,
+       uint                            src_len,
+       int                             *i)
+{
+       struct xfs_attri_log_format     *src_f = NULL;
+       xlog_op_header_t                *head = NULL;
+       uint                            dst_len;
+       int                             error = 0;
+
+       dst_len = sizeof(struct xfs_attri_log_format);
+       if (src_len != dst_len) {
+               fprintf(stderr, _("%s: bad size of attri format: %u; expected %u\n"),
+                               progname, src_len, dst_len);
+               return 1;
+       }
+
+       /*
+        * memmove to ensure 8-byte alignment for the long longs in
+        * xfs_attri_log_format_t structure
+        */
+       src_f = malloc(src_len);
+       if (!src_f) {
+               fprintf(stderr, _("%s: xlog_print_trans_attri: malloc failed\n"),
+                               progname);
+               exit(1);
+       }
+       memmove((char*)src_f, *ptr, src_len);
+       *ptr += src_len;
+
+       printf(_("ATTRI:  #regs: %d     name_len: %d, value_len: %d  id: 0x%llx\n"),
+               src_f->alfi_size, src_f->alfi_name_len, src_f->alfi_value_len,
+                               (unsigned long long)src_f->alfi_id);
+
+       if (src_f->alfi_name_len > 0) {
+               printf(_("\n"));
+               (*i)++;
+               head = (xlog_op_header_t *)*ptr;
+               xlog_print_op_header(head, *i, ptr);
+               error = xlog_print_trans_attri_name(ptr, be32_to_cpu(head->oh_len));
+               if (error)
+                       goto error;
+       }
+
+       if (src_f->alfi_value_len > 0) {
+               printf(_("\n"));
+               (*i)++;
+               head = (xlog_op_header_t *)*ptr;
+               xlog_print_op_header(head, *i, ptr);
+               error = xlog_print_trans_attri_value(ptr, be32_to_cpu(head->oh_len),
+                               src_f->alfi_value_len);
+       }
+error:
+       free(src_f);
+
+       return error;
+}      /* xlog_print_trans_attri */
+
+int
+xlog_print_trans_attri_name(
+       char                            **ptr,
+       uint                            src_len)
+{
+       printf(_("ATTRI:  name len:%u\n"), src_len);
+       print_or_dump(*ptr, src_len);
+
+       *ptr += src_len;
+
+       return 0;
+}      /* xlog_print_trans_attri */
+
+int
+xlog_print_trans_attri_value(
+       char                            **ptr,
+       uint                            src_len,
+       int                             value_len)
+{
+       int len = min(value_len, src_len);
+
+       printf(_("ATTRI:  value len:%u\n"), value_len);
+       print_or_dump(*ptr, len);
+
+       *ptr += src_len;
+
+       return 0;
+}      /* xlog_print_trans_attri_value */
+
+void
+xlog_recover_print_attri(
+       struct xlog_recover_item        *item)
+{
+       struct xfs_attri_log_format     *f, *src_f = NULL;
+       uint                            src_len, dst_len;
+
+       int                             region = 0;
+
+       src_f = (struct xfs_attri_log_format *)item->ri_buf[0].i_addr;
+       src_len = item->ri_buf[region].i_len;
+
+       /*
+        * An xfs_attri_log_format structure contains a attribute name and
+        * variable length value  as the last field.
+        */
+       dst_len = sizeof(struct xfs_attri_log_format);
+
+       if ((f = ((struct xfs_attri_log_format *)malloc(dst_len))) == NULL) {
+               fprintf(stderr, _("%s: xlog_recover_print_attri: malloc failed\n"),
+                       progname);
+               exit(1);
+       }
+       if (xfs_attri_copy_log_format((char*)src_f, src_len, f))
+               goto out;
+
+       printf(_("ATTRI:  #regs: %d     name_len: %d, value_len: %d  id: 0x%llx\n"),
+               f->alfi_size, f->alfi_name_len, f->alfi_value_len, (unsigned long long)f->alfi_id);
+
+       if (f->alfi_name_len > 0) {
+               region++;
+               printf(_("ATTRI:  name len:%u\n"), f->alfi_name_len);
+               print_or_dump((char *)item->ri_buf[region].i_addr,
+                              f->alfi_name_len);
+       }
+
+       if (f->alfi_value_len > 0) {
+               int len = f->alfi_value_len;
+
+               if (len > MAX_ATTR_VAL_PRINT)
+                       len = MAX_ATTR_VAL_PRINT;
+
+               region++;
+               printf(_("ATTRI:  value len:%u\n"), f->alfi_value_len);
+               print_or_dump((char *)item->ri_buf[region].i_addr, len);
+       }
+
+out:
+       free(f);
+
+}
+
+int
+xlog_print_trans_attrd(char **ptr, uint len)
+{
+       struct xfs_attrd_log_format *f;
+       struct xfs_attrd_log_format lbuf;
+       uint core_size = sizeof(struct xfs_attrd_log_format);
+
+       memcpy(&lbuf, *ptr, MIN(core_size, len));
+       f = &lbuf;
+       *ptr += len;
+       if (len >= core_size) {
+               printf(_("ATTRD:  #regs: %d     id: 0x%llx\n"),
+                       f->alfd_size,
+                       (unsigned long long)f->alfd_alf_id);
+               return 0;
+       } else {
+               printf(_("ATTRD: Not enough data to decode further\n"));
+               return 1;
+       }
+}      /* xlog_print_trans_attrd */
+
+void
+xlog_recover_print_attrd(
+       struct xlog_recover_item                *item)
+{
+       struct xfs_attrd_log_format     *f;
+
+       f = (struct xfs_attrd_log_format *)item->ri_buf[0].i_addr;
+
+       printf(_("      ATTRD:  #regs: %d       id: 0x%llx\n"),
+               f->alfd_size,
+               (unsigned long long)f->alfd_alf_id);
+}