From: <mr...@us...> - 2003-08-28 21:07:25
|
Update of /cvsroot/ltp/ltp/testcases/kernel/device-drivers/usb/user_usb In directory sc8-pr-cvs1:/tmp/cvs-serv24279 Modified Files: user_tusb.c Log Message: updates for 2.5.73 kernel Index: user_tusb.c =================================================================== RCS file: /cvsroot/ltp/ltp/testcases/kernel/device-drivers/usb/user_usb/user_tusb.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- user_tusb.c 10 Jun 2003 20:08:40 -0000 1.1 +++ user_tusb.c 28 Aug 2003 21:07:21 -0000 1.2 @@ -1,31 +1,86 @@ #include <fcntl.h> #include <stdlib.h> #include <stdio.h> +#include <errno.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <linux/kernel.h> +#include <linux/errno.h> #include "../tusb/tusb.h" static int tusb_fd = -1; //file descriptor int tusbopen() { - struct stat st; //for test exist tusb driver - - /* - * Make sure the tusb driver is up - */ - if (stat("/dev/tusb", &st)) { - printf("\tFailed to find tusb driver\n"); - return 1; - } - if ((tusb_fd = open("/dev/tusb", O_RDWR)) < 0) { - printf("\tFailed opening tusb driver\n"); - return 1; - } + dev_t devt; + struct stat st; + int rc = 0; + + devt = makedev(TUSB_MAJOR, 0); + + if (rc) { + if (errno == ENOENT) { + /* dev node does not exist. */ + rc = mkdir(DEVICE_NAME, (S_IFDIR | S_IRWXU | + S_IRGRP | S_IXGRP | + S_IROTH | S_IXOTH)); + } else { + printf("ERROR: Problem with Base dev directory. Error code from stat() is %d\n\n", errno); + } + + } else { + if (!(st.st_mode & S_IFDIR)) { + rc = unlink(DEVICE_NAME); + if (!rc) { + rc = mkdir(DEVICE_NAME, (S_IFDIR | S_IRWXU | + S_IRGRP | S_IXGRP | + S_IROTH | S_IXOTH)); + } + } + } + + + /* + * Check for the /dev/tbase node, and create if it does not + * exist. + */ + rc = stat(DEVICE_NAME, &st); + if (rc) { + if (errno == ENOENT) { + /* dev node does not exist */ + rc = mknod(DEVICE_NAME, (S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP), devt); + } else { + printf("ERROR:Problem with tbase device node directory. Error code form stat() is %d\n\n", errno); + } + + } else { + /* + * /dev/tbase CHR device exists. Check to make sure it is for a + * block device and that it has the right major and minor. + */ + if ((!(st.st_mode & S_IFCHR)) || + (st.st_rdev != devt)) { + + /* Recreate the dev node. */ + rc = unlink(DEVICE_NAME); + if (!rc) { + rc = mknod(DEVICE_NAME, (S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP), devt); + } + } + } + + tusb_fd = open(DEVICE_NAME, O_RDWR); + + if (tusb_fd < 0) { + printf("ERROR: Open of device %s failed %d errno = %d\n", DEVICE_NAME,tusb_fd, errno); + return errno; + } + else { + printf("Device opened successfully \n"); + return 0; + } - return 0; } int |