forked from tituswinters/std-papers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesystem-injection.html
2156 lines (1936 loc) · 94.5 KB
/
filesystem-injection.html
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
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
body { color: #000000; background-color: #FFFFFF; max-width: 60em}
del { text-decoration: line-through; color: #8B0040; }
ins { text-decoration: underline; color: #005100; }
p.example { margin-left: 2em; }
pre.example { margin-left: 2em; }
div.example { margin-left: 2em; }
code.extract { background-color: #F5F6A2; }
pre.extract { margin-left: 2em; background-color: #F5F6A2;
border: 1px solid #E1E28E; }
p.function { }
.attribute { margin-left: 2em; }
.attribute dt { float: left; font-style: italic;
padding-right: 1ex; }
.attribute dd { margin-left: 0em; }
blockquote.std { color: #000000; background-color: #F1F1F1;
border: 1px solid #D1D1D1;
padding-left: 0.5em; padding-right: 0.5em; }
blockquote.stddel { text-decoration: line-through;
color: #000000; background-color: #FFEBFF;
border: 1px solid #ECD7EC;
padding-left: 0.5empadding-right: 0.5em; ; }
blockquote.stdins { text-decoration: underline;
color: #000000; background-color: #C8FFC8;
border: 1px solid #B3EBB3; padding: 0.5em; }
blockquote pre em { font-family: normal }
table { border: 1px solid black; border-spacing: 0px;
margin-left: auto; margin-right: auto; }
th { text-align: left; vertical-align: top;
padding-left: 0.8em; border: none; }
th.multicol { text-align: center; vertical-align:top;
padding-left: 0.8em; border: none; }
td { text-align: left; vertical-align: top;
padding-left: 0.8em; border: none; border-top: 1px solid black; }
ul.function { list-style-type: none; margin-top: 0.5ex }
ul.function > li { padding-top:0.25ex; padding-bottom:0.25ex }
pre.function { margin-bottom:0.5ex }
pre span.comment { font-family: serif; font-style: italic }
caption { font-size: 1.25em; font-weight: bold; padding-bottom: 3px;}
</style>
<title>User Injection of Filesystems</title>
</head>
<body>
<p><b>Document number:</b> p0544R0
<br><b>Date:</b> 2017-02-01
<br><b>Audience:</b> Library Evolution Working Group
<br><b>Reply to:</b>
Titus Winters <<a href="mailto:[email protected]">[email protected]</a>>,
Geoff Romer <<a href="mailto:[email protected]">[email protected]</a>>
</p>
<h1>User Injection of Filesystems</h1>
<ol>
<li><a href="#rationale">Rationale</a>
</li><li><a href="#design">Design Choices</a>
</li><li><a href="#wording">Proposed Wording</a>
</li></ol>
<h2 id="rationale">Rationale</h2>
<p>The existing proposals in the Filesystem TS (now adopted for inclusion with
C++17) effectively specify the C++ filesystem API as a set of C++ wrappers and
types (like <code>directory_iterator</code>) directly on top of whatever is
provided by the OS for filesystem interaction. This is easy to specify and
implement, but inflexible and likely does not provide the functionality needed
for a modern C++ codebase — for example, it is impossible to fake
filesystem errors in testing, or to use the same interfaces for in-memory
filesystems (avoiding the essential OS and I/O overhead). Our belief, based on
extensive experience in the Google codebase and production systems, is that
most robust C++ installations will wind up wrapping the proposed interface in
order to provide opportunities to change the backing store, simulate errors
for testing, etc. To that end, we propose the definition of a filesystem type,
and injection mechanisms to allow user-customization of the filesystem backend
used by the free functions provided by the Filesystem TS.</p>
<p>This proposal is pure-library, OS and compiler agnostic, and is
backwards compatible with any existing code written against the
Filesystem TS. It has not yet been implemented in this form. However,
the filesystems at use in Google production work in roughly this way
with small differences. In the Google design, multiple filesystems
are present at once, they are all pinned into the filesystem at some
root (/memfile, /virtualfs, etc) with the OS local filesystem as the
generic fallback. This works for us because we have no symlinks.
Once symlinks are in the equation, the design has to shift to
something like what we are describing.
</p>
<h2 id="design">Design Choices</h2>
<p>The biggest point of discussion in the design for filesystem injection is
how to specify where injection takes place. Is it a new filesystem root? If so,
how is it specified (especially on POSIX systems)? If you can inject at any
point in a filesystem, does that injection respect symlinks? If so, that
requires one (or more) OS calls on every filesystem call to resolve symlinks
in order to determine if the specified path(s) fall inside the injection point.
Since we cannot determine one policy that will satisfy all users for the above
questions, we instead choose to present a more general injection mechanism:
replace the filesystem entirely. In conjunction with the ability to get the
“default” filesystem, a user can then build a solution that forwards to the
underlying filesystem in a fashion congruent with any of the above designs.</p>
<!--Rationale for using the non-throwing versions: it's more general in
the case of status(), and it enables us to support exception-disabled
environments. -->
<p>Under this design, the expected cost is bounded by following an
atomic pointer plus a vtable dereference. In comparison to the
overhead of performing I/O through the OS, this is expected to be
negligible.</p>
<!-- Rationale for using atomic instead of shared_ptr: simplicity -->
<h2 id="wording">Proposed Wording</h2>
<p>Changes are relative to <a href="http://wg21.link/N4582">N4582</a>.</p>
<!--
* directory_iterator overhaul
* filesystem class
* default filesystem class
* inject_filesystem, get_default_filesystem
* individual filesystem functions
-->
<p>Add the following to the <code><filesystem></code> synopsis in
[fs.filesystem.syn]:</p>
<blockquote class="std">
…
<pre>class filesystem_error;
class directory_entry;
<ins>
class filesystem;
class default_filesystem_impl; <i>// exposition only</i>
class directory_traverser;
</ins>
class directory_iterator;
<i>// range access for</i> directory_iterator
directory_iterator begin(directory_iterator iter) noexcept;
directory_iterator end(const directory_iterator&) noexcept;
<ins>
bool operator==(const directory_iterator& lhs, const directory_iterator& rhs);
bool operator!=(const directory_iterator& lhs, const directory_iterator& rhs);
</ins>
class recursive_directory_iterator;
</pre>
…
<pre>typedef chrono::time_point<<i>trivial-clock</i>> file_time_type;
<ins>
<i>// filesystem injection</i>
extern atomic<filesystem*> current_filesystem; <i>// exposition only</i>
void inject_filesystem(filesystem& fs);
filesystem& default_filesystem();
</ins>
<i>// filesystem operation functions</i>
</pre>
…
</blockquote>
<p>Add a new paragraph to the end of [fs.err.report] as follows:</p>
<blockquote class="stdins">
<p>When a function that does not take an <code>error_code</code> parameter is
specified to call a function that takes an <code>error_code</code> parameter,
the outer function is understood to construct a local <code>error_code</code>
variable <code>ec</code> to pass to the function call. If <code>!ec</code>
after the call completes, unless otherwise specified the function throws a
<code>filesystem_error</code> exception containing <code>ec</code>, an
implementation-defined message, and any paths that were passed to the
function.</p>
</blockquote>
<p>Insert new sections above [class.directory_iterator]:</p>
<blockquote class="stdins">
<h2>27.10.? Class <code>filesystem</code> [class.filesystem]</h2>
<p>Class <code>filesystem</code> defines the base class for the types
of objects that provide access to the fundamental operations of a specific
file system. A special <code>filesystem</code> object
([class.default_filesystem_impl]) provides access to the native file system
provided by the operating system, and other <code>filesystem</code> objects
can implement virtual file systems for purposes such as testing.</p>
<p>Classes derived from <code>filesystem</code> shall satisfy all of the
requirements of <code>filesystem</code>.</p>
<pre>class filesystem {
public:
filesystem() = default;
virtual ~filesystem();
filesystem(const filesystem&) = delete;
filesystem& operator=(const filesystem&) = delete;
virtual bool copy_file(const path& from, const path& to,
copy_options options, error_code& ec) noexcept = 0;
virtual bool create_directory(const path& p, error_code& ec) noexcept = 0;
virtual bool create_directory(const path& p, const path& existing_p,
error_code& ec) noexcept = 0;
virtual void create_directory_symlink(
const path& to, const path& new_symlink, error_code& ec) noexcept = 0;
virtual void create_hard_link(const path& to, const path& new_hard_link,
error_code& ec) noexcept = 0;
virtual void create_symlink(const path& to, const path& new_symlink,
error_code& ec) noexcept = 0;
virtual path current_path(error_code& ec) const = 0;
virtual void current_path(const path& p, error_code& ec) noexcept = 0;
virtual bool equivalent(const path& p1, const path& p2, error_code& ec) const noexcept = 0;
virtual uintmax_t file_size(const path& p, error_code& ec) const noexcept = 0;
virtual uintmax_t hard_link_count(const path& p, error_code& ec) const noexcept = 0;
virtual file_time_type last_write_time(const path& p, error_code& ec) const noexcept = 0;
virtual void last_write_time(const path& p, file_time_type new_time,
error_code& ec) const noexcept = 0;
virtual void permissions(const path& p, perms prms, error_code& ec) const noexcept = 0;
virtual path read_symlink(const path& p, error_code& ec) const = 0;
virtual bool remove(const path& p, error_code& ec) noexcept = 0;
virtual void rename(const path& old_p, const path& new_p, error_code& ec) noexcept = 0;
virtual void resize_file(const path& p, uintmax_t new_size, error_code& ec) noexcept = 0;
virtual space_info space(const path& p, error_code& ec) const noexcept = 0;
virtual file_status status(const path& p, error_code& ec) const noexcept = 0;
virtual file_status symlink_status(const path& p, error_code& ec) const noexcept = 0;
virtual path system_complete(const path& p, error_code& ec) const = 0;
virtual path temp_directory_path(error_code& ec) = 0;
virtual unique_ptr<directory_traverser> directory_traverser(
const path& p, directory_options options, error_code& ec) const = 0;
};
</pre>
<h3>27.10.?.1 <code>filesystem</code> members [filesystem.members]</h3>
<h4>27.10.?.1.1 Copy file [filesystem.copy_file]</h4>
<pre class="function">virtual bool copy_file(const path& from, const path& to,
copy_options options, error_code& ec) noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.copy_file] paragraphs 3 to 9 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Requires:</i> At most one constant from each <code>copy_options</code>
group is present in <code>options</code>.</li>
<li><i>Effects:</i> Report a file already exists error as specified in
Error reporting (27.5.6.5) if:
<ul>
<li><code>exists(to)</code> and <code>equivalent(from, to)</code>, or</li>
<li><code>exists(to)</code> and
<code>(options & (copy_options::skip_existing |
copy_options::overwrite_existing | copy_options::update_existing)) ==
copy_options::none</code>.</li>
</ul>
Otherwise copy the contents and attributes of the file <code>from</code>
resolves to to the file <code>to</code> resolves to if:
<ul>
<li><code>!exists(to)</code>, or</li>
<li><code>exists(to)</code> and <code>(options &
copy_options::overwrite_existing) != copy_options::none</code>, or</li>
<li><code>exists(to)</code> and <code>(options &
copy_options::update_existing) != copy_options::none</code>, and
<code>from</code> is more recent than <code>to</code>, determined as if
by use of the <code>last_write_time</code> function.</li>
</ul>
Otherwise no effects.</li>
<li><i>Returns:</i> <code>true</code> if the <code>from</code> file was copied,
otherwise <code>false</code>. <del>The signature with argument
<code>ec</code> r</del><ins>R</ins>eturn <code>false</code> if an error
occurs.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li><i>Complexity:</i> At most one direct or indirect invocation of
<code>status(to)</code>.</li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.2 Create directory [filesystem.create_directory]</h4>
<pre class="function">virtual bool create_directory(const path& p, error_code& ec) noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.create_directory] paragraphs 1 to 4 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> Establishes the postcondition by attempting to create the
directory <code>p</code> resolves to<del>, as if by POSIX
<code>mkdir()</code> with a second argument of
<code>static_cast<int>(perms::all)</code></del>. Creation failure
because <code>p</code> resolves to an existing directory shall not be
treated as an error.</li>
<li><i>Postcondition:</i> <code>is_directory(p)</code>.</li>
<li><i>Returns:</i> <code>true</code> if a new directory was created,
otherwise <code>false</code>. <del>The signature with argument
<code>ec</code> r</del><ins>R</ins>eturns <code>false</code> if an error
occurs.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<pre class="function">virtual bool create_directory(const path& p, const path& existing_p,
error_code& ec) noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.create_directory] paragraphs 5 to 8 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> Establishes the postcondition by attempting to create the
directory <code>p</code> resolves to, with attributes copied from directory
<code>existing_p</code>. The set of attributes copied is operating system
dependent. Creation failure because <code>p</code> resolves to an existing
directory shall not be treated as an error. [<i>Note:</i> For POSIX based
operating systems the attributes are those copied by native API
<code>stat(existing_p.c_str(), &attributes_stat)</code> followed by
<code>mkdir(p.c_str(), attributes_stat.st_mode)</code>. For Windows based
operating systems the attributes are those copied by native API
<code>CreateDirectoryExW(existing_p.c_str(), p.c_str(), 0)</code>. —
<i>end note</i>]</li>
<li><i>Postcondition:</i> <code>is_directory(p)</code>.</li>
<li><i>Returns:</i> <code>true</code> if a new directory was created, otherwise
<code>false</code>. <del>The signature with argument <code>ec</code>
r</del><ins>R</ins>eturns false if an error occurs.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.3 Create directory symlink [filesystem.create_directory_symlink]
</h4>
<pre class="function">virtual void create_directory_symlink(
const path& to, const path& new_symlink, error_code& ec) noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.create_dir_symlk] paragraphs 1 to 5 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> Establishes the postcondition<del>, as if by POSIX
<code>symlink()</code></del>.</li>
<li><i>Postcondition:</i> <code>new_symlink</code> resolves to a symbolic
link file that contains an unspecified representation of <code>to</code>.
</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li><del>[<i>Note:</i> Some operating systems require symlink creation to
identify that the link is to a directory. Portable code should use
<code>create_directory_symlink()</code> to create directory symlinks rather
than <code>create_symlink()</code> — <i>end note</i>]</del></li>
<li><del>[<i>Note:</i> Some operating systems do not support symbolic links at
all or support them only for regular files. Some file systems (such as the
FAT file system) do not support symbolic links regardless of the operating
system. — <i>end note</i>]</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.4 Create hard link [filesystem.create_hard_link]</h4>
<pre class="function">virtual void create_hard_link(const path& to, const path& new_hard_link,
error_code& ec) noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.create_hard_lk] paragraphs 1 to 4 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> Establishes the postcondition<del>, as if by POSIX
<code>link()</code></del>.</li>
<li><i>Postcondition:</i>
<ul>
<li><code>exists(to) && exists(new_hard_link) &&
equivalent(to, new_hard_link)</code></li>
<li>The contents of the file or directory <code>to</code> resolves to are
unchanged.</li>
</ul></li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li><del>[<i>Note:</i> Some operating systems do not support hard links at all
or support them only for regular files. Some file systems (such as the FAT
file system) do not support hard links regardless of the operating system.
Some file systems limit the number of links per file. —
<i>end note</i>]</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.5 Create symlink [filesystem.create_symlink]</h4>
<pre class="function">virtual void create_symlink(const path& to, const path& new_symlink,
error_code& ec) noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.create_symlink] paragraphs 1 to 4 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> Establishes the postcondition<del>, as if by POSIX
<code>symlink()</code></del>.</li>
<li><i>Postcondition:</i> <code>new_symlink</code> resolves to a symbolic
link file that contains an unspecified representation of <code>to</code>.
</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li><del>[<i>Note:</i> Some operating systems do not support symbolic links at
all or support them only for regular files. Some file systems (such as the
FAT file system) do not support symbolic links regardless of the operating
system. — <i>end note</i>]</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.6 Current path [filesystem.current_path]</h4>
<pre class="function">virtual path current_path(error_code& ec) const = 0;
</pre>
</blockquote>
<p>Copy [fs.op.current_path] paragraphs 1 to 5 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Returns:</i> The absolute path of the current working directory<del>,
obtained as if by POSIX <code>getcwd()</code></del>. <del>The
signature with argument <code>ec</code> r</del><ins>R</ins>eturns
<code>path()</code> if an error occurs.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li><i>Remarks:</i> The current working directory is the directory,
associated with the process, that is used as the starting location in
pathname resolution for relative paths.</li>
<li><del>[<i>Note:</i> The current_path() name was chosen to emphasize that
the return is a path, not just a single directory name.</del></li>
<li><del>The current path as returned by many operating systems is a dangerous
global variable. It may be changed unexpectedly by a third-party or system
library functions, or by another thread. — <i>end note</i>]</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<pre class="function">virtual void current_path(const path& p, error_code& ec) noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.current_path] paragraphs 6 to 9 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> Establishes the postcondition<del>, as if by POSIX
<code>chdir()</code></del>.</li>
<li><i>Postcondition:</i> <code>equivalent(p, current_path())</code>.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li><del>[<i>Note:</i> The current path for many operating systems is a
dangerous global state. It may be changed unexpectedly by a third-party or
system library functions, or by another thread. — <i>end note</i>]
</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.7 Equivalent [filesystem.equivalent]</h4>
<pre class="function">virtual bool equivalent(const path& p1, const path& p2, error_code& ec) const noexcept = 0
</pre>
</blockquote>
<p>Copy [fs.op.equivalent] paragraphs 1 to 4 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> Determines <code>file_status s1</code> and <code>s2</code>,
as if by <code>status(p1)</code> and <code>status(p2)</code>, respectively.
</li>
<li><i>Returns:</i> <code>true</code>, if <code>s1 == s2</code> and
<code>p1</code> and <code>p2</code> resolve to the same file system entity,
else <code>false</code>. <del>The signature with argument <code>ec</code>
r</del><ins>R</ins>eturns <code>false</code> if an error occurs.</li>
<li>Two paths are considered to resolve to the same file system entity if
two candidate entities reside on the same device at the same location.
<del>This is determined as if by the values of the POSIX <code>stat</code>
structure, obtained as if by <code>stat()</code> for the two paths, having
equal <code>st_dev</code> values and equal <code>st_ino</code> values.</del>
</li>
<li><del><i>Throws:</i> <code>filesystem_error</code> if <code>(!exists(s2))
|| (is_other(s1) && is_other(s2))</code>, otherwise as specified in
Error reporting (27.5.6.5).</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.8 File size [filesystem.file_size]</h4>
<pre class="function">virtual uintmax_t file_size(const path& p, error_code& ec) const noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.file_size] paragraphs 1 to 2 here, with edits as specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Returns:</i> If <code>!exists(p) || !is_regular_file(p)</code> an error
is reported 27.5.6.5. Otherwise, the size in bytes of the file <code>p</code>
resolves to<del>, determined as if by the value of the POSIX
<code>stat</code> structure member <code>st_size</code> obtained as if by
POSIX <code>stat()</code></del>. <del>The signature with argument
<code>ec</code> r</del><ins>R</ins>eturns
<code>static_cast<uintmax_t>(-1)</code> if an error occurs.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.9 Hard link count [filesystem.hard_link_count]</h4>
<pre class="function">virtual uintmax_t hard_link_count(const path& p, error_code& ec) const noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.hard_lk_ct] paragraphs 1 to 2 here, with edits as specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Returns:</i> The number of hard links for <code>p</code>. <del>The
signature with argument <code>ec</code> r</del><ins>R</ins>eturns
<code>static_cast<uintmax_t>(-1)</code> if an error occurs.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.10 Last write time [filesystem.last_write_time]</h4>
<pre class="function">virtual file_time_type last_write_time(const path& p, error_code& ec) const noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.last_write_time] paragraphs 1 to 2 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Returns:</i> The time of last data modification of <code>p</code><del>,
determined as if by the value of the POSIX <code>stat</code> structure member
<code>st_mtime</code> obtained as if by POSIX <code>stat()</code></del>.
<del>The signature with argument <code>ec</code> r</del><ins>R</ins>eturns
<code>file_time_type::min()</code> if an error occurs.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<pre class="function">virtual void last_write_time(const path& p, file_time_type new_time,
error_code& ec) const noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.last_write_time] paragraphs 3 to 5 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> Sets the time of last modification of the file resolved
to by <code>p</code> to <code>new_time</code><del>, as if by POSIX
<code>futimens()</code></del>.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li><del>[<i>Note:</i> A postcondition of <code>last_write_time(p) ==
new_time</code> is not specified since it might not hold for file systems
with coarse time granularity. — <i>end note</i>]</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.11 Permissions [filesystem.permissions]</h4>
<pre class="function">virtual void permissions(const path& p, perms prms, error_code& ec) const noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.permissions] paragraphs 1 to 4 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Requires:</i> <code>!((prms & prms::add_perms) != perms::none<br>
&& (prms & perms::remove_perms) != perms::none)</code>.</li>
<li><i>Effects:</i> Applies the effective permissions bits from
<code>prms</code> to the file <code>p</code> resolves to<del>, as if by POSIX
<code>fchmodat()</code></del>. The effective permission bits are determined
as specified in Table 150.
<table>
<caption>Table 150 — Effects of permission bits</caption>
<tbody><tr>
<th>Bits present in <code>prms</code></th>
<th>Effective bits applied</th>
</tr>
<tr>
<td>Neither <code>add_perms</code> nor <code>remove_perms</code></td>
<td><code>prms && perms::mask</code></td>
</tr>
<tr>
<td><code>add_perms</code></td>
<td><code>status(p).permissions() | (prms & perms::mask)</code></td>
</tr>
<tr>
<td><code>remove_perms</code></td>
<td><code>status(p).permissions() & (prms & perms::mask)
</code></td></tr>
</tbody></table>
</li>
<li>[<i>Note:</i> Conceptually permissions are viewed as bits, but the actual
implementation may use some other mechanism. — <i>end note</i>]</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.12 Read symlink [filesystem.read_symlink]</h4>
<pre class="function">virtual path read_symlink(const path& p, error_code& ec) const noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.read_symlink] paragraphs 1 to 2 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Returns:</i> If <code>p</code> resolves to a symbolic link, a
<code>path</code> object containing the contents of that symbolic link.
<del>The signature with argument <code>ec</code> returns <code>path()</code>
if an error occurs.</del></li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del>
[<i>Note:</i> It is an error if <code>p</code> does not resolve to a
symbolic link. — <i>end note</i>]</li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.13 Remove [filesystem.remove]</h4>
<pre class="function">virtual bool remove(const path& p, error_code& ec) noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.remove] paragraphs 1 to 5 here, with edits as specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> If <code>exists(symlink_status(p,ec))</code>, it is
removed<del> as if by POSIX <code>remove()</code></del>.</li>
<li>[<i>Note:</i> A symbolic link is itself removed, rather that the file it
resolves to being removed. — <i>end note</i>]</li>
<li><i>Postcondition:</i> <code>!exists(symlink_status(p))</code>.</li>
<li><i>Returns:</i> <code>false</code> if <code>p</code> did not exist,
otherwise <code>true</code>. <del>The signature with argument <code>ec</code>
r</del><ins>R</ins>eturns <code>false</code> if an error occurs.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.14 Rename [filesystem.rename]</h4>
<pre class="function">virtual void rename(const path& old_p, const path& new_p, error_code& ec) noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.rename] paragraphs 1 to 3 here, with edits as specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> Renames <code>old_p</code> to <code>new_p</code><del>,
as if by POSIX <code>rename()</code></del>.</li>
<li>[<i>Note:</i> If <code>old_p</code> and <code>new_p</code> resolve to
the same existing file, no action is taken. Otherwise, if <code>new_p</code>
resolves to an existing non-directory file, it is removed, while if
<code>new_p</code> resolves to an existing directory, it is removed if
empty on POSIX compliant operating systems but is an error on some other
operating systems. A symbolic link is itself renamed, rather than the file
it resolves to being renamed. — <i>end note</i>]</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.15 Resize file [filesystem.resize_file]</h4>
<pre class="function">virtual void resize_file(const path& p, uintmax_t new_size, error_code& ec) noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.resize_file] paragraphs 1 to 3 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Postcondition:</i> <code>file_size() == new_size</code>.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li><del><i>Remarks:</i> Achieves its postconditions as if by POSIX
<code>truncate()</code>.</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.16 Space [filesystem.space]</h4>
<pre class="function">virtual space_info space(const path& p, error_code& ec) const noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.space] paragraphs 1 to 3 here, with edits as specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Returns:</i> An object of type <code>space_info</code>. <del>The value
of the <code>space_info</code> object is determined as if by using POSIX
<code>statvfs</code> to obtain a POSIX <code>struct statvfs</code>, and then
multiplying its <code>f_blocks</code>, <code>f_bfree</code>, and
<code>f_bavail</code> members by its <code>f_frsize</code> member, and
assigning the results to the <code>capacity</code>, <code>free</code>, and
<code>available</code> members respectively.</del> <ins>The object's
members will be set as follows:
<ul>
<li><code>capacity</code> will be set to the total storage capacity of
the storage volume containing <code>p</code>.</li>
<li><code>free</code> will be set to the total amount of free space on
the storage volume containing <code>p</code>.</li>
<li><code>available</code> will be set to the amount of free space that
is available to hold user data on the storage volume containing
<code>p</code> [<i>Note:</i> This can be less than <code>free</code>
because it excludes storage reserved for file system internals. —
<i>end note</i>].</li>
</ul></ins>
Any members for which the value cannot be determined shall be set to
<code>static_cast<uintmax_t>(-1)</code>. <del>For the signature with
argument <code>ec</code>, a</del><ins>A</ins>ll members are set to
<code>static_cast<uintmax_t>(-1)</code> if an error occurs.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li><del><i>Remarks:</i> The value of member <code>space_info::available</code>
is operating system dependent. [<i>Note:</i> <code>available</code> may
be less than <code>free</code>. — <i>end note</i>]</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.17 Status [filesystem.status]</h4>
<pre class="function">virtual file_status status(const path& p, error_code& ec) const noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.status] paragraphs 4 to 9 here, with edits as specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> If possible, determines the attributes of the file
<code>p</code> resolves to<del>, as if by POSIX <code>stat()</code></del>.
If, during attribute determination, the underlying file system API reports
an error, sets <code>ec</code> to indicate the specific error reported.
Otherwise, <code>ec.clear()</code>.</li>
<li>[<i>Note:</i> This allows users to inspect the specifics of underlying API
errors even when the value returned by <code>status()</code> is not
<code>file_status(file_type::none)</code>. — <i>end note</i>]</li>
<li><i>Returns:</i> If <code>ec != error_code()</code>:
<ul>
<li>If the specific error indicates that <code>p</code> cannot be resolved
because some element of the path does not exist, return
<code>file_status(file_type::not_found)</code>.</li>
<li>Otherwise, if the specific error indicates that <code>p</code> can be
resolved but the attributes cannot be determined, return
<code>file_status(file_type::unknown)</code>.</li>
<li>Otherwise, return <code>file_status(file_type::none)</code>.</li>
</ul>
<p>[<i>Note:</i> These semantics distinguish between <code>p</code> being
known not to exist, <code>p</code> existing but not being able to
determine its attributes, and there being an error that prevents even
knowing if <code>p</code> exists. These distinctions are important to some
use cases. — <i>end note</i>]</p>
<p>Otherwise,
</p><ul>
<li>If the attributes indicate a regular file, <del>as if by POSIX
<code>S_ISREG</code>,</del> return
<code>file_status(file_type::regular)</code>. [<i>Note:</i>
<code>file_type::regular</code> implies appropriate
<code><fstream></code> operations would succeed, assuming no
hardware, permission, access, or file system race errors. Lack of
<code>file_type::regular</code> does not necessarily imply
<code><fstream></code> operations would fail on a directory. —
<i>end note</i>]</li>
<li>Otherwise, if the attributes indicate a directory, <del>as if by POSIX
<code>S_ISDIR</code>,</del> return
<code>file_status(file_type::directory)</code>. [<i>Note:</i>
<code>file_type::directory</code> implies
<code>directory_iterator(p)</code> would succeed. — <i>end note</i>]
</li>
<li>Otherwise, if the attributes indicate a block special file, <del>as if
by POSIX <code>S_ISBLK</code>,</del> return
<code>file_status(file_type::block)</code>.</li>
<li>Otherwise, if the attributes indicate a character special file, <del>as
if by POSIX <code>S_ISCHR</code>,</del> return
<code>file_status(file_type::character)</code>.</li>
<li>Otherwise, if the attributes indicate a fifo or pipe file, <del>as if by
POSIX <code>S_ISFIFO</code>,</del> return
<code>file_status(file_type::fifo)</code>.</li>
<li>Otherwise, if the attributes indicate a socket, <del>as if by POSIX
<code>S_ISSOCK</code>,</del> return
<code>file_status(file_type::socket)</code>.</li>
<li>Otherwise, return <code>file_status(file_type::unknown)</code>.
</li></ul><p></p></li>
<li><i>Remarks:</i> If a symbolic link is encountered during pathname
resolution, pathname resolution continues using the contents of the
symbolic link.</li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.18 Symlink status [filesystem.symlink_status]</h4>
<pre class="function">virtual file_status symlink_status(const path& p, error_code& ec) const noexcept = 0;
</pre>
</blockquote>
<p>Copy [fs.op.symlink_status] paragraphs 1 to 4 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> Same as status(), above, except that the attributes of
<code>p</code> are <del>determined as if by POSIX <code>lstat()</code></del>
<ins>always determined, even if <code>p</code> names a symbolic link</ins>.
</li>
<li><i>Returns:</i> Same as status(), above, except that if the attributes
indicate a symbolic link, <del>as if by POSIX <code>S_ISLNK</code>,</del>
return <code>file_status(file_type::symlink)</code>. <del>The signature with
argument <code>ec</code> r</del><ins>R</ins>eturns
<code>file_status(file_type::none)</code> if an error occurs.</li>
<li><i>Remarks:</i>Pathname resolution terminates if <code>p</code> names a
symbolic link.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.19 System complete [filesystem.system_complete]</h4>
<pre class="function">virtual path system_complete(const path& p error_code& ec) const = 0;
</pre>
</blockquote>
<p>Copy [fs.op.system_complete] paragraphs 1 to 6 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> Composes an absolute path from <code>p</code>, using the
same rules used <del>by the operating system</del> to resolve a path
passed <del>as the filename argument to standard library open functions</del>
<ins>to other functions in this section</ins>.</li>
<li><i>Returns:</i> The composed path. <del>The signature with argument
<code>ec</code> r</del><ins>R</ins>eturns <code>path()</code> if an error
occurs.</li>
<li><i>Postcondition:</i> For the returned path, <code>rp,
rp.is_absolute()</code> is true.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li>[<i>Example:</i> For POSIX based operating systems,
<code>system_complete(p)</code> has the same semantics as
<code>absolute(p, current_path())</code>.</li>
<li>For Windows based operating systems, <code>system_complete(p)</code> has
the same semantics as <code>absolute(p, current_path())</code> if
<code>p.is_absolute() || !p.has_root_name()</code> or <code>p</code> and
<code>base</code> have the same <code>root_name()</code>. Otherwise it acts
like <code>absolute(p, cwd)</code> is the current directory for the
<code>p.root_name()</code> drive. This will be the current directory for
that drive the last time it was set, and thus may be residue left over from
a prior program run by the command processor. Although these semantics are
useful, they may be surprising. — <i>end example</i>]</li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.20 Temp directory path [filesystem.temp_directory_path]</h4>
<pre class="function">virtual path temp_directory_path(error_code& ec) const = 0;
</pre>
</blockquote>
<p>Copy [fs.op.temp_dir_path] paragraphs 1 to 4 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Returns:</i> An unspecifed directory path suitable for temporary files.
An error shall be reported if <code>!exists(p) || !is_directory(p)</code>,
where <code>p</code> is the path to be returned. <del>The signature with
argument <code>ec</code> r</del><ins>R</ins>eturns <code>path()</code> if
an error occurs.</li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li>[<i>Example:</i> For POSIX based operating systems, an implementation
might return the path supplied by the first environment variable found in
the list TMPDIR, TMP, TEMP, TEMPDIR, or if none of these are found,
<code>"/tmp"</code>.</li>
<li>For Windows based operating systems, an implementation might return the
path reported by the Windows <code>GetTempPath</code> API function. —
<i>end example</i>]</li>
</ul>
</blockquote>
<blockquote class="stdins">
<h4>27.10.?.1.21 Directory traverser [filesystem.directory_traverser]</h4>
<pre class="function">virtual unique_ptr<directory_traverser> directory_traverser(
const path& p, directory_options options, error_code& ec) const = 0;
</pre>
</blockquote>
<p>Copy [directory_iterator.members] paragraphs 2 to 4 here, with edits as
specified:</p>
<blockquote class="std">
<ul class="function">
<li><i>Effects:</i> For the directory that <code>p</code> resolves to,
<del>constructs an iterator</del><ins>allocates a
<code>directory_traverser</code> </ins> for the first element in a sequence
of <code>directory_entry</code> elements representing the files in the
directory, if any; otherwise the <del>end iterator</del><ins>past-the-end
value</ins>. However, if
<blockquote>
<code>(options & directory_options::skip_permissions_denied) !=
directory_options::none</code>
</blockquote>
and construction encounters an error indicating that permission to access
<code>p</code> is denied, constructs the <del>end iterator</del>
<ins>past-the-end value</ins> and does not report an error.</li>
<li><ins><i>Returns:</i> a pointer to the allocated
<code>directory_traverser</code>.</ins></li>
<li><del><i>Throws:</i> As specified in Error reporting (27.5.6.5).</del></li>
<li><del>[<i>Note:</i> To iterate over the current directory, use
<code>directory_iterator(".")</code> rather than
<code>directory_iterator("")</code>. — <i>end note</i>]</del></li>
</ul>
</blockquote>
<blockquote class="stdins">
<h2>27.10.? Class <code>default_filesystem_impl</code>
[class.default_filesystem_impl]</h2>
<p>Class <code>default_filesystem_impl</code> is for exposition only. An
implementation is permitted to provide equivalent functionality without
providing a class with this name. This class provides a default implementation
of the <code>filesystem</code> interface, which is implemented by delegating
to the underlying operating system.</p>
<p>Descriptions are provided only where this class differs from the
base class <code>filesystem</code>.</p>
<pre>class default_filesystem_impl : public filesystem { <i>// exposition only</i>
public:
virtual bool copy_file(const path& from, const path& to,
copy_options options, error_code& ec) noexcept;
virtual bool create_directory(const path& p, error_code& ec) noexcept;
virtual bool create_directory(const path& p, const path& existing_p,
error_code& ec) noexcept;
virtual void create_directory_symlink(
const path& to, const path& new_symlink, error_code& ec) noexcept;
virtual void create_hard_link(const path& to, const path& new_hard_link,
error_code& ec) noexcept;
virtual void create_symlink(const path& to, const path& new_symlink,
error_code& ec) noexcept;
virtual path current_path(error_code& ec);
virtual void current_path(const path& p, error_code& ec) noexcept;
virtual bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
virtual uintmax_t file_size(const path& p, error_code& ec) noexcept;
virtual uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
virtual file_time_type last_write_time(const path& p, error_code& ec) noexcept;
virtual void last_write_time(const path& p, file_time_type new_time,
error_code& ec) noexcept;
virtual void permissions(const path& p, perms prms, error_code& ec) noexcept;
virtual path read_symlink(const path& p, error_code& ec);
virtual bool remove(const path& p, error_code& ec) noexcept;
virtual void rename(const path& old_p, const path& new_p, erorr_code& ec) noexcept;
virtual void resize_file(const path& p, uintmax_t new_size, error_code& ec) noexcept;
virtual space_info space(const path& p, error_code& ec) noexcept;
virtual file_status status(const path& p, error_code& ec) noexcept;
virtual file_status symlink_status(const path& p, error_code& ec) noexcept;
virtual path system_complete(const path& p, error_code& ec);
virtual path temp_directory_path(error_code& ec);
virtual unique_ptr<directory_traverser> directory_traverser(
const path& p, directory_options options, error_code& ec);