SMREmulator 1.0
ShingledMagneticRecordingEmulator

emulator.h File Reference

Defines the Macros, data types and function prototypes for using the SMR Emulator. More...

#include "emutypes.h"
#include "emuerror.h"

Go to the source code of this file.

Defines

#define MAX_EDIS   8
 Maximum number of simultaneous EDIs that can be opened.

Functions

int edi_init ()
int edi_open (const char *)
 Opens the specified EDI file and verifies its validity.
int edi_close (int)
 Closes an open EDI file.
int edi_modesense (int, inq_t, void *)
 Queries the Emulated Disk to retrieve disk parameters such as block size, band count, etc.
int edi_managebands (int, svc_act_t, band_t *, rba_t *, int)
 Manages bands on the Emulated Disk.
int edi_read (int, band_t, rba_t, char *, rba_t)
 Reads data from the specified band and block.
int edi_write (int, band_t, rba_t, char *, rba_t)
 Writes data to the specified band and block.

Detailed Description

Defines the Macros, data types and function prototypes for using the SMR Emulator.

Author:
Anand Suresh <anandsuresh@cmu.edu>
Bug:
No known bugs

Definition in file emulator.h.


Function Documentation

int edi_close ( int  fd)

Closes an open EDI file.

Parameters:
fdThe file descriptor index returned by edi_open()
Returns:
0 on success; -1 on failure

Error Codes:

  • EBADFD - The file descriptor index passed is invalid

Other than the above, the function also returns the error codes returned by close() and the close() function call for the specific EDI version.

Definition at line 285 of file emudiskimg.c.

int edi_init ( )

Initializes the Emulated Disk Image interface.

Returns:
0 on success; -1 on failure

Definition at line 569 of file emudiskimg.c.

References ediv_init(), emulog_open(), and MAX_EDIS.

int edi_managebands ( int  fd,
svc_act_t  action,
band_t band,
rba_t rba,
int  len 
)

Manages bands on the Emulated Disk.

The Manage Bands command is used for multiple actions, depending on the Service Action requested. Each Service Action expects a certain number of parameters for the function to execute correctly.

1. SVC_GETPTR: Retrieves the Write Pointer for the specified band. It expects 2 parameters:

  • The Band No. of the band whose Write Pointer is to be retrieved
  • A pointer to a variable to store the retrieved RBA.

2. SVC_SETPTR: Sets the Write Pointer for the specified band. It expects 2 parameters:

  • The Band No. of the band whose Write Pointer is to be set
  • The new RBA to set as the Write Pointer for the band

3. SVC_GETMULTIPLE: Retrieves the Write Pointers for multiple bands. It expects 3 parameters:

  • An array of Band Numbers whose Write Pointers are to be retrieved.
  • An array to store the Write Pointers of the bands
  • A count of the number of bands passed in the array

4. SVC_RESETALL: Resets the Write Pointers of all bands to the start of the band. This function does not expect any parameters.

5. SVC_GETBANDCONFIG: Retrieves the band configuration for the specific band. It expects 2 parameters:

  • The Band No. of the band whose configuration is to be retrieved
  • A pointer to a variable to store the retrieved configuration.
Parameters:
fdThe file descriptor index returned by edi_open()
actionThe desired action to perform
bandPointer to the band on which the action is to be performed
rbaPointer to the RBA for the operation
lenLength of the array of band numbers (only for SVC_GETMULTIPLE)
Returns:
Depends on the version

Error Codes:

  • EBADFD - The file descriptor index passed is invalid
  • EUNSUPPORTED - If the version of the EDI does not support the operation

Other than the above, the function also returns the error codes returned by the managegbands() function call for the specific EDI version.

Definition at line 417 of file emudiskimg.c.

int edi_modesense ( int  fd,
inq_t  inq,
void *  data 
)

Queries the Emulated Disk to retrieve disk parameters such as block size, band count, etc.

This function takes a void pointer for the data variable. However, internally, it will cast the pointer to the desired type depending on the data being requested. It is up to the programmer to ensure that the pointer being passed addresses the required amount of memory for the returned data.

See also:
inq_t
Parameters:
fdThe file descriptor index returned by edi_open()
inqThe Inquiry code for the desired data
dataPointer to a variable to store the returned data
Returns:
Depends on the version

Error Codes:

  • EBADFD - The file descriptor index passed is invalid
  • EUNSUPPORTED - The version of the EDI does not support the operation

Definition at line 334 of file emudiskimg.c.

int edi_open ( const char *  filename)

Opens the specified EDI file and verifies its validity.

In case or any errors, the function DOES NOT close the open EDI file. It is up to the programmer to detect any errors, handle them accordingly and then close the open EDI file.

Parameters:
filenamePath to the EDI file.
Returns:
On success, the index of the file descriptor in the edis array; -1 on failure

Errors returned:

  • EINVALIDFILE The file is not a valid EDI file
  • EVERSION The version of the EDI file is unknown
  • EUNSUPPORTED The version of the EDI file is unsupported

Other than the above, the function also returns the error codes returned by open() and the open() function for the specific EDI version.

Definition at line 205 of file emudiskimg.c.

References EDI_MAGIC_NUMBER, and ediv_is_valid().

int edi_read ( int  fd,
band_t  band,
rba_t  rba,
char *  buf,
rba_t  len 
)

Reads data from the specified band and block.

It is up to the programmer to ensure that the buffer passed to the function is sufficiently large to hold the requested data.

Parameters:
fdThe file descriptor index returned by edi_open()
bandThe Band no. of the band from which data is to be read
rbaThe starting block in the band from which data is to be read
bufPointer to the buffer into which the data is to be read
lenNumber of contiguous "blocks" to read, starting from rba
Returns:
Depends on the version

Error Codes:

  • EBADFD - The file descriptor index passed is invalid
  • EUNSUPPORTED - If the version of the EDI does not support the operation

Definition at line 493 of file emudiskimg.c.

int edi_write ( int  fd,
band_t  band,
rba_t  rba,
char *  buf,
rba_t  len 
)

Writes data to the specified band and block.

Parameters:
fdThe file descriptor index returned by edi_open()
bandThe Band no. of the band to which data is to be written
rbaThe starting block in the band to which data is to be written
bufPointer to the buffer which holds the data is to be written
lenNumber of contiguous "blocks" to write, starting from rba
Returns:
Depends on the version

Error Codes:

  • EBADFD - The file descriptor index passed is invalid
  • EUNSUPPORTED - If the version of the EDI does not support the operation

Definition at line 536 of file emudiskimg.c.