目錄功能

如要瞭解每個元件隔離的目錄,請參閱儲存空間功能

提供目錄功能

如要提供目錄能力,元件必須宣告該能力,並從 self 轉送該功能。

如要定義能力,請為該功能新增 capabilities 宣告:

{
    capabilities: [
        {
            directory: "data",
            rights: ["r*"],
            path: "/published-data",
        },
    ],
}

這會定義由這個元件代管的能力,其傳出目錄路徑為 /published-data,且可用的權限上限為「唯讀」。

轉送目錄功能

元件會將目錄功能exposing給其父項,並「提供」給其子項,藉此將目錄功能轉送到其父項。

如要進一步瞭解架構路徑元件功能,請參閱「功能轉送」。

公開

公開目錄能力可讓元件的父項存取該能力:

{
    expose: [
        {
            directory: "data",
            from: "self",
        },
    ],
}

您可以選擇指定:

提供

提供儲存空間能力可讓子項元件存取該能力:

{
    offer: [
        {
            directory: "data",
            from: "parent",
            to: [ "#child-a", "#child-b" ],
        },
    ],
}

您可以選擇指定:

使用目錄功能

如要要求能力,請為該功能新增 use 宣告:

{
    use: [
        {
            directory: "data",
            rights: ["r*"],
            path: "/data",
        },
    ],
}

這會將包含共用目錄內容的 path 目錄填入元件的命名空間。

您必須指定 rights。您可以視需要指定 subdir

使用選用目錄功能

請參閱「連線元件:使用選用功能」。

目錄權限

目錄權限可讓元件在目錄在整個系統中轉送時控管存取權。目錄權限的使用方式如下:

  • capabilities必填。 提供目錄可用的基本權限組合。useofferexpose 中指定的任何權利都必須屬於此處宣告的子集。
  • use必填。 說明消耗元件要求的存取權限。
  • offer選填。 目的地元件可用的修改權限。如未顯示權限,則會從 offer 來源繼承。
  • expose選填。 目的地元件可用的修改權限。如未顯示權限,則會從 expose 來源繼承。

rights 欄位可包含下列 fuchsia.io.Rights 符記的任意組合:

rights: [
  "connect",
  "enumerate",
  "traverse",
  "read_bytes",
  "write_bytes",
  "execute_bytes",
  "update_attributes",
  "get_attributes",
  "modify_directory",
]

這個架構提供簡化形式,使用aliases宣告 rights。每個別名都代表的 FIDL 權限符記組合,可提供一般讀取、寫入或執行存取權:

別名 FIDL 權限
r* connect, enumerate, traverse, read_bytes, get_attributes
w* connect, enumerate, traverse, write_bytes, update_attributes, modify_directory
x* connect, enumerate, traverse, execute_bytes
rw* connect, enumerate, traverse, read_bytes, write_bytes, get_attributes, update_attributes, modify_directory
rx* connect, enumerate, traverse, read_bytes, execute_bytes, get_attributes

rights 欄位只能包含一個別名。只要沒有別名所表示的權利,就可能具有額外 FIDL 權限。

範例

請設想以下例子,其中元件 A 要求存取 data 目錄的讀取/寫入權限:

// A.cml
{
    use: [
        {
            directory: "data",
            rights: ["rw*"],
            path: "/data",
        },
    ],
}

不過,父項元件 BA 元件提供目錄 data 時,只有唯讀權限。在這種情況下,轉送失敗,且 A 的命名空間中沒有 data

// B.cml
{
    capabilities: [
        {
            directory: "data",
            rights: ["r*"],
            path: "/published-data",
        },
    ],
    offer: [
        {
            directory: "data",
            from: "self",
            to: [ "#A" ],
        },
    ],
}

子目錄

您可以選擇 exposeofferuse 目錄能力的子目錄:

{
    offer: [
        {
            directory: "data",
            from: "parent",
            to: [ "#child-a", "#child-b" ],
            subdir: "children",
        },
    ],
}

重新命名目錄

您可以使用不同的名稱 exposeoffer 目錄能力:

{
    offer: [
        {
            directory: "data",
            from: "#child-a",
            to: [ "#child-b" ],
            as: "a-data",
        },
    ],
}