2
* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
2
* Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
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.
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.
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.
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.
23
23
* Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24
24
* Mountain View, CA 94043, or:
28
* For further information regarding this notice, see:
28
* For further information regarding this notice, see:
30
30
* http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
88
88
* Check the magic number, corrupted if wrong.
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);
102
105
* No stale entries? Need space for entry and new leaf.
104
if (INT_GET(btp->stale, ARCH_CONVERT) == 0) {
107
if (INT_ISZERO(btp->stale, ARCH_CONVERT)) {
106
109
* Tag just before the first leaf entry.
290
293
* No stale entries, will use enddup space to hold new leaf.
292
if (INT_GET(btp->stale, ARCH_CONVERT) == 0) {
295
if (INT_ISZERO(btp->stale, ARCH_CONVERT)) {
294
297
* Mark the space needed for the new leaf entry, now in use.
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));
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);
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));
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) {
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);
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 */
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.
927
bcopy(sfp, buf, dp->i_df.if_bytes);
932
buf_len = dp->i_df.if_bytes;
933
buf = kmem_alloc(dp->i_df.if_bytes, KM_SLEEP);
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);
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);
1060
1070
sfep = XFS_DIR2_SF_NEXTENTRY(sfp, sfep);
1072
/* Done with the temporary buffer */
1073
kmem_free(buf, buf_len);
1063
1075
* Sort the leaf entries by hash value.
1065
1077
qsort(blp, INT_GET(btp->count, ARCH_CONVERT), sizeof(*blp), xfs_dir2_block_sort);
1067
1079
* Log the leaf entry area and tail.
1068
1080
* Already logged the header in data_init, ignore needlog.