]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
db: add a special attribute buffer verifier
authorDave Chinner <dchinner@redhat.com>
Wed, 13 Nov 2013 06:40:50 +0000 (06:40 +0000)
committerRich Johnston <rjohnston@sgi.com>
Wed, 13 Nov 2013 17:14:04 +0000 (11:14 -0600)
Because we only have a single attribute type that is used for all
the attribute buffer types, we need to provide a special verifier
for the read code. That verifier needs to know all the attribute
types and when it find one it knows about, switch to the correct
verifier and call it.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Rich Johnston <rjohnston@sgi.com>
db/attr.c
db/attr.h
db/type.c

index cd95a0a8475e3a3eae21e0bba2cc90e13c47e6eb..740d5649755ba203c4bf55ed8342fa85fc82c48b 100644 (file)
--- a/db/attr.c
+++ b/db/attr.c
@@ -25,6 +25,7 @@
 #include "attr.h"
 #include "io.h"
 #include "init.h"
+#include "output.h"
 
 static int     attr_leaf_entries_count(void *obj, int startoff);
 static int     attr_leaf_hdr_count(void *obj, int startoff);
@@ -522,3 +523,53 @@ const field_t      attr3_leaf_hdr_flds[] = {
        { NULL }
 };
 
+/*
+ * Special read verifier for attribute buffers. Detect the magic number
+ * appropriately and set the correct verifier and call it.
+ */
+static void
+xfs_attr3_db_read_verify(
+       struct xfs_buf          *bp)
+{
+       __be32                  magic32;
+       __be16                  magic16;
+
+       magic32 = *(__be32 *)bp->b_addr;
+       magic16 = ((struct xfs_da_blkinfo *)bp->b_addr)->magic;
+
+       switch (magic16) {
+       case cpu_to_be16(XFS_ATTR3_LEAF_MAGIC):
+               bp->b_ops = &xfs_attr3_leaf_buf_ops;
+               goto verify;
+       case cpu_to_be16(XFS_DA3_NODE_MAGIC):
+               bp->b_ops = &xfs_da3_node_buf_ops;
+               goto verify;
+       default:
+               break;
+       }
+
+       switch (magic32) {
+       case cpu_to_be32(XFS_ATTR3_RMT_MAGIC):
+               bp->b_ops = &xfs_attr3_rmt_buf_ops;
+               break;
+       default:
+               dbprintf(_("Unknown attribute buffer type!\n"));
+               xfs_buf_ioerror(bp, EFSCORRUPTED);
+               return;
+       }
+verify:
+       bp->b_ops->verify_read(bp);
+}
+
+static void
+xfs_attr3_db_write_verify(
+       struct xfs_buf          *bp)
+{
+       dbprintf(_("Writing unknown attribute buffer type!\n"));
+       xfs_buf_ioerror(bp, EFSCORRUPTED);
+}
+
+const struct xfs_buf_ops xfs_attr3_db_buf_ops = {
+       .verify_read = xfs_attr3_db_read_verify,
+       .verify_write = xfs_attr3_db_write_verify,
+};
index 30653728a32689f696d701d58c08e4d6a1264f05..bc3431f9e0e637479f56705146399ec0056c1ab8 100644 (file)
--- a/db/attr.h
+++ b/db/attr.h
@@ -33,3 +33,5 @@ extern const field_t  attr3_node_hdr_flds[];
 
 extern int     attr_leaf_name_size(void *obj, int startoff, int idx);
 extern int     attr_size(void *obj, int startoff, int idx);
+
+extern const struct xfs_buf_ops xfs_attr3_db_buf_ops;
index 2c3431e38ddf2eeb56a65428230cb127d4cb9da4..04d0d56e0dcc22d2f956971dda3892e65a8b4cd7 100644 (file)
--- a/db/type.c
+++ b/db/type.c
@@ -77,7 +77,8 @@ static const typ_t    __typtab_crc[] = {
        { TYP_AGF, "agf", handle_struct, agf_hfld, &xfs_agf_buf_ops },
        { TYP_AGFL, "agfl", handle_struct, agfl_crc_hfld, &xfs_agfl_buf_ops },
        { TYP_AGI, "agi", handle_struct, agi_hfld, &xfs_agfl_buf_ops },
-       { TYP_ATTR, "attr3", handle_struct, attr3_hfld, NULL },
+       { TYP_ATTR, "attr3", handle_struct, attr3_hfld,
+               &xfs_attr3_db_buf_ops },
        { TYP_BMAPBTA, "bmapbta", handle_struct, bmapbta_crc_hfld,
                &xfs_bmbt_buf_ops },
        { TYP_BMAPBTD, "bmapbtd", handle_struct, bmapbtd_crc_hfld,