Source code of Windows XP (NT5)
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.

77 lines
1.4 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. trackbuf.c
  5. Abstract:
  6. Routine to allocate a buffer suitable for i/o a track
  7. at a time.
  8. Author:
  9. Ted Miller (tedm) 29-May-1997
  10. Revision History:
  11. --*/
  12. #include <mytypes.h>
  13. #include <misclib.h>
  14. #include <malloc.h>
  15. BOOL
  16. _far
  17. AllocTrackBuffer(
  18. IN BYTE SectorsPerTrack,
  19. OUT FPVOID _far *AlignedBuffer,
  20. OUT FPVOID _far *Buffer
  21. )
  22. {
  23. FPVOID p;
  24. ULONG u;
  25. //
  26. //
  27. // We allocate twice the size we need because we will need to ensure
  28. // that the buffer doesn't cross a 64K physical boundary.
  29. // NOTE: sectors per track is assumed to be max 63!
  30. //
  31. if(SectorsPerTrack > 63) {
  32. return(FALSE);
  33. }
  34. p = malloc(SectorsPerTrack * 512 * 2);
  35. if(!p) {
  36. return(FALSE);
  37. }
  38. //
  39. // Calculate physical address of buffer.
  40. //
  41. u = ((ULONG)p & 0xffffL) + (((ULONG)p >> 16) << 4);
  42. //
  43. // Figure out whether the buffer crosses a 64k boundary.
  44. // If it does, we allocated enough to relocate it
  45. // to the next 64k boundary.
  46. //
  47. if((u & 0xf0000L) != ((u + (512*SectorsPerTrack)) & 0xf0000L)) {
  48. u = (u & 0xf0000L) + 0x10000;
  49. }
  50. //
  51. // Convert back to seg:offset. The conversion guarantees that
  52. // the offset will be in the range 0-f.
  53. //
  54. *AlignedBuffer = (FPVOID)(((u >> 4) << 16) + (u & 0xf));
  55. *Buffer = p;
  56. return(TRUE);
  57. }