Pārlūkot izejas kodu

Updated linux/kernel/api/vfs_stat

dyokunev 8 gadi atpakaļ
vecāks
revīzija
3a63bbdf9c
1 mainītis faili ar 27 papildinājumiem un 9 dzēšanām
  1. 27 9
      linux/kernel/api/vfs_stat.md

+ 27 - 9
linux/kernel/api/vfs_stat.md

@@ -1,7 +1,8 @@
 I don't know if this correct or not, but:
 
 ```
-#include
+#include <linux/uaccess.h>
+
 vfs_stat ( char *path, struct kstat *kstat )
 ```
 
@@ -44,20 +45,37 @@ struct kstat {
 
 Function source code: http://lxr.linux.no/linux+v4.6.4/fs/stat.c#L121
 
-Example:
+A wrapper example:
 
 ```
 int file_stat ( char *fpath, struct kstat stat )
 {
-        int error;
-        mm_segment_t old_fs;
+  int error;
+  mm_segment_t old_fs;
+
+  old_fs = get_fs();
+  set_fs(KERNEL_DS);
 
-        old_fs = get_fs();
-        set_fs(KERNEL_DS);
+  error = vfs_stat (fpath, &stat);
+  set_fs(old_fs);
+
+  return error;
+}
+```
 
-        error = vfs_stat (fpath, &stat);
-        set_fs(old_fs);
+Getting a file size:
 
-        return error;
+```
+static int __init my_module_init()
+{
+  struct kstat stat
+  mm_segment_t old_fs;
+  old_fs = get_fs();
+  set_fs(KERNEL_DS);
+  vfs_stat ("/bin/ls", &stat)
+  printk (KERN_INFO "mode of ls: %o\n", stat.size);
+  set_fs(old_fs);
 }
+
+module_init ( my_module_init )
 ```