blob: 9428f1b1ff27ff33c4d2b3ec957b3f06735ce61b [file] [log] [blame]
Jed Estepf1fc48c2015-12-15 16:04:53 -08001/*
2 * Copyright (C) 2015 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/*
18 * Provide a series of proxy functions for basic file accessors.
19 * The behavior of these functions can be changed to return different
20 * errors under a variety of conditions.
21 */
22
23#ifndef _UPDATER_OTA_IO_H_
24#define _UPDATER_OTA_IO_H_
25
26#include <stdio.h>
27#include <sys/stat.h>
28
Tao Bao3dc14cb2016-11-22 11:37:13 -080029#include <memory>
30
Tao Bao6e02ea92016-11-17 11:24:07 -080031#include <android-base/unique_fd.h>
32
Jed Estepff6df892015-12-15 16:04:53 -080033#define OTAIO_CACHE_FNAME "/cache/saved.file"
34
35void ota_set_fault_files();
36
Jed Estepf1fc48c2015-12-15 16:04:53 -080037int ota_open(const char* path, int oflags);
38
39int ota_open(const char* path, int oflags, mode_t mode);
40
41FILE* ota_fopen(const char* filename, const char* mode);
42
Jed Estepf1fc48c2015-12-15 16:04:53 -080043size_t ota_fread(void* ptr, size_t size, size_t nitems, FILE* stream);
44
45ssize_t ota_read(int fd, void* buf, size_t nbyte);
46
47size_t ota_fwrite(const void* ptr, size_t size, size_t count, FILE* stream);
48
49ssize_t ota_write(int fd, const void* buf, size_t nbyte);
50
51int ota_fsync(int fd);
52
Tao Bao6e02ea92016-11-17 11:24:07 -080053struct OtaCloser {
Tao Bao358c2ec2016-11-28 11:48:43 -080054 static void Close(int);
Tao Bao6e02ea92016-11-17 11:24:07 -080055};
56
57using unique_fd = android::base::unique_fd_impl<OtaCloser>;
58
Tao Bao3dc14cb2016-11-22 11:37:13 -080059int ota_close(unique_fd& fd);
60
Tao Bao358c2ec2016-11-28 11:48:43 -080061struct OtaFcloser {
Mikhail Lappob49767c2017-03-23 21:44:26 +010062 void operator()(FILE*) const;
Tao Bao358c2ec2016-11-28 11:48:43 -080063};
64
65using unique_file = std::unique_ptr<FILE, OtaFcloser>;
66
67int ota_fclose(unique_file& fh);
Tao Bao3dc14cb2016-11-22 11:37:13 -080068
Jed Estepf1fc48c2015-12-15 16:04:53 -080069#endif