smb-server 0.12.1

SMB2/3 file-sharing server library with pluggable storage backends.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
//! A writable backend rebuilt on the cache directory of an earlier one, and
//! the use of the directory itself.

use std::fs;
use std::sync::Arc;
use std::sync::atomic::Ordering::SeqCst;

use tokio::sync::Notify;
use tokio::task::JoinSet;

use super::fixture::{TestBucket, foreground, pattern, put};
use super::gateway::REGION;
use super::proxy::{Fault, Reply};
use super::share::{
    Listed, READ, Rig, Smb, Spec, WRITE_ATTRIBUTES, filetime, names, wait_for_requests, wait_until,
    wait_until_async, writable_builder,
};
use super::writes::{changes, create_dir, create_file, open_rw, records};
use crate::ntstatus::STATUS_OBJECT_NAME_NOT_FOUND;
use crate::s3::record::{Record, RecordId, TombstoneRecord};
use crate::tests::logs::Logs;
use crate::tests::util::scratch_dir;
use crate::{OpenIntent, OpenOptions, S3Backend, S3Error, ShareBackend, SmbPath};

/// What a directory listing and the files in it say, for comparing.
type Seen = Vec<(String, u64, u32, [u64; 4])>;

fn seen(listed: &[Listed]) -> Seen {
    let mut seen: Seen = listed
        .iter()
        .map(|e| (e.name.clone(), e.size, e.attributes, e.times))
        .collect();
    seen.sort();
    seen
}

async fn listing(smb: &mut Smb, dir: &str) -> Seen {
    let opened = smb.open_dir(dir).await.unwrap();
    let listed = smb.list(opened.id, "*").await;
    smb.close(opened.id).await;
    seen(&listed)
}

#[tokio::test]
async fn files_directories_times_and_attributes_come_back_after_a_restart() {
    let mut rig = Rig::writable().await;
    let big = pattern(7, 2 * (1 << 20) + 333);
    let based = pattern(1, 200_000);
    put(rig.store(), "stored.bin", &based).await;
    put(rig.store(), "untouched.txt", b"as it is").await;

    // A directory with a name that needs encoding, and files in it.
    let dir = rig.smb.create("dir one", create_dir()).await.unwrap();
    let name = "dir one\\f+ile%1 \u{e9}.txt";
    let made = rig.smb.create(name, create_file()).await.unwrap();
    for (at, piece) in big.chunks(60_000).enumerate() {
        assert_eq!(
            rig.smb.write(made.id, (at * 60_000) as u64, piece).await,
            Ok(piece.len() as u32)
        );
    }
    assert_eq!(rig.smb.flush(made.id).await, 0);
    let empty = rig.smb.create("empty.txt", create_file()).await.unwrap();
    assert_eq!(rig.smb.flush(empty.id).await, 0);
    let small = rig
        .smb
        .create("dir one\\small.txt", create_file())
        .await
        .unwrap();
    assert_eq!(rig.smb.write(small.id, 0, b"tiny").await, Ok(4));
    assert_eq!(rig.smb.flush(small.id).await, 0);

    // An object with pieces written into it, and a time on it.
    let patched = rig.smb.create("stored.bin", open_rw()).await.unwrap();
    assert_eq!(rig.smb.write(patched.id, 10, &[9; 100]).await, Ok(100));
    assert_eq!(
        rig.smb.write(patched.id, 150_000, &[8; 4000]).await,
        Ok(4000)
    );
    assert_eq!(rig.smb.set_size(patched.id, 199_000).await, 0);
    assert_eq!(rig.smb.flush(patched.id).await, 0);
    let mut patched_data = based.to_vec();
    patched_data[10..110].fill(9);
    patched_data[150_000..154_000].fill(8);
    patched_data.truncate(199_000);

    // Times and attributes on an object nothing else changed.
    let marked = rig
        .smb
        .create("untouched.txt", Spec::FILE.access(READ | WRITE_ATTRIBUTES))
        .await
        .unwrap();
    let times = [
        filetime(1_400_000_000, 0),
        filetime(1_410_000_000, 7_000),
        filetime(1_420_000_000, 0),
        filetime(1_430_000_000, 100),
    ];
    assert_eq!(
        rig.smb
            .set_basic(marked.id, times.map(|t| t as i64), 0x2)
            .await,
        0
    );
    for id in [dir.id, made.id, empty.id, small.id, patched.id, marked.id] {
        rig.smb.close(id).await;
    }

    let root_before = listing(&mut rig.smb, "").await;
    let dir_before = listing(&mut rig.smb, "dir one").await;
    assert_eq!(
        root_before.iter().map(|e| e.0.as_str()).collect::<Vec<_>>(),
        ["dir one", "empty.txt", "stored.bin", "untouched.txt"]
    );
    let records_before = records(&rig);
    assert_eq!(records_before.len(), 5);
    let entries_before = rig.backend.overlay_len();
    let puts = changes(&rig);
    assert_eq!(puts, 1, "only the directory reached the bucket");

    for round in 0..2 {
        rig = rig.restart().await;
        assert_eq!(rig.backend.overlay_len(), entries_before, "round {round}");
        assert_eq!(
            listing(&mut rig.smb, "").await,
            root_before,
            "round {round}"
        );
        assert_eq!(listing(&mut rig.smb, "dir one").await, dir_before);
        assert_eq!(rig.smb.contents(name, 50_000).await, big.to_vec());
        assert_eq!(rig.smb.contents("dir one\\small.txt", 10).await, b"tiny");
        assert_eq!(rig.smb.contents("empty.txt", 10).await, b"");
        assert_eq!(rig.smb.contents("stored.bin", 40_000).await, patched_data);
        assert_eq!(rig.smb.contents("untouched.txt", 10).await, b"as it is");
        let marked = rig.smb.open("untouched.txt").await.unwrap();
        assert_eq!((marked.times, marked.attributes), (times, 0x2));
        assert_eq!(records(&rig), records_before, "round {round}");
        assert_eq!(
            changes(&rig),
            puts,
            "a restart changes nothing in the bucket"
        );
    }
}

#[tokio::test]
async fn bytes_written_past_the_flushed_ranges_are_not_kept_when_the_save_at_close_fails() {
    let mut rig = Rig::writable().await;
    let base = pattern(0, 100);
    put(rig.store(), "f.bin", &base).await;
    let file = rig.smb.create("f.bin", open_rw()).await.unwrap();
    assert_eq!(rig.smb.write(file.id, 0, &[b'a'; 10]).await, Ok(10));
    assert_eq!(rig.smb.flush(file.id).await, 0);
    assert_eq!(rig.smb.write(file.id, 50, &[b'b'; 10]).await, Ok(10));
    assert_eq!(rig.smb.write(file.id, 90, &[b'c'; 20]).await, Ok(20));
    rig.backend.hooks().disk_full.store(true, SeqCst);
    rig.backend.hooks().record_writes.store(1, SeqCst);
    rig.smb.close(file.id).await;
    assert_eq!(rig.backend.hooks().record_writes.load(SeqCst), 0);

    let mut rig = rig.restart().await;
    let mut expected = base.to_vec();
    expected[..10].fill(b'a');
    assert_eq!(rig.smb.contents("f.bin", 30).await, expected);
}

#[tokio::test]
async fn a_name_that_was_made_before_a_restart_cannot_be_made_again() {
    let mut rig = Rig::writable().await;
    let file = rig.smb.create("Kept.txt", create_file()).await.unwrap();
    assert_eq!(rig.smb.flush(file.id).await, 0);
    let mut rig = rig.restart().await;
    assert_eq!(
        rig.smb.create("kept.TXT", create_file()).await.unwrap_err(),
        crate::ntstatus::STATUS_OBJECT_NAME_COLLISION
    );
    let again = rig.smb.open("kept.txt").await.unwrap();
    assert_eq!(again.size, 0);
    let root = rig.smb.open_dir("").await.unwrap();
    assert_eq!(names(&rig.smb.list(root.id, "*").await), ["Kept.txt"]);
}

#[tokio::test]
async fn ids_are_random_and_not_made_from_the_name() {
    let mut rig = Rig::writable().await;
    let file = rig.smb.create("same.txt", create_file()).await.unwrap();
    assert_eq!(rig.smb.flush(file.id).await, 0);
    let first = records(&rig)[0].id.clone();

    let (bucket, proxy, _cache) = rig.stop().await;
    let mut rig = Rig::start(bucket, proxy, scratch_dir(), |b| b).await;
    let file = rig.smb.create("same.txt", create_file()).await.unwrap();
    assert_eq!(rig.smb.flush(file.id).await, 0);
    assert_ne!(first, records(&rig)[0].id);
}

#[tokio::test]
async fn a_cache_directory_in_use_cannot_be_used_by_another_backend() {
    let rig = Rig::writable().await;
    let second = writable_builder(&rig.bucket, rig.proxy.addr, rig.cache_dir())
        .build()
        .await;
    let Err(S3Error::InvalidArgument(why)) = second.map(|_| ()) else {
        panic!("a second backend took the directory");
    };
    assert!(why.contains("in use"), "{why}");
}

#[tokio::test]
async fn a_cache_directory_of_another_bucket_prefix_endpoint_or_case_setting_is_refused() {
    let rig = Rig::writable().await;
    let (bucket, proxy, cache) = rig.stop().await;
    let other_bucket = TestBucket::new().await;
    let credentials = (&bucket.gateway.access_key, &bucket.gateway.secret_key);
    for (what, built) in [
        (
            "bucket",
            S3Backend::builder(format!("http://{}", proxy.addr), REGION, &other_bucket.name)
                .credentials(credentials.0, credentials.1)
                .cache_dir(cache.path())
                .build()
                .await,
        ),
        (
            "prefix",
            S3Backend::builder(format!("http://{}", proxy.addr), REGION, &bucket.name)
                .credentials(credentials.0, credentials.1)
                .prefix("elsewhere")
                .cache_dir(cache.path())
                .build()
                .await,
        ),
        (
            "endpoint",
            S3Backend::builder(
                format!("http://{}", bucket.gateway.addr),
                REGION,
                &bucket.name,
            )
            .credentials(credentials.0, credentials.1)
            .cache_dir(cache.path())
            .build()
            .await,
        ),
        (
            "case setting",
            S3Backend::builder(format!("http://{}", proxy.addr), REGION, &bucket.name)
                .credentials(credentials.0, credentials.1)
                .case_insensitive(false)
                .cache_dir(cache.path())
                .build()
                .await,
        ),
    ] {
        let Err(S3Error::InvalidArgument(why)) = built.map(|_| ()) else {
            panic!("{what} was not refused");
        };
        assert!(why.contains("belongs to another"), "{what}: {why}");
    }
}

#[tokio::test]
async fn a_build_that_fails_on_the_bucket_leaves_the_cache_directory_as_it_was() {
    let mut rig = Rig::writable().await;
    let file = rig.smb.create("kept.txt", create_file()).await.unwrap();
    assert_eq!(rig.smb.write(file.id, 0, b"kept").await, Ok(4));
    assert_eq!(rig.smb.flush(file.id).await, 0);
    let (bucket, proxy, cache) = rig.stop().await;
    let junk = cache.path().join("records").join("1".repeat(32));
    fs::write(&junk, b"garbage").unwrap();
    let stray = cache.path().join("data").join("2".repeat(32));
    fs::write(&stray, b"no record").unwrap();

    proxy.inject(
        |seen| seen.method == "GET" && seen.has_param("list-type"),
        Fault::Reply(Reply::error(403, "AccessDenied")),
        usize::MAX,
    );
    let failed = writable_builder(&bucket, proxy.addr, cache.path())
        .build()
        .await;
    assert!(failed.is_err());
    assert!(junk.exists() && stray.exists());
    assert!(names_in(&cache.path().join("conflicts")).is_empty());

    proxy.clear_rules();
    let mut rig = Rig::start(bucket, proxy, cache, |builder| builder).await;
    assert!(!junk.exists() && !stray.exists());
    assert_eq!(rig.smb.contents("kept.txt", 10).await, b"kept");
}

fn names_in(dir: &std::path::Path) -> Vec<String> {
    let mut names: Vec<String> = fs::read_dir(dir)
        .unwrap()
        .map(|entry| entry.unwrap().file_name().to_string_lossy().into_owned())
        .collect();
    names.sort();
    names
}

#[tokio::test]
async fn records_and_data_that_cannot_be_used_move_to_conflicts_and_the_rest_comes_back() {
    let mut rig = Rig::writable().await;
    for name in ["good.txt", "short.txt", "gone.txt"] {
        let file = rig.smb.create(name, create_file()).await.unwrap();
        assert_eq!(rig.smb.write(file.id, 0, b"0123456789").await, Ok(10));
        assert_eq!(rig.smb.flush(file.id).await, 0);
        rig.smb.close(file.id).await;
    }
    let all = records(&rig);
    let by_key = |key: &str| all.iter().find(|r| r.key == key).unwrap().clone();
    let (short, gone) = (by_key("short.txt"), by_key("gone.txt"));
    let (bucket, proxy, cache) = rig.stop().await;

    let data = cache.path().join("data");
    fs::OpenOptions::new()
        .write(true)
        .open(data.join(short.id.as_str()))
        .unwrap()
        .set_len(4)
        .unwrap();
    fs::remove_file(data.join(gone.id.as_str())).unwrap();

    let mut rig = Rig::start(bucket, proxy, cache, |builder| builder).await;

    assert_eq!(rig.smb.contents("good.txt", 100).await, b"0123456789");
    for name in ["short.txt", "gone.txt"] {
        assert_eq!(
            rig.smb.open(name).await.unwrap_err(),
            STATUS_OBJECT_NAME_NOT_FOUND,
            "{name}"
        );
    }
    assert_eq!(rig.backend.overlay_len(), 1);
}

#[tokio::test]
async fn a_move_to_conflicts_is_logged_at_error_level() {
    let temp = scratch_dir();
    let junk = "2".repeat(32);
    let logs = Logs::new();
    let dir = crate::s3::cachedir::CacheDir::open(temp.path(), "identity").unwrap();
    fs::write(temp.path().join("records").join(&junk), b"junk").unwrap();
    dir.recover("", false).unwrap();
    let log = logs.text();
    assert!(log.contains("ERROR"), "{log}");
    assert!(log.contains(&junk), "{log}");
    assert!(log.contains("conflicts"), "{log}");
    assert!(
        !log.contains("junk"),
        "the contents of the record are not logged"
    );
}

#[tokio::test]
async fn a_key_to_delete_is_hidden_from_lookups_and_listings() {
    let rig = Rig::writable().await;
    put(rig.store(), "gone.txt", b"x").await;
    put(rig.store(), "kept.txt", b"y").await;
    let (bucket, proxy, cache) = rig.stop().await;
    let record = Record::Tombstone(TombstoneRecord {
        id: RecordId::parse(&"a".repeat(32)).unwrap(),
        keys: vec!["gone.txt".to_owned()],
    });
    fs::write(
        cache.path().join("records").join("a".repeat(32)),
        record.encode(),
    )
    .unwrap();
    let mut rig = Rig::start(bucket, proxy, cache, |builder| builder).await;
    assert_eq!(
        rig.smb.open("gone.txt").await.unwrap_err(),
        STATUS_OBJECT_NAME_NOT_FOUND
    );
    assert!(rig.smb.open("kept.txt").await.is_ok());
    let root = rig.smb.open_dir("").await.unwrap();
    assert_eq!(names(&rig.smb.list(root.id, "*").await), ["kept.txt"]);
    assert!(rig.smb.list(root.id, "gone.txt").await.is_empty());
}

fn tombstone(id: &str, keys: &[&str]) -> Record {
    Record::Tombstone(TombstoneRecord {
        id: RecordId::parse(id).unwrap(),
        keys: keys.iter().map(|key| (*key).to_owned()).collect(),
    })
}

#[tokio::test]
async fn a_file_made_where_a_key_waits_to_be_deleted_may_exist_in_the_bucket() {
    let rig = Rig::writable().await;
    put(rig.store(), "gone.txt", b"old").await;
    let (bucket, proxy, cache) = rig.stop().await;
    let id = "b".repeat(32);
    fs::write(
        cache.path().join("records").join(&id),
        tombstone(&id, &["gone.txt"]).encode(),
    )
    .unwrap();
    let mut rig = Rig::start(bucket, proxy, cache, |builder| builder).await;
    for name in ["gone.txt", "fresh.txt"] {
        let file = rig.smb.create(name, create_file()).await.unwrap();
        assert_eq!(file.action, 2, "{name}");
        assert_eq!(rig.smb.flush(file.id).await, 0);
    }
    let remote = |key: &str| {
        records(&rig)
            .into_iter()
            .find(|record| record.key == key)
            .unwrap()
            .remote
    };
    assert!(remote("gone.txt"));
    assert!(!remote("fresh.txt"));
}

#[tokio::test]
async fn an_entry_is_not_hidden_by_a_key_to_delete_of_its_name() {
    let mut rig = Rig::writable().await;
    let file = rig.smb.create("both.txt", create_file()).await.unwrap();
    assert_eq!(rig.smb.write(file.id, 0, b"new").await, Ok(3));
    assert_eq!(rig.smb.flush(file.id).await, 0);
    put(rig.store(), "both.txt", b"old").await;
    put(rig.store(), "gone.txt", b"old").await;
    let (bucket, proxy, cache) = rig.stop().await;
    let id = "c".repeat(32);
    fs::write(
        cache.path().join("records").join(&id),
        tombstone(&id, &["both.txt", "gone.txt"]).encode(),
    )
    .unwrap();

    let mut rig = Rig::start(bucket, proxy, cache, |builder| builder).await;
    assert_eq!(rig.smb.contents("both.txt", 10).await, b"new");
    assert_eq!(
        rig.smb.open("gone.txt").await.unwrap_err(),
        STATUS_OBJECT_NAME_NOT_FOUND
    );
}

#[tokio::test]
async fn a_directory_wins_over_an_object_of_its_name_when_entries_are_below_it() {
    let mut rig = Rig::writable().await;
    rig.smb.create("x", create_dir()).await.unwrap();
    let inner = rig.smb.create("x\\inner.txt", create_file()).await.unwrap();
    assert_eq!(rig.smb.write(inner.id, 0, b"in").await, Ok(2));
    assert_eq!(rig.smb.flush(inner.id).await, 0);
    let (bucket, proxy, cache) = rig.stop().await;
    bucket
        .client
        .delete_object("x/", foreground())
        .await
        .unwrap();
    put(&bucket.client, "x", b"an object").await;

    let mut rig = Rig::start(bucket, proxy, cache, |builder| builder).await;
    let dir = rig.smb.open_dir("x").await.unwrap();
    assert_eq!(names(&rig.smb.list(dir.id, "*").await), ["inner.txt"]);
    assert_eq!(rig.smb.contents("x\\inner.txt", 10).await, b"in");
    let root = rig.smb.open_dir("").await.unwrap();
    let listed = rig.smb.list(root.id, "*").await;
    assert_eq!(names(&listed), ["x"]);
    assert!(listed[0].is_dir());
    assert_eq!(
        rig.smb
            .create("x", Spec::FILE.access(READ))
            .await
            .unwrap_err(),
        crate::ntstatus::STATUS_FILE_IS_A_DIRECTORY
    );
}

#[tokio::test]
async fn a_directory_that_only_entries_below_it_imply_lists_and_opens() {
    let mut rig = Rig::writable().await;
    rig.smb.create("d", create_dir()).await.unwrap();
    let file = rig.smb.create("d\\f.txt", create_file()).await.unwrap();
    assert_eq!(rig.smb.write(file.id, 0, b"in d").await, Ok(4));
    assert_eq!(rig.smb.flush(file.id).await, 0);
    let (bucket, proxy, cache) = rig.stop().await;

    // With no marker in the bucket, only the file below the directory holds
    // it up.
    bucket
        .client
        .delete_object("d/", foreground())
        .await
        .unwrap();

    let mut rig = Rig::start(bucket, proxy, cache, |builder| builder).await;
    let root = rig.smb.open_dir("").await.unwrap();
    let listed = rig.smb.list(root.id, "*").await;
    assert_eq!(names(&listed), ["d"]);
    assert!(listed[0].is_dir());
    let d = rig.smb.open_dir("d").await.unwrap();
    assert_eq!(names(&rig.smb.list(d.id, "*").await), ["f.txt"]);
    assert_eq!(rig.smb.contents("d\\f.txt", 10).await, b"in d");
    let made = rig.smb.create("d\\g.txt", create_file()).await.unwrap();
    assert_eq!(rig.smb.write(made.id, 0, b"x").await, Ok(1));
    assert_eq!(names(&rig.smb.list(d.id, "*").await), ["f.txt", "g.txt"]);
    assert_eq!(
        rig.smb.open_dir("d").await.map(|d| d.attributes & 0x10),
        Ok(0x10)
    );
}

#[tokio::test]
async fn a_directory_with_entries_is_not_empty() {
    let mut rig = Rig::writable().await;
    rig.smb.create("d", create_dir()).await.unwrap();
    let dir = rig
        .backend
        .open(&"d".parse::<SmbPath>().unwrap(), OpenOptions::default())
        .await
        .unwrap()
        .0;
    assert!(dir.dir_is_empty().await.unwrap());
    rig.smb.create("d\\f.txt", create_file()).await.unwrap();
    assert!(!dir.dir_is_empty().await.unwrap());
}

#[tokio::test]
async fn the_volume_is_the_one_that_holds_the_cache_directory() {
    let rig = Rig::writable().await;
    let info = rig.backend.volume_info().await.unwrap();
    assert_ne!(info, crate::VolumeInfo::default());
    let held = volume_of(rig.cache_dir());
    assert_eq!(info.total_allocation_units, held.total_allocation_units);
    assert_eq!(info.allocation_unit(), held.allocation_unit());
    assert_eq!(info.serial_number, held.serial_number);
    assert_eq!(info.max_name_length, held.max_name_length);
    assert!(info.caller_available_allocation_units <= info.total_allocation_units);
    assert!(info.actual_available_allocation_units <= info.total_allocation_units);
}

/// The volume that holds the directory `dir`.
fn volume_of(dir: &std::path::Path) -> crate::VolumeInfo {
    #[cfg(unix)]
    {
        let st = rustix::fs::statvfs(dir).unwrap();
        crate::host::volume_info(&st, st.f_fsid)
    }
    #[cfg(windows)]
    {
        crate::host::volume_info_of(&fs::File::open(dir.join("lock")).unwrap()).unwrap()
    }
}

#[tokio::test]
async fn a_directory_create_whose_request_is_dropped_still_finishes() {
    let rig = Rig::writable().await;
    let release = Arc::new(Notify::new());
    let path = format!("/{}/held/", rig.bucket.name);
    rig.proxy.inject(
        move |seen| seen.method == "PUT" && seen.target == path,
        Fault::Hold(Arc::clone(&release)),
        1,
    );
    let opts = OpenOptions {
        write: true,
        intent: OpenIntent::Create,
        directory: true,
        ..OpenOptions::default()
    };
    let backend = rig.backend.clone();
    let mut tasks = JoinSet::new();
    tasks.spawn(async move {
        backend
            .open(&"held".parse::<SmbPath>().unwrap(), opts)
            .await
            .map(|_| ())
    });
    wait_for_requests(&rig.proxy, 1, |seen| seen.method == "PUT").await;
    assert_eq!(rig.proxy.count(|seen| seen.method == "PUT"), 1);
    let held = records(&rig);
    assert_eq!(
        held.len(),
        1,
        "the record is written before the marker is put"
    );
    assert!(held[0].marker_pending);
    assert!(
        rig.store()
            .head_object("held/", foreground())
            .await
            .is_err()
    );
    tasks.abort_all();
    while tasks.join_next().await.is_some() {}
    release.notify_one();
    wait_until_async("the marker to land", async || {
        rig.store().head_object("held/", foreground()).await.is_ok()
    })
    .await;
    wait_until("the record to go, as the marker carries the times", || {
        records(&rig).is_empty() && rig.backend.overlay_len() == 0
    })
    .await;
}