Re: [PATCH 1/8] LinuxPPS core support.

From: Rodolfo Giometti
Date: Mon Feb 11 2008 - 13:40:23 EST


On Mon, Feb 11, 2008 at 07:31:53PM +0100, Rodolfo Giometti wrote:
> Do you think is better create these files anyway and in case report a
> NULL string?

Is that ok?

/*
* Attribute functions
*/

static ssize_t pps_show_assert(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct pps_device *pps = dev_get_drvdata(dev);

if (!(pps->info.mode & PPS_CAPTUREASSERT))
return 0;

return sprintf(buf, "%lld.%09d#%d\n",
pps->assert_tu.sec, pps->assert_tu.nsec,
pps->assert_sequence);
}
DEVICE_ATTR(assert, S_IRUGO, pps_show_assert, NULL);

static ssize_t pps_show_clear(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct pps_device *pps = dev_get_drvdata(dev);

if (!(pps->info.mode & PPS_CAPTURECLEAR))
return 0;

return sprintf(buf, "%lld.%09d#%d\n",
pps->clear_tu.sec, pps->clear_tu.nsec,
pps->clear_sequence);
}
DEVICE_ATTR(clear, S_IRUGO, pps_show_clear, NULL);

static ssize_t pps_show_mode(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct pps_device *pps = dev_get_drvdata(dev);

return sprintf(buf, "%4x\n", pps->info.mode);
}
DEVICE_ATTR(mode, S_IRUGO, pps_show_mode, NULL);

...

static struct attribute *pps_attrs[] = {
&dev_attr_mode.attr,
&dev_attr_echo.attr,
&dev_attr_name.attr,
&dev_attr_path.attr,
&dev_attr_assert.attr,
&dev_attr_clear.attr,
NULL
};

static struct attribute_group pps_group = {
.attrs = pps_attrs,
};

/*
* Public functions
*/

void pps_sysfs_remove_source_entry(struct pps_device *pps)
{
/* Delete info files */
sysfs_remove_group(&pps->dev->kobj, &pps_group);
}

int pps_sysfs_create_source_entry(struct pps_device *pps)
{
int ret;

/* Create info files */
ret = sysfs_create_group(&pps->dev->kobj, &pps_group);
if (ret)
dev_err(pps->dev, "unable to create default sysfs entries");

return 0;
}

Ciao,

Rodolfo

--

GNU/Linux Solutions e-mail: giometti@xxxxxxxxxxxx
Linux Device Driver giometti@xxxxxxxxx
Embedded Systems giometti@xxxxxxxx
UNIX programming phone: +39 349 2432127
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/