Andrew de los Reyes | b4025e6 | 2010-02-23 17:47:03 -0800 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Alex Deymo | 161c4a1 | 2014-05-16 15:56:21 -0700 | [diff] [blame] | 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_GENERATOR_EXTENT_MAPPER_H_ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_GENERATOR_EXTENT_MAPPER_H_ |
Andrew de los Reyes | b4025e6 | 2010-02-23 17:47:03 -0800 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | #include <vector> |
Alex Deymo | 161c4a1 | 2014-05-16 15:56:21 -0700 | [diff] [blame] | 10 | |
| 11 | #include <base/basictypes.h> |
| 12 | |
Andrew de los Reyes | b4025e6 | 2010-02-23 17:47:03 -0800 | [diff] [blame] | 13 | #include "update_engine/update_metadata.pb.h" |
| 14 | |
| 15 | namespace chromeos_update_engine { |
| 16 | |
| 17 | namespace extent_mapper { |
| 18 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 19 | // Uses the FIBMAP ioctl to get all blocks used by a file and return them |
| 20 | // as extents. Blocks are relative to the start of the filesystem. If |
| 21 | // there is a sparse "hole" in the file, the blocks for that will be |
| 22 | // represented by an extent whose start block is kSpareseHole. |
| 23 | // The resulting extents are stored in 'out'. Keep in mind that while |
| 24 | // the blocksize of a filesystem is often 4096 bytes, that is not always |
| 25 | // the case, so one should consult GetFilesystemBlockSize(), too. |
| 26 | // Returns true on success. |
Darin Petkov | 8e447e0 | 2013-04-16 16:23:50 +0200 | [diff] [blame] | 27 | // |
| 28 | // ExtentsForFileChunkFibmap gets the blocks starting from |
| 29 | // |chunk_offset|. |chunk_offset| must be a multiple of the block size. If |
| 30 | // |chunk_size| is not -1, only blocks covering up to |chunk_size| bytes are |
| 31 | // returned. |
Andrew de los Reyes | b4025e6 | 2010-02-23 17:47:03 -0800 | [diff] [blame] | 32 | bool ExtentsForFileFibmap(const std::string& path, std::vector<Extent>* out); |
Darin Petkov | 8e447e0 | 2013-04-16 16:23:50 +0200 | [diff] [blame] | 33 | bool ExtentsForFileChunkFibmap(const std::string& path, |
| 34 | off_t chunk_offset, |
| 35 | off_t chunk_size, |
| 36 | std::vector<Extent>* out); |
Andrew de los Reyes | b4025e6 | 2010-02-23 17:47:03 -0800 | [diff] [blame] | 37 | |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 38 | // Puts the blocksize of the filesystem, as used by the FIBMAP ioctl, into |
| 39 | // out_blocksize by using the FIGETBSZ ioctl. Returns true on success. |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 40 | bool GetFilesystemBlockSize(const std::string& path, uint32_t* out_blocksize); |
Andrew de los Reyes | b10320d | 2010-03-31 16:44:44 -0700 | [diff] [blame] | 41 | |
Andrew de los Reyes | b4025e6 | 2010-02-23 17:47:03 -0800 | [diff] [blame] | 42 | } // namespace extent_mapper |
| 43 | |
| 44 | } // namespace chromeos_update_engine |
| 45 | |
Alex Deymo | 161c4a1 | 2014-05-16 15:56:21 -0700 | [diff] [blame] | 46 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_PAYLOAD_GENERATOR_EXTENT_MAPPER_H_ |