Riferimenti per il file sfat_mkfile.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_mkfile.c.


Documentazione delle funzioni

void byebye (  )  [static]

exit function

Definizione alla linea 89 del file sfat_mkfile.c.

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

int main ( int  argc,
char **  argv 
)

Sfat mkfile

Comando: sfat_mkdir dir1/.../dirk/file

crea un file "file" nella directory "dir1/.../dirk/", se non esiste alcun file o directory con lo stesso nome. Tutte le directory "dir1/.../dirk/" devono esistere.
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_MKFILE.
Tutti gli errori sono riportati sullo standar error.

Definizione alla linea 33 del file sfat_mkfile.c.

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


Documentazione delle variabili

struttura rappresentante un messaggio tra client e server

Definizione alla linea 18 del file sfat_mkfile.c.

tipo descrittore del canale di comunicazione (server e client)

Definizione alla linea 19 del file sfat_mkfile.c.

char* path

directory e nome del socket AF_UNIX

Definizione alla linea 20 del file sfat_mkfile.c.

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