0

I have to read an entire file in a buffer inside a kernel module I'm writing. I started following as written here

but, I'm not clear how to retrieve the file size, to allocate the memory for the array buffer. I could not find a good documentation of the VFS functions. (I'm working on 3.2 kernel).

How can achieve that? Thanks

user3376554
  • 19
  • 2
  • 5

1 Answers1

0

By using vfs_stat() or vfs_fstat as answered in How do you get the size of a file in the linux kernel?

Vishal
  • 43
  • 1
  • 4
  • Thanks, I used vfs_stat(). Now I get the "size" from the struct kstat. Seems that it is of type loff_t (long long). So, for example, printing the value with %lld, I see for "/bin/ls" : -131941060952272. This is impossible. What am I doing wrong? – user3376554 Jul 11 '17 at 11:44
  • Check if your arguments are correct and there is no error set by `vfs_stat()` – Vishal Jul 11 '17 at 12:04
  • An example already exists at https://stackoverflow.com/questions/19195560/whats-wrong-with-vfs-stat-call and you should have all the details at http://www.linuxjournal.com/node/8110/print – Vishal Jul 11 '17 at 12:15
  • 2
    `-131941060952272` looks like a pointer. You probably have to deref it to get the actual value. – Georg Schölly Jan 24 '18 at 09:09