[IMPROVE] create swap dir in sysfs
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 19 Sep 2013 08:54:12 +0000 (12:54 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Thu, 19 Sep 2013 09:35:40 +0000 (13:35 +0400)
Change-Id: If365053a7437c7cacb78a8d378556e6f0f123822
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
driver/Kbuild
driver/swap_debugfs.c [new file with mode: 0644]
driver/swap_debugfs.h [new file with mode: 0644]
driver/swap_driver_module.c

index 01cd0b8..ccd3071 100644 (file)
@@ -3,4 +3,5 @@ EXTRA_CFLAGS := $(extra_cflags)
 obj-m := swap_driver.o
 swap_driver-y := swap_driver_module.o \
                      device_driver.o \
-                     driver_to_buffer.o
+                     driver_to_buffer.o \
+                     swap_debugfs.o
diff --git a/driver/swap_debugfs.c b/driver/swap_debugfs.c
new file mode 100644 (file)
index 0000000..bc13e1d
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ *  SWAP kernel features
+ *  driver/swap_debugfs.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2013
+ *
+ * 2013         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#include <linux/module.h>
+#include <linux/debugfs.h>
+
+
+static struct dentry *swap_dir = NULL;
+
+
+struct dentry *get_swap_debugfs_dir(void)
+{
+       return swap_dir;
+}
+EXPORT_SYMBOL_GPL(get_swap_debugfs_dir);
+
+int swap_debugfs_init(void)
+{
+       swap_dir = debugfs_create_dir("swap", NULL);
+       if (swap_dir == NULL)
+               return -ENOMEM;
+
+       return 0;
+}
+
+void swap_debugfs_exit(void)
+{
+       struct dentry *dir = swap_dir;
+
+       swap_dir = NULL;
+       debugfs_remove_recursive(dir);
+}
diff --git a/driver/swap_debugfs.h b/driver/swap_debugfs.h
new file mode 100644 (file)
index 0000000..305030f
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef _SWAP_DEBUG_FS_H
+#define _SWAP_DEBUG_FS_H
+
+/*
+ *  SWAP kernel features
+ *  driver/swap_debugfs.h
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2013
+ *
+ * 2013         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+struct dentry;
+
+
+struct dentry *get_swap_debugfs_dir(void);
+int swap_debugfs_init(void);
+void swap_debugfs_exit(void);
+
+#endif /* _SWAP_DEBUG_FS_H */
index e599660..f0e4d6b 100644 (file)
 
 #include "driver_defs.h"
 #include "device_driver.h"
+#include "swap_debugfs.h"
 
 static int __init swap_driver_init(void)
 {
+       int ret;
+
+       ret = swap_debugfs_init();
+       if (ret)
+               return ret;
+
        swap_device_init();
        print_msg("Driver module initialized\n");
 
@@ -38,6 +45,7 @@ static int __init swap_driver_init(void)
 static void __exit swap_driver_exit(void)
 {
        swap_device_exit();
+       swap_debugfs_exit();
        print_msg("Driver module uninitialized\n");
 }