2 * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
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
7 * published by the Free Software Foundation.
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.
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
19 #include <xfs/libxfs.h>
37 IS_USER_QUOTA
, IS_PROJECT_QUOTA
, IS_GROUP_QUOTA
,
41 DBM_UNKNOWN
, DBM_AGF
, DBM_AGFL
, DBM_AGI
,
42 DBM_ATTR
, DBM_BTBMAPA
, DBM_BTBMAPD
, DBM_BTBNO
,
43 DBM_BTCNT
, DBM_BTINO
, DBM_DATA
, DBM_DIR
,
44 DBM_FREE1
, DBM_FREE2
, DBM_FREELIST
, DBM_INODE
,
45 DBM_LOG
, DBM_MISSING
, DBM_QUOTA
, DBM_RTBITMAP
,
46 DBM_RTDATA
, DBM_RTFREE
, DBM_RTSUM
, DBM_SB
,
51 typedef struct inodata
{
59 struct inodata
*parent
;
62 #define MIN_INODATA_HASH_SIZE 256
63 #define MAX_INODATA_HASH_SIZE 65536
64 #define INODATA_AVG_HASH_LENGTH 8
66 typedef struct qinfo
{
72 #define QDATA_HASH_SIZE 256
73 typedef struct qdata
{
80 typedef struct blkent
{
81 xfs_fileoff_t startoff
;
83 xfs_fsblock_t blks
[1];
85 #define BLKENT_SIZE(n) \
86 (offsetof(blkent_t, blks) + (sizeof(xfs_fsblock_t) * (n)))
88 typedef struct blkmap
{
93 #define BLKMAP_SIZE(n) \
94 (offsetof(blkmap_t, ents) + (sizeof(blkent_t *) * (n)))
96 typedef struct freetab
{
99 xfs_dir2_data_off_t ents
[1];
101 #define FREETAB_SIZE(n) \
102 (offsetof(freetab_t, ents) + (sizeof(xfs_dir2_data_off_t) * (n)))
104 typedef struct dirhash
{
105 struct dirhash
*next
;
110 #define DIR_HASH_SIZE 1024
111 #define DIR_HASH_FUNC(h,a) (((h) ^ (a)) % DIR_HASH_SIZE)
113 static xfs_extlen_t agffreeblks
;
114 static xfs_extlen_t agflongest
;
115 static __uint64_t agf_aggr_freeblks
; /* aggregate count over all */
116 static __uint32_t agfbtreeblks
;
117 static int lazycount
;
118 static xfs_agino_t agicount
;
119 static xfs_agino_t agifreecount
;
120 static xfs_fsblock_t
*blist
;
121 static int blist_size
;
122 static char **dbmap
; /* really dbm_t:8 */
123 static dirhash_t
**dirhash
;
125 static __uint64_t fdblocks
;
126 static __uint64_t frextents
;
127 static __uint64_t icount
;
128 static __uint64_t ifree
;
129 static inodata_t
***inodata
;
130 static int inodata_hash_size
;
131 static inodata_t
***inomap
;
135 static qdata_t
**qpdata
;
137 static qdata_t
**qudata
;
139 static qdata_t
**qgdata
;
141 static unsigned sbversion
;
142 static int sbver_err
;
143 static int serious_error
;
145 static xfs_suminfo_t
*sumcompute
;
146 static xfs_suminfo_t
*sumfile
;
147 static const char *typename
[] = {
177 #define CHECK_BLIST(b) (blist_size && check_blist(b))
178 #define CHECK_BLISTA(a,b) \
179 (blist_size && check_blist(XFS_AGB_TO_FSB(mp, a, b)))
181 typedef void (*scan_lbtree_f_t
)(struct xfs_btree_block
*block
,
193 typedef void (*scan_sbtree_f_t
)(struct xfs_btree_block
*block
,
199 static void add_blist(xfs_fsblock_t bno
);
200 static void add_ilist(xfs_ino_t ino
);
201 static void addlink_inode(inodata_t
*id
);
202 static void addname_inode(inodata_t
*id
, char *name
, int namelen
);
203 static void addparent_inode(inodata_t
*id
, xfs_ino_t parent
);
204 static void blkent_append(blkent_t
**entp
, xfs_fsblock_t b
,
206 static blkent_t
*blkent_new(xfs_fileoff_t o
, xfs_fsblock_t b
,
208 static void blkent_prepend(blkent_t
**entp
, xfs_fsblock_t b
,
210 static blkmap_t
*blkmap_alloc(xfs_extnum_t
);
211 static void blkmap_free(blkmap_t
*blkmap
);
212 static xfs_fsblock_t
blkmap_get(blkmap_t
*blkmap
, xfs_fileoff_t o
);
213 static int blkmap_getn(blkmap_t
*blkmap
, xfs_fileoff_t o
, int nb
,
215 static void blkmap_grow(blkmap_t
**blkmapp
, blkent_t
**entp
,
217 static xfs_fileoff_t
blkmap_next_off(blkmap_t
*blkmap
, xfs_fileoff_t o
,
219 static void blkmap_set_blk(blkmap_t
**blkmapp
, xfs_fileoff_t o
,
221 static void blkmap_set_ext(blkmap_t
**blkmapp
, xfs_fileoff_t o
,
222 xfs_fsblock_t b
, xfs_extlen_t c
);
223 static void blkmap_shrink(blkmap_t
*blkmap
, blkent_t
**entp
);
224 static int blockfree_f(int argc
, char **argv
);
225 static int blockget_f(int argc
, char **argv
);
226 static int blocktrash_f(int argc
, char **argv
);
227 static int blockuse_f(int argc
, char **argv
);
228 static int check_blist(xfs_fsblock_t bno
);
229 static void check_dbmap(xfs_agnumber_t agno
, xfs_agblock_t agbno
,
230 xfs_extlen_t len
, dbm_t type
);
231 static int check_inomap(xfs_agnumber_t agno
, xfs_agblock_t agbno
,
232 xfs_extlen_t len
, xfs_ino_t c_ino
);
233 static void check_linkcounts(xfs_agnumber_t agno
);
234 static int check_range(xfs_agnumber_t agno
, xfs_agblock_t agbno
,
236 static void check_rdbmap(xfs_drfsbno_t bno
, xfs_extlen_t len
,
238 static int check_rinomap(xfs_drfsbno_t bno
, xfs_extlen_t len
,
240 static void check_rootdir(void);
241 static int check_rrange(xfs_drfsbno_t bno
, xfs_extlen_t len
);
242 static void check_set_dbmap(xfs_agnumber_t agno
,
243 xfs_agblock_t agbno
, xfs_extlen_t len
,
244 dbm_t type1
, dbm_t type2
,
245 xfs_agnumber_t c_agno
,
246 xfs_agblock_t c_agbno
);
247 static void check_set_rdbmap(xfs_drfsbno_t bno
, xfs_extlen_t len
,
248 dbm_t type1
, dbm_t type2
);
249 static void check_summary(void);
250 static void checknot_dbmap(xfs_agnumber_t agno
, xfs_agblock_t agbno
,
251 xfs_extlen_t len
, int typemask
);
252 static void checknot_rdbmap(xfs_drfsbno_t bno
, xfs_extlen_t len
,
254 static void dir_hash_add(xfs_dahash_t hash
,
255 xfs_dir2_dataptr_t addr
);
256 static void dir_hash_check(inodata_t
*id
, int v
);
257 static void dir_hash_done(void);
258 static void dir_hash_init(void);
259 static int dir_hash_see(xfs_dahash_t hash
,
260 xfs_dir2_dataptr_t addr
);
261 static inodata_t
*find_inode(xfs_ino_t ino
, int add
);
262 static void free_inodata(xfs_agnumber_t agno
);
263 static int init(int argc
, char **argv
);
264 static char *inode_name(xfs_ino_t ino
, inodata_t
**ipp
);
265 static int ncheck_f(int argc
, char **argv
);
266 static char *prepend_path(char *oldpath
, char *parent
);
267 static xfs_ino_t
process_block_dir_v2(blkmap_t
*blkmap
, int *dot
,
268 int *dotdot
, inodata_t
*id
);
269 static void process_bmbt_reclist(xfs_bmbt_rec_t
*rp
, int numrecs
,
270 dbm_t type
, inodata_t
*id
,
273 static void process_btinode(inodata_t
*id
, xfs_dinode_t
*dip
,
274 dbm_t type
, xfs_drfsbno_t
*totd
,
275 xfs_drfsbno_t
*toti
, xfs_extnum_t
*nex
,
276 blkmap_t
**blkmapp
, int whichfork
);
277 static xfs_ino_t
process_data_dir_v2(int *dot
, int *dotdot
,
278 inodata_t
*id
, int v
,
280 freetab_t
**freetabp
);
281 static xfs_dir2_data_free_t
282 *process_data_dir_v2_freefind(xfs_dir2_data_t
*data
,
283 xfs_dir2_data_unused_t
*dup
);
284 static void process_dir(xfs_dinode_t
*dip
, blkmap_t
*blkmap
,
286 static int process_dir_v2(xfs_dinode_t
*dip
, blkmap_t
*blkmap
,
287 int *dot
, int *dotdot
, inodata_t
*id
,
289 static void process_exinode(inodata_t
*id
, xfs_dinode_t
*dip
,
290 dbm_t type
, xfs_drfsbno_t
*totd
,
291 xfs_drfsbno_t
*toti
, xfs_extnum_t
*nex
,
292 blkmap_t
**blkmapp
, int whichfork
);
293 static void process_inode(xfs_agf_t
*agf
, xfs_agino_t agino
,
294 xfs_dinode_t
*dip
, int isfree
);
295 static void process_lclinode(inodata_t
*id
, xfs_dinode_t
*dip
,
296 dbm_t type
, xfs_drfsbno_t
*totd
,
297 xfs_drfsbno_t
*toti
, xfs_extnum_t
*nex
,
298 blkmap_t
**blkmapp
, int whichfork
);
299 static xfs_ino_t
process_leaf_node_dir_v2(blkmap_t
*blkmap
, int *dot
,
300 int *dotdot
, inodata_t
*id
,
301 xfs_fsize_t dirsize
);
302 static void process_leaf_node_dir_v2_free(inodata_t
*id
, int v
,
305 static void process_leaf_node_dir_v2_int(inodata_t
*id
, int v
,
308 static void process_quota(qtype_t qtype
, inodata_t
*id
,
310 static void process_rtbitmap(blkmap_t
*blkmap
);
311 static void process_rtsummary(blkmap_t
*blkmap
);
312 static xfs_ino_t
process_sf_dir_v2(xfs_dinode_t
*dip
, int *dot
,
313 int *dotdot
, inodata_t
*id
);
314 static void quota_add(xfs_dqid_t
*p
, xfs_dqid_t
*g
, xfs_dqid_t
*u
,
315 int dq
, xfs_qcnt_t bc
, xfs_qcnt_t ic
,
317 static void quota_add1(qdata_t
**qt
, xfs_dqid_t id
, int dq
,
318 xfs_qcnt_t bc
, xfs_qcnt_t ic
,
320 static void quota_check(char *s
, qdata_t
**qt
);
321 static void quota_init(void);
322 static void scan_ag(xfs_agnumber_t agno
);
323 static void scan_freelist(xfs_agf_t
*agf
);
324 static void scan_lbtree(xfs_fsblock_t root
, int nlevels
,
325 scan_lbtree_f_t func
, dbm_t type
,
326 inodata_t
*id
, xfs_drfsbno_t
*totd
,
327 xfs_drfsbno_t
*toti
, xfs_extnum_t
*nex
,
328 blkmap_t
**blkmapp
, int isroot
,
330 static void scan_sbtree(xfs_agf_t
*agf
, xfs_agblock_t root
,
331 int nlevels
, int isroot
,
332 scan_sbtree_f_t func
, typnm_t btype
);
333 static void scanfunc_bmap(struct xfs_btree_block
*block
,
334 int level
, dbm_t type
, xfs_fsblock_t bno
,
335 inodata_t
*id
, xfs_drfsbno_t
*totd
,
336 xfs_drfsbno_t
*toti
, xfs_extnum_t
*nex
,
337 blkmap_t
**blkmapp
, int isroot
,
339 static void scanfunc_bno(struct xfs_btree_block
*block
, int level
,
340 xfs_agf_t
*agf
, xfs_agblock_t bno
,
342 static void scanfunc_cnt(struct xfs_btree_block
*block
, int level
,
343 xfs_agf_t
*agf
, xfs_agblock_t bno
,
345 static void scanfunc_ino(struct xfs_btree_block
*block
, int level
,
346 xfs_agf_t
*agf
, xfs_agblock_t bno
,
348 static void set_dbmap(xfs_agnumber_t agno
, xfs_agblock_t agbno
,
349 xfs_extlen_t len
, dbm_t type
,
350 xfs_agnumber_t c_agno
, xfs_agblock_t c_agbno
);
351 static void set_inomap(xfs_agnumber_t agno
, xfs_agblock_t agbno
,
352 xfs_extlen_t len
, inodata_t
*id
);
353 static void set_rdbmap(xfs_drfsbno_t bno
, xfs_extlen_t len
,
355 static void set_rinomap(xfs_drfsbno_t bno
, xfs_extlen_t len
,
357 static void setlink_inode(inodata_t
*id
, nlink_t nlink
, int isdir
,
360 static const cmdinfo_t blockfree_cmd
=
361 { "blockfree", NULL
, blockfree_f
, 0, 0, 0,
362 NULL
, N_("free block usage information"), NULL
};
363 static const cmdinfo_t blockget_cmd
=
364 { "blockget", "check", blockget_f
, 0, -1, 0,
365 N_("[-s|-v] [-n] [-t] [-b bno]... [-i ino] ..."),
366 N_("get block usage and check consistency"), NULL
};
367 static const cmdinfo_t blocktrash_cmd
=
368 { "blocktrash", NULL
, blocktrash_f
, 0, -1, 0,
369 N_("[-n count] [-x minlen] [-y maxlen] [-s seed] [-0123] [-t type] ..."),
370 N_("trash randomly selected block(s)"), NULL
};
371 static const cmdinfo_t blockuse_cmd
=
372 { "blockuse", NULL
, blockuse_f
, 0, 3, 0,
373 N_("[-n] [-c blockcount]"),
374 N_("print usage for current block(s)"), NULL
};
375 static const cmdinfo_t ncheck_cmd
=
376 { "ncheck", NULL
, ncheck_f
, 0, -1, 0,
377 N_("[-s] [-i ino] ..."),
378 N_("print inode-name pairs"), NULL
};
386 blist
= xrealloc(blist
, blist_size
* sizeof(bno
));
387 blist
[blist_size
- 1] = bno
;
396 id
= find_inode(ino
, 1);
398 dbprintf(_("-i %lld bad inode number\n"), ino
);
409 if (verbose
|| id
->ilist
)
410 dbprintf(_("inode %lld add link, now %u\n"), id
->ino
,
420 if (!nflag
|| id
->name
)
422 id
->name
= xmalloc(namelen
+ 1);
423 memcpy(id
->name
, name
, namelen
);
424 id
->name
[namelen
] = '\0';
434 pid
= find_inode(parent
, 1);
436 if (verbose
|| id
->ilist
|| (pid
&& pid
->ilist
))
437 dbprintf(_("inode %lld parent %lld\n"), id
->ino
, parent
);
450 *entp
= ent
= xrealloc(ent
, BLKENT_SIZE(c
+ ent
->nblks
));
451 for (i
= 0; i
< c
; i
++)
452 ent
->blks
[ent
->nblks
+ i
] = b
+ i
;
465 ent
= xmalloc(BLKENT_SIZE(c
));
468 for (i
= 0; i
< c
; i
++)
469 ent
->blks
[i
] = b
+ i
;
484 newent
= xmalloc(BLKENT_SIZE(oldent
->nblks
+ c
));
485 newent
->nblks
= oldent
->nblks
+ c
;
486 newent
->startoff
= oldent
->startoff
- c
;
487 for (i
= 0; i
< c
; i
++)
488 newent
->blks
[i
] = b
+ c
;
489 for (; i
< oldent
->nblks
+ c
; i
++)
490 newent
->blks
[i
] = oldent
->blks
[i
- c
];
503 blkmap
= xmalloc(BLKMAP_SIZE(nex
));
504 blkmap
->naents
= nex
;
516 for (i
= 0, entp
= blkmap
->ents
; i
< blkmap
->nents
; i
++, entp
++)
530 for (i
= 0, entp
= blkmap
->ents
; i
< blkmap
->nents
; i
++, entp
++) {
532 if (o
>= ent
->startoff
&& o
< ent
->startoff
+ ent
->nblks
)
533 return ent
->blks
[o
- ent
->startoff
];
552 for (i
= nex
= 0, bmp
= NULL
, entp
= blkmap
->ents
;
556 if (ent
->startoff
>= o
+ nb
)
558 if (ent
->startoff
+ ent
->nblks
<= o
)
560 for (ento
= ent
->startoff
;
561 ento
< ent
->startoff
+ ent
->nblks
&& ento
< o
+ nb
;
566 bmp
[nex
- 1].startoff
+ bmp
[nex
- 1].blockcount
==
568 bmp
[nex
- 1].startblock
+ bmp
[nex
- 1].blockcount
==
569 ent
->blks
[ento
- ent
->startoff
])
570 bmp
[nex
- 1].blockcount
++;
572 bmp
= realloc(bmp
, ++nex
* sizeof(*bmp
));
573 bmp
[nex
- 1].startoff
= ento
;
574 bmp
[nex
- 1].startblock
=
575 ent
->blks
[ento
- ent
->startoff
];
576 bmp
[nex
- 1].blockcount
= 1;
577 bmp
[nex
- 1].flag
= 0;
596 idx
= (int)(entp
- blkmap
->ents
);
597 if (blkmap
->naents
== blkmap
->nents
) {
598 blkmap
= xrealloc(blkmap
, BLKMAP_SIZE(blkmap
->nents
+ 1));
602 for (i
= blkmap
->nents
; i
> idx
; i
--)
603 blkmap
->ents
[i
] = blkmap
->ents
[i
- 1];
604 blkmap
->ents
[idx
] = newent
;
616 ent
= blkmap
->ents
[blkmap
->nents
- 1];
617 return ent
->startoff
+ ent
->nblks
;
631 if (o
== NULLFILEOFF
) {
633 ent
= blkmap
->ents
[0];
634 return ent
->startoff
;
636 entp
= &blkmap
->ents
[*t
];
638 if (o
< ent
->startoff
+ ent
->nblks
- 1)
641 if (entp
>= &blkmap
->ents
[blkmap
->nents
])
645 return ent
->startoff
;
660 for (entp
= blkmap
->ents
; entp
< &blkmap
->ents
[blkmap
->nents
]; entp
++) {
662 if (o
< ent
->startoff
- 1) {
663 ent
= blkent_new(o
, b
, 1);
664 blkmap_grow(blkmapp
, entp
, ent
);
667 if (o
== ent
->startoff
- 1) {
668 blkent_prepend(entp
, b
, 1);
671 if (o
>= ent
->startoff
&& o
< ent
->startoff
+ ent
->nblks
) {
672 ent
->blks
[o
- ent
->startoff
] = b
;
675 if (o
> ent
->startoff
+ ent
->nblks
)
677 blkent_append(entp
, b
, 1);
678 if (entp
== &blkmap
->ents
[blkmap
->nents
- 1])
682 if (ent
->startoff
+ ent
->nblks
< nextent
->startoff
)
684 blkent_append(entp
, nextent
->blks
[0], nextent
->nblks
);
685 blkmap_shrink(blkmap
, &entp
[1]);
688 ent
= blkent_new(o
, b
, 1);
689 blkmap_grow(blkmapp
, entp
, ent
);
705 if (!blkmap
->nents
) {
706 blkmap
->ents
[0] = blkent_new(o
, b
, c
);
710 entp
= &blkmap
->ents
[blkmap
->nents
- 1];
712 if (ent
->startoff
+ ent
->nblks
== o
) {
713 blkent_append(entp
, b
, c
);
716 if (ent
->startoff
+ ent
->nblks
< o
) {
717 ent
= blkent_new(o
, b
, c
);
718 blkmap_grow(blkmapp
, &blkmap
->ents
[blkmap
->nents
], ent
);
721 for (i
= 0; i
< c
; i
++)
722 blkmap_set_blk(blkmapp
, o
+ i
, b
+ i
);
734 idx
= (int)(entp
- blkmap
->ents
);
735 for (i
= idx
+ 1; i
< blkmap
->nents
; i
++)
736 blkmap
->ents
[i
] = blkmap
->ents
[i
- 1];
750 dbprintf(_("block usage information not allocated\n"));
753 rt
= mp
->m_sb
.sb_rextents
!= 0;
754 for (c
= 0; c
< mp
->m_sb
.sb_agcount
; c
++) {
764 sumcompute
= sumfile
= NULL
;
776 * Check consistency of xfs filesystem contents.
788 dbprintf(_("already have block usage information\n"));
791 if (!init(argc
, argv
)) {
798 oldprefix
= dbprefix
;
800 for (agno
= 0, sbyell
= 0; agno
< mp
->m_sb
.sb_agcount
; agno
++) {
802 if (sbver_err
> 4 && !sbyell
&& sbver_err
>= agno
) {
804 dbprintf(_("WARNING: this may be a newer XFS "
815 dbprefix
= oldprefix
;
820 * Check that there are no blocks either
821 * a) unaccounted for or
822 * b) bno-free but not cnt-free
824 if (!tflag
) { /* are we in test mode, faking out freespace? */
825 for (agno
= 0; agno
< mp
->m_sb
.sb_agcount
; agno
++)
826 checknot_dbmap(agno
, 0, mp
->m_sb
.sb_agblocks
,
827 (1 << DBM_UNKNOWN
) | (1 << DBM_FREE1
));
829 for (agno
= 0; agno
< mp
->m_sb
.sb_agcount
; agno
++)
830 check_linkcounts(agno
);
831 if (mp
->m_sb
.sb_rblocks
) {
833 (xfs_extlen_t
)(mp
->m_sb
.sb_rextents
*
834 mp
->m_sb
.sb_rextsize
),
838 if (mp
->m_sb
.sb_icount
!= icount
) {
840 dbprintf(_("sb_icount %lld, counted %lld\n"),
841 mp
->m_sb
.sb_icount
, icount
);
844 if (mp
->m_sb
.sb_ifree
!= ifree
) {
846 dbprintf(_("sb_ifree %lld, counted %lld\n"),
847 mp
->m_sb
.sb_ifree
, ifree
);
850 if (mp
->m_sb
.sb_fdblocks
!= fdblocks
) {
852 dbprintf(_("sb_fdblocks %lld, counted %lld\n"),
853 mp
->m_sb
.sb_fdblocks
, fdblocks
);
856 if (lazycount
&& mp
->m_sb
.sb_fdblocks
!= agf_aggr_freeblks
) {
858 dbprintf(_("sb_fdblocks %lld, aggregate AGF count %lld\n"),
859 mp
->m_sb
.sb_fdblocks
, agf_aggr_freeblks
);
862 if (mp
->m_sb
.sb_frextents
!= frextents
) {
864 dbprintf(_("sb_frextents %lld, counted %lld\n"),
865 mp
->m_sb
.sb_frextents
, frextents
);
868 if (mp
->m_sb
.sb_bad_features2
!= 0 &&
869 mp
->m_sb
.sb_bad_features2
!= mp
->m_sb
.sb_features2
) {
871 dbprintf(_("sb_features2 (0x%x) not same as "
872 "sb_bad_features2 (0x%x)\n"),
873 mp
->m_sb
.sb_features2
,
874 mp
->m_sb
.sb_bad_features2
);
877 if ((sbversion
& XFS_SB_VERSION_ATTRBIT
) &&
878 !xfs_sb_version_hasattr(&mp
->m_sb
)) {
880 dbprintf(_("sb versionnum missing attr bit %x\n"),
881 XFS_SB_VERSION_ATTRBIT
);
884 if ((sbversion
& XFS_SB_VERSION_NLINKBIT
) &&
885 !xfs_sb_version_hasnlink(&mp
->m_sb
)) {
887 dbprintf(_("sb versionnum missing nlink bit %x\n"),
888 XFS_SB_VERSION_NLINKBIT
);
891 if ((sbversion
& XFS_SB_VERSION_QUOTABIT
) &&
892 !xfs_sb_version_hasquota(&mp
->m_sb
)) {
894 dbprintf(_("sb versionnum missing quota bit %x\n"),
895 XFS_SB_VERSION_QUOTABIT
);
898 if (!(sbversion
& XFS_SB_VERSION_ALIGNBIT
) &&
899 xfs_sb_version_hasalign(&mp
->m_sb
)) {
901 dbprintf(_("sb versionnum extra align bit %x\n"),
902 XFS_SB_VERSION_ALIGNBIT
);
906 quota_check("user", qudata
);
908 quota_check("project", qpdata
);
910 quota_check("group", qgdata
);
911 if (sbver_err
> mp
->m_sb
.sb_agcount
/ 2)
912 dbprintf(_("WARNING: this may be a newer XFS filesystem.\n"));
915 dbprefix
= oldprefix
;
919 typedef struct ltab
{
940 static char *modestr
[] = {
941 N_("zeroed"), N_("set"), N_("flipped"), N_("randomized")
944 len
= (int)((random() % (ltabp
->max
- ltabp
->min
+ 1)) + ltabp
->min
);
945 offset
= (int)(random() % (int)(mp
->m_sb
.sb_blocksize
* NBBY
));
948 set_cur(&typtab
[DBM_UNKNOWN
],
949 XFS_AGB_TO_DADDR(mp
, agno
, agbno
), blkbb
, DB_RING_IGN
, NULL
);
950 if ((buf
= iocur_top
->data
) == NULL
) {
951 dbprintf(_("can't read block %u/%u for trashing\n"), agno
, agbno
);
955 for (bitno
= 0; bitno
< len
; bitno
++) {
956 bit
= (offset
+ bitno
) % (mp
->m_sb
.sb_blocksize
* NBBY
);
968 newbit
= (buf
[byte
] & mask
) == 0;
971 newbit
= (int)random() & 1;
981 printf(_("blocktrash: %u/%u %s block %d bit%s starting %d:%d %s\n"),
982 agno
, agbno
, typename
[type
], len
, len
== 1 ? "" : "s",
983 offset
/ NBBY
, offset
% NBBY
, modestr
[mode
]);
994 xfs_drfsbno_t blocks
;
1007 xfs_drfsbno_t randb
;
1013 dbprintf(_("must run blockget first\n"));
1021 gettimeofday(&now
, NULL
);
1022 seed
= (unsigned int)(now
.tv_sec
^ now
.tv_usec
);
1025 goodmask
= (1 << DBM_AGF
) |
1029 (1 << DBM_BTBMAPA
) |
1030 (1 << DBM_BTBMAPD
) |
1037 (1 << DBM_RTBITMAP
) |
1040 while ((c
= getopt(argc
, argv
, "0123n:s:t:x:y:")) != EOF
) {
1055 count
= (int)strtol(optarg
, &p
, 0);
1056 if (*p
!= '\0' || count
<= 0) {
1057 dbprintf(_("bad blocktrash count %s\n"), optarg
);
1062 seed
= (uint
)strtoul(optarg
, &p
, 0);
1066 for (i
= 0; typename
[i
]; i
++) {
1067 if (strcmp(typename
[i
], optarg
) == 0)
1070 if (!typename
[i
] || (((1 << i
) & goodmask
) == 0)) {
1071 dbprintf(_("bad blocktrash type %s\n"), optarg
);
1077 min
= (int)strtol(optarg
, &p
, 0);
1078 if (*p
!= '\0' || min
<= 0 ||
1079 min
> mp
->m_sb
.sb_blocksize
* NBBY
) {
1080 dbprintf(_("bad blocktrash min %s\n"), optarg
);
1085 max
= (int)strtol(optarg
, &p
, 0);
1086 if (*p
!= '\0' || max
<= 0 ||
1087 max
> mp
->m_sb
.sb_blocksize
* NBBY
) {
1088 dbprintf(_("bad blocktrash max %s\n"), optarg
);
1093 dbprintf(_("bad option for blocktrash command\n"));
1098 dbprintf(_("bad min/max for blocktrash command\n"));
1103 lentab
= xmalloc(sizeof(ltab_t
));
1104 lentab
->min
= lentab
->max
= min
;
1106 for (i
= min
+ 1; i
<= max
; i
++) {
1107 if ((i
& (i
- 1)) == 0) {
1108 lentab
= xrealloc(lentab
,
1109 sizeof(ltab_t
) * (lentablen
+ 1));
1110 lentab
[lentablen
].min
= lentab
[lentablen
].max
= i
;
1113 lentab
[lentablen
- 1].max
= i
;
1115 for (blocks
= 0, agno
= 0; agno
< mp
->m_sb
.sb_agcount
; agno
++) {
1116 for (agbno
= 0, p
= dbmap
[agno
];
1117 agbno
< mp
->m_sb
.sb_agblocks
;
1119 if ((1 << *p
) & tmask
)
1124 dbprintf(_("blocktrash: no matching blocks\n"));
1128 dbprintf(_("blocktrash: seed %u\n"), seed
);
1130 for (i
= 0; i
< count
; i
++) {
1131 randb
= (xfs_drfsbno_t
)((((__int64_t
)random() << 32) |
1132 random()) % blocks
);
1133 for (bi
= 0, agno
= 0, done
= 0;
1134 !done
&& agno
< mp
->m_sb
.sb_agcount
;
1136 for (agbno
= 0, p
= dbmap
[agno
];
1137 agbno
< mp
->m_sb
.sb_agblocks
;
1139 if (!((1 << *p
) & tmask
))
1143 blocktrash_b(agno
, agbno
, (dbm_t
)*p
,
1144 &lentab
[random() % lentablen
], mode
);
1159 xfs_agblock_t agbno
;
1160 xfs_agnumber_t agno
;
1170 dbprintf(_("must run blockget first\n"));
1176 fsb
= XFS_DADDR_TO_FSB(mp
, iocur_top
->off
>> BBSHIFT
);
1177 agno
= XFS_FSB_TO_AGNO(mp
, fsb
);
1178 end
= agbno
= XFS_FSB_TO_AGBNO(mp
, fsb
);
1179 while ((c
= getopt(argc
, argv
, "c:n")) != EOF
) {
1182 count
= (int)strtol(optarg
, &p
, 0);
1183 end
= agbno
+ count
- 1;
1184 if (*p
!= '\0' || count
<= 0 ||
1185 end
>= mp
->m_sb
.sb_agblocks
) {
1186 dbprintf(_("bad blockuse count %s\n"), optarg
);
1192 dbprintf(_("must run blockget -n first\n"));
1198 dbprintf(_("bad option for blockuse command\n"));
1202 while (agbno
<= end
) {
1203 p
= &dbmap
[agno
][agbno
];
1204 i
= inomap
[agno
][agbno
];
1205 dbprintf(_("block %llu (%u/%u) type %s"),
1206 (xfs_dfsbno_t
)XFS_AGB_TO_FSB(mp
, agno
, agbno
),
1207 agno
, agbno
, typename
[(dbm_t
)*p
]);
1209 dbprintf(_(" inode %lld"), i
->ino
);
1210 if (shownames
&& (p
= inode_name(i
->ino
, NULL
))) {
1227 for (i
= 0; i
< blist_size
; i
++) {
1228 if (blist
[i
] == bno
)
1236 xfs_agnumber_t agno
,
1237 xfs_agblock_t agbno
,
1244 for (i
= 0, p
= &dbmap
[agno
][agbno
]; i
< len
; i
++, p
++) {
1245 if ((dbm_t
)*p
!= type
) {
1246 if (!sflag
|| CHECK_BLISTA(agno
, agbno
+ i
))
1247 dbprintf(_("block %u/%u expected type %s got "
1249 agno
, agbno
+ i
, typename
[type
],
1250 typename
[(dbm_t
)*p
]);
1259 add_command(&blockfree_cmd
);
1260 add_command(&blockget_cmd
);
1262 add_command(&blocktrash_cmd
);
1263 add_command(&blockuse_cmd
);
1264 add_command(&ncheck_cmd
);
1269 xfs_agnumber_t agno
,
1270 xfs_agblock_t agbno
,
1278 if (!check_range(agno
, agbno
, len
)) {
1279 dbprintf(_("blocks %u/%u..%u claimed by inode %lld\n"),
1280 agno
, agbno
, agbno
+ len
- 1, c_ino
);
1283 for (i
= 0, rval
= 1, idp
= &inomap
[agno
][agbno
]; i
< len
; i
++, idp
++) {
1285 if (!sflag
|| (*idp
)->ilist
||
1286 CHECK_BLISTA(agno
, agbno
+ i
))
1287 dbprintf(_("block %u/%u claimed by inode %lld, "
1288 "previous inum %lld\n"),
1289 agno
, agbno
+ i
, c_ino
, (*idp
)->ino
);
1299 xfs_agnumber_t agno
)
1307 for (idx
= 0; idx
< inodata_hash_size
; ht
++, idx
++) {
1310 if (ep
->link_set
!= ep
->link_add
|| ep
->link_set
== 0) {
1311 path
= inode_name(ep
->ino
, NULL
);
1312 if (!path
&& ep
->link_add
)
1313 path
= xstrdup("?");
1314 if (!sflag
|| ep
->ilist
) {
1316 dbprintf(_("link count mismatch "
1317 "for inode %lld (name "
1323 else if (ep
->link_set
)
1324 dbprintf(_("disconnected inode "
1325 "%lld, nlink %d\n"),
1326 ep
->ino
, ep
->link_set
);
1328 dbprintf(_("allocated inode %lld "
1329 "has 0 link count\n"),
1335 } else if (verbose
|| ep
->ilist
) {
1336 path
= inode_name(ep
->ino
, NULL
);
1338 dbprintf(_("inode %lld name %s\n"),
1351 xfs_agnumber_t agno
,
1352 xfs_agblock_t agbno
,
1356 xfs_agblock_t low
= 0;
1357 xfs_agblock_t high
= 0;
1358 int valid_range
= 0;
1361 if (agno
>= mp
->m_sb
.sb_agcount
||
1362 agbno
+ len
- 1 >= mp
->m_sb
.sb_agblocks
) {
1363 for (i
= 0; i
< len
; i
++) {
1364 cur
= !sflag
|| CHECK_BLISTA(agno
, agbno
+ i
) ? 1 : 0;
1365 if (cur
== 1 && prev
== 0) {
1366 low
= high
= agbno
+ i
;
1368 } else if (cur
== 0 && prev
== 0) {
1370 } else if (cur
== 0 && prev
== 1) {
1372 dbprintf(_("block %u/%u out of range\n"),
1375 dbprintf(_("blocks %u/%u..%u "
1380 } else if (cur
== 1 && prev
== 1) {
1387 dbprintf(_("block %u/%u out of range\n"),
1390 dbprintf(_("blocks %u/%u..%u "
1410 for (i
= 0, p
= &dbmap
[mp
->m_sb
.sb_agcount
][bno
]; i
< len
; i
++, p
++) {
1411 if ((dbm_t
)*p
!= type
) {
1412 if (!sflag
|| CHECK_BLIST(bno
+ i
))
1413 dbprintf(_("rtblock %llu expected type %s got "
1415 bno
+ i
, typename
[type
],
1416 typename
[(dbm_t
)*p
]);
1432 if (!check_rrange(bno
, len
)) {
1433 dbprintf(_("rtblocks %llu..%llu claimed by inode %lld\n"),
1434 bno
, bno
+ len
- 1, c_ino
);
1437 for (i
= 0, rval
= 1, idp
= &inomap
[mp
->m_sb
.sb_agcount
][bno
];
1441 if (!sflag
|| (*idp
)->ilist
|| CHECK_BLIST(bno
+ i
))
1442 dbprintf(_("rtblock %llu claimed by inode %lld, "
1443 "previous inum %lld\n"),
1444 bno
+ i
, c_ino
, (*idp
)->ino
);
1457 id
= find_inode(mp
->m_sb
.sb_rootino
, 0);
1460 dbprintf(_("root inode %lld is missing\n"),
1461 mp
->m_sb
.sb_rootino
);
1463 } else if (!id
->isdir
) {
1464 if (!sflag
|| id
->ilist
)
1465 dbprintf(_("root inode %lld is not a directory\n"),
1466 mp
->m_sb
.sb_rootino
);
1478 if (bno
+ len
- 1 >= mp
->m_sb
.sb_rblocks
) {
1479 for (i
= 0; i
< len
; i
++) {
1480 if (!sflag
|| CHECK_BLIST(bno
+ i
))
1481 dbprintf(_("rtblock %llu out of range\n"),
1492 xfs_agnumber_t agno
,
1493 xfs_agblock_t agbno
,
1497 xfs_agnumber_t c_agno
,
1498 xfs_agblock_t c_agbno
)
1504 if (!check_range(agno
, agbno
, len
)) {
1505 dbprintf(_("blocks %u/%u..%u claimed by block %u/%u\n"), agno
,
1506 agbno
, agbno
+ len
- 1, c_agno
, c_agbno
);
1509 check_dbmap(agno
, agbno
, len
, type1
);
1510 mayprint
= verbose
| blist_size
;
1511 for (i
= 0, p
= &dbmap
[agno
][agbno
]; i
< len
; i
++, p
++) {
1513 if (mayprint
&& (verbose
|| CHECK_BLISTA(agno
, agbno
+ i
)))
1514 dbprintf(_("setting block %u/%u to %s\n"), agno
, agbno
+ i
,
1530 if (!check_rrange(bno
, len
))
1532 check_rdbmap(bno
, len
, type1
);
1533 mayprint
= verbose
| blist_size
;
1534 for (i
= 0, p
= &dbmap
[mp
->m_sb
.sb_agcount
][bno
]; i
< len
; i
++, p
++) {
1536 if (mayprint
&& (verbose
|| CHECK_BLIST(bno
+ i
)))
1537 dbprintf(_("setting rtblock %llu to %s\n"),
1538 bno
+ i
, typename
[type2
]);
1552 for (log
= 0; log
< mp
->m_rsumlevels
; log
++) {
1554 bno
< mp
->m_sb
.sb_rbmblocks
;
1555 bno
++, csp
++, fsp
++) {
1558 dbprintf(_("rt summary mismatch, size %d "
1559 "block %llu, file: %d, "
1561 log
, bno
, *fsp
, *csp
);
1570 xfs_agnumber_t agno
,
1571 xfs_agblock_t agbno
,
1578 if (!check_range(agno
, agbno
, len
))
1580 for (i
= 0, p
= &dbmap
[agno
][agbno
]; i
< len
; i
++, p
++) {
1581 if ((1 << *p
) & typemask
) {
1582 if (!sflag
|| CHECK_BLISTA(agno
, agbno
+ i
))
1583 dbprintf(_("block %u/%u type %s not expected\n"),
1584 agno
, agbno
+ i
, typename
[(dbm_t
)*p
]);
1599 if (!check_rrange(bno
, len
))
1601 for (i
= 0, p
= &dbmap
[mp
->m_sb
.sb_agcount
][bno
]; i
< len
; i
++, p
++) {
1602 if ((1 << *p
) & typemask
) {
1603 if (!sflag
|| CHECK_BLIST(bno
+ i
))
1604 dbprintf(_("rtblock %llu type %s not expected\n"),
1605 bno
+ i
, typename
[(dbm_t
)*p
]);
1614 xfs_dir2_dataptr_t addr
)
1619 i
= DIR_HASH_FUNC(hash
, addr
);
1620 p
= malloc(sizeof(*p
));
1621 p
->next
= dirhash
[i
];
1636 for (i
= 0; i
< DIR_HASH_SIZE
; i
++) {
1637 for (p
= dirhash
[i
]; p
; p
= p
->next
) {
1640 if (!sflag
|| id
->ilist
|| v
)
1641 dbprintf(_("dir ino %lld missing leaf entry for "
1643 id
->ino
, p
->hashval
, p
->address
);
1656 for (i
= 0; i
< DIR_HASH_SIZE
; i
++) {
1657 for (p
= dirhash
[i
]; p
; p
= n
) {
1669 dirhash
= calloc(DIR_HASH_SIZE
, sizeof(*dirhash
));
1675 xfs_dir2_dataptr_t addr
)
1680 i
= DIR_HASH_FUNC(hash
, addr
);
1681 for (p
= dirhash
[i
]; p
; p
= p
->next
) {
1682 if (p
->hashval
== hash
&& p
->address
== addr
) {
1698 xfs_agnumber_t agno
;
1703 agno
= XFS_INO_TO_AGNO(mp
, ino
);
1704 agino
= XFS_INO_TO_AGINO(mp
, ino
);
1705 if (agno
>= mp
->m_sb
.sb_agcount
||
1706 XFS_AGINO_TO_INO(mp
, agno
, agino
) != ino
)
1708 htab
= inodata
[agno
];
1709 ih
= agino
% inodata_hash_size
;
1712 if (ent
->ino
== ino
)
1718 ent
= xcalloc(1, sizeof(*ent
));
1720 ent
->next
= htab
[ih
];
1727 xfs_agnumber_t agno
)
1735 for (i
= 0; i
< inodata_hash_size
; i
++) {
1759 if (mp
->m_sb
.sb_magicnum
!= XFS_SB_MAGIC
) {
1760 dbprintf(_("bad superblock magic number %x, giving up\n"),
1761 mp
->m_sb
.sb_magicnum
);
1767 rt
= mp
->m_sb
.sb_rextents
!= 0;
1768 dbmap
= xmalloc((mp
->m_sb
.sb_agcount
+ rt
) * sizeof(*dbmap
));
1769 inomap
= xmalloc((mp
->m_sb
.sb_agcount
+ rt
) * sizeof(*inomap
));
1770 inodata
= xmalloc(mp
->m_sb
.sb_agcount
* sizeof(*inodata
));
1772 (int)MAX(MIN(mp
->m_sb
.sb_icount
/
1773 (INODATA_AVG_HASH_LENGTH
* mp
->m_sb
.sb_agcount
),
1774 MAX_INODATA_HASH_SIZE
),
1775 MIN_INODATA_HASH_SIZE
);
1776 for (c
= 0; c
< mp
->m_sb
.sb_agcount
; c
++) {
1777 dbmap
[c
] = xcalloc(mp
->m_sb
.sb_agblocks
, sizeof(**dbmap
));
1778 inomap
[c
] = xcalloc(mp
->m_sb
.sb_agblocks
, sizeof(**inomap
));
1779 inodata
[c
] = xcalloc(inodata_hash_size
, sizeof(**inodata
));
1782 dbmap
[c
] = xcalloc(mp
->m_sb
.sb_rblocks
, sizeof(**dbmap
));
1783 inomap
[c
] = xcalloc(mp
->m_sb
.sb_rblocks
, sizeof(**inomap
));
1784 sumfile
= xcalloc(mp
->m_rsumsize
, 1);
1785 sumcompute
= xcalloc(mp
->m_rsumsize
, 1);
1787 nflag
= sflag
= tflag
= verbose
= optind
= 0;
1788 while ((c
= getopt(argc
, argv
, "b:i:npstv")) != EOF
) {
1791 bno
= strtoll(optarg
, NULL
, 10);
1795 ino
= strtoll(optarg
, NULL
, 10);
1814 dbprintf(_("bad option for blockget command\n"));
1818 error
= sbver_err
= serious_error
= 0;
1819 fdblocks
= frextents
= icount
= ifree
= 0;
1820 sbversion
= XFS_SB_VERSION_4
;
1821 if (mp
->m_sb
.sb_inoalignmt
)
1822 sbversion
|= XFS_SB_VERSION_ALIGNBIT
;
1823 if ((mp
->m_sb
.sb_uquotino
&& mp
->m_sb
.sb_uquotino
!= NULLFSINO
) ||
1824 (mp
->m_sb
.sb_gquotino
&& mp
->m_sb
.sb_gquotino
!= NULLFSINO
))
1825 sbversion
|= XFS_SB_VERSION_QUOTABIT
;
1839 id
= find_inode(ino
, 0);
1844 if (id
->name
== NULL
)
1846 path
= xstrdup(id
->name
);
1847 while (id
->parent
) {
1849 if (id
->name
== NULL
)
1851 npath
= prepend_path(path
, id
->name
);
1863 xfs_agnumber_t agno
;
1876 if (!inodata
|| !nflag
) {
1877 dbprintf(_("must run blockget -n first\n"));
1880 security
= optind
= ilist_size
= 0;
1882 while ((c
= getopt(argc
, argv
, "i:s")) != EOF
) {
1885 ino
= strtoll(optarg
, NULL
, 10);
1886 ilist
= xrealloc(ilist
, (ilist_size
+ 1) *
1888 ilist
[ilist_size
++] = ino
;
1894 dbprintf(_("bad option -%c for ncheck command\n"), c
);
1899 for (ilp
= ilist
; ilp
< &ilist
[ilist_size
]; ilp
++) {
1901 if ((p
= inode_name(ino
, &hp
))) {
1902 dbprintf("%11llu %s", ino
, p
);
1912 for (agno
= 0; agno
< mp
->m_sb
.sb_agcount
; agno
++) {
1914 for (i
= 0; i
< inodata_hash_size
; i
++) {
1916 for (hp
= ht
[i
]; hp
; hp
= hp
->next
) {
1917 ino
= XFS_AGINO_TO_INO(mp
, agno
, hp
->ino
);
1918 p
= inode_name(ino
, &id
);
1921 if (!security
|| id
->security
) {
1922 dbprintf("%11llu %s", ino
, p
);
1942 len
= (int)(strlen(oldpath
) + strlen(parent
) + 2);
1943 path
= xmalloc(len
);
1944 snprintf(path
, len
, "%s/%s", parent
, oldpath
);
1949 process_block_dir_v2(
1963 nex
= blkmap_getn(blkmap
, 0, mp
->m_dirblkfsbs
, &bmp
);
1964 v
= id
->ilist
|| verbose
;
1967 dbprintf(_("block 0 for directory inode %lld is "
1975 make_bbmap(&bbmap
, nex
, bmp
);
1976 set_cur(&typtab
[TYP_DIR2
], XFS_FSB_TO_DADDR(mp
, bmp
->startblock
),
1977 mp
->m_dirblkfsbs
* blkbb
, DB_RING_IGN
, nex
> 1 ? &bbmap
: NULL
);
1978 for (x
= 0; !v
&& x
< nex
; x
++) {
1979 for (b
= bmp
[x
].startblock
;
1980 !v
&& b
< bmp
[x
].startblock
+ bmp
[x
].blockcount
;
1985 if (iocur_top
->data
== NULL
) {
1986 if (!sflag
|| id
->ilist
|| v
)
1987 dbprintf(_("can't read block 0 for directory inode "
1995 parent
= process_data_dir_v2(dot
, dotdot
, id
, v
, mp
->m_dirdatablk
,
1997 dir_hash_check(id
, v
);
2004 process_bmbt_reclist(
2012 xfs_agblock_t agbno
;
2013 xfs_agnumber_t agno
;
2019 xfs_agblock_t iagbno
;
2020 xfs_agnumber_t iagno
;
2027 v
= verbose
|| id
->ilist
;
2028 iagno
= XFS_INO_TO_AGNO(mp
, id
->ino
);
2029 iagbno
= XFS_INO_TO_AGBNO(mp
, id
->ino
);
2030 for (i
= 0; i
< numrecs
; i
++, rp
++) {
2031 convert_extent(rp
, &o
, &s
, &c
, &f
);
2033 dbprintf(_("inode %lld extent [%lld,%lld,%lld,%d]\n"),
2034 id
->ino
, o
, s
, c
, f
);
2035 if (!sflag
&& i
> 0 && op
+ cp
> o
)
2036 dbprintf(_("bmap rec out of order, inode %lld entry %d\n"),
2040 if (type
== DBM_RTDATA
) {
2041 if (!sflag
&& s
>= mp
->m_sb
.sb_rblocks
) {
2042 dbprintf(_("inode %lld bad rt block number %lld, "
2047 } else if (!sflag
) {
2048 agno
= XFS_FSB_TO_AGNO(mp
, s
);
2049 agbno
= XFS_FSB_TO_AGBNO(mp
, s
);
2050 if (agno
>= mp
->m_sb
.sb_agcount
||
2051 agbno
>= mp
->m_sb
.sb_agblocks
) {
2052 dbprintf(_("inode %lld bad block number %lld "
2053 "[%d,%d], offset %lld\n"),
2054 id
->ino
, s
, agno
, agbno
, o
);
2057 if (agbno
+ c
- 1 >= mp
->m_sb
.sb_agblocks
) {
2058 dbprintf(_("inode %lld bad block number %lld "
2059 "[%d,%d], offset %lld\n"),
2060 id
->ino
, s
+ c
- 1, agno
,
2061 agbno
+ (xfs_agblock_t
)c
- 1, o
);
2065 if (blkmapp
&& *blkmapp
)
2066 blkmap_set_ext(blkmapp
, (xfs_fileoff_t
)o
,
2067 (xfs_fsblock_t
)s
, (xfs_extlen_t
)c
);
2068 if (type
== DBM_RTDATA
) {
2069 set_rdbmap((xfs_fsblock_t
)s
, (xfs_extlen_t
)c
,
2071 set_rinomap((xfs_fsblock_t
)s
, (xfs_extlen_t
)c
, id
);
2072 for (b
= (xfs_fsblock_t
)s
;
2073 blist_size
&& b
< s
+ c
;
2076 dbprintf(_("inode %lld block %lld at "
2078 id
->ino
, (xfs_dfsbno_t
)b
, o
);
2081 agno
= XFS_FSB_TO_AGNO(mp
, (xfs_fsblock_t
)s
);
2082 agbno
= XFS_FSB_TO_AGBNO(mp
, (xfs_fsblock_t
)s
);
2083 set_dbmap(agno
, agbno
, (xfs_extlen_t
)c
, type
, iagno
,
2085 set_inomap(agno
, agbno
, (xfs_extlen_t
)c
, id
);
2086 for (b
= (xfs_fsblock_t
)s
;
2087 blist_size
&& b
< s
+ c
;
2088 b
++, o
++, agbno
++) {
2090 dbprintf(_("inode %lld block %lld at "
2092 id
->ino
, (xfs_dfsbno_t
)b
, o
);
2104 xfs_drfsbno_t
*totd
,
2105 xfs_drfsbno_t
*toti
,
2110 xfs_bmdr_block_t
*dib
;
2114 dib
= (xfs_bmdr_block_t
*)XFS_DFORK_PTR(dip
, whichfork
);
2115 if (be16_to_cpu(dib
->bb_level
) >= XFS_BM_MAXLEVELS(mp
, whichfork
)) {
2116 if (!sflag
|| id
->ilist
)
2117 dbprintf(_("level for ino %lld %s fork bmap root too "
2120 whichfork
== XFS_DATA_FORK
? _("data") : _("attr"),
2121 be16_to_cpu(dib
->bb_level
));
2125 if (be16_to_cpu(dib
->bb_numrecs
) >
2126 xfs_bmdr_maxrecs(mp
, XFS_DFORK_SIZE(dip
, mp
, whichfork
),
2127 be16_to_cpu(dib
->bb_level
) == 0)) {
2128 if (!sflag
|| id
->ilist
)
2129 dbprintf(_("numrecs for ino %lld %s fork bmap root too "
2132 whichfork
== XFS_DATA_FORK
? _("data") : _("attr"),
2133 be16_to_cpu(dib
->bb_numrecs
));
2137 if (be16_to_cpu(dib
->bb_level
) == 0) {
2138 xfs_bmbt_rec_t
*rp
= XFS_BMDR_REC_ADDR(dib
, 1);
2139 process_bmbt_reclist(rp
, be16_to_cpu(dib
->bb_numrecs
), type
,
2141 *nex
+= be16_to_cpu(dib
->bb_numrecs
);
2144 pp
= XFS_BMDR_PTR_ADDR(dib
, 1, xfs_bmdr_maxrecs(mp
,
2145 XFS_DFORK_SIZE(dip
, mp
, whichfork
), 0));
2146 for (i
= 0; i
< be16_to_cpu(dib
->bb_numrecs
); i
++)
2147 scan_lbtree(be64_to_cpu(pp
[i
]),
2148 be16_to_cpu(dib
->bb_level
),
2149 scanfunc_bmap
, type
, id
, totd
, toti
,
2151 whichfork
== XFS_DATA_FORK
?
2152 TYP_BMAPBTD
: TYP_BMAPBTA
);
2154 if (*nex
<= XFS_DFORK_SIZE(dip
, mp
, whichfork
) / sizeof(xfs_bmbt_rec_t
)) {
2155 if (!sflag
|| id
->ilist
)
2156 dbprintf(_("extent count for ino %lld %s fork too low "
2157 "(%d) for file format\n"),
2159 whichfork
== XFS_DATA_FORK
? _("data") : _("attr"),
2166 process_data_dir_v2(
2172 freetab_t
**freetabp
)
2174 xfs_dir2_dataptr_t addr
;
2175 xfs_dir2_data_free_t
*bf
;
2177 xfs_dir2_block_t
*block
;
2178 xfs_dir2_block_tail_t
*btp
= NULL
;
2181 xfs_dir2_data_t
*data
;
2183 xfs_dir2_data_entry_t
*dep
;
2184 xfs_dir2_data_free_t
*dfp
;
2185 xfs_dir2_data_unused_t
*dup
;
2192 xfs_dir2_leaf_entry_t
*lep
= NULL
;
2194 xfs_ino_t parent
= 0;
2199 struct xfs_name xname
;
2201 data
= iocur_top
->data
;
2202 block
= iocur_top
->data
;
2203 if (be32_to_cpu(block
->hdr
.magic
) != XFS_DIR2_BLOCK_MAGIC
&&
2204 be32_to_cpu(data
->hdr
.magic
) != XFS_DIR2_DATA_MAGIC
) {
2206 dbprintf(_("bad directory data magic # %#x for dir ino "
2208 be32_to_cpu(data
->hdr
.magic
), id
->ino
, dabno
);
2212 db
= xfs_dir2_da_to_db(mp
, dabno
);
2213 bf
= data
->hdr
.bestfree
;
2214 ptr
= (char *)data
->u
;
2215 if (be32_to_cpu(block
->hdr
.magic
) == XFS_DIR2_BLOCK_MAGIC
) {
2216 btp
= xfs_dir2_block_tail_p(mp
, &block
->hdr
);
2217 lep
= xfs_dir2_block_leaf_p(btp
);
2218 endptr
= (char *)lep
;
2219 if (endptr
<= ptr
|| endptr
> (char *)btp
) {
2220 endptr
= (char *)data
+ mp
->m_dirblksize
;
2223 dbprintf(_("bad block directory tail for dir ino "
2229 endptr
= (char *)data
+ mp
->m_dirblksize
;
2230 bf_err
= lastfree_err
= tag_err
= 0;
2231 count
= lastfree
= freeseen
= 0;
2232 if (be16_to_cpu(bf
[0].length
) == 0) {
2233 bf_err
+= be16_to_cpu(bf
[0].offset
) != 0;
2236 if (be16_to_cpu(bf
[1].length
) == 0) {
2237 bf_err
+= be16_to_cpu(bf
[1].offset
) != 0;
2240 if (be16_to_cpu(bf
[2].length
) == 0) {
2241 bf_err
+= be16_to_cpu(bf
[2].offset
) != 0;
2244 bf_err
+= be16_to_cpu(bf
[0].length
) < be16_to_cpu(bf
[1].length
);
2245 bf_err
+= be16_to_cpu(bf
[1].length
) < be16_to_cpu(bf
[2].length
);
2247 freetab
= *freetabp
;
2248 if (freetab
->naents
<= db
) {
2249 *freetabp
= freetab
=
2250 realloc(freetab
, FREETAB_SIZE(db
+ 1));
2251 for (i
= freetab
->naents
; i
< db
; i
++)
2252 freetab
->ents
[i
] = NULLDATAOFF
;
2253 freetab
->naents
= db
+ 1;
2255 if (freetab
->nents
< db
+ 1)
2256 freetab
->nents
= db
+ 1;
2257 freetab
->ents
[db
] = be16_to_cpu(bf
[0].length
);
2259 while (ptr
< endptr
) {
2260 dup
= (xfs_dir2_data_unused_t
*)ptr
;
2261 if (be16_to_cpu(dup
->freetag
) == XFS_DIR2_DATA_FREE_TAG
) {
2262 lastfree_err
+= lastfree
!= 0;
2263 tagp
= xfs_dir2_data_unused_tag_p(dup
);
2264 if ((be16_to_cpu(dup
->length
) & (XFS_DIR2_DATA_ALIGN
- 1)) ||
2265 be16_to_cpu(dup
->length
) == 0 ||
2266 (char *)tagp
>= endptr
) {
2268 dbprintf(_("dir %lld block %d bad free "
2276 tag_err
+= be16_to_cpu(*tagp
) != (char *)dup
- (char *)data
;
2277 dfp
= process_data_dir_v2_freefind(data
, dup
);
2279 i
= (int)(dfp
- bf
);
2280 bf_err
+= (freeseen
& (1 << i
)) != 0;
2283 bf_err
+= be16_to_cpu(dup
->length
) >
2284 be16_to_cpu(bf
[2].length
);
2285 ptr
+= be16_to_cpu(dup
->length
);
2289 dep
= (xfs_dir2_data_entry_t
*)dup
;
2290 if (dep
->namelen
== 0) {
2292 dbprintf(_("dir %lld block %d zero length entry "
2295 (int)((char *)dep
- (char *)data
));
2298 tagp
= xfs_dir2_data_entry_tag_p(dep
);
2299 if ((char *)tagp
>= endptr
) {
2301 dbprintf(_("dir %lld block %d bad entry at %d\n"),
2303 (int)((char *)dep
- (char *)data
));
2307 tag_err
+= be16_to_cpu(*tagp
) != (char *)dep
- (char *)data
;
2308 addr
= xfs_dir2_db_off_to_dataptr(mp
, db
,
2309 (char *)dep
- (char *)data
);
2310 xname
.name
= dep
->name
;
2311 xname
.len
= dep
->namelen
;
2312 dir_hash_add(mp
->m_dirnameops
->hashname(&xname
), addr
);
2313 ptr
+= xfs_dir2_data_entsize(dep
->namelen
);
2316 lino
= be64_to_cpu(dep
->inumber
);
2317 cid
= find_inode(lino
, 1);
2319 dbprintf(_("dir %lld block %d entry %*.*s %lld\n"),
2320 id
->ino
, dabno
, dep
->namelen
, dep
->namelen
,
2326 dbprintf(_("dir %lld block %d entry %*.*s bad "
2327 "inode number %lld\n"),
2328 id
->ino
, dabno
, dep
->namelen
,
2329 dep
->namelen
, dep
->name
, lino
);
2332 if (dep
->namelen
== 2 && dep
->name
[0] == '.' &&
2333 dep
->name
[1] == '.') {
2336 dbprintf(_("multiple .. entries in dir "
2337 "%lld (%lld, %lld)\n"),
2338 id
->ino
, parent
, lino
);
2341 parent
= cid
? lino
: NULLFSINO
;
2343 } else if (dep
->namelen
!= 1 || dep
->name
[0] != '.') {
2347 addname_inode(cid
, (char *)dep
->name
,
2351 if (lino
!= id
->ino
) {
2353 dbprintf(_("dir %lld entry . inode "
2354 "number mismatch (%lld)\n"),
2361 if (be32_to_cpu(data
->hdr
.magic
) == XFS_DIR2_BLOCK_MAGIC
) {
2362 endptr
= (char *)data
+ mp
->m_dirblksize
;
2363 for (i
= stale
= 0; lep
&& i
< be32_to_cpu(btp
->count
); i
++) {
2364 if ((char *)&lep
[i
] >= endptr
) {
2366 dbprintf(_("dir %lld block %d bad count "
2367 "%u\n"), id
->ino
, dabno
,
2368 be32_to_cpu(btp
->count
));
2372 if (be32_to_cpu(lep
[i
].address
) == XFS_DIR2_NULL_DATAPTR
)
2374 else if (dir_hash_see(be32_to_cpu(lep
[i
].hashval
),
2375 be32_to_cpu(lep
[i
].address
))) {
2377 dbprintf(_("dir %lld block %d extra leaf "
2380 be32_to_cpu(lep
[i
].hashval
),
2381 be32_to_cpu(lep
[i
].address
));
2386 bf_err
+= freeseen
!= 7;
2389 dbprintf(_("dir %lld block %d bad bestfree data\n"),
2393 if (be32_to_cpu(data
->hdr
.magic
) == XFS_DIR2_BLOCK_MAGIC
&&
2394 count
!= be32_to_cpu(btp
->count
) -
2395 be32_to_cpu(btp
->stale
)) {
2397 dbprintf(_("dir %lld block %d bad block tail count %d "
2399 id
->ino
, dabno
, be32_to_cpu(btp
->count
),
2400 be32_to_cpu(btp
->stale
));
2403 if (be32_to_cpu(data
->hdr
.magic
) == XFS_DIR2_BLOCK_MAGIC
&&
2404 stale
!= be32_to_cpu(btp
->stale
)) {
2406 dbprintf(_("dir %lld block %d bad stale tail count %d\n"),
2407 id
->ino
, dabno
, be32_to_cpu(btp
->stale
));
2412 dbprintf(_("dir %lld block %d consecutive free entries\n"),
2418 dbprintf(_("dir %lld block %d entry/unused tag "
2426 static xfs_dir2_data_free_t
*
2427 process_data_dir_v2_freefind(
2428 xfs_dir2_data_t
*data
,
2429 xfs_dir2_data_unused_t
*dup
)
2431 xfs_dir2_data_free_t
*dfp
;
2432 xfs_dir2_data_aoff_t off
;
2434 off
= (xfs_dir2_data_aoff_t
)((char *)dup
- (char *)data
);
2435 if (be16_to_cpu(dup
->length
) < be16_to_cpu(data
->hdr
.
2436 bestfree
[XFS_DIR2_DATA_FD_COUNT
- 1].length
))
2438 for (dfp
= &data
->hdr
.bestfree
[0]; dfp
< &data
->hdr
.
2439 bestfree
[XFS_DIR2_DATA_FD_COUNT
]; dfp
++) {
2440 if (be16_to_cpu(dfp
->offset
) == 0)
2442 if (be16_to_cpu(dfp
->offset
) == off
)
2460 if (process_dir_v2(dip
, blkmap
, &dot
, &dotdot
, id
, &parent
))
2463 bno
= XFS_INO_TO_FSB(mp
, id
->ino
);
2465 if (!sflag
|| id
->ilist
|| CHECK_BLIST(bno
))
2466 dbprintf(_("no . entry for directory %lld\n"), id
->ino
);
2470 if (!sflag
|| id
->ilist
|| CHECK_BLIST(bno
))
2471 dbprintf(_("no .. entry for directory %lld\n"), id
->ino
);
2473 } else if (parent
== id
->ino
&& id
->ino
!= mp
->m_sb
.sb_rootino
) {
2474 if (!sflag
|| id
->ilist
|| CHECK_BLIST(bno
))
2475 dbprintf(_(". and .. same for non-root directory %lld\n"),
2478 } else if (id
->ino
== mp
->m_sb
.sb_rootino
&& id
->ino
!= parent
) {
2479 if (!sflag
|| id
->ilist
|| CHECK_BLIST(bno
))
2480 dbprintf(_("root directory %lld has .. %lld\n"), id
->ino
,
2483 } else if (parent
!= NULLFSINO
&& id
->ino
!= parent
)
2484 addparent_inode(id
, parent
);
2496 xfs_fileoff_t last
= 0;
2497 xfs_fsize_t size
= be64_to_cpu(dip
->di_size
);
2500 last
= blkmap_last_off(blkmap
);
2501 if (size
<= XFS_DFORK_DSIZE(dip
, mp
) &&
2502 dip
->di_format
== XFS_DINODE_FMT_LOCAL
)
2503 *parent
= process_sf_dir_v2(dip
, dot
, dotdot
, id
);
2504 else if (last
== mp
->m_dirblkfsbs
&&
2505 (dip
->di_format
== XFS_DINODE_FMT_EXTENTS
||
2506 dip
->di_format
== XFS_DINODE_FMT_BTREE
))
2507 *parent
= process_block_dir_v2(blkmap
, dot
, dotdot
, id
);
2508 else if (last
>= mp
->m_dirleafblk
+ mp
->m_dirblkfsbs
&&
2509 (dip
->di_format
== XFS_DINODE_FMT_EXTENTS
||
2510 dip
->di_format
== XFS_DINODE_FMT_BTREE
))
2511 *parent
= process_leaf_node_dir_v2(blkmap
, dot
, dotdot
, id
, size
);
2513 dbprintf(_("bad size (%lld) or format (%d) for directory inode "
2515 size
, dip
->di_format
, id
->ino
);
2528 xfs_drfsbno_t
*totd
,
2529 xfs_drfsbno_t
*toti
,
2536 rp
= (xfs_bmbt_rec_t
*)XFS_DFORK_PTR(dip
, whichfork
);
2537 *nex
= XFS_DFORK_NEXTENTS(dip
, whichfork
);
2538 if (*nex
< 0 || *nex
> XFS_DFORK_SIZE(dip
, mp
, whichfork
) /
2539 sizeof(xfs_bmbt_rec_t
)) {
2540 if (!sflag
|| id
->ilist
)
2541 dbprintf(_("bad number of extents %d for inode %lld\n"),
2546 process_bmbt_reclist(rp
, *nex
, type
, id
, totd
, blkmapp
);
2557 xfs_fsblock_t bno
= 0;
2558 xfs_icdinode_t idic
;
2559 inodata_t
*id
= NULL
;
2561 xfs_extnum_t nextents
= 0;
2564 xfs_drfsbno_t totblocks
;
2565 xfs_drfsbno_t totdblocks
= 0;
2566 xfs_drfsbno_t totiblocks
= 0;
2568 xfs_extnum_t anextents
= 0;
2569 xfs_drfsbno_t atotdblocks
= 0;
2570 xfs_drfsbno_t atotiblocks
= 0;
2576 static char okfmts
[] = {
2577 0, /* type 0 unused */
2578 1 << XFS_DINODE_FMT_DEV
, /* FIFO */
2579 1 << XFS_DINODE_FMT_DEV
, /* CHR */
2580 0, /* type 3 unused */
2581 (1 << XFS_DINODE_FMT_LOCAL
) |
2582 (1 << XFS_DINODE_FMT_EXTENTS
) |
2583 (1 << XFS_DINODE_FMT_BTREE
), /* DIR */
2584 0, /* type 5 unused */
2585 1 << XFS_DINODE_FMT_DEV
, /* BLK */
2586 0, /* type 7 unused */
2587 (1 << XFS_DINODE_FMT_EXTENTS
) |
2588 (1 << XFS_DINODE_FMT_BTREE
), /* REG */
2589 0, /* type 9 unused */
2590 (1 << XFS_DINODE_FMT_LOCAL
) |
2591 (1 << XFS_DINODE_FMT_EXTENTS
), /* LNK */
2592 0, /* type 11 unused */
2593 1 << XFS_DINODE_FMT_DEV
, /* SOCK */
2594 0, /* type 13 unused */
2595 1 << XFS_DINODE_FMT_UUID
, /* MNT */
2596 0 /* type 15 unused */
2598 static char *fmtnames
[] = {
2599 "dev", "local", "extents", "btree", "uuid"
2602 libxfs_dinode_from_disk(&idic
, dip
);
2604 ino
= XFS_AGINO_TO_INO(mp
, be32_to_cpu(agf
->agf_seqno
), agino
);
2606 id
= find_inode(ino
, 1);
2607 bno
= XFS_INO_TO_FSB(mp
, ino
);
2610 v
= (!sflag
|| (id
&& id
->ilist
) || CHECK_BLIST(bno
));
2611 if (idic
.di_magic
!= XFS_DINODE_MAGIC
) {
2613 dbprintf(_("bad magic number %#x for inode %lld\n"),
2614 idic
.di_magic
, ino
);
2618 if (!XFS_DINODE_GOOD_VERSION(idic
.di_version
)) {
2620 dbprintf(_("bad version number %#x for inode %lld\n"),
2621 idic
.di_version
, ino
);
2626 if (idic
.di_nblocks
!= 0) {
2628 dbprintf(_("bad nblocks %lld for free inode "
2630 idic
.di_nblocks
, ino
);
2633 if (idic
.di_version
== 1)
2634 nlink
= idic
.di_onlink
;
2636 nlink
= idic
.di_nlink
;
2639 dbprintf(_("bad nlink %d for free inode %lld\n"),
2643 if (idic
.di_mode
!= 0) {
2645 dbprintf(_("bad mode %#o for free inode %lld\n"),
2652 if (be32_to_cpu(dip
->di_next_unlinked
) != NULLAGINO
) {
2654 dbprintf(_("bad next unlinked %#x for inode %lld\n"),
2655 be32_to_cpu(dip
->di_next_unlinked
), ino
);
2659 * di_mode is a 16-bit uint so no need to check the < 0 case
2661 if ((((idic
.di_mode
& S_IFMT
) >> 12) > 15) ||
2662 (!(okfmts
[(idic
.di_mode
& S_IFMT
) >> 12] & (1 << idic
.di_format
)))) {
2664 dbprintf(_("bad format %d for inode %lld type %#o\n"),
2665 idic
.di_format
, id
->ino
, idic
.di_mode
& S_IFMT
);
2669 if ((unsigned int)XFS_DFORK_ASIZE(dip
, mp
) >= XFS_LITINO(mp
)) {
2671 dbprintf(_("bad fork offset %d for inode %lld\n"),
2672 idic
.di_forkoff
, id
->ino
);
2676 if ((unsigned int)idic
.di_aformat
> XFS_DINODE_FMT_BTREE
) {
2678 dbprintf(_("bad attribute format %d for inode %lld\n"),
2679 idic
.di_aformat
, id
->ino
);
2683 if (verbose
|| (id
&& id
->ilist
) || CHECK_BLIST(bno
))
2684 dbprintf(_("inode %lld mode %#o fmt %s "
2686 "nex %d anex %d nblk %lld sz %lld%s%s%s%s%s%s%s\n"),
2687 id
->ino
, idic
.di_mode
, fmtnames
[(int)idic
.di_format
],
2688 fmtnames
[(int)idic
.di_aformat
],
2691 idic
.di_nblocks
, idic
.di_size
,
2692 idic
.di_flags
& XFS_DIFLAG_REALTIME
? " rt" : "",
2693 idic
.di_flags
& XFS_DIFLAG_PREALLOC
? " pre" : "",
2694 idic
.di_flags
& XFS_DIFLAG_IMMUTABLE
? " imm" : "",
2695 idic
.di_flags
& XFS_DIFLAG_APPEND
? " app" : "",
2696 idic
.di_flags
& XFS_DIFLAG_SYNC
? " syn" : "",
2697 idic
.di_flags
& XFS_DIFLAG_NOATIME
? " noa" : "",
2698 idic
.di_flags
& XFS_DIFLAG_NODUMP
? " nod" : "");
2700 switch (idic
.di_mode
& S_IFMT
) {
2703 if (idic
.di_format
== XFS_DINODE_FMT_LOCAL
)
2705 blkmap
= blkmap_alloc(idic
.di_nextents
);
2708 if (idic
.di_flags
& XFS_DIFLAG_REALTIME
)
2710 else if (id
->ino
== mp
->m_sb
.sb_rbmino
) {
2711 type
= DBM_RTBITMAP
;
2712 blkmap
= blkmap_alloc(idic
.di_nextents
);
2714 } else if (id
->ino
== mp
->m_sb
.sb_rsumino
) {
2716 blkmap
= blkmap_alloc(idic
.di_nextents
);
2719 else if (id
->ino
== mp
->m_sb
.sb_uquotino
||
2720 id
->ino
== mp
->m_sb
.sb_gquotino
) {
2722 blkmap
= blkmap_alloc(idic
.di_nextents
);
2727 if (idic
.di_mode
& (S_ISUID
| S_ISGID
))
2738 if (idic
.di_version
== 1)
2739 setlink_inode(id
, idic
.di_onlink
, type
== DBM_DIR
, security
);
2741 sbversion
|= XFS_SB_VERSION_NLINKBIT
;
2742 setlink_inode(id
, idic
.di_nlink
, type
== DBM_DIR
, security
);
2744 switch (idic
.di_format
) {
2745 case XFS_DINODE_FMT_LOCAL
:
2746 process_lclinode(id
, dip
, type
, &totdblocks
, &totiblocks
,
2747 &nextents
, &blkmap
, XFS_DATA_FORK
);
2749 case XFS_DINODE_FMT_EXTENTS
:
2750 process_exinode(id
, dip
, type
, &totdblocks
, &totiblocks
,
2751 &nextents
, &blkmap
, XFS_DATA_FORK
);
2753 case XFS_DINODE_FMT_BTREE
:
2754 process_btinode(id
, dip
, type
, &totdblocks
, &totiblocks
,
2755 &nextents
, &blkmap
, XFS_DATA_FORK
);
2758 if (XFS_DFORK_Q(dip
)) {
2759 sbversion
|= XFS_SB_VERSION_ATTRBIT
;
2760 switch (idic
.di_aformat
) {
2761 case XFS_DINODE_FMT_LOCAL
:
2762 process_lclinode(id
, dip
, DBM_ATTR
, &atotdblocks
,
2763 &atotiblocks
, &anextents
, NULL
, XFS_ATTR_FORK
);
2765 case XFS_DINODE_FMT_EXTENTS
:
2766 process_exinode(id
, dip
, DBM_ATTR
, &atotdblocks
,
2767 &atotiblocks
, &anextents
, NULL
, XFS_ATTR_FORK
);
2769 case XFS_DINODE_FMT_BTREE
:
2770 process_btinode(id
, dip
, DBM_ATTR
, &atotdblocks
,
2771 &atotiblocks
, &anextents
, NULL
, XFS_ATTR_FORK
);
2775 if (qgdo
|| qpdo
|| qudo
) {
2783 bc
= totdblocks
+ totiblocks
+
2784 atotdblocks
+ atotiblocks
;
2788 bc
= totiblocks
+ atotdblocks
+ atotiblocks
;
2796 dqprid
= xfs_get_projid(&idic
); /* dquot ID is u32 */
2797 quota_add(&dqprid
, &idic
.di_gid
, &idic
.di_uid
,
2801 totblocks
= totdblocks
+ totiblocks
+ atotdblocks
+ atotiblocks
;
2802 if (totblocks
!= idic
.di_nblocks
) {
2804 dbprintf(_("bad nblocks %lld for inode %lld, counted "
2806 idic
.di_nblocks
, id
->ino
, totblocks
);
2809 if (nextents
!= idic
.di_nextents
) {
2811 dbprintf(_("bad nextents %d for inode %lld, counted %d\n"),
2812 idic
.di_nextents
, id
->ino
, nextents
);
2815 if (anextents
!= idic
.di_anextents
) {
2817 dbprintf(_("bad anextents %d for inode %lld, counted "
2819 idic
.di_anextents
, id
->ino
, anextents
);
2822 if (type
== DBM_DIR
)
2823 process_dir(dip
, blkmap
, id
);
2824 else if (type
== DBM_RTBITMAP
)
2825 process_rtbitmap(blkmap
);
2826 else if (type
== DBM_RTSUM
)
2827 process_rtsummary(blkmap
);
2829 * If the CHKD flag is not set, this can legitimately contain garbage;
2830 * xfs_repair may have cleared that bit.
2832 else if (type
== DBM_QUOTA
) {
2833 if (id
->ino
== mp
->m_sb
.sb_uquotino
&&
2834 (mp
->m_sb
.sb_qflags
& XFS_UQUOTA_ACCT
) &&
2835 (mp
->m_sb
.sb_qflags
& XFS_UQUOTA_CHKD
))
2836 process_quota(IS_USER_QUOTA
, id
, blkmap
);
2837 else if (id
->ino
== mp
->m_sb
.sb_gquotino
&&
2838 (mp
->m_sb
.sb_qflags
& XFS_GQUOTA_ACCT
) &&
2839 (mp
->m_sb
.sb_qflags
& XFS_OQUOTA_CHKD
))
2840 process_quota(IS_GROUP_QUOTA
, id
, blkmap
);
2841 else if (id
->ino
== mp
->m_sb
.sb_gquotino
&&
2842 (mp
->m_sb
.sb_qflags
& XFS_PQUOTA_ACCT
) &&
2843 (mp
->m_sb
.sb_qflags
& XFS_OQUOTA_CHKD
))
2844 process_quota(IS_PROJECT_QUOTA
, id
, blkmap
);
2847 blkmap_free(blkmap
);
2856 xfs_drfsbno_t
*totd
,
2857 xfs_drfsbno_t
*toti
,
2862 xfs_attr_shortform_t
*asf
;
2865 bno
= XFS_INO_TO_FSB(mp
, id
->ino
);
2866 if (whichfork
== XFS_DATA_FORK
&& be64_to_cpu(dip
->di_size
) >
2867 XFS_DFORK_DSIZE(dip
, mp
)) {
2868 if (!sflag
|| id
->ilist
|| CHECK_BLIST(bno
))
2869 dbprintf(_("local inode %lld data is too large (size "
2871 id
->ino
, be64_to_cpu(dip
->di_size
));
2874 else if (whichfork
== XFS_ATTR_FORK
) {
2875 asf
= (xfs_attr_shortform_t
*)XFS_DFORK_APTR(dip
);
2876 if (be16_to_cpu(asf
->hdr
.totsize
) > XFS_DFORK_ASIZE(dip
, mp
)) {
2877 if (!sflag
|| id
->ilist
|| CHECK_BLIST(bno
))
2878 dbprintf(_("local inode %lld attr is too large "
2880 id
->ino
, be16_to_cpu(asf
->hdr
.totsize
));
2887 process_leaf_node_dir_v2(
2892 xfs_fsize_t dirsize
)
2908 v2
= verbose
|| id
->ilist
;
2911 freetab
= malloc(FREETAB_SIZE(dirsize
/ mp
->m_dirblksize
));
2912 freetab
->naents
= (int)(dirsize
/ mp
->m_dirblksize
);
2914 for (i
= 0; i
< freetab
->naents
; i
++)
2915 freetab
->ents
[i
] = NULLDATAOFF
;
2917 while ((dbno
= blkmap_next_off(blkmap
, dbno
, &t
)) != NULLFILEOFF
) {
2918 nex
= blkmap_getn(blkmap
, dbno
, mp
->m_dirblkfsbs
, &bmp
);
2920 for (v
= v2
, x
= 0; !v
&& x
< nex
; x
++) {
2921 for (b
= bmp
[x
].startblock
;
2922 !v
&& b
< bmp
[x
].startblock
+ bmp
[x
].blockcount
;
2927 dbprintf(_("dir inode %lld block %u=%llu\n"), id
->ino
,
2929 (xfs_dfsbno_t
)bmp
->startblock
);
2932 make_bbmap(&bbmap
, nex
, bmp
);
2933 set_cur(&typtab
[TYP_DIR2
], XFS_FSB_TO_DADDR(mp
, bmp
->startblock
),
2934 mp
->m_dirblkfsbs
* blkbb
, DB_RING_IGN
,
2935 nex
> 1 ? &bbmap
: NULL
);
2937 if (iocur_top
->data
== NULL
) {
2939 dbprintf(_("can't read block %u for directory "
2941 (__uint32_t
)dbno
, id
->ino
);
2944 dbno
+= mp
->m_dirblkfsbs
- 1;
2947 if (dbno
< mp
->m_dirleafblk
) {
2948 lino
= process_data_dir_v2(dot
, dotdot
, id
, v
,
2949 (xfs_dablk_t
)dbno
, &freetab
);
2953 dbprintf(_("multiple .. entries "
2960 } else if (dbno
< mp
->m_dirfreeblk
) {
2961 process_leaf_node_dir_v2_int(id
, v
, (xfs_dablk_t
)dbno
,
2964 process_leaf_node_dir_v2_free(id
, v
, (xfs_dablk_t
)dbno
,
2968 dbno
+= mp
->m_dirblkfsbs
- 1;
2970 dir_hash_check(id
, v
);
2972 for (i
= 0; i
< freetab
->nents
; i
++) {
2973 if (freetab
->ents
[i
] != NULLDATAOFF
) {
2975 dbprintf(_("missing free index for data block %d "
2976 "in dir ino %lld\n"),
2977 xfs_dir2_db_to_da(mp
, i
), id
->ino
);
2986 process_leaf_node_dir_v2_free(
2992 xfs_dir2_data_off_t ent
;
2993 xfs_dir2_free_t
*free
;
2998 free
= iocur_top
->data
;
2999 if (be32_to_cpu(free
->hdr
.magic
) != XFS_DIR2_FREE_MAGIC
) {
3001 dbprintf(_("bad free block magic # %#x for dir ino %lld "
3003 be32_to_cpu(free
->hdr
.magic
), id
->ino
, dabno
);
3007 maxent
= xfs_dir2_free_max_bests(mp
);
3008 if (be32_to_cpu(free
->hdr
.firstdb
) != xfs_dir2_da_to_db(mp
,
3009 dabno
- mp
->m_dirfreeblk
) * maxent
) {
3011 dbprintf(_("bad free block firstdb %d for dir ino %lld "
3013 be32_to_cpu(free
->hdr
.firstdb
), id
->ino
, dabno
);
3017 if (be32_to_cpu(free
->hdr
.nvalid
) > maxent
||
3018 be32_to_cpu(free
->hdr
.nvalid
) < 0 ||
3019 be32_to_cpu(free
->hdr
.nused
) > maxent
||
3020 be32_to_cpu(free
->hdr
.nused
) < 0 ||
3021 be32_to_cpu(free
->hdr
.nused
) >
3022 be32_to_cpu(free
->hdr
.nvalid
)) {
3024 dbprintf(_("bad free block nvalid/nused %d/%d for dir "
3025 "ino %lld block %d\n"),
3026 be32_to_cpu(free
->hdr
.nvalid
),
3027 be32_to_cpu(free
->hdr
.nused
), id
->ino
, dabno
);
3031 for (used
= i
= 0; i
< be32_to_cpu(free
->hdr
.nvalid
); i
++) {
3032 if (freetab
->nents
<= be32_to_cpu(free
->hdr
.firstdb
) + i
)
3035 ent
= freetab
->ents
[be32_to_cpu(free
->hdr
.firstdb
) + i
];
3036 if (ent
!= be16_to_cpu(free
->bests
[i
])) {
3038 dbprintf(_("bad free block ent %d is %d should "
3039 "be %d for dir ino %lld block %d\n"),
3040 i
, be16_to_cpu(free
->bests
[i
]), ent
,
3044 if (be16_to_cpu(free
->bests
[i
]) != NULLDATAOFF
)
3046 if (ent
!= NULLDATAOFF
)
3047 freetab
->ents
[be32_to_cpu(free
->hdr
.firstdb
) + i
] =
3050 if (used
!= be32_to_cpu(free
->hdr
.nused
)) {
3052 dbprintf(_("bad free block nused %d should be %d for dir "
3053 "ino %lld block %d\n"),
3054 be32_to_cpu(free
->hdr
.nused
), used
, id
->ino
,
3061 process_leaf_node_dir_v2_int(
3069 xfs_dir2_leaf_t
*leaf
;
3070 xfs_dir2_leaf_entry_t
*lep
;
3071 xfs_dir2_leaf_tail_t
*ltp
;
3072 xfs_da_intnode_t
*node
;
3075 leaf
= iocur_top
->data
;
3076 switch (be16_to_cpu(leaf
->hdr
.info
.magic
)) {
3077 case XFS_DIR2_LEAF1_MAGIC
:
3078 if (be32_to_cpu(leaf
->hdr
.info
.forw
) ||
3079 be32_to_cpu(leaf
->hdr
.info
.back
)) {
3081 dbprintf(_("bad leaf block forw/back pointers "
3082 "%d/%d for dir ino %lld block %d\n"),
3083 be32_to_cpu(leaf
->hdr
.info
.forw
),
3084 be32_to_cpu(leaf
->hdr
.info
.back
),
3088 if (dabno
!= mp
->m_dirleafblk
) {
3090 dbprintf(_("single leaf block for dir ino %lld "
3091 "block %d should be at block %d\n"),
3093 (xfs_dablk_t
)mp
->m_dirleafblk
);
3096 ltp
= xfs_dir2_leaf_tail_p(mp
, leaf
);
3097 lbp
= xfs_dir2_leaf_bests_p(ltp
);
3098 for (i
= 0; i
< be32_to_cpu(ltp
->bestcount
); i
++) {
3099 if (freetab
->nents
<= i
|| freetab
->ents
[i
] !=
3100 be16_to_cpu(lbp
[i
])) {
3102 dbprintf(_("bestfree %d for dir ino %lld "
3103 "block %d doesn't match table "
3105 freetab
->nents
<= i
?
3109 xfs_dir2_db_to_da(mp
, i
),
3110 be16_to_cpu(lbp
[i
]));
3112 if (freetab
->nents
> i
)
3113 freetab
->ents
[i
] = NULLDATAOFF
;
3116 case XFS_DIR2_LEAFN_MAGIC
:
3117 /* if it's at the root location then we can check the
3118 * pointers are null XXX */
3120 case XFS_DA_NODE_MAGIC
:
3121 node
= iocur_top
->data
;
3122 if (be16_to_cpu(node
->hdr
.level
) < 1 ||
3123 be16_to_cpu(node
->hdr
.level
) >
3124 XFS_DA_NODE_MAXDEPTH
) {
3126 dbprintf(_("bad node block level %d for dir ino "
3128 be16_to_cpu(node
->hdr
.level
), id
->ino
,
3135 dbprintf(_("bad directory data magic # %#x for dir ino "
3137 be16_to_cpu(leaf
->hdr
.info
.magic
), id
->ino
,
3143 for (i
= stale
= 0; i
< be16_to_cpu(leaf
->hdr
.count
); i
++) {
3144 if (be32_to_cpu(lep
[i
].address
) == XFS_DIR2_NULL_DATAPTR
)
3146 else if (dir_hash_see(be32_to_cpu(lep
[i
].hashval
),
3147 be32_to_cpu(lep
[i
].address
))) {
3149 dbprintf(_("dir %lld block %d extra leaf entry "
3150 "%x %x\n"), id
->ino
, dabno
,
3151 be32_to_cpu(lep
[i
].hashval
),
3152 be32_to_cpu(lep
[i
].address
));
3156 if (stale
!= be16_to_cpu(leaf
->hdr
.stale
)) {
3158 dbprintf(_("dir %lld block %d stale mismatch "
3160 id
->ino
, dabno
, stale
,
3161 be16_to_cpu(leaf
->hdr
.stale
));
3176 u_int8_t exp_flags
= 0;
3187 exp_flags
= XFS_DQ_USER
;
3189 case IS_PROJECT_QUOTA
:
3191 exp_flags
= XFS_DQ_PROJ
;
3193 case IS_GROUP_QUOTA
:
3195 exp_flags
= XFS_DQ_GROUP
;
3201 perblock
= (uint
)(mp
->m_sb
.sb_blocksize
/ sizeof(*dqb
));
3204 while ((qbno
= blkmap_next_off(blkmap
, qbno
, &t
)) != NULLFILEOFF
) {
3205 bno
= blkmap_get(blkmap
, qbno
);
3206 dqid
= (xfs_dqid_t
)qbno
* perblock
;
3207 cb
= CHECK_BLIST(bno
);
3208 scicb
= !sflag
|| id
->ilist
|| cb
;
3210 set_cur(&typtab
[TYP_DQBLK
], XFS_FSB_TO_DADDR(mp
, bno
), blkbb
,
3212 if ((dqb
= iocur_top
->data
) == NULL
) {
3214 dbprintf(_("can't read block %lld for %s quota "
3215 "inode (fsblock %lld)\n"),
3216 (xfs_dfiloff_t
)qbno
, s
,
3222 for (i
= 0; i
< perblock
; i
++, dqid
++, dqb
++) {
3223 if (verbose
|| id
->ilist
|| cb
)
3224 dbprintf(_("%s dqblk %lld entry %d id %u bc "
3225 "%lld ic %lld rc %lld\n"),
3226 s
, (xfs_dfiloff_t
)qbno
, i
, dqid
,
3227 be64_to_cpu(dqb
->dd_diskdq
.d_bcount
),
3228 be64_to_cpu(dqb
->dd_diskdq
.d_icount
),
3229 be64_to_cpu(dqb
->dd_diskdq
.d_rtbcount
));
3230 if (be16_to_cpu(dqb
->dd_diskdq
.d_magic
) != XFS_DQUOT_MAGIC
) {
3232 dbprintf(_("bad magic number %#x for %s "
3233 "dqblk %lld entry %d id %u\n"),
3234 be16_to_cpu(dqb
->dd_diskdq
.d_magic
), s
,
3235 (xfs_dfiloff_t
)qbno
, i
, dqid
);
3239 if (dqb
->dd_diskdq
.d_version
!= XFS_DQUOT_VERSION
) {
3241 dbprintf(_("bad version number %#x for "
3242 "%s dqblk %lld entry %d id "
3244 dqb
->dd_diskdq
.d_version
, s
,
3245 (xfs_dfiloff_t
)qbno
, i
, dqid
);
3249 if (dqb
->dd_diskdq
.d_flags
!= exp_flags
) {
3251 dbprintf(_("bad flags %#x for %s dqblk "
3252 "%lld entry %d id %u\n"),
3253 dqb
->dd_diskdq
.d_flags
, s
,
3254 (xfs_dfiloff_t
)qbno
, i
, dqid
);
3258 if (be32_to_cpu(dqb
->dd_diskdq
.d_id
) != dqid
) {
3260 dbprintf(_("bad id %u for %s dqblk %lld "
3261 "entry %d id %u\n"),
3262 be32_to_cpu(dqb
->dd_diskdq
.d_id
), s
,
3263 (xfs_dfiloff_t
)qbno
, i
, dqid
);
3267 quota_add((qtype
== IS_PROJECT_QUOTA
) ? &dqid
: NULL
,
3268 (qtype
== IS_GROUP_QUOTA
) ? &dqid
: NULL
,
3269 (qtype
== IS_USER_QUOTA
) ? &dqid
: NULL
,
3271 be64_to_cpu(dqb
->dd_diskdq
.d_bcount
),
3272 be64_to_cpu(dqb
->dd_diskdq
.d_icount
),
3273 be64_to_cpu(dqb
->dd_diskdq
.d_rtbcount
));
3285 xfs_fileoff_t bmbno
;
3292 xfs_drfsbno_t rtbno
;
3296 xfs_rtword_t
*words
;
3298 bitsperblock
= mp
->m_sb
.sb_blocksize
* NBBY
;
3299 bit
= extno
= prevbit
= start_bmbno
= start_bit
= 0;
3300 bmbno
= NULLFILEOFF
;
3301 while ((bmbno
= blkmap_next_off(blkmap
, bmbno
, &t
)) !=
3303 bno
= blkmap_get(blkmap
, bmbno
);
3304 if (bno
== NULLFSBLOCK
) {
3306 dbprintf(_("block %lld for rtbitmap inode is "
3308 (xfs_dfiloff_t
)bmbno
);
3313 set_cur(&typtab
[TYP_RTBITMAP
], XFS_FSB_TO_DADDR(mp
, bno
), blkbb
,
3315 if ((words
= iocur_top
->data
) == NULL
) {
3317 dbprintf(_("can't read block %lld for rtbitmap "
3319 (xfs_dfiloff_t
)bmbno
);
3325 bit
< bitsperblock
&& extno
< mp
->m_sb
.sb_rextents
;
3327 if (xfs_isset(words
, bit
)) {
3328 rtbno
= extno
* mp
->m_sb
.sb_rextsize
;
3329 set_rdbmap(rtbno
, mp
->m_sb
.sb_rextsize
,
3333 start_bmbno
= (int)bmbno
;
3337 } else if (prevbit
== 1) {
3338 len
= ((int)bmbno
- start_bmbno
) *
3339 bitsperblock
+ (bit
- start_bit
);
3340 log
= XFS_RTBLOCKLOG(len
);
3341 offs
= XFS_SUMOFFS(mp
, log
, start_bmbno
);
3347 if (extno
== mp
->m_sb
.sb_rextents
)
3351 len
= ((int)bmbno
- start_bmbno
) * bitsperblock
+
3353 log
= XFS_RTBLOCKLOG(len
);
3354 offs
= XFS_SUMOFFS(mp
, log
, start_bmbno
);
3365 xfs_fileoff_t sumbno
;
3368 sumbno
= NULLFILEOFF
;
3369 while ((sumbno
= blkmap_next_off(blkmap
, sumbno
, &t
)) != NULLFILEOFF
) {
3370 bno
= blkmap_get(blkmap
, sumbno
);
3371 if (bno
== NULLFSBLOCK
) {
3373 dbprintf(_("block %lld for rtsummary inode is "
3375 (xfs_dfiloff_t
)sumbno
);
3380 set_cur(&typtab
[TYP_RTSUMMARY
], XFS_FSB_TO_DADDR(mp
, bno
),
3381 blkbb
, DB_RING_IGN
, NULL
);
3382 if ((bytes
= iocur_top
->data
) == NULL
) {
3384 dbprintf(_("can't read block %lld for rtsummary "
3386 (xfs_dfiloff_t
)sumbno
);
3391 memcpy((char *)sumfile
+ sumbno
* mp
->m_sb
.sb_blocksize
, bytes
,
3392 mp
->m_sb
.sb_blocksize
);
3410 xfs_dir2_sf_entry_t
*sfe
;
3413 sf
= (xfs_dir2_sf_t
*)XFS_DFORK_DPTR(dip
);
3415 v
= verbose
|| id
->ilist
;
3417 dbprintf(_("dir %lld entry . %lld\n"), id
->ino
, id
->ino
);
3419 sfe
= xfs_dir2_sf_firstentry(&sf
->hdr
);
3420 offset
= XFS_DIR2_DATA_FIRST_OFFSET
;
3421 for (i
= sf
->hdr
.count
- 1, i8
= 0; i
>= 0; i
--) {
3422 if ((__psint_t
)sfe
+ xfs_dir2_sf_entsize(&sf
->hdr
,sfe
->namelen
) -
3423 (__psint_t
)sf
> be64_to_cpu(dip
->di_size
)) {
3425 dbprintf(_("dir %llu bad size in entry at %d\n"),
3427 (int)((char *)sfe
- (char *)sf
));
3431 lino
= xfs_dir2_sfe_get_ino(&sf
->hdr
, sfe
);
3432 if (lino
> XFS_DIR2_MAX_SHORT_INUM
)
3434 cid
= find_inode(lino
, 1);
3437 dbprintf(_("dir %lld entry %*.*s bad inode "
3439 id
->ino
, sfe
->namelen
, sfe
->namelen
,
3446 addname_inode(cid
, (char *)sfe
->name
, sfe
->namelen
);
3449 dbprintf(_("dir %lld entry %*.*s offset %d %lld\n"),
3450 id
->ino
, sfe
->namelen
, sfe
->namelen
, sfe
->name
,
3451 xfs_dir2_sf_get_offset(sfe
), lino
);
3452 if (xfs_dir2_sf_get_offset(sfe
) < offset
) {
3454 dbprintf(_("dir %lld entry %*.*s bad offset %d\n"),
3455 id
->ino
, sfe
->namelen
, sfe
->namelen
,
3456 sfe
->name
, xfs_dir2_sf_get_offset(sfe
));
3460 xfs_dir2_sf_get_offset(sfe
) +
3461 xfs_dir2_sf_entsize(&sf
->hdr
, sfe
->namelen
);
3462 sfe
= xfs_dir2_sf_nextentry(&sf
->hdr
, sfe
);
3464 if (i
< 0 && (__psint_t
)sfe
- (__psint_t
)sf
!=
3465 be64_to_cpu(dip
->di_size
)) {
3467 dbprintf(_("dir %llu size is %lld, should be %u\n"),
3468 id
->ino
, be64_to_cpu(dip
->di_size
),
3469 (uint
)((char *)sfe
- (char *)sf
));
3472 if (offset
+ (sf
->hdr
.count
+ 2) * sizeof(xfs_dir2_leaf_entry_t
) +
3473 sizeof(xfs_dir2_block_tail_t
) > mp
->m_dirblksize
) {
3475 dbprintf(_("dir %llu offsets too high\n"), id
->ino
);
3478 lino
= xfs_dir2_sf_get_parent_ino(&sf
->hdr
);
3479 if (lino
> XFS_DIR2_MAX_SHORT_INUM
)
3481 cid
= find_inode(lino
, 1);
3486 dbprintf(_("dir %lld entry .. bad inode number %lld\n"),
3491 dbprintf(_("dir %lld entry .. %lld\n"), id
->ino
, lino
);
3492 if (i8
!= sf
->hdr
.i8count
) {
3494 dbprintf(_("dir %lld i8count mismatch is %d should be "
3496 id
->ino
, sf
->hdr
.i8count
, i8
);
3500 return cid
? lino
: NULLFSINO
;
3514 if (qudo
&& usrid
!= NULL
)
3515 quota_add1(qudata
, *usrid
, dq
, bc
, ic
, rc
);
3516 if (qgdo
&& grpid
!= NULL
)
3517 quota_add1(qgdata
, *grpid
, dq
, bc
, ic
, rc
);
3518 if (qpdo
&& prjid
!= NULL
)
3519 quota_add1(qpdata
, *prjid
, dq
, bc
, ic
, rc
);
3535 qh
= (int)(id
% QDATA_HASH_SIZE
);
3539 qi
= dq
? &qe
->dq
: &qe
->count
;
3547 qe
= xmalloc(sizeof(*qe
));
3549 qi
= dq
? &qe
->dq
: &qe
->count
;
3553 qi
= dq
? &qe
->count
: &qe
->dq
;
3554 qi
->bc
= qi
->ic
= qi
->rc
= 0;
3568 for (i
= 0; i
< QDATA_HASH_SIZE
; i
++) {
3572 if (qp
->count
.bc
!= qp
->dq
.bc
||
3573 qp
->count
.ic
!= qp
->dq
.ic
||
3574 qp
->count
.rc
!= qp
->dq
.rc
) {
3576 dbprintf(_("%s quota id %u, have/exp"),
3578 if (qp
->count
.bc
!= qp
->dq
.bc
)
3579 dbprintf(_(" bc %lld/%lld"),
3582 if (qp
->count
.ic
!= qp
->dq
.ic
)
3583 dbprintf(_(" ic %lld/%lld"),
3586 if (qp
->count
.rc
!= qp
->dq
.rc
)
3587 dbprintf(_(" rc %lld/%lld"),
3604 qudo
= mp
->m_sb
.sb_uquotino
!= 0 &&
3605 mp
->m_sb
.sb_uquotino
!= NULLFSINO
&&
3606 (mp
->m_sb
.sb_qflags
& XFS_UQUOTA_ACCT
) &&
3607 (mp
->m_sb
.sb_qflags
& XFS_UQUOTA_CHKD
);
3608 qgdo
= mp
->m_sb
.sb_gquotino
!= 0 &&
3609 mp
->m_sb
.sb_gquotino
!= NULLFSINO
&&
3610 (mp
->m_sb
.sb_qflags
& XFS_GQUOTA_ACCT
) &&
3611 (mp
->m_sb
.sb_qflags
& XFS_OQUOTA_CHKD
);
3612 qpdo
= mp
->m_sb
.sb_gquotino
!= 0 &&
3613 mp
->m_sb
.sb_gquotino
!= NULLFSINO
&&
3614 (mp
->m_sb
.sb_qflags
& XFS_PQUOTA_ACCT
) &&
3615 (mp
->m_sb
.sb_qflags
& XFS_OQUOTA_CHKD
);
3617 qudata
= xcalloc(QDATA_HASH_SIZE
, sizeof(qdata_t
*));
3619 qgdata
= xcalloc(QDATA_HASH_SIZE
, sizeof(qdata_t
*));
3621 qpdata
= xcalloc(QDATA_HASH_SIZE
, sizeof(qdata_t
*));
3626 xfs_agnumber_t agno
)
3632 xfs_sb_t
*sb
= &tsb
;
3634 agffreeblks
= agflongest
= 0;
3636 agicount
= agifreecount
= 0;
3637 push_cur(); /* 1 pushed */
3638 set_cur(&typtab
[TYP_SB
],
3639 XFS_AG_DADDR(mp
, agno
, XFS_SB_DADDR
),
3640 XFS_FSS_TO_BB(mp
, 1), DB_RING_IGN
, NULL
);
3642 if (!iocur_top
->data
) {
3643 dbprintf(_("can't read superblock for ag %u\n"), agno
);
3648 libxfs_sb_from_disk(sb
, iocur_top
->data
);
3650 if (sb
->sb_magicnum
!= XFS_SB_MAGIC
) {
3652 dbprintf(_("bad sb magic # %#x in ag %u\n"),
3653 sb
->sb_magicnum
, agno
);
3656 if (!xfs_sb_good_version(sb
)) {
3658 dbprintf(_("bad sb version # %#x in ag %u\n"),
3659 sb
->sb_versionnum
, agno
);
3663 if (!lazycount
&& xfs_sb_version_haslazysbcount(sb
)) {
3666 if (agno
== 0 && sb
->sb_inprogress
!= 0) {
3668 dbprintf(_("mkfs not completed successfully\n"));
3671 set_dbmap(agno
, XFS_SB_BLOCK(mp
), 1, DBM_SB
, agno
, XFS_SB_BLOCK(mp
));
3672 if (sb
->sb_logstart
&& XFS_FSB_TO_AGNO(mp
, sb
->sb_logstart
) == agno
)
3673 set_dbmap(agno
, XFS_FSB_TO_AGBNO(mp
, sb
->sb_logstart
),
3674 sb
->sb_logblocks
, DBM_LOG
, agno
, XFS_SB_BLOCK(mp
));
3675 push_cur(); /* 2 pushed */
3676 set_cur(&typtab
[TYP_AGF
],
3677 XFS_AG_DADDR(mp
, agno
, XFS_AGF_DADDR(mp
)),
3678 XFS_FSS_TO_BB(mp
, 1), DB_RING_IGN
, NULL
);
3679 if ((agf
= iocur_top
->data
) == NULL
) {
3680 dbprintf(_("can't read agf block for ag %u\n"), agno
);
3684 if (be32_to_cpu(agf
->agf_magicnum
) != XFS_AGF_MAGIC
) {
3686 dbprintf(_("bad agf magic # %#x in ag %u\n"),
3687 be32_to_cpu(agf
->agf_magicnum
), agno
);
3690 if (!XFS_AGF_GOOD_VERSION(be32_to_cpu(agf
->agf_versionnum
))) {
3692 dbprintf(_("bad agf version # %#x in ag %u\n"),
3693 be32_to_cpu(agf
->agf_versionnum
), agno
);
3696 if (XFS_SB_BLOCK(mp
) != XFS_AGF_BLOCK(mp
))
3697 set_dbmap(agno
, XFS_AGF_BLOCK(mp
), 1, DBM_AGF
, agno
,
3699 if (sb
->sb_agblocks
> be32_to_cpu(agf
->agf_length
))
3700 set_dbmap(agno
, be32_to_cpu(agf
->agf_length
),
3701 sb
->sb_agblocks
- be32_to_cpu(agf
->agf_length
),
3702 DBM_MISSING
, agno
, XFS_SB_BLOCK(mp
));
3703 push_cur(); /* 3 pushed */
3704 set_cur(&typtab
[TYP_AGI
],
3705 XFS_AG_DADDR(mp
, agno
, XFS_AGI_DADDR(mp
)),
3706 XFS_FSS_TO_BB(mp
, 1), DB_RING_IGN
, NULL
);
3707 if ((agi
= iocur_top
->data
) == NULL
) {
3708 dbprintf(_("can't read agi block for ag %u\n"), agno
);
3712 if (be32_to_cpu(agi
->agi_magicnum
) != XFS_AGI_MAGIC
) {
3714 dbprintf(_("bad agi magic # %#x in ag %u\n"),
3715 be32_to_cpu(agi
->agi_magicnum
), agno
);
3718 if (!XFS_AGI_GOOD_VERSION(be32_to_cpu(agi
->agi_versionnum
))) {
3720 dbprintf(_("bad agi version # %#x in ag %u\n"),
3721 be32_to_cpu(agi
->agi_versionnum
), agno
);
3724 if (XFS_SB_BLOCK(mp
) != XFS_AGI_BLOCK(mp
) &&
3725 XFS_AGF_BLOCK(mp
) != XFS_AGI_BLOCK(mp
))
3726 set_dbmap(agno
, XFS_AGI_BLOCK(mp
), 1, DBM_AGI
, agno
,
3731 be32_to_cpu(agf
->agf_roots
[XFS_BTNUM_BNO
]),
3732 be32_to_cpu(agf
->agf_levels
[XFS_BTNUM_BNO
]),
3733 1, scanfunc_bno
, TYP_BNOBT
);
3736 be32_to_cpu(agf
->agf_roots
[XFS_BTNUM_CNT
]),
3737 be32_to_cpu(agf
->agf_levels
[XFS_BTNUM_CNT
]),
3738 1, scanfunc_cnt
, TYP_CNTBT
);
3740 be32_to_cpu(agi
->agi_root
),
3741 be32_to_cpu(agi
->agi_level
),
3742 1, scanfunc_ino
, TYP_INOBT
);
3743 if (be32_to_cpu(agf
->agf_freeblks
) != agffreeblks
) {
3745 dbprintf(_("agf_freeblks %u, counted %u in ag %u\n"),
3746 be32_to_cpu(agf
->agf_freeblks
),
3750 if (be32_to_cpu(agf
->agf_longest
) != agflongest
) {
3752 dbprintf(_("agf_longest %u, counted %u in ag %u\n"),
3753 be32_to_cpu(agf
->agf_longest
),
3758 be32_to_cpu(agf
->agf_btreeblks
) != agfbtreeblks
) {
3760 dbprintf(_("agf_btreeblks %u, counted %u in ag %u\n"),
3761 be32_to_cpu(agf
->agf_btreeblks
),
3762 agfbtreeblks
, agno
);
3765 agf_aggr_freeblks
+= agffreeblks
+ agfbtreeblks
;
3766 if (be32_to_cpu(agi
->agi_count
) != agicount
) {
3768 dbprintf(_("agi_count %u, counted %u in ag %u\n"),
3769 be32_to_cpu(agi
->agi_count
),
3773 if (be32_to_cpu(agi
->agi_freecount
) != agifreecount
) {
3775 dbprintf(_("agi_freecount %u, counted %u in ag %u\n"),
3776 be32_to_cpu(agi
->agi_freecount
),
3777 agifreecount
, agno
);
3780 for (i
= 0; i
< XFS_AGI_UNLINKED_BUCKETS
; i
++) {
3781 if (be32_to_cpu(agi
->agi_unlinked
[i
]) != NULLAGINO
) {
3783 xfs_agino_t agino
=be32_to_cpu(agi
->agi_unlinked
[i
]);
3784 dbprintf(_("agi unlinked bucket %d is %u in ag "
3785 "%u (inode=%lld)\n"), i
, agino
, agno
,
3786 XFS_AGINO_TO_INO(mp
, agno
, agino
));
3803 xfs_agnumber_t seqno
= be32_to_cpu(agf
->agf_seqno
);
3809 if (XFS_SB_BLOCK(mp
) != XFS_AGFL_BLOCK(mp
) &&
3810 XFS_AGF_BLOCK(mp
) != XFS_AGFL_BLOCK(mp
) &&
3811 XFS_AGI_BLOCK(mp
) != XFS_AGFL_BLOCK(mp
))
3812 set_dbmap(seqno
, XFS_AGFL_BLOCK(mp
), 1, DBM_AGFL
, seqno
,
3814 if (be32_to_cpu(agf
->agf_flcount
) == 0)
3817 set_cur(&typtab
[TYP_AGFL
],
3818 XFS_AG_DADDR(mp
, seqno
, XFS_AGFL_DADDR(mp
)),
3819 XFS_FSS_TO_BB(mp
, 1), DB_RING_IGN
, NULL
);
3820 if ((agfl
= iocur_top
->data
) == NULL
) {
3821 dbprintf(_("can't read agfl block for ag %u\n"), seqno
);
3826 i
= be32_to_cpu(agf
->agf_flfirst
);
3828 /* verify agf values before proceeding */
3829 if (be32_to_cpu(agf
->agf_flfirst
) >= XFS_AGFL_SIZE(mp
) ||
3830 be32_to_cpu(agf
->agf_fllast
) >= XFS_AGFL_SIZE(mp
)) {
3831 dbprintf(_("agf %d freelist blocks bad, skipping "
3832 "freelist scan\n"), i
);
3839 bno
= be32_to_cpu(agfl
->agfl_bno
[i
]);
3840 set_dbmap(seqno
, bno
, 1, DBM_FREELIST
, seqno
,
3841 XFS_AGFL_BLOCK(mp
));
3843 if (i
== be32_to_cpu(agf
->agf_fllast
))
3845 if (++i
== XFS_AGFL_SIZE(mp
))
3848 if (count
!= be32_to_cpu(agf
->agf_flcount
)) {
3850 dbprintf(_("freeblk count %u != flcount %u in ag %u\n"),
3851 count
, be32_to_cpu(agf
->agf_flcount
),
3856 agf_aggr_freeblks
+= count
;
3864 scan_lbtree_f_t func
,
3867 xfs_drfsbno_t
*totd
,
3868 xfs_drfsbno_t
*toti
,
3875 set_cur(&typtab
[btype
], XFS_FSB_TO_DADDR(mp
, root
), blkbb
, DB_RING_IGN
,
3877 if (iocur_top
->data
== NULL
) {
3879 dbprintf(_("can't read btree block %u/%u\n"),
3880 XFS_FSB_TO_AGNO(mp
, root
),
3881 XFS_FSB_TO_AGBNO(mp
, root
));
3886 (*func
)(iocur_top
->data
, nlevels
- 1, type
, root
, id
, totd
, toti
, nex
,
3887 blkmapp
, isroot
, btype
);
3897 scan_sbtree_f_t func
,
3900 xfs_agnumber_t seqno
= be32_to_cpu(agf
->agf_seqno
);
3903 set_cur(&typtab
[btype
],
3904 XFS_AGB_TO_DADDR(mp
, seqno
, root
), blkbb
, DB_RING_IGN
, NULL
);
3905 if (iocur_top
->data
== NULL
) {
3907 dbprintf(_("can't read btree block %u/%u\n"), seqno
, root
);
3912 (*func
)(iocur_top
->data
, nlevels
- 1, agf
, root
, isroot
);
3918 struct xfs_btree_block
*block
,
3923 xfs_drfsbno_t
*totd
,
3924 xfs_drfsbno_t
*toti
,
3930 xfs_agblock_t agbno
;
3931 xfs_agnumber_t agno
;
3936 agno
= XFS_FSB_TO_AGNO(mp
, bno
);
3937 agbno
= XFS_FSB_TO_AGBNO(mp
, bno
);
3938 if (be32_to_cpu(block
->bb_magic
) != XFS_BMAP_MAGIC
) {
3939 if (!sflag
|| id
->ilist
|| CHECK_BLIST(bno
))
3940 dbprintf(_("bad magic # %#x in inode %lld bmbt block "
3942 be32_to_cpu(block
->bb_magic
), id
->ino
, agno
, agbno
);
3945 if (be16_to_cpu(block
->bb_level
) != level
) {
3946 if (!sflag
|| id
->ilist
|| CHECK_BLIST(bno
))
3947 dbprintf(_("expected level %d got %d in inode %lld bmbt "
3949 level
, be16_to_cpu(block
->bb_level
), id
->ino
, agno
, agbno
);
3952 set_dbmap(agno
, agbno
, 1, type
, agno
, agbno
);
3953 set_inomap(agno
, agbno
, 1, id
);
3956 if (be16_to_cpu(block
->bb_numrecs
) > mp
->m_bmap_dmxr
[0] ||
3957 (isroot
== 0 && be16_to_cpu(block
->bb_numrecs
) < mp
->m_bmap_dmnr
[0])) {
3958 if (!sflag
|| id
->ilist
|| CHECK_BLIST(bno
))
3959 dbprintf(_("bad btree nrecs (%u, min=%u, max=%u) "
3960 "in inode %lld bmap block %lld\n"),
3961 be16_to_cpu(block
->bb_numrecs
), mp
->m_bmap_dmnr
[0],
3962 mp
->m_bmap_dmxr
[0], id
->ino
,
3967 rp
= XFS_BMBT_REC_ADDR(mp
, block
, 1);
3968 *nex
+= be16_to_cpu(block
->bb_numrecs
);
3969 process_bmbt_reclist(rp
, be16_to_cpu(block
->bb_numrecs
), type
, id
, totd
,
3973 if (be16_to_cpu(block
->bb_numrecs
) > mp
->m_bmap_dmxr
[1] ||
3974 (isroot
== 0 && be16_to_cpu(block
->bb_numrecs
) < mp
->m_bmap_dmnr
[1])) {
3975 if (!sflag
|| id
->ilist
|| CHECK_BLIST(bno
))
3976 dbprintf(_("bad btree nrecs (%u, min=%u, max=%u) in "
3977 "inode %lld bmap block %lld\n"),
3978 be16_to_cpu(block
->bb_numrecs
), mp
->m_bmap_dmnr
[1],
3979 mp
->m_bmap_dmxr
[1], id
->ino
, (xfs_dfsbno_t
)bno
);
3983 pp
= XFS_BMBT_PTR_ADDR(mp
, block
, 1, mp
->m_bmap_dmxr
[0]);
3984 for (i
= 0; i
< be16_to_cpu(block
->bb_numrecs
); i
++)
3985 scan_lbtree(be64_to_cpu(pp
[i
]), level
, scanfunc_bmap
, type
, id
,
3986 totd
, toti
, nex
, blkmapp
, 0, btype
);
3991 struct xfs_btree_block
*block
,
3998 xfs_alloc_ptr_t
*pp
;
3999 xfs_alloc_rec_t
*rp
;
4000 xfs_agnumber_t seqno
= be32_to_cpu(agf
->agf_seqno
);
4001 xfs_agblock_t lastblock
;
4003 if (be32_to_cpu(block
->bb_magic
) != XFS_ABTB_MAGIC
) {
4004 dbprintf(_("bad magic # %#x in btbno block %u/%u\n"),
4005 be32_to_cpu(block
->bb_magic
), seqno
, bno
);
4011 if (be16_to_cpu(block
->bb_level
) != level
) {
4013 dbprintf(_("expected level %d got %d in btbno block "
4015 level
, be16_to_cpu(block
->bb_level
), seqno
, bno
);
4018 set_dbmap(seqno
, bno
, 1, DBM_BTBNO
, seqno
, bno
);
4020 if (be16_to_cpu(block
->bb_numrecs
) > mp
->m_alloc_mxr
[0] ||
4021 (isroot
== 0 && be16_to_cpu(block
->bb_numrecs
) < mp
->m_alloc_mnr
[0])) {
4022 dbprintf(_("bad btree nrecs (%u, min=%u, max=%u) in "
4023 "btbno block %u/%u\n"),
4024 be16_to_cpu(block
->bb_numrecs
), mp
->m_alloc_mnr
[0],
4025 mp
->m_alloc_mxr
[0], seqno
, bno
);
4029 rp
= XFS_ALLOC_REC_ADDR(mp
, block
, 1);
4031 for (i
= 0; i
< be16_to_cpu(block
->bb_numrecs
); i
++) {
4032 set_dbmap(seqno
, be32_to_cpu(rp
[i
].ar_startblock
),
4033 be32_to_cpu(rp
[i
].ar_blockcount
), DBM_FREE1
,
4035 if (be32_to_cpu(rp
[i
].ar_startblock
) <= lastblock
) {
4037 "out-of-order bno btree record %d (%u %u) block %u/%u\n"),
4038 i
, be32_to_cpu(rp
[i
].ar_startblock
),
4039 be32_to_cpu(rp
[i
].ar_blockcount
),
4040 be32_to_cpu(agf
->agf_seqno
), bno
);
4043 lastblock
= be32_to_cpu(rp
[i
].ar_startblock
);
4048 if (be16_to_cpu(block
->bb_numrecs
) > mp
->m_alloc_mxr
[1] ||
4049 (isroot
== 0 && be16_to_cpu(block
->bb_numrecs
) < mp
->m_alloc_mnr
[1])) {
4050 dbprintf(_("bad btree nrecs (%u, min=%u, max=%u) in btbno block "
4052 be16_to_cpu(block
->bb_numrecs
), mp
->m_alloc_mnr
[1],
4053 mp
->m_alloc_mxr
[1], seqno
, bno
);
4057 pp
= XFS_ALLOC_PTR_ADDR(mp
, block
, 1, mp
->m_alloc_mxr
[1]);
4058 for (i
= 0; i
< be16_to_cpu(block
->bb_numrecs
); i
++)
4059 scan_sbtree(agf
, be32_to_cpu(pp
[i
]), level
, 0, scanfunc_bno
, TYP_BNOBT
);
4064 struct xfs_btree_block
*block
,
4070 xfs_agnumber_t seqno
= be32_to_cpu(agf
->agf_seqno
);
4072 xfs_alloc_ptr_t
*pp
;
4073 xfs_alloc_rec_t
*rp
;
4074 xfs_extlen_t lastcount
;
4076 if (be32_to_cpu(block
->bb_magic
) != XFS_ABTC_MAGIC
) {
4077 dbprintf(_("bad magic # %#x in btcnt block %u/%u\n"),
4078 be32_to_cpu(block
->bb_magic
), seqno
, bno
);
4084 if (be16_to_cpu(block
->bb_level
) != level
) {
4086 dbprintf(_("expected level %d got %d in btcnt block "
4088 level
, be16_to_cpu(block
->bb_level
), seqno
, bno
);
4091 set_dbmap(seqno
, bno
, 1, DBM_BTCNT
, seqno
, bno
);
4093 if (be16_to_cpu(block
->bb_numrecs
) > mp
->m_alloc_mxr
[0] ||
4094 (isroot
== 0 && be16_to_cpu(block
->bb_numrecs
) < mp
->m_alloc_mnr
[0])) {
4095 dbprintf(_("bad btree nrecs (%u, min=%u, max=%u) in "
4096 "btbno block %u/%u\n"),
4097 be16_to_cpu(block
->bb_numrecs
), mp
->m_alloc_mnr
[0],
4098 mp
->m_alloc_mxr
[0], seqno
, bno
);
4102 rp
= XFS_ALLOC_REC_ADDR(mp
, block
, 1);
4104 for (i
= 0; i
< be16_to_cpu(block
->bb_numrecs
); i
++) {
4105 check_set_dbmap(seqno
, be32_to_cpu(rp
[i
].ar_startblock
),
4106 be32_to_cpu(rp
[i
].ar_blockcount
), DBM_FREE1
, DBM_FREE2
,
4108 fdblocks
+= be32_to_cpu(rp
[i
].ar_blockcount
);
4109 agffreeblks
+= be32_to_cpu(rp
[i
].ar_blockcount
);
4110 if (be32_to_cpu(rp
[i
].ar_blockcount
) > agflongest
)
4111 agflongest
= be32_to_cpu(rp
[i
].ar_blockcount
);
4112 if (be32_to_cpu(rp
[i
].ar_blockcount
) < lastcount
) {
4114 "out-of-order cnt btree record %d (%u %u) block %u/%u\n"),
4115 i
, be32_to_cpu(rp
[i
].ar_startblock
),
4116 be32_to_cpu(rp
[i
].ar_blockcount
),
4117 be32_to_cpu(agf
->agf_seqno
), bno
);
4119 lastcount
= be32_to_cpu(rp
[i
].ar_blockcount
);
4124 if (be16_to_cpu(block
->bb_numrecs
) > mp
->m_alloc_mxr
[1] ||
4125 (isroot
== 0 && be16_to_cpu(block
->bb_numrecs
) < mp
->m_alloc_mnr
[1])) {
4126 dbprintf(_("bad btree nrecs (%u, min=%u, max=%u) in btbno block "
4128 be16_to_cpu(block
->bb_numrecs
), mp
->m_alloc_mnr
[1],
4129 mp
->m_alloc_mxr
[1], seqno
, bno
);
4133 pp
= XFS_ALLOC_PTR_ADDR(mp
, block
, 1, mp
->m_alloc_mxr
[1]);
4134 for (i
= 0; i
< be16_to_cpu(block
->bb_numrecs
); i
++)
4135 scan_sbtree(agf
, be32_to_cpu(pp
[i
]), level
, 0, scanfunc_cnt
, TYP_CNTBT
);
4140 struct xfs_btree_block
*block
,
4147 xfs_agnumber_t seqno
= be32_to_cpu(agf
->agf_seqno
);
4153 xfs_inobt_ptr_t
*pp
;
4154 xfs_inobt_rec_t
*rp
;
4156 if (be32_to_cpu(block
->bb_magic
) != XFS_IBT_MAGIC
) {
4157 dbprintf(_("bad magic # %#x in inobt block %u/%u\n"),
4158 be32_to_cpu(block
->bb_magic
), seqno
, bno
);
4162 if (be16_to_cpu(block
->bb_level
) != level
) {
4164 dbprintf(_("expected level %d got %d in inobt block "
4166 level
, be16_to_cpu(block
->bb_level
), seqno
, bno
);
4169 set_dbmap(seqno
, bno
, 1, DBM_BTINO
, seqno
, bno
);
4171 if (be16_to_cpu(block
->bb_numrecs
) > mp
->m_inobt_mxr
[0] ||
4172 (isroot
== 0 && be16_to_cpu(block
->bb_numrecs
) < mp
->m_inobt_mnr
[0])) {
4173 dbprintf(_("bad btree nrecs (%u, min=%u, max=%u) in "
4174 "inobt block %u/%u\n"),
4175 be16_to_cpu(block
->bb_numrecs
), mp
->m_inobt_mnr
[0],
4176 mp
->m_inobt_mxr
[0], seqno
, bno
);
4180 rp
= XFS_INOBT_REC_ADDR(mp
, block
, 1);
4181 for (i
= 0; i
< be16_to_cpu(block
->bb_numrecs
); i
++) {
4182 agino
= be32_to_cpu(rp
[i
].ir_startino
);
4183 off
= XFS_INO_TO_OFFSET(mp
, agino
);
4185 if ((sbversion
& XFS_SB_VERSION_ALIGNBIT
) &&
4186 mp
->m_sb
.sb_inoalignmt
&&
4187 (XFS_INO_TO_AGBNO(mp
, agino
) %
4188 mp
->m_sb
.sb_inoalignmt
))
4189 sbversion
&= ~XFS_SB_VERSION_ALIGNBIT
;
4190 set_dbmap(seqno
, XFS_AGINO_TO_AGBNO(mp
, agino
),
4191 (xfs_extlen_t
)MAX(1,
4192 XFS_INODES_PER_CHUNK
>>
4193 mp
->m_sb
.sb_inopblog
),
4194 DBM_INODE
, seqno
, bno
);
4196 icount
+= XFS_INODES_PER_CHUNK
;
4197 agicount
+= XFS_INODES_PER_CHUNK
;
4198 ifree
+= be32_to_cpu(rp
[i
].ir_freecount
);
4199 agifreecount
+= be32_to_cpu(rp
[i
].ir_freecount
);
4201 set_cur(&typtab
[TYP_INODE
],
4202 XFS_AGB_TO_DADDR(mp
, seqno
,
4203 XFS_AGINO_TO_AGBNO(mp
, agino
)),
4204 (int)XFS_FSB_TO_BB(mp
, XFS_IALLOC_BLOCKS(mp
)),
4206 if (iocur_top
->data
== NULL
) {
4208 dbprintf(_("can't read inode block "
4211 XFS_AGINO_TO_AGBNO(mp
, agino
));
4216 for (j
= 0, nfree
= 0; j
< XFS_INODES_PER_CHUNK
; j
++) {
4217 isfree
= XFS_INOBT_IS_FREE_DISK(&rp
[i
], j
);
4220 process_inode(agf
, agino
+ j
,
4221 (xfs_dinode_t
*)((char *)iocur_top
->data
+ ((off
+ j
) << mp
->m_sb
.sb_inodelog
)),
4224 if (nfree
!= be32_to_cpu(rp
[i
].ir_freecount
)) {
4226 dbprintf(_("ir_freecount/free mismatch, "
4227 "inode chunk %u/%u, freecount "
4230 be32_to_cpu(rp
[i
].ir_freecount
), nfree
);
4237 if (be16_to_cpu(block
->bb_numrecs
) > mp
->m_inobt_mxr
[1] ||
4238 (isroot
== 0 && be16_to_cpu(block
->bb_numrecs
) < mp
->m_inobt_mnr
[1])) {
4239 dbprintf(_("bad btree nrecs (%u, min=%u, max=%u) in inobt block "
4241 be16_to_cpu(block
->bb_numrecs
), mp
->m_inobt_mnr
[1],
4242 mp
->m_inobt_mxr
[1], seqno
, bno
);
4246 pp
= XFS_INOBT_PTR_ADDR(mp
, block
, 1, mp
->m_inobt_mxr
[1]);
4247 for (i
= 0; i
< be16_to_cpu(block
->bb_numrecs
); i
++)
4248 scan_sbtree(agf
, be32_to_cpu(pp
[i
]), level
, 0, scanfunc_ino
, TYP_INOBT
);
4253 xfs_agnumber_t agno
,
4254 xfs_agblock_t agbno
,
4257 xfs_agnumber_t c_agno
,
4258 xfs_agblock_t c_agbno
)
4260 check_set_dbmap(agno
, agbno
, len
, DBM_UNKNOWN
, type
, c_agno
, c_agbno
);
4265 xfs_agnumber_t agno
,
4266 xfs_agblock_t agbno
,
4274 if (!check_inomap(agno
, agbno
, len
, id
->ino
))
4276 mayprint
= verbose
| id
->ilist
| blist_size
;
4277 for (i
= 0, idp
= &inomap
[agno
][agbno
]; i
< len
; i
++, idp
++) {
4280 (verbose
|| id
->ilist
|| CHECK_BLISTA(agno
, agbno
+ i
)))
4281 dbprintf(_("setting inode to %lld for block %u/%u\n"),
4282 id
->ino
, agno
, agbno
+ i
);
4292 check_set_rdbmap(bno
, len
, DBM_UNKNOWN
, type
);
4305 if (!check_rinomap(bno
, len
, id
->ino
))
4307 mayprint
= verbose
| id
->ilist
| blist_size
;
4308 for (i
= 0, idp
= &inomap
[mp
->m_sb
.sb_agcount
][bno
];
4312 if (mayprint
&& (verbose
|| id
->ilist
|| CHECK_BLIST(bno
+ i
)))
4313 dbprintf(_("setting inode to %lld for rtblock %llu\n"),
4325 id
->link_set
= nlink
;
4327 id
->security
= security
;
4328 if (verbose
|| id
->ilist
)
4329 dbprintf(_("inode %lld nlink %u %s dir\n"), id
->ino
, nlink
,
4330 isdir
? "is" : "not");