François Gautrais il y a 9 ans
Parent
commit
50b1063f8a
8 fichiers modifiés avec 117 ajouts et 4 suppressions
  1. 1 1
      MakefileRpi
  2. 1 0
      backend.c
  3. 1 0
      backend.h
  4. 16 0
      config.c
  5. 1 1
      config.cfg
  6. 81 0
      mount.c
  7. 3 1
      mount.h
  8. 13 1
      recv.c

+ 1 - 1
MakefileRpi

@@ -1,4 +1,4 @@
-OBJ=bus.o stub.o timer.o recv.o backend.o config.o
+OBJ=bus.o stub.o timer.o recv.o backend.o config.o mount.o
 TARGET=recv
 #CROSS_COMPILE=/home/ptitcois/Programmation/rpi/tools/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-
 CC=$(CROSS_COMPILE)gcc

+ 1 - 0
backend.c

@@ -28,6 +28,7 @@ int do_pid_file(config_t* cfg)
 }
 
 
+
 int main_loop()
 {
 	config_t cfg;

+ 1 - 0
backend.h

@@ -11,6 +11,7 @@
 
 #include "bus.h"
 
+int do_pid_file(config_t* cfg);
 int main_loop();
 
 #endif

+ 16 - 0
config.c

@@ -6,7 +6,23 @@ void config_load_default(config_t *cfg)
 	config_add_int(cfg, "pin.clk", 3); 
 	config_add_int(cfg, "pin.ack", 4);
 	config_add_int(cfg, "cache.size", 4096);
+
+	config_add_string(cfg, "cache.file", "/tmp/compteur_elec.cache");
+	
+	config_add_int(cfg, "mount", 1);
+	config_add_string(cfg, "mount.file", "192.168.0.88");
+	config_add_string(cfg, "mount.src", "//192.168.0.88/nas");
+	config_add_string(cfg, "mount.dst", "/media/nas");
+	config_add_string(cfg, "mount.username", "ptitcois");
+	config_add_string(cfg, "mount.password", "e1010898");
+	
+	config_add_string(cfg, "storage.location", "/media/samba");
+	config_add_string(cfg, "storage.data", "data");
+	config_add_string(cfg, "storage.years", "years");
+	config_add_string(cfg, "storage.monthes", "monthes");
+	config_add_string(cfg, "storage.days", "days");
 	
+	config_add_string(cfg, "misc.pidfile", "/tmp/compteur_elec.cache");
 }
 
 opt_t* _config_get(config_t* cfg, const char* name)

+ 1 - 1
config.cfg

@@ -10,7 +10,7 @@ cache.file="/tmp/compteur_elec.cache";
 #Samba mount
 mount=1;
 mount.ip="192.168.0.88";
-mount.src="\\\\nas\\";
+mount.src="//192.168.0.88/nas";
 mount.dst="/media/samba";
 mount.username="ptitcois";
 mount.password="e1010898";

+ 81 - 0
mount.c

@@ -1 +1,82 @@
 #include "mount.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+
+#include <sys/mount.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <string.h>
+
+int next_word(FILE* f, char* out)
+{
+	int i,c;
+	for(i=0; (c=fgetc(f))!='\t' && c!=' ' && c!='\n' && c!=EOF; i++)
+		out[i]=c;
+	out[i]=0;
+	
+	if(c=='\n') return 1;
+	if(c==' ' || c=='\t') return 0;
+	if(c==EOF) return -1;
+}
+
+int is_mounted(const char* mp)
+{
+	int c=0;
+	char buf[2048];
+	FILE* f = fopen("/proc/mounts", "r");
+	if(!f) 
+	{
+		fprintf(stderr, "Errue unable to open '/proc/mounts' ");
+		perror(" ");
+		return -1;
+	}
+	
+	while(c>=0)
+	{
+		next_word(f, buf);
+		next_word(f, buf);
+		if(!strcmp(buf, mp))
+		{
+			fclose(f);
+			return 1;
+		}
+		while((c=next_word(f, buf))==0);
+	}
+	
+	
+	
+	fclose(f);
+	return 0;
+}
+
+
+
+int mount_samba(config_t* cfg)
+{
+	int tomount=config_get_int(cfg, "mount");
+	char buffer[4096];
+	const char* ip = config_get_string(cfg, "mount.ip");
+	const char* src = config_get_string(cfg, "mount.src");
+	const char* dst = config_get_string(cfg, "mount.dst");
+	const char* username = config_get_string(cfg, "mount.username");
+	const char* password = config_get_string(cfg, "mount.password");
+	
+	if(!tomount) return 0;
+	
+	sprintf(buffer, "unc=%s,ip=%s,username=%s,password=%s", src, ip, username, password); 
+	printf("%s\n", buffer);
+	
+	if(mount(src, dst, "cifs", MS_MGC_VAL | MS_SILENT, buffer))
+	{
+		fprintf(stderr, "Erreur unable to mount : %s\n", strerror(errno));
+		return errno;
+	}
+	return 0;
+}
+
+
+

+ 3 - 1
mount.h

@@ -1,6 +1,8 @@
 #ifndef MOUNT_H
 #define MOUNT_H
 
-
+#include "config.h"
+int is_mounted(const char* mp);
+int mount_samba(config_t* cfg);
 
 #endif

+ 13 - 1
recv.c

@@ -1,9 +1,21 @@
 #include "backend.h"
 #include "config.h"
+#include "mount.h"
 
 
 
 int main()
 {
-	main_loop();
+	config_t c;
+	printf("/ : %d\n\n", is_mounted("/"));
+	printf("/home : %d\n\n", is_mounted("/home"));
+	printf("/existepas : %d\n\n", is_mounted("/existepas"));
+	printf("/dev : %d\n\n", is_mounted("/dev"));
+	config_init(&c, "config.cfg");
+	
+	mount_samba(&c);
+
+	
+	config_free(&c);
+	//main_loop();
 }