@@ -698,47 +698,24 @@ xfs_attr_shortform_create(
698
698
}
699
699
700
700
/*
701
- * Return -EEXIST if attr is found, or -ENOATTR if not
702
- * args: args containing attribute name and namelen
703
- * sfep: If not null, pointer will be set to the last attr entry found on
704
- -EEXIST. On -ENOATTR pointer is left at the last entry in the list
705
- * basep: If not null, pointer is set to the byte offset of the entry in the
706
- * list on -EEXIST. On -ENOATTR, pointer is left at the byte offset of
707
- * the last entry in the list
701
+ * Return the entry if the attr in args is found, or NULL if not.
708
702
*/
709
- int
703
+ struct xfs_attr_sf_entry *
710
704
xfs_attr_sf_findname (
711
- struct xfs_da_args * args ,
712
- struct xfs_attr_sf_entry * * sfep ,
713
- unsigned int * basep )
705
+ struct xfs_da_args * args )
714
706
{
715
- struct xfs_attr_shortform * sf = args -> dp -> i_af .if_data ;
716
- struct xfs_attr_sf_entry * sfe ;
717
- unsigned int base = sizeof (struct xfs_attr_sf_hdr );
718
- int size = 0 ;
719
- int end ;
720
- int i ;
707
+ struct xfs_attr_shortform * sf = args -> dp -> i_af .if_data ;
708
+ struct xfs_attr_sf_entry * sfe ;
721
709
722
- sfe = & sf -> list [0 ];
723
- end = sf -> hdr .count ;
724
- for (i = 0 ; i < end ; sfe = xfs_attr_sf_nextentry (sfe ),
725
- base += size , i ++ ) {
726
- size = xfs_attr_sf_entsize (sfe );
727
- if (!xfs_attr_match (args , sfe -> namelen , sfe -> nameval ,
728
- sfe -> flags ))
729
- continue ;
730
- break ;
710
+ for (sfe = & sf -> list [0 ];
711
+ sfe < xfs_attr_sf_endptr (sf );
712
+ sfe = xfs_attr_sf_nextentry (sfe )) {
713
+ if (xfs_attr_match (args , sfe -> namelen , sfe -> nameval ,
714
+ sfe -> flags ))
715
+ return sfe ;
731
716
}
732
717
733
- if (sfep != NULL )
734
- * sfep = sfe ;
735
-
736
- if (basep != NULL )
737
- * basep = base ;
738
-
739
- if (i == end )
740
- return - ENOATTR ;
741
- return - EEXIST ;
718
+ return NULL ;
742
719
}
743
720
744
721
/*
@@ -755,21 +732,19 @@ xfs_attr_shortform_add(
755
732
struct xfs_ifork * ifp = & dp -> i_af ;
756
733
struct xfs_attr_shortform * sf = ifp -> if_data ;
757
734
struct xfs_attr_sf_entry * sfe ;
758
- int offset , size ;
735
+ int size ;
759
736
760
737
trace_xfs_attr_sf_add (args );
761
738
762
739
dp -> i_forkoff = forkoff ;
763
740
764
741
ASSERT (ifp -> if_format == XFS_DINODE_FMT_LOCAL );
765
- if (xfs_attr_sf_findname (args , & sfe , NULL ) == - EEXIST )
766
- ASSERT (0 );
742
+ ASSERT (!xfs_attr_sf_findname (args ));
767
743
768
- offset = (char * )sfe - (char * )sf ;
769
744
size = xfs_attr_sf_entsize_byname (args -> namelen , args -> valuelen );
770
745
sf = xfs_idata_realloc (dp , size , XFS_ATTR_FORK );
771
- sfe = (struct xfs_attr_sf_entry * )((char * )sf + offset );
772
746
747
+ sfe = xfs_attr_sf_endptr (sf );
773
748
sfe -> namelen = args -> namelen ;
774
749
sfe -> valuelen = args -> valuelen ;
775
750
sfe -> flags = args -> attr_filter ;
@@ -809,39 +784,38 @@ xfs_attr_sf_removename(
809
784
struct xfs_mount * mp = dp -> i_mount ;
810
785
struct xfs_attr_shortform * sf = dp -> i_af .if_data ;
811
786
struct xfs_attr_sf_entry * sfe ;
812
- int size = 0 , end , totsize ;
813
- unsigned int base ;
814
- int error ;
787
+ uint16_t totsize = be16_to_cpu ( sf -> hdr . totsize ) ;
788
+ void * next , * end ;
789
+ int size = 0 ;
815
790
816
791
trace_xfs_attr_sf_remove (args );
817
792
818
- error = xfs_attr_sf_findname (args , & sfe , & base );
819
-
820
- /*
821
- * If we are recovering an operation, finding nothing to
822
- * remove is not an error - it just means there was nothing
823
- * to clean up.
824
- */
825
- if (error == - ENOATTR && (args -> op_flags & XFS_DA_OP_RECOVERY ))
826
- return 0 ;
827
- if (error != - EEXIST )
828
- return error ;
829
- size = xfs_attr_sf_entsize (sfe );
793
+ sfe = xfs_attr_sf_findname (args );
794
+ if (!sfe ) {
795
+ /*
796
+ * If we are recovering an operation, finding nothing to remove
797
+ * is not an error, it just means there was nothing to clean up.
798
+ */
799
+ if (args -> op_flags & XFS_DA_OP_RECOVERY )
800
+ return 0 ;
801
+ return - ENOATTR ;
802
+ }
830
803
831
804
/*
832
805
* Fix up the attribute fork data, covering the hole
833
806
*/
834
- end = base + size ;
835
- totsize = be16_to_cpu (sf -> hdr .totsize );
836
- if (end != totsize )
837
- memmove (& ((char * )sf )[base ], & ((char * )sf )[end ], totsize - end );
807
+ size = xfs_attr_sf_entsize (sfe );
808
+ next = xfs_attr_sf_nextentry (sfe );
809
+ end = xfs_attr_sf_endptr (sf );
810
+ if (next < end )
811
+ memmove (sfe , next , end - next );
838
812
sf -> hdr .count -- ;
839
- be16_add_cpu (& sf -> hdr .totsize , - size );
813
+ totsize -= size ;
814
+ sf -> hdr .totsize = cpu_to_be16 (totsize );
840
815
841
816
/*
842
817
* Fix up the start offset of the attribute fork
843
818
*/
844
- totsize -= size ;
845
819
if (totsize == sizeof (xfs_attr_sf_hdr_t ) && xfs_has_attr2 (mp ) &&
846
820
(dp -> i_df .if_format != XFS_DINODE_FMT_BTREE ) &&
847
821
!(args -> op_flags & (XFS_DA_OP_ADDNAME | XFS_DA_OP_REPLACE ))) {
0 commit comments