[PATCH] atari aranym nfstderr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds a character device driver to allow user space access to
the aranym natfeats nfstderr.

Signed-off-by: Stephen R. Marenka <stephen@xxxxxxxxxxx>

--- linux-2.6.22/arch/m68k/emu/nfstderr.c.orig	1969-12-31 18:00:00.000000000 -0600
+++ linux-2.6.22/arch/m68k/emu/nfstderr.c	2008-01-10 16:43:39.000000000 -0600
@@ -0,0 +1,120 @@
+/*
+ * nfstderr.c - ARAnyM NF_STDERR handler for GNU/Linux
+ *
+ * With this module you may write to the emulator's stderr output 
+ * (the native console).
+ *
+ * Copyright (c) 2008 Stephen R. Marenka
+ *
+ * Based on the ARAnyM driver for FreeMiNT written by Standa Opichal,
+ * the ARAnyM driver nfeth driver for linux written by Milan Jurik,
+ * and the scull char module from the book "Linux Device Drivers" by 
+ * Alessandro Rubini and Jonathan Corbet, published by 
+ * O'Reilly & Associates (LDD3).
+ *
+ * This software may be used and distributed according to the terms of
+ * the GNU General Public License (GPL), incorporated herein by reference.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+
+#include <linux/kernel.h>	/* printk() */
+#include <linux/fs.h>		/* everything... */
+#include <linux/errno.h>	/* error codes */
+#include <linux/types.h>	/* size_t */
+#include <linux/proc_fs.h>
+#include <linux/fcntl.h>	/* O_ACCMODE */
+#include <linux/seq_file.h>
+#include <linux/cdev.h>
+
+#include <asm/system.h>		/* cli(), *_flags */
+#include <asm/uaccess.h>	/* copy_*_user */
+#include <asm/natfeat.h>	/* nfprint */
+
+/* define device major at compile or load time */
+#ifndef NFSTDERR_MAJOR
+#define NFSTDERR_MAJOR 0	/* default to dynamic */
+#endif
+int nfstderr_major = NFSTDERR_MAJOR;
+
+module_param(nfstderr_major, int, S_IRUGO);
+
+/* character device */
+struct cdev cdev;
+
+
+MODULE_AUTHOR("Stephen R. Marenka");
+MODULE_DESCRIPTION("ARAnyM NFstderr driver");
+MODULE_LICENSE("GPL");
+
+
+ssize_t nfstderr_write(struct file *filp, const char __user *str, size_t count,
+                loff_t *f_pos)
+{
+	int id;
+	char buf[68];
+	size_t retcount = count;
+
+	id = nf_get_id("NF_STDERR");
+	if ( id )
+	{
+		buf[64] = 0;
+		while (count > 64) {
+			copy_from_user(buf, str, 64);
+			nf_call(id, buf);
+			str += 64;
+			count -= 64;
+		}
+		copy_from_user(buf, str, count);
+		buf[count] = 0;
+		nf_call(id, buf);
+	}
+	return retcount;
+}
+
+struct file_operations nfstderr_fops = {
+	.owner =    THIS_MODULE,
+	.write =    nfstderr_write,
+};
+
+int nfstderr_init_module(void)
+{
+	int result;
+	dev_t devno = 0;
+	if (nfstderr_major) {
+		devno = MKDEV(nfstderr_major, 0);
+		result = register_chrdev_region(devno, 1, "nfstderr");
+	} else {
+		result = alloc_chrdev_region(&devno, 0, 0, "nfstderr");
+		nfstderr_major = MAJOR(devno);
+	}
+	if (0 > result) {
+		printk(KERN_ERR "nfstderr: error can't get major %d\n", nfstderr_major);
+		return result;
+	}
+	else {
+		int err;
+		cdev_init(&cdev, &nfstderr_fops);
+		cdev.owner = THIS_MODULE;
+		cdev.ops = &nfstderr_fops;
+		err = cdev_add(&cdev, devno, 1);
+		/* Fail gracefully if need be */
+		if (err) {
+			printk(KERN_ERR "nfstderr: error adding cdev: %d\n", err);
+			return err;
+		}
+	}
+
+	return 0;
+}
+
+void nfstderr_cleanup_module(void)
+{
+	cdev_del(&cdev);
+	unregister_chrdev_region( MKDEV(nfstderr_major, 0), 0);
+}
+
+module_init(nfstderr_init_module);
+module_exit(nfstderr_cleanup_module);
 
 
--- linux-2.6.22/arch/m68k/emu/Makefile.orig	2008-01-09 12:42:03.000000000 -0600
+++ linux-2.6.22/arch/m68k/emu/Makefile	2008-01-10 16:45:07.000000000 -0600
@@ -2,6 +2,6 @@
 # Makefile for Linux arch/m68k/emu source directory
 #
 
-obj-y			+= natfeat.o
+obj-y			+= natfeat.o nfstderr.o
 
 obj-$(CONFIG_NFETH)	+= nfeth.o 
 
 
-- 
Stephen R. Marenka     If life's not fun, you're not doing it right!
<stephen@xxxxxxxxxxx>

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Video for Linux]     [Yosemite News]     [Linux S/390]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux