瀏覽代碼

Updated linux/kernel/api/vfs_stat

dyokunev 8 年之前
父節點
當前提交
3a63bbdf9c
共有 1 個文件被更改,包括 27 次插入9 次删除
  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 )
 ```