mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jesper Juhl <juhl-lkml@dif.dk>
To: Stephen Hemminger <shemminger@osdl.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	Nico Schottelius <nico-kernel@schottelius.org>,
	Paulo Marques <pmarques@grupopie.com>,
	Martin Waitz <tali@admingilde.org>
Subject: [PATCH] add sysfs attribute 'carrier' for net devices - try 2.
Date: Tue, 28 Sep 2004 21:23:25 +0200 (CEST)	[thread overview]
Message-ID: <Pine.LNX.4.61.0409282118340.2729@dragon.hygekrogen.localhost> (raw)
In-Reply-To: <Pine.LNX.4.61.0409281316191.22088@jjulnx.backbone.dif.dk>

On Tue, 28 Sep 2004, Jesper Juhl wrote:

> On Mon, 27 Sep 2004, Stephen Hemminger wrote:
> 
> > Date: Mon, 27 Sep 2004 10:29:13 -0700
> > From: Stephen Hemminger <shemminger@osdl.org>
> > To: Jesper Juhl <juhl-lkml@dif.dk>
> > Cc: linux-kernel <linux-kernel@vger.kernel.org>,
> >     Nico Schottelius <nico-kernel@schottelius.org>
> > Subject: Re: [PATCH] add sysfs attribute 'carrier' for net devices
> > 
> > On Mon, 2004-09-27 at 00:51 +0200, Jesper Juhl wrote:
> > >  
> > > +static ssize_t show_carrier(struct class_device *dev, char *buf)
> > > +{
> > > +	struct net_device *net = to_net_dev(dev);
> > > +	if (netif_running(net)) {
> > > +		if (netif_carrier_ok(net))
> > > +			return snprintf(buf, 3, "%d\n", 1);
> > > +		else
> > > +			return snprintf(buf, 3, "%d\n", 0);
> > 
> > Using snprintf in this way is kind of silly. since buffer is PAGESIZE.
> > The most concise format of this would be:
> > 	return sprintf(buf, dec_fmt, !!netif_carrier_ok(dev));
> > 
> 
> I see your point and I'll create a new patch this evening when I get home 
> from work.
> Thank you for your feedback.
> 

Here's a second try at a patch to properly implement a 'carrier' sysfs 
attribute for net devices.

Signed-off-by: Jesper Juhl <juhl-lkml@dif.dk>

diff -u linux-2.6.9-rc2-bk14-orig/net/core/net-sysfs.c linux-2.6.9-rc2-bk14/net/core/net-sysfs.c
--- linux-2.6.9-rc2-bk14-orig/net/core/net-sysfs.c	2004-09-14 23:19:53.000000000 +0200
+++ linux-2.6.9-rc2-bk14/net/core/net-sysfs.c	2004-09-28 19:37:45.000000000 +0200
@@ -126,8 +126,18 @@
 	return -EINVAL;
 }
 
+static ssize_t show_carrier(struct class_device *dev, char *buf)
+{
+	struct net_device *netdev = to_net_dev(dev);
+	if (netif_running(netdev)) {
+		return sprintf(buf, fmt_dec, !!netif_carrier_ok(netdev));
+	}
+	return -EINVAL;
+}
+
 static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
 static CLASS_DEVICE_ATTR(broadcast, S_IRUGO, show_broadcast, NULL);
+static CLASS_DEVICE_ATTR(carrier, S_IRUGO, show_carrier, NULL);
 
 /* read-write attributes */
 NETDEVICE_SHOW(mtu, fmt_dec);
@@ -186,6 +196,7 @@
 	&class_device_attr_type,
 	&class_device_attr_address,
 	&class_device_attr_broadcast,
+	&class_device_attr_carrier,
 	NULL
 };
 


  reply	other threads:[~2004-09-28 19:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20041021112750.GN15294@schottelius.org>
     [not found] ` <Pine.LNX.4.61.0410221744500.15769@jjulnx.backbone.dif.dk>
     [not found]   ` <Pine.LNX.4.61.0410231216110.3151@dragon.hygekrogen.localhost>
2004-09-26 22:51     ` [PATCH] add sysfs attribute 'carrier' for net devices Jesper Juhl
2004-09-27 17:29       ` Stephen Hemminger
2004-09-28 11:18         ` Jesper Juhl
2004-09-28 19:23           ` Jesper Juhl [this message]
2004-09-28 19:22             ` [PATCH] add sysfs attribute 'carrier' for net devices - try 2 Stephen Hemminger
2004-09-28 20:54             ` Nico Schottelius
2004-09-28 22:24               ` Stephen Hemminger
2004-09-29  6:54                 ` Nico Schottelius
2004-09-28 12:10         ` [PATCH] add sysfs attribute 'carrier' for net devices Paulo Marques
2004-09-28 16:09           ` Martin Waitz
2004-10-23 18:49             ` Nico Schottelius

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=Pine.LNX.4.61.0409282118340.2729@dragon.hygekrogen.localhost \
    --to=juhl-lkml@dif.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nico-kernel@schottelius.org \
    --cc=pmarques@grupopie.com \
    --cc=shemminger@osdl.org \
    --cc=tali@admingilde.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

all inboxes | Powered by JetHome®