Hello Deepak,
I think you're missing one declaration in kobject.h I had to add it...
extern struct kobject * __must_check kobject_create_and_add(const char
*name, struct kobject *parent);
Otherwise, when compiling i get an error that there has been an
implicit use of function 'kobject_create_and_add'.
Seems to be working okay now!
Ben
P.S.
I don't suppose you have any idea of how to configure android proxies
when using real hardware?
On Sep 24, 6:09 am, deepak singal <[EMAIL PROTECTED]> wrote:
> Hi Ben,
>
> I'm using below patch for lib/kobject.c (linux-2.6.22.6 kernel)
>
> diff -Naur linux-2.6.22/include/linux/kobject.h test-linux/include/
> linux/kobject.h
> --- linux-2.6.22/include/linux/kobject.h 2007-07-09
> 05:02:17.000000000 +0530
> +++ test-linux/include/linux/kobject.h 2008-09-23 20:40:07.000000000
> +0530
> @@ -57,6 +57,11 @@
> struct kobj_type * ktype;
> struct dentry * dentry;
> wait_queue_head_t poll;
> + struct sysfs_dirent *sd;
> + unsigned int state_initialized:1;
> + unsigned int state_in_sysfs:1;
> + unsigned int state_add_uevent_sent:1;
> + unsigned int state_remove_uevent_sent:1;
> };
>
> extern int kobject_set_name(struct kobject *, const char *, ...)
> @@ -123,6 +128,14 @@
> int num_envp, char *buffer, int buffer_size);
> };
>
> +struct kobj_attribute {
> + struct attribute attr;
> + ssize_t (*show)(struct kobject *kobj, struct kobj_attribute
> *attr,
> + char *buf);
> + ssize_t (*store)(struct kobject *kobj, struct kobj_attribute
> *attr,
> + const char *buf, size_t count);
> +};
> +
> struct kset {
> struct kobj_type * ktype;
> struct list_head list;
> diff -Naur linux-2.6.22/lib/kobject.c test-linux/lib/kobject.c
> --- linux-2.6.22/lib/kobject.c 2007-07-09 05:02:17.000000000 +0530
> +++ test-linux/lib/kobject.c 2008-09-23 19:32:19.000000000 +0530
> @@ -166,7 +166,7 @@
> {
> int error = 0;
> struct kobject * parent;
> -
> +
> if (!(kobj = kobject_get(kobj)))
> return -ENOENT;
> if (!kobj->k_name)
> @@ -518,6 +518,52 @@
> .default_attrs = NULL,
> };
>
> +
> +/* default kobject attribute operations */
> +
> +static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute
> *attr,
> + char *buf)
> +{
> + struct kobj_attribute *kattr;
> + ssize_t ret = -EIO;
> +
> + kattr = container_of(attr, struct kobj_attribute, attr);
> + if (kattr->show)
> + ret = kattr->show(kobj, kattr, buf);
> + return ret;
> +}
> +
> +static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute
> *attr,
> + const char *buf, size_t count)
> +{
> + struct kobj_attribute *kattr;
> + ssize_t ret = -EIO;
> +
> + kattr = container_of(attr, struct kobj_attribute, attr);
> + if (kattr->store)
> + ret = kattr->store(kobj, kattr, buf, count);
> + return ret;
> +}
> +
> +
> +struct sysfs_ops kobj_sysfs_ops = {
> + .show = kobj_attr_show,
> + .store = kobj_attr_store,
> +};
> +
> +static void dynamic_kobj_release(struct kobject *kobj)
> +{
> + pr_debug("kobject: (%p): %s\n", kobj, __FUNCTION__);
> + kfree(kobj);
> +}
> +
> +
> +static struct kobj_type dynamic_kobj_ktype = {
> + .release = dynamic_kobj_release,
> + .sysfs_ops = &kobj_sysfs_ops,
> +};
> +
> /**
> * kobject_kset_add_dir - add sub directory of object.
> * @kset: kset the directory is belongs to.
> @@ -616,6 +662,71 @@
> kobject_unregister(&k->kobj);
> }
>
> +static int kobject_set_name_vargs(struct kobject *kobj, const char
> *fmt,
> + va_list vargs)
> +{
> + va_list aq;
> + char *name;
> +
> + va_copy(aq, vargs);
> + name = kvasprintf(GFP_KERNEL, fmt, vargs);
> + va_end(aq);
> +
> + if (!name)
> + return -ENOMEM;
> +
> + /* Free the old name, if necessary. */
> + kfree(kobj->k_name);
> +
> + /* Now, set the new name */
> + kobj->k_name = name;
> +
> + return 0;
> +}
> +
> +
> +static int kobject_add_varg(struct kobject *kobj, struct kobject
> *parent,
> + const char *fmt, va_list vargs)
> +{
> + va_list aq;
> + int retval;
> +
> + va_copy(aq, vargs);
> + retval = kobject_set_name_vargs(kobj, fmt, aq);
> + va_end(aq);
> + if (retval) {
> + printk(KERN_ERR "kobject: can not set name properly!
> \n");
> + return retval;
> + }
> + kobj->parent = parent;
> + //return kobject_add_internal(kobj);
> + return kobject_add(kobj);
> +}
> +
> +int kobject_add_android(struct kobject *kobj, struct kobject *parent,
> + const char *fmt, ...)
> +{
> + va_list args;
> + int retval;
> +
> + if (!kobj)
> + return -EINVAL;
> +
> +#if 0
> + if (!kobj->state_initialized) {
> + printk(KERN_ERR "kobject '%s' (%p): tried to add an "
> + "uninitialized object, something is seriously
> wrong.\n",
> + kobject_name(kobj), kobj);
> + dump_stack();
> + return -EINVAL;
> + }
> +#endif
> + va_start(args, fmt);
> + retval = kobject_add_varg(kobj, parent, fmt, args);
> + va_end(args);
> +
> + return retval;
> +}
>
> /**
> * kset_find_obj - search for object in kset.
> @@ -679,6 +790,71 @@
> return error;
> }
> +void kobject_init_android(struct kobject *kobj, struct kobj_type
> *ktype)
> +{
> + char *err_str;
> +
> + if (!kobj) {
> + err_str = "invalid kobject pointer!";
> + goto error;
> + }
> + if (!ktype) {
> + err_str = "must have a ktype to be initialized
> properly!\n";
> + goto error;
> + }
> +#if 0
> + if (kobj->state_initialized) {
> + /* do not error out as sometimes we can recover */
> + printk(KERN_ERR "kobject (%p): tried to init an
> initialized "
> + "object, something is seriously wrong.\n",
> kobj);
> + dump_stack();
> + }
> +#endif
> + // kobject_init_internal(kobj);
> + kobject_init(kobj);
> + kobj->ktype = ktype;
> + return;
> +
> +error:
> + printk("kobject (%p): %s\n", kobj, err_str);
> + dump_stack();
> +}
> +EXPORT_SYMBOL(kobject_init_android);
> +
> +
> +struct kobject *kobject_create(void)
> +{
> + struct kobject *kobj;
> +
> + kobj = kzalloc(sizeof(*kobj), GFP_KERNEL);
> + if (!kobj)
> + return NULL;
> +
> + kobject_init_android(kobj, &dynamic_kobj_ktype);
> + return kobj;
> +}
> +
> +struct kobject *kobject_create_and_add(const char *name, struct
> kobject *parent)
> +{
> + struct kobject *kobj;
> + int retval;
> +
> + kobj = kobject_create();
> + if (!kobj)
> + return NULL;
> +
> + retval = kobject_add_android(kobj, parent, "%s", name);
> + // retval = kobject_add(kobj);
> + if (retval) {
> + printk(KERN_WARNING "%s: kobject_add error: %d\n",
> + __FUNCTION__, retval);
> + kobject_put(kobj);
> + kobj = NULL;
> + }
> + return kobj;
> +}
> +EXPORT_SYMBOL_GPL(kobject_create_and_add);
> +
> EXPORT_SYMBOL(kobject_init);
> EXPORT_SYMBOL(kobject_register);
> EXPORT_SYMBOL(kobject_unregister);
>
> Warm Regards,
> Deepak
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Android Internals" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-internals?hl=en
-~----------~----~----~----~------~----~------~--~---