Baixe o app para aproveitar ainda mais
Esta é uma pré-visualização de arquivo. Entre para ver o arquivo original
Inode/Bloco.h Bloco *setQtdBlocos(int &QTD) { int i; Bloco *B; while(QTD>1000 || QTD<1) { fflush(stdin); printf("DIGITE A QUANTIDADE DE BLOCOS DO DISCO\n"); scanf("%d",&QTD); if(QTD>1000 || QTD<1) printf("QUANTIDADE INVALIDA\n"); } printf("\n\n"); B = new Bloco[QTD]; for(i = 0; i<QTD; i++) B[i].status = 'F'; inicializa(P); for(i = QTD-1; i>=0; i--) push(P,i); return B; } void recPerdidos(int TL, int vetAux[]) { Diretorio D; if(TL==1) { int i,aux,k; char cd[50], auxS[100]; aux = C.caminho; strcpy(auxS,C.nome); D = B[B[C.caminho].I.pont[0]].D; for(i=2; i<D.TL; i++) { if(B[D.entrada[i]].status != 'B') { vetAux[D.entrada[i]] = 0; iNodeP I = B[D.entrada[i]].I; for(k=0;k<I.TL;k++) { if(B[I.pont[k]].status != 'B') vetAux[I.pont[k]] = 0; } if(B[D.entrada[i]].status == 'D') { strcpy(cd, "cd "); strcat(cd,D.nomes[i]); verificaComando(cd); recPerdidos(TL,vetAux); } strcpy(C.nome,auxS); C.caminho = aux; } } } } int procuraD(char nome[]) { int i,n; for(i = 0; i<QTD; i++) { if(stricmp(B[i].I.nome,nome) == 0) return i; } } Inode/Diretorio.h Diretorio NewDir(int atual, int pai) { Diretorio D2; D2.entrada[0] = atual; D2.entrada[1] = pai; strcpy(D2.nomes[0],"."); strcpy(D2.nomes[1],".."); D2.TL = 2; return D2; } void criaRaiz(char nome[]) { int livre = pop(P), dir; B[livre].status = 'A'; B[livre].D = NewDir(livre, -1); dir = livre; livre = pop(P); sprintf(data, "%02d/%02d/%04d",hl->tm_mday, hl->tm_mon + 1, hl->tm_year + 1900); sprintf(hora, "%02d:%02d",hl->tm_hour,hl->tm_min); B[livre].I = NewIP(data, hora, 10, "R W E", nome, dir); B[livre].status = 'D'; strcpy(C.nome,nome); C.caminho = livre; //C.TL++; } void listaBlocos() { Diretorio D; iNodeP I; int i,j; D = B[B[C.caminho].I.pont[0]].D; printf("\n\n"); for(i=2; i<D.TL; i++) { if(B[D.entrada[i]].status != 'B') { printf("[%c] %s ",B[D.entrada[i]].status,D.nomes[i]); I = B[D.entrada[i]].I; for(j=0;j<I.TL;j++) { if(j<I.TL-1) printf("%d-",I.pont[j]); else printf("%d",I.pont[j]); } printf("\n"); } } } void listaTree() { char aux[50]; int j,i; Diretorio D = B[B[C.caminho].I.pont[0]].D; printf("\n"); for(i = 2, j=0; i<D.TL; i++) { for(j=0;j<ident;j++) printf(" "); printf(D.nomes[i]); printf("\n"); } printf("\n"); } void listaDir() { char aux[50]; int j,i; Diretorio D = B[B[C.caminho].I.pont[0]].D; printf("\n"); for(i = 2, j=0; i<D.TL; i++) { if(B[D.entrada[i]].status != 'B') { strcpy(aux,B[D.entrada[i]].I.data); LsAll(D.nomes[i],20 - strlen(D.nomes[i])); j++; if(j==4) { printf("\n"); j = 0; } } } printf("\n"); } void listaDir2() { char aux[50]; Diretorio D = B[B[C.caminho].I.pont[0]].D; printf("\n\n"); for(int i = 2; i<D.TL; i++) { strcpy(aux,B[D.entrada[i]].I.data); if(B[D.entrada[i]].status == 'D') LsDir(strcat(strcat(aux," "),B[D.entrada[i]].I.hora),D.nomes[i],1); else LsDir(strcat(strcat(aux," "),B[D.entrada[i]].I.hora),D.nomes[i],2); } } void listaStatus() { char aux[50]; int flag,j; Diretorio D = B[B[C.caminho].I.pont[0]].D; printf("\n\n"); for(int i = 0; i<D.TL; i++) { if(B[D.entrada[i]].status == 'I') { flag = 0; for(j=0; j < B[D.entrada[i]].I.TL; j++) { if(B[B[D.entrada[i]].I.pont[j]].status == 'B') flag = 1; } if(flag == 0) alinhado(B[D.entrada[i]].I.nome,"NORMAL"); else alinhado(B[D.entrada[i]].I.nome,"CORROMPIDO"); } } } void criaDiretorio(char nome[]) { int livre = pop(P), dir, endAt; B[livre].status = 'A'; B[livre].D = NewDir(livre,C.caminho); dir = livre; livre = pop(P); sprintf(data, "%02d/%02d/%04d",hl->tm_mday, hl->tm_mon + 1, hl->tm_year + 1900); sprintf(hora, "%02d:%02d",hl->tm_hour,hl->tm_min); B[livre].I = NewIP(data, hora, 10, "R W E", nome, dir); B[livre].status = 'D'; endAt = B[C.caminho].I.pont[0]; strcpy(B[endAt].D.nomes[B[endAt].D.TL],nome); B[endAt].D.entrada[B[endAt].D.TL] = livre; B[endAt].D.TL++; } void criaArquivo(char nome[50], int tam) { int livre,endAt; livre = pop(P); sprintf(data, "%02d/%02d/%04d",hl->tm_mday, hl->tm_mon + 1, hl->tm_year + 1900); sprintf(hora, "%02d:%02d",hl->tm_hour,hl->tm_min); B[livre].status = 'I'; B[livre].I = NewIP(data,hora,10,"R W E",nome); for(int i =0; i<tam; i++) { addBloco(livre); } endAt = B[C.caminho].I.pont[0]; strcpy(B[endAt].D.nomes[B[endAt].D.TL],nome); B[endAt].D.entrada[B[endAt].D.TL] = livre; B[endAt].D.TL++; } void removeEntrada(int pos) { int i=0; int endAt = B[C.caminho].I.pont[0]; while(i<B[endAt].D.TL && B[endAt].D.entrada[i] != pos) i++; while(i<B[endAt].D.TL-1) B[endAt].D.entrada[i] = B[endAt].D.entrada[i+1]; B[endAt].D.TL--; } int getEntrada(char nome[]) { int achou = 0,i; Diretorio D = B[B[C.caminho].I.pont[0]].D; for(i=0;i<D.TL && achou==0;i++) { if(stricmp(D.nomes[i],nome)==0 && B[D.entrada[i]].status != 'B') achou=1; } if(achou == 1) return D.entrada[i-1]; return -1; } int tamArquivo(char nome[]) { int pos = getEntrada(nome); if(pos!=-1) return B[pos].I.TL; return -1; } int removeArquivo(char nome[]) { int pos = getEntrada(nome),i; if(pos != -1) { for( i = 0; i < B[pos].I.TL; i++) { B[B[pos].I.pont[i]].status = 'F'; push(P,B[pos].I.pont[i]); } B[pos].status = 'F'; removeEntrada(B[pos].I.pont[i]); return 1; } else return -1; } int buscaDiretorio(char caminho[]) { char path[100]; int i; strcpy(path,""); i = getEntrada(caminho); if(i != -1 && strcmp(caminho,".") != 0 && B[i].status == 'D') { C.caminho = i; if(strcmp(caminho,"..") == 0) { //char **ant = split(C.nome,'\\'); //int TL2 = matLength(ant); int TL = strlen(C.nome); int i = TL-1; while(i >= 0 && C.nome[i] != '\\') i--; C.nome[i] = '\0'; //for(i=0;i<=TL2-2;i++) //{ //strcat(path,ant[i]); //if(i+1 <= TL2-2) //strcat(path,"\\"); //} //strcpy(C.nome,path); //delete(ant); } else { strcat(C.nome,"\\"); strcat(C.nome,B[i].I.nome); } return 1; } else { printf("DIRETORIO INEXISTENTE\n\n"); return -1; } } Inode/Funcoes.hvoid exibeDisco() { for(int i=0; i<QTD; i++) { if(i%35 == 0) printf("\n"); if(B[i].status == 'B') textcolor(12); else if(B[i].status == 'A') textcolor(15); else if(B[i].status == 'D' || B[i].status == 'I') textcolor(9); printf("%c ",B[i].status); textcolor(7); } printf("\n\n"); } void listaComandos() { printf("\n\n- COMANDOS:\n"); alinhado("BAD [NUMERO]","DANIFICA BLOCO ESCOLHIDO"); alinhado("DISC","EXIBE SITUACAO ATUAL DO DISCO"); alinhado("CLEAR","LIMPA A TELA"); alinhado("HELP","EXIBE LISTA DE COMANDOS"); alinhado("LS","LISTA ARQUIVOS E DIRETORIOS DO CAMINHO ATUAL"); alinhado("MKDIR [NOME]","CRIA DIRETORIO NO CAMINHO FORNECIDO"); alinhado("CAT [NOME] [TAMANHO]","CRIA ARQUIVO NO CAMINHO FORNECIDO"); alinhado("REMOVE [NOME]","REMOVE ARQUIVO DO CAMINHO ATUAL"); alinhado("SIZEOF [NOME]","EXIBE TAMANHO DO ARQUIVO NO DIRETORIO ATUAL"); alinhado("MAXSIZE","EXIBE TAMANHO DO MAIOR AQUIVO QUE PODE SER CRIADO"); alinhado("TREE","DESENHA A ARVORE DE DIRETORIOS A PARTIR DO CAMINHO ATUAL"); printf("\n\n"); } int verificaComando(char frase[100]) { char **args; int num,flag=0; int TL, ret; args = split(frase, ' '); TL = matLength(args); //--------------------------------------------------------------- if(strcmp(frase,"") == 0) flag=1; if(flag==0 && stricmp(args[0],"bad") == 0) { num = getArgs(args[1]); if(num<QTD && num>=0) { B[num].status = 'B'; printf("BLOCO %d DANIFICADO COM SUCESSO\n\n",num); } else printf("BLOCO INEXISTENTE\n\n"); flag=1; } //--------------------------------------------------------------- if(flag==0 && stricmp(args[0],"disc") == 0) { exibeDisco(); flag=1; } //--------------------------------------------------------------- if(flag==0 && (stricmp(args[0],"clear") == 0 || stricmp(args[0],"cls") == 0)) { clrscr(); flag=1; } //--------------------------------------------------------------- if(flag==0 && (stricmp(args[0],"help") == 0 || stricmp(args[0],"hlp") == 0)) { listaComandos(); flag=1; } //--------------------------------------------------------------- if(flag==0 && stricmp(args[0],"mkdir") == 0) { int i,aux,t = 1; char **nome, cd[50], auxS[100]; nome = split(args[1],'/'); TL = matLength(nome); aux = C.caminho; strcpy(auxS,C.nome); for(i=0; i<TL-1 && t == 1; i++) { strcpy(cd,"cd "); strcat(cd,nome[i]); t = verificaComando(cd); } if(t==1) criaDiretorio(nome[i]); strcpy(C.nome,auxS); C.caminho = aux; flag = 1; } //--------------------------------------------------------------- if(flag==0 && stricmp(args[0],"cd") == 0) { if(TL == 2) { int i; char **caminho = split(args[1],'//'); int tam = matLength(caminho); for(i=0;i<tam;i++) ret = buscaDiretorio(caminho[i]); flag = 1; } } //--------------------------------------------------------------- if(flag==0 && stricmp(args[0],"ls") == 0) { if(TL == 1) listaDir(); else if(TL == 2 && stricmp(args[1],"-status") == 0) listaStatus(); else if(TL == 2 && stricmp(args[1],"-a") == 0) listaAtributos(); else if(TL == 2 && stricmp(args[1],"-b") == 0) listaBlocos(); flag = 1; printf("\n\n"); } //--------------------------------------------------------------- if(flag==0 && stricmp(args[0],"cat") == 0) { if(TL==3) { int i,aux,t = 1,tam; char **nome, cd[50], auxS[100]; nome = split(args[1],'//'); TL = matLength(nome); aux = C.caminho; strcpy(auxS,C.nome); for(i=0; i<TL-1 && t == 1; i++) { strcpy(cd,"cd "); strcat(cd,nome[i]); t = verificaComando(cd); } if(t == 1) { tam = getArgs(args[2]); criaArquivo(nome[i],tam/10); } strcpy(C.nome,auxS); C.caminho = aux; flag = 1; } else { printf("PARAMETROS INCORRETOS\n\n"); } flag = 1; } //--------------------------------------------------------------- if(flag==0 && stricmp(args[0],"remove") == 0) { if(TL==2) { if(removeArquivo(args[1]) == -1) printf("ARQUIVO INEXISTENTE\n\n"); } flag = 1; } //--------------------------------------------------------------- if(flag==0 && stricmp(args[0],"sizeof") == 0) { if(TL==2) { int n = tamArquivo(args[1]); if(n!=-1) printf("BYTES: %d BLOCOS: %d\n\n",10*n,n); else printf("ARQUIVO INEXISTENTE\n\n"); flag = 1; } } //--------------------------------------------------------------- if(flag==0 && stricmp(args[0],"maxsize") == 0) { if(TL==1) { printf("BYTES: %d BLOCOS: %d\n\n",P.cont*10,P.cont); flag = 1; } } //--------------------------------------------------------------- if(flag==0 && stricmp(args[0],"maxsize") == 0) { if(TL==1) { printf("BYTES: %d BLOCOS: %d\n\n",P.cont*10,P.cont); flag = 1; } } //--------------------------------------------------------------- if(flag==0 && stricmp(args[0],"tree") == 0) { if(ident == 0) printf("\n\n"); Diretorio D; if(TL==1) { ident++; int i,aux; char cd[50], auxS[100]; aux = C.caminho; strcpy(auxS,C.nome); D = B[B[C.caminho].I.pont[0]].D; for(i=2; i<D.TL; i++) { if(B[D.entrada[i]].status != 'B') { if (i == 2) fident = 0; if(i == D.TL-1) fident = 2; else fident = 1; for(int k=0; k<ident;k++) { if(k == ident-1 && fident == 1) printf(" %c%c%c%c",195,196,196,196); else if(k == ident-1) printf(" %c%c%c%c",192,196,196,196); else printf(" %c",179); } printf("%s\n",D.nomes[i]); if(B[D.entrada[i]].status == 'D') { strcpy(cd, "cd "); strcat(cd,D.nomes[i]); verificaComando(cd); verificaComando("tree"); } strcpy(C.nome,auxS); C.caminho = aux; } } flag = 1; ident--; } if(ident == 0) printf("\n\n"); } if(flag==0 && stricmp(args[0],"lose") == 0) { int vetAux[QTD], k; vetAux[0] = vetAux[1] = 0; for(int i=2; i<QTD;i++) { if(B[i].status == 'F' || B[i].status == 'B') vetAux[i] = 0; else vetAux[i] = 1; } recPerdidos(TL, vetAux); printf("\n\n"); for(int i=0, k=-1; i<QTD;i++) { if(vetAux[i] == 1) { printf("%02d ",i); k++; if(k == 10) { printf("\n"); k=-1; } } } printf("\n\n"); flag = 1; } /*if(flag==0 && stricmp(args[0],"link") == 0) { if(stricmp(args[1],"-f") == 0) { int inode,aux,tam; char cd[50], auxS[100]; char **nome = split(args[2],'//'); tam = matLength(nome); aux = C.caminho; strcpy(auxS,C.nome); strcpy(cd,"cd "); strcat(cd,args[2]); verificaComando(cd); inode = C.caminho; strcpy(C.nome,auxS); C.caminho = aux; Diretorio D = B[B[C.caminho].I.pont[0]].D; strcpy(B[B[C.caminho].I.pont[0]].D.nomes[D.TL],nome[tam-1]); B[B[C.caminho].I.pont[0]].D.entrada[D.TL] = inode; B[B[C.caminho].I.pont[0]].D.TL++; flag = 1; } }*/ //--------------------------------------------------------------- if(flag==0) { printf("COMANDO DESCONHECIDO\n\n"); return 0; } else return ret; //--------------------------------------------------------------- delete args; } Inode/iNodeP.h iNodeP NewIP(char dt[30], char hor[10], int tam, char perm[30], char nome[50]) { iNodeP I; strcpy(I.data,dt); strcpy(I.hora,hor); I.tamanho = tam; strcpy(I.permissao,perm); strcpy(I.nome,nome); I.TL = 0; return I; } iNodeP NewIP(char dt[30], char hor[10], int tam, char perm[30],char nome[], int bloco) { iNodeP I; strcpy(I.data,dt); strcpy(I.hora,hor); I.tamanho = tam; strcpy(I.permissao,perm); I.pont[0] = bloco; I.TL = 1; strcpy(I.nome,nome); return I; } void addBloco(int livre) { int pos = pop(P); B[livre].I.pont[B[livre].I.TL] = pos; B[pos].status = 'A'; B[livre].I.TL++; } void exibeInfoIP(iNodeP I) { printf("Data: %s\nHora: %s\nTamanho: %d\nPermissoes: %s\nPonteiro: %d",I.data,I.hora,I.tamanho,I.permissao,I.pont[0]); printf("\n\n"); } Inode/iNodeS.h#include <string.h> #include <conio2.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <ctype.h> #include <time.h> char **split(char frase[100], char C); int matLength(char **mat); void LsDir(char arg[], char descr[],int flag); void alinhado(char arg[], char descr[]); void LsAll(char nome[], int esp); int verificaComando(char frase[100]); char data[20]; char hora[10]; struct Diretorio { char nomes[50][19]; int entrada[50]; int TL; }; struct No { int end; No *prox; }; struct Pilha { No *topo; int cont; }; struct Path { int caminho;//N PODE char nome[100]; }; struct iNodeS { int pont[5]; }; struct iNodeP { char nome[50]; char data[30]; char hora[10]; int tamanho; char permissao[10]; int pont[8]; int TL; }; struct Bloco { iNodeP I; iNodeS IS; Diretorio D; int dado[5]; char status; }; Pilha P; Bloco *B; Path C; int QTD; int ident = 0; int fident = 0; struct tm *hl; time_t hr; Inode/Pilha.h void inicializa(Pilha &P) { P.cont=0; P.topo = NULL; } No *novaCaixa(int end) { No *nc = new No; nc->end = end; nc->prox = NULL; return nc; } void push(Pilha &P,int end) { No *nc = novaCaixa(end); nc->prox = P.topo; P.topo = nc; P.cont ++; } int pop(Pilha &P) { int end = P.topo->end; No *nc = P.topo; P.topo = P.topo->prox; free(nc); P.cont--; return end; } Inode/Utilitarios.hvoid listaComandos(); void exibeDisco(); void listaAtributos() { printf("\n\n"); int i; Diretorio D = B[B[C.caminho].I.pont[0]].D; for(i=2; i<D.TL; i++) { if(B[D.entrada[i]].status != 'B') { if(B[D.entrada[i]].status == 'D') printf("%s %s %s %s 4096\n",B[D.entrada[i]].I.permissao, B[D.entrada[i]].I.nome, B[D.entrada[i]].I.data, B[D.entrada[i]].I.hora); else printf("%s %s %s %s %d\n",B[D.entrada[i]].I.permissao,B[D.entrada[i]].I.nome, B[D.entrada[i]].I.data, B[D.entrada[i]].I.hora,B[D.entrada[i]].I.tamanho); } } } void alinhado(char arg[], char descr[]) { int esp = 21 - strlen(arg); printf("%s",arg); for(int i=0; i<esp; i++) printf(" "); printf("%s\n",descr); } void LsDir(char arg[], char descr[],int flag) { int esp = 25 - strlen(arg); printf("%s",arg); for(int i=0; i<esp; i++) { if(i==esp/2 && flag==1) printf("<DIR>"); else if(i==esp/2 && flag==2) printf("<ARQ>"); printf(" "); } printf(" "); printf("%s\n",descr); } void LsAll(char nome[], int esp) { int i; printf("%s",nome); for(i=0;i<esp;i++) printf(" "); } char *getComando(char frase[]) { int i=0; char comando[100]; strcpy(comando,frase); while(i<100 && comando[i]!=' ' && comando[i]!='\0') {i++;} comando[i] = '\0'; return comando; } int getArgs(char frase[]) { int i=0,j,k; int num=0, flag=0; for(i=strlen(frase)-1,j=1; i>=0 && flag == 0;i--,j*=10) { if(isdigit(frase[i])) num+=(frase[i]-48)*j; else flag = 1; } if(flag==0) return num; else return -1; } char *getArgsS(char frase[100]) { int i=0,j,k; char comando[100],aux[100]; int num=0, flag=0; strcpy(comando,frase); while(i<100 && comando[i]!=' ' && comando[i]!='\0') {i++;} for(j = i+1, k=0; j<100 && comando[j]!='\0'; j++, k++) { aux[k] = comando[j]; } aux[k] = '\0'; return aux; } int matLength(char **mat) { int k=0; for(int i=0;i<50;i++) { if(mat[i][0]!='\0') k++; } return k; } char **split(char frase[100], char C) { int fim = 0,k=0,j=0,i=0; char **mat = new char*[50]; for(int s=0;s<50;s++) { mat[s] = new char; mat[s][0]='\0'; } while(fim==0) { while(i<strlen(frase) && frase[i]!=C && frase[i]!='\0') { if(frase[i]!=' ') mat[k][j] = frase[i]; i++; j++; } mat[k][j] = '\0'; while(frase[i]==C) i++; k++; j=0; if(frase[i]=='\0') fim=1; } return mat; } Inode/TrabSOII.cpp#include "iNodeS.h" #include "Pilha.h" #include "iNodeP.h" #include "Bloco.h" #include "Diretorio.h" #include "Utilitarios.h" #include "Funcoes.h" int main() { time(&hr); hl = localtime(&hr); char **mat; char comando[100]; B = setQtdBlocos(QTD); criaRaiz("caiocarneloz@caiocarneloz:/$"); clrscr(); printf("\t BEM VINDO AO SIMULADOR DE SISTEMAS DE ARQUIVO iNODE\n\t\t\t"); printf("POR CAIO CARNELOZ E NAYARA MAIORANO\n\t\t\t DIGITE HELP PARA MAIS INFORMACOES\n\n"); fflush(stdin); verificaComando("mkdir Caio"); verificaComando("cd Caio"); verificaComando("cat trabSOII.c 80"); verificaComando("cd .."); verificaComando("mkdir Robson"); verificaComando("mkdir Robson/Provas"); verificaComando("cat arq.txt 80"); verificaComando("cd Robson"); verificaComando("cat jogo.exe 80"); verificaComando("cd Provas"); verificaComando("cat doc1.inf 80"); verificaComando("cat doc2.inf 80"); verificaComando("cat doc3.inf 80"); verificaComando("cat doc4.inf 80"); verificaComando("cd .."); verificaComando("cd .."); while(1) { printf("%s ",C.nome); verificaComando(gets(comando)); } }
Compartilhar