2017-08-06 01:48:32 +05:30
|
|
|
(import
|
2017-09-08 20:21:33 +05:30
|
|
|
(bcache block-manager)
|
2017-08-11 20:11:57 +05:30
|
|
|
(btree)
|
2017-08-06 01:48:32 +05:30
|
|
|
(fmt fmt)
|
2017-08-10 19:37:20 +05:30
|
|
|
(matchable)
|
2017-08-11 20:11:57 +05:30
|
|
|
(mapping-tree)
|
2017-09-08 20:21:33 +05:30
|
|
|
(chezscheme))
|
2017-08-06 01:48:32 +05:30
|
|
|
|
|
|
|
;;;;---------------------------------------------------
|
|
|
|
;;;; Constants
|
|
|
|
;;;;---------------------------------------------------
|
|
|
|
|
|
|
|
;; FIXME: duplicate with main.scm
|
2017-08-10 19:37:20 +05:30
|
|
|
(define (current-metadata) "./metadata.bin")
|
2017-08-06 01:48:32 +05:30
|
|
|
|
2017-08-10 19:37:20 +05:30
|
|
|
(define $superblock-magic 27022010)
|
|
|
|
(define $superblock-salt 160774)
|
|
|
|
(define $uuid-size 16)
|
|
|
|
(define $space-map-root-size 128)
|
2017-08-06 01:48:32 +05:30
|
|
|
|
2017-09-08 20:21:33 +05:30
|
|
|
(define-ftype Superblock
|
|
|
|
(packed
|
|
|
|
(endian little
|
|
|
|
(struct
|
|
|
|
(csum unsigned-32)
|
|
|
|
(flags unsigned-32)
|
|
|
|
(block-nr unsigned-64)
|
|
|
|
(uuid (bytes $uuid-size))
|
|
|
|
(magic unsigned-32)
|
|
|
|
(version unsigned-32)
|
|
|
|
(time unsigned-32)
|
|
|
|
(trans-id unsigned-64)
|
|
|
|
(metadata-snap unsigned-64)
|
|
|
|
(data-space-map-root (bytes $space-map-root-size))
|
|
|
|
(metadata-space-map-root (bytes $space-map-root-size))
|
|
|
|
(data-mapping-root unsigned-64)
|
|
|
|
(device-details-root unsigned-64)
|
|
|
|
(data-block-size unsigned-32)
|
|
|
|
(metadata-block-size unsigned-32)
|
|
|
|
(metadata-nr-blocks unsigned-64)
|
|
|
|
(compat-flags unsigned-32)
|
|
|
|
(compat-ro-flags unsigned-32)
|
|
|
|
(incompat-flags unsigned-32)))))
|
2017-08-06 01:48:32 +05:30
|
|
|
|
|
|
|
;;;;---------------------------------------------------
|
|
|
|
;;;; Top level
|
|
|
|
;;;;---------------------------------------------------
|
|
|
|
|
|
|
|
(define (check-magic sb)
|
|
|
|
((let ((m (bytevector-u32-ref sb 32 (endianness little))))
|
|
|
|
(fmt #t (dsp "on disk magic: ") (num m) nl)
|
|
|
|
)))
|
|
|
|
|
|
|
|
(define (read-superblock)
|
|
|
|
(with-metadata (md (current-metadata))
|
2017-08-11 20:11:57 +05:30
|
|
|
(superblock-unpack (read-block md 0) 0)))
|
|
|
|
|
|
|
|
(define (dump-dev-tree)
|
|
|
|
(with-metadata (md (current-metadata))
|
|
|
|
(let ((sb (superblock-unpack (read-block md 0) 0)))
|
|
|
|
(btree-each (btree-open le64-type md (superblock-data-mapping-root sb))
|
|
|
|
(lambda (k v)
|
|
|
|
(fmt #t (dsp "dev-id: ") (num k)
|
|
|
|
(dsp ", mapping root: ") (num v) nl))))))
|
|
|
|
|
|
|
|
(define (dump-mappings root)
|
|
|
|
(with-metadata (md (current-metadata))
|
|
|
|
(btree-each (btree-open le64-type md root)
|
|
|
|
(lambda (k v)
|
|
|
|
(fmt #t (dsp "vblock: ") (num k)
|
|
|
|
(dsp ", pblock: ") (num v) nl)))))
|
|
|
|
|
|
|
|
(define (dump-all-mappings)
|
|
|
|
(with-metadata (md (current-metadata))
|
|
|
|
(let ((sb (superblock-unpack (read-block md 0) 0)))
|
|
|
|
(let ((mappings (mapping-tree-open md (superblock-data-mapping-root sb))))
|
|
|
|
(mapping-tree-each mappings
|
2017-08-12 23:57:21 +05:30
|
|
|
(lambda (dev-id vblock pblock time)
|
2017-08-11 20:11:57 +05:30
|
|
|
(fmt #t
|
|
|
|
(dsp "thin dev ") (num dev-id)
|
|
|
|
(dsp ", vblock ") (num vblock)
|
|
|
|
(dsp ", pblock ") (num pblock)
|
2017-08-12 23:57:21 +05:30
|
|
|
(dsp ", time ") (num time)
|
2017-08-11 20:11:57 +05:30
|
|
|
nl)))))))
|
2017-08-06 01:48:32 +05:30
|
|
|
|
|
|
|
(define (check-superblock)
|
|
|
|
(with-metadata (md (current-metadata))
|
|
|
|
(let ((superblock (read-block md 0)))
|
|
|
|
(fmt #t (dsp "checksum on disk: ") (dsp (bytevector-u32-ref superblock 0 (endianness little))) nl)
|
2017-08-10 19:37:20 +05:30
|
|
|
;(fmt #t (dsp "calculated checksum: ") (dsp (crc32-region $superblock-salt superblock 4 4092)) nl)
|
2017-08-06 01:48:32 +05:30
|
|
|
(check-magic superblock))))
|