23 #include <linux/device.h>
26 #include <linux/list.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
30 #include <linux/slab.h>
34 static struct class enclosure_class;
103 error =
fn(edev, data);
140 edev->
edev.class = &enclosure_class;
184 edev->
cb = &enclosure_null_callbacks;
189 #define ENCLOSURE_NAME_SIZE 64
193 strcpy(name,
"enclosure_device:");
201 enclosure_link_name(cdev, name);
215 enclosure_link_name(cdev, name);
223 static void enclosure_release(
struct device *cdev)
231 static void enclosure_component_release(
struct device *
dev)
236 enclosure_remove_links(cdev);
284 cdev->
release = enclosure_component_release;
285 cdev->
groups = enclosure_groups;
322 if (cdev->
dev == dev)
326 enclosure_remove_links(cdev);
330 return enclosure_add_links(cdev);
352 if (cdev->
dev == dev) {
353 enclosure_remove_links(cdev);
368 static ssize_t enclosure_show_components(
struct device *cdev,
382 static struct class enclosure_class = {
385 .dev_release = enclosure_release,
386 .dev_attrs = enclosure_attrs,
401 static const char *
const enclosure_type [] = {
412 if (edev->
cb->get_fault)
413 edev->
cb->get_fault(edev, ecomp);
419 const char *buf,
size_t count)
425 if (edev->
cb->set_fault)
426 edev->
cb->set_fault(edev, ecomp, val);
436 if (edev->
cb->get_status)
437 edev->
cb->get_status(edev, ecomp);
438 return snprintf(buf, 40,
"%s\n", enclosure_status[ecomp->
status]);
443 const char *buf,
size_t count)
449 for (i = 0; enclosure_status[
i]; i++) {
450 if (
strncmp(buf, enclosure_status[i],
451 strlen(enclosure_status[i])) == 0 &&
452 (buf[
strlen(enclosure_status[i])] ==
'\n' ||
453 buf[
strlen(enclosure_status[i])] ==
'\0'))
457 if (enclosure_status[i] && edev->
cb->set_status) {
458 edev->
cb->set_status(edev, ecomp, i);
470 if (edev->
cb->get_active)
471 edev->
cb->get_active(edev, ecomp);
477 const char *buf,
size_t count)
483 if (edev->
cb->set_active)
484 edev->
cb->set_active(edev, ecomp, val);
494 if (edev->
cb->get_locate)
495 edev->
cb->get_locate(edev, ecomp);
501 const char *buf,
size_t count)
507 if (edev->
cb->set_locate)
508 edev->
cb->set_locate(edev, ecomp, val);
517 return snprintf(buf, 40,
"%s\n", enclosure_type[ecomp->
type]);
522 set_component_fault);
524 set_component_status);
526 set_component_active);
528 set_component_locate);
531 static struct attribute *enclosure_component_attrs[] = {
532 &dev_attr_fault.attr,
533 &dev_attr_status.attr,
534 &dev_attr_active.attr,
535 &dev_attr_locate.attr,
541 .attrs = enclosure_component_attrs,
549 static int __init enclosure_init(
void)
560 static void __exit enclosure_exit(
void)