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 90 del file sfat_mkfile.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 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 34 del file sfat_mkfile.c.

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

tipo descrittore del canale di comunicazione (server e client)

Definizione alla linea 20 del file sfat_mkfile.c.

char* path

directory e nome del socket AF_UNIX

Definizione alla linea 21 del file sfat_mkfile.c.

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