内核态do_gettimeofday函数返回的timeval如何转成年月日时分秒的格式?

morneve1 2010-02-05 04:51:49
struct timespec {
time_t tv_sec; /* seconds */
long tv_nsec; /* nanoseconds */
};
#endif

struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
};

struct timezone {
int tz_minuteswest; /* minutes west of Greenwich */
int tz_dsttime; /* type of dst correction */
};

内核态do_gettimeofday函数返回的timeval如何转成年月日时分秒的格式?
有什么函数可用,还望大家指点,感激
...全文
2030 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
morneve1 2010-02-21
  • 打赏
  • 举报
回复
先用proc文件系统简单传到kernel吧,do_fork的方法留以后试试
morneve1 2010-02-21
  • 打赏
  • 举报
回复
非常感谢各位指教,特别是do_fork
do_fork 2010-02-09
  • 打赏
  • 举报
回复
open => filp_open
read => vfs_read
write => vfs_write
close => filp_close

内核空间和用户空间的地址空间不同,一些函数有地址空间限制,
所以读写的时候,vfs_xxx之前需要set_fs解除这个限制。

fs/exec.c中有个例子,可以参考下
 681 int kernel_read(struct file *file, loff_t offset,
682 char *addr, unsigned long count)
683 {
684 mm_segment_t old_fs;
685 loff_t pos = offset;
686 int result;
687
688 old_fs = get_fs();
689 set_fs(get_ds());
690 /* The cast to a user pointer is valid due to the set_fs() */
691 result = vfs_read(file, (void __user *)addr, count, &pos);
692 set_fs(old_fs);
693 return result;
694 }


你也可以开一个内核线程,在内核线程中做这样的事情,
最好还是由用户空间程序配合内核做这个事情,以减少潜在错误,降低不稳定性因素。
morneve1 2010-02-07
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 morneve1 的回复:]
喔,那怎么在内核查普通文件? 感谢
[/Quote]

do_fork兄还在不?我查到我的系统用的是/etc/TZ这个文件
morneve1 2010-02-07
  • 打赏
  • 举报
回复
strftime是内核可以用的函数吗?

这个函数好象不能用吧
morneve1 2010-02-07
  • 打赏
  • 举报
回复
喔,那怎么在内核查普通文件? 感谢
do_fork 2010-02-07
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 morneve1 的回复:]
谢谢do_fork,我是2.6.20.s内核没发现有/etc/localtime 这个文件啊?


谢谢mostmark,strftime是内核可以用的函数吗?
[/Quote]

这个文件是文件系统中的,不是内核的一部分,只是个普通文件
morneve1 2010-02-07
  • 打赏
  • 举报
回复
谢谢do_fork,我是2.6.20.s内核没发现有/etc/localtime 这个文件啊?


谢谢mostmark,strftime是内核可以用的函数吗?
do_fork 2010-02-07
  • 打赏
  • 举报
回复
从内核中访问 /etc/localtime 文件,里面存储着时区信息
mostmark 2010-02-07
  • 打赏
  • 举报
回复
strftime()
很强大
morneve1 2010-02-07
  • 打赏
  • 举报
回复
内核模块如何取得时区啊?

兄弟们知道的帮忙啊
morneve1 2010-02-05
  • 打赏
  • 举报
回复
谢谢2楼,是不是没有现成函数的?

还有内核态如何取得时区
morneve1 2010-02-05
  • 打赏
  • 举报
回复
最终转换还缺个时间timezone喔,还请解释下,这个从哪可以取到?

谢谢兄弟们了
ma100 2010-02-05
  • 打赏
  • 举报
回复
http://www.xgdown.com/article/175/50550_1.htm
morneve1 2010-02-05
  • 打赏
  • 举报
回复
用户态下有localtime和gmtime将timeval.time_t转成struct tm的,
不知道内核应该怎么搞,好象没有这些函数的
获取USB摄像头的1080p的JPEG格式的图片20180608_1806.7z 电脑上的系统:ubuntu14.04 // http://www.linuxidc.com/Linux/2011-03/33020.htm // V4L2摄像头获取单幅图片测试程序(MMAP模式) // [日期:2011-03-06] 来源:Linux社区 作者:aokikyon [字体:大 中 小] // // #加了点注释 // // #Rockie Cheng // printf #include #include // memset #include #include #include #include // close write usleep read #include #include #include #include #include #include // mmap #include #include #include #include // pthread_create pthread_join #include #define CLEAR(x) memset (&(x), 0, sizeof (x)) #define REQ_COUNT 6 #define uchar unsigned char struct buffer { void * start; size_t length; }; static char * dev_name = "/dev/video0";//摄像头设备名 static int fd = -1; struct buffer * buffers = NULL; // static unsigned int n_buffers = 0; // 2012-7-13 11:33 camera flag // static int iFlagCamera = 0; volatile int iFlagCamera = 0; // 函数名称:thread1 // 函数功能:用于接受键盘的输入,之后通知thread2抓图 // 参数列表: // 返回值 : void thread1(void) { char ch; printf("\n !!!!Warning!!!!\n Max 1000 color bmp\n Input the char: \n"); printf("\n !!!!press o an capture 1 frame picture! \n"); printf("\n !!!!press t an capture 10 frame picture! \n"); printf("\n !!!!press h an capture 100 frame picture! \n"); while(1) { while((ch=getchar()) != '\n') { printf("%c\n", ch); if('o'==ch) { iFlagCamera = 1; printf("thread1=%d\n", iFlagCamera); } else if('t'==ch) { iFlagCamera = 10; printf("thread1=%d\n", iFlagCamera); } else if('h'==ch) { iFlagCamera = 101; printf("thread1=%d\n", iFlagCamera); } else if('q'==ch) { iFlagCamera = 10001; printf("thread1=%d\n", iFlagCamera

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧