X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;ds=sidebyside;f=libcfs%2Finclude%2Flibcfs%2Fwinnt%2Fwinnt-prim.h;h=7d8147f61696f6063e3298eec6e14f394b9107fe;hb=976c0abd4efab4f56cf4b21b940eb1b976c37372;hp=3c8560b71c952f95e5aacf4404100ce68136840c;hpb=e1b3d71a27c166bebd26ab33f7299c41bd75dab5;p=fs%2Flustre-release.git diff --git a/libcfs/include/libcfs/winnt/winnt-prim.h b/libcfs/include/libcfs/winnt/winnt-prim.h index 3c8560b..7d8147f 100644 --- a/libcfs/include/libcfs/winnt/winnt-prim.h +++ b/libcfs/include/libcfs/winnt/winnt-prim.h @@ -1,25 +1,41 @@ -/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=4:tabstop=4: +/* + * GPL HEADER START * - * Copyright (C) 2001 Cluster File Systems, Inc. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * - * This file is part of Lustre, http://www.lustre.org. + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 only, + * as published by the Free Software Foundation. * - * Lustre is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. + * 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 version 2 for more details (a copy is included + * in the LICENSE file that accompanied this code). * - * Lustre 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 + * version 2 along with this program; If not, see + * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf * - * You should have received a copy of the GNU General Public License - * along with Lustre; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. * - * Basic library routines. + * GPL HEADER END + */ +/* + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. + * Use is subject to license terms. * + * Copyright (c) 2012, Intel Corporation. + */ +/* + * This file is part of Lustre, http://www.lustre.org/ + * Lustre is a trademark of Sun Microsystems, Inc. + * + * libcfs/include/libcfs/winnt/winnt-prim.h + * + * Basic library routines. */ #ifndef __LIBCFS_WINNT_CFS_PRIM_H__ @@ -29,14 +45,17 @@ #error Do not #include this file directly. #include instead #endif +#ifndef EXPORT_SYMBOL +# define EXPORT_SYMBOL(s) +#endif /* * libcfs proc device object */ -#define LUSTRE_PROC_DEVICE L"\\Device\\lproc" /* proc fs emulator device object */ -#define LUSTRE_PROC_SYMLNK L"\\DosDevices\\lproc" /* proc fs user-visible device */ +#define LUSTRE_PROC_DEVICE L"\\Device\\LNetProcFS" /* proc fs emulator device object */ +#define LUSTRE_PROC_SYMLNK L"\\DosDevices\\LNetProcFS" /* proc fs user-visible device */ /* @@ -45,8 +64,6 @@ #define FILE_DEVICE_LIBCFS ('LC') -#define FILE_DEVICE_LIBCFS ('LC') - #define FUNC_LIBCFS_VERSION 0x101 // get version of current libcfs #define FUNC_LIBCFS_IOCTL 0x102 // Device i/o control to proc fs @@ -57,21 +74,22 @@ CTL_CODE(FILE_DEVICE_LIBCFS, FUNC_LIBCFS_IOCTL, METHOD_BUFFERED, FILE_ANY_ACCESS) #pragma pack(4) - typedef struct _CFS_PROC_IOCTL { ULONG cmd; // ioctl command identifier ULONG len; // length of data + int rc; // return code + ULONG usused; // unused // UCHAR data[]; // content of the real ioctl } CFS_PROC_IOCTL, *PCFS_PROC_IOCTL; - #pragma pack() #ifdef __KERNEL__ -#include +void cfs_enter_debugger(void); +#define __builtin_return_address(x) (0) /* * Symbol functions for libcfs @@ -82,10 +100,10 @@ typedef struct _CFS_PROC_IOCTL { #define CFS_SYMBOL_LEN 64 struct cfs_symbol { - char name[CFS_SYMBOL_LEN]; - void *value; - int ref; - struct list_head sym_list; + char name[CFS_SYMBOL_LEN]; + void *value; + int ref; + struct list_head sym_list; }; extern int cfs_symbol_register(const char *, const void *); @@ -94,34 +112,30 @@ extern void * cfs_symbol_get(const char *); extern void cfs_symbol_put(const char *); extern void cfs_symbol_clean(); - - typedef struct file_operations cfs_file_operations_t; -typedef struct file cfs_file_t; /* * Pseudo device register */ -typedef struct -{ +typedef struct miscdevice{ int minor; const char * name; cfs_file_operations_t * fops; -} cfs_psdev_t; +}; -int cfs_psdev_register(cfs_psdev_t * psdev); -int cfs_psdev_deregister(cfs_psdev_t * psdev); +int misc_register(struct miscdevice *psdev); +int misc_deregister(struct miscdevice *psdev); /* * Proc emulator file system APIs */ -typedef int cfs_read_proc_t(char *page, char **start, off_t off, - int count, int *eof, void *data); -typedef int cfs_write_proc_t(struct file *file, const char *buffer, - ulong_ptr count, void *data); +typedef int read_proc_t(char *page, char **start, off_t off, + int count, int *eof, void *data); +typedef int write_proc_t(struct file *file, const char *buffer, + unsigned long count, void *data); #define CFS_PROC_ENTRY_MAGIC 'CPEM' @@ -138,17 +152,20 @@ typedef struct cfs_proc_entry PRTL_SPLAY_LINKS root; }; + struct cfs_proc_entry *parent; + struct _file_entry { // proc file / leaf entry - cfs_read_proc_t * read_proc; - cfs_write_proc_t * write_proc; + read_proc_t * read_proc; + write_proc_t * write_proc; }; mode_t mode; unsigned short nlink; + BOOLEAN deleted; - struct file_operations * proc_fops; - void * data; + struct file_operations *proc_fops; + void *data; // proc_dir_entry ended. @@ -163,41 +180,37 @@ typedef struct cfs_proc_entry } cfs_proc_entry_t, cfs_proc_dir_entry_t; typedef cfs_proc_entry_t cfs_proc_dir_entry_t; +#define proc_dir_entry cfs_proc_entry #define PROC_BLOCK_SIZE PAGE_SIZE +struct proc_dir_entry *PDE(const struct inode *inode); + + /* * Sysctl register */ - -typedef struct ctl_table cfs_sysctl_table_t; -typedef struct ctl_table_header cfs_sysctl_table_header_t; - - -typedef int ctl_handler ( - cfs_sysctl_table_t *table, - int *name, int nlen, +typedef int ctl_handler(struct ctl_table *table, + int *name, int nlen, void *oldval, size_t *oldlenp, - void *newval, size_t newlen, - void **context ); + void *newval, size_t newlen, + void **context); -typedef int proc_handler ( - cfs_sysctl_table_t *ctl, - int write, struct file * filp, - void *buffer, size_t *lenp ); +typedef int proc_handler (struct ctl_table *ctl, + int write, struct file *filp, + void *buffer, size_t *lenp); -int proc_dointvec(cfs_sysctl_table_t *table, int write, struct file *filp, +int proc_dointvec(struct ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp); -int proc_dostring(cfs_sysctl_table_t *table, int write, struct file *filp, +int proc_dostring(struct ctl_table *table, int write, struct file *filp, void *buffer, size_t *lenp); -int sysctl_string(cfs_sysctl_table_t *table, int *name, int nlen, +int sysctl_string(struct ctl_table *table, int *name, int nlen, void *oldval, size_t *oldlenp, void *newval, size_t newlen, void **context); - /* * System io control definitions */ @@ -229,7 +242,7 @@ struct ctl_table void *data; int maxlen; mode_t mode; - cfs_sysctl_table_t *child; + struct ctl_table *child; proc_handler *proc_handler; /* text formatting callback */ ctl_handler *strategy; /* read / write callback functions */ cfs_proc_entry_t *de; /* proc entry block */ @@ -241,98 +254,151 @@ struct ctl_table /* the mantaner of the cfs_sysctl_table trees */ struct ctl_table_header { - cfs_sysctl_table_t * ctl_table; - struct list_head ctl_entry; + struct ctl_table *ctl_table; + struct list_head ctl_entry; }; +/* proc root entries, support routines */ +extern cfs_proc_entry_t * cfs_proc_root; /* / */ +extern cfs_proc_entry_t * cfs_proc_proc; /* /proc */ +extern cfs_proc_entry_t * cfs_proc_fs; /* /proc/fs */ +extern cfs_proc_entry_t * cfs_proc_sys; /* /proc/sys */ +extern cfs_proc_entry_t * cfs_proc_dev; /* /dev */ -cfs_proc_entry_t * create_proc_entry(char *name, mode_t mod, +cfs_proc_entry_t * create_proc_entry(const char *name, mode_t mod, cfs_proc_entry_t *parent); void proc_free_entry(cfs_proc_entry_t *de); -void remove_proc_entry(char *name, cfs_proc_entry_t *entry); -cfs_proc_entry_t * search_proc_entry(char * name, +void remove_proc_entry(const char *name, cfs_proc_entry_t *entry); +cfs_proc_entry_t * search_proc_entry(const char * name, cfs_proc_entry_t * root ); +cfs_proc_entry_t *proc_symlink(const char *name, + cfs_proc_entry_t *parent, + const char *dest); +cfs_proc_entry_t *proc_mkdir(const char *name, + cfs_proc_entry_t *parent); #define cfs_create_proc_entry create_proc_entry #define cfs_free_proc_entry proc_free_entry #define cfs_remove_proc_entry remove_proc_entry -#define register_cfs_sysctl_table(t, a) register_sysctl_table(t, a) -#define unregister_cfs_sysctl_table(t) unregister_sysctl_table(t, a) +struct ctl_table_header *register_sysctl_table(struct ctl_table *table); +void unregister_sysctl_table(struct ctl_table_header *header); + +/* + * seq device (linux/seq_file.h) + */ /* - * declaration of proc kernel process routines + * seq file definitions */ -cfs_file_t * -lustre_open_file(char * filename); +struct dentry; +struct vfsmount; -int -lustre_close_file(cfs_file_t * fh); +struct path { + struct vfsmount *mnt; + struct dentry *dentry; +}; -int -lustre_do_ioctl( cfs_file_t * fh, - unsigned long cmd, - ulong_ptr arg ); +struct seq_operations; +struct file; +struct inode; + +struct seq_file { + char *buf; + size_t size; + size_t from; + size_t count; + loff_t index; + u32 version; + struct mutex lock; + const struct seq_operations *op; + void *private; +}; -int -lustre_ioctl_file( cfs_file_t * fh, - PCFS_PROC_IOCTL devctl); - -size_t -lustre_read_file( cfs_file_t * fh, - loff_t off, - size_t size, - char * buf - ); - -size_t -lustre_write_file( cfs_file_t * fh, - loff_t off, - size_t size, - char * buf - ); +struct seq_operations { + void * (*start) (struct seq_file *m, loff_t *pos); + void (*stop) (struct seq_file *m, void *v); + void * (*next) (struct seq_file *m, void *v, loff_t *pos); + int (*show) (struct seq_file *m, void *v); +}; + +int seq_open(struct file *, const struct seq_operations *); +ssize_t seq_read(struct file *, char __user *, size_t, loff_t *); +loff_t seq_lseek(struct file *, loff_t, int); +int seq_release(struct inode *, struct file *); +int seq_escape(struct seq_file *, const char *, const char *); +int seq_putc(struct seq_file *m, char c); +int seq_puts(struct seq_file *m, const char *s); + +int seq_path(struct seq_file *, struct path *, char *); + +int single_open(struct file *, int (*)(struct seq_file *, void *), void *); +int single_release(struct inode *, struct file *); +void *__seq_open_private(struct file *, const struct seq_operations *, int); +int seq_open_private(struct file *, const struct seq_operations *, int); +int seq_release_private(struct inode *, struct file *); + +#define SEQ_START_TOKEN ((void *)1) /* - * Wait Queue + * Helpers for iteration over list_head-s in seq_files */ +extern struct list_head *seq_list_start(struct list_head *head, loff_t pos); +extern struct list_head *seq_list_start_head(struct list_head *head, loff_t pos); +extern struct list_head *seq_list_next(void *v, struct list_head *head, loff_t *ppos); + +/* + * declaration of proc kernel process routines + */ -typedef int cfs_task_state_t; +struct file *lustre_open_file(char *filename); -#define CFS_TASK_INTERRUPTIBLE 0x00000001 -#define CFS_TASK_UNINT 0x00000002 +int lustre_close_file(struct file *fh); +int lustre_do_ioctl(struct file *fh, unsigned long cmd, ulong_ptr_t arg); +int lustre_ioctl_file(struct file *fh, PCFS_PROC_IOCTL devctl); + +size_t lustre_read_file(struct file *fh, loff_t offl, size_t size, char *buf); + +size_t lustre_write_file(struct file *fh, loff_t off, size_t size, char *buf); + +/* + * Wait Queue + */ + + +#define TASK_INTERRUPTIBLE 0x00000001 +#define TASK_UNINTERRUPTIBLE 0x00000002 +#define TASK_RUNNING 0x00000003 +#define CFS_TASK_UNINTERRUPTIBLE TASK_UNINTERRUPTIBLE #define CFS_WAITQ_MAGIC 'CWQM' #define CFS_WAITLINK_MAGIC 'CWLM' typedef struct cfs_waitq { + unsigned int magic; + unsigned int flags; - unsigned int magic; - unsigned int flags; - - spinlock_t guard; - struct list_head waiters; - -} cfs_waitq_t; + spinlock_t guard; + struct list_head waiters; +} wait_queue_head_t; -typedef struct cfs_waitlink cfs_waitlink_t; +typedef struct cfs_waitlink wait_queue_t; #define CFS_WAITQ_CHANNELS (2) #define CFS_WAITQ_CHAN_NORMAL (0) #define CFS_WAITQ_CHAN_FORWARD (1) - - typedef struct cfs_waitlink_channel { - struct list_head link; - cfs_waitq_t * waitq; - cfs_waitlink_t * waitl; + struct list_head link; + wait_queue_head_t *waitq; + wait_queue_t *waitl; } cfs_waitlink_channel_t; struct cfs_waitlink { @@ -340,7 +406,7 @@ struct cfs_waitlink { unsigned int magic; int flags; event_t * event; - atomic_t * hits; + atomic_t * hits; cfs_waitlink_channel_t waitq[CFS_WAITQ_CHANNELS]; }; @@ -349,28 +415,7 @@ enum { CFS_WAITQ_EXCLUSIVE = 1 }; -#define CFS_DECL_WAITQ(name) cfs_waitq_t name - - -void cfs_waitq_init(struct cfs_waitq *waitq); -void cfs_waitlink_init(struct cfs_waitlink *link); - -void cfs_waitq_add(struct cfs_waitq *waitq, struct cfs_waitlink *link); -void cfs_waitq_add_exclusive(struct cfs_waitq *waitq, - struct cfs_waitlink *link); -void cfs_waitq_forward(struct cfs_waitlink *link, struct cfs_waitq *waitq); -void cfs_waitq_del(struct cfs_waitq *waitq, struct cfs_waitlink *link); -int cfs_waitq_active(struct cfs_waitq *waitq); - -void cfs_waitq_signal(struct cfs_waitq *waitq); -void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr); -void cfs_waitq_broadcast(struct cfs_waitq *waitq); - -void cfs_waitq_wait(struct cfs_waitlink *link, cfs_task_state_t state); -cfs_duration_t cfs_waitq_timedwait(struct cfs_waitlink *link, - cfs_task_state_t state, cfs_duration_t timeout); - - +#define CFS_DECL_WAITQ(name) wait_queue_head_t name /* Kernel thread */ @@ -381,8 +426,6 @@ typedef struct _cfs_thread_context { void * arg; } cfs_thread_context_t; -int cfs_kernel_thread(int (*func)(void *), void *arg, int flag); - /* * thread creation flags from Linux, not used in winnt */ @@ -400,41 +443,132 @@ int cfs_kernel_thread(int (*func)(void *), void *arg, int flag); #define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD) +/* + * group_info: linux/sched.h + */ +#define NGROUPS_SMALL 32 +#define NGROUPS_PER_BLOCK ((int)(PAGE_SIZE / sizeof(gid_t))) +struct group_info { + int ngroups; + atomic_t usage; + gid_t small_block[NGROUPS_SMALL]; + int nblocks; + gid_t *blocks[0]; +}; + +#define get_group_info(group_info) do { \ + atomic_inc(&(group_info)->usage); \ +} while (0) + +#define put_group_info(group_info) do { \ + if (atomic_dec_and_test(&(group_info)->usage)) \ + groups_free(group_info); \ +} while (0) + +static __inline struct group_info *groups_alloc(int gidsetsize) +{ + struct group_info * groupinfo; + KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__, __FUNCTION__)); + groupinfo = kmalloc(sizeof(struct group_info), 0); + + if (groupinfo) { + memset(groupinfo, 0, sizeof(struct group_info)); + } + return groupinfo; +} + +static __inline void groups_free(struct group_info *group_info) +{ + KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__, + __FUNCTION__)); + kfree(group_info); +} + +static __inline int +set_current_groups(struct group_info *group_info) +{ + KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__, + __FUNCTION__)); + return 0; +} + +static __inline int groups_search(struct group_info *group_info, + gid_t grp) { + KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__, + __FUNCTION__)); + return 0; +} /* - * sigset ... + * capability issue (linux/capability.h) */ -typedef sigset_t cfs_sigset_t; +/* Override resource limits. Set resource limits. */ +/* Override quota limits. */ +/* Override reserved space on ext2 filesystem */ +/* Modify data journaling mode on ext3 filesystem (uses journaling + resources) */ +/* NOTE: ext2 honors fsuid when checking for resource overrides, so + you can override using fsuid too */ +/* Override size restrictions on IPC message queues */ +/* Allow more than 64hz interrupts from the real-time clock */ +/* Override max number of consoles on console allocation */ +/* Override max number of keymaps */ + +#define CAP_SYS_RESOURCE 24 /* - * Task struct + * capabilities support */ -#define MAX_SCHEDULE_TIMEOUT ((long_ptr)(~0UL>>12)) +typedef __u32 kernel_cap_t; +#define cap_raise(c, flag) do {} while(0) +#define cap_lower(c, flag) do {} while(0) +#define cap_raised(c, flag) do {} while(0) -#define NGROUPS 1 -#define CFS_CURPROC_COMM_MAX (16) -typedef struct task_sruct{ - mode_t umask; - pid_t pid; - pid_t pgrp; +/* + * Task struct + */ + +#define MAX_SCHEDULE_TIMEOUT ((long_ptr_t)(~0UL>>12)) +#define schedule_timeout(t) schedule_timeout_and_set_state(0, t) - uid_t uid,euid,suid,fsuid; - gid_t gid,egid,sgid,fsgid; +struct vfsmount; - int ngroups; - gid_t groups[NGROUPS]; - cfs_kernel_cap_t cap_effective, - cap_inheritable, - cap_permitted; +#define NGROUPS 1 +#define CFS_CURPROC_COMM_MAX (16) +struct task_struct{ + mode_t umask; + sigset_t blocked; + + pid_t pid; + pid_t pgrp; + + uid_t uid,euid,suid,fsuid; + gid_t gid,egid,sgid,fsgid; + + int ngroups; + int cgroups; + gid_t groups[NGROUPS]; + struct group_info *group_info; + kernel_cap_t cap_effective, + cap_inheritable, + cap_permitted; + + char comm[CFS_CURPROC_COMM_MAX]; + void *journal_info; + struct vfsmount *fs; +}; - char comm[CFS_CURPROC_COMM_MAX]; - void * journal_info; -} cfs_task_t; +static inline void task_lock(struct task_struct *t) +{ +} +static inline void task_unlock(struct task_struct *t) +{ +} /* * linux task struct emulator ... @@ -444,91 +578,113 @@ typedef struct task_sruct{ #define TASKSLT_MAGIC 'TSLT' /* Task Slot */ typedef struct _TASK_MAN { + ULONG Magic; /* Magic and Flags */ + ULONG Flags; - ULONG Magic; /* Magic and Flags */ - ULONG Flags; - - spinlock_t Lock; /* Protection lock */ + spinlock_t Lock; /* Protection lock */ - cfs_mem_cache_t * slab; /* Memory slab for task slot */ - - ULONG NumOfTasks; /* Total tasks (threads) */ - LIST_ENTRY TaskList; /* List of task slots */ + struct kmem_cache *slab; /* Memory slab for task slot */ + ULONG NumOfTasks; /* Total tasks (threads) */ + LIST_ENTRY TaskList; /* List of task slots */ } TASK_MAN, *PTASK_MAN; typedef struct _TASK_SLOT { - ULONG Magic; /* Magic and Flags */ - ULONG Flags; + ULONG Magic; /* Magic and Flags */ + ULONG Flags; - LIST_ENTRY Link; /* To be linked to TaskMan */ + LIST_ENTRY Link; /* To be linked to TaskMan */ - event_t Event; /* Schedule event */ + event_t Event; /* Schedule event */ - HANDLE Pid; /* Process id */ - HANDLE Tid; /* Thread id */ - PETHREAD Tet; /* Pointer to ethread */ + HANDLE Pid; /* Process id */ + HANDLE Tid; /* Thread id */ + PETHREAD Tet; /* Pointer to ethread */ atomic_t count; /* refer count */ atomic_t hits; /* times of waken event singaled */ - KIRQL irql; /* irql for rwlock ... */ + KIRQL irql; /* irql for rwlock ... */ - cfs_task_t task; /* linux task part */ + struct task_struct task; /* linux task part */ } TASK_SLOT, *PTASK_SLOT; -#define current cfs_current() -#define set_current_state(s) do {;} while (0) +#define set_current_state(s) do {;} while (0) #define wait_event(wq, condition) \ -do { \ - cfs_waitlink_t __wait; \ - \ - cfs_waitlink_init(&__wait); \ +do { \ + wait_queue_t __wait; \ + \ + init_waitqueue_entry_current(&__wait); \ while (TRUE) { \ - cfs_waitq_add(&wq, &__wait); \ - if (condition) { \ - break; \ - } \ - cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE); \ - cfs_waitq_del(&wq, &__wait); \ - } \ - cfs_waitq_del(&wq, &__wait); \ + add_wait_queue(&wq, &__wait); \ + if (condition) { \ + break; \ + } \ + waitq_wait(&__wait, TASK_INTERRUPTIBLE); \ + remove_wait_queue(&wq, &__wait); \ + } \ + remove_wait_queue(&wq, &__wait); \ } while(0) -#define wait_event_interruptible(wq, condition, __ret) \ -do { \ - cfs_waitlink_t __wait; \ - \ - __ret = 0; \ - cfs_waitlink_init(&__wait); \ +#define wait_event_interruptible(wq, condition) \ +{ \ + wait_queue_t __wait; \ + \ + __ret = 0; \ + init_waitqueue_entry_current(&__wait); \ while (TRUE) { \ - cfs_waitq_add(&wq, &__wait); \ - if (condition) { \ - break; \ - } \ - cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE); \ - cfs_waitq_del(&wq, &__wait); \ - } \ - cfs_waitq_del(&wq, &__wait); \ -} while(0) + add_wait_queue(&wq, &__wait); \ + if (condition) { \ + break; \ + } \ + waitq_wait(&__wait, TASK_INTERRUPTIBLE);\ + remove_wait_queue(&wq, &__wait); \ + } \ + remove_wait_queue(&wq, &__wait); \ + __ret; \ +} +# define wait_event_interruptible_exclusive(wq, condition) \ + wait_event_interruptible(wq, condition) + +/* + retval == 0; condition met; we're good. + retval < 0; interrupted by signal. + retval > 0; timed out. +*/ + +#define wait_event_interruptible_timeout(wq, condition, timeout)\ +do { \ + wait_queue_t __wait; \ + \ + init_waitqueue_entry_current(&__wait); \ + while (TRUE) { \ + add_wait_queue(&wq, &__wait); \ + if (condition) { \ + break; \ + } \ + if (waitq_timedwait(&__wait, \ + TASK_INTERRUPTIBLE, timeout) == 0) { \ + break; \ + } \ + remove_wait_queue(&wq, &__wait); \ + } \ + remove_wait_queue(&wq, &__wait); \ +} while(0) int init_task_manager(); void cleanup_task_manager(); -cfs_task_t * cfs_current(); -int schedule_timeout(int64_t time); -int schedule(); -int wake_up_process(cfs_task_t * task); -#define cfs_schedule_timeout(state, time) schedule_timeout(time) -void sleep_on(cfs_waitq_t *waitq); - -#define CFS_DECL_JOURNAL_DATA -#define CFS_PUSH_JOURNAL do {;} while(0) -#define CFS_POP_JOURNAL do {;} while(0) +struct task_struct * current; +int wake_up_process(struct task_struct * task); +void sleep_on(wait_queue_head_t *waitq); +#define might_sleep() do {} while(0) +#define DECL_JOURNAL_DATA +#define PUSH_JOURNAL do {;} while(0) +#define POP_JOURNAL do {;} while(0) /* module related definitions */ @@ -540,9 +696,14 @@ void sleep_on(cfs_waitq_t *waitq); #define __init #endif -#define request_module(x) (0) +struct module{ + const char *name; +}; + +extern struct module libcfs_global_module; +#define THIS_MODULE &libcfs_global_module -#define EXPORT_SYMBOL(s) +#define request_module(x, y) (0) #define MODULE_AUTHOR(s) #define MODULE_DESCRIPTION(s) #define MODULE_LICENSE(s) @@ -564,22 +725,44 @@ void sleep_on(cfs_waitq_t *waitq); /* Module interfaces */ #define cfs_module(name, version, init, fini) \ -module_init(init); \ -module_exit(fini) + module_init(init); \ + module_exit(fini) +#define module_refcount(x) (1) + +/* + * typecheck + */ +#define typecheck(a, b) do {} while(0) /* - * Linux kernel version definition + * linux/crypto.h */ -#define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c) -#define LINUX_VERSION_CODE (2*100+6*10+7) +#define CRYPTO_MAX_ALG_NAME 64 +#define CRYPTO_TFM_MODE_ECB 0x00000001 +#define CRYPTO_TFM_MODE_CBC 0x00000002 +#define CRYPTO_TFM_MODE_CFB 0x00000004 +#define CRYPTO_TFM_MODE_CTR 0x00000008 +#define CRYPTO_TFM_MODE_EME 0x00000010 /* - * Signal + * hash */ -#define SIGNAL_MASK_ASSERT() +/* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */ +#define GOLDEN_RATIO_PRIME_32 0x9e370001UL + +#if 0 /* defined in libcfs/libcfs_hash.h */ +static inline u32 hash_long(u32 val, unsigned int bits) +{ + /* On some cpus multiply is faster, on others gcc will do shifts */ + u32 hash = val * GOLDEN_RATIO_PRIME_32; + + /* High bits are more random, so use them. */ + return hash >> (32 - bits); +} +#endif /* * Timer @@ -588,7 +771,7 @@ module_exit(fini) #define CFS_TIMER_FLAG_INITED 0x00000001 // Initialized already #define CFS_TIMER_FLAG_TIMERED 0x00000002 // KeSetTimer is called -typedef struct cfs_timer { +struct timer_list { KSPIN_LOCK Lock; @@ -599,39 +782,10 @@ typedef struct cfs_timer { cfs_time_t deadline; - void (*proc)(ulong_ptr); + void (*proc)(ulong_ptr_t); void * arg; -} cfs_timer_t; - - -typedef void (*timer_func_t)(ulong_ptr); - -#define cfs_init_timer(t) - -void cfs_timer_init(cfs_timer_t *timer, void (*func)(ulong_ptr), void *arg); -void cfs_timer_done(cfs_timer_t *t); -void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline); -void cfs_timer_disarm(cfs_timer_t *t); -int cfs_timer_is_armed(cfs_timer_t *t); -cfs_time_t cfs_timer_deadline(cfs_timer_t *t); - - -/* deschedule for a bit... */ -static inline void cfs_pause(cfs_duration_t ticks) -{ - cfs_schedule_timeout(TASK_UNINTERRUPTIBLE, ticks); -} - - -static inline void cfs_enter_debugger(void) -{ -#if _X86_ - __asm int 3; -#else - KdBreakPoint(); -#endif -} +}; /* * libcfs globals initialization/cleanup @@ -644,23 +798,33 @@ void libcfs_arch_cleanup(void); /* + * cache alignment size + */ + +#define L1_CACHE_ALIGN(x) (x) + +#define __cacheline_aligned + +/* * SMP ... */ + #define SMP_CACHE_BYTES 128 -#define __cacheline_aligned -#define NR_CPUS (2) -#define smp_processor_id() KeGetCurrentProcessorNumber() -#define smp_num_cpus NR_CPUS -#define num_online_cpus() smp_num_cpus +#define NR_CPUS (32) +#define smp_num_cpus ((CCHAR)KeNumberProcessors) +#define num_possible_cpus() smp_num_cpus +#define num_online_cpus() smp_num_cpus +#define smp_processor_id() ((USHORT)KeGetCurrentProcessorNumber()) #define smp_call_function(f, a, n, w) do {} while(0) +#define smp_rmb() do {} while(0) /* * Irp related */ -#define NR_IRQS 512 -#define in_interrupt() (0) +#define NR_IRQS 512 +#define in_interrupt() (0) /* * printk flags @@ -679,7 +843,6 @@ libcfs_arch_cleanup(void); * Misc */ - #define inter_module_get(n) cfs_symbol_get(n) #define inter_module_put(n) cfs_symbol_put(n) @@ -690,73 +853,77 @@ libcfs_arch_cleanup(void); #define unlikely(exp) (exp) #endif -#define lock_kernel() do {} while(0) -#define unlock_kernel() do {} while(0) - -#define CAP_SYS_ADMIN 0 -#define CAP_SYS_ROOT 1 - -#define capable(a) (TRUE) - -#define USERMODEHELPER(path, argv, envp) (0) - - #define local_irq_save(x) #define local_irq_restore(x) -#define cfs_assert ASSERT +#define va_copy(_d, _s) (_d = _s) -#define THREAD_NAME +char *strnchr(const char *s, size_t count, int c); -#else /* !__KERNEL__ */ +#define adler32(a,b,l) zlib_adler32(a,b,l) +ULONG zlib_adler32(ULONG adler, const BYTE *buf, UINT len); -#define PAGE_CACHE_SIZE PAGE_SIZE -#define PAGE_CACHE_MASK PAGE_MASK +typedef ssize_t (*read_actor_t)(); -#define getpagesize() (PAGE_SIZE) +#if DBG +/* + * winnt debug routines + */ +VOID +KsPrintf( + LONG DebugPrintLevel, + PCHAR DebugMessage, + ... + ); -typedef struct { - int foo; -} pthread_mutex_t; +PUCHAR +KsNtStatusToString (IN NTSTATUS Status); +#endif -typedef struct { - int foo; -} pthread_cond_t; +#else /* !__KERNEL__ */ -#define pthread_mutex_init(x, y) do {} while(0) -#define pthread_cond_init(x, y) do {} while(0) +void cfs_enter_debugger(); -#define pthread_mutex_lock(x) do {} while(0) -#define pthread_mutex_unlock(x) do {} while(0) +/* + * PAGE_SIZE ... + */ -#define pthread_cond_wait(x,y) do {} while(0) -#define pthread_cond_broadcast(x) do {} while(0) +#ifndef PAGE_SIZE +#define PAGE_SIZE (4096) +#endif -typedef struct file { - int foo; -} cfs_file_t; +#define getpagesize() (4096) -typedef struct cfs_proc_dir_entry{ - void *data; -}cfs_proc_dir_entry_t; +#define PAGE_CACHE_SIZE PAGE_SIZE +#define PAGE_CACHE_MASK PAGE_MASK +#define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1) +#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t) -2) +#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t) -3) +struct file { + int foo; +}; #include "../user-prim.h" - +#include "../user-lock.h" #include #include #define strcasecmp strcmp #define strncasecmp strncmp -#define snprintf _snprintf #define getpid() (0) - -#define getpwuid(x) (NULL) +#define getuid() (0) #define getgrgid(x) (NULL) +struct passwd { + uid_t pw_uid; + char pw_name[64]; +}; +struct passwd * getpwuid(uid_t uid); + int cfs_proc_mknod(const char *path, mode_t mode, dev_t dev); int gethostname(char * name, int namelen); @@ -764,195 +931,190 @@ int gethostname(char * name, int namelen); #define setlinebuf(x) do {} while(0) -NTSYSAPI VOID NTAPI DebugBreak(); +/* Maximum EA Information Length */ +#define EA_MAX_LENGTH (sizeof(FILE_FULL_EA_INFORMATION) + 15) +/* + * proc user mode routines + */ -static inline void cfs_enter_debugger(void) -{ -#if _X86_ - __asm int 3; +int cfs_proc_open (char * filename, int oflag); +int cfs_proc_close(int fd); +int cfs_proc_read(int fd, void *buffer, unsigned int count); +int cfs_proc_write(int fd, void *buffer, unsigned int count); +int cfs_proc_ioctl(int fd, int cmd, void *buffer); +FILE *cfs_proc_fopen(char *path, char * mode); +char *cfs_proc_fgets(char * buf, int len, FILE *fp); +int cfs_proc_fclose(FILE *fp); + +/* Bits set in the FLAGS argument to `glob'. */ +#define GLOB_ERR (1 << 0)/* Return on read errors. */ +#define GLOB_MARK (1 << 1)/* Append a slash to each name. */ +#define GLOB_NOSORT (1 << 2)/* Don't sort the names. */ +#define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */ +#define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */ +#define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */ +#define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */ +#define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */ + +#if !defined __USE_POSIX2 || defined __USE_BSD || defined __USE_GNU +# define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */ +# define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */ +# define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */ +# define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */ +# define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */ +# define GLOB_ONLYDIR (1 << 13)/* Match only directories. */ +# define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error + if the user name is not available. */ +# define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ + GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \ + GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \ + GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK) #else - DebugBreak(); +# define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ + GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \ + GLOB_PERIOD) #endif -} -/* Maximum EA Information Length */ -#define EA_MAX_LENGTH (sizeof(FILE_FULL_EA_INFORMATION) + 15) +/* Error returns from `glob'. */ +#define GLOB_NOSPACE 1 /* Ran out of memory. */ +#define GLOB_ABORTED 2 /* Read error. */ +#define GLOB_NOMATCH 3 /* No matches found. */ +#define GLOB_NOSYS 4 /* Not implemented. */ +#ifdef __USE_GNU +/* Previous versions of this file defined GLOB_ABEND instead of + GLOB_ABORTED. Provide a compatibility definition here. */ +# define GLOB_ABEND GLOB_ABORTED +#endif +/* Structure describing a globbing run. */ +#ifdef __USE_GNU +struct stat; +#endif +typedef struct + { + size_t gl_pathc; /* Count of paths matched by the pattern. */ + char **gl_pathv; /* List of matched pathnames. */ + size_t gl_offs; /* Slots to reserve in `gl_pathv'. */ + int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */ + + /* If the GLOB_ALTDIRFUNC flag is set, the following functions + are used instead of the normal file access functions. */ + void (*gl_closedir) (void *); +#ifdef __USE_GNU + struct dirent *(*gl_readdir) (void *); +#else + void *(*gl_readdir) (void *); +#endif + void *(*gl_opendir) (const char *); +#ifdef __USE_GNU + int (*gl_lstat) (const char *__restrict, struct stat *__restrict); + int (*gl_stat) (const char *__restrict, struct stat *__restrict); +#else + int (*gl_lstat) (const char *__restrict, void *__restrict); + int (*gl_stat) (const char *__restrict, void *__restrict); +#endif + } glob_t; + +#ifdef __USE_LARGEFILE64 +# ifdef __USE_GNU +struct stat64; +# endif +typedef struct + { + __size_t gl_pathc; + char **gl_pathv; + __size_t gl_offs; + int gl_flags; + + /* If the GLOB_ALTDIRFUNC flag is set, the following functions + are used instead of the normal file access functions. */ + void (*gl_closedir) (void *); +# ifdef __USE_GNU + struct dirent64 *(*gl_readdir) (void *); +# else + void *(*gl_readdir) (void *); +# endif + void *(*gl_opendir) (__const char *); +# ifdef __USE_GNU + int (*gl_lstat) (__const char *__restrict, struct stat64 *__restrict); + int (*gl_stat) (__const char *__restrict, struct stat64 *__restrict); +# else + int (*gl_lstat) (__const char *__restrict, void *__restrict); + int (*gl_stat) (__const char *__restrict, void *__restrict); +# endif + } glob64_t; +#endif + +int glob (const char * __pattern, int __flags, + int (*__errfunc) (const char *, int), + glob_t * __pglob); +void globfree(glob_t *__pglog); + +#endif /* !__KERNEL__ */ /* - * proc user mode routines + * module routines */ -HANDLE cfs_proc_open (char * filename, int oflag); -int cfs_proc_close(HANDLE handle); -int cfs_proc_read(HANDLE handle, void *buffer, unsigned int count); -int cfs_proc_write(HANDLE handle, void *buffer, unsigned int count); -int cfs_proc_ioctl(HANDLE handle, int cmd, void *buffer); +static inline void __module_get(struct module *module) +{ +} +static inline int try_module_get(struct module *module) +{ + return 1; +} + +static inline void module_put(struct module *module) +{ +} /* - * Native API definitions + * sigset_t routines */ -// -// Disk I/O Routines -// - -NTSYSAPI -NTSTATUS -NTAPI -NtReadFile(HANDLE FileHandle, - HANDLE Event OPTIONAL, - PIO_APC_ROUTINE ApcRoutine OPTIONAL, - PVOID ApcContext OPTIONAL, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID Buffer, - ULONG Length, - PLARGE_INTEGER ByteOffset OPTIONAL, - PULONG Key OPTIONAL); - -NTSYSAPI -NTSTATUS -NTAPI -NtWriteFile(HANDLE FileHandle, - HANDLE Event OPTIONAL, - PIO_APC_ROUTINE ApcRoutine OPTIONAL, - PVOID ApcContext OPTIONAL, - PIO_STATUS_BLOCK IoStatusBlock, - PVOID Buffer, - ULONG Length, - PLARGE_INTEGER ByteOffset OPTIONAL, - PULONG Key OPTIONAL); - -NTSYSAPI -NTSTATUS -NTAPI -NtClose(HANDLE Handle); - -NTSYSAPI -NTSTATUS -NTAPI -NtCreateFile(PHANDLE FileHandle, - ACCESS_MASK DesiredAccess, - POBJECT_ATTRIBUTES ObjectAttributes, - PIO_STATUS_BLOCK IoStatusBlock, - PLARGE_INTEGER AllocationSize OPTIONAL, - ULONG FileAttributes, - ULONG ShareAccess, - ULONG CreateDisposition, - ULONG CreateOptions, - PVOID EaBuffer OPTIONAL, - ULONG EaLength); - - -NTSYSAPI -NTSTATUS -NTAPI -NtDeviceIoControlFile( - IN HANDLE FileHandle, - IN HANDLE Event, - IN PIO_APC_ROUTINE ApcRoutine, - IN PVOID ApcContext, - OUT PIO_STATUS_BLOCK IoStatusBlock, - IN ULONG IoControlCode, - IN PVOID InputBuffer, - IN ULONG InputBufferLength, - OUT PVOID OutputBuffer, - OUT ULONG OutputBufferLength - ); - -NTSYSAPI -NTSTATUS -NTAPI -NtFsControlFile( - IN HANDLE FileHandle, - IN HANDLE Event OPTIONAL, - IN PIO_APC_ROUTINE ApcRoutine OPTIONAL, - IN PVOID ApcContext OPTIONAL, - OUT PIO_STATUS_BLOCK IoStatusBlock, - IN ULONG FsControlCode, - IN PVOID InputBuffer OPTIONAL, - IN ULONG InputBufferLength, - OUT PVOID OutputBuffer OPTIONAL, - IN ULONG OutputBufferLength -); - - -NTSYSAPI -NTSTATUS -NTAPI -NtQueryInformationFile( - IN HANDLE FileHandle, - OUT PIO_STATUS_BLOCK IoStatusBlock, - OUT PVOID FileInformation, - IN ULONG Length, - IN FILE_INFORMATION_CLASS FileInformationClass - ); +#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) +#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) +#define sigemptyset(what) (*(what) = 0, 0) +#define sigfillset(what) (*(what) = ~(0), 0) +#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) + +static __inline int +sigprocmask(int sig, sigset_t *w1, sigset_t *w2) { + return 0; +} +static __inline int +sigpending(sigset_t *what) { + return 0; +} + +/* + * common inode flags (user & kernel) + */ -// -// Random routines ... -// - -NTSYSAPI -ULONG -NTAPI -RtlRandom( - IN OUT PULONG Seed - ); - -#endif /* __KERNEL__ */ - - -// -// Inode flags (Linux uses octad number, but why ? strange!!!) -// - -#undef S_IFMT -#undef S_IFDIR -#undef S_IFCHR -#undef S_IFREG -#undef S_IREAD -#undef S_IWRITE -#undef S_IEXEC - -#define S_IFMT 0x0F000 /* 017 0000 */ -#define S_IFSOCK 0x0C000 /* 014 0000 */ -#define S_IFLNK 0x0A000 /* 012 0000 */ -#define S_IFREG 0x08000 /* 010 0000 */ -#define S_IFBLK 0x06000 /* 006 0000 */ -#define S_IFDIR 0x04000 /* 004 0000 */ -#define S_IFCHR 0x02000 /* 002 0000 */ -#define S_IFIFO 0x01000 /* 001 0000 */ -#define S_ISUID 0x00800 /* 000 4000 */ -#define S_ISGID 0x00400 /* 000 2000 */ -#define S_ISVTX 0x00200 /* 000 1000 */ - -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) -#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) -#define S_ISFIL(m) (((m) & S_IFMT) == S_IFFIL) -#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) -#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) - -#define S_IPERMISSION_MASK 0x1FF /* */ - -#define S_IRWXU 0x1C0 /* 0 0700 */ -#define S_IRUSR 0x100 /* 0 0400 */ -#define S_IWUSR 0x080 /* 0 0200 */ -#define S_IXUSR 0x040 /* 0 0100 */ - -#define S_IRWXG 0x038 /* 0 0070 */ -#define S_IRGRP 0x020 /* 0 0040 */ -#define S_IWGRP 0x010 /* 0 0020 */ -#define S_IXGRP 0x008 /* 0 0010 */ - -#define S_IRWXO 0x007 /* 0 0007 */ -#define S_IROTH 0x004 /* 0 0004 */ -#define S_IWOTH 0x002 /* 0 0002 */ -#define S_IXOTH 0x001 /* 0 0001 */ +#define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) +#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) +#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) +#define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) + +#define S_IRWXU 00700 +#define S_IRUSR 00400 +#define S_IWUSR 00200 +#define S_IXUSR 00100 + +#define S_IRWXG 00070 +#define S_IRGRP 00040 +#define S_IWGRP 00020 +#define S_IXGRP 00010 + +#define S_IRWXO 00007 +#define S_IROTH 00004 +#define S_IWOTH 00002 +#define S_IXOTH 00001 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO) #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO) @@ -960,6 +1122,7 @@ RtlRandom( #define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH) #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH) + /* * linux ioctl coding definitions */ @@ -969,7 +1132,7 @@ RtlRandom( #define _IOC_SIZEBITS 14 #define _IOC_DIRBITS 2 -#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) +#define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) @@ -1004,16 +1167,26 @@ RtlRandom( #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK) #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK) -/* - * Io vector ... - */ - -struct iovec -{ +/* i/o vector sgructure ... */ +struct iovec { void *iov_base; size_t iov_len; }; +/* idr support routines */ +struct idr_context *cfs_idr_init(); +int cfs_idr_remove(struct idr_context *idp, int id); +int cfs_idr_get_new(struct idr_context *idp, void *ptr); +int cfs_idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id); +void *cfs_idr_find(struct idr_context *idp, int id); +void cfs_idr_exit(struct idr_context *idp); + +/* runtime time routines for both kenrel and user mode */ +extern int cfs_isalpha(int); +extern int cfs_isspace(int); +extern int cfs_isupper(int); +extern int cfs_isdigit(int); +extern int cfs_isxdigit(int); #define ULONG_LONG_MAX ((__u64)(0xFFFFFFFFFFFFFFFF)) /* @@ -1022,61 +1195,86 @@ struct iovec * Ignores `locale' stuff. Assumes that the upper and lower case * alphabets and digits are each contiguous. */ -static inline __u64 -strtoull( - char *nptr, - char **endptr, - int base) +__u64 strtoull(char *nptr, char **endptr,int base); + +/* + * getopt routines + */ + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +extern char *optarg; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns -1, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +extern int optind; + +/* Callers store zero here to inhibit the error message `getopt' prints + for unrecognized options. */ + +extern int opterr; + +/* Set to an option character which was unrecognized. */ + +extern int optopt; + + +struct option { - char *s = nptr; - __u64 acc, cutoff; - int c, neg = 0, any, cutlim; - - /* - * See strtol for comments as to the logic used. - */ - do { - c = *s++; - } while (isspace(c)); - if (c == '-') { - neg = 1; - c = *s++; - } else if (c == '+') - c = *s++; - if ((base == 0 || base == 16) && - c == '0' && (*s == 'x' || *s == 'X')) { - c = s[1]; - s += 2; - base = 16; - } - if (base == 0) - base = c == '0' ? 8 : 10; - cutoff = (__u64)ULONG_LONG_MAX / (__u64)base; - cutlim = (int)((__u64)ULONG_LONG_MAX % (__u64)base); - for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) - c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; - else - break; - if (c >= base) - break; - if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) - any = -1; - else { - any = 1; - acc *= base; - acc += c; - } - } - if (any < 0) { - acc = ULONG_LONG_MAX; - } else if (neg) - acc = 0 - acc; - if (endptr != 0) - *endptr = (char *) (any ? s - 1 : nptr); - return (acc); -} + const char *name; + /* has_arg can't be an enum because some compilers complain about + type mismatches in all the code that assumes it is an int. */ + int has_arg; + int *flag; + int val; +}; + +/* Names for the values of the `has_arg' field of `struct option'. */ +# define no_argument 0 +# define required_argument 1 +# define optional_argument 2 + +extern int getopt(int ___argc, char *const *___argv, const char *__shortopts); +extern int getopt_long (int ___argc, char *const *___argv, + const char *__shortopts, + const struct option *__longopts, int *__longind); +extern int getopt_long_only (int ___argc, char *const *___argv, + const char *__shortopts, + const struct option *__longopts, int *__longind); + +extern char *strcasestr (const char *phaystack, const char *pneedle); + +/* + * global environment runtime routine + */ + +static __inline char * __cdecl cfs_getenv(const char *ENV) {return NULL;} +static __inline void __cdecl set_getenv(const char *ENV, const char *value, int overwrite) {} + +int setenv(const char *envname, const char *envval, int overwrite); + +typedef struct utsname { + char sysname[64]; + char nodename[64]; + char release[128]; + char version[128]; + char machine[64]; +}; + +int uname(struct utsname *uts); #endif