From 2084c82df834a4d9882a1878510577e1aa715ee3 Mon Sep 17 00:00:00 2001 From: Tzafrir Cohen Date: Wed, 23 May 2012 12:39:07 +0000 Subject: dahdi_ioctl_spanstat() backward compat hack Signed-off-by: Shaun Ruffell Acked-by: Tzafrir Cohen git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@10686 a0bf4364-ded3-4de4-8d8a-66a801d63aff --- drivers/dahdi/dahdi-base.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/drivers/dahdi/dahdi-base.c b/drivers/dahdi/dahdi-base.c index 85dafd0..70edabc 100644 --- a/drivers/dahdi/dahdi-base.c +++ b/drivers/dahdi/dahdi-base.c @@ -4361,8 +4361,39 @@ static int dahdi_ioctl_spanstat(struct file *file, unsigned long data) sizeof(spaninfo.location)); } if (s->spantype) { - strlcpy(spaninfo.spantype, dahdi_spantype2str(s->spantype), - sizeof(spaninfo.spantype)); + /* + * The API is brain-damaged, returning fixed length + * null terminated strings via ioctl() is... + * + * This field contain only 6 characters + * (including null termination, 5 effective characters). + * + * For backward compatibility, massage this info for dahdi-scan + * and friends, until: + * - They either learn to read the info from sysfs + * - Or this API is broken to return the enum value + */ + const char *st = dahdi_spantype2str(s->spantype); + switch (s->spantype) { + case SPANTYPE_DIGITAL_BRI_NT: + strlcpy(spaninfo.spantype, "NT", + sizeof(spaninfo.spantype)); + break; + case SPANTYPE_DIGITAL_BRI_TE: + strlcpy(spaninfo.spantype, "TE", + sizeof(spaninfo.spantype)); + break; + default: + /* + * The rest are either short (FXS, FXO, E1, T1, J1) + * Or new (BRI_SOFT, ANALOG_MIXED, INVALID), + * so no backward compatibility for this + * broken interface. + */ + strlcpy(spaninfo.spantype, st, + sizeof(spaninfo.spantype)); + break; + } } if (copy_to_user((void __user *)data, &spaninfo, size_to_copy)) -- cgit v1.2.3