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