gvisor.dev/gvisor@v0.0.0-20240520182842-f9d4d51c7e0f/test/util/fuse_util.cc (about)

     1  // Copyright 2020 The gVisor Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  #include "test/util/fuse_util.h"
    16  
    17  #include <sys/stat.h>
    18  #include <sys/types.h>
    19  
    20  #include <string>
    21  
    22  namespace gvisor {
    23  namespace testing {
    24  
    25  // Create a default FuseAttr struct with specified mode, inode, and size.
    26  fuse_attr DefaultFuseAttr(mode_t mode, uint64_t inode, uint64_t size) {
    27    const int time_sec = 1595436289;
    28    const int time_nsec = 134150844;
    29    return (struct fuse_attr){
    30        .ino = inode,
    31        .size = size,
    32        .blocks = 4,
    33        .atime = time_sec,
    34        .mtime = time_sec,
    35        .ctime = time_sec,
    36        .atimensec = time_nsec,
    37        .mtimensec = time_nsec,
    38        .ctimensec = time_nsec,
    39        .mode = mode,
    40        .nlink = 2,
    41        .uid = 1234,
    42        .gid = 4321,
    43        .rdev = 12,
    44        .blksize = 4096,
    45    };
    46  }
    47  
    48  // Create response body with specified mode, nodeID, and size.
    49  fuse_entry_out DefaultEntryOut(mode_t mode, uint64_t node_id, uint64_t size) {
    50    struct fuse_entry_out default_entry_out = {
    51        .nodeid = node_id,
    52        .generation = 0,
    53        .entry_valid = 0,
    54        .attr_valid = 0,
    55        .entry_valid_nsec = 0,
    56        .attr_valid_nsec = 0,
    57        .attr = DefaultFuseAttr(mode, node_id, size),
    58    };
    59    return default_entry_out;
    60  }
    61  
    62  }  // namespace testing
    63  }  // namespace gvisor