summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
d7b9dc5)
include $(TOPDIR)/rules.mk
PKG_NAME:=unvram
include $(TOPDIR)/rules.mk
PKG_NAME:=unvram
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
nvram_handle_t * nvram_open(const char *file, int rdonly)
{
int fd;
nvram_handle_t * nvram_open(const char *file, int rdonly)
{
int fd;
nvram_handle_t *h;
nvram_header_t *header;
nvram_handle_t *h;
nvram_header_t *header;
if( (nvram_erase_size == 0) || (file == NULL) )
{
/* Finding the mtd will set the appropriate erase size */
if( (nvram_erase_size == 0) || (file == NULL) )
{
/* Finding the mtd will set the appropriate erase size */
- if( file == NULL )
- file = nvram_find_mtd();
- else
- (void) nvram_find_mtd();
-
- if( nvram_erase_size == 0 )
+ if( (mtd = nvram_find_mtd()) == NULL || nvram_erase_size == 0 )
+ {
+ free(mtd);
- if( (fd = open(file, O_RDWR)) > -1 )
+ if( (fd = open(file ? file : mtd, O_RDWR)) > -1 )
{
char *mmap_area = (char *) mmap(
NULL, nvram_erase_size, PROT_READ | PROT_WRITE,
{
char *mmap_area = (char *) mmap(
NULL, nvram_erase_size, PROT_READ | PROT_WRITE,
if( header->magic == NVRAM_MAGIC )
{
_nvram_rehash(h);
if( header->magic == NVRAM_MAGIC )
{
_nvram_rehash(h);
}
/* Determine NVRAM device node. */
}
/* Determine NVRAM device node. */
-const char * nvram_find_mtd(void)
+char * nvram_find_mtd(void)
char *path = NULL;
struct stat s;
char *path = NULL;
struct stat s;
- // "/dev/mtdblock/" + ( 0 < x < 99 ) + \0 = 19
- if( (path = (char *) malloc(19)) == NULL )
- return NULL;
-
- if ((fp = fopen("/proc/mtd", "r"))) {
- while (fgets(dev, sizeof(dev), fp)) {
- if (strstr(dev, "nvram") && sscanf(dev, "mtd%d: %08x", &i, &esz))
+ if( (fp = fopen("/proc/mtd", "r")) )
+ {
+ while( fgets(dev, sizeof(dev), fp) )
+ {
+ if( strstr(dev, "nvram") && sscanf(dev, "mtd%d: %08x", &i, &esz) )
{
nvram_erase_size = esz;
{
nvram_erase_size = esz;
}
/* Check NVRAM staging file. */
}
/* Check NVRAM staging file. */
-const char * nvram_find_staging(void)
+char * nvram_find_staging(void)
int nvram_to_staging(void)
{
int fdmtd, fdstg, stat;
int nvram_to_staging(void)
{
int fdmtd, fdstg, stat;
- const char *mtd = nvram_find_mtd();
+ char *mtd = nvram_find_mtd();
char buf[nvram_erase_size];
stat = -1;
char buf[nvram_erase_size];
stat = -1;
int staging_to_nvram(void)
{
int fdmtd, fdstg, stat;
int staging_to_nvram(void)
{
int fdmtd, fdstg, stat;
- const char *mtd = nvram_find_mtd();
+ char *mtd = nvram_find_mtd();
char buf[nvram_erase_size];
stat = -1;
char buf[nvram_erase_size];
stat = -1;
uint8_t nvram_calc_crc(nvram_header_t * nvh);
/* Determine NVRAM device node. */
uint8_t nvram_calc_crc(nvram_header_t * nvh);
/* Determine NVRAM device node. */
-const char * nvram_find_mtd(void);
+char * nvram_find_mtd(void);
/* Copy NVRAM contents to staging file. */
int nvram_to_staging(void);
/* Copy NVRAM contents to staging file. */
int nvram_to_staging(void);
int staging_to_nvram(void);
/* Check NVRAM staging file. */
int staging_to_nvram(void);
/* Check NVRAM staging file. */
-const char * nvram_find_staging(void);
+char * nvram_find_staging(void);
/* Staging file for NVRAM */
/* Staging file for NVRAM */