Get file size with stat syscall

后端 未结 3 787
失恋的感觉
失恋的感觉 2021-01-03 12:44

I\'m trying to get file size wit stat syscall with assembly (nasm):

section .data
    encodeFile db \"/home/user/file\"

section .bss
    stat resb 64

struc         


        
3条回答
  •  别那么骄傲
    2021-01-03 13:42

    In my reference (although it is 32 bit) the STAT structure is described a little bit different. At least, your structure has size different from 64.

    struct STAT
      .st_dev     dw  ?     ; ID of device containing file
      .pad1       dw  ?
      .st_ino     dd  ?     ; inode number
      .st_mode    dw  ?     ; protection
      .st_nlink   dw  ?     ; number of hard links
      .st_uid     dw  ?     ; user ID of owner
      .st_gid     dw  ?     ; group ID of owner
      .st_rdev    dw  ?     ; device ID (if special file)
      .pad2       dw  ?
      .st_size    dd  ?     ; total size, in bytes
      .st_blksize dd  ?     ; block size
      .st_blocks  dd  ?
    
      .st_atime   dd  ?     ; time of last access
      .unused1    dd  ?
    
      .st_mtime   dd  ?     ; time of last modification
      .unused2    dd  ?
    
      .st_ctime   dd  ?     ; time of last status change
      .unused3    dd  ?
      .unused4    dd  ?
      .unused5    dd  ?
    ends
    

    Although, these differences does not explain why your program does not work. What is actually the size of "/home/usr/file". Isn't it 0?

提交回复
热议问题