aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_dir2_sf.c
diff options
context:
space:
mode:
authorBarry Naujok <bnaujok@sgi.com>2008-05-21 02:41:01 -0400
committerNiv Sardi <xaiki@debian.org>2008-07-28 02:58:36 -0400
commit5163f95a08cbf058ae16452c2242c5600fedc32e (patch)
tree5d6b905f7031144a62fb1fa17ba3106d99268003 /fs/xfs/xfs_dir2_sf.c
parent68f34d5107dbace3d14a1c2f060fc8941894879c (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_sf.c')
-rw-r--r--fs/xfs/xfs_dir2_sf.c62
1 files changed, 36 insertions, 26 deletions
diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
index ca33bc62edc2..dcd09cada43f 100644
--- a/fs/xfs/xfs_dir2_sf.c
+++ b/fs/xfs/xfs_dir2_sf.c
@@ -814,6 +814,7 @@ xfs_dir2_sf_lookup(
814 int i; /* entry index */ 814 int i; /* entry index */
815 xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */ 815 xfs_dir2_sf_entry_t *sfep; /* shortform directory entry */
816 xfs_dir2_sf_t *sfp; /* shortform structure */ 816 xfs_dir2_sf_t *sfp; /* shortform structure */
817 enum xfs_dacmp cmp; /* comparison result */
817 818
818 xfs_dir2_trace_args("sf_lookup", args); 819 xfs_dir2_trace_args("sf_lookup", args);
819 xfs_dir2_sf_check(args); 820 xfs_dir2_sf_check(args);
@@ -836,6 +837,7 @@ xfs_dir2_sf_lookup(
836 */ 837 */
837 if (args->namelen == 1 && args->name[0] == '.') { 838 if (args->namelen == 1 && args->name[0] == '.') {
838 args->inumber = dp->i_ino; 839 args->inumber = dp->i_ino;
840 args->cmpresult = XFS_CMP_EXACT;
839 return XFS_ERROR(EEXIST); 841 return XFS_ERROR(EEXIST);
840 } 842 }
841 /* 843 /*
@@ -844,27 +846,39 @@ xfs_dir2_sf_lookup(
844 if (args->namelen == 2 && 846 if (args->namelen == 2 &&
845 args->name[0] == '.' && args->name[1] == '.') { 847 args->name[0] == '.' && args->name[1] == '.') {
846 args->inumber = xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent); 848 args->inumber = xfs_dir2_sf_get_inumber(sfp, &sfp->hdr.parent);
849 args->cmpresult = XFS_CMP_EXACT;
847 return XFS_ERROR(EEXIST); 850 return XFS_ERROR(EEXIST);
848 } 851 }
849 /* 852 /*
850 * Loop over all the entries trying to match ours. 853 * Loop over all the entries trying to match ours.
851 */ 854 */
852 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); 855 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); i < sfp->hdr.count;
853 i < sfp->hdr.count; 856 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) {
854 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) { 857 /*
855 if (sfep->namelen == args->namelen && 858 * Compare name and if it's an exact match, return the inode
856 sfep->name[0] == args->name[0] && 859 * number. If it's the first case-insensitive match, store the
857 memcmp(args->name, sfep->name, args->namelen) == 0) { 860 * inode number and continue looking for an exact match.
858 args->inumber = 861 */
859 xfs_dir2_sf_get_inumber(sfp, 862 cmp = dp->i_mount->m_dirnameops->compname(args, sfep->name,
860 xfs_dir2_sf_inumberp(sfep)); 863 sfep->namelen);
861 return XFS_ERROR(EEXIST); 864 if (cmp != XFS_CMP_DIFFERENT && cmp != args->cmpresult) {
865 args->cmpresult = cmp;
866 args->inumber = xfs_dir2_sf_get_inumber(sfp,
867 xfs_dir2_sf_inumberp(sfep));
868 if (cmp == XFS_CMP_EXACT)
869 return XFS_ERROR(EEXIST);
862 } 870 }
863 } 871 }
872 ASSERT(args->oknoent);
873 /*
874 * Here, we can only be doing a lookup (not a rename or replace).
875 * If a case-insensitive match was found earlier, return "found".
876 */
877 if (args->cmpresult == XFS_CMP_CASE)
878 return XFS_ERROR(EEXIST);
864 /* 879 /*
865 * Didn't find it. 880 * Didn't find it.
866 */ 881 */
867 ASSERT(args->oknoent);
868 return XFS_ERROR(ENOENT); 882 return XFS_ERROR(ENOENT);
869} 883}
870 884
@@ -904,24 +918,21 @@ xfs_dir2_sf_removename(
904 * Loop over the old directory entries. 918 * Loop over the old directory entries.
905 * Find the one we're deleting. 919 * Find the one we're deleting.
906 */ 920 */
907 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); 921 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); i < sfp->hdr.count;
908 i < sfp->hdr.count; 922 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) {
909 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) { 923 if (xfs_da_compname(args, sfep->name, sfep->namelen) ==
910 if (sfep->namelen == args->namelen && 924 XFS_CMP_EXACT) {
911 sfep->name[0] == args->name[0] &&
912 memcmp(sfep->name, args->name, args->namelen) == 0) {
913 ASSERT(xfs_dir2_sf_get_inumber(sfp, 925 ASSERT(xfs_dir2_sf_get_inumber(sfp,
914 xfs_dir2_sf_inumberp(sfep)) == 926 xfs_dir2_sf_inumberp(sfep)) ==
915 args->inumber); 927 args->inumber);
916 break; 928 break;
917 } 929 }
918 } 930 }
919 /* 931 /*
920 * Didn't find it. 932 * Didn't find it.
921 */ 933 */
922 if (i == sfp->hdr.count) { 934 if (i == sfp->hdr.count)
923 return XFS_ERROR(ENOENT); 935 return XFS_ERROR(ENOENT);
924 }
925 /* 936 /*
926 * Calculate sizes. 937 * Calculate sizes.
927 */ 938 */
@@ -1042,11 +1053,10 @@ xfs_dir2_sf_replace(
1042 */ 1053 */
1043 else { 1054 else {
1044 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); 1055 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp);
1045 i < sfp->hdr.count; 1056 i < sfp->hdr.count;
1046 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) { 1057 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) {
1047 if (sfep->namelen == args->namelen && 1058 if (xfs_da_compname(args, sfep->name, sfep->namelen) ==
1048 sfep->name[0] == args->name[0] && 1059 XFS_CMP_EXACT) {
1049 memcmp(args->name, sfep->name, args->namelen) == 0) {
1050#if XFS_BIG_INUMS || defined(DEBUG) 1060#if XFS_BIG_INUMS || defined(DEBUG)
1051 ino = xfs_dir2_sf_get_inumber(sfp, 1061 ino = xfs_dir2_sf_get_inumber(sfp,
1052 xfs_dir2_sf_inumberp(sfep)); 1062 xfs_dir2_sf_inumberp(sfep));