#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 |
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_mkdir.c.
void byebye | ( | ) | [static] |
exit function
Definizione alla linea 92 del file sfat_mkdir.c.
00092 { 00093 extern message_t msg; 00094 extern char * path; 00095 extern channel_t sk_client; 00096 00097 /* Chiudo la socket di comunicazione del client */ 00098 if (sk_client != -1) closeConnection(sk_client); 00099 00100 if (msg.buffer!=NULL) free(msg.buffer); 00101 if (path!=NULL) free(path); 00102 }
int main | ( | int | argc, | |
char ** | argv | |||
) |
Comando: sfat_mkdir dir1/.../dirk/dir
crea una directory "dir" 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_MKDIR.
Tutti gli errori sono riportati sullo standar error.
Definizione alla linea 32 del file sfat_mkdir.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_mkdir: 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_mkdir: errore non e' stato passato alcun nome per la cartella da creare\n"); 00050 exit(EXIT_FAILURE); 00051 } 00052 00053 if (!(path = calloc((strlen(TMP) + strlen(SKTNAME) + 1), sizeof(char)))){ 00054 errore(__FILE__,__LINE__, 00055 "sfat_mkdir: 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 msg.type = MSG_MKDIR; 00062 msg.length = strlen(argv[1])+1; 00063 if (!(msg.buffer = malloc(msg.length))){ 00064 errore(__FILE__,__LINE__, 00065 "sfat_mkdir: error on allocate memory for 'buffer'",errno); 00066 exit(EXIT_FAILURE); 00067 } 00068 memset(msg.buffer, 0x0, msg.length); 00069 /* uso strncat perche' termina la stringa */ 00070 strncat(msg.buffer,argv[1],msg.length); 00071 00072 /* Apro la socket di comunicazione col server */ 00073 if ((sk_client = openConnection(path)) == -1) { 00074 fprintf(stderr,"sfat_read: Errore nella apertura del socket di comunicazione\n"); 00075 exit(EXIT_FAILURE); 00076 } 00077 else if (sk_client == SFATENAMETOOLONG){ 00078 fprintf(stderr,"sfat_read: Error Path Too Long (exceeding UNIX_PATH_MAX)\n"); 00079 exit(EXIT_FAILURE); 00080 } 00081 00082 if (sendMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE); 00083 if (receiveMessage(sk_client, &msg) == -1) exit(EXIT_FAILURE); 00084 if (msg.type==MSG_OK) 00085 printf("sfat_mkdir: %s created!\n", argv[1]); 00086 else exit(EXIT_FAILURE); 00087 00088 exit(EXIT_SUCCESS); 00089 return 0; 00090 }
struttura rappresentante un messaggio tra client e server
Definizione alla linea 17 del file sfat_mkdir.c.
tipo descrittore del canale di comunicazione (server e client)
Definizione alla linea 18 del file sfat_mkdir.c.
char* path |
directory e nome del socket AF_UNIX
Definizione alla linea 19 del file sfat_mkdir.c.