mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usbutils.git
synced 2024-11-27 05:43:49 +08:00
Move read_sysfs_prop() from names.c to its own file
This function was added to names.c by commit dddb696e01
("lsusb: Read
unkown names from sysfs device desc."), but it doesn't really belong
there: sysfs is an entirely different data source from the udev hwdb
that names.c works with, and this function both does things (like
directly accessing files) that other functions in names.c don't and
doesn't do things (like depending on the work done by names_init()) that
those other functions do.
Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
This commit is contained in:
parent
c92f196289
commit
c37f33cf31
@ -31,6 +31,7 @@ lsusb_SOURCES = \
|
||||
desc-defs.c desc-defs.h \
|
||||
desc-dump.c desc-dump.h \
|
||||
names.c names.h \
|
||||
sysfs.c sysfs.h \
|
||||
usb-spec.h \
|
||||
usbmisc.c usbmisc.h
|
||||
|
||||
|
1
lsusb.c
1
lsusb.c
@ -27,6 +27,7 @@
|
||||
|
||||
#include "lsusb.h"
|
||||
#include "names.h"
|
||||
#include "sysfs.h"
|
||||
#include "usbmisc.h"
|
||||
#include "desc-defs.h"
|
||||
#include "desc-dump.h"
|
||||
|
24
names.c
24
names.c
@ -20,7 +20,6 @@
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <linux/limits.h>
|
||||
|
||||
#include <libudev.h>
|
||||
|
||||
@ -32,8 +31,6 @@
|
||||
#define HASH2 0x02
|
||||
#define HASHSZ 512
|
||||
|
||||
#define SYSFS_DEV_ATTR_PATH "/sys/bus/usb/devices/%d-%d/%s"
|
||||
|
||||
static unsigned int hashnum(unsigned int num)
|
||||
{
|
||||
unsigned int mask1 = HASH1 << 27, mask2 = HASH2 << 27;
|
||||
@ -406,27 +403,6 @@ static void print_tables(void)
|
||||
}
|
||||
*/
|
||||
|
||||
int read_sysfs_prop(char *buf, size_t size, uint8_t bnum, uint8_t pnum, char *propname)
|
||||
{
|
||||
int n, fd;
|
||||
char path[PATH_MAX];
|
||||
|
||||
buf[0] = '\0';
|
||||
snprintf(path, sizeof(path), SYSFS_DEV_ATTR_PATH, bnum, pnum, propname);
|
||||
fd = open(path, O_RDONLY);
|
||||
|
||||
if (fd == -1)
|
||||
return 0;
|
||||
|
||||
n = read(fd, buf, size);
|
||||
|
||||
if (n > 0)
|
||||
buf[n-1] = '\0'; // Turn newline into null terminator
|
||||
|
||||
close(fd);
|
||||
return n;
|
||||
}
|
||||
|
||||
int names_init(void)
|
||||
{
|
||||
int r;
|
||||
|
2
names.h
2
names.h
@ -32,8 +32,6 @@ extern int get_product_string(char *buf, size_t size, uint16_t vid, uint16_t pid
|
||||
extern int get_class_string(char *buf, size_t size, uint8_t cls);
|
||||
extern int get_subclass_string(char *buf, size_t size, uint8_t cls, uint8_t subcls);
|
||||
|
||||
extern int read_sysfs_prop(char *buf, size_t size, uint8_t bnum, uint8_t pnum, char *propname);
|
||||
|
||||
extern int names_init(void);
|
||||
extern void names_exit(void);
|
||||
|
||||
|
36
sysfs.c
Normal file
36
sysfs.c
Normal file
@ -0,0 +1,36 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Helpers for querying USB properties from sysfs
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <linux/limits.h>
|
||||
|
||||
#include "sysfs.h"
|
||||
|
||||
#define SYSFS_DEV_ATTR_PATH "/sys/bus/usb/devices/%d-%d/%s"
|
||||
|
||||
int read_sysfs_prop(char *buf, size_t size, uint8_t bnum, uint8_t pnum, char *propname)
|
||||
{
|
||||
int n, fd;
|
||||
char path[PATH_MAX];
|
||||
|
||||
buf[0] = '\0';
|
||||
snprintf(path, sizeof(path), SYSFS_DEV_ATTR_PATH, bnum, pnum, propname);
|
||||
fd = open(path, O_RDONLY);
|
||||
|
||||
if (fd == -1)
|
||||
return 0;
|
||||
|
||||
n = read(fd, buf, size);
|
||||
|
||||
if (n > 0)
|
||||
buf[n-1] = '\0'; // Turn newline into null terminator
|
||||
|
||||
close(fd);
|
||||
return n;
|
||||
}
|
13
sysfs.h
Normal file
13
sysfs.h
Normal file
@ -0,0 +1,13 @@
|
||||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Helpers for querying USB properties from sysfs
|
||||
*/
|
||||
|
||||
#ifndef _SYSFS_H
|
||||
#define _SYSFS_H
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
extern int read_sysfs_prop(char *buf, size_t size, uint8_t bnum, uint8_t pnum, char *propname);
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
#endif /* _SYSFS_H */
|
Loading…
Reference in New Issue
Block a user