SMREmulator 1.0
ShingledMagneticRecordingEmulator

emudiskimg.c File Reference

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

#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <stdarg.h>
#include <emulator.h>
#include <emudebug.h>
#include <emudiskimg.h>
#include <ediversion.h>
#include <emulog.h>

Go to the source code of this file.

Data Structures

struct  edi_fd_t
 Structure of the file descriptor lookup table used by the Emulator. More...

Defines

#define EDI_MAGIC_NUMBER   0xE5D10000U
 Magic Number identifying the disk image files.

Functions

int edi_create (const char *filename, uint32_t version,...)
 Creates a new EDI file based on the parameters specified.
int edi_dump (int fd)
 Dumps the metadata for the specified EDI file.
int edi_open (const char *filename)
 Opens the specified EDI file and verifies its validity.
int edi_close (int fd)
 Closes an open EDI file.
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.
int edi_managebands (int fd, svc_act_t action, band_t *band, rba_t *rba, int len)
 Manages bands on the Emulated Disk.
int edi_read (int fd, band_t band, rba_t rba, char *buf, rba_t len)
 Reads data from the specified band and block.
int edi_write (int fd, band_t band, rba_t rba, char *buf, rba_t len)
 Writes data to the specified band and block.
int edi_init ()

Detailed Description

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

Author:
Anand Suresh <anandsuresh@cmu.edu>
Todo:
Figure out a way to fix SVC_GETMULTIPLE in managebands() cuz the current implementation just wont do! Preferably in a manner so as to not break the current

Definition in file emudiskimg.c.


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_create ( const char *  filename,
uint32_t  version,
  ... 
)

Creates a new EDI file based on the parameters specified.

Parameters:
filenameThe name of the new EDI file
versionThe EDI format version to use for creating the new EDI file
...Version specific parameters
Returns:
On success, the file descriptor of the newly created EDI file; -1 on failure

Error Codes:

  • EVERSION Invalid/Unknown version number
  • EUNSUPPORTED The version is not supported

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

Definition at line 82 of file emudiskimg.c.

References EDI_MAGIC_NUMBER, and ediv_is_valid().

int edi_dump ( int  fd)

Dumps the metadata for the specified EDI file.

Calling this function sends output to stdout. All metadata for the specified EDI file is printed, including the version, block size, band count, and the write pointers for each band.

Parameters:
fdThe file descriptor index returned by edi_open()
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 164 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.