Question: #include #include #include #include mdadm.h #include jbod.h static int mounted = 0 ; / / Helper function to create JBOD operation command static
#include
#include
#include
#include "mdadm.h
#include "jbod.h
static int mounted ;
Helper function to create JBOD operation command
static uintt createoperationjbodcmdt cmd int disknum, int blocknum
uintt op
op disknum ; Disk ID in bits
op blocknum ; Block ID in bits
op cmd ; Command in bits
return op;
int mdadmmountvoid
If already mounted, return error
if mounted
return ; System is already mounted
Create the mount operation command
Since the operation is to mount, we don't care about disknum or blocknum.
uintt op JBODMOUNT ; Command is stored in bits so shift JBODMOUNT by bits.
Call jbodoperation to execute the mount operation
if jbodoperationop NULL
mounted ; Mark system as mounted
return ; Return success
else
return ; Mount operation failed
extern int mounted;
int mdadmunmountvoid
If not mounted, return error
if mounted
return ; System is not mounted, cannot unmount
Create the unmount operation command
Since the operation is to unmount, we don't care about disknum or blocknum.
uintt op JBODUNMOUNT ; Command is stored in bits so shift JBODUNMOUNT by bits.
Call jbodoperation to execute the unmount operation
if jbodoperationop NULL
mounted ; Mark system as unmounted
return ; Return success
else
return ; Unmount operation failed
int mdadmreaduintt startaddr, uintt readlen, uintt readbuf
Basic validation checks
if mounted return ; System is unmounted
if readlen return ; Exceeds max read length
if readlen and readbuf NULL return ; Null buffer
if readlen return ; Nothing to read
if startaddr JBODNUMDISKS JBODDISKSIZE return ; Out of bounds
if startaddr readlen JBODNUMDISKS JBODDISKSIZE return ; Out of bounds
uintt bytesread
uintt curraddr startaddr;
Calculate the initial disk and block based on the start address
uintt diskid curraddr JBODDISKSIZE;
uintt diskoffset curraddr JBODDISKSIZE;
uintt blockid diskoffset JBODBLOCKSIZE;
uintt blockoffset diskoffset JBODBLOCKSIZE;
Seek to the initial disk and block
uintt seekdiskop createoperationJBODSEEKTODISK, diskid;
if jbodoperationseekdiskop NULL return ;
uintt seekblockop createoperationJBODSEEKTOBLOCK, blockid;
if jbodoperationseekblockop NULL return ;
while bytesread readlen
Read the block at the current position
uintt blockJBODBLOCKSIZE;
uintt readop createoperationJBODREADBLOCK, ;
if jbodoperationreadop block return ;
Calculate how many bytes to copy from this block
uintt remaininginblock JBODBLOCKSIZE blockoffset;
uintt remainingtoread readlen bytesread;
uintt bytestocopy remaininginblock remainingtoread remaininginblock : remainingtoread;
Copy the required bytes from the block to the output buffer
memcpyreadbuf bytesread, block blockoffset, bytestocopy;
Update counters
bytesread bytestocopy;
curraddr bytestocopy;
if curraddr JBODBLOCKSIZE
blockid; Move to the next block
blockoffset ; Reset block offset to for the new block
Reset blockoffset since we start reading from the beginning of the next block
blockoffset ;
Move to the next disk if the current address exceeds the disk boundary
if curraddr JBODDISKSIZE
diskid;
blockid ;
seekdiskop createoperationJBODSEEKTODISK, diskid;
if jbodoperationseekdiskop NULL return ;
return bytesread; Return the number of bytes read
This is my code for a JBOD program. Disk Operation Format:
Bits Width Field Description
DiskID ID of the disk for the operation
BlockID ID of the block within the disk
Command The command to be executed
Reserved Unused
Each of these hard disks consists of i blocks, with each block holding bytes. Since youve bought j disks, the total storage capacity is:
bytes MB
The following function can be used to control the disks:
int jbodoperationuintt op uintt block;
Only of my test cases are
running The mdadmread function correctly handles reading within a single disk, but when it tries to read across disk boundaries, the data read does not match the expected result.
The test case is expecting the last bytes of disk to be xee and the first bytes of disk to be xff However, the mdadmread function is returning xaa for both disks,indicating that the disk switch from disk to disk PLEASE CORRECT MY CODE TO HANDLE THESE EDGE CASES. you dont need more lib funcs
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
