|
@@ -1,18 +1,13 @@
|
|
-I don't know if this correct or not, but here a manpage ugly draft:
|
|
|
|
-
|
|
|
|
-#### SYNOPSIS
|
|
|
|
|
|
+I don't know if this correct or not, but:
|
|
|
|
|
|
```
|
|
```
|
|
-#include <linux/uaccess.h>
|
|
|
|
-
|
|
|
|
|
|
+#include
|
|
vfs_stat ( char *path, struct kstat *kstat )
|
|
vfs_stat ( char *path, struct kstat *kstat )
|
|
```
|
|
```
|
|
|
|
|
|
-#### DESCRIPTION
|
|
|
|
|
|
+`vfs_stat()` — retrieve information about the file pointed to by `path`.
|
|
|
|
|
|
-`vfs_stat()` — retrieve information about the file pointed to by `path`. Read `man 2 stat`.
|
|
|
|
-
|
|
|
|
-About `struct kstat` see file linux-source/include/linux/stat.h:
|
|
|
|
|
|
+About `struct kstat` see [https://docs.oracle.com/cd/E53394_01/html/E54769/kstat-3kstat.html](https://docs.oracle.com/cd/E53394_01/html/E54769/kstat-3kstat.html) and file linux-source/include/linux/stat.h:
|
|
```
|
|
```
|
|
#include <asm/stat.h>
|
|
#include <asm/stat.h>
|
|
#include <uapi/linux/stat.h>
|
|
#include <uapi/linux/stat.h>
|
|
@@ -49,43 +44,20 @@ struct kstat {
|
|
|
|
|
|
Function source code: http://lxr.linux.no/linux+v4.6.4/fs/stat.c#L121
|
|
Function source code: http://lxr.linux.no/linux+v4.6.4/fs/stat.c#L121
|
|
|
|
|
|
-#### EXAMPLES
|
|
|
|
-
|
|
|
|
-A wrapper example:
|
|
|
|
|
|
+Example:
|
|
|
|
|
|
```
|
|
```
|
|
int file_stat ( char *fpath, struct kstat stat )
|
|
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);
|
|
|
|
-
|
|
|
|
- error = vfs_stat (fpath, &stat);
|
|
|
|
- set_fs(old_fs);
|
|
|
|
-
|
|
|
|
- return error;
|
|
|
|
-}
|
|
|
|
-```
|
|
|
|
|
|
+ old_fs = get_fs();
|
|
|
|
+ set_fs(KERNEL_DS);
|
|
|
|
|
|
-Getting a file size:
|
|
|
|
|
|
+ error = vfs_stat (fpath, &stat);
|
|
|
|
+ set_fs(old_fs);
|
|
|
|
|
|
-```
|
|
|
|
-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);
|
|
|
|
|
|
+ return error;
|
|
}
|
|
}
|
|
-
|
|
|
|
-module_init ( my_module_init )
|
|
|
|
-```
|
|
|
|
-
|
|
|
|
-#### RETURN VALUE
|
|
|
|
-
|
|
|
|
-On success, `vfs_stat()` return zero; otherwise non-zero.
|
|
|
|
|
|
+```
|