0Pricing
WebAssembly (WASM) for High Performance Apps · Ders

WASI Dosya Sistemiyle Çalışma

WASI'ın önceden açılmış dizinler ve yetenek tabanlı dosya erişimi aracılığıyla ana bilgisayar dosya sistemini korumalı bir modüle nasıl sunduğunu öğrenin.

WASI Dosya Sistemiyle Çalışma, CoddyKit'te ücretsiz bir WebAssembly (WASM) for High Performance Apps dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, WebAssembly (WASM) for High Performance Apps öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. WebAssembly (WASM) for High Performance Apps kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Why Files Need Special Handling

A WASM module has no ambient authority — it cannot open any file by default. WASI grants file access only through preopened directories handed to the module at startup.

  • No path traversal outside what was granted
  • Access is capability-based, not permission-based

Preopened Directories

When a runtime launches a module it can map a host folder to a guest path. The module receives a file descriptor for each mapping.

Example with wasmtime: wasmtime --dir=. app.wasm grants the current directory.

wasmtime run --dir=./data app.wasm

Reading a File from WASI

In a WASI language SDK the standard library file APIs are wired to WASI calls. In C, fopen works only for preopened paths.

#include <stdio.h>
int main() {
  FILE *f = fopen("data/hello.txt", "r");
  if (!f) { perror("open"); return 1; }
  char buf[128];
  while (fgets(buf, sizeof buf, f)) fputs(buf, stdout);
  fclose(f);
  return 0;
}

Writing Files Safely

Writing also requires a preopened directory with the right rights. Attempting to write outside it returns an error such as ENOTCAPABLE.

#include <stdio.h>
int main() {
  FILE *f = fopen("data/out.txt", "w");
  if (!f) return 1;
  fputs("written via WASI\n", f);
  fclose(f);
  return 0;
}

File Descriptors & Rights

Each WASI file descriptor carries a set of rights (read, write, seek, etc.). A directory descriptor can be more restrictive than its host counterpart, enabling least-privilege design.

Path Resolution Rules

WASI resolves paths relative to a preopened descriptor. The runtime picks the longest matching preopen. There is no global root; / is meaningless unless mapped.

The wasi-libc Layer

Languages like C compiled with wasi-sdk use wasi-libc, which translates POSIX calls into WASI syscalls. This is why familiar APIs just work inside the sandbox.

clang --target=wasm32-wasi -o app.wasm app.c

Listing a Directory

Directory iteration uses fd_readdir under the hood. High-level languages expose this as normal directory listing once a directory is preopened.

Common Errors

Typical filesystem errors when learning WASI:

  • ENOENT — file not found within the preopen
  • ENOTCAPABLE — path is outside any granted directory
  • EACCES — descriptor lacks the required right

Multiple Preopens

You can grant several directories, each with a distinct guest alias.

wasmtime run --dir=./in::input --dir=./out::output app.wasm

Best Practices

Grant the narrowest directory possible, prefer read-only preopens, and never assume host absolute paths exist inside the module.

Quick Check

Test your understanding of WASI file access.

Recap

You learned that WASI uses preopened directories and capability-based descriptors to expose files safely. Paths resolve relative to preopens, rights enforce least privilege, and wasi-libc bridges POSIX APIs to WASI syscalls.

Sıkça Sorulan Sorular

“WASI Dosya Sistemiyle Çalışma” dersi ücretsiz mi?

Evet — “WASI Dosya Sistemiyle Çalışma” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve WebAssembly (WASM) for High Performance Apps kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. WebAssembly (WASM) for High Performance Apps kursu toplamda 4 dersten oluşur.

“WASI Dosya Sistemiyle Çalışma” dersinde ne öğreneceğim?

WASI'ın önceden açılmış dizinler ve yetenek tabanlı dosya erişimi aracılığıyla ana bilgisayar dosya sistemini korumalı bir modüle nasıl sunduğunu öğrenin. WebAssembly (WASM) for High Performance Apps ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

WebAssembly (WASM) for High Performance Apps öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te WebAssembly (WASM) for High Performance Apps, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.

“WASI Dosya Sistemiyle Çalışma” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu WebAssembly (WASM) for High Performance Apps dersinde kod yazıp çalıştırabilir miyim?

Evet. Her WebAssembly (WASM) for High Performance Apps dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. WASI'ye ve Hedeflerine Giriş
  2. WASI Modülleri Oluşturma ve Çalıştırma
  3. WASI Yetenekleri ve Geleceği
  4. WASI Dosya Sistemiyle Çalışma
← WebAssembly (WASM) for High Performance Apps Sayfasına Dön