-
Notifications
You must be signed in to change notification settings - Fork 0
/
xfs_info.py
1741 lines (1467 loc) · 58.2 KB
/
xfs_info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
from __future__ import print_function
#from fs_lib import *
#from misc.percpu import get_per_cpu
from pykdump.API import *
try:
from pykdump.Generic import SUInfo
except:
from pykdump.datatypes import SUInfo
from LinuxDump.Tasks import TaskTable
from LinuxDump.inet.proto import *
from libs.sorenson import *
from fs_lib import *
#import ppstruct_vars
def ntohll(x):
if sys.byteorder == 'little':
return (
((x << 56) & 0xff00000000000000) |
((x << 40) & 0x00ff000000000000) |
((x << 24) & 0x0000ff0000000000) |
((x << 8) & 0x000000ff00000000) |
((x >> 8) & 0x00000000ff000000) |
((x >> 24) & 0x0000000000ff0000) |
((x >> 40) & 0x000000000000ff00) |
(x >> 56) & 0x000000000000000ff)
else:
return x
def htonll(x):
return ntohll(x)
BBSHIFT = 9
BBSIZE = (1 << BBSHIFT)
BBMASK = (BBSIZE - 1)
XFS_SB_MAGIC = 0x58465342 # /* 'XFSB' */
XFS_SB_VERSION_1 = 1 # /* 5.3, 6.0.1, 6.1 */
XFS_SB_VERSION_2 = 2 # /* 6.2 - attributes */
XFS_SB_VERSION_3 = 3 # /* 6.2 - new inode version */
XFS_SB_VERSION_4 = 4 # /* 6.2+ - bitmask version */
XFS_SB_VERSION_5 = 5 # /* CRC enabled filesystem */
__XFS_SB_VERSION_FLAGS = '''
#define XFS_SB_VERSION_NUMBITS 0x000f
#define XFS_SB_VERSION_ALLFBITS 0xfff0
#define XFS_SB_VERSION_ATTRBIT 0x0010
#define XFS_SB_VERSION_NLINKBIT 0x0020
#define XFS_SB_VERSION_QUOTABIT 0x0040
#define XFS_SB_VERSION_ALIGNBIT 0x0080
#define XFS_SB_VERSION_DALIGNBIT 0x0100
#define XFS_SB_VERSION_SHAREDBIT 0x0200
#define XFS_SB_VERSION_LOGV2BIT 0x0400
#define XFS_SB_VERSION_SECTORBIT 0x0800
#define XFS_SB_VERSION_EXTFLGBIT 0x1000
#define XFS_SB_VERSION_DIRV2BIT 0x2000
#define XFS_SB_VERSION_BORGBIT 0x4000 /* ASCII only case-insens. */
#define XFS_SB_VERSION_MOREBITSBIT 0x8000
'''
XFS_SB_VERSION_FLAGS = CDefine(__XFS_SB_VERSION_FLAGS)
XFS_TRANS_HEADER_MAGIC = 0x5452414e # /* TRAN */
XFS_BMAP_MAGIC = 0x424d4150 # /* 'BMAP' */
XFS_BMAP_CRC_MAGIC = 0x424d4133 # /* 'BMA3' */
XFS_AGF_MAGIC = 0x58414746 # /* 'XAGF' */
XFS_AGI_MAGIC = 0x58414749 # /* 'XAGI' */
XFS_AGFL_MAGIC = 0x5841464c # /* 'XAFL' */
XFS_DINODE_MAGIC = 0x494e # /* 'IN' */
XFS_DQUOT_MAGIC = 0x4451 # /* 'DQ' */
XFS_SYMLINK_MAGIC = 0x58534c4d # /* XSLM */
XFS_ABTB_MAGIC = 0x41425442 # /* 'ABTB' for bno tree */
XFS_ABTB_CRC_MAGIC = 423342 # /* 'AB3B' */
XFS_ABTC_MAGIC = 0x41425443 # /* 'ABTC' for cnt tree */
XFS_ABTC_CRC_MAGIC = 423343 # /* 'AB3C' */
XFS_IBT_MAGIC = 0x49414254 # /* 'IABT' */
XFS_IBT_CRC_MAGIC = 9414233 # /* 'IAB3' */
XFS_FIBT_MAGIC = 0x46494254 # /* 'FIBT' */
XFS_FIBT_CRC_MAGIC = 494233 # /* 'FIB3' */
def indent_str(lvl):
return "{spaces}".format(spaces = ' ' * 4 * lvl)
def indent(lvl):
print(indent_str(lvl), end="")
#define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
def XFS_SB_VERSION_NUM(sbp):
return sbp.sb_versionnum & XFS_SB_VERSION_FLAGS['XFS_SB_VERSION_NUMBITS']
# return sbp.sb_versionnum & XFS_SB_VERSION_NUMBITS
def xfs_sb_version(sbp, flagname):
flagname = "XFS_SB_VERSION_" + flagname
return sbp.sb_versionnum & XFS_SB_VERSION_FLAGS[flagname]
__XFS_SB_VERSION2_FLAGS = '''
#define XFS_SB_VERSION2_RESERVED1BIT 0x00000001
#define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000002 /* Superblk counters */
#define XFS_SB_VERSION2_RESERVED4BIT 0x00000004
#define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */
#define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* parent pointers */
#define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32 bit project id */
#define XFS_SB_VERSION2_CRCBIT 0x00000100 /* metadata CRCs */
#define XFS_SB_VERSION2_FTYPE 0x00000200 /* inode type in dir */
#define XFS_SB_VERSION2_OKBITS \
(XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
XFS_SB_VERSION2_ATTR2BIT | \
XFS_SB_VERSION2_PROJID32BIT | \
XFS_SB_VERSION2_FTYPE)
'''
XFS_SB_VERSION2_FLAGS = CDefine(__XFS_SB_VERSION2_FLAGS)
def xfs_sb_version2(sbp, flagname):
flagname = "XFS_SB_VERSION2_" + flagname
return sbp.sb_features2 & XFS_SB_VERSION2_FLAGS[flagname]
__XFS_SB_FEAT_FLAGS_orig = '''
#define XFS_SB_FEAT_COMPAT_ALL 0
#define XFS_SB_FEAT_COMPAT_UNKNOWN ~XFS_SB_FEAT_COMPAT_ALL
#define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0) /* free inode btree */
#define XFS_SB_FEAT_RO_COMPAT_RMAPBT (1 << 1) /* reverse map btree */
#define XFS_SB_FEAT_RO_COMPAT_REFLINK (1 << 2) /* reflinked files */
#define XFS_SB_FEAT_RO_COMPAT_ALL \
(XFS_SB_FEAT_RO_COMPAT_FINOBT | \
XFS_SB_FEAT_RO_COMPAT_RMAPBT | \
XFS_SB_FEAT_RO_COMPAT_REFLINK)
#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL
#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */
#define XFS_SB_FEAT_INCOMPAT_SPINODES (1 << 1) /* sparse inode chunks */
#define XFS_SB_FEAT_INCOMPAT_META_UUID (1 << 2) /* metadata UUID */
#define XFS_SB_FEAT_INCOMPAT_ALL \
(XFS_SB_FEAT_INCOMPAT_FTYPE| \
XFS_SB_FEAT_INCOMPAT_SPINODES| \
XFS_SB_FEAT_INCOMPAT_META_UUID)
#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL
#define XFS_SB_FEAT_INCOMPAT_LOG_ALL 0
#define XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_LOG_ALL
'''
__XFS_SB_FEAT_FLAGS = '''
#define XFS_SB_FEAT_COMPAT_ALL 0
#define XFS_SB_FEAT_COMPAT_UNKNOWN 0xffffffffffffffff
#define XFS_SB_FEAT_RO_COMPAT_FINOBT 0x1
#define XFS_SB_FEAT_RO_COMPAT_RMAPBT 0x2
#define XFS_SB_FEAT_RO_COMPAT_REFLINK 0x4
#define XFS_SB_FEAT_RO_COMPAT_ALL 0x7
#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN 0xfffffffffffffff8
#define XFS_SB_FEAT_INCOMPAT_FTYPE 0x1
#define XFS_SB_FEAT_INCOMPAT_SPINODES 0x2
#define XFS_SB_FEAT_INCOMPAT_META_UUID 0x4
#define XFS_SB_FEAT_INCOMPAT_ALL 0x7
#define XFS_SB_FEAT_INCOMPAT_UNKNOWN 0xfffffffffffffff8
#define XFS_SB_FEAT_INCOMPAT_LOG_ALL 0
#define XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN 0xffffffffffffffff
'''
XFS_SB_FEAT_FLAGS = CDefine(__XFS_SB_FEAT_FLAGS)
def xfs_sb_hasfeat(sbp, flagname):
flagname = "XFS_SB_FEAT_" + flagname
return "?"
def xfs_sb_has_compat_feat(sbp, flagname):
flagname = "XFS_SB_FEAT_COMPAT_" .flagname
if sbp.sb_features_compat & XFS_SB_FEAT_FLAGS[flagname]: return 1
return 0
def xfs_sb_has_ro_compat_feat(sbp, flagname):
flagname = "XFS_SB_FEAT_RO_COMPAT_" + flagname
if sbp.sb_features_ro_compat & XFS_SB_FEAT_FLAGS[flagname]: return 1
return 0
def xfs_sb_has_incompat_feat(sbp, flagname):
try:
flagname = "XFS_SB_FEAT_INCOMPAT_" + flagname
# print("XFS_SB_FEAT_FLAGS = {}".format(XFS_SB_FEAT_FLAGS))
if sbp.sb_features_incompat & XFS_SB_FEAT_FLAGS[flagname]: return 1
except:
pass
return 0
def xfs_sb_has_incompat_log_feat(sbp, flagname):
flagname = "XFS_SB_FEAT_INCOMPAT_LOG_" + flagname
if sbp.sb_features_log_incompat & XFS_SB_FEAT_INCOMPAT_LOG_FLAGS[flagname]: return 1
return 0
def xfs_sb_version_hasreflink(sbp):
if XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 and xfs_sb_has_ro_compat_feat(sbp, "REFLINK"): return 1
return 0
#from libxfs/xfs_fs.h in xfsprogs
__XFS_FSOP_GEOM_FLAGS = '''
#define XFS_FSOP_GEOM_VERSION 0
#define XFS_FSOP_GEOM_FLAGS_ATTR 0x0001 /* attributes in use */
#define XFS_FSOP_GEOM_FLAGS_NLINK 0x0002 /* 32-bit nlink values */
#define XFS_FSOP_GEOM_FLAGS_QUOTA 0x0004 /* quotas enabled */
#define XFS_FSOP_GEOM_FLAGS_IALIGN 0x0008 /* inode alignment */
#define XFS_FSOP_GEOM_FLAGS_DALIGN 0x0010 /* large data alignment */
#define XFS_FSOP_GEOM_FLAGS_SHARED 0x0020 /* read-only shared */
#define XFS_FSOP_GEOM_FLAGS_EXTFLG 0x0040 /* special extent flag */
#define XFS_FSOP_GEOM_FLAGS_DIRV2 0x0080 /* directory version 2 */
#define XFS_FSOP_GEOM_FLAGS_LOGV2 0x0100 /* log format version 2 */
#define XFS_FSOP_GEOM_FLAGS_SECTOR 0x0200 /* sector sizes >1BB */
#define XFS_FSOP_GEOM_FLAGS_ATTR2 0x0400 /* inline attributes rework */
#define XFS_FSOP_GEOM_FLAGS_PROJID32 0x0800 /* 32-bit project IDs */
#define XFS_FSOP_GEOM_FLAGS_DIRV2CI 0x1000 /* ASCII only CI names */
#define XFS_FSOP_GEOM_FLAGS_LAZYSB 0x4000 /* lazy superblock counters */
#define XFS_FSOP_GEOM_FLAGS_V5SB 0x8000 /* version 5 superblock */
#define XFS_FSOP_GEOM_FLAGS_FTYPE 0x10000 /* inode directory types */
#define XFS_FSOP_GEOM_FLAGS_FINOBT 0x20000 /* free inode btree */
#define XFS_FSOP_GEOM_FLAGS_SPINODES 0x40000 /* sparse inode chunks */
#define XFS_FSOP_GEOM_FLAGS_RMAPBT 0x80000 /* reverse mapping btree */
#define XFS_FSOP_GEOM_FLAGS_REFLINK 0x100000 /* files can share blocks */
'''
XFS_FSOP_GEOM_FLAGS = CDefine(__XFS_FSOP_GEOM_FLAGS)
def xfs_sb_version_hasmorebits(sbp):
if XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5:
return 1
elif sbp.sb_versionnum & XFS_SB_VERSION_FLAGS['XFS_SB_VERSION_MOREBITSBIT']:
return 1
return 0
def xfs_sb_version_hascrc(sbp):
if XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5:
return 1
return 0
def xfs_sb_version_hasfinobt(sbp):
if XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 and xfs_sb_has_ro_compat_feat(sbp, 'FINOBT'):
return 1
return 0
def xfs_sb_version_hasprojid32bit(sbp):
sbp = readSU("struct xfs_sb", sbp)
if XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5:
return 1
if xfs_sb_version_hasmorebits(sbp) and xfs_sb_version2(sbp, 'PROJID32BIT'):
return 1
return 0
def xfs_sb_version_hasftype(sbp):
if XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 and xfs_sb_has_incompat_feat(sbp, "FTYPE"):
return 1
if xfs_sb_version(sbp, "MOREBITSBIT") and xfs_sb_version2(sbp, "FTYPE"):
return 1
return 0
def xfs_version_haslogv2(sbp):
if XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5:
return 1
if xfs_sb_version(sbp, "LOGV2BIT"):
return 1
return 0
def super_block_devname(sb):
sb = readSU("struct super_block", sb)
try:
first_mount = readSU("struct mount", container_of(sb.s_mounts.next, "struct mount", "mnt_instance"))
return first_mount.mnt_devname
except:
return "UNKNOWN"
pass
#static inline uint64_t xfs_mask64hi(int n) { return (uint64_t)-1 << (64 - (n)); }
#static inline uint32_t xfs_mask32lo(int n) { return ((uint32_t)1 << (n)) - 1; }
#static inline uint64_t xfs_mask64lo(int n) { return ((uint64_t)1 << (n)) - 1;}
def xfs_mask64hi(n):
return (0xffffffffffffffff << (64 - n))
def xfs_mask32lo(n):
return (0xffffffff & ((1 << n) - 1))
def xfs_mask64lo(n):
return (0xffffffffffffffff & ((1 << n) - 1))
########################## xfs conversions ##########################
# 1037 /*
# 1038 * Inode number format:
# 1039 * low inopblog bits - offset in block
# 1040 * next agblklog bits - block number in ag
# 1041 * next agno_log bits - ag number
# 1042 * high agno_log-agblklog-inopblog bits - 0
# 1043 */
def cast__xfs_daddr_t(i):
return (i & 0xffffffffffffffff)
def cast__xfs_agblock_t(i):
return (i & 0xffffffff)
def cast__xfs_ino_t(i):
return i & 0xffffffffffffffff
def cast__xfs_agnumber_t(i):
return i & 0xffffffff
def cast__xfs_agino_t(i):
return (int)(i & 0xffffffff)
#/*
# * File system block to basic block conversions.
# */
##define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log)
def XFS_FSB_TO_BB(mp, fsbno):
return (fsbno << (readSU("struct xfs_mount", mp).m_blkbb_log))
##define XFS_BB_TO_FSB(mp,bb) \
# (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
def XFS_BB_TO_FSB(mp, bb):
mp = readSU("struct xfs_mount", mp)
return ((bb + (XFS_FSB_TO_BB(mp, 1) - 1)) >> mp.m_blkbb_log)
##define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log)
def XFS_BB_TO_FSBT(mp, bb):
return (bb >> readSU("struct xfs_mount", mp).m_blkbb_log)
#define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
def XFS_SB_DADDR():
return cast__xfs_daddr_t(0)
##define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
def XFS_SB_BLOCK(mp):
return XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
##define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)((bp)->b_addr))
def XFS_BUF_TO_SBP(bp):
return readSU("struct xfs_dsb_t", readSU("struct xfs_buf", bp).b_addr)
##define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
def XFS_HDR_BLOCK(mp, d):
return (cast__xfs_agblock_t(XFS_BB_TO_FSBT(mp, d)))
#define xfs_daddr_to_agno(mp,d) \
# ((xfs_agnumber_t)(XFS_BB_TO_FSBT(mp, d) / (mp)->m_sb.sb_agblocks))
def xfs_daddr_to_agno(mp, d):
# return cast__xfs_agnumber_t(XFS_BB_TO_FSBT(mp, d) / mp.m_sb.sb_agblocks)
return cast__xfs_agnumber_t(int(XFS_BB_TO_FSBT(mp, d) / mp.m_sb.sb_agblocks))
#define xfs_daddr_to_agbno(mp,d) \
# ((xfs_agblock_t)(XFS_BB_TO_FSBT(mp, d) % (mp)->m_sb.sb_agblocks))
def xfs_daddr_to_agbno(mp, d):
return cast__xfs_agblock_t(XFS_BB_TO_FSBT(mp, d) % mp.m_sb.sb_agblocks)
##define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
# xfs_daddr_to_agno(mp,d), xfs_daddr_to_agbno(mp,d))
def XFS_DADDR_TO_FSB(mp, d):
return XFS_AGB_TO_FSB(mp, xfs_daddr_to_agno(mp, d),
xfs_daddr_to_agbno(mp, d))
##define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \
# XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
def XFS_FSB_TO_DADDR(mp, fsbno):
return XFS_AGB_TO_DADDR(mp, XFS_FSB_TO_AGNO(mp,fsbno),
XFS_FSB_TO_AGBNO(mp,fsbno))
# #define XFS_INO_MASK(k) (__uint32_t)((1ULL << (k)) - 1)
def XFS_INO_MASK(k):
return ((1 << k) - 1) & 0xffffffff
#1045 #define XFS_INO_OFFSET_BITS(mp) (mp)->m_sb.sb_inopblog
def XFS_INO_OFFSET_BITS(mp):
return readSU("struct xfs_mount", mp).m_sb.sb_inopblog
#1046 #define XFS_INO_AGBNO_BITS(mp) (mp)->m_sb.sb_agblklog
def XFS_INO_AGBNO_BITS(mp):
return readSU("struct xfs_mount", mp).m_sb.sb_agblklog
#1047 #define XFS_INO_AGINO_BITS(mp) (mp)->m_agino_log
def XFS_INO_AGINO_BITS(mp):
return readSU("struct xfs_mount", mp).m_agino_log
#1048 #define XFS_INO_AGNO_BITS(mp) (mp)->m_agno_log
def XFS_INO_AGNO_BITS(mp):
return readSU("struct xfs_mount", mp).m_agno_log
#1049 #define XFS_INO_BITS(mp) \
#1050 XFS_INO_AGNO_BITS(mp) + XFS_INO_AGINO_BITS(mp)
def XFS_INO_BITS(mp):
return XFS_INO_AGNO_BITS(mp) + XFS_INO_AGINO_BITS(mp)
#1051 #define XFS_INO_TO_AGNO(mp,i) \
#1052 ((xfs_agnumber_t)((i) >> XFS_INO_AGINO_BITS(mp)))
def XFS_INO_TO_AGNO(mp, i):
return (cast__xfs_agnumber_t(i >> XFS_INO_AGINO_BITS(mp)))
#1053 #define XFS_INO_TO_AGINO(mp,i) \
#1054 ((xfs_agino_t)(i) & XFS_INO_MASK(XFS_INO_AGINO_BITS(mp)))
def XFS_INO_TO_AGINO(mp, i):
return (cast__xfs_agino_t(i) & XFS_INO_MASK(XFS_INO_AGINO_BITS(mp)))
#1055 #define XFS_INO_TO_AGBNO(mp,i) \
#1056 (((xfs_agblock_t)(i) >> XFS_INO_OFFSET_BITS(mp)) & \
#1057 XFS_INO_MASK(XFS_INO_AGBNO_BITS(mp)))
def XFS_INO_TO_AGBNO(mp, i):
return ((cast__xfs_agblock_t(i) >> XFS_INO_OFFSET_BITS(mp)) &
XFS_INO_MASK(XFS_INO_AGBNO_BITS(mp)))
#1058 #define XFS_INO_TO_OFFSET(mp,i) \
#1059 ((int)(i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
def XFS_INO_TO_OFFSET(mp, i):
return ((int)(i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
#1060 #define XFS_INO_TO_FSB(mp,i) \
#1061 XFS_AGB_TO_FSB(mp, XFS_INO_TO_AGNO(mp,i), XFS_INO_TO_AGBNO(mp,i))
def XFS_INO_TO_FSB(mp, i):
return XFS_AGB_TO_FSB(mp, XFS_INO_TO_AGNO(mp, i), XFS_INO_TO_AGBNO(mp, i))
#1062 #define XFS_AGINO_TO_INO(mp,a,i) \
#1063 (((xfs_ino_t)(a) << XFS_INO_AGINO_BITS(mp)) | (i))
def XFS_AGINO_TO_INO(mp, a, i):
return ((cast__xfs_ino_t(a) << XFS_INO_AGINO_BITS(mp)) | (i))
#1064 #define XFS_AGINO_TO_AGBNO(mp,i) ((i) >> XFS_INO_OFFSET_BITS(mp))
def XFS_AGINO_TO_AGBNO(mp, i):
return (i >> XFS_INO_OFFSET_BITS(mp))
#1065 #define XFS_AGINO_TO_OFFSET(mp,i) \
#1066 ((i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
def XFS_AGINO_TO_OFFSET(mp, i):
return (i & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
#1067 #define XFS_OFFBNO_TO_AGINO(mp,b,o) \
#1068 ((xfs_agino_t)(((b) << XFS_INO_OFFSET_BITS(mp)) | (o)))
def XFS_OFFBNO_TO_AGINO(mp, b, o):
return cast__xfs_agino_t((b << XFS_INO_OFFSET_BITS(mp)) | o)
#define XFS_AGB_TO_FSB(mp,agno,agbno) \
# (((xfs_fsblock_t)(agno) << (mp)->m_sb.sb_agblklog) | (agbno))
def XFS_AGB_TO_FSB(mp, agno, agbno):
return ((agno << mp.m_sb.sb_agblklog) | agbno)
#define XFS_FSB_TO_AGNO(mp,fsbno) \
# ((xfs_agnumber_t)((fsbno) >> (mp)->m_sb.sb_agblklog))
def XFS_FSB_TO_AGNO(mp, fsbno):
return cast__xfs_agnumber_t(fsbno >> mp.m_sb.sb_agblklog)
#define XFS_FSB_TO_AGBNO(mp,fsbno) \
# ((xfs_agblock_t)((fsbno) & xfs_mask32lo((mp)->m_sb.sb_agblklog)))
def XFS_FSB_TO_AGBNO(mp, fsbno):
return cast__xfs_agblock_t(fsbno & xfs_mask32lo(mp.m_sb.sb_agblklog))
#define XFS_AGB_TO_DADDR(mp,agno,agbno) \
# ((xfs_daddr_t)XFS_FSB_TO_BB(mp, (xfs_fsblock_t)(agno) * (mp)->m_sb.sb_agblocks + (agbno)))
def XFS_AGB_TO_DADDR(mp, agno, agbno):
return cast__xfs_daddr_t(XFS_FSB_TO_BB(mp, agno * (mp.m_sb.sb_agblocks + agbno)))
#define XFS_AG_DADDR(mp,agno,d) (XFS_AGB_TO_DADDR(mp, agno, 0) + (d))
def XFS_AG_DADDR(mp, agno, d):
return (XFS_AGB_TO_DADDR(mp, agno, 0) + d)
#define agblock_to_bytes(x) \
# ((uint64_t)(x) << mp->m_sb.sb_blocklog)
def agblock_to_bytes(mp, x):
return (x << mp.m_sb.sb_blocklog)
#define agino_to_bytes(x) \
# ((uint64_t)(x) << mp->m_sb.sb_inodelog)
def agino_to_bytes(mp, x):
return (x << mp.m_sb.sb_inodelog)
#define agnumber_to_bytes(x) \
# agblock_to_bytes((uint64_t)(x) * mp->m_sb.sb_agblocks)
def agnumber_to_bytes(mp, x):
return agblock_to_bytes(mp, x * mp.m_sb.sb_agblocks)
#define daddr_to_bytes(x) \
# ((uint64_t)(x) << BBSHIFT)
def daddr_to_bytes(mp, x):
return (x << BBSHIFT)
#define fsblock_to_bytes(x) \
# (agnumber_to_bytes(XFS_FSB_TO_AGNO(mp, (x))) + \
# agblock_to_bytes(XFS_FSB_TO_AGBNO(mp, (x))))
def fsblock_to_bytes(mp, x):
return (agnumber_to_bytes(mp, XFS_FSB_TO_AGNO(mp, x)) +
agblock_to_bytes(mp, XFS_FSB_TO_AGBNO(mp, x)))
#define ino_to_bytes(x) \
# (agnumber_to_bytes(XFS_INO_TO_AGNO(mp, (x))) + \
# agino_to_bytes(XFS_INO_TO_AGINO(mp, (x))))
def ino_to_bytes(mp, x):
return (agnumber_to_bytes(mp, XFS_INO_TO_AGNO(mp, x)) +
agino_to_bytes(mp, XFS_INO_TO_AGINO(mp, x)))
#define inoidx_to_bytes(x) \
# ((uint64_t)(x) << mp->m_sb.sb_inodelog)
def inoidx_to_bytes(mp, x):
return (x << mp.m_sb.sb_inodelog)
try:
# xfs_inode_operations = readSU(readSymbol("xfs_inode_operations"), "struct inode_operations")
xfs_inode_operations = readSymbol("xfs_inode_operations")
except Exception as e:
print("could not read 'xfs_inode_operations': {}".format(e))
xfs_inode_operations = 0
try:
# xfs_dir_inode_operations = readSU(readSymbol("xfs_dir_inode_operations"), "struct inode_operations")
xfs_dir_inode_operations = readSymbol("xfs_dir_inode_operations")
except:
print("could not read 'xfs_dir_inode_operations'")
xfs_dir_inode_operations = 0
try:
# xfs_dir_ci_inode_operations = readSU(readSymbol("xfs_dir_ci_inode_operations"), "struct inode_operations")
xfs_dir_ci_inode_operations = readSymbol("xfs_dir_ci_inode_operations")
except:
print("could not read 'xfs_dir_ci_inode_operations'")
xfs_dir_ci_inode_operations = 0
try:
# xfs_symlink_inode_operations = readSU(readSymbol("xfs_symlink_inode_operations"), "struct inode_operations")
xfs_symlink_inode_operations = readSymbol("xfs_symlink_inode_operations")
except Exception as e:
print("could not read 'xfs_symlink_inode_operations': {}".format(e))
xfs_symlink_inode_operations = 0
try:
xfs_file_operations = readSU(readSymbol("xfs_file_operations"), "struct file_operations")
xfs_dir_file_operations = readSU(readSymbol("xfs_dir_file_operations"), "struct file_operations")
except:
xfs_file_operations = 0
xfs_dir_file_operations = 0
try:
xfs_super_operations = readSU(readSymbol("xfs_super_operations"), "struct super_operations")
xfs_address_space_operations = readSU(readSymbol("xfs_address_space_operations"), "struct address_space_operations")
# xfs_quotactl_operations
# xfs_export_operations
except:
xfs_address_space_operations = 0
xfs_super_operations = 0
def check_prune(struct_name, addr):
global prune_list
prune_key = "{}.0x{:016x}".format(struct_name, addr)
try:
prune_this = prune_list[prune_key]
except:
prune_this = False
prune_list[prune_key] = True
return prune_this
def show_uuid_be(addr):
uuid = readSU("uuid_be", addr)
for i in range(0, 16):
print("{:02x}".format(uuid[i] & 0xff), end='')
if (i == 3 or i == 5 or i == 7 or i == 9):
print("-", end='')
print("")
#def from_type_bytes(mp, from_type, val):
# if from_type == "agblock" or from_type == "agbno":
def xfs_whatever_is_xfs_sb(addr):
try:
xfs_sb = readSU("struct xfs_sb", addr)
if xfs_sb.sb_magicnum == XFS_SB_MAGIC:
return True
except:
return False
def xfs_whatever_is_xfs_mount(addr):
try:
xfs_mount = readSU("struct xfs_mount", addr)
# ail = xfs_mount.m_ail
# if ail.m_sb != xfs_mount.m_sb:
# return False
return xfs_whatever_is_xfs_sb(xfs_mount.m_sb)
except:
return False
def xfs_whatever_is_sb(addr):
try:
sb = readSU("struct super_block", addr)
return xfs_whatever_is_xfs_mount(sb.s_fs_info)
except:
return False
def xfs_whatever_is_xfs_trans(addr):
try:
tp = readSU("struct xfs_trans", addr)
if tp.t_magic == XFS_TRANS_HEADER_MAGIC:
return True
except:
return False
return False
def xfs_whatever_is_bmap(addr):
try:
btb = readSU("struct xfs_btree_block", addr)
if btb.bb_magic == htonl(XFS_BMAP_MAGIC):
return True
except:
return False
return False
def xfs_whatever_is_bmap_crc(addr):
try:
btb = readSU("struct xfs_btree_block", addr)
if btb.bb_magic == htonl(XFS_BMAP_CRC_MAGIC):
return True
except:
return False
return False
def xfs_whatever_is_xfs_buftarg(addr):
try:
xbt = readSU("struct xfs_buftarg", addr)
if xbt.bt_mount and xfs_whatever_is_xfs_mount(xbt.bt_mount):
return True
except:
pass
return False
def xfs_whatever_is_xfs_buf(addr):
try:
xbf = readSU("struct xfs_buf", addr)
if xfs_whatever_is_xfs_trans(xbf.b_transp):
return True
if xbf.b_target and xfs_whatever_is_xfs_buftarg(xbf.b_target):
return True
except:
pass
return False
def xfs_whatever_is_xfs_perag(addr):
try:
pag = readSU("struct xfs_perag", addr)
return xfs_whatever_is_xfs_mount(pag.pag_mount)
except:
return False
def xfs_whatever_is_xfs_inode(addr):
try:
xi = readSU("struct xfs_inode", addr)
except:
return False
try:
i_op = xi.i_vnode.i_op
if i_op == 0:
return False
if i_op == xfs_inode_operations:
print("xfs_whatever_is_xfs_inode i_op {:016x} is an xfs_inode_operations: {:016x}".format(i_op, xfs_inode_operations))
return True
if i_op == xfs_dir_inode_operations:
# print("xfs_whatever_is_xfs_inode i_op {:016x} is an xfs_dir_inode_operations {:016x}".format(i_op, xfs_dir_inode_operations))
return True
if i_op == xfs_dir_ci_inode_operations or i_op == xfs_symlink_inode_operations:
# print("xfs_whatever_is_xfs_inode i_op is an xfs_dir_ci_inode_operations or xfs_symlink_inode_operations")
return True
# print("got i_op (0{:016x}, but it doesn't match some stuff".format(i_op)) # hmm. what else would it be?
except:
print("got exceptions trying to read xi.i_vnode.*")
pass
# print("still checking")
try:
if xfs_whatever_is_xfs_mount(xi.i_mount):
print("it's an xfs_mount")
return True
except:
pass
return False
def xfs_whatever_is_inode(addr):
inode = readSU("struct inode", addr)
sb = inode.i_sb
if not xfs_whatever_is_sb(sb):
return False
try:
xi = readSU("struct xfs_inode", container_of(addr, "struct xfs_inode", "i_vnode"))
except:
return False
return xfs_whatever_is_xfs_inode(xi)
def xfs_whatever_is_xlog(addr):
xlog = readSU("struct xlog", addr)
try:
ail = xlog.l_ailp
xfs_mount = xlog.l_mp
if ail.xa_mount != xlog.l_mp:
return False
if xfs_mount.m_log != xlog:
return False
except:
return False
return xfs_whatever_is_xfs_mount(xfs_mount)
def xfs_whatever_is_cil(addr):
try:
cil = readSU("struct xfs_cil", addr)
xc_ctx = cil.xc_ctx
if xc_ctx.cil != cil:
return False
except:
return False
return xfs_whatever_is_xlog(cil.xc_log)
def xfs_whatever_is_xfs_buftarg(addr):
try:
bt = readSU("struct xfs_buftarg", addr)
if not xfs_whatever_is_xfs_mount(bt.bt_mount):
return False
#crash> xfs_buftarg.bt_meta_sectormask,bt_meta_sectorsize,bt_logical_sectorsize,bt_logical_sectormask 0xffff9de6629c3700
# bt_meta_sectormask = 0x1ff
# bt_meta_sectorsize = 0x200
# bt_logical_sectorsize = 0x200
# bt_logical_sectormask = 0x1ff
#crash> px (0x200 & 0x1ff)
#$1 = 0x0
#crash> px (0x200 ^ 0x1ff)
#$2 = 0x3ff
#crash> px (0x200 | 0x1ff)
#$3 = 0x3ff
ss1 = bt.bt_meta_sectorsize
sm1 = bt.bt_meta_sectormask
ss2 = bt.bt_logical_sectorsize
sm2 = bt.bt_logical_sectormask
if (ss1 & sm1 != 0) or (ss1 ^ sm1 != ss1 | sm1):
return False
if (ss1 & sm1 == 0) and (ss1 ^ sm1 == ss1 | sm1) and (ss1 == sm1 + 1) and \
(ss2 & sm2 == 0) and (ss2 ^ sm2 == ss2 | sm2) and (ss2 == sm2 + 2):
return True
# pretty tenuous, but possible... anything further we can check?
return True
except:
return False
return False
def xfs_whatever_id(addr):
if xfs_whatever_is_xfs_mount(addr):
return "xfs_mount"
if xfs_whatever_is_xfs_sb(addr):
return "xfs_sb"
if xfs_whatever_is_sb(addr):
return "super_block"
if xfs_whatever_is_xfs_buf(addr):
return "xfs_buf"
if xfs_whatever_is_xfs_inode(addr):
return "xfs_inode"
if xfs_whatever_is_xfs_trans(addr):
return "xfs_trans"
if xfs_whatever_is_inode(addr):
return "inode"
if xfs_whatever_is_bmap(addr):
return "xfs_bmap"
if xfs_whatever_is_bmap_crc(addr):
return "xfs_bmap"
if xfs_whatever_is_xlog(addr):
return "xlog"
if xfs_whatever_is_cil(addr):
return "xfs_cil"
if xfs_whatever_is_xfs_perag(addr):
return "xfs_perag"
if xfs_whatever_is_xfs_buftarg(addr):
return "xfs_buftarg"
return "UNKNOWN"
def xfs_mount_from_xfs_sb(addr):
try:
xfs_sb = readSU("struct xfs_sb", addr)
return readSU("struct xfs_mount", container_of(xfs_sb, "struct xfs_mount", "m_sb"))
except:
return 0
def xfs_mount_from_sb(addr):
try:
sb = readSU("struct super_block", addr)
return readSU("struct xfs_mount", sb.s_fs_info)
except:
return 0
def xfs_mount_from_xfs_buf(addr):
try:
return readSU("struct xfs_buf", addr).b_transp.t_mountp
except:
pass
try:
return readSU("struct xfs_buf", addr).b_pag.pag_mount
except:
return 0
return 0
def xfs_mount_from_xfs_inode(addr):
try:
return readSU("struct xfs_inode", addr).i_mount
except:
return 0
def xfs_mount_from_xfs_inode(addr):
try:
return readSU("struct xfs_inode", addr).i_mount
except:
return 0
def xfs_mount_from_inode(addr):
try:
xi = readSU("struct xfs_inode", container_of(addr, "struct xfs_inode", "i_vnode"))
except:
return 0
return xfs_mount_from_xfs_inode(xi)
def xfs_mount_from_xlog(addr):
try:
xlog = readSU("struct xlog", addr)
# print("checking xlog {:016x}".format(xlog))
return xlog.l_mp
except:
return 0
def xfs_mount_from_xfs_cil(addr):
try:
cil = readSU("struct xfs_cil", addr)
xlog = cil.xc_log
except:
return 0
return xfs_mount_from_xlog(xlog)
def xfs_mount_from_whatever(id, addr):
if id == "xfs_mount":
return readSU("struct xfs_mount", addr)
if id == "xfs_sb":
return xfs_mount_from_xfs_sb(addr)
if id == "super_block":
return xfs_mount_from_sb(addr)
if id == "xfs_buf":
return xfs_mount_from_xfs_buf(addr)
if id == "xfs_inode":
return xfs_mount_from_xfs_inode(addr)
if id == "inode":
return xfs_mount_from_inode(addr)
if id == "xlog":
return xfs_mount_from_xlog(addr)
if id == "xfs_cil":
return xfs_mount_from_xfs_cil(addr)
print("0x{:016x} is Unknown".format(addr))
return None
agblock_strings = ("agblock", "agbno")
agino_strings = ("agino", "aginode")
agnumber_strings = ("agnumbrer", "agno")
bboff_strings = ("bboff", "daddroff")
blkoff_strings = ("blkoff", "fsboff", "agboff")
byte_strings = ("byte", "fsbyte")
daddr_strings = ("daddr", "bb")
fsblock_strings = ("fsblock", "fsb", "fsbno")
ino_strings = ("ino", "inode")
inoidx_strings = ("inoidx", "offset")
inooff_strings = ("inooff", "inodeoff")
def do_convert_from(mp, from_type, val):
mp = readSU("struct xfs_mount", mp)
# bytes = from_type_bytes(mp, from_type, val)
if from_type in agblock_strings:
# M(AGNUMBER)|M(BBOFF)|M(BLKOFF)|M(INOIDX)|M(INOOFF)
return agblock_to_bytes(mp, val);
elif from_type in agino_strings:
# M(AGNUMBER)|M(INOOFF)
return agino_to_bytes(mp, val)
elif from_type in agnumber_strings:
# M(AGBLOCK)|M(AGINO)|M(BBOFF)|M(BLKOFF)|M(INOIDX)|M(INOOFF)
return agnumber_to_bytes(mp, val)
# print("from agno {} to {} bytes".format(val, bytes))
# if to_type in agblock_strings:
# return xfs_daddr_to_agbno(mp, bytes >> BBSHIFT)
# elif to_type in agino_strings:
# print("to AGINO: {}".format(((bytes >> mp.m_sb.sb_inodelog) % (mp.m_sb.sb_agblocks << mp.m_sb.sb_inopblog))))
# print("... {} bytes >> something ({}) = {}".format(bytes, mp.m_sb.sb_inodelog, (bytes >> mp.m_sb.sb_inodelog)))
# print("(mp.m_sb.sb_agblocks ({}) << mp.m_sb.sb_inopblog ({})) = {}".format(mp.m_sb.sb_agblocks, mp.m_sb.sb_inopblog, (mp.m_sb.sb_agblocks << mp.m_sb.sb_inopblog)))
# return ((bytes >> mp.m_sb.sb_inodelog) %
# (mp.m_sb.sb_agblocks << mp.m_sb.sb_inopblog))
elif from_type in bboff_strings:
# M(AGBLOCK)|M(AGNUMBER)|M(DADDR)|M(FSBLOCK)
return val
elif from_type in blkoff_strings:
# M(AGBLOCK)|M(AGNUMBER)|M(FSBLOCK),
return val
elif from_type in byte_strings:
# nothing?
return val
elif from_type in daddr_strings:
# BBOFF
ret = (daddr_to_bytes(mp, val) & BBMASK)
print("from daddr {} - bytes: {}".format(val, ret))
return (daddr_to_bytes(mp, val) & BBMASK)
elif from_type in fsblock_strings:
# M(BBOFF)|M(BLKOFF)|M(INOIDX
return fsblock_to_bytes(mp, val)
elif from_type in ino_strings:
# INOOFF
return ino_to_bytes(mp, val)
# bytes = ino_to_bytes(mp, val)
# print("from ino_strings {} to {} bytes".format(val, bytes))
# if to_type in inooff_strings:
# print("converting TO INOOFF")
# return (bytes & (mp.m_sb.sb_inodesize - 1))
# elif to_type in daddr_strings:
# print("converting TO DADDR")
# return (bytes >> BBSHIFT)
elif from_type in inoidx_strings:
# M(AGBLOCK)|M(AGNUMBER)|M(FSBLOCK)|M(INOOFF)
return inoidx_to_bytes(mp, val)
elif from_type in inooff_strings:
# M(AGBLOCK)|M(AGINO)|M(AGNUMBER)|M(FSBLOCK)|M(INO)|M(INOIDX
return val
else:
print("Error: unable to process 'from' type '{}'".format(from_type))
return None
# print("unable to convert to type '{}'".format(to_type))
print("unable to convert from type '{}'".format(from_type))
return None
def do_convert_to(mp, bytes, to_type):
mp = readSU("struct xfs_mount", mp)
# bytes = from_type_bytes(mp, from_type, val)
if to_type in agnumber_strings:
return xfs_daddr_to_agno(mp, bytes >> BBSHIFT)
elif to_type in bboff_strings:
return (bytes & BBMASK)
elif to_type in blkoff_strings:
return (bytes & mp.m_blockmask)
elif to_type in inoidx_strings:
return (bytes >> mp.m_sb.sb_inodelog) & (mp.m_sb.sb_inopblock - 1)
elif to_type in inooff_strings:
# print("converting TO INOOFF")
return (bytes & (mp.m_sb.sb_inodesize - 1))
elif to_type in agblock_strings:
return xfs_daddr_to_agbno(mp, bytes >> BBSHIFT)
elif to_type in agino_strings:
# print("to AGINO: {}".format(((bytes >> mp.m_sb.sb_inodelog) % (mp.m_sb.sb_agblocks << mp.m_sb.sb_inopblog))))
# print("... {} bytes >> something ({}) = {}".format(bytes, mp.m_sb.sb_inodelog, (bytes >> mp.m_sb.sb_inodelog)))
# print("(mp.m_sb.sb_agblocks ({}) << mp.m_sb.sb_inopblog ({})) = {}".format(mp.m_sb.sb_agblocks, mp.m_sb.sb_inopblog, (mp.m_sb.sb_agblocks << mp.m_sb.sb_inopblog)))
return ((bytes >> mp.m_sb.sb_inodelog) %
(mp.m_sb.sb_agblocks << mp.m_sb.sb_inopblog))
elif to_type in fsblock_strings:
return XFS_DADDR_TO_FSB(mp, bytes >> BBSHIFT)
elif to_type in daddr_strings:
return (bytes >> BBSHIFT)
elif to_type in ino_strings:
# return (bytes & (mp.m_sb.sb_inodesize - 1))
return XFS_AGINO_TO_INO(mp, xfs_daddr_to_agno(mp, bytes >> BBSHIFT),
(bytes >> mp.m_sb.sb_inodelog) % (mp.m_sb.sb_agblocks << mp.m_sb.sb_inopblog))
else:
print("Unable to convert to '{}'".format(to_type))
return None
def do_convert(mp, from_type, val, to_type):
mp = readSU("struct xfs_mount", mp)
# bytes = from_type_bytes(mp, from_type, val)
if from_type in agblock_strings:
# M(AGNUMBER)|M(BBOFF)|M(BLKOFF)|M(INOIDX)|M(INOOFF)
bytes = agblock_to_bytes(mp, val);
if to_type in agnumber_strings:
return xfs_daddr_to_agno(mp, bytes >> BBSHIFT)
elif to_type in bboff_strings:
return (bytes & BBMASK)
elif to_type in blkoff_strings:
return (bytes & mp.m_blockmask)
elif to_type in inoidx_strings:
return (bytes >> mp.m_sb.sb_inodelog) & (mp.m_sb.sb_inopblock - 1)
elif to_type in inooff_strings:
return (bytes & (mp.m_sb.sb_inodesize - 1))
elif from_type in agino_strings:
# M(AGNUMBER)|M(INOOFF)
bytes = agino_to_bytes(mp, val)
if to_type in agnumber_strings:
return xfs_daddr_to_agno(mp, bytes >> BBSHIFT)
elif to_type in inooff_strings:
return (bytes & (mp.m_sb.sb_inodesize - 1))
elif from_type in agnumber_strings:
# M(AGBLOCK)|M(AGINO)|M(BBOFF)|M(BLKOFF)|M(INOIDX)|M(INOOFF)
bytes = agnumber_to_bytes(mp, val)
print("from agno {} to {} bytes".format(val, bytes))
if to_type in agblock_strings:
return xfs_daddr_to_agbno(mp, bytes >> BBSHIFT)
elif to_type in agino_strings:
print("to AGINO: {}".format(((bytes >> mp.m_sb.sb_inodelog) % (mp.m_sb.sb_agblocks << mp.m_sb.sb_inopblog))))
print("... {} bytes >> something ({}) = {}".format(bytes, mp.m_sb.sb_inodelog, (bytes >> mp.m_sb.sb_inodelog)))
print("(mp.m_sb.sb_agblocks ({}) << mp.m_sb.sb_inopblog ({})) = {}".format(mp.m_sb.sb_agblocks, mp.m_sb.sb_inopblog, (mp.m_sb.sb_agblocks << mp.m_sb.sb_inopblog)))
return ((bytes >> mp.m_sb.sb_inodelog) %
(mp.m_sb.sb_agblocks << mp.m_sb.sb_inopblog))