USB挂载小程序(无注释)
2017-04-05 09:45
218 查看
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <Linux/kernel>
static unsigned long get_file_size(const char *path)
{
struct stat statbuff;
if(stat(path, &statbuff) >= 0){
return statbuff.st_size;
}
return -1;
}
static unsigned int print_mount_point(void)
{
int fd = -1;
int size = 0;
int i = 0;
int j = 0;
char strBuf[100];
char *p;
system("cat /proc/mounts > ./.1.txt");
unsigned long fileSize = get_file_size("./.1.txt");
system("rm ./.1.txt");
char *buffer = (char *)malloc(fileSize + 1);
char *tmpBuf = (char *)malloc(fileSize + 1);
if(NULL == buffer || NULL == tmpBuf)
{
printf("%s malloc error \n", __func__);
return -1;
}
fd = open("/proc/mounts", O_RDONLY);
if(-1 == fd)
{
printf("%s open error \n", __func__);
return -1;
}
size = read(fd, buffer, fileSize);
if(size != fileSize)
{
printf("%s read file len error \n", __func__);
close(fd);
return -1;
}
buffer[fileSize] = '\0';
close(fd);
p = buffer;
while(i<fileSize)
while(i<fileSize)
{
memset(tmpBuf, 0xff, sizeof(tmpBuf));
j = i;
while((i<fileSize) && (*p != '\0'))
{
tmpBuf[i] = *p;
i++;
p++;
if((*p == ' ') || (*p == '\n'))
{
break;
}
}
tmpBuf[i] = '\0';
if(NULL != strstr(&tmpBuf[j], "media"))
{
memset(strBuf, 0xff, 100);
sprintf(strBuf, "USB disk mount point : %s ", &tmpBuf[j]);
printf("%s \n", strBuf);
}
}
free(buffer);
free(tmpBuf);
return 0;
}
void main(void)
{
print_mount_point();
}
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <Linux/kernel>
static unsigned long get_file_size(const char *path)
{
struct stat statbuff;
if(stat(path, &statbuff) >= 0){
return statbuff.st_size;
}
return -1;
}
static unsigned int print_mount_point(void)
{
int fd = -1;
int size = 0;
int i = 0;
int j = 0;
char strBuf[100];
char *p;
system("cat /proc/mounts > ./.1.txt");
unsigned long fileSize = get_file_size("./.1.txt");
system("rm ./.1.txt");
char *buffer = (char *)malloc(fileSize + 1);
char *tmpBuf = (char *)malloc(fileSize + 1);
if(NULL == buffer || NULL == tmpBuf)
{
printf("%s malloc error \n", __func__);
return -1;
}
fd = open("/proc/mounts", O_RDONLY);
if(-1 == fd)
{
printf("%s open error \n", __func__);
return -1;
}
size = read(fd, buffer, fileSize);
if(size != fileSize)
{
printf("%s read file len error \n", __func__);
close(fd);
return -1;
}
buffer[fileSize] = '\0';
close(fd);
p = buffer;
while(i<fileSize)
while(i<fileSize)
{
memset(tmpBuf, 0xff, sizeof(tmpBuf));
j = i;
while((i<fileSize) && (*p != '\0'))
{
tmpBuf[i] = *p;
i++;
p++;
if((*p == ' ') || (*p == '\n'))
{
break;
}
}
tmpBuf[i] = '\0';
if(NULL != strstr(&tmpBuf[j], "media"))
{
memset(strBuf, 0xff, 100);
sprintf(strBuf, "USB disk mount point : %s ", &tmpBuf[j]);
printf("%s \n", strBuf);
}
}
free(buffer);
free(tmpBuf);
return 0;
}
void main(void)
{
print_mount_point();
}
相关文章推荐
- 使用JBuilder 2005创建程序注释(1)
- 经典的分页完整程序+注释,对带与不带参数的网址通用
- 一个日历程序(基本每一行都带有注释)
- 面向对象技术JAVA(NO.0009)-JAVA程序的注释及演示
- 关于.NET程序中XML文档注释的总结
- Linux: 挂载U盘 mount the USB on linux system
- Redhat-FC3,AS4下USB设备(有时候磁盘)挂载死机的预防代码!
- 程序代码注释的探讨[未完待续]
- 我的程序(4):C++代码注释分离
- 蛙蛙推荐:刚刚写了一个考试程序,给大家贴一下,我没写过多注释哦
- java程序访问USB设备
- [转帖]源程序大公开-16X2字符液晶8Bit接口程序(注释应该算详细了)
- 第三章 程序注释
- java程序访问USB设备
- 3、程序注释
- 关于程序注释的基础知识
- 微软ping程序源代码完整版(附详细的注释)
- 程序注释-计算程序的挂钟时间、虚拟时间...(《kernel projects for linux》)
- 识别USB端口程序开发感想
- vmware下为linux挂载(mount) u盘(usb device)