- 论坛徽章:
- 0
|
vi版本 version 7.0.39
问题:使用vi编辑aaa文件,保存后inode号居然变了
步骤如下:
0 lfs:~$
0 lfs:~$ stat abc
File: `abc'
Size: 14 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 235224 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ lfs) Gid: ( 1000/ lfs)
Access: 2009-10-16 07:19:34.000000000 +0800
Modify: 2009-10-16 07:19:34.000000000 +0800
Change: 2009-10-16 07:24:01.000000000 +0800
0 lfs:~$ vi abc
1 3111111111111
~
~
~
~
:wq
"abc" 1L, 14C written
0 lfs:~$ stat abc
File: `abc'
Size: 14 Blocks: 8 IO Block: 4096 regular file
Device: 802h/2050d Inode: 235219 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ lfs) Gid: ( 1000/ lfs)
Access: 2009-10-16 07:25:55.000000000 +0800
Modify: 2009-10-16 07:25:55.000000000 +0800
Change: 2009-10-16 07:25:55.000000000 +0800
保存后再查看,abc的inode号变化了
使用strace跟踪查看,发现vi会先以只读方式读入文件,如下
766 open("abc", O_RDONLY) = 3
767 write(1, "\33[1;34r\33[?25h\33[?8c\33[?25h\33[?0c\33[2"..., 72) = 72
768 read(3, "3111111111111\n", 8192) = 14
769 select(1, [0], NULL, [0], {0, 0}) = 0 (Timeout)
再写入保存文件的时候,会以O_TRUNC方式重新写入一个新文件,如下
909 open("abc", O_WRONLY|O_CREAT|O_TRUNC, 0644) = 3
910 write(3, "3111111111111\n", 14) = 14
911 fsync(3)
vi为什么要这么做了? |
|