Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: introduce an abstract file system interface into std #18324

Closed
RossComputerGuy opened this issue Dec 20, 2023 · 6 comments
Closed

Proposal: introduce an abstract file system interface into std #18324

RossComputerGuy opened this issue Dec 20, 2023 · 6 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@RossComputerGuy
Copy link
Contributor

RossComputerGuy commented Dec 20, 2023

The problem: people may want to use libraries which could connect to things like Gvfs. The issue is that overriding stuff in root module is necessary to perform this.

The solution:

  • Refactor std.fs to include generic things such a path (similar to std.mem but file system stuff)
  • Introduce the abstract interface into std.vfs
  • Add std.fs.local() to the OS implemented file system interface

This will introduce a lot of incompatibilities but would make it possible to use other file system libraries with libraries which expect Zig's std.fs.

VFS implementations:

@Vexu Vexu added standard library This issue involves writing Zig code for the standard library. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. labels Dec 20, 2023
@Vexu Vexu added this to the 0.13.0 milestone Dec 20, 2023
@matu3ba
Copy link
Contributor

matu3ba commented Dec 21, 2023

to include generic things such a path (similar to std.mem but file system stuff)

  1. Can you provide specific use cases for the compiler/package manager?
  2. Can you explain the specific use case you want to refactor std.fs for? It would be nice to have some concrete use case you would propose to estimate feasibility + sketch of list of things needed to be changed.

This will introduce a lot of incompatibilities but would make it possible to use other file system libraries with libraries which expect Zig's std.fs.

  1. Do you maybe mean breaking changes here or what current supported use cases would not be usable and not be fixable anymore?

Personally my biggest concern would be, if and how file system semantics can and can not be cleanly mapped and how to make these things explicit to the user (say how to make absence of flush needed to write a file an error to make things interchangeably usable).
Virtualization can hide lots of bugs in broken code, which can also be the case for allocation related things in a virtual machine and it would be good to have some best practice (for third parties).

  1. What is your position on this or what could/should libstd do with regard to this?

@notcancername
Copy link
Contributor

Can you provide specific use cases for the compiler/package manager?

Unpacking archives using something like the familiar IterableDir interface is a use case for the package manager. Such an interface would also be useful for accessing file systems over a network (FUSE file systems are already doing this: sshfs, curlftpfs).

Virtualization can hide lots of bugs in broken code, which can also be the case for allocation related things in a virtual machine and it would be good to have some best practice (for third parties).

Could you elaborate on this? I don't understand what you mean.

I share your semantics concern, the only solution I can think of is to not guarantee precise semantics of operations.

std.fs.path already appears well-equipped to handle such an interface, disregarding functions that call out to std.os and the whole path separator stuffs. Maybe it should become std.path eventually.

@Khitiara
Copy link

an abstract file system interface would also be useful in the context of certain kinds of gamedev resource loading, especially when space-constrained, especially if it could allow nesting/mounting, as that permits even nested archives etc in the asset file tree as needed by the game/application

@matu3ba
Copy link
Contributor

matu3ba commented Jan 15, 2024

Could you elaborate on this? I don't understand what you mean.

Jamie has an excellent talk on the differences in the context of databases, which has some simple performance examples:

Faster means, that you can get away without or potentially erroneous synchronization in the in-memory file system (msync & others), but not in the hardware-based file system (fsync & others).
The difference is usually only observable, if you access a file system from different processes or close and open a file, because the Kernel with file system also tries to call flush to disk as few as possible.

@Cloudef
Copy link
Contributor

Cloudef commented Feb 15, 2024

This would be great for tests as well that rely on platform specific search paths and what not, to validate that the search path logic works.

@arkadiuszwojcik
Copy link

arkadiuszwojcik commented Dec 30, 2024

@matu3ba one use case I would be intrested in would be custom file system for webserver hosted on embedded device. I would like to provide custom filesystem based on LittleFS with files stored in board flash memory.

I think this relates to: #6600

Some inspirations:
RT-Thread DFS
Zephyr FS

@andrewrk andrewrk closed this as not planned Won't fix, can't repro, duplicate, stale Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

8 participants