#include <stdio.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include "RioInterfaceTypes.h"
#include "ObjectInfo.h"
#include "ObjMapMgr.h"
#include "ServerTypes.h"
Go to the source code of this file.
Defines | |
#define | PADSIZE 7 |
#define | MD5SUMSIZE 16 |
Functions | |
int | main (int argc, char *argv[]) |
Variables | |
const char * | TypesObject [] |
#define MD5SUMSIZE 16 |
Definition at line 37 of file readMetaData.cpp.
#define PADSIZE 7 |
Definition at line 36 of file readMetaData.cpp.
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 39 of file readMetaData.cpp.
00040 { 00041 int j, HandleArq, NumLidos; 00042 unsigned int i, NumBlocos; 00043 short TipoObjeto; 00044 struct ObjectHeader Header; 00045 struct tm *UltimaEscrita; 00046 struct RioDiskBlock *Blocos; 00047 char StrUltimaEscrita[ 80 ]; 00048 00049 if( argc < 2 ) 00050 { 00051 printf( "Sinate: %s <nome arquivo>.\n", argv[ 0 ] ); 00052 return 1; 00053 } 00054 00055 HandleArq = open( argv[ 1 ], O_RDONLY, 0 ); 00056 00057 if( HandleArq == -1 ) 00058 { 00059 printf("Erro ao abrir o arquivo %s: %d - %s.\n", argv[ 1 ], errno, 00060 strerror(errno)); 00061 return 1; 00062 } 00063 00064 /* Le o cabecalho. */ 00065 NumLidos = read( HandleArq, &Header, sizeof( struct ObjectHeader ) ); 00066 if( NumLidos == -1 ) 00067 { 00068 printf( "Erro %d (%s) ao ler o arquivo %s.\n", errno, strerror( errno ), 00069 argv[ 1 ] ); 00070 close( HandleArq ); 00071 return 1; 00072 } 00073 00074 if( ( unsigned int ) NumLidos != sizeof( struct ObjectHeader ) ) 00075 { 00076 printf( "Erro ao ler o arquivo %s: lidos %d bytes (esperado %lu bytes).\n", 00077 argv[ 1 ], NumLidos, ( ( unsigned long ) 00078 sizeof( struct ObjectHeader ) ) ); 00079 close( HandleArq ); 00080 return 1; 00081 } 00082 00083 /* Verifica se e um objeto do servidor RIO. */ 00084 if( strncmp( ObjectSignatureValue, Header.Signature, 8 ) != 0 ) 00085 { 00086 printf( "O tipo do arquivo %s nao e valido.\n", argv[ 1 ] ); 00087 close( HandleArq ); 00088 return 1; 00089 } 00090 00091 /* Le os blocos do disco. */ 00092 NumBlocos = Header.nRep * Header.nBlocks; 00093 /* Aloca memoria para os blocos. */ 00094 Blocos = ( struct RioDiskBlock * ) malloc( NumBlocos * 00095 sizeof( struct RioDiskBlock ) ); 00096 if( Blocos == NULL ) 00097 { 00098 printf( "Memoria insuficiente para ler os blocos do arquivo %s.\n", 00099 argv[ 1 ] ); 00100 close( HandleArq ); 00101 return 1; 00102 } 00103 00104 NumLidos = read( HandleArq, Blocos, NumBlocos * 00105 sizeof( struct RioDiskBlock ) ); 00106 close( HandleArq ); 00107 if( NumLidos == -1 ) 00108 { 00109 printf( "Erro %d (%s) ao ler o arquivo %s.\n", errno, strerror( errno ), 00110 argv[ 1 ] ); 00111 free( Blocos ); 00112 return 1; 00113 } 00114 if( ( unsigned int ) NumLidos != NumBlocos * sizeof( struct RioDiskBlock ) ) 00115 { 00116 printf( "Erro ao ler o arquivo %s: lidos %d bytes (esperado %lu bytes).\n", 00117 argv[ 1 ], NumLidos, ( unsigned long ) ( NumBlocos * 00118 sizeof( struct RioDiskBlock ) ) ); 00119 free( Blocos ); 00120 return 1; 00121 } 00122 00123 printf( "Arquivo %s:\n", argv[ 1 ] ); 00124 TipoObjeto = Header.Type; 00125 if( TipoObjeto > 6 ) 00126 TipoObjeto = 6; 00127 printf( "-Tipo do objeto: %d (%s)\n", Header.Type, 00128 TypesObject[ TipoObjeto ] ); 00129 UltimaEscrita = localtime( &Header.LastWrite ); 00130 strftime( StrUltimaEscrita, sizeof( StrUltimaEscrita ), 00131 "%a %d-%m-%Y %H:%M:%S %Z", UltimaEscrita ); 00132 printf( "-Tempo da ultima alteracao: %s\n", StrUltimaEscrita ); 00133 printf( "-Numero de replicacoes: %d\n", Header.nRep ); 00134 printf( "-Tamanho dos blocos: %u\n", Header.BlockSize ); 00135 printf( "-Numero de blocos: %u\n", Header.nBlocks ); 00136 printf( "-Tamanho do objeto: %lld\n", Header.Size ); 00137 printf( "-Taxa de transmissao do video: %u\n", Header.VideoRate ); 00138 printf( "-Valor da variavel booleana nullmd5: %s\n", 00139 Header.nullmd5 ? "true" : "false" ); 00140 printf( "-Valor do MD5 (em hexa): " ); 00141 for( i = 0; i < MD5SUMSIZE; i++ ) 00142 printf( "%02x", Header.md5sum[ i ] ); 00143 printf( "\n" ); 00144 printf( "-Valor do campo pad (%u bytes): ", PADSIZE ); 00145 for( i = 0; i < PADSIZE; i++ ) 00146 { 00147 printf( "%02X", Header.pad[ i ] ); 00148 if( i < PADSIZE - 1 ) 00149 printf( ", " ); 00150 else 00151 printf( "\n" ); 00152 } 00153 printf( "-Blocos logicos do disco: [replica: (disco, bloco)]\n" ); 00154 for( i = 0; i < Header.nBlocks; i++ ) 00155 { 00156 printf( "--Bloco logico %u: ", i+1 ); 00157 for( j = 0; j < Header.nRep; j++ ) 00158 { 00159 printf( "%d: (%d, %u)", j+1, Blocos[ i*Header.nRep+j ].disk, 00160 Blocos[ i*Header.nRep+j ].block ); 00161 if( j < Header.nRep - 1 ) 00162 printf( ", " ); 00163 else 00164 printf( "\n" ); 00165 } 00166 } 00167 free( Blocos ); 00168 return 0; 00169 }
const char* TypesObject[] |
{ "Objeto invalido", "Diretorio", "Dados", "Link de dados", "Link de diretorio", "Link quebrado", "Tipo invalido" }
Definition at line 32 of file readMetaData.cpp.