zoukankan      html  css  js  c++  java
  • 通过lseek产生空洞文件

    //off_t lseek(int fd,off_t offset, int base) 偏移量 搜索的起始位置(文件头(SEEK_SET),当前指针位置(SEEK_CUR),文件尾(SEEK_END))unistd.h
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include<errno.h>
    #include<unistd.h>
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    //#define ERR_EXIT(m)  (perror(m),exit(EXIT_FAILURE))
    #define ERR_EXIT(m)
        do
        {
            perror(m);
            exit(EXIT_FAILURE);
        }while(0)  //宏要求一条语句
    int main(void)
    {
        int fd;
        fd=open("hole.txt",O_WRONLY|O_CREAT|O_TRUNC,0644);
        if(fd==-1)
            ERR_EXIT("open error");
        //写入5个字符
        write(fd,"ABCDE",5);
        //将文件偏移
        //od  -c hole.txt查看文件空洞。实际磁盘上并未存放这些空洞  ls -lh hole.txt有1.1G但实际磁盘上并未全部存储。
        //并未在磁盘中全部存放,很多的信息未存放在磁盘,只有部分信息。du -h hole.txt(磁盘最小块4K大小)
        if(ret==-1)
        int ret=lseek(fd,1024*1024*1024/*32*/,SEEK_CUR);  //从文件当前位置,偏移到1G之后。只在内核中操作,实际不在磁盘操作。
            ERR_EXIT("lseek error");
        write(fd,"hello",5);
        close(fd);
        return 0;
    }

  • 相关阅读:
    Flask 中的路由系统
    Flask 中内置的 Session
    Flask中的模板语言jinja2
    Flask 中的 5种返回值
    Redis快速入门
    动态实现前后台分页、翻页按钮、上一页、下一页、首页、末页
    bus.js非父子组件之间通讯
    vue中父子组件之间相互传值
    js实现加减乘除
    禁用微信分享
  • 原文地址:https://www.cnblogs.com/wsw-seu/p/8280593.html
Copyright © 2011-2022 走看看