summaryrefslogtreecommitdiff
path: root/src/extent-scan.h
diff options
context:
space:
mode:
authorjeff.liu <jeff.liu@oracle.com>2010-09-29 16:11:41 +0800
committerJim Meyering <meyering@redhat.com>2011-01-30 20:44:11 +0100
commit2db1433eabc847d9ad43e059764222e9b33233aa (patch)
tree52004fa39c3225022cbb77d501be0f3ffd309add /src/extent-scan.h
parentf3e78eeff292fcc79814e62d015a271688e0212a (diff)
downloadcoreutils-2db1433eabc847d9ad43e059764222e9b33233aa.tar.xz
fiemap copy: add extent-scan.[ch], avoid a double-free and reorganize
Changes: ======== 1. fix write_zeros() per Jim's comments. 2. remove char const *fname from struct extent_scan. 3. change the signature of open_extent_scan() from "void open_extent_scan(struct extent_scan **scan)" to "void open_extent_scan(struct extent_scan *scan)" to avoid having to malloc the extent_scan variable; instead save it on the stack. 4. move close_extent_scan() from a function defined in extent-scan.c to extent-scan.h as a macro definition, but it does nothing for now, since initial extent scan defined at stack. 5. add a macro "free_extents_info()" defined at extent-scan.h to release the memory allocated to extent info which should be called combine with get_extents_info(), it just one line, so IMHO, define it as macro should be ok. * src/extent-scan.c: New file; functions to read "extents". * src/extent-scan.h: Header file of extent-scan.c. * src/Makefile.am: Reference it and link it to copy_source. * src/copy.c: Use the new functions and avoid double-free.
Diffstat (limited to 'src/extent-scan.h')
-rw-r--r--src/extent-scan.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/extent-scan.h b/src/extent-scan.h
new file mode 100644
index 000000000..07c2e5bc5
--- /dev/null
+++ b/src/extent-scan.h
@@ -0,0 +1,68 @@
+/* core functions for efficient reading sparse files
+ Copyright (C) 2010 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+ Written by Jie Liu (jeff.liu@oracle.com). */
+
+#ifndef EXTENT_SCAN_H
+# define EXTENT_SCAN_H
+
+/* Structure used to reserve information of each extent. */
+struct extent_info
+{
+ /* Logical offset of an extent. */
+ off_t ext_logical;
+
+ /* Extent length. */
+ uint64_t ext_length;
+
+ /* Extent flags, use it for FIEMAP only, or set it to zero. */
+ uint32_t ext_flags;
+};
+
+/* Structure used to reserve extent scan information per file. */
+struct extent_scan
+{
+ /* File descriptor of extent scan run against. */
+ int fd;
+
+ /* Next scan start offset. */
+ off_t scan_start;
+
+ /* How many extent info returned for a scan. */
+ uint32_t ei_count;
+
+ /* If true, fall back to a normal copy, either
+ set by the failure of ioctl(2) for FIEMAP or
+ lseek(2) with SEEK_DATA. */
+ bool initial_scan_failed;
+
+ /* If ture, the total extent scan per file has been finished. */
+ bool hit_last_extent;
+
+ /* Extent information. */
+ struct extent_info *ext_info;
+};
+
+void
+open_extent_scan (int src_fd, struct extent_scan *scan);
+
+bool
+get_extents_info (struct extent_scan *scan);
+
+#define free_extents_info(ext_scan) free ((ext_scan)->ext_info)
+#define close_extent_scan(ext_scan) /* empty */
+
+#endif /* EXTENT_SCAN_H */