mirror of
https://github.com/vivier/EMILE.git
synced 2024-06-11 12:29:30 +00:00
tools: add tools to set conf path into emiledriver
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
This commit is contained in:
parent
02fdcb3eb4
commit
3be63e7001
|
@ -9,13 +9,14 @@ TOP=$(shell pwd)
|
||||||
PROGRAMS = emile-set-cmdline emile-first-tune emile-install \
|
PROGRAMS = emile-set-cmdline emile-first-tune emile-install \
|
||||||
emile-set-output emile emile-map-set iso9660_ls \
|
emile-set-output emile emile-map-set iso9660_ls \
|
||||||
iso9660_cat minigzip read_vmlinuz emile-mkisofs \
|
iso9660_cat minigzip read_vmlinuz emile-mkisofs \
|
||||||
ext2_ls ext2_cat emile-mktable
|
ext2_ls ext2_cat emile-mktable emile-conf
|
||||||
|
|
||||||
SOURCES = emile-set-cmdline.c Makefile emile-first-tune.c \
|
SOURCES = emile-set-cmdline.c Makefile emile-first-tune.c \
|
||||||
emile-install.c emile-set-output.c emile.c \
|
emile-install.c emile-set-output.c emile.c \
|
||||||
emile_scanbus.c emile-map-set.c iso9660_ls.c \
|
emile_scanbus.c emile-map-set.c iso9660_ls.c \
|
||||||
iso9660_cat.c minigzip.c read_vmlinuz.c device.c gzio.c \
|
iso9660_cat.c minigzip.c read_vmlinuz.c device.c gzio.c \
|
||||||
emile-mkisofs.c ext2_ls.c ext2_cat.c emile-mktable.c
|
emile-mkisofs.c ext2_ls.c ext2_cat.c emile-mktable.c \
|
||||||
|
emile-conf.c
|
||||||
|
|
||||||
HEADERS = device.h
|
HEADERS = device.h
|
||||||
|
|
||||||
|
@ -54,6 +55,7 @@ read_vmlinuz: read_vmlinuz.o gzio.o
|
||||||
|
|
||||||
emile-mkisofs: emile-mkisofs.o device.o
|
emile-mkisofs: emile-mkisofs.o device.o
|
||||||
emile-mktable: emile-mktable.o device.o
|
emile-mktable: emile-mktable.o device.o
|
||||||
|
emile-conf: emile-conf.o device.o
|
||||||
|
|
||||||
install:
|
install:
|
||||||
install -d $(DESTDIR)/$(PREFIX)/sbin/
|
install -d $(DESTDIR)/$(PREFIX)/sbin/
|
||||||
|
@ -65,6 +67,7 @@ install:
|
||||||
install emile-map-set $(DESTDIR)/$(PREFIX)/sbin/emile-map-set
|
install emile-map-set $(DESTDIR)/$(PREFIX)/sbin/emile-map-set
|
||||||
install emile-mkisofs $(DESTDIR)/$(PREFIX)/sbin/emile-mkisofs
|
install emile-mkisofs $(DESTDIR)/$(PREFIX)/sbin/emile-mkisofs
|
||||||
install emile-mktable $(DESTDIR)/$(PREFIX)/sbin/emile-mktable
|
install emile-mktable $(DESTDIR)/$(PREFIX)/sbin/emile-mktable
|
||||||
|
install emile-conf $(DESTDIR)/$(PREFIX)/sbin/emile-conf
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f $(DESTDIR)/$(PREFIX)/sbin/emile-set-cmdline
|
rm -f $(DESTDIR)/$(PREFIX)/sbin/emile-set-cmdline
|
||||||
|
@ -75,6 +78,7 @@ uninstall:
|
||||||
rm -f $(DESTDIR)/$(PREFIX)/sbin/emile-map-set
|
rm -f $(DESTDIR)/$(PREFIX)/sbin/emile-map-set
|
||||||
rm -f $(DESTDIR)/$(PREFIX)/sbin/emile-mkisofs
|
rm -f $(DESTDIR)/$(PREFIX)/sbin/emile-mkisofs
|
||||||
rm -f $(DESTDIR)/$(PREFIX)/sbin/emile-mktable
|
rm -f $(DESTDIR)/$(PREFIX)/sbin/emile-mktable
|
||||||
|
rm -f $(DESTDIR)/$(PREFIX)/sbin/emile-conf
|
||||||
|
|
||||||
dist:
|
dist:
|
||||||
@echo TAR tools
|
@echo TAR tools
|
||||||
|
|
188
tools/emile-conf.c
Normal file
188
tools/emile-conf.c
Normal file
|
@ -0,0 +1,188 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* (c) 2004 Laurent Vivier <Laurent@Vivier.EU>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libemile.h"
|
||||||
|
#include "libconfig.h"
|
||||||
|
#include "device.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
ARG_NONE = 0,
|
||||||
|
ARG_HELP ='h',
|
||||||
|
ARG_GETINFO = 'g',
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct option long_options[] =
|
||||||
|
{
|
||||||
|
{"help", 0, NULL, ARG_HELP },
|
||||||
|
{"getinfo", 1, NULL, ARG_GETINFO },
|
||||||
|
{NULL, 0, NULL, 0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
static void usage(int argc, char** argv)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Usage: %s [OPTION] <partition> <path>\n", argv[0]);
|
||||||
|
fprintf(stderr, "Set/get the path to the configuration file\n");
|
||||||
|
fprintf(stderr, " -h, --help display this text\n");
|
||||||
|
fprintf(stderr, " -g, --getinfo "
|
||||||
|
"get second level information\n");
|
||||||
|
fprintf(stderr, "Example:\n");
|
||||||
|
fprintf(stderr, " %s /dev/sda2 (sd0,4)/emile.conf\n", argv[0]);
|
||||||
|
fprintf(stderr, "sd -> SCSI disk\n");
|
||||||
|
fprintf(stderr, "0 -> SCSI Id\n");
|
||||||
|
fprintf(stderr, "4 -> partition /dev/sda5\n");
|
||||||
|
fprintf(stderr, "\nbuild: \n%s\n", SIGNATURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int set_conf(char* image, char *path)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
char property[256];
|
||||||
|
int ret;
|
||||||
|
device_io_t device;
|
||||||
|
int driver;
|
||||||
|
int disk;
|
||||||
|
int partition;
|
||||||
|
char dev_name[256];
|
||||||
|
map_t *map;
|
||||||
|
|
||||||
|
snprintf(property, 256, "configuration %s", path);
|
||||||
|
|
||||||
|
fd = open(image, O_RDWR);
|
||||||
|
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
perror("Cannot open image file");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = emile_second_set_configuration(fd, (int8_t *)property);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (ret == -1) {
|
||||||
|
fprintf(stderr, "Cannot set configuration\n");
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* compute driver new checksum */
|
||||||
|
|
||||||
|
ret = emile_scsi_get_rdev(image, &driver, &disk, &partition);
|
||||||
|
emile_get_dev_name(dev_name, driver, disk, 0);
|
||||||
|
device_sector_size = 512;
|
||||||
|
device.write_sector = (stream_write_sector_t)device_write_sector;
|
||||||
|
device.read_sector = (stream_read_sector_t)device_read_sector;
|
||||||
|
device.close = (stream_close_t)device_close;
|
||||||
|
device.get_blocksize = (stream_get_blocksize_t)device_get_blocksize;
|
||||||
|
device.data = (void*)device_open(dev_name, O_RDWR);
|
||||||
|
|
||||||
|
map = map_open(&device);
|
||||||
|
if (map == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: cannot open partition map\n");
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = map_update_checksum(map, 0);
|
||||||
|
if (ret == -1) {
|
||||||
|
fprintf(stderr, "ERROR: cannot update driver checksum\n");
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
map_close(map);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_conf(char* image)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
int8_t *configuration;
|
||||||
|
char property[256];
|
||||||
|
|
||||||
|
fd = open(image, O_RDONLY);
|
||||||
|
if (fd == -1)
|
||||||
|
{
|
||||||
|
perror("Cannot open image file");
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
configuration = emile_second_get_configuration(fd);
|
||||||
|
close(fd);
|
||||||
|
|
||||||
|
if (configuration == NULL) {
|
||||||
|
fprintf(stderr, "Cannot find configuration\n");
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config_get_property(configuration, "configuration", property) == -1) {
|
||||||
|
fprintf(stderr, "Invalid configuration\n");
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("%s\n", property);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
char *file = NULL;
|
||||||
|
char *conf = NULL;
|
||||||
|
int action_getinfo = 0;
|
||||||
|
int option_index;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
c = getopt_long(argc, argv, "ha:k:r:g", long_options,
|
||||||
|
&option_index);
|
||||||
|
if (c == -1)
|
||||||
|
break;
|
||||||
|
switch(c)
|
||||||
|
{
|
||||||
|
case ARG_HELP:
|
||||||
|
usage(argc, argv);
|
||||||
|
return 0;
|
||||||
|
case ARG_GETINFO:
|
||||||
|
action_getinfo = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (optind < argc)
|
||||||
|
file = argv[optind];
|
||||||
|
optind++;
|
||||||
|
if (optind < argc)
|
||||||
|
conf = argv[optind];
|
||||||
|
|
||||||
|
if (file == NULL)
|
||||||
|
{
|
||||||
|
fprintf(stderr,
|
||||||
|
"ERROR: you must provide an image file or a block device.\n");
|
||||||
|
usage(argc, argv);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action_getinfo)
|
||||||
|
return get_conf(file);
|
||||||
|
|
||||||
|
if (conf == NULL) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"ERROR: you must provide an configuration path.\n");
|
||||||
|
usage(argc, argv);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
ret = set_conf(file, conf);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user