linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Stekloff <dsteklof@us.ibm.com>
To: linux-hotplug@vger.kernel.org
Subject: Re: [ANNOUNCE] udev 0.2 release
Date: Wed, 13 Aug 2003 09:35:36 +0000	[thread overview]
Message-ID: <marc-linux-hotplug-106080520422431@msgid-missing> (raw)
In-Reply-To: <marc-linux-hotplug-105917102320963@msgid-missing>


Thank you very much for the revised patch. We will put it into our tree. 

As for writing values to sysfs, sysfs files or attributes are sometimes 
writeable. You can write to them as you write to any file. For instance, I 
could have a "debug" file for my usb device driver. The driver could export 
the callback through sysfs as a file. Reading from the file returns the 
current "debug" state of the driver. Writing to the file would change the 
debug level for the driver. 

Is this what you were asking?

Thanks,

Dan


On Tuesday 12 August 2003 07:24 am, Guo, Min wrote:
> How to write value to sysfs? now sysfs is only readable.
>
> Thanks
> Guo Min
> -----Original Message-----
> From: Guo, Min
> Sent: Tuesday, August 12, 2003 3:19 PM
> To: 'Daniel Stekloff'
> Cc: linux-hotplug-devel@lists.sourceforge.net; Greg KH
> Subject: RE: [ANNOUNCE] udev 0.2 release
>
>
> Thanks!The revised path!
> ---------------------------------------------------------------------------
>------------------------------- diff -Nuar /udev/libsysfs/libsysfs.h
> /root/udev-0.2/libsysfs/libsysfs.h --- /udev/libsysfs/libsysfs.h	2003-07-19
> 03:06:48.000000000 +0800
> +++ /root/udev-0.2/libsysfs/libsysfs.h	2003-08-12 16:05:36.483706096 +0800
> @@ -124,6 +124,9 @@
>  extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
>  extern int sysfs_read_attribute_value(const char *attrpath, char *value,
>  								size_t vsize);
> +extern int sysfs_write_attribute(struct sysfs_attribute *sysattr);
> +extern int sysfs_write_attribute_value(const char *attrpath, char *value);
> +
>  extern char *sysfs_get_value_from_attributes(struct sysfs_attribute *attr,
>  							const char * name);
>  extern void sysfs_close_directory(struct sysfs_directory *sysdir);
> diff -Nuar /udev/libsysfs/sysfs_dir.c /root/udev-0.2/libsysfs/sysfs_dir.c
> --- /udev/libsysfs/sysfs_dir.c	2003-07-19 03:06:34.000000000 +0800
> +++ /root/udev-0.2/libsysfs/sysfs_dir.c	2003-08-12 16:07:45.000168624 +0800
> @@ -78,6 +78,43 @@
>
>  	return sysattr;
>  }
> +/**
> + * sysfs_write_attribute: write value to the attribute
> + * @sysattr: attribute to write
> + * returns 0 with success and -1 with error.
> + */
> +int sysfs_write_attribute(struct sysfs_attribute *sysattr)
> +{
> +	int fd;
> +	int length;
> +
> +	if (sysattr = NULL) {
> +		errno = EINVAL;
> +		return -1;
> +	}
> +
> +	if (!(sysattr->method & SYSFS_METHOD_STORE)) {
> +		dprintf (stderr, "Store method not supported for attribute %s\n",
> +			sysattr->path);
> +		return -1;
> +	}
> +
> +	if ((fd = open(sysattr->path, O_RDWR)) < 0) {
> +		dprintf (stderr, "Error reading attribute %s\n", sysattr->path);
> +		return -1;
> +	}
> +
> +	length = write(fd,sysattr->value,sizeof(sysattr->value));
> +	if (length < 0) {
> +		dprintf (stderr, "Error write to the attribute %s\n",
> +			sysattr->path);
> +		close(fd);
> +		return -1;
> +	}
> +	close(fd);
> +	return 0;
> +}
> +
>
>  /**
>   * sysfs_read_attribute: reads value from attribute
> @@ -134,6 +171,41 @@
>  }
>
>  /**
> + * sysfs_write_attribute_value: given path to attribute,
> + * value will be saved to the attribute.
> + * @attrpath: sysfs path to attribute
> + * @value: value to give to attribute
> + * returns 0 with success and -1 with error.
> + */
> +int sysfs_write_attribute_value(const char *attrpath, char *value)
> +{
> +	struct sysfs_attribute *attr = NULL;
> +
> +	if (attrpath = NULL || value = NULL) {
> +		errno = EINVAL;
> +		return -1;
> +	}
> +
> +	attr = sysfs_open_attribute(attrpath);
> +	if (attr = NULL) {
> +		dprintf(stderr, "Invalid attribute path %s\n", attrpath);
> +		errno = EINVAL;
> +		return -1;
> +	}
> +	strncpy(attr->value,value,sizeof(value));
> +	if((sysfs_write_attribute(attr) != 0 )){
> +		dprintf(stderr, "Error write to attribute %s\n", attrpath);
> +		sysfs_close_attribute(attr);
> +		return -1;
> +	}
> +
> +	sysfs_close_attribute(attr);
> +
> +	return 0;
> +}
> +
> +
> +/**
>   * sysfs_read_attribute_value: given path to attribute, return its value.
>   *	values can be up to a pagesize, if buffer is smaller the value will
>   *	be truncated.
> -----Original Message-----
> From: Daniel Stekloff [mailto:dsteklof@us.ibm.com]
> Sent: Tuesday, August 05, 2003 6:09 PM
> To: Guo, Min
> Cc: linux-hotplug-devel@lists.sourceforge.net; Greg KH
> Subject: RE: [ANNOUNCE] udev 0.2 release
>
>
>
> Hi Guo Min,
>
> Thank you very much for the patch. It's a good start. Some ideas:
>
> - sysfs_write_attribute needs to actually write the value out to the
> file/attribute. Use the path in sysfs_attribute.
>
>  - sysfs_write_attribute should probably only need the sysfs_attribute
> *sysattr as an argument, the value being already assigned to the
> sysfs_attribute.
>
> - sysfs_write_attribute_value could assign the value to the included
> sysfs_attribute and then call sysfs_write_attribute like you have it now.
>
> - Please look at sysfs_read_attribute as a guide.
>
> Thanks,
>
> Dan
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
> Linux-hotplug-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel




-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including
Data Reports, E-commerce, Portals, and Forums are available now.
Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

      parent reply	other threads:[~2003-08-13  9:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-25 21:47 [ANNOUNCE] udev 0.2 release Greg KH
2003-07-26  0:18 ` Joshua Schmidlkofer
2003-07-26 15:57 ` Greg KH
2003-07-31  7:46 ` Guo, Min
2003-07-31  7:47 ` Guo, Min
2003-07-31 23:04 ` Greg KH
2003-08-01  0:48 ` Guo, Min
2003-08-05  0:19 ` Greg KH
2003-08-05  2:22 ` Guo, Min
2003-08-05 10:08 ` Daniel Stekloff
2003-08-12  7:17 ` Guo, Min
2003-08-12  7:24 ` Guo, Min
2003-08-13  9:35 ` Daniel Stekloff [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=marc-linux-hotplug-106080520422431@msgid-missing \
    --to=dsteklof@us.ibm.com \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).