1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <fs/service.h>
6 
7 #include <utility>
8 
9 namespace fs {
10 
Service(Connector connector)11 Service::Service(Connector connector)
12     : connector_(std::move(connector)) {}
13 
14 Service::~Service() = default;
15 
ValidateFlags(uint32_t flags)16 zx_status_t Service::ValidateFlags(uint32_t flags) {
17     if (flags & ZX_FS_FLAG_DIRECTORY) {
18         return ZX_ERR_NOT_DIR;
19     }
20     return ZX_OK;
21 }
22 
Getattr(vnattr_t * attr)23 zx_status_t Service::Getattr(vnattr_t* attr) {
24     // TODO(ZX-1152): V_TYPE_FILE isn't right, we should use a type for services
25     memset(attr, 0, sizeof(vnattr_t));
26     attr->mode = V_TYPE_FILE;
27     attr->nlink = 1;
28     return ZX_OK;
29 }
30 
Serve(Vfs * vfs,zx::channel channel,uint32_t flags)31 zx_status_t Service::Serve(Vfs* vfs, zx::channel channel, uint32_t flags) {
32     ZX_DEBUG_ASSERT(!(flags & ZX_FS_FLAG_DIRECTORY)); // checked by Open
33 
34     if (!connector_) {
35         return ZX_ERR_NOT_SUPPORTED;
36     }
37     return connector_(std::move(channel));
38 }
39 
40 } // namespace fs
41