[PATCH 1/3] env: add register_persistent_environment

Sascha Hauer s.hauer at pengutronix.de
Thu Feb 14 14:31:35 EST 2013


On Thu, Feb 14, 2013 at 12:56:49PM +0100, Eric Bénard wrote:
> - heavily copied from register_persistant_environment which was
> Signed-off-by: Juergen Beisert <jbe at pengutronix.de>
> 
> Signed-off-by: Eric Bénard <eric at eukrea.com>
> ---
>  common/environment.c  | 40 ++++++++++++++++++++++++++++++++++++++++
>  include/environment.h |  1 +

Please move the prototype to include/envfs.h. include/environment.h has
stuff for shell environment variables only.

>  2 files changed, 41 insertions(+)
> 
> diff --git a/common/environment.c b/common/environment.c
> index e8d623f..55befd9 100644
> --- a/common/environment.c
> +++ b/common/environment.c
> @@ -363,3 +363,43 @@ out:
>  		free(buf_free);
>  	return ret;
>  }
> +
> +#ifdef __BAREBOX__
> +/**
> + * Try to register an environment storage on a device's partition
> + * @return 0 on success
> + *
> + * We rely on the existence of a usable storage device, already attached to
> + * our system, to get something like a persistent memory for our environment.
> + * We need to specify the partition number to use on this device.
> + * @param[in] devname Name of the device
> + * @param[in] partnr Partition number
> + * @return 0 on success, anything else in case of failure
> + */
> +
> +int register_persistent_environment(const char *devname, unsigned int partnr)

I think envfs_register_partition would be a better name.

> +{
> +	struct cdev *cdev;
> +	char *partname;
> +
> +	if (!devname)
> +		return -EINVAL;
> +
> +	cdev = cdev_by_name(devname);
> +	if (cdev == NULL) {
> +		pr_err("No %s present\n", devname);
> +		return -ENODEV;
> +	}
> +	partname = asprintf("%s.%d", devname, partnr);

free partname?

Sascha

> +	cdev = cdev_by_name(partname);
> +	if (cdev == NULL) {
> +		pr_err("No %s partition available\n", partname);
> +		pr_info("Please create the partition %s to store the env\n", partname);
> +		return -ENODEV;
> +	}
> +
> +	return devfs_add_partition(partname, 0, cdev->size,
> +						DEVFS_PARTITION_FIXED, "env0");
> +}
> +EXPORT_SYMBOL(register_persistent_environment);
> +#endif
> diff --git a/include/environment.h b/include/environment.h
> index 7bdd213..d172f8f 100644
> --- a/include/environment.h
> +++ b/include/environment.h
> @@ -71,6 +71,7 @@ int env_pop_context(void);
>  int env_push_context(void);
>  
>  int export(const char *);
> +int register_persistent_environment(const char *devname, unsigned int partnr);
>  
>  #endif	/* _ENVIRONMENT_H_ */
>  
> -- 
> 1.7.11.7
> 
> 
> _______________________________________________
> barebox mailing list
> barebox at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list