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_remount(bfuse):
24 def test_lostfound(bfuse):
27 lf = bfuse.mnt / "lost+found"
31 assert st.st_mode == 0o40700
36 def test_create(bfuse):
39 path = bfuse.mnt / "file"
41 with util.Timestamp() as ts:
42 fd = os.open(path, os.O_CREAT, 0o700)
51 assert st.st_mode == 0o100700
52 assert st.st_mtime == st.st_ctime
53 assert st.st_mtime == st.st_atime
54 assert ts.contains(st.st_mtime)
57 dst = bfuse.mnt.stat()
58 assert dst.st_mtime == dst.st_ctime
59 assert ts.contains(dst.st_mtime)
64 def test_mkdir(bfuse):
67 path = bfuse.mnt / "dir"
69 with util.Timestamp() as ts:
76 assert st.st_mode == 0o40700
77 assert st.st_mtime == st.st_ctime
78 assert st.st_mtime == st.st_atime
79 assert ts.contains(st.st_mtime)
82 dst = bfuse.mnt.stat()
83 assert dst.st_mtime == dst.st_ctime
84 assert ts.contains(dst.st_mtime)
89 def test_unlink(bfuse):
92 path = bfuse.mnt / "file"
93 path.touch(mode=0o600, exist_ok=False)
95 with util.Timestamp() as ts:
98 assert not path.exists()
101 dst = bfuse.mnt.stat()
102 assert dst.st_mtime == dst.st_ctime
103 assert ts.contains(dst.st_mtime)
108 def test_rmdir(bfuse):
111 path = bfuse.mnt / "dir"
112 path.mkdir(mode=0o700, exist_ok=False)
114 with util.Timestamp() as ts:
117 assert not path.exists()
120 dst = bfuse.mnt.stat()
121 assert dst.st_mtime == dst.st_ctime
122 assert ts.contains(dst.st_mtime)
127 def test_rename(bfuse):
132 path = srcdir / "file"
133 path.touch(mode=0o600, exist_ok=False)
135 destdir = srcdir / "dir"
136 destdir.mkdir(mode=0o700, exist_ok=False)
138 destpath = destdir / "file"
140 path_pre_st = path.stat()
142 with util.Timestamp() as ts:
143 os.rename(path, destpath)
145 assert not path.exists()
146 assert destpath.is_file()
149 src_st = srcdir.stat()
150 assert src_st.st_mtime == src_st.st_ctime
151 assert ts.contains(src_st.st_mtime)
153 dest_st = destdir.stat()
154 assert dest_st.st_mtime == dest_st.st_ctime
155 assert ts.contains(dest_st.st_mtime)
158 path_post_st = destpath.stat()
159 assert path_post_st.st_mtime == path_pre_st.st_mtime
160 assert path_post_st.st_atime == path_pre_st.st_atime
161 assert ts.contains(path_post_st.st_ctime)
166 def test_link(bfuse):
171 path = srcdir / "file"
172 path.touch(mode=0o600, exist_ok=False)
174 destdir = srcdir / "dir"
175 destdir.mkdir(mode=0o700, exist_ok=False)
177 destpath = destdir / "file"
179 path_pre_st = path.stat()
180 srcdir_pre_st = srcdir.stat()
182 with util.Timestamp() as ts:
183 os.link(path, destpath)
186 assert destpath.is_file()
188 # Verify source dir is unchanged.
189 srcdir_post_st = srcdir.stat()
190 assert srcdir_pre_st == srcdir_post_st
193 destdir_st = destdir.stat()
194 assert destdir_st.st_mtime == destdir_st.st_ctime
195 assert ts.contains(destdir_st.st_mtime)
198 path_post_st = path.stat()
199 destpath_post_st = destpath.stat()
200 assert path_post_st == destpath_post_st
202 assert path_post_st.st_mtime == path_pre_st.st_mtime
203 assert path_post_st.st_atime == path_pre_st.st_atime
204 assert ts.contains(path_post_st.st_ctime)
209 def test_write(bfuse):
212 path = bfuse.mnt / "file"
213 path.touch(mode=0o600, exist_ok=False)
217 fd = os.open(path, os.O_WRONLY)
220 with util.Timestamp() as ts:
221 written = os.write(fd, b'test')
227 post_st = path.stat()
228 assert post_st.st_atime == pre_st.st_atime
229 assert post_st.st_mtime == post_st.st_ctime
230 assert ts.contains(post_st.st_mtime)
232 assert path.read_bytes() == b'test'