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 91 del file sfat_ls.c.

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

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 32 del file sfat_ls.c.

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


Documentazione delle variabili

struttura rappresentante un messaggio tra client e server

Definizione alla linea 19 del file sfat_ls.c.

tipo descrittore del canale di comunicazione (server e client)

Definizione alla linea 20 del file sfat_ls.c.

char* path

directory e nome del socket AF_UNIX

Definizione alla linea 21 del file sfat_ls.c.

Generato il Sat Jan 29 15:05:42 2011 per SFAT: Simplified File Allocation Table Project da  doxygen 1.6.3