dart-sdk/runtime/bin/file_system_watcher.h
Zachary Anderson d0295c873c [dart:io] Namespaces for file IO
Fuchsia requires the ability to sandbox Isolates w.r.t. file IO.
When a new Isolate starts, Fuchsia will pass the Isolate an object
called a namespace. We can translate the namespace object into a
file descriptor suitable for passing to the *at() family of
POSIX file system calls. The file system calls will then
have visibility only into the specified namespace.

We also plumb Namespaces through on all the other platforms as well to
make the change easier to test and so that in the future we can
implement e.g. per-isolate cwds.

This change adds a new internal class to dart:io called _Namespace,
which is implemented in a patch file. See:

sdk/lib/io/namespace_impl.dart
runtime/bin/namespace_patch.dart

The embedder can set up a non-default namespace by calling
_Namespace._setupNamespace during Isolate setup.

Instances of _Namespace have a native field that holds a pointer
to a native Namespace object. See:

runtime/bin/namespace.h

Calls from e.g. file_impl.dart are now also passed a
_Namespace object. The implementations in e.g. file.cc and
file_linux.cc then extract the namespace, and use it to compute a
file descriptor and path suitable for passing to e.g. openat().

related US-313

R=asiva@google.com, rmacnak@google.com

Review-Url: https://codereview.chromium.org/3007703002 .
2017-08-30 09:34:36 -07:00

59 lines
1.4 KiB
C++

// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef RUNTIME_BIN_FILE_SYSTEM_WATCHER_H_
#define RUNTIME_BIN_FILE_SYSTEM_WATCHER_H_
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "bin/builtin.h"
#include "bin/dartutils.h"
#include "bin/namespace.h"
namespace dart {
namespace bin {
class FileSystemWatcher {
public:
enum EventType {
kCreate = 1 << 0,
kModifyContent = 1 << 1,
kDelete = 1 << 2,
kMove = 1 << 3,
kModefyAttribute = 1 << 4,
kDeleteSelf = 1 << 5,
kIsDir = 1 << 6
};
struct Event {
intptr_t path_id;
int event;
const char* filename;
int link;
};
static bool IsSupported();
static intptr_t Init();
static void Close(intptr_t id);
static intptr_t WatchPath(intptr_t id,
Namespace* namespc,
const char* path,
int events,
bool recursive);
static void UnwatchPath(intptr_t id, intptr_t path_id);
static intptr_t GetSocketId(intptr_t id, intptr_t path_id);
static Dart_Handle ReadEvents(intptr_t id, intptr_t path_id);
private:
DISALLOW_COPY_AND_ASSIGN(FileSystemWatcher);
};
} // namespace bin
} // namespace dart
#endif // RUNTIME_BIN_FILE_SYSTEM_WATCHER_H_