diff options
author | Barry Naujok <bnaujok@sgi.com> | 2008-05-21 02:41:01 -0400 |
---|---|---|
committer | Niv Sardi <xaiki@debian.org> | 2008-07-28 02:58:36 -0400 |
commit | 5163f95a08cbf058ae16452c2242c5600fedc32e (patch) | |
tree | 5d6b905f7031144a62fb1fa17ba3106d99268003 /fs/xfs/xfs_dir2_block.c | |
parent | 68f34d5107dbace3d14a1c2f060fc8941894879c (diff) |
[XFS] Name operation vector for hash and compare
Adds two pieces of functionality for the basis of case-insensitive support
in XFS:
1. A comparison result enumerated type: xfs_dacmp. It represents an
exact match, case-insensitive match or no match at all. This patch
only implements different and exact results.
2. xfs_nameops vector for specifying how to perform the hash generation
of filenames and comparision methods. In this patch the hash vector
points to the existing xfs_da_hashname function and the comparison
method does a length compare, and if the same, does a memcmp and
return the xfs_dacmp result.
All filename functions that use the hash (create, lookup remove, rename,
etc) now use the xfs_nameops.hashname function and all directory lookup
functions also use the xfs_nameops.compname function.
The lookup functions also handle case-insensitive results even though the
default comparison function cannot return that. And important aspect of
the lookup functions is that an exact match always has precedence over a
case-insensitive. So while a case-insensitive match is found, we have to
keep looking just in case there is an exact match. In the meantime, the
info for the first case-insensitive match is retained if no exact match is
found.
SGI-PV: 981519
SGI-Modid: xfs-linux-melb:xfs-kern:31205a
Signed-off-by: Barry Naujok <bnaujok@sgi.com>
Signed-off-by: Christoph Hellwig <hch@infradead.org>
Diffstat (limited to 'fs/xfs/xfs_dir2_block.c')
-rw-r--r-- | fs/xfs/xfs_dir2_block.c | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/fs/xfs/xfs_dir2_block.c b/fs/xfs/xfs_dir2_block.c index e8a7aca5fe23..98588491cb0e 100644 --- a/fs/xfs/xfs_dir2_block.c +++ b/fs/xfs/xfs_dir2_block.c | |||
@@ -643,6 +643,7 @@ xfs_dir2_block_lookup_int( | |||
643 | int mid; /* binary search current idx */ | 643 | int mid; /* binary search current idx */ |
644 | xfs_mount_t *mp; /* filesystem mount point */ | 644 | xfs_mount_t *mp; /* filesystem mount point */ |
645 | xfs_trans_t *tp; /* transaction pointer */ | 645 | xfs_trans_t *tp; /* transaction pointer */ |
646 | enum xfs_dacmp cmp; /* comparison result */ | ||
646 | 647 | ||
647 | dp = args->dp; | 648 | dp = args->dp; |
648 | tp = args->trans; | 649 | tp = args->trans; |
@@ -697,20 +698,31 @@ xfs_dir2_block_lookup_int( | |||
697 | dep = (xfs_dir2_data_entry_t *) | 698 | dep = (xfs_dir2_data_entry_t *) |
698 | ((char *)block + xfs_dir2_dataptr_to_off(mp, addr)); | 699 | ((char *)block + xfs_dir2_dataptr_to_off(mp, addr)); |
699 | /* | 700 | /* |
700 | * Compare, if it's right give back buffer & entry number. | 701 | * Compare name and if it's an exact match, return the index |
702 | * and buffer. If it's the first case-insensitive match, store | ||
703 | * the index and buffer and continue looking for an exact match. | ||
701 | */ | 704 | */ |
702 | if (dep->namelen == args->namelen && | 705 | cmp = mp->m_dirnameops->compname(args, dep->name, dep->namelen); |
703 | dep->name[0] == args->name[0] && | 706 | if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) { |
704 | memcmp(dep->name, args->name, args->namelen) == 0) { | 707 | args->cmpresult = cmp; |
705 | *bpp = bp; | 708 | *bpp = bp; |
706 | *entno = mid; | 709 | *entno = mid; |
707 | return 0; | 710 | if (cmp == XFS_CMP_EXACT) |
711 | return 0; | ||
708 | } | 712 | } |
709 | } while (++mid < be32_to_cpu(btp->count) && be32_to_cpu(blp[mid].hashval) == hash); | 713 | } while (++mid < be32_to_cpu(btp->count) && |
714 | be32_to_cpu(blp[mid].hashval) == hash); | ||
715 | |||
716 | ASSERT(args->oknoent); | ||
717 | /* | ||
718 | * Here, we can only be doing a lookup (not a rename or replace). | ||
719 | * If a case-insensitive match was found earlier, return success. | ||
720 | */ | ||
721 | if (args->cmpresult == XFS_CMP_CASE) | ||
722 | return 0; | ||
710 | /* | 723 | /* |
711 | * No match, release the buffer and return ENOENT. | 724 | * No match, release the buffer and return ENOENT. |
712 | */ | 725 | */ |
713 | ASSERT(args->oknoent); | ||
714 | xfs_da_brelse(tp, bp); | 726 | xfs_da_brelse(tp, bp); |
715 | return XFS_ERROR(ENOENT); | 727 | return XFS_ERROR(ENOENT); |
716 | } | 728 | } |
@@ -1033,6 +1045,7 @@ xfs_dir2_sf_to_block( | |||
1033 | xfs_dir2_sf_t *sfp; /* shortform structure */ | 1045 | xfs_dir2_sf_t *sfp; /* shortform structure */ |
1034 | __be16 *tagp; /* end of data entry */ | 1046 | __be16 *tagp; /* end of data entry */ |
1035 | xfs_trans_t *tp; /* transaction pointer */ | 1047 | xfs_trans_t *tp; /* transaction pointer */ |
1048 | struct xfs_name name; | ||
1036 | 1049 | ||
1037 | xfs_dir2_trace_args("sf_to_block", args); | 1050 | xfs_dir2_trace_args("sf_to_block", args); |
1038 | dp = args->dp; | 1051 | dp = args->dp; |
@@ -1187,8 +1200,10 @@ xfs_dir2_sf_to_block( | |||
1187 | tagp = xfs_dir2_data_entry_tag_p(dep); | 1200 | tagp = xfs_dir2_data_entry_tag_p(dep); |
1188 | *tagp = cpu_to_be16((char *)dep - (char *)block); | 1201 | *tagp = cpu_to_be16((char *)dep - (char *)block); |
1189 | xfs_dir2_data_log_entry(tp, bp, dep); | 1202 | xfs_dir2_data_log_entry(tp, bp, dep); |
1190 | blp[2 + i].hashval = cpu_to_be32(xfs_da_hashname( | 1203 | name.name = sfep->name; |
1191 | (char *)sfep->name, sfep->namelen)); | 1204 | name.len = sfep->namelen; |
1205 | blp[2 + i].hashval = cpu_to_be32(mp->m_dirnameops-> | ||
1206 | hashname(&name)); | ||
1192 | blp[2 + i].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp, | 1207 | blp[2 + i].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(mp, |
1193 | (char *)dep - (char *)block)); | 1208 | (char *)dep - (char *)block)); |
1194 | offset = (int)((char *)(tagp + 1) - (char *)block); | 1209 | offset = (int)((char *)(tagp + 1) - (char *)block); |