1e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki/*
2e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * Copyright (c) 2009-2013, Google Inc.
3e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * All rights reserved.
4e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki *
5e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * Redistribution and use in source and binary forms, with or without
6e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * modification, are permitted provided that the following conditions
7e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * are met:
8e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki *  * Redistributions of source code must retain the above copyright
9e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki *    notice, this list of conditions and the following disclaimer.
10e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki *  * Redistributions in binary form must reproduce the above copyright
11e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki *    notice, this list of conditions and the following disclaimer in
12e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki *    the documentation and/or other materials provided with the
13e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki *    distribution.
14e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki *  * Neither the name of Google, Inc. nor the names of its contributors
15e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki *    may be used to endorse or promote products derived from this
16e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki *    software without specific prior written permission.
17e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki *
18e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki * SUCH DAMAGE.
30e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki */
31e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki
32e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki#ifndef _FASTBOOT_UTLIS_H
33e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki#define _FASTBOOT_UTILS_H
34e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki
35e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki#include <stdio.h>
36e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki
37e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzyckiint get_stream_size(FILE *);
38e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki
39e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzyckichar *strip(char *str);
40e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki
41e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzyckiuint64_t get_file_size64(int fd);
42e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzyckiuint64_t get_file_size(int fd);
43e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzyckiuint64_t get_block_device_size(int fd);
44e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzyckiint wipe_block_device(int fd, int64_t len);
45b015b16c977d2cdf3fe1028c08270833ff428d07Szymon Starzyckiint create_temp_file();
46b015b16c977d2cdf3fe1028c08270833ff428d07Szymon Starzyckissize_t bulk_read(int bulk_out, char *buf, size_t length);
47b015b16c977d2cdf3fe1028c08270833ff428d07Szymon Starzyckissize_t bulk_write(int bulk_in, const char *buf, size_t length);
48658122881774460d43952673a1f4553e2952bd54Szymon Starzyckiint service_start(const char *service_name);
49658122881774460d43952673a1f4553e2952bd54Szymon Starzyckiint service_stop(const char *service_name);
508c3263ea94ab7292ce8ba88d60c4672ec75b5e1aSzymon Starzyckiint ssh_server_start();
51e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki
52e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki#define ROUND_TO_PAGE(address,pagesize) ((address + pagesize - 1) & (~(pagesize - 1)))
53e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki
54e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki#define ROUND_UP(number,size) (((number + size - 1) / size) * size)
55e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki
56e160f81713034e1b5cfa6f8d8b47870b47ae84c8Szymon Starzycki#endif
57