Re: [LEDE-DEV] [PATCH] Mountd: Add sysupgrade functionality.

2016-07-08 Thread Olivier Hardouin
Hi Philipp,

> Yes, good point. But then we should rewrite/redesign the whole update
> process
> including the sysupgrade binary in my opinion. For example writing a
> small library and a daemon
> which does the updates for us. A daemon which executes a sysupgrade tool
> doesn't
> make more sense for me as the mountd solution.

I'm not sure why a complete re-design of the sysupgrade would be
needed in this particular case.
At the end you only want to trigger the upgrade when a stick is
inserted, and hotplug can do that.
If the following (untested and unfinished) script is stored in
/etc/hotplug.d/mount/99-autoupgrade, it would perform the upgrade.
#/bin/sh
if [ "${ACTION}" == "add" ]; then
if [[ "$(uci get -q autoupgrade.usbdisk.enabled)" == "1" ]]; then
filename="$(uci get -q
mountd.mountd.path)${NAME}/$(uci get -q autoupgrade.usbdisk.filename)"
[[ ! -f "$filename" ]] && exit
uci get -q autoupgrade.usbdisk.delay >/dev/null &&
delay="-d $(uci get -q autoupgrade.usbdisk.delay)"
[[ "$(uci get -q autoupgrade.usbdisk.save_config)" ==
"1" ]] && backup="-c" || backup="-n"
[[ "$(uci get -q autoupgrade.usbdisk.preserve_part)" =
"1" ]] && preserve_partition="-p"
logger -t hotplug " Starting upgrade with
/sbin/sysupgrade $delay $backup $preserve_partition $filename"
/sbin/sysupgrade $delay $backup $preserve_partition $filename
# TODO find a good way to not execute this at every boot ...
fi
fi
The uci config is the same as what you described in your patch (just
replace mountd by autoupgrade).
This is a proof of concept. You may argue about doing the upgrade from
within a hotplug script. I indeed would be cleaner to have a separate
daemon, especially if they are several sources for the upgrade (and
not only the usb).

Olivier

___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev


Re: [LEDE-DEV] [PATCH] Mountd: Add sysupgrade functionality.

2016-07-06 Thread Olivier Hardouin
Though I like the idea of being able to upgrade using a usb stick, I
wonder if mountd is the correct place to implement this.
Indeed mountd is sending events via hotplug, so some other subsystems
could listen to these ones and decide whether the upgrade should be
based on some file of an attached usb disk or some other place (in the
network).
I think mountd should only do what it is good at, meaning detecting
disk, finding partition, mounting filesystem and inform other
subsystems.


On Wed, Jul 6, 2016 at 12:34 PM, Wang Linetkux  wrote:
> Another possible solution is to record the HASH of system image after
> system upgrade is done. Next time when we try to do the system
> upgrade, we can compare the recorded HASH value and the compute value
> from system upgrade file?
>
> 2016-07-06 18:18 GMT+08:00 Bruno Randolf :
>> On 06/07/16 06:58, John Crispin wrote:
>>> Hi Philipp
>>>
>>> the thing that i am worried about is this process
>>>
>>> 1) plug a stick
>>> 2) mountd detects the upgrade file
>>> 3) mountd triggers sysupgrade
>>> 4) system reboots
>>> 5) goto 1)
>>>
>>> there is no way to know at what point between 3 and 4 we need to unplug
>>> the usb stick
>>
>> One possible solution is to write a file, something like
>> ".sysupgrade-applied" or remove the upgrade file before actually doing
>> the upgrade, or during first boot.
>>
>> bruno
>>
>>>   John
>>>
>>> On 04/07/2016 18:56, Philipp Deppenwiese wrote:
 Extend the mountd with the ability to apply sysupgrades from mounted 
 devices.
 Upgrade files are identified by filename and executed through the
 commandline sysupgrade utility of LEDE.

 Option List:

 config mountd 'sysupgrade'
  option  check_filename  firmware.bin (required)
  option  save_config 1   (optional, default disabled)
  option  delay   10  (optional, default disabled)
  option  preserve_part   1   (optional, default disabled)
  option  enabled 1

 The so called "filesearch" is done only in the root of a mounted
 devices.

 Signed-off-by: Philipp Deppenwiese 
 ---
  CMakeLists.txt|   2 +-
  autofs.c  |  19 ++-
  include/upgrade.h |   6 ++
  mount.c   |   2 +
  upgrade.c | 162 
 ++
  5 files changed, 189 insertions(+), 2 deletions(-)
  create mode 100644 include/upgrade.h
  create mode 100644 upgrade.c

 diff --git a/CMakeLists.txt b/CMakeLists.txt
 index 2e712cd..ed3602e 100644
 --- a/CMakeLists.txt
 +++ b/CMakeLists.txt
 @@ -5,7 +5,7 @@ ADD_DEFINITIONS(-Os -ggdb -Wall -Werror --std=gnu99 
 -Wmissing-declarations)

  SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")

 -ADD_EXECUTABLE(mountd main.c log.c sys.c autofs.c mount.c timer.c 
 signal.c ucix.c led.c fs.c ucix.c)
 +ADD_EXECUTABLE(mountd main.c log.c sys.c autofs.c mount.c timer.c 
 signal.c ucix.c led.c fs.c ucix.c upgrade.c)
  TARGET_LINK_LIBRARIES(mountd uci ubox)

  INSTALL(TARGETS mountd
 diff --git a/autofs.c b/autofs.c
 index 4ad782d..79a3e97 100644
 --- a/autofs.c
 +++ b/autofs.c
 @@ -37,6 +37,13 @@ dev_t dev;
  time_t uci_timeout;
  char uci_path[32];

 +// Sysupgrade uci options
 +char uci_upgrade_filename[255];
 +int uci_upgrade_backup;
 +int uci_upgrade_delay;
 +int uci_upgrade_enabled;
 +int uci_upgrade_preserve_partition;
 +
  static void umount_autofs(void)
  {
  system_printf("umount %s 2> /dev/null", "/tmp/run/mountd/");
 @@ -186,18 +193,28 @@ static void autofs_cleanup_handler(void)
  static void autofs_init(void)
  {
  int kproto_version;
 -char *p;
 +char *p, *filename = NULL;
  struct uci_context *ctx;
  signal_init(autofs_cleanup_handler);
  ctx = ucix_init("mountd");
  uci_timeout = ucix_get_option_int(ctx, "mountd", "mountd", "timeout", 
 60);
  p = ucix_get_option(ctx, "mountd", "mountd", "path");
 +filename = ucix_get_option(ctx, "mountd", "sysupgrade", 
 "check_filename");
 +uci_upgrade_backup = ucix_get_option_int(ctx, "mountd", "sysupgrade", 
 "save_config", 0);
 +uci_upgrade_delay = ucix_get_option_int(ctx, "mountd", "sysupgrade", 
 "delay", 0);
 +uci_upgrade_enabled = ucix_get_option_int(ctx, "mountd", 
 "sysupgrade", "enabled", 0);
 +uci_upgrade_preserve_partition = ucix_get_option_int(ctx, "mountd", 
 "sysupgrade", "preserve_part", 0);
  ucix_cleanup(ctx);
  if(p)
  snprintf(uci_path, 31, "%s", p);
  else
  snprintf(uci_path, 31, "/tmp/mounts/");
  uci_path[31] = '\0';
 +
 +if(filename) {
 +snprintf(uci_upgrade_filename, 255, "%s", filename);
 +}
 +
  mkdir("/tmp/run/",

Re: [LEDE-DEV] [PATCH mountd 2/2] support for disk without partition table

2016-06-23 Thread Olivier Hardouin
I have a USB flash drive fat32 formatted without any partition table.
I agree this is unusual nowadays (manufacturers usually put a
partition table on their devices), but as it mounts ok on my laptop, I
wanted the same behavior.


On Thu, Jun 23, 2016 at 9:24 AM, John Crispin  wrote:
>
>
> On 22/06/2016 09:51, olivier.hardo...@gmail.com wrote:
>> if no partition found, try to mount the block device itself
>>
>> Signed-off-by: Olivier Hardouin 
>
> Hi,
>
> looks ok, just wondering what kind of storage you see this on. i have
> only seen superfloppy type formating on mmc cards and that is almost a
> decade ago.
>
> John
>
>> ---
>>  mount.c | 14 ++
>>  1 file changed, 10 insertions(+), 4 deletions(-)
>>
>> diff --git a/mount.c b/mount.c
>> index 0c2862a..7cbb8ff 100644
>> --- a/mount.c
>> +++ b/mount.c
>> @@ -693,13 +693,19 @@ static void mount_enum_drives(void)
>>   char tmp[64];
>>   snprintf(tmp, 64, "/sys/block/%s/", 
>> namelist[n]->d_name);
>>   m = scandir(tmp, &namelist2, dir_filter2, 
>> dir_sort);
>> - while(m--)
>> + if(m > 0)
>>   {
>> - strncpy(&block[blk_cnt][0], 
>> namelist2[m]->d_name, MAX_BLOCK);
>> + while(m--)
>> + {
>> + strncpy(&block[blk_cnt][0], 
>> namelist2[m]->d_name, MAX_BLOCK);
>> + blk_cnt++;
>> + free(namelist2[m]);
>> + }
>> + free(namelist2);
>> + } else {
>> + strncpy(&block[blk_cnt][0], 
>> namelist[n]->d_name, MAX_BLOCK);
>>   blk_cnt++;
>> - free(namelist2[m]);
>>   }
>> - free(namelist2);
>>   }
>>   free(namelist[n]);
>>   }
>>

___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev


[LEDE-DEV] [PATCH mountd 2/2] support for disk without partition table

2016-06-22 Thread olivier . hardouin
if no partition found, try to mount the block device itself

Signed-off-by: Olivier Hardouin 
---
 mount.c | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/mount.c b/mount.c
index 0c2862a..7cbb8ff 100644
--- a/mount.c
+++ b/mount.c
@@ -693,13 +693,19 @@ static void mount_enum_drives(void)
char tmp[64];
snprintf(tmp, 64, "/sys/block/%s/", 
namelist[n]->d_name);
m = scandir(tmp, &namelist2, dir_filter2, 
dir_sort);
-   while(m--)
+   if(m > 0)
{
-   strncpy(&block[blk_cnt][0], 
namelist2[m]->d_name, MAX_BLOCK);
+   while(m--)
+   {
+   strncpy(&block[blk_cnt][0], 
namelist2[m]->d_name, MAX_BLOCK);
+   blk_cnt++;
+   free(namelist2[m]);
+   }
+   free(namelist2);
+   } else {
+   strncpy(&block[blk_cnt][0], 
namelist[n]->d_name, MAX_BLOCK);
blk_cnt++;
-   free(namelist2[m]);
}
-   free(namelist2);
}
free(namelist[n]);
}
-- 
1.9.1


___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev


[LEDE-DEV] [PATCH mountd 1/2] hfs+ journal partition support as read only

2016-06-22 Thread olivier . hardouin
use hfsplus driver to mount hfs+ partition marked as journalled,
read only mounting since partial support from the kernel for write 
access (as stated in Documentatiom/filesystems/hfsplus.txt)
add new index 'LASTFS' to be used in case of support for another
driver

Signed-off-by: Olivier Hardouin 
---
 fs.c |  4 ++--
 include/fs.h | 25 ++---
 mount.c  | 16 +++-
 3 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/fs.c b/fs.c
index fee6608..ca77a76 100644
--- a/fs.c
+++ b/fs.c
@@ -153,8 +153,8 @@ static int detect_hfsplus(int fd)
{
if(!journal)
ret = HFSPLUS;
-   //  else
-   //  ret = HFSPLUSJOURNAL;
+   else
+   ret = HFSPLUSJOURNAL;
}
 out:
free(buffer);
diff --git a/include/fs.h b/include/fs.h
index 1c66db3..b86f383 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -1,13 +1,16 @@
-#define NONE   -1
-#define MBR2
-#define EXT2   3
-#define EXT3   4
-#define FAT5
-#define HFSPLUS6
-#define EFI7
-#define NTFS   8
-#define EXTENDED   9
-#define EXFAT  10
-#define EXT4   11
+#define NONE   -1
+#define MBR2
+#define EXT2   3
+#define EXT3   4
+#define FAT5
+#define HFSPLUS6
+#define EFI7
+#define NTFS   8
+#define EXTENDED   9
+#define EXFAT  10
+#define EXT4   11
+#define HFSPLUSJOURNAL 12
+
+#define LASTFS HFSPLUSJOURNAL
 
 int detect_fs(char *device);
diff --git a/mount.c b/mount.c
index 219146b..0c2862a 100644
--- a/mount.c
+++ b/mount.c
@@ -60,7 +60,8 @@ char *fs_names[] = {
"ntfs",
"",
"exfat",
-   "ext4"
+   "ext4",
+   "hfsplusjournal"
 };
 
 #define MAX_MOUNTED32
@@ -100,7 +101,7 @@ static void mount_dump_uci_state(void)
ucix_add_option(ctx, mountd, q->serial, "rev", q->rev);
snprintf(t, 64, "size%d", atoi(&q->dev[3]));
ucix_add_option(ctx, mountd, q->serial, t, q->size);
-   if(q->fs > MBR && q->fs <= EXT4)
+   if(q->fs > MBR && q->fs <= LASTFS)
{
snprintf(t, 64, "fs%d", atoi(&q->dev[3]));
ucix_add_option(ctx, mountd, q->serial, t, 
fs_names[q->fs]);
@@ -138,7 +139,7 @@ static void mount_add_list(char *name, char *dev, char 
*serial,
 {
struct mount *mount;
char tmp[64], tmp2[64];
-   if(fs <= MBR || fs > EXT4)
+   if(fs <= MBR || fs > LASTFS)
return;
mount  = malloc(sizeof(struct mount));
INIT_LIST_HEAD(&mount->list);
@@ -154,7 +155,7 @@ static void mount_add_list(char *name, char *dev, char 
*serial,
mount->mounted = 0;
mount->fs = fs;
list_add(&mount->list, &mounts);
-   if((!mount->ignore) && (mount->fs > MBR) && (mount->fs <= EXT4))
+   if((!mount->ignore) && (mount->fs > MBR) && (mount->fs <= LASTFS))
{
log_printf("new mount : %s -> %s (%s)\n", name, dev, 
fs_names[mount->fs]);
snprintf(tmp, 64, "%s%s", uci_path, name);
@@ -260,12 +261,17 @@ int mount_new(char *path, char *dev)
options = "rw,defaults,uid=1000,gid=1000";
fstype = "hfsplus";
}
+   if(mount->fs == HFSPLUSJOURNAL)
+   {
+   options = "ro,defaults,uid=1000,gid=1000";
+   fstype = "hfsplus";
+   }
if(mount->fs == NTFS)
{
options = "force";
fstype = "ntfs-3g";
}
-   if(mount->fs > MBR && mount->fs <= EXT4)
+   if(mount->fs > MBR && mount->fs <= LASTFS)
{
struct uci_context *ctx;
char *uci_options, *uci_fstype;
-- 
1.9.1


___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev


[LEDE-DEV] [PATCH mountd 1/4] align fs_names table to indexes defined in include/fs.h

2016-06-15 Thread olivier . hardouin
Signed-off-by: Olivier Hardouin 
---
 mount.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/mount.c b/mount.c
index 8892040..36b99f5 100644
--- a/mount.c
+++ b/mount.c
@@ -59,6 +59,7 @@ char *fs_names[] = {
"",
"NTFS",
"",
+   "EXFAT",
"EXT4"
 };
 
-- 
1.9.1


___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev


[LEDE-DEV] [PATCH mountd 3/4] add hotplug events

2016-06-15 Thread olivier . hardouin
add hotplug events (add, remove) to inform other subsystems
remove obsolete /etc/mountd/event call

Signed-off-by: Olivier Hardouin 
---
 mount.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mount.c b/mount.c
index aaddb70..219146b 100644
--- a/mount.c
+++ b/mount.c
@@ -161,6 +161,7 @@ static void mount_add_list(char *name, char *dev, char 
*serial,
snprintf(tmp2, 64, "/tmp/run/mountd/%s", dev);
symlink(tmp2, tmp);
mount_new("/tmp/run/mountd/", dev);
+   system_printf("ACTION=add DEVICE=%s NAME=%s /sbin/hotplug-call 
mount", dev, name);
}
 }
 
@@ -734,7 +735,7 @@ static void mount_enum_drives(void)
log_printf("removing %s\n", q->dev);
snprintf(tmp, 64, "%s%s", uci_path, q->name);
unlink(tmp);
-   system_printf("/etc/mountd/event remove %s %s", q->dev, 
q->name);
+   system_printf("ACTION=remove DEVICE=%s NAME=%s 
/sbin/hotplug-call mount", q->dev, q->name);
free(q);
mount_dump_uci_state();
system_printf("/etc/fonstated/ReloadSamba");
-- 
1.9.1


___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev


[LEDE-DEV] [PATCH mountd 2/4] fix crash if no uci config file present

2016-06-15 Thread olivier . hardouin
fix also possible null dereferenced pointers 

Signed-off-by: Olivier Hardouin 
---
 uci.c  | 6 ++
 ucix.c | 9 -
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/uci.c b/uci.c
index f5aad02..46c3922 100644
--- a/uci.c
+++ b/uci.c
@@ -54,6 +54,9 @@ char* uci_get_option(struct uci_context *ctx, char *section, 
char *option)
char *value = NULL;
struct uci_ptr ptr;
 
+   if (!p)
+   return NULL;
+
memset(&ptr, 0, sizeof(ptr));
ptr.package = p->e.name;
ptr.section = section;
@@ -101,6 +104,9 @@ void uci_for_each_section_type(char *type, void 
(*cb)(char*, void*), void *priv)
 {
struct uci_element *e;
 
+   if (!p)
+   return;
+
uci_foreach_element(&p->sections, e)
if (!strcmp(type, uci_to_section(e)->type))
cb(e->name, priv);
diff --git a/ucix.c b/ucix.c
index e2a6780..1e4d1e6 100644
--- a/ucix.c
+++ b/ucix.c
@@ -18,6 +18,8 @@ static inline int ucix_get_ptr(struct uci_context *ctx, const 
char *p, const cha
 struct uci_context* ucix_init(const char *config_file)
 {
struct uci_context *ctx = uci_alloc_context();
+   if(!ctx)
+   return NULL;
uci_add_delta_path(ctx, "/var/state");
if(uci_load(ctx, config_file, NULL) != UCI_OK)
{
@@ -30,6 +32,8 @@ struct uci_context* ucix_init(const char *config_file)
 struct uci_context* ucix_init_path(const char *path, const char *config_file)
 {
struct uci_context *ctx = uci_alloc_context();
+   if(!ctx)
+   return NULL;
if(path)
{
uci_set_savedir(ctx, path);
@@ -44,7 +48,10 @@ struct uci_context* ucix_init_path(const char *path, const 
char *config_file)
 
 void ucix_cleanup(struct uci_context *ctx)
 {
-   uci_free_context(ctx);
+   if(ctx)
+   {
+   uci_free_context(ctx);
+   }
 }
 
 int ucix_save(struct uci_context *ctx, const char *p)
-- 
1.9.1


___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev


[LEDE-DEV] [PATCH mountd 4/4] filesystem mount options in uci as optional parameter

2016-06-15 Thread olivier . hardouin
Possibility to overwrite the default hardcoded settings by adding 'options' 
and 'fstype' in the uci configuration. The fs names are changed in lowercase 
to comply with UCI general naming.

Signed-off-by: Olivier Hardouin 
---
replaces patch "filesystem mount options in uci config" according to review 
comments
obsoletes patch "uci config for mountd fileystem options"

 mount.c | 63 +--
 1 file changed, 41 insertions(+), 22 deletions(-)

diff --git a/mount.c b/mount.c
index 36b99f5..aaddb70 100644
--- a/mount.c
+++ b/mount.c
@@ -51,16 +51,16 @@ struct mount {
 char *fs_names[] = {
"",
"",
-   "MBR",
-   "EXT2",
-   "EXT3",
-   "FAT",
-   "HFSPLUS",
+   "mbr",
+   "ext2",
+   "ext3",
+   "fat",
+   "hfsplus",
"",
-   "NTFS",
+   "ntfs",
"",
-   "EXFAT",
-   "EXT4"
+   "exfat",
+   "ext4"
 };
 
 #define MAX_MOUNTED32
@@ -228,40 +228,59 @@ int mount_new(char *path, char *dev)
pid = autofs_safe_fork();
if(!pid)
{
+   char *options, *fstype;
if(mount->fs == EXFAT)
{
-   log_printf("mount -t exfat -o rw,uid=1000,gid=1000 
/dev/%s %s", mount->dev, tmp);
-   ret = system_printf("mount -t exfat -o 
rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp);
+   options = "rw,uid=1000,gid=1000";
+   fstype = "exfat";
}
if(mount->fs == FAT)
{
-   log_printf("mount -t vfat -o rw,uid=1000,gid=1000 
/dev/%s %s", mount->dev, tmp);
-   ret = system_printf("mount -t vfat -o 
rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp);
+   options = "rw,uid=1000,gid=1000";
+   fstype = "vfat";
}
if(mount->fs == EXT4)
{
-   log_printf("mount -t ext4 -o rw,defaults /dev/%s %s", 
mount->dev, tmp);
-   ret = system_printf("mount -t ext4 -o rw,defaults 
/dev/%s %s", mount->dev, tmp);
+   options = "rw,defaults";
+   fstype = "ext4";
}
if(mount->fs == EXT3)
{
-   log_printf("mount -t ext3 -o rw,defaults /dev/%s %s", 
mount->dev, tmp);
-   ret = system_printf("mount -t ext3 -o rw,defaults 
/dev/%s %s", mount->dev, tmp);
+   options = "rw,defaults";
+   fstype = "ext3";
}
if(mount->fs == EXT2)
{
-   log_printf("mount -t ext2 -o rw,defaults /dev/%s %s", 
mount->dev, tmp);
-   ret = system_printf("mount -t ext2 -o rw,defaults 
/dev/%s %s", mount->dev, tmp);
+   options = "rw,defaults";
+   fstype = "ext2";
}
if(mount->fs == HFSPLUS)
{
-   log_printf("mount -t hfsplus -o 
rw,defaults,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp);
-   ret = system_printf("mount -t hfsplus -o 
rw,defaults,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp);
+   options = "rw,defaults,uid=1000,gid=1000";
+   fstype = "hfsplus";
}
if(mount->fs == NTFS)
{
-   log_printf("ntfs-3g /dev/%s %s -o force", mount->dev, 
tmp);
-   ret = system_printf("ntfs-3g /dev/%s %s -o force", 
mount->dev, tmp);
+   options = "force";
+   fstype = "ntfs-3g";
+   }
+   if(mount->fs > MBR && mount->fs <= EXT4)
+   {
+   struct uci_context *ctx;
+   char *uci_options, *uci_fstype;
+   ctx = ucix_init("mountd");
+   if(fs_names[mount->fs])
+   {
+   uci_options = ucix_get_option(ctx, "mountd", 
fs_names[mount->fs], "options");
+   uci_fstype = ucix_get_option(ctx, "mountd", 
fs_names[mount->fs], "fsty

[LEDE-DEV] [PATCH package mountd] uci config for mountd fileystem options

2016-06-10 Thread olivier . hardouin
Signed-off-by: Olivier Hardouin 
---
 package/system/mountd/files/mountd.config | 28 
 1 file changed, 28 insertions(+)

diff --git a/package/system/mountd/files/mountd.config 
b/package/system/mountd/files/mountd.config
index 5610129..c105606 100644
--- a/package/system/mountd/files/mountd.config
+++ b/package/system/mountd/files/mountd.config
@@ -1,3 +1,31 @@
 config mountd mountd
option  timeout 60
option  path/tmp/mounts/
+
+config filesystem ext2
+   option options  'rw,defaults'
+   option fstype   'ext2'
+
+config filesystem ext3
+   option options  'rw,defaults'
+   option fstype   'ext3'
+
+config filesystem ext4
+   option options  'rw,defaults'
+   option fstype   'ext4'
+
+config filesystem fat
+   option options  'rw,uid=1000,gid=1000'
+   option fstype   'vfat'
+
+config filesystem exfat
+   option options  'rw,uid=1000,gid=1000'
+   option fstype   'exfat'
+
+config filesystem hfsplus
+   option options  'rw,defaults,uid=1000,gid=1000'
+   option fstype   'hfsplus'
+
+config filesystem ntfs
+   option options  'force'
+   option fstype   'ntfs'
-- 
1.9.1


___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev


[LEDE-DEV] [PATCH mountd] filesystem mount options in uci config

2016-06-10 Thread olivier . hardouin
Move (previously hardcoded) mount option to UCI to allow different 
configuration 
like charset (utf-8 or iso) and filesystem driver (if alternative ones are 
used).
The fs names are changed in lowercase to comply with UCI general naming.

Signed-off-by: Olivier Hardouin 
---
 mount.c | 69 ++---
 1 file changed, 28 insertions(+), 41 deletions(-)

diff --git a/mount.c b/mount.c
index 8892040..c8f7ea6 100644
--- a/mount.c
+++ b/mount.c
@@ -51,15 +51,15 @@ struct mount {
 char *fs_names[] = {
"",
"",
-   "MBR",
-   "EXT2",
-   "EXT3",
-   "FAT",
-   "HFSPLUS",
+   "mbr",
+   "ext2",
+   "ext3",
+   "fat",
+   "hfsplus",
"",
-   "NTFS",
+   "ntfs",
"",
-   "EXT4"
+   "ext4"
 };
 
 #define MAX_MOUNTED32
@@ -227,42 +227,29 @@ int mount_new(char *path, char *dev)
pid = autofs_safe_fork();
if(!pid)
{
-   if(mount->fs == EXFAT)
+   if(mount->fs > MBR && mount->fs <= EXT4)
{
-   log_printf("mount -t exfat -o rw,uid=1000,gid=1000 
/dev/%s %s", mount->dev, tmp);
-   ret = system_printf("mount -t exfat -o 
rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp);
-   }
-   if(mount->fs == FAT)
-   {
-   log_printf("mount -t vfat -o rw,uid=1000,gid=1000 
/dev/%s %s", mount->dev, tmp);
-   ret = system_printf("mount -t vfat -o 
rw,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp);
-   }
-   if(mount->fs == EXT4)
-   {
-   log_printf("mount -t ext4 -o rw,defaults /dev/%s %s", 
mount->dev, tmp);
-   ret = system_printf("mount -t ext4 -o rw,defaults 
/dev/%s %s", mount->dev, tmp);
-   }
-   if(mount->fs == EXT3)
-   {
-   log_printf("mount -t ext3 -o rw,defaults /dev/%s %s", 
mount->dev, tmp);
-   ret = system_printf("mount -t ext3 -o rw,defaults 
/dev/%s %s", mount->dev, tmp);
-   }
-   if(mount->fs == EXT2)
-   {
-   log_printf("mount -t ext2 -o rw,defaults /dev/%s %s", 
mount->dev, tmp);
-   ret = system_printf("mount -t ext2 -o rw,defaults 
/dev/%s %s", mount->dev, tmp);
-   }
-   if(mount->fs == HFSPLUS)
-   {
-   log_printf("mount -t hfsplus -o 
rw,defaults,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp);
-   ret = system_printf("mount -t hfsplus -o 
rw,defaults,uid=1000,gid=1000 /dev/%s %s", mount->dev, tmp);
-   }
-   if(mount->fs == NTFS)
-   {
-   log_printf("ntfs-3g /dev/%s %s -o force", mount->dev, 
tmp);
-   ret = system_printf("ntfs-3g /dev/%s %s -o force", 
mount->dev, tmp);
+   struct uci_context *ctx;
+   char *options, *fstype;
+   ctx = ucix_init("mountd");
+   options = ucix_get_option(ctx, "mountd", 
fs_names[mount->fs], "options");
+   fstype = ucix_get_option(ctx, "mountd", 
fs_names[mount->fs], "fstype");
+   ucix_cleanup(ctx);
+   if(!fstype)
+   {
+   log_printf("mounting /dev/%s failed, expecting 
'fstype' uci parameter (kernel driver) for %s", mount->dev, 
fs_names[mount->fs]);
+   } else {
+   if(!options)
+   {
+   log_printf("mount -t %s /dev/%s %s", 
fstype, mount->dev, tmp);
+   ret = system_printf("mount -t %s 
/dev/%s %s", fstype, mount->dev, tmp);
+   } else {
+   log_printf("mount -t %s -o %s /dev/%s 
%s", fstype, options, mount->dev, tmp);
+   ret = system_printf("mount -t %s -o %s 
/dev/%s %s", fstype, options, mount->dev, tmp);
+   }
+   }
+   exit(WEXITSTATUS(ret));
}
-   exit(WEXITSTATUS(ret));
}
pid = waitpid(pid, &ret, 0);
ret = WEXITSTATUS(ret);
-- 
1.9.1


___
Lede-dev mailing list
Lede-dev@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/lede-dev