Novell Home

NSS14

From Developer Community

This code demonstrates how to get the total number of files on an NSS volume with NSS APIs (NetWare).

Sample Code

#include <stdio.h>
#include <stdlib.h>
#include <zPublics.h>

static void print64u( unsigned __int64 x) {
  unsigned __int64 quot = x / 1000;
  if ( quot != 0) {
    print64u( quot);
    printf( ".%03u", ( unsigned int)( x % 1000));
  }
  else {
    printf( "%u", ( unsigned int)( x % 1000));
  }
}
int main( int argc, char* argv[]) {
  Key_t   root_key;
  NINT    task_id;
  Key_t   file_key;
  zInfo_s info;
  STATUS  ccode;
  if ( argc != 2) {
    printf( "Usage: %s <volname>\n", argv[ 0]);
    return EXIT_FAILURE;
  }
  if (( ccode = zRootKey( 0, &root_key)) != zOK) {
    printf( "zRootKey failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zBeginTask( root_key, 0, &task_id)) != zOK) {
    zClose( root_key);
    printf( "zBeginTask failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zOpen( root_key, task_id, zNSPACE_LONG|zMODE_UTF8, argv[ 1], zRR_READ_ACCESS, &file_key)) != zOK) {
    zEndTask( root_key, task_id);
    zClose( root_key);
    printf( "zOpen failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  printf( "sizeof( zInfo_s) = %u\n", sizeof( zInfo_s));
  if (( ccode = zGetInfo( file_key, zGET_VOLUME_INFO, sizeof( info), zINFO_VERSION_A, &info)) != zOK) {
    zClose( file_key);
    zEndTask( root_key, task_id);
    zClose( root_key);
    printf( "zGetInfo failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  printf( "info.vol.numFiles = ");
  print64u( info.vol.numFiles);
  puts( "");
  if (( ccode = zClose( file_key)) != zOK) {
    zEndTask( root_key, task_id);
    zClose( root_key);
    printf( "zClose failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zEndTask( root_key, task_id)) != zOK) {
    zClose( root_key);
    printf( "zEndTask failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zClose( root_key)) != zOK) {
    printf( "zClose failed, ccode = %d\n", ccode);
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2009 Novell, Inc. All Rights Reserved.