Subversion Repositories Kolibri OS

Rev

Rev 4850 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3913 dunkaist 1
; from stat.h
2
; distinguish file types
3
S_IFMT      = 0170000o  ; These bits determine file type.
4
S_IFDIR     = 0040000o  ; Directory.
5
S_IFCHR     = 0020000o  ; Character device.
6
S_IFBLK     = 0060000o  ; Block device.
7
S_IFREG     = 0100000o  ; Regular file.
8
S_IFIFO     = 0010000o  ; FIFO.
9
S_IFLNK     = 0120000o  ; Symbolic link.
10
S_IFSOCK    = 0140000o  ; Socket.
11
; end stat.h
12
 
13
 
14
; XFS null constant: empty fields must be all ones, not zeros!
15
XFS_NULL                = -1
16
 
17
 
18
; static sector numbers
19
XFS_SECT_SB             = 0
20
XFS_SECT_AGF            = 1
21
XFS_SECT_AGI            = 2
22
XFS_SECT_AGFL           = 3
23
 
24
 
25
; signatures of file system structures
26
; 'string' numbers are treated by fasm as big endian
27
XFS_SB_MAGIC            = 'XFSB'
28
XFS_AGF_MAGIC           = 'XAGF'
29
XFS_AGI_MAGIC           = 'XAGI'
30
XFS_ABTB_MAGIC          = 'ABTB'
31
XFS_ABTC_MAGIC          = 'ABTC'
32
XFS_IBT_MAGIC           = 'IABT'
33
XFS_DINODE_MAGIC        = 'IN'
34
XFS_BMAP_MAGIC          = 'BMAP'
35
XFS_DA_NODE_MAGIC       = 0xbefe        ; those are little endian here
36
XFS_ATTR_LEAF_MAGIC     = 0xeefb        ; but big endian in docs
37
XFS_DIR2_LEAF1_MAGIC    = 0xf1d2        ; pay attention!
38
XFS_DIR2_LEAFN_MAGIC    = 0xffd2        ;
39
XFS_DIR2_BLOCK_MAGIC    = 'XD2B'
40
XFS_DIR2_DATA_MAGIC     = 'XD2D'
41
XFS_DIR2_FREE_MAGIC     = 'XD2F'
42
XFS_DQUOT_MAGIC         = 'DQ'
43
 
44
 
45
; bitfield lengths for packed extent
46
; MSB to LSB / left to right
47
BMBT_EXNTFLAG_BITLEN    =  1
48
BMBT_STARTOFF_BITLEN    = 54
49
BMBT_STARTBLOCK_BITLEN  = 52
50
BMBT_BLOCKCOUNT_BITLEN  = 21
51
 
52
 
53
; those constants are taken from linux source (xfs_dir2_leaf.h)
54
; they are magic infile offsets for directories
55
XFS_DIR2_DATA_ALIGN_LOG = 3     ; i.e., 8 bytes
56
XFS_DIR2_LEAF_SPACE     = 1
57
XFS_DIR2_SPACE_SIZE     = (1 SHL (32 + XFS_DIR2_DATA_ALIGN_LOG))
58
XFS_DIR2_LEAF_OFFSET    = (XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE)
59
XFS_DIR2_FREE_SPACE     = 2
60
XFS_DIR2_SPACE_SIZE     = (1 SHL (32 + XFS_DIR2_DATA_ALIGN_LOG))
61
XFS_DIR2_FREE_OFFSET    = (XFS_DIR2_FREE_SPACE * XFS_DIR2_SPACE_SIZE)
62
 
63
 
64
; data section magic constants for directories (xfs_dir2_data.h)
65
XFS_DIR2_DATA_FD_COUNT  = 3
66
XFS_DIR2_DATA_FREE_TAG  = 0xffff
67
 
68
 
69
; valid inode formats
70
; enum xfs_dinode_fmt (xfs_dinode.h)
71
XFS_DINODE_FMT_DEV      = 0     ; xfs_dev_t
72
XFS_DINODE_FMT_LOCAL    = 1     ; one inode is enough (shortdir)
73
XFS_DINODE_FMT_EXTENTS  = 2     ; one or more extents (leafdir, nodedir, regular files)
74
XFS_DINODE_FMT_BTREE    = 3     ; highly fragmented files or really huge directories
75
XFS_DINODE_FMT_UUID     = 4     ; uuid_t
76
 
77
 
78
; size of the unlinked inode hash table in the agi
79
XFS_AGI_UNLINKED_BUCKETS = 64
80
 
81
 
82
; possible extent states
83
; enum xfs_exntst_t (xfs_bmap_btree.h)
84
XFS_EXT_NORM            = 0
85
XFS_EXT_UNWRITTEN       = 1
86
XFS_EXT_DMAPI_OFFLINE   = 2
87
XFS_EXT_INVALID         = 3
88
 
89
 
90
; values for inode core flags / di_flags (xfs_dinode.h)
91
XFS_DIFLAG_REALTIME_BIT     =  0        ; file's blocks come from rt area
92
XFS_DIFLAG_PREALLOC_BIT     =  1        ; file space has been preallocated
93
XFS_DIFLAG_NEWRTBM_BIT      =  2        ; for rtbitmap inode, new format
94
XFS_DIFLAG_IMMUTABLE_BIT    =  3        ; inode is immutable
95
XFS_DIFLAG_APPEND_BIT       =  4        ; inode is append-only
96
XFS_DIFLAG_SYNC_BIT         =  5        ; inode is written synchronously
97
XFS_DIFLAG_NOATIME_BIT      =  6        ; do not update atime
98
XFS_DIFLAG_NODUMP_BIT       =  7        ; do not dump
99
XFS_DIFLAG_RTINHERIT_BIT    =  8        ; create with realtime bit set
100
XFS_DIFLAG_PROJINHERIT_BIT  =  9        ; create with parents projid
101
XFS_DIFLAG_NOSYMLINKS_BIT   = 10        ; disallow symlink creation
102
XFS_DIFLAG_EXTSIZE_BIT      = 11        ; inode extent size allocator hint
103
XFS_DIFLAG_EXTSZINHERIT_BIT = 12        ; inherit inode extent size
104
XFS_DIFLAG_NODEFRAG_BIT     = 13        ; do not reorganize/defragment
105
XFS_DIFLAG_FILESTREAM_BIT   = 14        ; use filestream allocator
106
XFS_DIFLAG_REALTIME         = (1 SHL XFS_DIFLAG_REALTIME_BIT)
107
XFS_DIFLAG_PREALLOC         = (1 SHL XFS_DIFLAG_PREALLOC_BIT)
108
XFS_DIFLAG_NEWRTBM          = (1 SHL XFS_DIFLAG_NEWRTBM_BIT)
109
XFS_DIFLAG_IMMUTABLE        = (1 SHL XFS_DIFLAG_IMMUTABLE_BIT)
110
XFS_DIFLAG_APPEND           = (1 SHL XFS_DIFLAG_APPEND_BIT)
111
XFS_DIFLAG_SYNC             = (1 SHL XFS_DIFLAG_SYNC_BIT)
112
XFS_DIFLAG_NOATIME          = (1 SHL XFS_DIFLAG_NOATIME_BIT)
113
XFS_DIFLAG_NODUMP           = (1 SHL XFS_DIFLAG_NODUMP_BIT)
114
XFS_DIFLAG_RTINHERIT        = (1 SHL XFS_DIFLAG_RTINHERIT_BIT)
115
XFS_DIFLAG_PROJINHERIT      = (1 SHL XFS_DIFLAG_PROJINHERIT_BIT)
116
XFS_DIFLAG_NOSYMLINKS       = (1 SHL XFS_DIFLAG_NOSYMLINKS_BIT)
117
XFS_DIFLAG_EXTSIZE          = (1 SHL XFS_DIFLAG_EXTSIZE_BIT)
118
XFS_DIFLAG_EXTSZINHERIT     = (1 SHL XFS_DIFLAG_EXTSZINHERIT_BIT)
119
XFS_DIFLAG_NODEFRAG         = (1 SHL XFS_DIFLAG_NODEFRAG_BIT)
120
XFS_DIFLAG_FILESTREAM       = (1 SHL XFS_DIFLAG_FILESTREAM_BIT)
121
 
122
 
123
; superblock _ondisk_ structure (xfs_sb.h)
124
; this is _not_ the partition structure
125
; for XFS partition structure see XFS below
126
struct xfs_sb
127
        sb_magicnum     dd ?    ; signature, must be XFS_SB_MAGIC
128
        sb_blocksize    dd ?    ; block is the minimal file system unit, in bytes
129
        sb_dblocks      dq ?    ; number of data blocks
130
        sb_rblocks      dq ?    ; number of realtime blocks (not supported yet!)
131
        sb_rextents     dq ?    ; number of realtime extents (not supported yet!)
132
        sb_uuid         rb 16   ; file system unique identifier
133
        sb_logstart     dq ?    ; starting block of log (for internal journal; journals on separate devices are not supported!)
134
        sb_rootino      dq ?    ; root inode number
135
        sb_rbmino       dq ?    ; bitmap inode for realtime extents (ignored)
136
        sb_rsumino      dq ?    ; summary inode for rt bitmap (ignored)
137
        sb_rextsize     dd ?    ; realtime extent size, blocks
138
        sb_agblocks     dd ?    ; size of an allocation group (the last one may be smaller!)
139
        sb_agcount      dd ?    ; number of allocation groups
140
        sb_rbmblocks    dd ?    ; number of rt bitmap blocks
141
        sb_logblocks    dd ?    ; number of log blocks
142
        sb_versionnum   dw ?    ; header version == XFS_SB_VERSION
143
        sb_sectsize     dw ?    ; volume sector size in bytes (only 512B sectors are supported)
144
        sb_inodesize    dw ?    ; inode size, bytes
145
        sb_inopblock    dw ?    ; inodes per block
146
        sb_fname        rb 12   ; inodes per block (aka label)
147
        sb_blocklog     db ?    ; log2 of sb_blocksize
148
        sb_sectlog      db ?    ; log2 of sb_blocksize
149
        sb_inodelog     db ?    ; log2 of sb_inodesize
150
        sb_inopblog     db ?    ; log2 of sb_inopblock
151
        sb_agblklog     db ?    ; log2 of sb_agblocks (rounded up!)
152
        sb_rextslog     db ?    ; log2 of sb_rextents
153
        sb_inprogress   db ?    ; mkfs is in progress, don't mount
154
        sb_imax_pct     db ?    ; max % of fs for inode space
155
        ; statistics
156
        sb_icount       dq ?    ; allocated inodes
157
        sb_ifree        dq ?    ; free inodes
158
        sb_fdblocks     dq ?    ; free data blocks
159
        sb_frextents    dq ?    ; free realtime extents
160
 
161
        sb_uquotino     dq ?    ; user quota inode
162
        sb_gquotino     dq ?    ; group quota inode
163
        sb_qflags       dw ?    ; quota flags
164
        sb_flags        db ?    ; misc. flags
165
        sb_shared_vn    db ?    ; shared version number
166
        sb_inoalignmt   dd ?    ; inode chunk alignment, fsblocks
167
        sb_unit         dd ?    ; stripe or raid unit
168
        sb_width        dd ?    ; stripe or raid width
169
        sb_dirblklog    db ?    ; log2 of dir block size (fsbs)
170
        sb_logsectlog   db ?    ; log2 of the log sector size
171
        sb_logsectsize  dw ?    ; sector size for the log, bytes
172
        sb_logsunit     dd ?    ; stripe unit size for the log
173
        sb_features2    dd ?    ; additional feature bits
174
ends
175
 
176
 
177
; allocation group inode (xfs_ag.h)
178
struct xfs_agi
179
        agi_magicnum    dd ?    ; magic number == XFS_AGI_MAGIC
180
        agi_versionnum  dd ?    ; header version == XFS_AGI_VERSION
181
        agi_seqno       dd ?    ; sequence number starting from 0
182
        agi_length      dd ?    ; size in blocks of a.g.
183
        agi_count       dd ?    ; count of allocated inodes
184
        agi_root        dd ?    ; root of inode btree
185
        agi_level       dd ?    ; levels in inode btree
186
        agi_freecount   dd ?    ; number of free inodes
187
        agi_newino      dd ?    ; new inode just allocated
188
        agi_dirino      dd ?    ; last directory inode chunk
189
        agi_unlinked    rd XFS_AGI_UNLINKED_BUCKETS     ; Hash table of inodes which have been unlinked but are still being referenced
190
ends
191
 
192
 
193
; superblock structure of b+tree node/leaf (same structure, bb_level matters)
194
struct xfs_btree_sblock
195
        bb_magic        dd ?
196
        bb_level        dw ?    ; distinguishes nodeds and leaves
197
        bb_numrecs      dw ?
198
        bb_leftsib      dd ?
199
        bb_rightsib     dd ?
200
ends
201
 
202
 
203
; record of b+tree inode
204
struct xfs_inobt_rec
205
        ir_startino     dd ?
206
        ir_freecount    dd ?
207
        ir_free         dq ?
208
ends
209
 
210
 
211
; structure to store create, access and modification time in inode core
212
struct xfs_timestamp
213
        t_sec           dd ?
214
        t_nsec          dd ?    ; nanoseconds
215
ends
216
 
217
 
218
; inode core structure: basic information about file
219
struct xfs_dinode_core
220
        di_magic        dw ?            ; inode magic = XFS_DINODE_MAGIC
221
        di_mode         dw ?            ; mode and type of file
222
        di_version      db ?            ; inode version
223
        di_format       db ?            ; format of di_c data
224
        di_onlink       dw ?            ; old number of links to file
225
        di_uid          dd ?            ; owner's user id
226
        di_gid          dd ?            ; owner's group id
227
        di_nlink        dd ?            ; number of links to file
228
        di_projid       dw ?            ; owner's project id
229
        di_pad          rb 8            ; unused, zeroed space
230
        di_flushiter    dw ?            ; incremented on flush
231
        di_atime        xfs_timestamp   ; time last accessed
232
        di_mtime        xfs_timestamp   ; time last modified
233
        di_ctime        xfs_timestamp   ; time created/inode modified
234
        di_size         dq ?            ; number of bytes in file
235
        di_nblocks      dq ?            ; number of direct & btree blocks used
236
        di_extsize      dd ?            ; basic/minimum extent size for file
237
        di_nextents     dd ?            ; number of extents in data fork
238
        di_anextents    dw ?            ; number of extents in attribute fork
239
        di_forkoff      db ?            ; attr fork offs, <<3 for 64b align
240
        di_aformat      db ?            ; format of attr fork's data
241
        di_dmevmask     dd ?            ; DMIG event mask
242
        di_dmstate      dw ?            ; DMIG state info
243
        di_flags        dw ?            ; random flags, XFS_DIFLAG_...
244
        di_gen          dd ?            ; generation number
245
ends
246
 
247
 
248
; shortform dir header
249
struct xfs_dir2_sf_hdr
250
        count           db ?            ; the number of directory entries, used only if each inode number fits 4 bytes; zero otherwise
251
        i8count         db ?            ; the number of directory entries, used only when count is zero
252
        parent          dq ?            ; parent inode number: xfs_dir2_inou_t (4 or 8 bytes)
253
ends
254
 
255
 
256
; shortform dir entry
257
struct xfs_dir2_sf_entry
258
        namelen         db ?            ; actual name length (ASCII)
259
        offset          rb 2            ; saved offset
260
        name            db ?            ; name, variable size
261
;       inumber         dq ?            ; xfs_dir2_inou_t
262
ends
263
 
264
 
265
; active entry in a data block
266
; aligned to 8 bytes
267
; tag appears as the last 2 bytes
268
struct xfs_dir2_data_entry
269
        inumber         dq ?            ; inode number
270
        namelen         db ?            ; name length
271
        name            db ?            ; name bytes, no null
272
;       tag             dw ?            ; starting offset of us
273
ends
274
 
275
 
276
; unused entry in a data block
277
; aligned to 8 bytes
278
; tag appears as the last 2 bytes
279
struct xfs_dir2_data_unused
280
        freetag         dw ?            ; XFS_DIR2_DATA_FREE_TAG
281
        length          dw ?            ; total free length
282
;        tag             dw ?           ; starting offset of us
283
ends
284
 
285
 
286
; generic data entry
287
struct xfs_dir2_data_union
288
  union
289
        xentry          xfs_dir2_data_entry
290
        unused          xfs_dir2_data_unused
291
  ends
292
ends
293
 
294
 
295
; describe a free area in the data block
296
; the freespace will be formatted as a xfs_dir2_data_unused_t
297
struct xfs_dir2_data_free
298
        offset          dw ?            ; start of freespace
299
        length          dw ?            ; length of freespace
300
ends
301
 
302
 
303
; header for the data blocks
304
; always at the beginning of a directory-sized block
305
; the code knows that XFS_DIR2_DATA_FD_COUNT is 3
306
struct xfs_dir2_data_hdr
307
        magic           dd ?                    ; XFS_DIR2_DATA_MAGIC or XFS_DIR2_BLOCK_MAGIC
308
        bestfree        xfs_dir2_data_free
309
        bestfree2       xfs_dir2_data_free
310
        bestfree3       xfs_dir2_data_free
311
ends
312
 
313
 
314
; leaf block entry
315
struct xfs_dir2_leaf_entry
316
        hashval         dd ?            ; hash value of name
317
        address         dd ?            ; address of data entry
318
ends
319
 
320
 
321
; the tail of directory block
322
struct xfs_dir2_block_tail
323
        count           dd ?            ; count of leaf entries
324
        stale           dd ?            ; count of stale leaf entries
325
ends
326
 
327
 
328
; generic single-block structure, for xfs_db
329
struct xfs_dir2_block
330
        hdr             xfs_dir2_data_hdr
331
        u               xfs_dir2_data_union
332
;        leaf            xfs_dir2_leaf_entry
333
;        tail            xfs_dir2_block_tail
334
ends
335
 
336
 
337
;
338
struct xfs_dir2_data
339
        hdr             xfs_dir2_data_hdr       ; magic XFS_DIR2_DATA_MAGIC
340
        u               xfs_dir2_data_union
341
ends
342
 
343
 
344
;
345
struct xfs_da_blkinfo
346
        forw            dd ?            ; previous block in list
347
        back            dd ?            ; following block in list
348
        magic           dw ?            ; validity check on block
349
        pad             dw ?            ; unused
350
ends
351
 
352
 
353
; leaf block header
354
struct xfs_dir2_leaf_hdr
355
        info            xfs_da_blkinfo  ; header for da routines
356
        count           dw ?            ; count of entries
357
        stale           dw ?            ; count of stale entries
358
ends
359
 
360
 
361
; leaf block tail
362
struct xfs_dir2_leaf_tail
363
        bestcount       dd ?
364
ends
365
 
366
 
367
; leaf block
368
; bests and tail are at the end of the block for single-leaf only
369
; (magic = XFS_DIR2_LEAF1_MAGIC not XFS_DIR2_LEAFN_MAGIC)
370
struct xfs_dir2_leaf
371
        hdr             xfs_dir2_leaf_hdr       ; leaf header
372
        ents            xfs_dir2_leaf_entry     ; entries
373
;       bests           dw ?                    ; best free counts
374
;       tail            xfs_dir2_leaf_tail      ; leaf tail
375
ends
376
 
377
 
378
; header of 'free' block part
379
struct xfs_dir2_free_hdr
380
        magic           dd ?    ; XFS_DIR2_FREE_MAGIC
381
        firstdb         dd ?    ; db of first entry
382
        nvalid          dd ?    ; count of valid entries
383
        nused           dd ?    ; count of used entries
384
ends
385
 
386
 
387
; 'free' part of directiry block
388
struct xfs_dir2_free
389
        hdr             xfs_dir2_free_hdr       ; block header
390
        bests           dw ?                    ; best free counts
391
                                                ; unused entries are -1 (XFS_NULL)
392
ends
393
 
394
 
395
; b+tree node header
396
struct xfs_da_node_hdr
397
        info            xfs_da_blkinfo
398
        count           dw ?
399
        level           dw ?
400
ends
401
 
402
 
403
; b+tree node
404
struct xfs_da_node_entry
405
        hashval         dd ?            ; hash value for this descendant
406
        before          dd ?            ; Btree block before this key
407
ends
408
 
409
 
410
;
411
struct xfs_da_intnode
412
        hdr             xfs_da_node_hdr
413
        btree           xfs_da_node_entry
414
ends
415
 
416
 
417
; packet extent
418
struct xfs_bmbt_rec
419
        l0              dq ?
420
        l1              dq ?
421
ends
422
 
423
 
424
; unpacked extent
425
struct xfs_bmbt_irec
426
        br_startoff     dq ?            ; starting file offset
427
        br_startblock   dq ?            ; starting block number
428
        br_blockcount   dd ?            ; number of blocks
429
        br_state        dd ?            ; extent state
430
ends
431
 
432
 
433
; bmap root header, on-disk form only
434
struct xfs_bmdr_block
435
        bb_level        dw ?            ; 0 is a leaf
436
        bb_numrecs      dw ?            ; current number of data records
437
ends
438
 
439
 
440
; key structure for non-leaf levels of the tree
441
struct xfs_bmbt_key
442
        br_startoff     dq ?            ; starting file offset
443
ends
444
 
445
 
446
sizeof.xfs_bmbt_ptr = 8                 ; workaround
447
sizeof.xfs_bmdr_ptr = 8                 ; workaround
448
 
449
 
450
; long form header: bmap btrees
451
; xfs_btree_lblock is xfs_bmbt_block (xfs_btree.h)
452
struct xfs_bmbt_block
453
        bb_magic        dd ?            ; magic number for block type
454
        bb_level        dw ?            ; 0 is a leaf
455
        bb_numrecs      dw ?            ; current number of data records
456
        bb_leftsib      dq ?            ; left sibling block or NULLDFSBNO
457
        bb_rightsib     dq ?            ; right sibling block or NULLDFSBNO
458
ends
459
 
460
 
461
; high level inode structure
462
struct xfs_inode
463
        di_core                 xfs_dinode_core ; main info, aka core
464
        di_next_unlinked        dd ?            ; unlinked but still used inode (if any, XFS_NULL otherwise)
465
        di_u                    db ?            ; data fork inode part
466
;        di_a                    db ?           ; data attribute
467
ends
468
 
469
 
470
; internal data for every XFS partition
471
; this _is_ XFS partition structure
472
; most fields are unpacked or bswap'ed values from the superblock, so see xfs_sb structure above
473
struct XFS PARTITION
474
        Lock                    MUTEX ?         ; access mutex
475
        blocksize               dd ?
476
        sectsize                dd ?
477
        dirblocksize            dd ?
478
        rootino                 dq ?
479
        cur_block               dd ?
480
        cur_inode               dd ?
481
        cur_sect                dd ?
482
        cur_dirblock            dd ?
483
        tmp_inode               dd ?
484
        versionnum              dd ?
485
        features2               dd ?
486
        inodesize               dd ?
487
        inopblock               dd ?
488
        blocklog                dd ?
489
        sectlog                 dd ?
490
        inodelog                dd ?
491
        inopblog                dd ?
492
        agblklog                dd ?
493
        blockmsectlog           dd ?
494
        inodetoblocklog         dd ?
495
        dirblklog               dd ?
496
        sectpblock              dd ?
497
        agblocks                dd ?
498
        ; helpers, temporary vars, etc
499
        agblockmask             dq ?
500
        extent                  xfs_bmbt_irec
501
        left_extents            dd ?
502
        left_leaves             dd ?
503
        bytes_to_read           dd ?
504
        bytes_read              dd ?
505
        entries_read            dd ?
506
        file_offset             dq ?
507
        max_dirblockaddr        dd ?
508
        next_block_num          dq ?
509
        dir2_leaf_offset_blocks dd ?
510
        dir2_free_offset_blocks dd ?
511
        cur_inode_save          dd ?
512
        bytes_left_in_file      dq ?
513
        ro_nextents             dd ?
514
        bb_ptrs                 dd ?
515
        maxnumrecs              dd ?
516
        buffer_pos              dd ?
517
        eof                     dd ?
518
ends