FwdLockFile.h revision fdd65a0fc7df2c878cc601e4c0f4021cb264f051
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 * Opens a Forward Lock file for reading.
40fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
41fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] pFilename A reference to a filename.
42fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
43fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A file descriptor.
44fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval -1 Failure.
45fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */
46fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_open(const char *pFilename);
47fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
48fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/**
49fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Reads the specified number of bytes from an open Forward Lock file.
50fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
51fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file.
52fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[out] pBuffer A reference to the buffer that should receive the read data.
53fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] numBytes The number of bytes to read.
54fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
55fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return The number of bytes read.
56fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval -1 Failure.
57fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */
58fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeherassize_t FwdLockFile_read(int fileDesc, void *pBuffer, size_t numBytes);
59fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
60fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/**
61fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Updates the file position within an open Forward Lock file.
62fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
63fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file.
64fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] offset The offset with which to update the file position.
65fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] whence One of SEEK_SET, SEEK_CUR, and SEEK_END.
66fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
67fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return The new file position.
68fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval ((off64_t)-1) Failure.
69fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */
70fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraoff64_t FwdLockFile_lseek(int fileDesc, off64_t offset, int whence);
71fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
72fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/**
73fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Detaches from an open Forward Lock file.
74fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
75fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file.
76fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
77fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A status code.
78fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval 0 Success.
79fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval -1 Failure.
80fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */
81fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_detach(int fileDesc);
82fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
83fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/**
84fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Closes an open Forward Lock file.
85fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
86fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file.
87fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
88fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A status code.
89fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval 0 Success.
90fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @retval -1 Failure.
91fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */
92fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_close(int fileDesc);
93fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
94fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/**
95fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Checks the data integrity of an open Forward Lock file.
96fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
97fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file.
98fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
99fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A Boolean value indicating whether the integrity check was successful.
100fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */
101fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_CheckDataIntegrity(int fileDesc);
102fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
103fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/**
104fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Checks the header integrity of an open Forward Lock file.
105fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
106fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file.
107fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
108fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A Boolean value indicating whether the integrity check was successful.
109fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */
110fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_CheckHeaderIntegrity(int fileDesc);
111fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
112fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/**
113fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Checks both the data and header integrity of an open Forward Lock file.
114fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
115fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file.
116fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
117fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return A Boolean value indicating whether the integrity check was successful.
118fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */
119fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraint FwdLockFile_CheckIntegrity(int fileDesc);
120fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
121fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera/**
122fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * Returns the content type of an open Forward Lock file.
123fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
124fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @param[in] fileDesc The file descriptor of an open Forward Lock file.
125fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *
126fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera * @return
127fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera *   A reference to the content type. The reference remains valid as long as the file is kept open.
128fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera */
129fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbeheraconst char *FwdLockFile_GetContentType(int fileDesc);
130fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
131fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#ifdef __cplusplus
132fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera}
133fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif
134fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera
135fdd65a0fc7df2c878cc601e4c0f4021cb264f051Pravat Dalbehera#endif // __FWDLOCKFILE_H__
136