|
@@ -36,9 +36,9 @@
|
|
/*
|
|
/*
|
|
* Check the consistency of the data block.
|
|
* Check the consistency of the data block.
|
|
* The input can also be a block-format directory.
|
|
* The input can also be a block-format directory.
|
|
- * Return 0 is the buffer is good, otherwise an error.
|
|
|
|
|
|
+ * Return true if the buffer is good.
|
|
*/
|
|
*/
|
|
-int
|
|
|
|
|
|
+bool
|
|
__xfs_dir3_data_check(
|
|
__xfs_dir3_data_check(
|
|
struct xfs_inode *dp, /* incore inode pointer */
|
|
struct xfs_inode *dp, /* incore inode pointer */
|
|
struct xfs_buf *bp) /* data block's buffer */
|
|
struct xfs_buf *bp) /* data block's buffer */
|
|
@@ -90,16 +90,16 @@ __xfs_dir3_data_check(
|
|
* so just ensure that the count falls somewhere inside the
|
|
* so just ensure that the count falls somewhere inside the
|
|
* block right now.
|
|
* block right now.
|
|
*/
|
|
*/
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, be32_to_cpu(btp->count) <
|
|
|
|
- ((char *)btp - p) / sizeof(struct xfs_dir2_leaf_entry));
|
|
|
|
|
|
+ if (be32_to_cpu(btp->count) >=
|
|
|
|
+ ((char *)btp - p) / sizeof(struct xfs_dir2_leaf_entry))
|
|
|
|
+ return false;
|
|
break;
|
|
break;
|
|
case cpu_to_be32(XFS_DIR3_DATA_MAGIC):
|
|
case cpu_to_be32(XFS_DIR3_DATA_MAGIC):
|
|
case cpu_to_be32(XFS_DIR2_DATA_MAGIC):
|
|
case cpu_to_be32(XFS_DIR2_DATA_MAGIC):
|
|
endp = (char *)hdr + geo->blksize;
|
|
endp = (char *)hdr + geo->blksize;
|
|
break;
|
|
break;
|
|
default:
|
|
default:
|
|
- XFS_ERROR_REPORT("Bad Magic", XFS_ERRLEVEL_LOW, mp);
|
|
|
|
- return -EFSCORRUPTED;
|
|
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -108,22 +108,25 @@ __xfs_dir3_data_check(
|
|
bf = ops->data_bestfree_p(hdr);
|
|
bf = ops->data_bestfree_p(hdr);
|
|
count = lastfree = freeseen = 0;
|
|
count = lastfree = freeseen = 0;
|
|
if (!bf[0].length) {
|
|
if (!bf[0].length) {
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, !bf[0].offset);
|
|
|
|
|
|
+ if (bf[0].offset)
|
|
|
|
+ return false;
|
|
freeseen |= 1 << 0;
|
|
freeseen |= 1 << 0;
|
|
}
|
|
}
|
|
if (!bf[1].length) {
|
|
if (!bf[1].length) {
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, !bf[1].offset);
|
|
|
|
|
|
+ if (bf[1].offset)
|
|
|
|
+ return false;
|
|
freeseen |= 1 << 1;
|
|
freeseen |= 1 << 1;
|
|
}
|
|
}
|
|
if (!bf[2].length) {
|
|
if (!bf[2].length) {
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, !bf[2].offset);
|
|
|
|
|
|
+ if (bf[2].offset)
|
|
|
|
+ return false;
|
|
freeseen |= 1 << 2;
|
|
freeseen |= 1 << 2;
|
|
}
|
|
}
|
|
|
|
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, be16_to_cpu(bf[0].length) >=
|
|
|
|
- be16_to_cpu(bf[1].length));
|
|
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, be16_to_cpu(bf[1].length) >=
|
|
|
|
- be16_to_cpu(bf[2].length));
|
|
|
|
|
|
+ if (be16_to_cpu(bf[0].length) < be16_to_cpu(bf[1].length))
|
|
|
|
+ return false;
|
|
|
|
+ if (be16_to_cpu(bf[1].length) < be16_to_cpu(bf[2].length))
|
|
|
|
+ return false;
|
|
/*
|
|
/*
|
|
* Loop over the data/unused entries.
|
|
* Loop over the data/unused entries.
|
|
*/
|
|
*/
|
|
@@ -135,22 +138,23 @@ __xfs_dir3_data_check(
|
|
* doesn't need to be there.
|
|
* doesn't need to be there.
|
|
*/
|
|
*/
|
|
if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
|
|
if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) {
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, lastfree == 0);
|
|
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, endp >=
|
|
|
|
- p + be16_to_cpu(dup->length));
|
|
|
|
- XFS_WANT_CORRUPTED_RETURN(mp,
|
|
|
|
- be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) ==
|
|
|
|
- (char *)dup - (char *)hdr);
|
|
|
|
|
|
+ if (lastfree != 0)
|
|
|
|
+ return false;
|
|
|
|
+ if (endp < p + be16_to_cpu(dup->length))
|
|
|
|
+ return false;
|
|
|
|
+ if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) !=
|
|
|
|
+ (char *)dup - (char *)hdr)
|
|
|
|
+ return false;
|
|
dfp = xfs_dir2_data_freefind(hdr, bf, dup);
|
|
dfp = xfs_dir2_data_freefind(hdr, bf, dup);
|
|
if (dfp) {
|
|
if (dfp) {
|
|
i = (int)(dfp - bf);
|
|
i = (int)(dfp - bf);
|
|
- XFS_WANT_CORRUPTED_RETURN(mp,
|
|
|
|
- (freeseen & (1 << i)) == 0);
|
|
|
|
|
|
+ if ((freeseen & (1 << i)) != 0)
|
|
|
|
+ return false;
|
|
freeseen |= 1 << i;
|
|
freeseen |= 1 << i;
|
|
} else {
|
|
} else {
|
|
- XFS_WANT_CORRUPTED_RETURN(mp,
|
|
|
|
- be16_to_cpu(dup->length) <=
|
|
|
|
- be16_to_cpu(bf[2].length));
|
|
|
|
|
|
+ if (be16_to_cpu(dup->length) >
|
|
|
|
+ be16_to_cpu(bf[2].length))
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
p += be16_to_cpu(dup->length);
|
|
p += be16_to_cpu(dup->length);
|
|
lastfree = 1;
|
|
lastfree = 1;
|
|
@@ -163,16 +167,17 @@ __xfs_dir3_data_check(
|
|
* The linear search is crude but this is DEBUG code.
|
|
* The linear search is crude but this is DEBUG code.
|
|
*/
|
|
*/
|
|
dep = (xfs_dir2_data_entry_t *)p;
|
|
dep = (xfs_dir2_data_entry_t *)p;
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, dep->namelen != 0);
|
|
|
|
- XFS_WANT_CORRUPTED_RETURN(mp,
|
|
|
|
- !xfs_dir_ino_validate(mp, be64_to_cpu(dep->inumber)));
|
|
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, endp >=
|
|
|
|
- p + ops->data_entsize(dep->namelen));
|
|
|
|
- XFS_WANT_CORRUPTED_RETURN(mp,
|
|
|
|
- be16_to_cpu(*ops->data_entry_tag_p(dep)) ==
|
|
|
|
- (char *)dep - (char *)hdr);
|
|
|
|
- XFS_WANT_CORRUPTED_RETURN(mp,
|
|
|
|
- ops->data_get_ftype(dep) < XFS_DIR3_FT_MAX);
|
|
|
|
|
|
+ if (dep->namelen == 0)
|
|
|
|
+ return false;
|
|
|
|
+ if (xfs_dir_ino_validate(mp, be64_to_cpu(dep->inumber)))
|
|
|
|
+ return false;
|
|
|
|
+ if (endp < p + ops->data_entsize(dep->namelen))
|
|
|
|
+ return false;
|
|
|
|
+ if (be16_to_cpu(*ops->data_entry_tag_p(dep)) !=
|
|
|
|
+ (char *)dep - (char *)hdr)
|
|
|
|
+ return false;
|
|
|
|
+ if (ops->data_get_ftype(dep) >= XFS_DIR3_FT_MAX)
|
|
|
|
+ return false;
|
|
count++;
|
|
count++;
|
|
lastfree = 0;
|
|
lastfree = 0;
|
|
if (hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) ||
|
|
if (hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) ||
|
|
@@ -188,31 +193,32 @@ __xfs_dir3_data_check(
|
|
be32_to_cpu(lep[i].hashval) == hash)
|
|
be32_to_cpu(lep[i].hashval) == hash)
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- XFS_WANT_CORRUPTED_RETURN(mp,
|
|
|
|
- i < be32_to_cpu(btp->count));
|
|
|
|
|
|
+ if (i >= be32_to_cpu(btp->count))
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
p += ops->data_entsize(dep->namelen);
|
|
p += ops->data_entsize(dep->namelen);
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
* Need to have seen all the entries and all the bestfree slots.
|
|
* Need to have seen all the entries and all the bestfree slots.
|
|
*/
|
|
*/
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, freeseen == 7);
|
|
|
|
|
|
+ if (freeseen != 7)
|
|
|
|
+ return false;
|
|
if (hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) ||
|
|
if (hdr->magic == cpu_to_be32(XFS_DIR2_BLOCK_MAGIC) ||
|
|
hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) {
|
|
hdr->magic == cpu_to_be32(XFS_DIR3_BLOCK_MAGIC)) {
|
|
for (i = stale = 0; i < be32_to_cpu(btp->count); i++) {
|
|
for (i = stale = 0; i < be32_to_cpu(btp->count); i++) {
|
|
if (lep[i].address ==
|
|
if (lep[i].address ==
|
|
cpu_to_be32(XFS_DIR2_NULL_DATAPTR))
|
|
cpu_to_be32(XFS_DIR2_NULL_DATAPTR))
|
|
stale++;
|
|
stale++;
|
|
- if (i > 0)
|
|
|
|
- XFS_WANT_CORRUPTED_RETURN(mp,
|
|
|
|
- be32_to_cpu(lep[i].hashval) >=
|
|
|
|
- be32_to_cpu(lep[i - 1].hashval));
|
|
|
|
|
|
+ if (i > 0 && be32_to_cpu(lep[i].hashval) <
|
|
|
|
+ be32_to_cpu(lep[i - 1].hashval))
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, count ==
|
|
|
|
- be32_to_cpu(btp->count) - be32_to_cpu(btp->stale));
|
|
|
|
- XFS_WANT_CORRUPTED_RETURN(mp, stale == be32_to_cpu(btp->stale));
|
|
|
|
|
|
+ if (count != be32_to_cpu(btp->count) - be32_to_cpu(btp->stale))
|
|
|
|
+ return false;
|
|
|
|
+ if (stale != be32_to_cpu(btp->stale))
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
- return 0;
|
|
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
static bool
|
|
static bool
|
|
@@ -235,9 +241,7 @@ xfs_dir3_data_verify(
|
|
if (hdr3->magic != cpu_to_be32(XFS_DIR2_DATA_MAGIC))
|
|
if (hdr3->magic != cpu_to_be32(XFS_DIR2_DATA_MAGIC))
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- if (__xfs_dir3_data_check(NULL, bp))
|
|
|
|
- return false;
|
|
|
|
- return true;
|
|
|
|
|
|
+ return __xfs_dir3_data_check(NULL, bp);
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|