3 # Tests of the fuse mount functionality.
9 pytestmark = pytest.mark.skipif(
10 not util.have_fuse(), reason="bcachefs not built with fuse support.")
12 def test_mount(bfuse):
17 def test_lostfound(bfuse):
20 lf = bfuse.mnt / "lost+found"
24 assert st.st_mode == 0o40700
29 def test_create(bfuse):
32 path = bfuse.mnt / "file"
34 with util.Timestamp() as ts:
35 fd = os.open(path, os.O_CREAT, 0o700)
44 assert st.st_mode == 0o100700
45 assert st.st_mtime == st.st_ctime
46 assert st.st_mtime == st.st_atime
47 assert ts.contains(st.st_mtime)
50 dst = bfuse.mnt.stat()
51 assert dst.st_mtime == dst.st_ctime
52 assert ts.contains(dst.st_mtime)
57 def test_mkdir(bfuse):
60 path = bfuse.mnt / "dir"
62 with util.Timestamp() as ts:
69 assert st.st_mode == 0o40700
70 assert st.st_mtime == st.st_ctime
71 assert st.st_mtime == st.st_atime
72 assert ts.contains(st.st_mtime)
75 dst = bfuse.mnt.stat()
76 assert dst.st_mtime == dst.st_ctime
77 assert ts.contains(dst.st_mtime)
82 def test_unlink(bfuse):
85 path = bfuse.mnt / "file"
86 path.touch(mode=0o600, exist_ok=False)
88 with util.Timestamp() as ts:
91 assert not path.exists()
94 dst = bfuse.mnt.stat()
95 assert dst.st_mtime == dst.st_ctime
96 assert ts.contains(dst.st_mtime)
101 def test_rmdir(bfuse):
104 path = bfuse.mnt / "dir"
105 path.mkdir(mode=0o700, exist_ok=False)
107 with util.Timestamp() as ts:
110 assert not path.exists()
113 dst = bfuse.mnt.stat()
114 assert dst.st_mtime == dst.st_ctime
115 assert ts.contains(dst.st_mtime)
120 def test_rename(bfuse):
125 path = srcdir / "file"
126 path.touch(mode=0o600, exist_ok=False)
128 destdir = srcdir / "dir"
129 destdir.mkdir(mode=0o700, exist_ok=False)
131 destpath = destdir / "file"
133 path_pre_st = path.stat()
135 with util.Timestamp() as ts:
136 os.rename(path, destpath)
138 assert not path.exists()
139 assert destpath.is_file()
142 src_st = srcdir.stat()
143 assert src_st.st_mtime == src_st.st_ctime
144 assert ts.contains(src_st.st_mtime)
146 dest_st = destdir.stat()
147 assert dest_st.st_mtime == dest_st.st_ctime
148 assert ts.contains(dest_st.st_mtime)
151 path_post_st = destpath.stat()
152 assert path_post_st.st_mtime == path_pre_st.st_mtime
153 assert path_post_st.st_atime == path_pre_st.st_atime
154 assert ts.contains(path_post_st.st_ctime)
159 def test_link(bfuse):
164 path = srcdir / "file"
165 path.touch(mode=0o600, exist_ok=False)
167 destdir = srcdir / "dir"
168 destdir.mkdir(mode=0o700, exist_ok=False)
170 destpath = destdir / "file"
172 path_pre_st = path.stat()
173 srcdir_pre_st = srcdir.stat()
175 with util.Timestamp() as ts:
176 os.link(path, destpath)
179 assert destpath.is_file()
181 # Verify source dir is unchanged.
182 srcdir_post_st = srcdir.stat()
183 assert srcdir_pre_st == srcdir_post_st
186 destdir_st = destdir.stat()
187 assert destdir_st.st_mtime == destdir_st.st_ctime
188 assert ts.contains(destdir_st.st_mtime)
191 path_post_st = path.stat()
192 destpath_post_st = destpath.stat()
193 assert path_post_st == destpath_post_st
195 assert path_post_st.st_mtime == path_pre_st.st_mtime
196 assert path_post_st.st_atime == path_pre_st.st_atime
197 assert ts.contains(path_post_st.st_ctime)
202 def test_write(bfuse):
205 path = bfuse.mnt / "file"
206 path.touch(mode=0o600, exist_ok=False)
210 fd = os.open(path, os.O_WRONLY)
213 with util.Timestamp() as ts:
214 written = os.write(fd, b'test')
220 post_st = path.stat()
221 assert post_st.st_atime == pre_st.st_atime
222 assert post_st.st_mtime == post_st.st_ctime
223 assert ts.contains(post_st.st_mtime)
225 assert path.read_bytes() == b'test'