Aug
22
稀疏文件的trick: 凭空增加1T的“可用”空间
一个简单的程序:
编译运行:
搞怪:
转载请注明出自 ,如是转载文则注明原出处,谢谢:)
RSS订阅地址: https://www.felix021.com/blog/feed.php 。
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
int fd = open(argv[1], O_CREAT | O_WRONLY);
if (fd < 0)
{
printf("err open");
return 1;
}
u_int64_t sz = lseek64(fd, (1ull << 40) - 1, SEEK_SET);
if (sz < 0)
{
printf("err lseek64");
return 2;
}
int nWrite = write(fd, &fd, 1);
printf("nWrite = %d\n", nWrite);
close(fd);
return 0;
}
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
int main(int argc, char *argv[])
{
int fd = open(argv[1], O_CREAT | O_WRONLY);
if (fd < 0)
{
printf("err open");
return 1;
}
u_int64_t sz = lseek64(fd, (1ull << 40) - 1, SEEK_SET);
if (sz < 0)
{
printf("err lseek64");
return 2;
}
int nWrite = write(fd, &fd, 1);
printf("nWrite = %d\n", nWrite);
close(fd);
return 0;
}
编译运行:
引用
$ gcc -o hole hole.c -D_FILE_OFFSET_BITS=64
$ ./hole disk
$ ls -lh disk
-rwxr-S--- 1 felix021 felix021 1.0T 2010-08-20 14:36 disk
$ ./hole disk
$ ls -lh disk
-rwxr-S--- 1 felix021 felix021 1.0T 2010-08-20 14:36 disk
搞怪:
引用
felix021@ubuntu-vbox:~/code$ mkdir mnt
felix021@ubuntu-vbox:~/code$ sudo mkfs.vfat disk
mkfs.vfat 3.0.7 (24 Dec 2009)
felix021@ubuntu-vbox:~/code$ sudo mount -oloop disk mnt
felix021@ubuntu-vbox:~/code$ df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 5.2G 1.5G 3.5G 30% /
...
/dev/sda1 2.3G 957M 1.3G 43% /home
/dev/loop0 1.0T 16K 1.0T 1% /home/felix021/code/mnt
felix021@ubuntu-vbox:~/code$ sudo mkfs.vfat disk
mkfs.vfat 3.0.7 (24 Dec 2009)
felix021@ubuntu-vbox:~/code$ sudo mount -oloop disk mnt
felix021@ubuntu-vbox:~/code$ df -lh
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 5.2G 1.5G 3.5G 30% /
...
/dev/sda1 2.3G 957M 1.3G 43% /home
/dev/loop0 1.0T 16K 1.0T 1% /home/felix021/code/mnt
欢迎扫码关注:
转载请注明出自 ,如是转载文则注明原出处,谢谢:)
RSS订阅地址: https://www.felix021.com/blog/feed.php 。
sigsegv4
2010-9-2 01:31
相当能骗人的把戏啊,我在想如果你那1.3G被用完了会怎么样。。。。
Me999
2010-8-26 21:48
看来NOIP可以拿一等的我,还是看不懂这种程序。。。
分页: 1/1 1