int GetStorageMessage(PUsbInfo usbinfor) { int iRet = 0; char DevName[MAX_STRING_LEN] = {0}; iRet = getDevName(DevName); if(iRet != 0 || strlen(DevName) <= 0) { fprintf(stderr, "can not get the device name\n"); return -6; } //we only do operation on not /dev/sda disks if(strncmp(DevName, "sda", strlen("sda")) == 0) return -6; if(strncmp(DevName, "sd", strlen("sd")) != 0) return -6; sprintf(usbinfor->devName,"/dev/%s", DevName); if(strlen(usbinfor->devName) <= 0) return -6; iRet = getMountPointandFileType(usbinfor->devName, usbinfor->mountpoint, usbinfor->filesystemtype); if(iRet == 0) { iRet = GetSpaceInfo(usbinfor->devName,&(usbinfor->capacity), &(usbinfor->usedspace), &(usbinfor->freespace)); if(iRet != 0) iRet = -6; } else iRet = -6; return iRet; }
int SerialImpl::open() { //m_fd = ::open (getDevName(), O_RDWR | O_NOCTTY, O_NONBLOCK); // non-blocking mode m_fd = ::open (getDevName(), O_RDWR | O_NOCTTY); if (0 > m_fd) { kuDebug (kuERR, "[SerialImpl::open] open failed : dev(%s) baud(%d)\n", getDevName(), getBaudRate()); return (kuNOK); } struct termios oldtio, newtio; // stores current setting to vairable if (0 > tcgetattr (m_fd, &oldtio)) { kuDebug (kuERR, "[SerialImpl::open] dev(%s) tcgetattr failed\n", getDevName()); //return (kuNOK); } bzero(&newtio, sizeof(newtio)); newtio.c_cflag = CS8; // 8N1 (8bit, no parity, 1stopbit) newtio.c_cflag |= CLOCAL; // local connection newtio.c_cflag |= CREAD; // enable reading // newtio.c_cflag |= CRTSCTS; // H/W flow control newtio.c_cflag &= ~CRTSCTS; // disable flow control. 2013. 12. 2 by woong newtio.c_cflag |= getBaudRate(); // baud rate : (ex) B115200 newtio.c_iflag = IGNPAR; // non-parity newtio.c_oflag = 0; newtio.c_lflag = 0; // input mode (non-canonical, no echo, ...) // timeout is 5 seconds newtio.c_cc[VTIME] = 50; // timeout : TIME * 0.1 sec newtio.c_cc[VMIN] = 0; // blocking if (0 > tcflush (m_fd, TCIFLUSH)) { kuDebug (kuERR, "[SerialImpl::open] dev(%s) tcflush failed\n", getDevName()); //return (kuNOK); } if (0 > tcsetattr (m_fd, TCSANOW, &newtio)) { kuDebug (kuERR, "[SerialImpl::open] dev(%s) tcsetattr failed\n", getDevName()); //return (kuNOK); } // duplicates fd to read and write concurrently among threads m_readFd = dup(m_fd); kuDebug (kuDEBUG, "[SerialImpl::open] dup(%d/%d)\n", m_fd, m_readFd); kuDebug (kuINFO, "[SerialImpl::open] dev(%s) was opened\n", getDevName()); return (kuOK); }
int SerialImpl::close() { if (isOpened()) { if (0 <= getFd()) { ::close (getFd()); setFd(-1); } if (0 <= getReadFd()) { ::close (getReadFd()); setReadFd(-1); } kuDebug (kuINFO, "[SerialImpl::close] dev(%s) was closed\n", getDevName()); } return (kuOK); }
int SerialImpl::write(void * buf, int size) { if ( (NULL == buf) || (0 >= size) ) { kuDebug (kuERR, "[SerialImpl::read] input is invalid \n"); return (kuNOK); } if (kuTRUE == kuCanPrint (kuDATA)) { kuDebug (kuMON, "[SerialImpl::write] dev(%s) ----------------------\n", m_strDevName.c_str()); kuStd::dump (size, (char *)buf); } if (size != writeWithControl (getFd(), (char *)buf, size)) { return (kuNOK); } kuDebug (kuTRACE, "[SerialImpl::write] dev(%s) : writes(%d)\n", getDevName(), size); return (kuOK); }
void *hotPlugThread(void *param) { int i = 0; int ret = 0; char buf[1024] = {0}; char devName[128] = {0}; char devPath[124] = {0}; char mountPath[128] = {0}; char cmd[128] = {0}; int hotplug_sock; int sum,size; char *str; #if 0 unsigned char uuid[16] = {0}; setDiskVolumeName("/dev/sda1", "abcd"); getDiskPartitionInfo("/dev/sda1", uuid, NULL, NULL); checkFallocateFile("/disk/disk0000", 1024*1024*1024); #endif hotplug_sock = init_hotplug_sock(); while(1) { sum = 0; memset(buf, 0, sizeof(buf)); size = recv(hotplug_sock, buf, sizeof(buf), 0); // fprintf(stderr,"size=%d, buf=[%s], strlen(buf)=%d\n", size, buf, strlen(buf)); while(sum < size) { str = buf + sum; sum += strlen(str); buf[sum] = '\n'; } buf[sum] = 0; // fprintf(stderr,"buf=[%s]\n\n", buf); if(((strstr(buf, "ACTION=add") != NULL) && (strstr(buf, "DEVTYPE=disk") != NULL))||((strstr(buf, "ACTION=add") != NULL) && (strstr(buf, "DEVTYPE=partition") != NULL))) { if((strstr(buf, "NPARTS=0") != NULL) || (strstr(buf, "PARTN=") != NULL)) { memset(devName, 0, sizeof(devName)); if(getDevName(buf, devName) == 0) { fprintf(stderr,"add devName = [%s]\r\n", devName); if(strstr(buf, "DEVPATH=/devices/platform/hiusb-ehci") != NULL) {//u盘 for(i = 0; i < 8; i++) { sprintf(devPath, "/dev/%s", devName); sprintf(mountPath, "/usb/usb%04d", i); ret = checkDiskPartitionIsMount(devPath, mountPath); if(ret == 0x00) { sprintf(cmd, "mount %s %s", devPath, mountPath); ret=pox_system(cmd); ret=iCheckSystemReturnValue(ret); if(0!=ret) continue; } else if(ret == 0x03) { break; } } } } } } if(((strstr(buf,"ACTION=remove")!=NULL) && (strstr(buf, "DEVTYPE=disk") != NULL))||((strstr(buf, "ACTION=remove") != NULL) && (strstr(buf, "DEVTYPE=partition") != NULL))) { if((strstr(buf, "NPARTS=0") != NULL) || (strstr(buf, "PARTN=") != NULL)) { if(getDevName(buf, devName) == 0) { printf("remove devName = [%s]\r\n", devName); if(strstr(buf, "DEVPATH=/devices/platform/hiusb-ehci") != NULL) {//u sprintf(devPath, "/dev/%s", devName); sprintf(cmd, "umount %s", devPath); int i ; for(i=0;i!=4;++i) { ret=pox_system(cmd); ret=iCheckSystemReturnValue(ret); if(0==ret) { break; } fprintf(stderr,"remove devName = [%s] fail \r\n", devName); sleep(1); } umount(devPath); umount(devPath); } else if(strstr(buf, "DEVPATH=/devices/platform/ahci") != NULL) {//sata硬盘 fprintf(stderr , "\n===============%s \n", buf); sprintf(devPath, "/dev/%s", devName); sprintf(cmd, "umount -f %s", devPath); fprintf(stderr, "================cmd %s \n", cmd); system(cmd); system(cmd); } else { umount("/usb/usb0000"); umount("/usb/usb0001"); umount("/usb/usb0002"); umount("/usb/usb0003"); } } } } usleep(400*1000); } return NULL; }
void SerialImpl::printConfiguration () { kuDebug (kuINFO, "[SerialImpl::configuration] dev(%s) baud(%d)\n", getDevName(), getBaudRate()); }