Extract common data structures to ksudoku header file
This commit is contained in:
parent
171b0f6946
commit
99dfe2f520
|
@ -92,3 +92,4 @@ extra_certificates
|
|||
signing_key.priv
|
||||
signing_key.x509
|
||||
x509.genkey
|
||||
*.mod
|
64
ksudoku.c
64
ksudoku.c
|
@ -1,34 +1,27 @@
|
|||
#include <linux/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <asm/atomic.h>
|
||||
#include <linux/slab.h>
|
||||
/*
|
||||
* KSudoku subsystem for Linux kernel to solve sudoku with different
|
||||
* algorithms.
|
||||
* Copyright (C) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#include "ksudoku.h"
|
||||
|
||||
#define KSUDOKU_VERSION "0.1"
|
||||
#define KSUDOKU_DESC "Kernel Sudoku Module"
|
||||
|
||||
#define KSUDOKU_READY 0
|
||||
#define KSUDOKU_BUSY 1
|
||||
|
||||
struct ksudoku {
|
||||
struct kobject kobj;
|
||||
const struct attribute_group *attr_group;
|
||||
char *matrix;
|
||||
atomic_t status;
|
||||
};
|
||||
#define to_ksudoku(obj) container_of(obj, struct ksudoku, kobj)
|
||||
|
||||
|
||||
struct ksudoku_attribute {
|
||||
struct attribute attr;
|
||||
ssize_t (*show)(struct ksudoku *s, struct ksudoku_attribute *attr,
|
||||
char *buf);
|
||||
ssize_t (*store)(struct ksudoku *s, struct ksudoku_attribute *attr,
|
||||
const char *buf, size_t count);
|
||||
bool value;
|
||||
};
|
||||
#define to_ksudoku_attr(_attr) container_of(_attr, struct ksudoku_attribute, attr)
|
||||
|
||||
/*
|
||||
* The default show callback that is called by sysfs when ever a read
|
||||
* operation happens on any attribute on ksudoku subsystem.
|
||||
|
@ -165,7 +158,11 @@ static struct kobj_type ksudoku_type = {
|
|||
|
||||
static struct kset *ksudoku_set;
|
||||
|
||||
static struct ksudoku *create_ksudoku(const char *name)
|
||||
/**
|
||||
* ksudoku_create_sudoku - create new sudoku with under ksudoku subsystem.
|
||||
* @name: name of the sudoku to create.
|
||||
*/
|
||||
struct ksudoku *ksudoku_create_sudoku(const char *name)
|
||||
{
|
||||
struct ksudoku *s;
|
||||
int result;
|
||||
|
@ -190,12 +187,17 @@ static struct ksudoku *create_ksudoku(const char *name)
|
|||
kobject_uevent(&s->kobj, KOBJ_ADD);
|
||||
return s;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(ksudoku_create_sudoku);
|
||||
|
||||
static void destroy_ksudoku(struct ksudoku *s)
|
||||
/**
|
||||
* ksudoku_destroy_ksudoku - destroys the given ksudoku instance.
|
||||
* @sudoku: Pointer to a ksudoku instance to destroy.
|
||||
*/
|
||||
void ksudoku_destroy_ksudoku(struct ksudoku *sudoku)
|
||||
{
|
||||
kobject_put(&s->kobj);
|
||||
kobject_put(&sudoku->kobj);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL_GPL(ksudoku_destroy_ksudoku);
|
||||
|
||||
static int ksudoku_init(void)
|
||||
{
|
||||
|
|
76
ksudoku.h
76
ksudoku.h
|
@ -1,3 +1,22 @@
|
|||
/*
|
||||
* KSudoku subsystem for Linux kernel to solve sudoku with different
|
||||
* algorithms.
|
||||
* Copyright (C) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
||||
*
|
||||
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
#ifndef _KSUDOKU_H_
|
||||
#define _KSUDOKU_H_
|
||||
|
||||
|
@ -5,50 +24,31 @@
|
|||
#include <linux/module.h>
|
||||
#include <linux/sysfs.h>
|
||||
#include <asm/atomic.h>
|
||||
#include <linux/slab.h>
|
||||
|
||||
struct ksudoku;
|
||||
|
||||
#define to_ksudoku(obj) container_of(obj, struct ksudoku, kobj)
|
||||
#define to_ksudoku_attr(_attr) container_of(_attr, struct kobj_attribute, attr)
|
||||
|
||||
struct sudoku_attribute {
|
||||
struct attribute attr;
|
||||
ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
|
||||
char *buf);
|
||||
ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
|
||||
const char *buf, size_t count);
|
||||
bool value;
|
||||
};
|
||||
|
||||
/*
|
||||
* The type of sudoku, "struct sudoku" is embedded in. A class
|
||||
* or bus can only contain one sudoku type.
|
||||
* This identifies the sudoku type and carries type-specific
|
||||
* information, equivalent to the kobj_type of a kobject.
|
||||
* Since we have only one type it always will be the same button
|
||||
* we're designing a subsystem so we have to make sysfs happy.
|
||||
* If "name" is specified, the uevent will contain it in
|
||||
* the DEVTYPE variable.
|
||||
*/
|
||||
/* struct sudoku_type { */
|
||||
/* const char *name; */
|
||||
/* const struct attribute_group **groups; */
|
||||
/* int (*uevent)(struct sudoku *s, struct kobj_uevent_env *env); */
|
||||
/* void (*release)(struct kobject *kobj); */
|
||||
/* const struct sysfs_ops *sysfs_ops; */
|
||||
/* }; */
|
||||
#define KSUDOKU_READY 0
|
||||
#define KSUDOKU_BUSY 1
|
||||
|
||||
struct ksudoku {
|
||||
struct kobject *kobj;
|
||||
struct kobject kobj;
|
||||
const struct attribute_group *attr_group;
|
||||
char matrix[81];
|
||||
char *matrix;
|
||||
atomic_t status;
|
||||
} ;
|
||||
};
|
||||
#define to_ksudoku(obj) container_of(obj, struct ksudoku, kobj)
|
||||
|
||||
#define SUDOKU_ATTR_RO(_name) \
|
||||
struct kobj_attribute sudoku_##_name = __ATTR_RO(_name)
|
||||
|
||||
#define SUDOKU_ATTR_WO(_name) \
|
||||
struct kobj_attribute sudoku_##_name = __ATTR_WO(_name)
|
||||
struct ksudoku_attribute {
|
||||
struct attribute attr;
|
||||
ssize_t (*show)(struct ksudoku *s, struct ksudoku_attribute *attr,
|
||||
char *buf);
|
||||
ssize_t (*store)(struct ksudoku *s, struct ksudoku_attribute *attr,
|
||||
const char *buf, size_t count);
|
||||
};
|
||||
|
||||
#define to_ksudoku_attr(_attr) container_of(_attr, struct ksudoku_attribute, attr)
|
||||
|
||||
extern struct ksudoku *ksudoku_create_sudoku(const char *name);
|
||||
extern void ksudoku_destroy_ksudoku(struct ksudoku *sudoku);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#! /bin/bash
|
||||
|
||||
qemu-system-x86_64 \
|
||||
-kernel /boot/vmlinuz-`uname -r` \
|
||||
-nographic \
|
||||
-append "console=ttyS0 nokaslr init=/bin/bash" \
|
||||
-initrd `pwd`/ram.disk \
|
||||
-m 512 \
|
||||
--enable-kvm \
|
||||
-cpu host
|
|
@ -0,0 +1,12 @@
|
|||
#! /bin/bash
|
||||
|
||||
IMG=`pwd`/qemu-image.img
|
||||
DIR=`pwd`/mounted_fs
|
||||
|
||||
qemu-img create $IMG 1g
|
||||
sudo mkfs.ext2 $IMG
|
||||
mkdir $DIR
|
||||
sudo mount -o loop $IMG $DIR
|
||||
sudo debootstrap --arch amd64 buster $DIR
|
||||
sudo umount $DIR
|
||||
rmdir $DIR
|
Loading…
Reference in New Issue