2 * cluster - Part of the Linux-NTFS project.
4 * Copyright (c) 2002-2003 Richard Russon
5 * Copyright (c) 2014 Jean-Pierre Andre
7 * This function will locate the owner of any given sector or cluster range.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (in the main directory of the Linux-NTFS
21 * distribution in the file COPYING); if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
44 int cluster_find(ntfs_volume
*vol
, LCN c_begin
, LCN c_end
, cluster_cb
*cb
, void *data
)
48 struct mft_search_ctx
*m_ctx
= NULL
;
49 ntfs_attr_search_ctx
*a_ctx
= NULL
;
58 m_ctx
= mft_get_search_ctx(vol
);
59 m_ctx
->flags_search
= FEMR_IN_USE
| FEMR_BASE_RECORD
;
62 while (mft_next_record(m_ctx
) == 0) {
64 if (!(m_ctx
->flags_match
& FEMR_BASE_RECORD
))
67 ntfs_log_verbose("Inode: %llu\n", (unsigned long long)
68 m_ctx
->inode
->mft_no
);
70 a_ctx
= ntfs_attr_get_search_ctx(m_ctx
->inode
, NULL
);
73 while ((rec
= find_attribute(AT_UNUSED
, a_ctx
))) {
75 if (!rec
->non_resident
) {
76 ntfs_log_verbose("0x%02x skipped - attr is resident\n",
77 (int)le32_to_cpu(a_ctx
->attr
->type
));
81 runs
= ntfs_mapping_pairs_decompress(vol
, a_ctx
->attr
, NULL
);
83 ntfs_log_error("Couldn't read the data runs.\n");
87 ntfs_log_verbose("\t[0x%02X]\n",
88 (int)le32_to_cpu(a_ctx
->attr
->type
));
90 ntfs_log_verbose("\t\tVCN\tLCN\tLength\n");
91 for (j
= 0; runs
[j
].length
> 0; j
++) {
92 LCN a_begin
= runs
[j
].lcn
;
93 LCN a_end
= a_begin
+ runs
[j
].length
- 1;
96 continue; // sparse, discontiguous, etc
98 ntfs_log_verbose("\t\t%lld\t%lld-%lld (%lld)\n",
99 (long long)runs
[j
].vcn
,
100 (long long)runs
[j
].lcn
,
101 (long long)(runs
[j
].lcn
+
103 (long long)runs
[j
].length
);
106 if ((a_begin
> c_end
) || (a_end
< c_begin
))
107 continue; // before or after search range
109 if ((*cb
) (m_ctx
->inode
, a_ctx
->attr
, runs
+j
, data
))
115 ntfs_attr_put_search_ctx(a_ctx
);
122 ntfs_log_info("* %lld inodes found\n",(long long)count
);
124 ntfs_log_info("* %s inode found\n", (count
? "one" : "no"));
127 ntfs_attr_put_search_ctx(a_ctx
);
128 mft_put_search_ctx(m_ctx
);