| 1135 | |
| 1136 | |
| 1137 | NTSTATUS |
| 1138 | Ext2ExpandFile( |
| 1139 | PEXT2_IRP_CONTEXT IrpContext, |
| 1140 | PEXT2_VCB Vcb, |
| 1141 | PEXT2_MCB Mcb, |
| 1142 | PLARGE_INTEGER Size |
| 1143 | ) |
| 1144 | { |
| 1145 | NTSTATUS status = STATUS_SUCCESS; |
| 1146 | ULONG Start = 0; |
| 1147 | ULONG End = 0; |
| 1148 | |
| 1149 | Start = (ULONG)((Mcb->Inode.i_size + BLOCK_SIZE - 1) >> BLOCK_BITS); |
| 1150 | End = (ULONG)((Size->QuadPart + BLOCK_SIZE - 1) >> BLOCK_BITS); |
| 1151 | |
| 1152 | /* it's a truncate operation, not expanding */ |
| 1153 | if (Start >= End) { |
| 1154 | Size->QuadPart = ((LONGLONG) Start) << BLOCK_BITS; |
| 1155 | return STATUS_SUCCESS; |
| 1156 | } |
| 1157 | |
| 1158 | /* ignore special files */ |
| 1159 | if (IsMcbSpecialFile(Mcb)) { |
| 1160 | return STATUS_INVALID_DEVICE_REQUEST; |
| 1161 | } |
| 1162 | |
| 1163 | /* expandind file extents */ |
| 1164 | if (INODE_HAS_EXTENT(&Mcb->Inode)) { |
| 1165 | |
| 1166 | status = Ext2ExpandExtent(IrpContext, Vcb, Mcb, Start, End, Size); |
| 1167 | |
| 1168 | } else { |
| 1169 | |
| 1170 | BOOLEAN do_expand; |
| 1171 | |
| 1172 | #if EXT2_PRE_ALLOCATION_SUPPORT |
| 1173 | do_expand = TRUE; |
| 1174 | #else |
| 1175 | do_expand = (IrpContext->MajorFunction == IRP_MJ_WRITE) || |
| 1176 | IsMcbDirectory(Mcb); |
| 1177 | #endif |
| 1178 | if (!do_expand) |
| 1179 | goto errorout; |
| 1180 | |
| 1181 | status = Ext2ExpandIndirect(IrpContext, Vcb, Mcb, Start, End, Size); |
| 1182 | } |
| 1183 | |
| 1184 | errorout: |
| 1185 | return status; |
| 1186 | } |
| 1187 | |
| 1188 | |
| 1189 | NTSTATUS |
no test coverage detected