~ubuntu-branches/ubuntu/edgy/xfsprogs/edgy

« back to all changes in this revision

Viewing changes to libxfs/xfs_dir2_block.c

  • Committer: Bazaar Package Importer
  • Author(s): Nathan Scott
  • Date: 2005-11-16 16:32:35 UTC
  • Revision ID: james.westby@ubuntu.com-20051116163235-synnef6xjj18ny42
Tags: 2.7.7-1
* New upstream release.
* Add support for (optional) ATTR2 format extension (closes: #336350)
* Allow gcc -pedantic option for C++ <xfs.h> users (closes: #249429)
* Fix segv in xfs_db frag command (closes: #338207)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
 
2
 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
 
3
 * All Rights Reserved.
3
4
 *
4
 
 * This program is free software; you can redistribute it and/or modify it
5
 
 * under the terms of version 2 of the GNU General Public License as
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License as
6
7
 * published by the Free Software Foundation.
7
8
 *
8
 
 * This program is distributed in the hope that it would be useful, but
9
 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 
 *
12
 
 * Further, this software is distributed without any warranty that it is
13
 
 * free of the rightful claim of any third person regarding infringement
14
 
 * or the like.  Any license provided herein, whether implied or
15
 
 * otherwise, applies only to this software file.  Patent licenses, if
16
 
 * any, provided herein do not apply to combinations of this program with
17
 
 * other software, or any other product whatsoever.
18
 
 *
19
 
 * You should have received a copy of the GNU General Public License along
20
 
 * with this program; if not, write the Free Software Foundation, Inc., 59
21
 
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22
 
 *
23
 
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24
 
 * Mountain View, CA  94043, or:
25
 
 *
26
 
 * http://www.sgi.com
27
 
 *
28
 
 * For further information regarding this notice, see:
29
 
 *
30
 
 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
 
9
 * This program is distributed in the hope that it would be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write the Free Software Foundation,
 
16
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
31
17
 */
32
18
 
33
19
/*
100
86
         */
101
87
        bf = block->hdr.bestfree;
102
88
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
103
 
        blp = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
 
89
        blp = XFS_DIR2_BLOCK_LEAF_P(btp);
104
90
        /*
105
91
         * No stale entries?  Need space for entry and new leaf.
106
92
         */
107
 
        if (INT_ISZERO(btp->stale, ARCH_CONVERT)) {
 
93
        if (!btp->stale) {
108
94
                /*
109
95
                 * Tag just before the first leaf entry.
110
96
                 */
292
278
        /*
293
279
         * No stale entries, will use enddup space to hold new leaf.
294
280
         */
295
 
        if (INT_ISZERO(btp->stale, ARCH_CONVERT)) {
 
281
        if (!btp->stale) {
296
282
                /*
297
283
                 * Mark the space needed for the new leaf entry, now in use.
298
284
                 */
425
411
        mp = tp->t_mountp;
426
412
        block = bp->data;
427
413
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
428
 
        blp = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
 
414
        blp = XFS_DIR2_BLOCK_LEAF_P(btp);
429
415
        xfs_da_log_buf(tp, bp, (uint)((char *)&blp[first] - (char *)block),
430
416
                (uint)((char *)&blp[last + 1] - (char *)block - 1));
431
417
}
479
465
        block = bp->data;
480
466
        xfs_dir2_data_check(dp, bp);
481
467
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
482
 
        blp = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
 
468
        blp = XFS_DIR2_BLOCK_LEAF_P(btp);
483
469
        /*
484
470
         * Get the offset from the leaf entry, to point to the data.
485
471
         */
531
517
        block = bp->data;
532
518
        xfs_dir2_data_check(dp, bp);
533
519
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
534
 
        blp = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
 
520
        blp = XFS_DIR2_BLOCK_LEAF_P(btp);
535
521
        /*
536
522
         * Loop doing a binary search for our hash value.
537
523
         * Find our entry, ENOENT if it's not there.
624
610
        mp = dp->i_mount;
625
611
        block = bp->data;
626
612
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
627
 
        blp = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
 
613
        blp = XFS_DIR2_BLOCK_LEAF_P(btp);
628
614
        /*
629
615
         * Point to the data entry using the leaf entry.
630
616
         */
700
686
        mp = dp->i_mount;
701
687
        block = bp->data;
702
688
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
703
 
        blp = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
 
689
        blp = XFS_DIR2_BLOCK_LEAF_P(btp);
704
690
        /*
705
691
         * Point to the data entry we need to change.
706
692
         */
776
762
         * These will show up in the leaf bests table.
777
763
         */
778
764
        while (dp->i_d.di_size > mp->m_dirblksize) {
779
 
                bestsp = XFS_DIR2_LEAF_BESTS_P_ARCH(ltp, ARCH_CONVERT);
 
765
                bestsp = XFS_DIR2_LEAF_BESTS_P(ltp);
780
766
                if (INT_GET(bestsp[INT_GET(ltp->bestcount, ARCH_CONVERT) - 1], ARCH_CONVERT) ==
781
767
                    mp->m_dirblksize - (uint)sizeof(block->hdr)) {
782
768
                        if ((error =
831
817
         */
832
818
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
833
819
        INT_SET(btp->count, ARCH_CONVERT, INT_GET(leaf->hdr.count, ARCH_CONVERT) - INT_GET(leaf->hdr.stale, ARCH_CONVERT));
834
 
        INT_ZERO(btp->stale, ARCH_CONVERT);
 
820
        btp->stale = 0;
835
821
        xfs_dir2_block_log_tail(tp, dbp);
836
822
        /*
837
823
         * Initialize the block leaf area.  We compact out stale entries.
838
824
         */
839
 
        lep = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
 
825
        lep = XFS_DIR2_BLOCK_LEAF_P(btp);
840
826
        for (from = to = 0; from < INT_GET(leaf->hdr.count, ARCH_CONVERT); from++) {
841
827
                if (INT_GET(leaf->ents[from].address, ARCH_CONVERT) == XFS_DIR2_NULL_DATAPTR)
842
828
                        continue;
977
963
         */
978
964
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
979
965
        INT_SET(btp->count, ARCH_CONVERT, INT_GET(sfp->hdr.count, ARCH_CONVERT) + 2);   /* ., .. */
980
 
        INT_ZERO(btp->stale, ARCH_CONVERT);
981
 
        blp = XFS_DIR2_BLOCK_LEAF_P_ARCH(btp, ARCH_CONVERT);
 
966
        btp->stale = 0;
 
967
        blp = XFS_DIR2_BLOCK_LEAF_P(btp);
982
968
        endoffset = (uint)((char *)blp - (char *)block);
983
969
        /*
984
970
         * Remove the freespace, we'll manage it.
1004
990
         */
1005
991
        dep = (xfs_dir2_data_entry_t *)
1006
992
                ((char *)block + XFS_DIR2_DATA_DOTDOT_OFFSET);
1007
 
        INT_SET(dep->inumber, ARCH_CONVERT, XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, &sfp->hdr.parent, ARCH_CONVERT));
 
993
        INT_SET(dep->inumber, ARCH_CONVERT, XFS_DIR2_SF_GET_INUMBER(sfp, &sfp->hdr.parent));
1008
994
        dep->namelen = 2;
1009
995
        dep->name[0] = dep->name[1] = '.';
1010
996
        tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
1031
1017
                if (sfep == NULL)
1032
1018
                        newoffset = endoffset;
1033
1019
                else
1034
 
                        newoffset = XFS_DIR2_SF_GET_OFFSET_ARCH(sfep, ARCH_CONVERT);
 
1020
                        newoffset = XFS_DIR2_SF_GET_OFFSET(sfep);
1035
1021
                /*
1036
1022
                 * There should be a hole here, make one.
1037
1023
                 */
1040
1026
                              ((char *)block + offset);
1041
1027
                        INT_SET(dup->freetag, ARCH_CONVERT, XFS_DIR2_DATA_FREE_TAG);
1042
1028
                        INT_SET(dup->length, ARCH_CONVERT, newoffset - offset);
1043
 
                        INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P_ARCH(dup, ARCH_CONVERT), ARCH_CONVERT,
 
1029
                        INT_SET(*XFS_DIR2_DATA_UNUSED_TAG_P(dup), ARCH_CONVERT,
1044
1030
                                (xfs_dir2_data_off_t)
1045
1031
                                ((char *)dup - (char *)block));
1046
1032
                        xfs_dir2_data_log_unused(tp, bp, dup);
1053
1039
                 * Copy a real entry.
1054
1040
                 */
1055
1041
                dep = (xfs_dir2_data_entry_t *)((char *)block + newoffset);
1056
 
                INT_SET(dep->inumber, ARCH_CONVERT, XFS_DIR2_SF_GET_INUMBER_ARCH(sfp,
1057
 
                                XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT));
 
1042
                INT_SET(dep->inumber, ARCH_CONVERT, XFS_DIR2_SF_GET_INUMBER(sfp,
 
1043
                                XFS_DIR2_SF_INUMBERP(sfep)));
1058
1044
                dep->namelen = sfep->namelen;
1059
1045
                memcpy(dep->name, sfep->name, dep->namelen);
1060
1046
                tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
1074
1060
        /*
1075
1061
         * Sort the leaf entries by hash value.
1076
1062
         */
1077
 
        qsort(blp, INT_GET(btp->count, ARCH_CONVERT), sizeof(*blp), xfs_dir2_block_sort);
 
1063
        xfs_sort(blp, INT_GET(btp->count, ARCH_CONVERT), sizeof(*blp), xfs_dir2_block_sort);
1078
1064
        /*
1079
1065
         * Log the leaf entry area and tail.
1080
1066
         * Already logged the header in data_init, ignore needlog.