summaryrefslogtreecommitdiffstats
path: root/drivers/staging/usbip
diff options
context:
space:
mode:
authormatt mooney <mfm@muteddisk.com>2011-06-19 22:44:41 -0700
committerGreg Kroah-Hartman <gregkh@suse.de>2011-07-05 20:11:34 -0700
commit30f0554659d277e126c1194b8c1edf5dc6e56914 (patch)
tree012ddf996c12c9b35f4ccf7d7fa606c3559b7778 /drivers/staging/usbip
parent42685d577f569a0c06b35cf0739fcb20bfe9acd8 (diff)
downloadlinux-0-day-30f0554659d277e126c1194b8c1edf5dc6e56914.tar.gz
linux-0-day-30f0554659d277e126c1194b8c1edf5dc6e56914.tar.xz
staging: usbip: userspace: utils.c: rewrite modify_match_busid
Rewrite the function to use libsysfs. Signed-off-by: matt mooney <mfm@muteddisk.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/usbip')
-rw-r--r--drivers/staging/usbip/userspace/src/utils.c68
1 files changed, 40 insertions, 28 deletions
diff --git a/drivers/staging/usbip/userspace/src/utils.c b/drivers/staging/usbip/userspace/src/utils.c
index 9b31c781dc9ef..2d4966e6289c6 100644
--- a/drivers/staging/usbip/userspace/src/utils.c
+++ b/drivers/staging/usbip/userspace/src/utils.c
@@ -1,64 +1,76 @@
/*
+ * Copyright (C) 2011 matt mooney <mfm@muteddisk.com>
+ * 2005-2007 Takahiro Hirofuchi
*
- * Copyright (C) 2005-2007 Takahiro Hirofuchi
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sysfs/libsysfs.h>
-#include <limits.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
-#include <fcntl.h>
-#include <libgen.h>
-#include <unistd.h>
-
#include "usbip_common.h"
#include "utils.h"
int modify_match_busid(char *busid, int add)
{
- int fd;
- int ret;
+ char bus_type[] = "usb";
+ char attr_name[] = "match_busid";
char buff[SYSFS_BUS_ID_SIZE + 4];
char sysfs_mntpath[SYSFS_PATH_MAX];
- char match_busid_path[SYSFS_PATH_MAX];
+ char match_busid_attr_path[SYSFS_PATH_MAX];
+ struct sysfs_attribute *match_busid_attr;
+ int rc, ret = 0;
- ret = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
- if (ret < 0) {
- err("sysfs must be mounted");
+ if (strnlen(busid, SYSFS_BUS_ID_SIZE) > SYSFS_BUS_ID_SIZE - 1) {
+ dbg("busid is too long");
return -1;
}
- snprintf(match_busid_path, sizeof(match_busid_path),
- "%s/%s/usb/%s/%s/match_busid", sysfs_mntpath, SYSFS_BUS_NAME,
- SYSFS_DRIVERS_NAME, USBIP_HOST_DRV_NAME);
-
- /* BUS_IS_SIZE includes NULL termination? */
- if (strnlen(busid, SYSFS_BUS_ID_SIZE) > SYSFS_BUS_ID_SIZE - 1) {
- dbg("busid is too long");
+ rc = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
+ if (rc < 0) {
+ err("sysfs must be mounted: %s", strerror(errno));
return -1;
}
- fd = open(match_busid_path, O_WRONLY);
- if (fd < 0)
+ snprintf(match_busid_attr_path, sizeof(match_busid_attr_path),
+ "%s/%s/%s/%s/%s/%s", sysfs_mntpath, SYSFS_BUS_NAME, bus_type,
+ SYSFS_DRIVERS_NAME, USBIP_HOST_DRV_NAME, attr_name);
+
+ match_busid_attr = sysfs_open_attribute(match_busid_attr_path);
+ if (!match_busid_attr) {
+ dbg("problem getting match_busid attribute: %s",
+ strerror(errno));
return -1;
+ }
if (add)
snprintf(buff, SYSFS_BUS_ID_SIZE + 4, "add %s", busid);
else
snprintf(buff, SYSFS_BUS_ID_SIZE + 4, "del %s", busid);
- dbg("write \"%s\" to %s", buff, match_busid_path);
+ dbg("write \"%s\" to %s", buff, match_busid_attr->path);
- ret = write(fd, buff, sizeof(buff));
- if (ret < 0) {
- close(fd);
- return -1;
+ rc = sysfs_write_attribute(match_busid_attr, buff, sizeof(buff));
+ if (rc < 0) {
+ dbg("failed to write match_busid: %s", strerror(errno));
+ ret = -1;
}
- close(fd);
+ sysfs_close_attribute(match_busid_attr);
- return 0;
+ return ret;
}