LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-25-2010, 05:42 AM   #1
slyv
LQ Newbie
 
Registered: Nov 2010
Posts: 3

Rep: Reputation: 0
EOF in sysfs


Hi everybody,
i'm trying to write in a file (foo) using sysfs.
I'll post part of using code:

Code:
static char foo[1024];
static int baz;
static char bar[1024];

/*
 * The "foo" file where a static variable is read from and written to.
 */
static ssize_t foo_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf) {	
return sprintf(buf, "%s\n\n\n\n\n\n", foo);
}

static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr,
			 const char *buf, size_t count)
{
	sscanf(buf, "%s", &foo);
	return count;
}

static struct kobj_attribute foo_attribute =
	__ATTR(foo, 0666, foo_show, foo_store);
I need a help. When i write a string (using echo), it seems work. When i write another one, the new one OVERWRITE the old one. Can I avoid this problem?
I note that, after writing a string, when i open the file, the cursor is positioning at the begin of the file...
Can you help me?
 
Old 11-26-2010, 10:41 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
?WTF?

"sysfs" is essentially "/proc" and friends.

It's primarily for reading system information. And, of course, some entries are also writable (e.g. to update system configuration parameters on-the-fly).

So what exactly are you trying to do? Can you cut/paste specific code (without the "foo, bar, baz" stuff)?

PS:
Here's one example of how I'd use sysf. I'm curious how your ideas differ:
Code:
#include <stdio.h>

int
main ()
{
  FILE *fp = fopen ("/proc/cpuinfo", "r");
  if (!fp)
  {
    perror ("Unable to open /proc/cpuinfo");
    return 1;
  }
  while (!feof (fp))
  {
    char buf[80];
    char *s = fgets (buf, sizeof (buf), fp);
    if (s)
      printf(s);
  }
  fclose (fp);
  return 0;
}

Last edited by paulsm4; 11-26-2010 at 10:49 PM.
 
Old 11-27-2010, 05:08 PM   #3
jefro
Moderator
 
Registered: Mar 2008
Posts: 20,225

Rep: Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196Reputation: 3196
Darn backkey. Wrong thread.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sysfs use chessi Linux - Kernel 1 04-24-2007 03:59 PM
How to use sysfs? asahlot Linux - Kernel 1 01-21-2007 03:44 PM
Mounting sysfs ? mystique98ls Linux - Newbie 4 07-15-2005 11:33 AM
kernel 2.4.26 and sysfs rgiggs Mandriva 2 06-03-2004 08:32 PM
mounting sysfs chichibabin Mandriva 3 02-13-2004 12:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:58 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration