Novell Home

Example of DFSReturnFileMappingInfo()

From Developer Community

This snippet of code demonstrates how to use DFSReturnFileMappingInfo()

Sample Code

#include <fcntl.h>
#include <nwdfs.h>
#include <nwfileng.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define NO_COMPRESSION

int main( int argc, char* argv[]) {
  int handle;
  struct FileMapStructure fmap[ 128];
  LONG starting_block = 0;
  LONG num_of_entries = 0;
  LONG total_blocks = 0;
  if ( argc != 2) {
    printf( "Syntax: %s <filename>", argv[ 0]);
    return EXIT_FAILURE;
  }
#ifdef NO_COMPRESSION
  handle = FEsopen( argv[ 1], O_RDONLY, SH_DENYRW, 0, 0, PrimaryDataStream);
#else
  handle = FEsopen( argv[ 1], O_RDONLY, SH_DENYRW, 0, LEAVE_FILE_COMPRESSED_DATA_BIT | ENABLE_IO_ON_COMPRESSED_DATA_BIT, PrimaryDataStream);
#endif
  if ( handle == -1) {
    perror( "FEsopen");
    return EXIT_FAILURE;
  }
  while ( DFSReturnFileMappingInformation(( LONG) handle, starting_block, &num_of_entries, sizeof( fmap) / sizeof( fmap[ 0]), fmap) == DFSNormalCompletion && num_of_entries != 0) {
    LONG i;
    printf( "num_of_entries = %lu\n", num_of_entries);
    for ( i = 0; i < num_of_entries; ++i) {
      total_blocks += fmap[ i].numberOfBlocks;
    }
    starting_block = fmap[ num_of_entries - 1].fileBlock + fmap[ num_of_entries - 1].numberOfBlocks;
  }
  printf( "total_blocks = %lu\n", total_blocks);
  close( handle);
  return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.