Novell Home

NSS13

From Developer Community

This code demonstrates how to get the physical amount of space occupied by a file with NSS APIs (NetWare).

Sample Code

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

static void print64u( unsigned long long x) {
  unsigned long long 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 <filename>n", argv[ 0]);
    return EXIT_FAILURE;
  }
  if (( ccode = zRootKey( 0, &root_key)) != zOK) {
    printf( "zRootKey failed, ccode = %dn", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zBeginTask( root_key, 0, &task_id)) != zOK) {
    zClose( root_key);
    printf( "zBeginTask failed, ccode = %dn", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zOpen( root_key, task_id, zNSPACE_LONG|zMODE_UTF8, argv[ 1],
zRR_READ_ACCESS|zRR_DENY_WRITE|zRR_LEAVE_FILE_COMPRESSED, &file_key)) != zOK) {
    zEndTask( root_key, task_id);
    zClose( root_key);
    printf( "zOpen failed, ccode = %dn", ccode);
    return EXIT_FAILURE;
  }
  printf( "sizeof( zInfo_s) = %un", sizeof( zInfo_s));
  if (( ccode = zGetInfo( file_key, zGET_STORAGE_USED, sizeof( info), zINFO_VERSION_A, &info)) != zOK) {
    zClose( file_key);
    zEndTask( root_key, task_id);
    zClose( root_key);
    printf( "zGetInfo failed, ccode = %dn", ccode);
    return EXIT_FAILURE;
  }
  printf( "info.storageUsed.physicalEOF = ");
  print64u( info.storageUsed.physicalEOF);
  puts( "");
  printf( "info.storageUsed.dataBytes = ");
  print64u( info.storageUsed.dataBytes);
  puts( "");
  printf( "info.storageUsed.metaDataBytes = ");
  print64u( info.storageUsed.metaDataBytes);
  puts( "");
  if (( ccode = zClose( file_key)) != zOK) {
    zEndTask( root_key, task_id);
    zClose( root_key);
    printf( "zClose failed, ccode = %dn", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zEndTask( root_key, task_id)) != zOK) {
    zClose( root_key);
    printf( "zEndTask failed, ccode = %dn", ccode);
    return EXIT_FAILURE;
  }
  if (( ccode = zClose( root_key)) != zOK) {
    printf( "zClose failed, ccode = %dn", ccode);
    return EXIT_FAILURE;
  }
  return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.