[OpenWrt-Devel] PATCH [kernel]: proper support for Edimax uimages
There is support for building proper images for Edimax devices which do have 20 bytes long header before uImage but those images are not bootable without adding extra kernel parameters as firmware partition is not automatically split into kernel, rootfs and rootfs_data. Attached patch is corrects this issue (at least for kernel 3.10.58). --- a/drivers/mtd/mtdsplit_uimage.c +++ b/drivers/mtd/mtdsplit_uimage.c @@ -121,6 +121,31 @@ break; } + if (uimage_size == 0 ) { + + /* find uImage on 20 bytes past erase block boundary (Edimax header is 20 bytes long) */ + for (offset = 20; offset master-size; offset += master-erasesize) { + + ret = read_uimage_header(master, offset, header); + if (ret) + continue; + + if (!verify(header)) { + pr_debug(no valid uImage found in \%s\ at offset %llx\n, +master-name, (unsigned long long) offset); + continue; + } + + uimage_size = sizeof(*header) + be32_to_cpu(header-ih_size); + if ((offset + uimage_size) master-size) { + pr_debug(uImage exceeds MTD device \%s\\n, +master-name); + continue; + } + break; + } + } + if (uimage_size == 0) { pr_debug(no uImage found in \%s\\n, master-name); ret = -ENODEV; @@ -129,7 +154,7 @@ uimage_offset = offset; - if (uimage_offset == 0) { + if (uimage_offset == 0 || uimage_offset == 20) { uimage_part = 0; rf_part = 1; @@ -271,10 +296,45 @@ .type = MTD_PARSER_TYPE_FIRMWARE, }; +#define FW_MAGIC_EDIMAX0x43535953 + +static bool uimage_verify_edimax(struct uimage_header *header) +{ + switch be32_to_cpu(header-ih_magic) { + case FW_MAGIC_EDIMAX: + break; + default: + return false; + } + + if (header-ih_os != IH_OS_LINUX || + header-ih_type != IH_TYPE_FILESYSTEM) + return false; + + return true; +} + +static int +mtdsplit_uimage_parse_edimax(struct mtd_info *master, +struct mtd_partition **pparts, +struct mtd_part_parser_data *data) +{ + return __mtdsplit_parse_uimage(master, pparts, data, + uimage_verify_edimax); +} + +static struct mtd_part_parser uimage_edimax_parser = { + .owner = THIS_MODULE, + .name = edimax-fw, + .parse_fn = mtdsplit_uimage_parse_edimax, + .type = MTD_PARSER_TYPE_FIRMWARE, +}; + static int __init mtdsplit_uimage_init(void) { register_mtd_parser(uimage_generic_parser); register_mtd_parser(uimage_netgear_parser); + register_mtd_parser(uimage_edimax_parser); return 0; } ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH] ZRAM: enhacements including /tmp on ZRAM for Barrier Breaker
Devices with less memory are still common so why limit ZRAM usage just to swap when it could be very useful as for /tmp storage. This patch changes 3 things: - sets default number of ZRAM devices to 2 (1st for /tmp, 2nd for swap) - adds ZRAM (default) support to procd's init (TMPFS is used when ZRAM is not available - changes zram-swap so it will use /dev/zram1 for 1st CPU, /dev/zram2 for 2nd and so on as /dev/zram0 is in use for /tmp. Signed-off-by: Tomasz Wasiak tjwas...@gmail.com --- package/system/procd/patches/procd-support_for_tmp_on_zram.patch | 185 ++ package/system/zram-swap/files/zram.init | 15 target/linux/generic/patches-3.10/998_zram_make_2_devices_by_default.patch | 11 3 files changed, 203 insertions(+), 8 deletions(-) --- a/package/system/procd/patches/procd-support_for_tmo_on_zram.patch +++ b/package/system/procd/patches/procd-support_for_tmp_on_zram.patch @@ -0,0 +1,185 @@ +--- a/initd/early.c b/initd/early.c +@@ -12,34 +12,130 @@ + * GNU General Public License for more details. + */ + +-#include sys/mount.h +-#include sys/types.h +-#include sys/stat.h +- +-#include stdio.h ++#include errno.h + #include fcntl.h +-#include unistd.h ++#include stdio.h + #include stdlib.h ++#include string.h ++#include strings.h ++#include unistd.h ++#include sys/mount.h ++#include sys/stat.h ++#include sys/types.h ++#include sys/wait.h + + #include ../log.h + #include init.h + ++static long ++check_ramsize(void) ++{ ++ FILE *fp; ++ char line[256]; ++ char *key; ++ long val = 0; ++ ++ fp = fopen(/proc/meminfo, r); ++ if(fp == NULL) ++ { ++ ERROR(Can't open /proc/meminfo: %s\n, strerror(errno)); ++ return errno; ++ } ++ ++ while(fgets(line, sizeof(line), fp)) ++ { ++ key = strtok(line, :); ++ val = atol(strtok(NULL, kB\n)); ++ ++ if (!key || !val) ++ continue; ++ ++ if (!strcasecmp(key, MemTotal)) ++ break; ++ } ++ ++ fclose(fp); ++ ++ return val; ++} ++ ++static int ++mount_zram_on_tmp(void) ++{ ++ FILE *fp; ++ long zramsize = (check_ramsize() / 2); ++ pid_t pid; ++ ++ if(!zramsize) ++ { ++ ERROR(Can't read size of RAM. Assuming 16 MB.\n); ++ zramsize = 8192; ++ } ++ ++ fp = fopen(/sys/block/zram0/disksize, r+); ++ if(fp == NULL) ++ { ++ ERROR(Can't open /sys/block/zram0/disksize: %s\n, strerror(errno)); ++ return errno; ++ } ++ ++ fprintf(fp, %ld, (zramsize * 1024)); ++ ++ fclose(fp); ++ ++ pid = fork(); ++ ++ if (!pid) ++ { ++ char *mkfs[] = { /sbin/mke2fs, -b, 4096, -F, -L, TEMP, -m, 0, /dev/zram0, NULL }; ++ int fd = open(/dev/null, O_RDWR); ++ ++ if (fd -1) { ++ dup2(fd, STDIN_FILENO); ++ dup2(fd, STDOUT_FILENO); ++ dup2(fd, STDERR_FILENO); ++ if (fd STDERR_FILENO) ++ close(fd); ++ } ++ ++ execvp(mkfs[0], mkfs); ++ ERROR(Can't exec /sbin/mke2fs\n); ++ exit(-1); ++ } ++ ++ if (pid = 0) ++ { ++ ERROR(Can't exec /sbin/mke2fs\n); ++ return -1; ++ } else { ++ waitpid(pid, NULL, 0); ++ } ++ ++ if(mount(/dev/zram0, /tmp, ext2, MS_NOSUID | MS_NODEV | MS_NOATIME, check=none,errors=continue,noquota) 0) ++ { ++ ERROR(Can't mount /dev/zram0 on /tmp: %s\n, strerror(errno)); ++ return errno; ++ } ++ ++ LOG(Using up to %ld kB of RAM as ZRAM storage on /mnt\n, zramsize); ++ return 0; ++} ++ + static void +-early_mounts(void) ++mount_tmpfs_on_tmp(void) + { +- mount(proc, /proc, proc, MS_NOATIME, 0); +- mount(sysfs, /sys, sysfs, MS_NOATIME, 0); ++ char line[256]; ++ long tmpfssize = (check_ramsize() / 2); + +- mount(tmpfs, /tmp, tmpfs, MS_NOSUID | MS_NODEV | MS_NOATIME, NULL); +- mkdir(/tmp/run, 0777); +- mkdir(/tmp/lock, 0777); +- mkdir(/tmp/state, 0777); +- symlink(/tmp, /var); ++ if(!tmpfssize) ++ { ++ ERROR(Can't read size of RAM. Assuming 16 MB.\n); ++ tmpfssize = 8192; ++ } + +- mount(tmpfs, /dev, tmpfs, MS_NOATIME, mode=0755,size=512K); +- mkdir(/dev/shm, 0755); +- mkdir(/dev/pts, 0755); +- mount(devpts, /dev/pts, devpts, MS_NOATIME, mode=600); ++ snprintf(line, 256, size=%ldk, tmpfssize); ++ mount(tmpfs, /tmp, tmpfs, MS_NOSUID | MS_NODEV | MS_NOATIME, line); ++ LOG(Using up to %ld kB of RAM as TMPFS storage on /tmp\n, tmpfssize); + } + + static void +@@ -50,6 +146,25 @@ early_dev(void) + } + + static void ++early_mounts(void) ++{ ++ mount(proc, /proc, proc, MS_NOATIME, 0
[OpenWrt-Devel] [PATCH] [package] util-linux-dmesg: Add missing install section
Package util-linux-dmesg is broken (at least) in Barrier Breaker git repo as you can select it within menuconfig, it will compile (as a part of util-linux) but it will not install as install section is missing from package Makefile. Signed-off-by: Tomasz Wasiak tjwas...@gmail.com --- Makefile |6 ++ 1 file changed, 6 insertions(+) --- a/package/utils/util-linux/Makefile +++ b/package/utils/util-linux/Makefile @@ -152,6 +152,7 @@ endef define Package/dmesg $(call Package/util-linux/Default) TITLE:=print or control the kernel ring buffer + DEPENDS:= +librt endef define Package/dmesg/description @@ -438,6 +439,11 @@ define Package/cfdisk/install $(INSTALL_BIN) $(PKG_BUILD_DIR)/.libs/cfdisk $(1)/usr/sbin/ endef +define Package/dmesg/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/dmesg $(1)/usr/sbin/ +endef + define Package/fdisk/install $(INSTALL_DIR) $(1)/usr/sbin $(INSTALL_BIN) $(PKG_BUILD_DIR)/.libs/fdisk $(1)/usr/sbin/ ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH] [kernel generic] configuration: Better handling of LIB80211 configuration
OpenWRT patch 255-lib80211_kconfig_hacks gives user possiblity to select LIB80211 dependant settings (LIB80211_CRYPT_*) without having LIB80211 selected which is wrong. My patch changes OpenWRT patch so LIB80211 is vissible and all LIB80211_CRYPT_* options selects LIB80211 automatically. Signed-off-by: Tomasz Wasiak tjwas...@gmail.com --- 255-lib80211_kconfig_hacks.patch | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) --- a/target/linux/generic/patches-3.10/255-lib80211_kconfig_hacks.patch +++ b/target/linux/generic/patches-3.10/255-lib80211_kconfig_hacks.patch @@ -1,19 +1,31 @@ --- a/net/wireless/Kconfig +++ b/net/wireless/Kconfig -@@ -149,13 +149,13 @@ config LIB80211 +@@ -140,7 +140,7 @@ config CFG80211_WEXT + extensions with cfg80211-based drivers. + + config LIB80211 +- tristate ++ tristate LIB80211 + default n + help + This options enables a library of common routines used +@@ -149,13 +149,16 @@ config LIB80211 Drivers should select this themselves if needed. config LIB80211_CRYPT_WEP - tristate + tristate LIB80211_CRYPT_WEP ++ select LIB80211 config LIB80211_CRYPT_CCMP - tristate + tristate LIB80211_CRYPT_CCMP ++ select LIB80211 config LIB80211_CRYPT_TKIP - tristate + tristate LIB80211_CRYPT_TKIP ++ select LIB80211 config LIB80211_DEBUG bool lib80211 debugging messages ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] ZRAM: enhacements including /tmp on ZRAM for Barrier Breaker
Hello, Here you are (of course it is just 1/3 of the original patch). --- diff --git a/initd/early.c b/initd/early.c index a9f6afb..b4a375f 100644 --- a/initd/early.c +++ b/initd/early.c @@ -12,34 +12,130 @@ * GNU General Public License for more details. */ -#include sys/mount.h -#include sys/types.h -#include sys/stat.h - -#include stdio.h +#include errno.h #include fcntl.h -#include unistd.h +#include stdio.h #include stdlib.h +#include string.h +#include strings.h +#include unistd.h +#include sys/mount.h +#include sys/stat.h +#include sys/types.h +#include sys/wait.h #include ../log.h #include init.h +static long +check_ramsize(void) +{ + FILE *fp; + char line[256]; + char *key; + long val = 0; + + fp = fopen(/proc/meminfo, r); + if(fp == NULL) + { + ERROR(Can't open /proc/meminfo: %s\n, strerror(errno)); + return errno; + } + + while(fgets(line, sizeof(line), fp)) + { + key = strtok(line, :); + val = atol(strtok(NULL, kB\n)); + + if (!key || !val) + continue; + + if (!strcasecmp(key, MemTotal)) + break; + } + + fclose(fp); + + return val; +} + +static int +mount_zram_on_tmp(void) +{ + FILE *fp; + long zramsize = (check_ramsize() / 2); + pid_t pid; + + if(!zramsize) + { + ERROR(Can't read size of RAM. Assuming 16 MB.\n); + zramsize = 8192; + } + + fp = fopen(/sys/block/zram0/disksize, r+); + if(fp == NULL) + { + ERROR(Can't open /sys/block/zram0/disksize: %s\n, strerror(errno)); + return errno; + } + + fprintf(fp, %ld, (zramsize * 1024)); + + fclose(fp); + + pid = fork(); + + if (!pid) + { + char *mkfs[] = { /sbin/mke2fs, -b, 4096, -F, -L, TEMP, -m, 0, /dev/zram0, NULL }; + int fd = open(/dev/null, O_RDWR); + + if (fd -1) { + dup2(fd, STDIN_FILENO); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); + if (fd STDERR_FILENO) + close(fd); + } + + execvp(mkfs[0], mkfs); + ERROR(Can't exec /sbin/mke2fs\n); + exit(-1); + } + + if (pid = 0) + { + ERROR(Can't exec /sbin/mke2fs\n); + return -1; + } else { + waitpid(pid, NULL, 0); + } + + if(mount(/dev/zram0, /tmp, ext2, MS_NOSUID | MS_NODEV | MS_NOATIME, check=none,errors=continue,noquota) 0) + { + ERROR(Can't mount /dev/zram0 on /tmp: %s\n, strerror(errno)); + return errno; + } + + LOG(Using up to %ld kB of RAM as ZRAM storage on /mnt\n, zramsize); + return 0; +} + static void -early_mounts(void) +mount_tmpfs_on_tmp(void) { - mount(proc, /proc, proc, MS_NOATIME, 0); - mount(sysfs, /sys, sysfs, MS_NOATIME, 0); + char line[256]; + long tmpfssize = (check_ramsize() / 2); - mount(tmpfs, /tmp, tmpfs, MS_NOSUID | MS_NODEV | MS_NOATIME, NULL); - mkdir(/tmp/run, 0777); - mkdir(/tmp/lock, 0777); - mkdir(/tmp/state, 0777); - symlink(/tmp, /var); + if(!tmpfssize) + { + ERROR(Can't read size of RAM. Assuming 16 MB.\n); + tmpfssize = 8192; + } - mount(tmpfs, /dev, tmpfs, MS_NOATIME, mode=0755,size=512K); - mkdir(/dev/shm, 0755); - mkdir(/dev/pts, 0755); - mount(devpts, /dev/pts, devpts, MS_NOATIME, mode=600); + snprintf(line, 256, size=%ldk, tmpfssize); + mount(tmpfs, /tmp, tmpfs, MS_NOSUID | MS_NODEV | MS_NOATIME, line); + LOG(Using up to %ld kB of RAM as TMPFS storage on /tmp\n, tmpfssize); } static void @@ -50,6 +146,25 @@ early_dev(void) } static void +early_mounts(void) +{ + mount(proc, /proc, proc, MS_NOATIME, 0); + mount(sysfs, /sys, sysfs, MS_NOATIME, 0); + mount(tmpfs, /dev, tmpfs, MS_NOATIME, mode=0755,size=512K); + mkdir(/dev/shm, 0755); + mkdir(/dev/pts, 0755); + mount(devpts, /dev/pts, devpts, MS_NOATIME, mode=600); + early_dev(); + + if(mount_zram_on_tmp() !=0) + mount_tmpfs_on_tmp(); + mkdir(/tmp/run, 0777); + mkdir(/tmp/lock, 0777); + mkdir(/tmp/state, 0777); + symlink(/tmp, /var); +} + +static void early_console(const char *dev) { struct stat s; @@ -89,7 +204,6 @@ early(void) return; early_mounts(); - early_dev(); early_env(); early_console(/dev/console); W dniu 22.10.2014 o 09:38, John Crispin pisze: Hi, please send patches directly against the procd git tree. John On 22/10/2014 09:20, Tomasz Wasiak wrote: Devices with less
Re: [OpenWrt-Devel] [PATCH] ZRAM: enhacements including /tmp on ZRAM for Barrier Breaker
Hello, In my opinion early init is too late as we need /tmp sooner - for example to be able to mount overlayfs (even init procd needs writeable /tmp!). Maybe we can temporaily mount something (RAMFS/TMPFS depending on kernel configuration) on /tmp and then remount ZRAM but I do not think it will be better as we will have to copy stuff over... I can provide patch using correct coding style if you need. Please find answers to your comments below. Regards, Thomas W dniu 22.10.2014 o 12:39, John Crispin pisze: Hi, a few comments inline. i am not sure if we want this inside procd directly. maybe we should put this into fstools and then call that code from early init. i need to think about that before i can make a decision. John On 22/10/2014 10:30, Tomasz Wasiak wrote: Hello, Here you are (of course it is just 1/3 of the original patch). --- diff --git a/initd/early.c b/initd/early.c index a9f6afb..b4a375f 100644 --- a/initd/early.c +++ b/initd/early.c @@ -12,34 +12,130 @@ * GNU General Public License for more details. */ -#include sys/mount.h -#include sys/types.h -#include sys/stat.h - -#include stdio.h +#include errno.h #include fcntl.h -#include unistd.h +#include stdio.h #include stdlib.h +#include string.h +#include strings.h +#include unistd.h +#include sys/mount.h +#include sys/stat.h +#include sys/types.h +#include sys/wait.h #include ../log.h #include init.h +static long +check_ramsize(void) +{ +FILE *fp; +char line[256]; +char *key; +long val = 0; + +fp = fopen(/proc/meminfo, r); +if(fp == NULL) +{ please use this coding style - if (fp == NULL) { } +ERROR(Can't open /proc/meminfo: %s\n, strerror(errno)); +return errno; +} + +while(fgets(line, sizeof(line), fp)) +{ and here aswell while () { } +key = strtok(line, :); +val = atol(strtok(NULL, kB\n)); what happens if strtok return NULL ? SIGSEGV :( But that means that /proc/meminfo does not contain information about total memory. Safer solution would be: char *key, *val; (...) key = strtok(line, :); val = strtok(NULL, kB\n); (...) break; fclose(fp); if(val != NULL) return(atol(val)); else return 0; fi } + +if (!key || !val) +continue; + +if (!strcasecmp(key, MemTotal)) +break; +} + +fclose(fp); + +return val; +} + +static int +mount_zram_on_tmp(void) +{ +FILE *fp; +long zramsize = (check_ramsize() / 2); where does the /2 come from ? is this just a good value to use or is there a technical reason that is must always be /2 and not /X /2 is here because I would like to limit memory used by /tmp filesystem to half of RAM. Now it is not limited so it can eat all memory! IMHO even if a device has only 16 MB of RAM 8 MB would be sufficient for /tmp (even when it will be pure RAMFS/TMPFS). +pid_t pid; + +if(!zramsize) +{ +ERROR(Can't read size of RAM. Assuming 16 MB.\n); +zramsize = 8192; dangerous, if the memory was not detected properly we have mayor issues and should not do any magic with the memory. in this case we should just continue without zram Of course but that way we are not able to limit /tmp memory usage. IMHO assumption that device has at least 16 MB of RAM is not harmful as I do not think one can run newer builds (based on 3.x kernels and modern toolchains) on any device equipped with 8 (or even less) MB of RAM. +} + +fp = fopen(/sys/block/zram0/disksize, r+); +if(fp == NULL) +{ +ERROR(Can't open /sys/block/zram0/disksize: %s\n, strerror(errno)); +return errno; +} + +fprintf(fp, %ld, (zramsize * 1024)); + +fclose(fp); + +pid = fork(); + +if (!pid) +{ +char *mkfs[] = { /sbin/mke2fs, -b, 4096, -F, -L, TEMP, -m, 0, /dev/zram0, NULL }; +int fd = open(/dev/null, O_RDWR); + +if (fd -1) { +dup2(fd, STDIN_FILENO); +dup2(fd, STDOUT_FILENO); +dup2(fd, STDERR_FILENO); +if (fd STDERR_FILENO) +close(fd); +} + +execvp(mkfs[0], mkfs); +ERROR(Can't exec /sbin/mke2fs\n); +exit(-1); +} + +if (pid = 0) +{ +ERROR(Can't exec /sbin/mke2fs\n); +return -1; +} else { +waitpid(pid, NULL, 0); +} + +if(mount(/dev/zram0, /tmp, ext2, MS_NOSUID | MS_NODEV | MS_NOATIME, check=none,errors=continue,noquota) 0) +{ +ERROR(Can't mount /dev/zram0 on /tmp: %s\n, strerror
Re: [OpenWrt-Devel] [PATCH] ZRAM: enhacements including /tmp on ZRAM for Barrier Breaker
I am going to test a totally not supported device with only 16MB of RAM if time permits. Unfortunately now I am having some strange issues with my development device - tmp on ZRAM works without any issues but I have to switch off swap on ZRAM as it was getting some random oops'es which might be connected to compressing one more time files on ZRAM device mounted as /tmp when they got swapped out. This device has 32 MB of RAM, and after booting shows ~ 15-16MB RAM available (~ 2-3 MB + caches and buffers). I have ~ 14 MB limit on /tmp ZRAM device and tried different swap on ZRAM size settings - from rather small (3200 kB) to 14 MB. It does not look like a no memory issue because it is able to work normally without swap even using unrestricted RAMFS or TMPFS volume mounted as /tmp. Thomas W dniu 22.10.2014 o 16:07, Fernando Frediani pisze: By the way. Has anyone compiled and used BB 14.07 for devices with 16MB of RAM that went unsupported with AA release because of lack of ZRAM ? Fernando On 22/10/2014 08:20, Tomasz Wasiak wrote: Devices with less memory are still common so why limit ZRAM usage just to swap when it could be very useful as for /tmp storage. This patch changes 3 things: - sets default number of ZRAM devices to 2 (1st for /tmp, 2nd for swap) - adds ZRAM (default) support to procd's init (TMPFS is used when ZRAM is not available - changes zram-swap so it will use /dev/zram1 for 1st CPU, /dev/zram2 for 2nd and so on as /dev/zram0 is in use for /tmp. Signed-off-by: Tomasz Wasiak tjwas...@gmail.com --- package/system/procd/patches/procd-support_for_tmp_on_zram.patch | 185 ++ package/system/zram-swap/files/zram.init | 15 target/linux/generic/patches-3.10/998_zram_make_2_devices_by_default.patch | 11 3 files changed, 203 insertions(+), 8 deletions(-) --- a/package/system/procd/patches/procd-support_for_tmo_on_zram.patch +++ b/package/system/procd/patches/procd-support_for_tmp_on_zram.patch @@ -0,0 +1,185 @@ +--- a/initd/early.c b/initd/early.c +@@ -12,34 +12,130 @@ + * GNU General Public License for more details. + */ + +-#include sys/mount.h +-#include sys/types.h +-#include sys/stat.h +- +-#include stdio.h ++#include errno.h + #include fcntl.h +-#include unistd.h ++#include stdio.h + #include stdlib.h ++#include string.h ++#include strings.h ++#include unistd.h ++#include sys/mount.h ++#include sys/stat.h ++#include sys/types.h ++#include sys/wait.h + + #include ../log.h + #include init.h + ++static long ++check_ramsize(void) ++{ ++FILE *fp; ++char line[256]; ++char *key; ++long val = 0; ++ ++fp = fopen(/proc/meminfo, r); ++if(fp == NULL) ++{ ++ERROR(Can't open /proc/meminfo: %s\n, strerror(errno)); ++return errno; ++} ++ ++while(fgets(line, sizeof(line), fp)) ++{ ++key = strtok(line, :); ++val = atol(strtok(NULL, kB\n)); ++ ++if (!key || !val) ++continue; ++ ++if (!strcasecmp(key, MemTotal)) ++break; ++} ++ ++fclose(fp); ++ ++return val; ++} ++ ++static int ++mount_zram_on_tmp(void) ++{ ++FILE *fp; ++long zramsize = (check_ramsize() / 2); ++pid_t pid; ++ ++if(!zramsize) ++{ ++ERROR(Can't read size of RAM. Assuming 16 MB.\n); ++zramsize = 8192; ++} ++ ++fp = fopen(/sys/block/zram0/disksize, r+); ++if(fp == NULL) ++{ ++ERROR(Can't open /sys/block/zram0/disksize: %s\n, strerror(errno)); ++return errno; ++} ++ ++fprintf(fp, %ld, (zramsize * 1024)); ++ ++fclose(fp); ++ ++pid = fork(); ++ ++if (!pid) ++{ ++char *mkfs[] = { /sbin/mke2fs, -b, 4096, -F, -L, TEMP, -m, 0, /dev/zram0, NULL }; ++int fd = open(/dev/null, O_RDWR); ++ ++if (fd -1) { ++dup2(fd, STDIN_FILENO); ++dup2(fd, STDOUT_FILENO); ++dup2(fd, STDERR_FILENO); ++if (fd STDERR_FILENO) ++close(fd); ++} ++ ++execvp(mkfs[0], mkfs); ++ERROR(Can't exec /sbin/mke2fs\n); ++exit(-1); ++} ++ ++if (pid = 0) ++{ ++ERROR(Can't exec /sbin/mke2fs\n); ++return -1; ++} else { ++waitpid(pid, NULL, 0); ++} ++ ++if(mount(/dev/zram0, /tmp, ext2, MS_NOSUID | MS_NODEV | MS_NOATIME, check=none,errors=continue,noquota) 0) ++{ ++ERROR(Can't mount /dev/zram0 on /tmp: %s\n, strerror(errno)); ++return errno; ++} ++ ++LOG(Using up to %ld kB of RAM as ZRAM storage on /mnt\n, zramsize); ++return 0; ++} ++ + static void +-early_mounts(void) ++mount_tmpfs_on_tmp(void) + { +-mount(proc, /proc, proc, MS_NOATIME, 0); +-mount(sysfs, /sys, sysfs, MS_NOATIME, 0); ++char line[256]; ++long