MCPcopy Create free account
hub / github.com/bobranten/Ext4Fsd / Ext2TotalBlocks

Function Ext2TotalBlocks

Ext4Fsd/fileinfo.c:1062–1110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1060}
1061
1062ULONG
1063Ext2TotalBlocks(
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
1082level2:
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
1104errorout:
1105
1106 if (pMeta)
1107 *pMeta = Meta;
1108 Blocks = (ULONG)((Size->QuadPart + BLOCK_SIZE - 1) >> BLOCK_BITS);
1109 return (Blocks + Meta);
1110}
1111
1112NTSTATUS
1113Ext2BlockMap(

Callers 1

Ext2CreateFileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected