/* $Id: inode.c,v 1.15 2001/11/12 09:43:39 davem Exp $
* openpromfs.c: /proc/openprom handling routines
*
* Copyright (C) 1996-1999 Jakub Jelinek (jakub@redhat.com)
* Copyright (C) 1998 Eddie C. Dost (ecd@skynet.be)
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/fs.h>
#include <linux/openprom_fs.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/smp_lock.h>
#include <asm/openprom.h>
#include <asm/oplib.h>
#include <asm/uaccess.h>
#define ALIASES_NNODES 64
typedef struct {
u16 parent;
u16 next;
u16 child;
u16 first_prop;
u32 node;
} openpromfs_node;
typedef struct {
#define OPP_STRING 0x10
#define OPP_STRINGLIST 0x20
#define OPP_BINARY 0x40
#define OPP_HEXSTRING 0x80
#define OPP_DIRTY 0x01
#define OPP_QUOTED 0x02
#define OPP_NOTQUOTED 0x04
#define OPP_ASCIIZ 0x08
u32 flag;
u32 alloclen;
u32 len;
char *value;
char name[8];
} openprom_property;
static openpromfs_node *nodes;
static int alloced;
static u16 last_node;
static u16 first_prop;
static u16 options = 0xffff;
static u16 aliases = 0xffff;
static int aliases_nodes;
static char *alias_names [ALIASES_NNODES];
#define OPENPROM_ROOT_INO 16
#define OPENPROM_FIRST_INO OPENPROM_ROOT_INO
#define NODE(ino) nodes[ino - OPENPROM_FIRST_INO]
#define NODE2INO(node) (node + OPENPROM_FIRST_INO)
#define NODEP2INO(no) (no + OPENPROM_FIRST_INO + last_node)
static int openpromfs_create (struct inode *, struct dentry *, int, struct nameidata *);
static int openpromfs_readdir(struct file *, void *, filldir_t);
static struct dentry *openpromfs_lookup(struct inode *, struct dentry *dentry, struct nameidata *nd);
static int openpromfs_unlink (struct inode *, struct dentry *dentry);
static ssize_t nodenum_read(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
struct inode *inode = file->f_dentry->d_inode;
char buffer[10];
if (count < 0 || !inode->u.generic_ip)
return -EINVAL;
sprintf (buffer, "%8.8x\n", (u32)(long)(inode->u.generic_ip));
if (file->f_pos >= 9)
return 0;
if (count > 9 - file->f_pos)
count = 9 - file->f_pos;
if (copy_to_user(buf, buffer + file->f_pos, count))
return -EFAULT;
*ppos += count;
return count;
}
static ssize_t property_read(struct file *filp, char __user *buf,
size_t count, loff_t *ppos)
{
struct inode *inode = filp->f_dentry->d_inode;
int i, j, k;
u32 node;
char *p, *s;
u32 *q;
openprom_property *op;
char buffer[64];
if (!filp->private_data) {
node = nodes[(u16)((long)inode->u.generic_ip)].node;
i = ((u32)(long)inode->u.generic_ip) >> 16;
if ((u16)((long)inode->u.generic_ip) == aliases) {
if (i >= aliases_nodes)
p = NULL;
else
p = alias_names [i];
} else
for (p = prom_firstprop (node, buffer);
i && p && *p;
p = prom_nextprop (node, p,