~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: 2004-07-28 21:11:38 UTC
  • Revision ID: james.westby@ubuntu.com-20040728211138-0v4pdnunnp7na5lm
Tags: 2.6.20-1
* New upstream release.
* Fix xfs_io segfault on non-XFS files.  (closes: #260470)
* Fix packaging botch, deleted files included.  (closes: #260491)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
3
 
 * 
 
2
 * Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
 
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify it
5
5
 * under the terms of version 2 of the GNU General Public License as
6
6
 * published by the Free Software Foundation.
7
 
 * 
 
7
 *
8
8
 * This program is distributed in the hope that it would be useful, but
9
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 
 * 
 
11
 *
12
12
 * Further, this software is distributed without any warranty that it is
13
13
 * free of the rightful claim of any third person regarding infringement
14
14
 * or the like.  Any license provided herein, whether implied or
15
15
 * otherwise, applies only to this software file.  Patent licenses, if
16
16
 * any, provided herein do not apply to combinations of this program with
17
17
 * other software, or any other product whatsoever.
18
 
 * 
 
18
 *
19
19
 * You should have received a copy of the GNU General Public License along
20
20
 * with this program; if not, write the Free Software Foundation, Inc., 59
21
21
 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
22
 
 * 
 
22
 *
23
23
 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24
24
 * Mountain View, CA  94043, or:
25
 
 * 
26
 
 * http://www.sgi.com 
27
 
 * 
28
 
 * For further information regarding this notice, see: 
29
 
 * 
 
25
 *
 
26
 * http://www.sgi.com
 
27
 *
 
28
 * For further information regarding this notice, see:
 
29
 *
30
30
 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31
31
 */
32
32
 
87
87
        /*
88
88
         * Check the magic number, corrupted if wrong.
89
89
         */
90
 
        if (INT_GET(block->hdr.magic, ARCH_CONVERT) != XFS_DIR2_BLOCK_MAGIC) {
 
90
        if (unlikely(INT_GET(block->hdr.magic, ARCH_CONVERT)
 
91
                                                != XFS_DIR2_BLOCK_MAGIC)) {
 
92
                XFS_CORRUPTION_ERROR("xfs_dir2_block_addname",
 
93
                                     XFS_ERRLEVEL_LOW, mp, block);
91
94
                xfs_da_brelse(tp, bp);
92
95
                return XFS_ERROR(EFSCORRUPTED);
93
96
        }
101
104
        /*
102
105
         * No stale entries?  Need space for entry and new leaf.
103
106
         */
104
 
        if (INT_GET(btp->stale, ARCH_CONVERT) == 0) {
 
107
        if (INT_ISZERO(btp->stale, ARCH_CONVERT)) {
105
108
                /*
106
109
                 * Tag just before the first leaf entry.
107
110
                 */
289
292
        /*
290
293
         * No stale entries, will use enddup space to hold new leaf.
291
294
         */
292
 
        if (INT_GET(btp->stale, ARCH_CONVERT) == 0) {
 
295
        if (INT_ISZERO(btp->stale, ARCH_CONVERT)) {
293
296
                /*
294
297
                 * Mark the space needed for the new leaf entry, now in use.
295
298
                 */
320
323
                blp--;
321
324
                mid++;
322
325
                if (mid)
323
 
                        ovbcopy(&blp[1], blp, mid * sizeof(*blp));
 
326
                        memmove(blp, &blp[1], mid * sizeof(*blp));
324
327
                lfloglow = 0;
325
328
                lfloghigh = mid;
326
329
        }
346
349
                    (highstale == INT_GET(btp->count, ARCH_CONVERT) ||
347
350
                     mid - lowstale <= highstale - mid)) {
348
351
                        if (mid - lowstale)
349
 
                                ovbcopy(&blp[lowstale + 1], &blp[lowstale],
 
352
                                memmove(&blp[lowstale], &blp[lowstale + 1],
350
353
                                        (mid - lowstale) * sizeof(*blp));
351
354
                        lfloglow = MIN(lowstale, lfloglow);
352
355
                        lfloghigh = MAX(mid, lfloghigh);
358
361
                        ASSERT(highstale < INT_GET(btp->count, ARCH_CONVERT));
359
362
                        mid++;
360
363
                        if (highstale - mid)
361
 
                                ovbcopy(&blp[mid], &blp[mid + 1],
 
364
                                memmove(&blp[mid + 1], &blp[mid],
362
365
                                        (highstale - mid) * sizeof(*blp));
363
366
                        lfloglow = MIN(mid, lfloglow);
364
367
                        lfloghigh = MAX(highstale, lfloghigh);
386
389
         */
387
390
        INT_SET(dep->inumber, ARCH_CONVERT, args->inumber);
388
391
        dep->namelen = args->namelen;
389
 
        bcopy(args->name, dep->name, args->namelen);
 
392
        memcpy(dep->name, args->name, args->namelen);
390
393
        tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
391
394
        INT_SET(*tagp, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dep - (char *)block));
392
395
        /*
571
574
                 */
572
575
                if (dep->namelen == args->namelen &&
573
576
                    dep->name[0] == args->name[0] &&
574
 
                    bcmp(dep->name, args->name, args->namelen) == 0) {
 
577
                    memcmp(dep->name, args->name, args->namelen) == 0) {
575
578
                        *bpp = bp;
576
579
                        *entno = mid;
577
580
                        return 0;
828
831
         */
829
832
        btp = XFS_DIR2_BLOCK_TAIL_P(mp, block);
830
833
        INT_SET(btp->count, ARCH_CONVERT, INT_GET(leaf->hdr.count, ARCH_CONVERT) - INT_GET(leaf->hdr.stale, ARCH_CONVERT));
831
 
        INT_SET(btp->stale, ARCH_CONVERT, 0);
 
834
        INT_ZERO(btp->stale, ARCH_CONVERT);
832
835
        xfs_dir2_block_log_tail(tp, dbp);
833
836
        /*
834
837
         * Initialize the block leaf area.  We compact out stale entries.
886
889
        xfs_dir2_leaf_entry_t   *blp;           /* block leaf entries */
887
890
        xfs_dabuf_t             *bp;            /* block buffer */
888
891
        xfs_dir2_block_tail_t   *btp;           /* block tail pointer */
889
 
        char                    buf[XFS_DIR2_SF_MAX_SIZE];      /* sf buffer */
 
892
        char                    *buf;           /* sf buffer */
 
893
        int                     buf_len;
890
894
        xfs_dir2_data_entry_t   *dep;           /* data entry pointer */
891
895
        xfs_inode_t             *dp;            /* incore directory inode */
892
896
        int                     dummy;          /* trash */
924
928
         * Copy the directory into the stack buffer.
925
929
         * Then pitch the incore inode data so we can make extents.
926
930
         */
927
 
        bcopy(sfp, buf, dp->i_df.if_bytes);
 
931
 
 
932
        buf_len = dp->i_df.if_bytes;
 
933
        buf = kmem_alloc(dp->i_df.if_bytes, KM_SLEEP);
 
934
 
 
935
        memcpy(buf, sfp, dp->i_df.if_bytes);
928
936
        xfs_idata_realloc(dp, -dp->i_df.if_bytes, XFS_DATA_FORK);
929
937
        dp->i_d.di_size = 0;
930
938
        xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE);
937
945
         */
938
946
        error = xfs_dir2_grow_inode(args, XFS_DIR2_DATA_SPACE, &blkno);
939
947
        if (error) {
 
948
                kmem_free(buf, buf_len);
940
949
                return error;
941
950
        }
942
951
        /*
944
953
         */
945
954
        error = xfs_dir2_data_init(args, blkno, &bp);
946
955
        if (error) {
 
956
                kmem_free(buf, buf_len);
947
957
                return error;
948
958
        }
949
959
        block = bp->data;
1046
1056
                INT_SET(dep->inumber, ARCH_CONVERT, XFS_DIR2_SF_GET_INUMBER_ARCH(sfp,
1047
1057
                                XFS_DIR2_SF_INUMBERP(sfep), ARCH_CONVERT));
1048
1058
                dep->namelen = sfep->namelen;
1049
 
                bcopy(sfep->name, dep->name, dep->namelen);
 
1059
                memcpy(dep->name, sfep->name, dep->namelen);
1050
1060
                tagp = XFS_DIR2_DATA_ENTRY_TAG_P(dep);
1051
1061
                INT_SET(*tagp, ARCH_CONVERT, (xfs_dir2_data_off_t)((char *)dep - (char *)block));
1052
1062
                xfs_dir2_data_log_entry(tp, bp, dep);
1059
1069
                else
1060
1070
                        sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep);
1061
1071
        }
 
1072
        /* Done with the temporary buffer */
 
1073
        kmem_free(buf, buf_len);
1062
1074
        /*
1063
1075
         * Sort the leaf entries by hash value.
1064
1076
         */
1065
1077
        qsort(blp, INT_GET(btp->count, ARCH_CONVERT), sizeof(*blp), xfs_dir2_block_sort);
1066
 
        /* 
 
1078
        /*
1067
1079
         * Log the leaf entry area and tail.
1068
1080
         * Already logged the header in data_init, ignore needlog.
1069
1081
         */