00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <stdio.h>
00019 #include <time.h>
00020 #include <errno.h>
00021 #include <string.h>
00022 #include <sys/types.h>
00023 #include <sys/stat.h>
00024 #include <fcntl.h>
00025 #include <unistd.h>
00026 #include <stdlib.h>
00027 #include "RioInterfaceTypes.h"
00028 #include "ObjectInfo.h"
00029 #include "ObjMapMgr.h"
00030 #include "ServerTypes.h"
00031
00032 const char *TypesObject[] = { "Objeto invalido", "Diretorio", "Dados",
00033 "Link de dados", "Link de diretorio",
00034 "Link quebrado", "Tipo invalido" };
00035
00036 #define PADSIZE 7
00037 #define MD5SUMSIZE 16
00038
00039 int main( int argc, char *argv[] )
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
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
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
00092 NumBlocos = Header.nRep * Header.nBlocks;
00093
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 }