lib: add fdelay_open_by_lun function

At CERN controls installations, devices of the same class are
enumerated by a statically defined number known as LUN (logical
unit number), that maps into geographical information via
database entries. These are mapped through userspace programs
and stored as tags in device node names.

This patch adds a function to exploit this numbering
parent 537671c0
......@@ -164,6 +164,28 @@ found:
return (void *)b;
}
/* Open one specific device by logical unit number (CERN/CO-like) */
struct fdelay_board *fdelay_open_by_lun(int lun)
{
ssize_t ret;
char dev_id_str[4];
char path_pattern[] = "/dev/fine-delay.%d";
char path[sizeof(path_pattern) + 1];
int dev_id;
ret = snprintf(path, sizeof(path), path_pattern, lun);
if (ret < 0 || ret >= sizeof(path)) {
errno = EINVAL;
return NULL;
}
ret = readlink(path, dev_id_str, sizeof(dev_id_str));
if (sscanf(dev_id_str, "%4x", &dev_id) != 1) {
errno = ENODEV;
return NULL;
}
return fdelay_open(-1, dev_id);
}
int fdelay_close(struct fdelay_board *userb)
{
__define_board(b, userb);
......
......@@ -54,6 +54,7 @@ extern int fdelay_init(void);
extern void fdelay_exit(void);
extern struct fdelay_board *fdelay_open(int offset, int dev_id);
extern struct fdelay_board *fdelay_open_by_lun(int lun);
extern int fdelay_close(struct fdelay_board *);
extern int fdelay_set_time(struct fdelay_board *b, struct fdelay_time *t);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment