Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: file_hasher.cc

Issue 6811030: verity: remove the depth parameter from bht_create (Closed) Base URL: http://git.chromium.org/git/dm-verity.git@master
Patch Set: Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by the GPL v2 license that can 2 // Use of this source code is governed by the GPL v2 license that can
3 // be found in the LICENSE file. 3 // be found in the LICENSE file.
4 // 4 //
5 // Implementation of FileHasher 5 // Implementation of FileHasher
6 6
7 #define __STDC_LIMIT_MACROS 1 7 #define __STDC_LIMIT_MACROS 1
8 #define __STDC_FORMAT_MACROS 1 8 #define __STDC_FORMAT_MACROS 1
9 #include <errno.h> 9 #include <errno.h>
10 #include <inttypes.h> 10 #include <inttypes.h>
(...skipping 27 matching lines...) Expand all
38 if (!f->WriteAt(to_bytes(count), dst, offset)) { 38 if (!f->WriteAt(to_bytes(count), dst, offset)) {
39 dm_bht_write_completed(entry, -EIO); 39 dm_bht_write_completed(entry, -EIO);
40 return -1; 40 return -1;
41 } 41 }
42 dm_bht_write_completed(entry, 0); 42 dm_bht_write_completed(entry, 0);
43 return 0; 43 return 0;
44 } 44 }
45 45
46 bool FileHasher::Initialize(simple_file::File *source, 46 bool FileHasher::Initialize(simple_file::File *source,
47 simple_file::File *destination, 47 simple_file::File *destination,
48 unsigned int depth,
49 unsigned int blocks, 48 unsigned int blocks,
50 const char *alg) { 49 const char *alg) {
51 if (!alg || !source || !destination) { 50 if (!alg || !source || !destination) {
52 LOG(ERROR) << "Invalid arguments supplied to Initialize"; 51 LOG(ERROR) << "Invalid arguments supplied to Initialize";
53 LOG(INFO) << "depth: " << depth;
54 LOG(INFO) << "s: " << source << " d: " << destination; 52 LOG(INFO) << "s: " << source << " d: " << destination;
55 return false; 53 return false;
56 } 54 }
57 if (source_ || destination_) { 55 if (source_ || destination_) {
58 LOG(ERROR) << "Initialize called more than once"; 56 LOG(ERROR) << "Initialize called more than once";
59 return false; 57 return false;
60 } 58 }
61 if (blocks > source->Size() / PAGE_SIZE) { 59 if (blocks > source->Size() / PAGE_SIZE) {
62 LOG(ERROR) << blocks << " blocks exceeds image size of " << source->Size(); 60 LOG(ERROR) << blocks << " blocks exceeds image size of " << source->Size();
63 return false; 61 return false;
64 } else if (blocks == 0) { 62 } else if (blocks == 0) {
65 blocks = source->Size() / PAGE_SIZE; 63 blocks = source->Size() / PAGE_SIZE;
66 if (source->Size() % PAGE_SIZE) { 64 if (source->Size() % PAGE_SIZE) {
67 LOG(ERROR) << "The source file size must be divisible by the block size"; 65 LOG(ERROR) << "The source file size must be divisible by the block size";
68 LOG(ERROR) << "Size: " << source->Size(); 66 LOG(ERROR) << "Size: " << source->Size();
69 LOG(INFO) << "Suggested size: " << ALIGN(source->Size(),PAGE_SIZE); 67 LOG(INFO) << "Suggested size: " << ALIGN(source->Size(),PAGE_SIZE);
70 return false; 68 return false;
71 } 69 }
72 } 70 }
73 alg_ = alg; 71 alg_ = alg;
74 source_ = source; 72 source_ = source;
75 destination_ = destination; 73 destination_ = destination;
76 depth_ = depth;
77 block_limit_ = blocks; 74 block_limit_ = blocks;
78 75
79 // Now we initialize the tree 76 // Now we initialize the tree
80 if (dm_bht_create(&tree_, depth_, block_limit_, alg_)) { 77 if (dm_bht_create(&tree_, block_limit_, alg_)) {
81 LOG(ERROR) << "Could not create the BH tree"; 78 LOG(ERROR) << "Could not create the BH tree";
82 return false; 79 return false;
83 } 80 }
84 dm_bht_set_write_cb(&tree_, FileHasher::WriteCallback); 81 dm_bht_set_write_cb(&tree_, FileHasher::WriteCallback);
85 // No reading is needed. 82 // No reading is needed.
86 dm_bht_set_read_cb(&tree_, dm_bht_zeroread_callback); 83 dm_bht_set_read_cb(&tree_, dm_bht_zeroread_callback);
87 84
88 return true; 85 return true;
89 } 86 }
90 87
(...skipping 22 matching lines...) Expand all
113 110
114 void FileHasher::PrintTable(bool colocated) { 111 void FileHasher::PrintTable(bool colocated) {
115 // Grab the digest (up to 1kbit supported) 112 // Grab the digest (up to 1kbit supported)
116 uint8_t digest[128]; 113 uint8_t digest[128];
117 dm_bht_root_hexdigest(&tree_, digest, sizeof(digest)); 114 dm_bht_root_hexdigest(&tree_, digest, sizeof(digest));
118 115
119 // TODO(wad) later support sizes that need 64-bit sectors. 116 // TODO(wad) later support sizes that need 64-bit sectors.
120 unsigned int hash_start = 0; 117 unsigned int hash_start = 0;
121 unsigned int root_end = to_sector(block_limit_ << PAGE_SHIFT); 118 unsigned int root_end = to_sector(block_limit_ << PAGE_SHIFT);
122 if (colocated) hash_start = root_end; 119 if (colocated) hash_start = root_end;
123 printf("0 %u verity ROOT_DEV HASH_DEV %u %u %s %s\n", 120 printf("0 %u verity ROOT_DEV HASH_DEV %u 0 %s %s\n",
124 root_end, hash_start, depth_, alg_, digest); 121 root_end, hash_start, alg_, digest);
Paul T 2011/04/07 21:54:33 Do you need to keep the 0? or should it just be de
Will Drewry 2011/04/07 22:45:17 It needs to stay for now until we change the kerne
125 } 122 }
126 123
127 } // namespace verity 124 } // namespace verity
128 125
129 126
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698