Page 1 of 1

(VIII-5) [10 points; 5 points each] Consider following example C structure for the RAM drive: typedef unsigned char BYTE

Posted: Sat May 14, 2022 7:28 pm
by answerhappygod
Viii 5 10 Points 5 Points Each Consider Following Example C Structure For The Ram Drive Typedef Unsigned Char Byte 1
Viii 5 10 Points 5 Points Each Consider Following Example C Structure For The Ram Drive Typedef Unsigned Char Byte 1 (144.87 KiB) Viewed 29 times
(VIII-5) [10 points; 5 points each] Consider following example C structure for the RAM drive: typedef unsigned char BYTE; typedef unsigned long DWORD; typedef struct_RAMDrive Manager { BYTE* pbBuffer; DWORD dwTotalSectors; pthread_mutex_t* pMutex; } RAMDrive Manager; RAMDrive Manager gMyRAMDrive; // RAM drive memory area // Total number of sectors in RAM drive // For synchronized I/O Using the above, we wrote an example RAM drive sector read function based on LBA addressing as: // Read iSectors starting from dwLBA, and return it into pcBuffer int readRAMDriveSector (DWORD dwLBA, int iSectors, char* pcBuffer) { int iRealCount = MIN ( gMyRAMDrive.dwTotalSectors - (dwLBA + iSectors), iSectors ); memcpy ( pcBuffer, gMyRAMDrive.pbBuffer + (dwLBA * 512), iRealCount * 512 ); return iRealCount; } where MIN(x, y) is a macro that will return x or y, whichever smaller. (a) Why do we need to calculate iRealCount using MINO? (b) Why are we multiplying 512 when passing arguments to the memcpy(?