Skip to content

Commit 8a481aa

Browse files
author
Nathan Memmott
committed
Define File System concept
Pulls out some implementation-defined concepts into a file system concept. This is so that the file system concept can be extended further in the future.
1 parent b38f13b commit 8a481aa

File tree

1 file changed

+127
-87
lines changed

1 file changed

+127
-87
lines changed

index.bs

Lines changed: 127 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,60 @@ different storage mechanism with a different API for such files. The entry point
6060

6161
## Concepts ## {#concepts}
6262

63+
### File System ### {#concept-file-system}
64+
65+
A <dfn export>file system</dfn> is an [=implementation-defined=]
66+
[=storage endpoint=] that maintains a mapping of [=file system path=]s to
67+
[=file system entry|file system entries=].
68+
69+
Each [=/file system=] has an associated <dfn for="file system" export>root</dfn>,
70+
an opaque [=string=] whose value is [=implementation-defined=].
71+
72+
A <dfn export>file system path</dfn> is a [=/list=] of one or more [=strings=].
73+
This may be a virtual path that is mapped to real location on disk or in memory,
74+
may correspond directly to a path on the local file system, or may not
75+
correspond to any file on disk at all. The actual physical location of the
76+
corresponding [=/file system entry=] is [=implementation-defined=].
77+
78+
A [=/file system path=] |a| is <dfn for="file system path">the same path as</dfn>
79+
a [=/file system path=] |b| if
80+
|a|'s [=list/size=] is the same as |b|'s [=list/size=] and
81+
[=list/for each=] |index| of |a|'s [=list/indices=]
82+
|a|.\[[|index|]] is |b|.\[[|index|]].
83+
84+
<div algorithm>
85+
Each [=/file system=] has an associated
86+
<dfn for="file system">locate an entry</dfn>
87+
algorithm, which takes [=/file system path=] |path| and runs an
88+
[=implementation-defined=] series of steps returning a [=file system entry=] or null.
89+
A non-null return value |entry| must adhere to these constraints:
90+
91+
- [=file system/Getting the path=] with |entry| returns |path|,
92+
provided no intermediate file system operations were run.
93+
- |entry|'s [=file system entry/name=] is the last [=list/item=] of |path|.
94+
95+
</div>
96+
97+
<div algorithm>
98+
Each [=/file system=] has an associated
99+
<dfn for="file system">get the path</dfn>
100+
algorithm, which takes [=/file system entry=] |entry| and runs an
101+
[=implementation-defined=] series of steps returning a [=file system path=]. The
102+
return value |path| must adhere to these constraints:
103+
104+
- [=file system/Locating an entry=] with |path| returns |entry|,
105+
provided no intermediate file system operations were run.
106+
- |entry|'s [=file system entry/name=] is the last [=list/item=] of |path|.
107+
108+
</div>
109+
110+
### File System Entry ### {#concept-file-system-entry}
111+
63112
A <dfn export id="entry">file system entry</dfn> is either a [=file entry=] or a [=directory entry=].
64113

114+
Each [=/file system entry=] has an associated
115+
<dfn for="file system entry">file system</dfn> (a [=/file system=]).
116+
65117
Each [=/file system entry=] has an associated
66118
<dfn for="file system entry" id=entry-query-access>query access</dfn>
67119
algorithm, which takes "`read`" or "`readwrite`" <var ignore>mode</var> and
@@ -200,15 +252,50 @@ A [=/file system entry=] |a| is <dfn for="file system entry">the same entry as</
200252
a [=/file system entry=] |b| if |a| is equal to |b|, or
201253
if |a| and |b| are backed by the same file or directory on the local file system.
202254

255+
### File System Locator ### {#concept-file-system-locator}
256+
257+
A <dfn export>file system locator</dfn> represents a potential location of a
258+
[=/file system entry=]. A [=/file system locator=] is either a [=file locator=]
259+
or a [=directory locator=].
260+
261+
Each [=/file system locator=] has an associated <dfn export for="file system locator" id=locator-path>path</dfn> (a [=/file system path=]),
262+
a <dfn export for="file system locator" id=locator-kind>kind</dfn> (a {{FileSystemHandleKind}}), and
263+
a <dfn export for="file system locator" id=locator-root>file system</dfn> (a [=/file system=]).
264+
265+
Issue(109): Consider giving each locator a [=storage bucket=].
266+
267+
A <dfn export>file locator</dfn> is a [=/file system locator=] whose
268+
[=file system locator/kind=] is "{{FileSystemHandleKind/file}}".
269+
A <dfn export>directory locator</dfn> is a [=/file system locator=] whose
270+
[=file system locator/kind=] is "{{FileSystemHandleKind/directory}}".
271+
272+
<p class=example id=example-locator>For a [=/file system locator=] |locator|
273+
whichs [=locate an entry|locates to=] a [=file entry=] |entry| that conceptually
274+
exists at the path `data/drafts/example.txt` relative to the root directory of
275+
a [=/bucket file system=],
276+
|locator|'s [=file system locator/kind=] has to be "{{FileSystemHandleKind/file}}",
277+
|locator|'s [=file system locator/path=] has to be « "`data`", "`drafts`", "`example.txt`" », and
278+
|locator|'s [=file system locator/file system=] has to be [=/bucket file system=].
279+
280+
A [=/file system locator=] |a| is <dfn for="file system locator">the same locator as</dfn>
281+
a [=/file system locator=] |b| if
282+
|a|'s [=file system locator/kind=] is |b|'s [=file system locator/kind=],
283+
|a|'s [=file system locator/file system=] is |b|'s [=file system locator/file system=], and
284+
|a|'s [=file system locator/path=] is [=the same path as=] |b|'s [=file system locator/path=].
285+
286+
<p class=example id=example-path>Let |path| be the [=/list=]
287+
« "`data`", "`drafts`", "`example.txt`" ».
288+
There is no expectation that a file named `example.txt` exists anywhere on disk.
289+
203290
<div algorithm>
204291

205292
To <dfn for="file system locator" id=locator-resolve>resolve</dfn> a
206293
[=/file system locator=] |child| relative to a [=directory locator=] |root|:
207294

208295
1. Let |result| be [=a new promise=].
209296
1. [=Enqueue the following steps=] to the [=file system queue=]:
210-
1. If |child|'s [=FileSystemHandle/locator=]'s [=file system locator/root=]
211-
is not |root|'s [=FileSystemHandle/locator=]'s [=file system locator/root=],
297+
1. If |child|'s [=FileSystemHandle/locator=]'s [=file system locator/file system=]
298+
is not |root|'s [=FileSystemHandle/locator=]'s [=file system locator/file system=],
212299
[=/resolve=] |result| with null, and abort these steps.
213300

214301
1. Let |childPath| be |child|'s [=FileSystemHandle/locator=]'s [=file system locator/path=].
@@ -234,85 +321,36 @@ To <dfn for="file system locator" id=locator-resolve>resolve</dfn> a
234321

235322
</div>
236323

237-
A <dfn export>file system locator</dfn> represents a potential location of a
238-
[=/file system entry=]. A [=/file system locator=] is either a [=file locator=]
239-
or a [=directory locator=].
240-
241-
Each [=/file system locator=] has an associated <dfn export for="file system locator" id=locator-path>path</dfn> (a [=/file system path=]),
242-
a <dfn export for="file system locator" id=locator-kind>kind</dfn> (a {{FileSystemHandleKind}}), and
243-
a <dfn export for="file system locator" id=locator-root>root</dfn> (a [=file system root=]).
244-
245-
Issue(109): Consider giving each locator a [=storage bucket=].
246-
247-
A <dfn export>file locator</dfn> is a [=/file system locator=] whose
248-
[=file system locator/kind=] is "{{FileSystemHandleKind/file}}".
249-
A <dfn export>directory locator</dfn> is a [=/file system locator=] whose
250-
[=file system locator/kind=] is "{{FileSystemHandleKind/directory}}".
251-
252-
A <dfn export>file system root</dfn> is an opaque [=string=] whose value is
253-
[=implementation-defined=].
254-
255-
<p class=example id=example-locator>For a [=/file system locator=] |locator|
256-
whichs [=locate an entry|locates to=] a [=file entry=] |entry| that conceptually
257-
exists at the path `data/drafts/example.txt` relative to the root directory of
258-
a [=/bucket file system=],
259-
|locator|'s [=file system locator/kind=] has to be "{{FileSystemHandleKind/file}}",
260-
|locator|'s [=file system locator/path=] has to be « "`data`", "`drafts`", "`example.txt`" », and
261-
|locator|'s [=file system locator/root=] might include relevant identifying
262-
information such as the [=storage bucket=] and the disk drive.
263-
264-
A [=/file system locator=] |a| is <dfn for="file system locator">the same locator as</dfn>
265-
a [=/file system locator=] |b| if
266-
|a|'s [=file system locator/kind=] is |b|'s [=file system locator/kind=],
267-
|a|'s [=file system locator/root=] is |b|'s [=file system locator/root=], and
268-
|a|'s [=file system locator/path=] is [=the same path as=] |b|'s [=file system locator/path=].
269-
270324
<div algorithm>
271325
The <dfn export data-lt="locating an entry">locate an entry</dfn> algorithm given a
272-
[=/file system locator=] |locator| runs an [=implementation-defined=] series of steps adhering to
273-
these constraints:
326+
[=/file system locator=] |locator| runs the following steps:
274327

275-
- If |locator| is a [=file locator=], they return a [=file entry=] or null.
276-
- If |locator| is a [=directory locator=], they return a [=directory entry=] or null.
277-
- If these steps return a non-null |entry|, then:
278-
- [=Getting the locator=] with |entry| returns |locator|,
279-
provided no intermediate file system operations were run.
280-
- |entry|'s [=file system entry/name=] is the last [=list/item=] of |locator|'s
281-
[=file system locator/path=].
328+
1. Let |file system| be |locator|'s [=file system locator/file system=].
329+
1. Let |path| be |locator|'s [=file system locator/path=].
330+
1. Let |entry| be the result of running |file system|'s
331+
[=file system/locate an entry=] given |path|.
332+
1. If |entry| is null, return null.
333+
1. If |locator| is a [=file locator=], [=Assert=]: |entry| is a [=file entry=].
334+
1. If |locator| is a [=directory locator=], [=Assert=]: |entry| is a [=directory entry=].
335+
1. Return |entry|.
282336

283337
</div>
284338

285339
<div algorithm>
286-
The <dfn export data-lt="getting the locator">get the locator</dfn> algorithm given
287-
[=/file system entry=] |entry| runs an [=implementation-defined=] series of steps adhering to these
288-
constraints:
289-
290-
- If |entry| is a [=file entry=], they return a [=file locator=].
291-
- If |entry| is a [=directory entry=], they return a [=directory locator=].
292-
- If these steps return |locator|, then:
293-
- [=Locating an entry=] with |locator| returns |entry|,
294-
provided no intermediate file system operations were run.
295-
- |entry|'s [=file system entry/name=] is the last [=list/item=] of |locator|'s
296-
[=file system locator/path=].
340+
The <dfn export data-lt="getting the locator">get the locator</dfn> algorithm given a
341+
[=/file system entry=] |entry| runs the following steps:
342+
343+
1. Let |file system| be |entry|'s [=file system entry/file system=].
344+
1. Let |path| be the result of running |file system|'s
345+
[=file system/get the path=] given |entry|.
346+
1. Let |locator| be a [=file system locator=] whose [=file system locator/path=]
347+
is |path| and whose [=file system locator/file system=] is |file system|.
348+
1. If |entry| is a [=file entry=], set |locator|'s [=file system locator/kind=] to "file".
349+
1. If |entry| is a [=directory entry=], set |locator|'s [=file system locator/kind=] to "directory".
350+
1. Return |entry|.
297351

298352
</div>
299353

300-
A <dfn export>file system path</dfn> is a [=/list=] of one or more [=strings=].
301-
This may be a virtual path that is mapped to real location on disk or in memory,
302-
may correspond directly to a path on the local file system, or may not
303-
correspond to any file on disk at all. The actual physical location of the
304-
corresponding [=/file system entry=] is [=implementation-defined=].
305-
306-
<p class=example id=example-path>Let |path| be the [=/list=]
307-
« "`data`", "`drafts`", "`example.txt`" ».
308-
There is no expectation that a file named `example.txt` exists anywhere on disk.
309-
310-
A [=/file system path=] |a| is <dfn for="file system path">the same path as</dfn>
311-
a [=/file system path=] |b| if
312-
|a|'s [=list/size=] is the same as |b|'s [=list/size=] and
313-
[=list/for each=] |index| of |a|'s [=list/indices=]
314-
|a|.\[[|index|]] is |b|.\[[|index|]].
315-
316354
<p class=warning> The contents of a [=/file system locator=], including its
317355
[=file system locator/path=], are not expected to be shared in their entirety
318356
with the website process. The [=/file system path=] might contain components
@@ -443,12 +481,12 @@ given a [=directory locator=] |parentLocator| and a string |name| in a [=/Realm=
443481

444482
1. Let |handle| be a [=new=] {{FileSystemFileHandle}} in |realm|.
445483
1. Let |childType| be "{{FileSystemHandleKind/file}}".
446-
1. Let |childRoot| be a copy of |parentLocator|'s [=file system locator/root=].
484+
1. Let |childFileSystem| be the |parentLocator|'s [=file system locator/file system=]
447485
1. Let |childPath| be the result of [=list/clone|cloning=] |parentLocator|'s
448486
[=file system locator/path=] and [=list/append|appending=] |name|.
449487
1. Set |handle|'s [=FileSystemHandle/locator=] to a [=/file system locator=] whose
450488
[=file system locator/kind=] is |childType|,
451-
[=file system locator/root=] is |childRoot|, and
489+
[=file system locator/file system=] is |childFileSystem|, and
452490
[=file system locator/path=] is |childPath|.
453491
1. Return |handle|.
454492

@@ -457,13 +495,13 @@ given a [=directory locator=] |parentLocator| and a string |name| in a [=/Realm=
457495
<div algorithm>
458496
To
459497
<dfn export data-lt="creating a new FileSystemFileHandle">create a new `FileSystemFileHandle`</dfn>
460-
given a [=/file system root=] |root| and a [=/file system path=] |path|
498+
given a [=/file system=] |file system| and a [=/file system path=] |path|
461499
in a [=/Realm=] |realm|:
462500

463501
1. Let |handle| be a [=new=] {{FileSystemFileHandle}} in |realm|.
464502
1. Set |handle|'s [=FileSystemHandle/locator=] to a [=/file system locator=] whose
465503
[=file system locator/kind=] is "{{FileSystemHandleKind/file}}",
466-
[=file system locator/root=] is |root|, and
504+
[=file system locator/file system=] is |file system|, and
467505
[=file system locator/path=] is |path|.
468506
1. Return |handle|.
469507

@@ -698,12 +736,12 @@ given a [=directory locator=] |parentLocator| and a string |name| in a [=/Realm=
698736

699737
1. Let |handle| be a [=new=] {{FileSystemDirectoryHandle}} in |realm|.
700738
1. Let |childType| be "{{FileSystemHandleKind/directory}}".
701-
1. Let |childRoot| be a copy of |parentLocator|'s [=file system locator/root=].
739+
1. Let |childFileSystem| be the |parentLocator|'s [=file system locator/file system=].
702740
1. Let |childPath| be the result of [=list/clone|cloning=] |parentLocator|'s
703741
[=file system locator/path=] and [=list/append|appending=] |name|.
704742
1. Set |handle|'s [=FileSystemHandle/locator=] to a [=/file system locator=] whose
705743
[=file system locator/kind=] is |childType|,
706-
[=file system locator/root=] is |childRoot|, and
744+
[=file system locator/file system=] is |childFileSystem|, and
707745
[=file system locator/path=] is |childPath|.
708746
1. Return |handle|.
709747

@@ -712,13 +750,13 @@ given a [=directory locator=] |parentLocator| and a string |name| in a [=/Realm=
712750
<div algorithm>
713751
To
714752
<dfn export data-lt="creating a new FileSystemDirectoryHandle">create a new `FileSystemDirectoryHandle`</dfn>
715-
given a [=/file system root=] |root| and a [=/file system path=] |path|
753+
given a [=/file system=] |file system| and a [=/file system path=] |path|
716754
in a [=/Realm=] |realm|:
717755

718756
1. Let |handle| be a [=new=] {{FileSystemDirectoryHandle}} in |realm|.
719757
1. Set |handle|'s [=FileSystemHandle/locator=] to a [=/file system locator=] whose
720758
[=file system locator/kind=] is "{{FileSystemHandleKind/directory}}",
721-
[=file system locator/root=] is |root|, and
759+
[=file system locator/file system=] is |file system|, and
722760
[=file system locator/path=] is |path|.
723761
1. Return |handle|.
724762

@@ -1675,12 +1713,17 @@ guarantee.
16751713

16761714
# Accessing the Bucket File System # {#sandboxed-filesystem}
16771715

1678-
The <dfn export id=origin-private-file-system>bucket file system</dfn> is a
1679-
[=storage endpoint=] whose
1680-
<a spec=storage for="storage endpoint">identifier</a> is `"fileSystem"`,
1716+
The <dfn export id=origin-private-file-system>bucket file system</dfn>
1717+
is a [=/file system=] implementation
1718+
whose [=file system/root=] is an [=implementation-defined=] opaque [=string=]
1719+
and whose [=storage endpoint=]'s
1720+
<a spec=storage for="storage endpoint">identifier</a> of `"fileSystem"`,
16811721
<a spec=storage for="storage endpoint">types</a> are `« "local" »`,
16821722
and <a spec=storage for="storage endpoint">quota</a> is null.
16831723

1724+
Note: [=/bucket file system=]'s [=file system/root=] might include relevant
1725+
identifying information such as the [=storage bucket=].
1726+
16841727
Issue: Storage endpoints should be defined in [[storage]] itself, rather
16851728
than being defined here. So merge this into the table there.
16861729

@@ -1721,13 +1764,10 @@ The <dfn method for=StorageManager>getDirectory()</dfn> method steps are:
17211764
1. Set |dir|'s [=directory entry/children=] to an empty [=/set=].
17221765
1. Set |map|["root"] to |dir|.
17231766

1724-
1. Let |root| be an [=implementation-defined=] opaque [=string=].
1767+
1. Let |file system| be [=/bucket file system=]'s [=/ile system/root=].
17251768
1. Let |path| be « the empty string ».
17261769
1. Let |handle| be the result of <a>creating a new `FileSystemDirectoryHandle`</a>.
1727-
given |root| and |path| in the [=current realm=].
1728-
1729-
Note: |root| might include relevant identifying information such as the
1730-
[=storage bucket=].
1770+
given |file system| and |path| in the [=current realm=].
17311771

17321772
1. Assert: [=locating an entry=] given |handle|'s [=FileSystemHandle/locator=]
17331773
returns a [=directory entry=] that is [=the same entry as=] |map|["root"].

0 commit comments

Comments
 (0)