1 // Copyright 2016 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 #pragma once
6 
7 #include <zircon/types.h>
8 #include <zircon/listnode.h>
9 #include <zircon/compiler.h>
10 
11 #include <stdio.h>
12 #include <unistd.h>  // ssize_t
13 
14 __BEGIN_CDECLS
15 
16 // On Fuchsia, the Block Device is transmitted by file descriptor, rather than
17 // by path. This can prevent some racy behavior relating to FS start-up.
18 #ifdef __Fuchsia__
19 #define FS_FD_BLOCKDEVICE 200
20 #endif
21 
22 // POSIX defines st_blocks to be the number of 512 byte blocks allocated
23 // to the file. The "blkcnt" field of vnattr attempts to accomplish
24 // this same goal, but by indirecting through VNATTR_BLKSIZE, we
25 // reserve the right to change this "block size unit" (which is distinct from
26 // "blksize", because POSIX) whenever we want.
27 #define VNATTR_BLKSIZE 512
28 
29 typedef struct vnattr {
30     uint32_t valid;        // mask of which bits to set for setattr
31     uint32_t mode;
32     uint64_t inode;
33     uint64_t size;
34     uint64_t blksize;      // Block size for filesystem I/O
35     uint64_t blkcount;     // Number of VNATTR_BLKSIZE byte blocks allocated
36     uint64_t nlink;
37     uint64_t create_time;  // posix time (seconds since epoch)
38     uint64_t modify_time;  // posix time
39 } vnattr_t;
40 
41 // mask that identifies what fields to set in setattr
42 #define ATTR_CTIME  0000001
43 #define ATTR_MTIME  0000002
44 #define ATTR_ATIME  0000004  // not yet implemented
45 
46 // bits compatible with POSIX stat
47 #define V_TYPE_MASK 0170000
48 #define V_TYPE_SOCK 0140000
49 #define V_TYPE_LINK 0120000
50 #define V_TYPE_FILE 0100000
51 #define V_TYPE_BDEV 0060000
52 #define V_TYPE_DIR  0040000
53 #define V_TYPE_CDEV 0020000
54 #define V_TYPE_PIPE 0010000
55 
56 #define V_ISUID 0004000
57 #define V_ISGID 0002000
58 #define V_ISVTX 0001000
59 #define V_IRWXU 0000700
60 #define V_IRUSR 0000400
61 #define V_IWUSR 0000200
62 #define V_IXUSR 0000100
63 #define V_IRWXG 0000070
64 #define V_IRGRP 0000040
65 #define V_IWGRP 0000020
66 #define V_IXGRP 0000010
67 #define V_IRWXO 0000007
68 #define V_IROTH 0000004
69 #define V_IWOTH 0000002
70 #define V_IXOTH 0000001
71 
72 #define VTYPE_TO_DTYPE(mode) (((mode)&V_TYPE_MASK) >> 12)
73 #define DTYPE_TO_VTYPE(type) (((type)&15) << 12)
74 
75 typedef struct vdirent {
76     uint64_t ino;
77     uint8_t size;
78     uint8_t type;
79     char name[0];
80 } __PACKED vdirent_t;
81 
82 __END_CDECLS
83