NVbit : Accessing Bitlocker volumes from linux.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

interface.c 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. nvbit Bitlocker for linux
  3. ------------------------------
  4. Nitin Kumar nitin at nvlabs.in
  5. Vipin Kumar vipin at nvlabs.in
  6. web: http://www.nvlabs.in
  7. Licensed under GPL Version 3
  8. -------------------
  9. Copyright (c) 2008
  10. Released under the GPL Version 3
  11. http://www.gnu.org/licenses/gpl-3.0.txt
  12. */
  13. #include "common.h"
  14. #include "FVE.h"
  15. #include "vmk.h"
  16. #include "interface.h"
  17. #include <malloc.h>
  18. #include <stdio.h>
  19. /* This function opens the file and returns an interface object]
  20. */
  21. Interface* InitializeInputInterface(char *input)
  22. {
  23. Interface* input_interface = malloc( sizeof(Interface));
  24. input_interface->stream = fopen(input,"rb");
  25. // if file could not be opened return NULL
  26. if( input_interface->stream == NULL) {
  27. free( input_interface);
  28. printf("File %s could not be opened",input);
  29. exit(1);
  30. }
  31. input_interface->SectorSize = 512; // init default sector size is this still the most common size ??
  32. return input_interface;
  33. }
  34. int custom_fseek( FILE * stream, int64 offset, int origin )
  35. {
  36. int error_code;
  37. #ifdef WIN32
  38. #ifdef MSVC6 // msvc doesn't have 64 bit seek support
  39. error_code = fseek( stream , offset, origin);
  40. #else
  41. error_code = _fseeki64( stream , offset, origin);
  42. #endif
  43. #else
  44. error_code= fseek( stream , offset, origin);
  45. #endif
  46. return error_code;
  47. }
  48. /* this funtion will read one sector at a time from interface, and put it in buffer
  49. however, it is responsibility of user to check the size of buffer for overflows
  50. */
  51. int32 Read_Sector( Interface *input_interface, int64 SectorNumber, int32 SectorCount, int8 * Buffer)
  52. {
  53. int64 offset;
  54. offset = SectorNumber * input_interface->SectorSize ;
  55. // first do a seek to get to position and then grab the data
  56. #ifdef WIN32
  57. #ifdef MSVC6 // msvc doesn't have 64 bit seek support
  58. fseek( input_interface->stream , offset, SEEK_SET);
  59. #else
  60. _fseeki64( input_interface->stream , offset, SEEK_SET);
  61. #endif
  62. #else
  63. fseek( input_interface->stream , offset, SEEK_SET);
  64. #endif
  65. fseek( input_interface->stream , offset, SEEK_SET);
  66. return fread(Buffer,sizeof(int8) ,input_interface->SectorSize * SectorCount,input_interface->stream) ;
  67. }