NASD Programmer's Documentation
Results and Errors

Background

Most NASD functions return type nasd_status_t, and all drive RPCs include a nasd_status_t in their result. This type is an all-purpose result code which can either indicate total success of an operation, indicate failure and the nature of the cause, or indicate some more complex status. Total success is always indicated by NASD_SUCCESS, which is guaranteed to be zero.

The function nasd_error_string() takes such a value as input, and returns a string describing the error code verbally. This function violates the normal NASD convention that all exported functions return nasd_status_t because it is expected that its primary use will be calls within calls to printf(). This function is always guaranteed to return a valid C string, but if the input value is garbage, the string may be uninformative.

For example:

{
  nasd_something_t thing;
  nasd_status_t rc;
  nasd_len_t len;

  /* ... */

  rc = nasd_init_something(&thing, len);
  if (rc == NASD_NO_MEM) {
    printf("ERROR: Out of memory initting thing\n");
    exit(1);
  }
  else if (rc == NASD_BAD_LEN) {
    printf("ERROR: Bad length initting thing\n");
    exit(1);
  }
  else if (rc) {
    printf("ERROR: Got 0x%x (%s) initting thing\n",
      rc, nasd_error_string(rc));
    exit(1);
  }
  
  
  
}

Adding new result codes

Understanding nasd_error.idl

Result codes are defined in include/nasd/nasd_error.idl. The result codes are broken into several ranges (note that these ranges may be redefined without warning; users of the API are not guaranteed that these ranges are meaningful):
RangeReserved for
0.999Codes that may be returned by drive operations
1000.4999Errors returned by local libraries or modules
5000.9999Errors returned by modules within the drive
(code outside the drive should never see or use these)
10000+Reserved for filesystems and applications built on NASD

Error codes are added as follows:

const nasd_int32 NASD_DEAD_WEASEL       = 1392; /* the weasel has died */

nasd_error.c

After defining a new result code in nasd_error.idl, it is important to make nasd_error_string() aware of how to translate this error to informative text. Do this by adding a translation entry to the location within nasd_error_string() (found in common/nasd_error.c which corresponds to the same ordering and location your new error code occupies in nasd_error.idl. For example:     KASE(NASD_DEAD_WEASEL,"The weasel has passed on")
<--- ---> ^<br>|<br>|
Output Modules NASD Programmer's Documentation