| 1060 | } |
| 1061 | |
| 1062 | ULONG |
| 1063 | Ext2TotalBlocks( |
| 1064 | PEXT2_VCB Vcb, |
| 1065 | PLARGE_INTEGER Size, |
| 1066 | PULONG pMeta |
| 1067 | ) |
| 1068 | { |
| 1069 | ULONG Blocks, Meta =0, Remain; |
| 1070 | |
| 1071 | Blocks = (ULONG)((Size->QuadPart + BLOCK_SIZE - 1) >> BLOCK_BITS); |
| 1072 | if (Blocks <= EXT2_NDIR_BLOCKS) |
| 1073 | goto errorout; |
| 1074 | Blocks -= EXT2_NDIR_BLOCKS; |
| 1075 | |
| 1076 | Meta += 1; |
| 1077 | if (Blocks <= Vcb->max_blocks_per_layer[1]) { |
| 1078 | goto errorout; |
| 1079 | } |
| 1080 | Blocks -= Vcb->max_blocks_per_layer[1]; |
| 1081 | |
| 1082 | level2: |
| 1083 | |
| 1084 | if (Blocks <= Vcb->max_blocks_per_layer[2]) { |
| 1085 | Meta += 1 + ((Blocks + BLOCK_SIZE/4 - 1) >> (BLOCK_BITS - 2)); |
| 1086 | goto errorout; |
| 1087 | } |
| 1088 | Meta += 1 + BLOCK_SIZE/4; |
| 1089 | Blocks -= Vcb->max_blocks_per_layer[2]; |
| 1090 | |
| 1091 | if (Blocks > Vcb->max_blocks_per_layer[3]) { |
| 1092 | Blocks = Vcb->max_blocks_per_layer[3]; |
| 1093 | } |
| 1094 | |
| 1095 | ASSERT(Vcb->max_blocks_per_layer[2]); |
| 1096 | Remain = Blocks % Vcb->max_blocks_per_layer[2]; |
| 1097 | Blocks = Blocks / Vcb->max_blocks_per_layer[2]; |
| 1098 | Meta += 1 + Blocks * (1 + BLOCK_SIZE/4); |
| 1099 | if (Remain) { |
| 1100 | Blocks = Remain; |
| 1101 | goto level2; |
| 1102 | } |
| 1103 | |
| 1104 | errorout: |
| 1105 | |
| 1106 | if (pMeta) |
| 1107 | *pMeta = Meta; |
| 1108 | Blocks = (ULONG)((Size->QuadPart + BLOCK_SIZE - 1) >> BLOCK_BITS); |
| 1109 | return (Blocks + Meta); |
| 1110 | } |
| 1111 | |
| 1112 | NTSTATUS |
| 1113 | Ext2BlockMap( |