chromium/components/services/filesystem/public/mojom/types.mojom

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

module filesystem.mojom;

import "mojo/public/mojom/base/file_path.mojom";

// Used to explain the meaning of an offset within a file. These values line up
// exactly with base::File.
enum Whence {
  // Offset is relative to the beginning of the file.
  FROM_BEGIN   = 0,
  // Offset is from current position in the file.
  FROM_CURRENT = 1,
  // Offset is relative to the end of the file.
  FROM_END     = 2
};

// Used for |Touch()| calls. If |now| is set, |timespec| must be null (the time
// "now" will be used). Otherwise, |timespec| must not be null.
// TODO(vtl): Use a union instead, when that becomes possible.
struct TimespecOrNow {
  bool now;
  double seconds;
};

// Describes various information about a file or directory (for |Stat()|). Note
// that access/modification times may be set arbitrarily (by those with
// appropriate capabilities) and may not reflect reality.
struct FileInformation {
  // Type of the file.
  FsFileType type;
  // Size of the file, in bytes. Zero for directories.
  int64 size;
  // Last access time, in seconds since Unix Epoch.
  double atime;
  // Last modification time, in seconds since Unix Epoch.
  double mtime;
  // Create time of the file, in seconds since Unix Epoch.
  double ctime;
};

// File and directory open flags. Is a limited subset of base::File::Flags. These
// are constants instead of enums so that they are bitwise OR-able.

// Opens a file, only if it exists.
const uint32 kFlagOpen = 0x1;
// Creates a new file, only if it does not already exist.
const uint32 kFlagCreate = 0x2;
// May create a new file.
const uint32 kFlagOpenAlways = 0x4;
// May overwrite an old file.
const uint32 kCreateAlways = 0x8;
// Opens a file and truncates it, only if it exists.
const uint32 kFlagOpenTruncated = 0x10;
const uint32 kFlagRead = 0x20;
const uint32 kFlagWrite = 0x40;
const uint32 kFlagAppend = 0x80;
// Deletes the file when closed.
const uint32 kDeleteOnClose = 0x2000;
// May change modified time of the file (used on Windows only).
const uint32 kFlagWriteAttributes = 0x4000;

// File types.
//
// Note: This is named FsFileType because otherwise we have a name collision
// with windows.h.
enum FsFileType {
  UNKNOWN = 0,
  REGULAR_FILE,
  DIRECTORY,
};

// Describes a directory entry (i.e., a single member of a directory).
struct DirectoryEntry {
  // It contains only the entry name, i.e.: /path/to/a/file would be just
  // "file". TODO(https://crbug/779196): Use Basename type when available.
  mojo_base.mojom.FilePath name;

  // Type of a given entry.
  FsFileType type;
};

// Deletion flags:
// Recursively delete.
const uint32 kDeleteFlagRecursive = 0x1;