Riferimenti per il file sfat_ls.c

#include "Include/common.h"

Vai al codice sorgente di questo file.

Funzioni

static void byebye ()
int main (int argc, char **argv)

Variabili

message_t msg
channel_t sk_client
char * path

Descrizione dettagliata

Autore:
Tranchida Giulio, No Matricola 241732
Si dichiara che il contenuto di questo file e', in ogni sua parte, opera originale dell'autore.

This program is free software; you can redistribuite it and/or modify it under the terms of the GNU/General Pubblic License as published the Free software Foundation; either version 2 of the License, or (at your opinion) any later version.

Definizione nel file sfat_ls.c.


Documentazione delle funzioni

void byebye (  )  [static]

exit function

Definizione alla linea 90 del file sfat_ls.c.

00090              {
00091         extern message_t msg;
00092         extern char * path;
00093         extern channel_t sk_client;
00094         
00095         /* Chiudo la socket di comunicazione del client */
00096         if (sk_client != -1) closeConnection(sk_client);
00097                         
00098         if (msg.buffer!=NULL) free(msg.buffer);
00099         if (path!=NULL) free(path);
00100 }

int main ( int  argc,
char **  argv 
)

Sfat ls

Comando: sfat_ls path

stampa il listing di tutti i file e le directory i "path", separati da TAB. All'invocazione il client controlla i parametri e contatta il server inviando una richiesta di connessione sul socket.
Se la connessione ha successo il client invia una richiesta di MSG_LS.
Tutti gli errori sono riportati sullo standar error.

Definizione alla linea 31 del file sfat_ls.c.

00031                                {
00032         extern message_t msg;
00033         extern channel_t sk_client;
00034         extern char * path;
00035         
00036         sk_client = 0;
00037         path = NULL;
00038         msg.buffer = NULL;
00039         
00040         if ((atexit(byebye))!=0){
00041                 errore(__FILE__,__LINE__,"sfat_ls: cannot set exit function",errno);
00042                 exit(EXIT_FAILURE);
00043         }
00044         
00045         /* Argomenti da riga di comando */
00046         if (argc<2){
00047                 fprintf(stderr,
00048                 "sfat_ls: errore nome cartella su cui listare mancante\n");
00049                 exit(EXIT_FAILURE);
00050         }
00051         
00052         if (!(path = calloc((strlen(TMP) + strlen(SKTNAME) + 1), sizeof(char)))){
00053                 errore(__FILE__,__LINE__,
00054                 "sfat_ls: error on allocate memory for 'path'",errno);
00055                 exit(EXIT_FAILURE);
00056         }
00057         strncpy(path,TMP,strlen(TMP));
00058         strncat(path,SKTNAME,strlen(SKTNAME));
00059 
00060         /* Apro la socket di comunicazione col server */
00061         if ((sk_client = openConnection(path)) == -1) {
00062                 fprintf(stderr,"sfat_ls: Errore nella apertura del socket di comunicazione\n");
00063                 exit(EXIT_FAILURE);
00064         }
00065         else if (sk_client == SFATENAMETOOLONG){
00066                 fprintf(stderr,"sfat_ls: Error Path Too Long (exceeding UNIX_PATH_MAX)\n");     
00067                 exit(EXIT_FAILURE);
00068         }
00069         
00070         msg.type = MSG_LS;
00071         msg.length = strlen(argv[1])+1;
00072         if (!(msg.buffer = strdup(argv[1]))){
00073                 errore(__FILE__,__LINE__,
00074                 "sfat_ls: error on allocate memory for 'buffer'",errno);
00075                 exit(EXIT_FAILURE);
00076         }       
00077         if (sendMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE);
00078         if (receiveMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE);
00079         
00080         if (msg.type==MSG_OK){
00081                 printf("sfat_ls: listing %s\n", argv[1]);
00082                 if (msg.buffer!=NULL) printf(" %s\n", msg.buffer);
00083         }
00084         else exit(EXIT_FAILURE);
00085         
00086         exit(EXIT_SUCCESS);
00087         return 0;
00088 }


Documentazione delle variabili

struttura rappresentante un messaggio tra client e server

Definizione alla linea 18 del file sfat_ls.c.

tipo descrittore del canale di comunicazione (server e client)

Definizione alla linea 19 del file sfat_ls.c.

char* path

directory e nome del socket AF_UNIX

Definizione alla linea 20 del file sfat_ls.c.

Generato il Fri Jan 28 22:16:29 2011 per SFAT: Simplified File Allocation Table Project da  doxygen 1.6.3