1fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/* 2fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Copyright (C) 2010 The Android Open Source Project 3fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 4fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Licensed under the Apache License, Version 2.0 (the "License"); 5fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * you may not use this file except in compliance with the License. 6fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * You may obtain a copy of the License at 7fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 8fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * http://www.apache.org/licenses/LICENSE-2.0 9fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 10fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Unless required by applicable law or agreed to in writing, software 11fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * distributed under the License is distributed on an "AS IS" BASIS, 12fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * See the License for the specific language governing permissions and 14fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * limitations under the License. 15fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 16fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 17fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifndef __FWDLOCKFILE_H__ 18fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#define __FWDLOCKFILE_H__ 19fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 20fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef __cplusplus 21fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraextern "C" { 22fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 23fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 24fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#include <sys/types.h> 25fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 26fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 27fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Attaches to an open Forward Lock file. The file position is assumed to be at the beginning of the 28fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * file. 29fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 30fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file. 31fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 32fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A status code. 33fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval 0 Success. 34fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval -1 Failure. 35fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 36fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_attach(int fileDesc); 37fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 38fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 39fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Reads the specified number of bytes from an open Forward Lock file. 40fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 41fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file. 42fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[out] pBuffer A reference to the buffer that should receive the read data. 43fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] numBytes The number of bytes to read. 44fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 45fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return The number of bytes read. 46fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval -1 Failure. 47fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 48fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherassize_t FwdLockFile_read(int fileDesc, void *pBuffer, size_t numBytes); 49fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 50fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 51fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Updates the file position within an open Forward Lock file. 52fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 53fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file. 54fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] offset The offset with which to update the file position. 55fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] whence One of SEEK_SET, SEEK_CUR, and SEEK_END. 56fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 57fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return The new file position. 58fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval ((off64_t)-1) Failure. 59fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 60fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraoff64_t FwdLockFile_lseek(int fileDesc, off64_t offset, int whence); 61fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 62fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 63fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Detaches from an open Forward Lock file. 64fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 65fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file. 66fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 67fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A status code. 68fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval 0 Success. 69fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval -1 Failure. 70fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 71fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_detach(int fileDesc); 72fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 73fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 74fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Closes an open Forward Lock file. 75fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 76fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file. 77fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 78fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A status code. 79fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval 0 Success. 80fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval -1 Failure. 81fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 82fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_close(int fileDesc); 83fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 84fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 85fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Checks the data integrity of an open Forward Lock file. 86fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 87fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file. 88fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 89fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A Boolean value indicating whether the integrity check was successful. 90fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 91fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_CheckDataIntegrity(int fileDesc); 92fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 93fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 94fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Checks the header integrity of an open Forward Lock file. 95fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 96fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file. 97fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 98fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A Boolean value indicating whether the integrity check was successful. 99fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 100fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_CheckHeaderIntegrity(int fileDesc); 101fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 102fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 103fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Checks both the data and header integrity of an open Forward Lock file. 104fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 105fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file. 106fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 107fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A Boolean value indicating whether the integrity check was successful. 108fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 109fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_CheckIntegrity(int fileDesc); 110fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 111fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/** 112fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Returns the content type of an open Forward Lock file. 113fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 114fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file. 115fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * 116fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return 117fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * A reference to the content type. The reference remains valid as long as the file is kept open. 118fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */ 119fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraconst char *FwdLockFile_GetContentType(int fileDesc); 120fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 121fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef __cplusplus 122fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera} 123fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif 124fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera 125fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif // __FWDLOCKFILE_H__ 126