3 # This is a test script for the overlay function of fusefile.
5 # 1) prepare a base image
6 # 2) set up a fusefile overlay
8 # 4) dismantle the fusefile overlay
9 # 5) remove test images
11 ; ID is hour, minute and second values packed into a string
13 'ID (apply string (3 3 (now)))
14 'BASE (format "%s.raw" ID)
15 'OLY (format "%s.oly" ID)
21 'LIBC6 "/lib/x86_64-linux-gnu/libc.so.6"
25 (import LIBC6 "on_exit" "int" "void*" "void*")
29 (write-line 2 (string "terminating: " x " " (get-string y)))
30 (! (format "fusermount -u %s" BASE))
34 ## note: BASE is set up as a holes file with SEGN segments of size SEGSZ
35 (! (format "dd if=/dev/zero of=%s bs=%d seek=%d count=0 status=none"
37 (unless (= (! (format "fusefile %s %s -overlay:%s %s"
38 "-ononempty -oallow_other" BASE OLY BASE)))
40 (on_exit (callback 'onexit "void" "int" "void*") MINE)
42 (println (list BASE OLY))
44 (define (die) (write-line 2 (apply string (args))))
48 (define (pos X (OFF 0))
51 (define (read-segment FILE X (OFF 0) (N SEGSZ))
52 (let ((FD (open FILE "r")) (BUFFER ""))
54 (prog1 (when (= N (read FD BUFFER N)) BUFFER)
57 (define (write-segment FILE X DATA (OFF 0))
58 (let ((FD (open FILE "u")))
64 (define (read-ulong FD)
66 (when (= 8 (read FD BUFFER 8)) ((unpack "ld" BUFFER) 0))))
69 (let ((AT (file-info BASE 0)) (FD (open OLY "r")) (COUNT 0) (OUT '()))
71 (unless (setf COUNT (read-ulong FD))
72 (write-line 2 "** Bad count")
76 (push (list (read-ulong FD) (read-ulong FD)) OUT -1))
79 (define (check-segment AT DATA (OFF 0))
80 (write-segment BASE AT DATA OFF)
82 (format "check %2d %d: %s %s %s" AT
84 (if (= (read-segment BASE AT OFF (length DATA)) DATA) "ok" "error")
85 (if (= (read-segment OLY AT OFF (length DATA)) DATA) "ok" "error")
86 (string (read-table))))
92 DATA (pack (dup "b" SEGSZ) (rand 256 SEGSZ))
93 DATB (pack (dup "b" (* 4 SEGSZ)) (rand 256 (* 4 SEGSZ)))
95 (check-segment 0 DATA 0)
97 (check-segment AT DATA)
98 (check-segment (+ AT 2) DATA)
99 (check-segment (+ AT 1) DATA)
100 (check-segment (- AT 1) DATA -10)
101 (check-segment (- AT 1) DATA 10)
103 (check-segment 0 DATA 0)
104 (check-segment 1 DATA 1)
105 (check-segment 2 DATA 2)
106 (check-segment 0 DATB 10)
108 (check-segment (- SEGN 1) DATA 0)
110 ;(setf DATA (pack (dup "b" SEGSZ) (rand 256 SEGSZ)) AT (- SEGN 4))