1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.virt.fs; 18 19 /** 20 * A service that works like a file server, where the files and directories are identified by 21 * "remote FD" that may be pre-exchanged or created on request. 22 * 23 * When a binder error is returned and it is a service specific error, the error code is an errno 24 * value which is an int. 25 * 26 * {@hide} 27 */ 28 interface IVirtFdService { 29 /** Maximum content size that the service allows the client to request. */ 30 const int MAX_REQUESTING_DATA = 16384; 31 32 /** 33 * Returns the content of the given remote FD, from the offset, for the amount of requested size 34 * or until EOF. 35 */ readFile(int fd, long offset, int size)36 byte[] readFile(int fd, long offset, int size); 37 38 /** 39 * Returns the content of fs-verity compatible Merkle tree of the given remote FD, from the 40 * offset, for the amount of requested size or until EOF. 41 */ readFsverityMerkleTree(int fd, long offset, int size)42 byte[] readFsverityMerkleTree(int fd, long offset, int size); 43 44 /** Returns the fs-verity signature of the given remote FD. */ readFsveritySignature(int fd)45 byte[] readFsveritySignature(int fd); 46 47 /** 48 * Writes the buffer to the given remote FD from the file's offset. Returns the number of bytes 49 * written. 50 */ writeFile(int fd, in byte[] buf, long offset)51 int writeFile(int fd, in byte[] buf, long offset); 52 53 /** Resizes the file backed by the given remote FD to the new size. */ resize(int fd, long size)54 void resize(int fd, long size); 55 56 /** Returns the file size. */ getFileSize(int fd)57 long getFileSize(int fd); 58 59 /** 60 * Opens a file given the remote directory FD. 61 * 62 * @param pathname The file path to open. Must be a related path. 63 * @return file A remote FD that represents the opened file. 64 */ openFileInDirectory(int dirFd, String pathname)65 int openFileInDirectory(int dirFd, String pathname); 66 67 /** 68 * Creates a file given the remote directory FD. 69 * 70 * @param basename The file name to create. Must not contain directory separator. 71 * @param mode File mode of the new file. See open(2). 72 * @return file A remote FD that represents the new created file. 73 */ createFileInDirectory(int dirFd, String basename, int mode)74 int createFileInDirectory(int dirFd, String basename, int mode); 75 76 /** 77 * Creates a directory inside the given remote directory FD. 78 * 79 * @param basename The directory name to create. Must not contain directory separator. 80 * @param mode File mode of the new directory. See mkdir(2). 81 * @return file FD that represents the new created directory. 82 */ createDirectoryInDirectory(int dirFd, String basename, int mode)83 int createDirectoryInDirectory(int dirFd, String basename, int mode); 84 85 /** 86 * Deletes a file in the given directory. 87 * 88 * @param basename The file name to delete. Must not contain directory separator. 89 */ deleteFile(int dirFd, String basename)90 void deleteFile(int dirFd, String basename); 91 92 /** 93 * Deletes a sub-directory in the given directory. 94 * 95 * @param basename The directory name to delete. Must not contain directory separator. 96 */ deleteDirectory(int dirFd, String basename)97 void deleteDirectory(int dirFd, String basename); 98 99 /** 100 * Changes mode of the FD. 101 * 102 * @param fd The FD to change. 103 * @param mode New file mode to pass to chmod(2)/fchmod(2). 104 */ chmod(int fd, int mode)105 void chmod(int fd, int mode); 106 107 /** Filesystem stats that AuthFS is interested in.*/ 108 parcelable FsStat { 109 /** Block size of the filesystem */ 110 long blockSize; 111 /** Fragment size of the filesystem */ 112 long fragmentSize; 113 /** Number of blocks in the filesystem */ 114 long blockNumbers; 115 /** Number of free blocks */ 116 long blockAvailable; 117 /** Number of free inodes */ 118 long inodesAvailable; 119 /** Maximum filename length */ 120 long maxFilename; 121 } 122 123 /** Returns relevant filesystem stats. */ statfs()124 FsStat statfs(); 125 } 126