1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * libcfs/include/libcfs/winnt/winnt-prim.h
38 * Basic library routines.
41 #ifndef __LIBCFS_WINNT_CFS_PRIM_H__
42 #define __LIBCFS_WINNT_CFS_PRIM_H__
44 #ifndef __LIBCFS_LIBCFS_H__
45 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
49 * libcfs proc device object
53 #define LUSTRE_PROC_DEVICE L"\\Device\\LNetProcFS" /* proc fs emulator device object */
54 #define LUSTRE_PROC_SYMLNK L"\\DosDevices\\LNetProcFS" /* proc fs user-visible device */
58 * Device IO Control Code Definitions
61 #define FILE_DEVICE_LIBCFS ('LC')
63 #define FUNC_LIBCFS_VERSION 0x101 // get version of current libcfs
64 #define FUNC_LIBCFS_IOCTL 0x102 // Device i/o control to proc fs
67 #define IOCTL_LIBCFS_VERSION \
68 CTL_CODE (FILE_DEVICE_LIBCFS, FUNC_LIBCFS_VERSION, METHOD_BUFFERED, FILE_ANY_ACCESS)
69 #define IOCTL_LIBCFS_ENTRY \
70 CTL_CODE(FILE_DEVICE_LIBCFS, FUNC_LIBCFS_IOCTL, METHOD_BUFFERED, FILE_ANY_ACCESS)
73 typedef struct _CFS_PROC_IOCTL {
75 ULONG cmd; // ioctl command identifier
76 ULONG len; // length of data
77 int rc; // return code
78 ULONG usused; // unused
80 // UCHAR data[]; // content of the real ioctl
82 } CFS_PROC_IOCTL, *PCFS_PROC_IOCTL;
87 void cfs_enter_debugger(void);
88 #define __builtin_return_address(x) (0)
91 * Symbol functions for libcfs
93 * OSX has no facility for use to register symbol.
94 * So we have to implement it.
96 #define CFS_SYMBOL_LEN 64
99 char name[CFS_SYMBOL_LEN];
105 extern int cfs_symbol_register(const char *, const void *);
106 extern void cfs_symbol_unregister(const char *);
107 extern void * cfs_symbol_get(const char *);
108 extern void cfs_symbol_put(const char *);
109 extern void cfs_symbol_clean();
111 typedef struct file_operations cfs_file_operations_t;
112 typedef struct file cfs_file_t;
115 * Pseudo device register
122 cfs_file_operations_t * fops;
125 int cfs_psdev_register(cfs_psdev_t * psdev);
126 int cfs_psdev_deregister(cfs_psdev_t * psdev);
130 * Proc emulator file system APIs
133 typedef int cfs_read_proc_t(char *page, char **start, off_t off,
134 int count, int *eof, void *data);
135 typedef int cfs_write_proc_t(struct file *file, const char *buffer,
136 unsigned long count, void *data);
138 #define CFS_PROC_ENTRY_MAGIC 'CPEM'
140 #define CFS_PROC_FLAG_DIRECTORY 0x00000001 // directory node
141 #define CFS_PROC_FLAG_ATTACHED 0x00000002 // node is attached to proc
142 #define CFS_PROC_FLAG_MISCDEV 0x00000004 // miscellaneous device
144 typedef struct cfs_proc_entry
146 ULONG magic; // Magic
147 ULONG flags; // Flags
149 struct _dir_entry { // proc directory entry
150 PRTL_SPLAY_LINKS root;
153 struct cfs_proc_entry *parent;
155 struct _file_entry { // proc file / leaf entry
156 cfs_read_proc_t * read_proc;
157 cfs_write_proc_t * write_proc;
161 unsigned short nlink;
165 struct file_operations *proc_fops;
168 // proc_dir_entry ended.
170 RTL_SPLAY_LINKS s_link; // splay link
173 // Maximum length of proc entry name is 0x20
178 } cfs_proc_entry_t, cfs_proc_dir_entry_t;
180 typedef cfs_proc_entry_t cfs_proc_dir_entry_t;
181 #define proc_dir_entry cfs_proc_entry
183 #define PROC_BLOCK_SIZE PAGE_SIZE
185 struct proc_dir_entry *PDE(const struct inode *inode);
192 typedef struct ctl_table cfs_sysctl_table_t;
193 typedef struct ctl_table_header cfs_sysctl_table_header_t;
196 typedef int ctl_handler (
197 cfs_sysctl_table_t *table,
199 void *oldval, size_t *oldlenp,
200 void *newval, size_t newlen,
203 typedef int proc_handler (
204 cfs_sysctl_table_t *ctl,
205 int write, struct file * filp,
206 void *buffer, size_t *lenp );
209 int proc_dointvec(cfs_sysctl_table_t *table, int write, struct file *filp,
210 void *buffer, size_t *lenp);
212 int proc_dostring(cfs_sysctl_table_t *table, int write, struct file *filp,
213 void *buffer, size_t *lenp);
215 int sysctl_string(cfs_sysctl_table_t *table, int *name, int nlen,
216 void *oldval, size_t *oldlenp,
217 void *newval, size_t newlen, void **context);
220 * System io control definitions
223 #define CTL_MAXNAME 10
225 #define CTL_ANY -1 /* Matches any name */
230 CTL_KERN=1, /* General kernel info and control */
231 CTL_VM=2, /* VM management */
232 CTL_NET=3, /* Networking */
233 CTL_PROC=4, /* Process info */
234 CTL_FS=5, /* Filesystems */
235 CTL_DEBUG=6, /* Debugging */
236 CTL_DEV=7, /* Devices */
237 CTL_BUS=8, /* Busses */
238 CTL_ABI=9, /* Binary emulation */
239 CTL_CPU=10 /* CPU stuff (speed scaling, etc) */
242 /* sysctl table definitons */
250 cfs_sysctl_table_t *child;
251 proc_handler *proc_handler; /* text formatting callback */
252 ctl_handler *strategy; /* read / write callback functions */
253 cfs_proc_entry_t *de; /* proc entry block */
259 /* the mantaner of the cfs_sysctl_table trees */
260 struct ctl_table_header
262 cfs_sysctl_table_t * ctl_table;
263 cfs_list_t ctl_entry;
266 /* proc root entries, support routines */
267 extern cfs_proc_entry_t * cfs_proc_root; /* / */
268 extern cfs_proc_entry_t * cfs_proc_proc; /* /proc */
269 extern cfs_proc_entry_t * cfs_proc_fs; /* /proc/fs */
270 extern cfs_proc_entry_t * cfs_proc_sys; /* /proc/sys */
271 extern cfs_proc_entry_t * cfs_proc_dev; /* /dev */
273 cfs_proc_entry_t * create_proc_entry(const char *name, mode_t mod,
274 cfs_proc_entry_t *parent);
275 void proc_free_entry(cfs_proc_entry_t *de);
276 void remove_proc_entry(const char *name, cfs_proc_entry_t *entry);
277 cfs_proc_entry_t * search_proc_entry(const char * name,
278 cfs_proc_entry_t * root );
279 cfs_proc_entry_t *proc_symlink(const char *name,
280 cfs_proc_entry_t *parent,
282 cfs_proc_entry_t *proc_mkdir(const char *name,
283 cfs_proc_entry_t *parent);
285 #define cfs_create_proc_entry create_proc_entry
286 #define cfs_free_proc_entry proc_free_entry
287 #define cfs_remove_proc_entry remove_proc_entry
289 struct ctl_table_header *register_sysctl_table(cfs_sysctl_table_t * table,
291 void unregister_sysctl_table(struct ctl_table_header * header);
293 #define cfs_register_sysctl_table(t, a) register_sysctl_table(t, a)
294 #define cfs_unregister_sysctl_table(t) unregister_sysctl_table(t)
297 * seq device (linux/seq_file.h)
302 * seq file definitions
309 struct vfsmount *mnt;
310 struct dentry *dentry;
313 struct seq_operations;
325 const struct seq_operations *op;
329 struct seq_operations {
330 void * (*start) (struct seq_file *m, loff_t *pos);
331 void (*stop) (struct seq_file *m, void *v);
332 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
333 int (*show) (struct seq_file *m, void *v);
336 int seq_open(struct file *, const struct seq_operations *);
337 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
338 loff_t seq_lseek(struct file *, loff_t, int);
339 int seq_release(struct inode *, struct file *);
340 int seq_escape(struct seq_file *, const char *, const char *);
341 int seq_putc(struct seq_file *m, char c);
342 int seq_puts(struct seq_file *m, const char *s);
344 int seq_printf(struct seq_file *, const char *, ...)
345 __attribute__ ((format (printf,2,3)));
347 int seq_path(struct seq_file *, struct path *, char *);
349 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
350 int single_release(struct inode *, struct file *);
351 void *__seq_open_private(struct file *, const struct seq_operations *, int);
352 int seq_open_private(struct file *, const struct seq_operations *, int);
353 int seq_release_private(struct inode *, struct file *);
355 #define SEQ_START_TOKEN ((void *)1)
358 * Helpers for iteration over list_head-s in seq_files
361 extern cfs_list_t *seq_list_start(cfs_list_t *head, loff_t pos);
362 extern cfs_list_t *seq_list_start_head(cfs_list_t *head, loff_t pos);
363 extern cfs_list_t *seq_list_next(void *v, cfs_list_t *head, loff_t *ppos);
366 * declaration of proc kernel process routines
370 lustre_open_file(char * filename);
373 lustre_close_file(cfs_file_t * fh);
376 lustre_do_ioctl( cfs_file_t * fh,
381 lustre_ioctl_file( cfs_file_t * fh,
382 PCFS_PROC_IOCTL devctl);
385 lustre_read_file( cfs_file_t * fh,
392 lustre_write_file( cfs_file_t * fh,
403 typedef int cfs_task_state_t;
405 #define CFS_TASK_INTERRUPTIBLE 0x00000001
406 #define CFS_TASK_UNINT 0x00000002
407 #define CFS_TASK_RUNNING 0x00000003
408 #define CFS_TASK_UNINTERRUPTIBLE CFS_TASK_UNINT
410 #define CFS_WAITQ_MAGIC 'CWQM'
411 #define CFS_WAITLINK_MAGIC 'CWLM'
413 typedef struct cfs_waitq {
418 cfs_spinlock_t guard;
424 typedef struct cfs_waitlink cfs_waitlink_t;
426 #define CFS_WAITQ_CHANNELS (2)
428 #define CFS_WAITQ_CHAN_NORMAL (0)
429 #define CFS_WAITQ_CHAN_FORWARD (1)
433 typedef struct cfs_waitlink_channel {
436 cfs_waitlink_t * waitl;
437 } cfs_waitlink_channel_t;
439 struct cfs_waitlink {
446 cfs_waitlink_channel_t waitq[CFS_WAITQ_CHANNELS];
450 CFS_WAITQ_EXCLUSIVE = 1
453 #define CFS_DECL_WAITQ(name) cfs_waitq_t name
457 typedef int (*cfs_thread_t) (void *arg);
459 typedef struct _cfs_thread_context {
462 } cfs_thread_context_t;
464 int cfs_kernel_thread(int (*func)(void *), void *arg, int flag);
467 * thread creation flags from Linux, not used in winnt
469 #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
470 #define CLONE_VM 0x00000100 /* set if VM shared between processes */
471 #define CLONE_FS 0x00000200 /* set if fs info shared between processes */
472 #define CLONE_FILES 0x00000400 /* set if open files shared between processes */
473 #define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */
474 #define CLONE_PID 0x00001000 /* set if pid shared */
475 #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
476 #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
477 #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
478 #define CLONE_THREAD 0x00010000 /* Same thread group? */
479 #define CLONE_NEWNS 0x00020000 /* New namespace group? */
481 #define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
485 * group_info: linux/sched.h
487 #define NGROUPS_SMALL 32
488 #define NGROUPS_PER_BLOCK ((int)(PAGE_SIZE / sizeof(gid_t)))
489 typedef struct cfs_group_info {
492 gid_t small_block[NGROUPS_SMALL];
497 #define cfs_get_group_info(group_info) do { \
498 cfs_atomic_inc(&(group_info)->usage); \
501 #define cfs_put_group_info(group_info) do { \
502 if (cfs_atomic_dec_and_test(&(group_info)->usage)) \
503 cfs_groups_free(group_info); \
506 static __inline cfs_group_info_t *cfs_groups_alloc(int gidsetsize)
508 cfs_group_info_t * groupinfo;
509 KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__, __FUNCTION__));
511 (cfs_group_info_t *)cfs_alloc(sizeof(cfs_group_info_t), 0);
514 memset(groupinfo, 0, sizeof(cfs_group_info_t));
518 static __inline void cfs_groups_free(cfs_group_info_t *group_info)
520 KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__,
522 cfs_free(group_info);
525 cfs_set_current_groups(cfs_group_info_t *group_info)
527 KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__,
531 static __inline int groups_search(cfs_group_info_t *group_info,
533 KdPrint(("%s(%d): %s NOT implemented.\n", __FILE__, __LINE__,
539 * capability issue (linux/capability.h)
542 /* Override resource limits. Set resource limits. */
543 /* Override quota limits. */
544 /* Override reserved space on ext2 filesystem */
545 /* Modify data journaling mode on ext3 filesystem (uses journaling
547 /* NOTE: ext2 honors fsuid when checking for resource overrides, so
548 you can override using fsuid too */
549 /* Override size restrictions on IPC message queues */
550 /* Allow more than 64hz interrupts from the real-time clock */
551 /* Override max number of consoles on console allocation */
552 /* Override max number of keymaps */
554 #define CAP_SYS_RESOURCE 24
557 * capabilities support
560 typedef __u32 cfs_kernel_cap_t;
562 #define cap_raise(c, flag) do {} while(0)
563 #define cap_lower(c, flag) do {} while(0)
564 #define cap_raised(c, flag) do {} while(0)
571 #define CFS_MAX_SCHEDULE_TIMEOUT ((long_ptr_t)(~0UL>>12))
572 #define cfs_schedule_timeout(t) cfs_schedule_timeout_and_set_state(0, t)
577 #define CFS_CURPROC_COMM_MAX (16)
578 typedef struct task_sruct{
585 uid_t uid,euid,suid,fsuid;
586 gid_t gid,egid,sgid,fsgid;
590 gid_t groups[NGROUPS];
591 cfs_group_info_t *group_info;
592 cfs_kernel_cap_t cap_effective,
596 char comm[CFS_CURPROC_COMM_MAX];
601 static inline void task_lock(cfs_task_t *t)
605 static inline void task_unlock(cfs_task_t *t)
610 * linux task struct emulator ...
613 #define TASKMAN_MAGIC 'TMAN' /* Task Manager */
614 #define TASKSLT_MAGIC 'TSLT' /* Task Slot */
616 typedef struct _TASK_MAN {
618 ULONG Magic; /* Magic and Flags */
621 cfs_spinlock_t Lock; /* Protection lock */
623 cfs_mem_cache_t *slab; /* Memory slab for task slot */
625 ULONG NumOfTasks; /* Total tasks (threads) */
626 LIST_ENTRY TaskList; /* List of task slots */
628 } TASK_MAN, *PTASK_MAN;
630 typedef struct _TASK_SLOT {
632 ULONG Magic; /* Magic and Flags */
635 LIST_ENTRY Link; /* To be linked to TaskMan */
637 event_t Event; /* Schedule event */
639 HANDLE Pid; /* Process id */
640 HANDLE Tid; /* Thread id */
641 PETHREAD Tet; /* Pointer to ethread */
643 cfs_atomic_t count; /* refer count */
644 cfs_atomic_t hits; /* times of waken event singaled */
646 KIRQL irql; /* irql for rwlock ... */
648 cfs_task_t task; /* linux task part */
650 } TASK_SLOT, *PTASK_SLOT;
653 #define current cfs_current()
654 #define cfs_set_current_state(s) do {;} while (0)
655 #define cfs_set_current_state(state) cfs_set_current_state(state)
657 #define cfs_wait_event(wq, condition) \
659 cfs_waitlink_t __wait; \
661 cfs_waitlink_init(&__wait); \
663 cfs_waitq_add(&wq, &__wait); \
667 cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE); \
668 cfs_waitq_del(&wq, &__wait); \
670 cfs_waitq_del(&wq, &__wait); \
673 #define cfs_wait_event_interruptible(wq, condition, __ret) \
675 cfs_waitlink_t __wait; \
678 cfs_waitlink_init(&__wait); \
680 cfs_waitq_add(&wq, &__wait); \
684 cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE); \
685 cfs_waitq_del(&wq, &__wait); \
687 cfs_waitq_del(&wq, &__wait); \
690 # define cfs_wait_event_interruptible_exclusive(wq, condition, rc) \
691 cfs_wait_event_interruptible(wq, condition, rc)
694 retval == 0; condition met; we're good.
695 retval < 0; interrupted by signal.
696 retval > 0; timed out.
699 #define cfs_waitq_wait_event_interruptible_timeout( \
700 wq, condition, timeout, rc) \
702 cfs_waitlink_t __wait; \
705 cfs_waitlink_init(&__wait); \
707 cfs_waitq_add(&wq, &__wait); \
711 if (cfs_waitq_timedwait(&__wait, \
712 CFS_TASK_INTERRUPTIBLE, timeout) == 0) { \
716 cfs_waitq_del(&wq, &__wait); \
718 cfs_waitq_del(&wq, &__wait); \
722 #define cfs_waitq_wait_event_timeout \
723 cfs_waitq_wait_event_interruptible_timeout
725 int init_task_manager();
726 void cleanup_task_manager();
727 cfs_task_t * cfs_current();
728 int wake_up_process(cfs_task_t * task);
729 void sleep_on(cfs_waitq_t *waitq);
730 #define cfs_might_sleep() do {} while(0)
731 #define CFS_DECL_JOURNAL_DATA
732 #define CFS_PUSH_JOURNAL do {;} while(0)
733 #define CFS_POP_JOURNAL do {;} while(0)
736 /* module related definitions */
745 typedef struct cfs_module {
749 extern cfs_module_t libcfs_global_module;
750 #define THIS_MODULE &libcfs_global_module
752 #define cfs_request_module(x, y) (0)
753 #define EXPORT_SYMBOL(s)
754 #define MODULE_AUTHOR(s)
755 #define MODULE_DESCRIPTION(s)
756 #define MODULE_LICENSE(s)
757 #define MODULE_PARM(a, b)
758 #define MODULE_PARM_DESC(a, b)
760 #define module_init(X) int __init module_##X() {return X();}
761 #define module_exit(X) void __exit module_##X() {X();}
763 #define DECLARE_INIT(X) extern int __init module_##X(void)
764 #define DECLARE_EXIT(X) extern void __exit module_##X(void)
766 #define MODULE_INIT(X) do { int rc = module_##X(); \
767 if (rc) goto errorout; \
770 #define MODULE_EXIT(X) do { module_##X(); } while(0)
773 /* Module interfaces */
774 #define cfs_module(name, version, init, fini) \
777 #define cfs_module_refcount(x) (1)
783 #define typecheck(a, b) do {} while(0)
789 #define CRYPTO_MAX_ALG_NAME 64
791 #define CRYPTO_TFM_MODE_ECB 0x00000001
792 #define CRYPTO_TFM_MODE_CBC 0x00000002
793 #define CRYPTO_TFM_MODE_CFB 0x00000004
794 #define CRYPTO_TFM_MODE_CTR 0x00000008
795 #define CRYPTO_TFM_MODE_EME 0x00000010
800 /* 2^31 + 2^29 - 2^25 + 2^22 - 2^19 - 2^16 + 1 */
801 #define GOLDEN_RATIO_PRIME_32 0x9e370001UL
803 #if 0 /* defined in libcfs/libcfs_hash.h */
804 static inline u32 cfs_hash_long(u32 val, unsigned int bits)
806 /* On some cpus multiply is faster, on others gcc will do shifts */
807 u32 hash = val * GOLDEN_RATIO_PRIME_32;
809 /* High bits are more random, so use them. */
810 return hash >> (32 - bits);
818 #define CFS_TIMER_FLAG_INITED 0x00000001 // Initialized already
819 #define CFS_TIMER_FLAG_TIMERED 0x00000002 // KeSetTimer is called
821 typedef struct cfs_timer {
832 void (*proc)(ulong_ptr_t);
838 * libcfs globals initialization/cleanup
842 libcfs_arch_init(void);
845 libcfs_arch_cleanup(void);
848 * cache alignment size
851 #define CFS_L1_CACHE_ALIGN(x) (x)
853 #define __cacheline_aligned
860 #define SMP_CACHE_BYTES 128
861 #define CFS_NR_CPUS (32)
862 #define smp_num_cpus ((CCHAR)KeNumberProcessors)
863 #define cfs_num_possible_cpus() smp_num_cpus
864 #define cfs_num_online_cpus() smp_num_cpus
865 #define cfs_smp_processor_id() ((USHORT)KeGetCurrentProcessorNumber())
866 #define smp_call_function(f, a, n, w) do {} while(0)
867 #define smp_rmb() do {} while(0)
873 #define CFS_NR_IRQS 512
874 #define cfs_in_interrupt() (0)
880 #define CFS_KERN_EMERG "<0>" /* system is unusable */
881 #define CFS_KERN_ALERT "<1>" /* action must be taken immediately */
882 #define CFS_KERN_CRIT "<2>" /* critical conditions */
883 #define CFS_KERN_ERR "<3>" /* error conditions */
884 #define CFS_KERN_WARNING "<4>" /* warning conditions */
885 #define CFS_KERN_NOTICE "<5>" /* normal but significant condition */
886 #define CFS_KERN_INFO "<6>" /* informational */
887 #define CFS_KERN_DEBUG "<7>" /* debug-level messages */
893 #define inter_module_get(n) cfs_symbol_get(n)
894 #define inter_module_put(n) cfs_symbol_put(n)
897 #define likely(exp) (exp)
900 #define unlikely(exp) (exp)
903 #define cfs_lock_kernel() do {} while(0)
904 #define cfs_unlock_kernel() do {} while(0)
906 #define local_irq_save(x)
907 #define local_irq_restore(x)
911 #define va_copy(_d, _s) (_d = _s)
913 char *strnchr(const char *s, size_t count, int c);
915 #define adler32(a,b,l) zlib_adler32(a,b,l)
916 ULONG zlib_adler32(ULONG adler, const BYTE *buf, UINT len);
918 typedef ssize_t (*read_actor_t)();
922 * winnt debug routines
927 LONG DebugPrintLevel,
933 KsNtStatusToString (IN NTSTATUS Status);
936 #else /* !__KERNEL__ */
938 void cfs_enter_debugger();
945 #define PAGE_SIZE (4096)
948 #define getpagesize() (4096)
950 #define PAGE_CACHE_SIZE PAGE_SIZE
951 #define PAGE_CACHE_MASK PAGE_MASK
953 #define PTHREAD_MUTEX_INITIALIZER ((pthread_mutex_t) -1)
954 #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER ((pthread_mutex_t) -2)
955 #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER ((pthread_mutex_t) -3)
957 typedef struct file {
961 #include "../user-prim.h"
962 #include "../user-lock.h"
963 #include <sys/stat.h>
964 #include <sys/types.h>
966 #define strcasecmp strcmp
967 #define strncasecmp strncmp
971 #define getgrgid(x) (NULL)
977 struct passwd * getpwuid(uid_t uid);
979 int cfs_proc_mknod(const char *path, mode_t mode, dev_t dev);
981 int gethostname(char * name, int namelen);
983 #define setlinebuf(x) do {} while(0)
986 /* Maximum EA Information Length */
987 #define EA_MAX_LENGTH (sizeof(FILE_FULL_EA_INFORMATION) + 15)
990 * proc user mode routines
993 int cfs_proc_open (char * filename, int oflag);
994 int cfs_proc_close(int fd);
995 int cfs_proc_read(int fd, void *buffer, unsigned int count);
996 int cfs_proc_write(int fd, void *buffer, unsigned int count);
997 int cfs_proc_ioctl(int fd, int cmd, void *buffer);
998 FILE *cfs_proc_fopen(char *path, char * mode);
999 char *cfs_proc_fgets(char * buf, int len, FILE *fp);
1000 int cfs_proc_fclose(FILE *fp);
1002 /* Bits set in the FLAGS argument to `glob'. */
1003 #define GLOB_ERR (1 << 0)/* Return on read errors. */
1004 #define GLOB_MARK (1 << 1)/* Append a slash to each name. */
1005 #define GLOB_NOSORT (1 << 2)/* Don't sort the names. */
1006 #define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */
1007 #define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */
1008 #define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */
1009 #define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */
1010 #define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */
1012 #if !defined __USE_POSIX2 || defined __USE_BSD || defined __USE_GNU
1013 # define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */
1014 # define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */
1015 # define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */
1016 # define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */
1017 # define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */
1018 # define GLOB_ONLYDIR (1 << 13)/* Match only directories. */
1019 # define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error
1020 if the user name is not available. */
1021 # define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
1022 GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \
1023 GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \
1024 GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK)
1026 # define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \
1027 GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \
1031 /* Error returns from `glob'. */
1032 #define GLOB_NOSPACE 1 /* Ran out of memory. */
1033 #define GLOB_ABORTED 2 /* Read error. */
1034 #define GLOB_NOMATCH 3 /* No matches found. */
1035 #define GLOB_NOSYS 4 /* Not implemented. */
1037 /* Previous versions of this file defined GLOB_ABEND instead of
1038 GLOB_ABORTED. Provide a compatibility definition here. */
1039 # define GLOB_ABEND GLOB_ABORTED
1042 /* Structure describing a globbing run. */
1048 size_t gl_pathc; /* Count of paths matched by the pattern. */
1049 char **gl_pathv; /* List of matched pathnames. */
1050 size_t gl_offs; /* Slots to reserve in `gl_pathv'. */
1051 int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */
1053 /* If the GLOB_ALTDIRFUNC flag is set, the following functions
1054 are used instead of the normal file access functions. */
1055 void (*gl_closedir) (void *);
1057 struct dirent *(*gl_readdir) (void *);
1059 void *(*gl_readdir) (void *);
1061 void *(*gl_opendir) (const char *);
1063 int (*gl_lstat) (const char *__restrict, struct stat *__restrict);
1064 int (*gl_stat) (const char *__restrict, struct stat *__restrict);
1066 int (*gl_lstat) (const char *__restrict, void *__restrict);
1067 int (*gl_stat) (const char *__restrict, void *__restrict);
1071 #ifdef __USE_LARGEFILE64
1082 /* If the GLOB_ALTDIRFUNC flag is set, the following functions
1083 are used instead of the normal file access functions. */
1084 void (*gl_closedir) (void *);
1086 struct dirent64 *(*gl_readdir) (void *);
1088 void *(*gl_readdir) (void *);
1090 void *(*gl_opendir) (__const char *);
1092 int (*gl_lstat) (__const char *__restrict, struct stat64 *__restrict);
1093 int (*gl_stat) (__const char *__restrict, struct stat64 *__restrict);
1095 int (*gl_lstat) (__const char *__restrict, void *__restrict);
1096 int (*gl_stat) (__const char *__restrict, void *__restrict);
1101 int glob (const char * __pattern, int __flags,
1102 int (*__errfunc) (const char *, int),
1104 void globfree(glob_t *__pglog);
1106 #endif /* !__KERNEL__ */
1112 static inline void __cfs_module_get(cfs_module_t *module)
1116 static inline int cfs_try_module_get(cfs_module_t *module)
1121 static inline void cfs_module_put(cfs_module_t *module)
1129 typedef sigset_t cfs_sigset_t;
1130 #define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0)
1131 #define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0)
1132 #define sigemptyset(what) (*(what) = 0, 0)
1133 #define sigfillset(what) (*(what) = ~(0), 0)
1134 #define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0)
1137 sigprocmask(int sig, cfs_sigset_t *w1, cfs_sigset_t *w2) {
1141 sigpending(cfs_sigset_t *what) {
1146 * common inode flags (user & kernel)
1149 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
1150 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
1151 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
1152 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
1153 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
1154 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
1155 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
1157 #define S_IRWXU 00700
1158 #define S_IRUSR 00400
1159 #define S_IWUSR 00200
1160 #define S_IXUSR 00100
1162 #define S_IRWXG 00070
1163 #define S_IRGRP 00040
1164 #define S_IWGRP 00020
1165 #define S_IXGRP 00010
1167 #define S_IRWXO 00007
1168 #define S_IROTH 00004
1169 #define S_IWOTH 00002
1170 #define S_IXOTH 00001
1172 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
1173 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
1174 #define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH)
1175 #define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH)
1176 #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
1180 * Linux kernel version definition
1183 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
1186 * linux ioctl coding definitions
1189 #define _IOC_NRBITS 8
1190 #define _IOC_TYPEBITS 8
1191 #define _IOC_SIZEBITS 14
1192 #define _IOC_DIRBITS 2
1194 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
1195 #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
1196 #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
1197 #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
1199 #define _IOC_NRSHIFT 0
1200 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
1201 #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
1202 #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
1207 #define _IOC_NONE 0U
1208 #define _IOC_WRITE 1U
1209 #define _IOC_READ 2U
1211 #define _IOC(dir,type,nr,size) \
1212 (((dir) << _IOC_DIRSHIFT) | \
1213 ((type) << _IOC_TYPESHIFT) | \
1214 ((nr) << _IOC_NRSHIFT) | \
1215 ((size) << _IOC_SIZESHIFT))
1217 /* used to create numbers */
1218 #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
1219 #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
1220 #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
1221 #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
1223 /* used to decode ioctl numbers.. */
1224 #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
1225 #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
1226 #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
1227 #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
1229 /* i/o vector sgructure ... */
1235 /* idr support routines */
1236 struct idr_context *cfs_idr_init();
1237 int cfs_idr_remove(struct idr_context *idp, int id);
1238 int cfs_idr_get_new(struct idr_context *idp, void *ptr);
1239 int cfs_idr_get_new_above(struct idr_context *idp, void *ptr, int starting_id);
1240 void *cfs_idr_find(struct idr_context *idp, int id);
1241 void cfs_idr_exit(struct idr_context *idp);
1243 /* runtime time routines for both kenrel and user mode */
1244 extern int cfs_isalpha(int);
1245 extern int cfs_isspace(int);
1246 extern int cfs_isupper(int);
1247 extern int cfs_isdigit(int);
1248 extern int cfs_isxdigit(int);
1250 #define ULONG_LONG_MAX ((__u64)(0xFFFFFFFFFFFFFFFF))
1252 * Convert a string to an unsigned long long integer.
1254 * Ignores `locale' stuff. Assumes that the upper and lower case
1255 * alphabets and digits are each contiguous.
1257 __u64 strtoull(char *nptr, char **endptr,int base);
1263 /* For communication from `getopt' to the caller.
1264 When `getopt' finds an option that takes an argument,
1265 the argument value is returned here.
1266 Also, when `ordering' is RETURN_IN_ORDER,
1267 each non-option ARGV-element is returned here. */
1269 extern char *optarg;
1271 /* Index in ARGV of the next element to be scanned.
1272 This is used for communication to and from the caller
1273 and for communication between successive calls to `getopt'.
1275 On entry to `getopt', zero means this is the first call; initialize.
1277 When `getopt' returns -1, this is the index of the first of the
1278 non-option elements that the caller should itself scan.
1280 Otherwise, `optind' communicates from one call to the next
1281 how much of ARGV has been scanned so far. */
1285 /* Callers store zero here to inhibit the error message `getopt' prints
1286 for unrecognized options. */
1290 /* Set to an option character which was unrecognized. */
1298 /* has_arg can't be an enum because some compilers complain about
1299 type mismatches in all the code that assumes it is an int. */
1305 /* Names for the values of the `has_arg' field of `struct option'. */
1306 # define no_argument 0
1307 # define required_argument 1
1308 # define optional_argument 2
1310 extern int getopt(int ___argc, char *const *___argv, const char *__shortopts);
1311 extern int getopt_long (int ___argc, char *const *___argv,
1312 const char *__shortopts,
1313 const struct option *__longopts, int *__longind);
1314 extern int getopt_long_only (int ___argc, char *const *___argv,
1315 const char *__shortopts,
1316 const struct option *__longopts, int *__longind);
1318 extern char *strcasestr (const char *phaystack, const char *pneedle);
1321 * global environment runtime routine
1324 static __inline char * __cdecl cfs_getenv(const char *ENV) {return NULL;}
1325 static __inline void __cdecl set_getenv(const char *ENV, const char *value, int overwrite) {}
1327 int setenv(const char *envname, const char *envval, int overwrite);
1329 typedef struct utsname {
1337 int uname(struct utsname *uts);