blob: e03ef215b8979966c177e17e65d5bcd25fe77136 [file] [log] [blame]
Andrew de los Reyesb4025e62010-02-23 17:47:03 -08001// 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
5#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_EXTENT_MAPPER_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_EXTENT_MAPPER_H__
7
8#include <string>
9#include <vector>
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070010#include "base/basictypes.h"
Andrew de los Reyesb4025e62010-02-23 17:47:03 -080011#include "update_engine/update_metadata.pb.h"
12
13namespace chromeos_update_engine {
14
15namespace extent_mapper {
16
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070017// Uses the FIBMAP ioctl to get all blocks used by a file and return them
18// as extents. Blocks are relative to the start of the filesystem. If
19// there is a sparse "hole" in the file, the blocks for that will be
20// represented by an extent whose start block is kSpareseHole.
21// The resulting extents are stored in 'out'. Keep in mind that while
22// the blocksize of a filesystem is often 4096 bytes, that is not always
23// the case, so one should consult GetFilesystemBlockSize(), too.
24// Returns true on success.
Darin Petkov8e447e02013-04-16 16:23:50 +020025//
26// ExtentsForFileChunkFibmap gets the blocks starting from
27// |chunk_offset|. |chunk_offset| must be a multiple of the block size. If
28// |chunk_size| is not -1, only blocks covering up to |chunk_size| bytes are
29// returned.
Andrew de los Reyesb4025e62010-02-23 17:47:03 -080030bool ExtentsForFileFibmap(const std::string& path, std::vector<Extent>* out);
Darin Petkov8e447e02013-04-16 16:23:50 +020031bool ExtentsForFileChunkFibmap(const std::string& path,
32 off_t chunk_offset,
33 off_t chunk_size,
34 std::vector<Extent>* out);
Andrew de los Reyesb4025e62010-02-23 17:47:03 -080035
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070036// Puts the blocksize of the filesystem, as used by the FIBMAP ioctl, into
37// out_blocksize by using the FIGETBSZ ioctl. Returns true on success.
Andrew de los Reyes09e56d62010-04-23 13:45:53 -070038bool GetFilesystemBlockSize(const std::string& path, uint32_t* out_blocksize);
Andrew de los Reyesb10320d2010-03-31 16:44:44 -070039
Andrew de los Reyesb4025e62010-02-23 17:47:03 -080040} // namespace extent_mapper
41
42} // namespace chromeos_update_engine
43
44#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_EXTENT_MAPPER_H__