1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=4:tabstop=4:
4 * Copyright (C) 2001 Cluster File Systems, Inc. <braam@clusterfs.com>
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * Basic library routines.
25 #ifndef __LIBCFS_WINNT_CFS_PRIM_H__
26 #define __LIBCFS_WINNT_CFS_PRIM_H__
28 #ifndef __LIBCFS_LIBCFS_H__
29 #error Do not #include this file directly. #include <libcfs/libcfs.h> instead
34 * libcfs proc device object
38 #define LUSTRE_PROC_DEVICE L"\\Device\\lproc" /* proc fs emulator device object */
39 #define LUSTRE_PROC_SYMLNK L"\\DosDevices\\lproc" /* proc fs user-visible device */
43 * Device IO Control Code Definitions
46 #define FILE_DEVICE_LIBCFS ('LC')
48 #define FILE_DEVICE_LIBCFS ('LC')
50 #define FUNC_LIBCFS_VERSION 0x101 // get version of current libcfs
51 #define FUNC_LIBCFS_IOCTL 0x102 // Device i/o control to proc fs
54 #define IOCTL_LIBCFS_VERSION \
55 CTL_CODE (FILE_DEVICE_LIBCFS, FUNC_LIBCFS_VERSION, METHOD_BUFFERED, FILE_ANY_ACCESS)
56 #define IOCTL_LIBCFS_ENTRY \
57 CTL_CODE(FILE_DEVICE_LIBCFS, FUNC_LIBCFS_IOCTL, METHOD_BUFFERED, FILE_ANY_ACCESS)
61 typedef struct _CFS_PROC_IOCTL {
63 ULONG cmd; // ioctl command identifier
64 ULONG len; // length of data
66 // UCHAR data[]; // content of the real ioctl
68 } CFS_PROC_IOCTL, *PCFS_PROC_IOCTL;
74 #include <libcfs/list.h>
77 * Symbol functions for libcfs
79 * OSX has no facility for use to register symbol.
80 * So we have to implement it.
82 #define CFS_SYMBOL_LEN 64
85 char name[CFS_SYMBOL_LEN];
88 struct list_head sym_list;
91 extern int cfs_symbol_register(const char *, const void *);
92 extern void cfs_symbol_unregister(const char *);
93 extern void * cfs_symbol_get(const char *);
94 extern void cfs_symbol_put(const char *);
95 extern void cfs_symbol_clean();
99 typedef struct file_operations cfs_file_operations_t;
100 typedef struct file cfs_file_t;
103 * Pseudo device register
110 cfs_file_operations_t * fops;
113 int cfs_psdev_register(cfs_psdev_t * psdev);
114 int cfs_psdev_deregister(cfs_psdev_t * psdev);
118 * Proc emulator file system APIs
121 typedef int cfs_read_proc_t(char *page, char **start, off_t off,
122 int count, int *eof, void *data);
123 typedef int cfs_write_proc_t(struct file *file, const char *buffer,
124 ulong_ptr count, void *data);
126 #define CFS_PROC_ENTRY_MAGIC 'CPEM'
128 #define CFS_PROC_FLAG_DIRECTORY 0x00000001 // directory node
129 #define CFS_PROC_FLAG_ATTACHED 0x00000002 // node is attached to proc
130 #define CFS_PROC_FLAG_MISCDEV 0x00000004 // miscellaneous device
132 typedef struct cfs_proc_entry
134 ULONG magic; // Magic
135 ULONG flags; // Flags
137 struct _dir_entry { // proc directory entry
138 PRTL_SPLAY_LINKS root;
141 struct _file_entry { // proc file / leaf entry
142 cfs_read_proc_t * read_proc;
143 cfs_write_proc_t * write_proc;
147 unsigned short nlink;
150 struct file_operations * proc_fops;
153 // proc_dir_entry ended.
155 RTL_SPLAY_LINKS s_link; // splay link
158 // Maximum length of proc entry name is 0x20
163 } cfs_proc_entry_t, cfs_proc_dir_entry_t;
165 typedef cfs_proc_entry_t cfs_proc_dir_entry_t;
167 #define PROC_BLOCK_SIZE PAGE_SIZE
173 typedef struct ctl_table cfs_sysctl_table_t;
174 typedef struct ctl_table_header cfs_sysctl_table_header_t;
177 typedef int ctl_handler (
178 cfs_sysctl_table_t *table,
180 void *oldval, size_t *oldlenp,
181 void *newval, size_t newlen,
184 typedef int proc_handler (
185 cfs_sysctl_table_t *ctl,
186 int write, struct file * filp,
187 void *buffer, size_t *lenp );
190 int proc_dointvec(cfs_sysctl_table_t *table, int write, struct file *filp,
191 void *buffer, size_t *lenp);
193 int proc_dostring(cfs_sysctl_table_t *table, int write, struct file *filp,
194 void *buffer, size_t *lenp);
196 int sysctl_string(cfs_sysctl_table_t *table, int *name, int nlen,
197 void *oldval, size_t *oldlenp,
198 void *newval, size_t newlen, void **context);
202 * System io control definitions
205 #define CTL_MAXNAME 10
207 #define CTL_ANY -1 /* Matches any name */
212 CTL_KERN=1, /* General kernel info and control */
213 CTL_VM=2, /* VM management */
214 CTL_NET=3, /* Networking */
215 CTL_PROC=4, /* Process info */
216 CTL_FS=5, /* Filesystems */
217 CTL_DEBUG=6, /* Debugging */
218 CTL_DEV=7, /* Devices */
219 CTL_BUS=8, /* Busses */
220 CTL_ABI=9, /* Binary emulation */
221 CTL_CPU=10 /* CPU stuff (speed scaling, etc) */
224 /* sysctl table definitons */
232 cfs_sysctl_table_t *child;
233 proc_handler *proc_handler; /* text formatting callback */
234 ctl_handler *strategy; /* read / write callback functions */
235 cfs_proc_entry_t *de; /* proc entry block */
241 /* the mantaner of the cfs_sysctl_table trees */
242 struct ctl_table_header
244 cfs_sysctl_table_t * ctl_table;
245 struct list_head ctl_entry;
249 cfs_proc_entry_t * create_proc_entry(char *name, mode_t mod,
250 cfs_proc_entry_t *parent);
251 void proc_free_entry(cfs_proc_entry_t *de);
252 void remove_proc_entry(char *name, cfs_proc_entry_t *entry);
253 cfs_proc_entry_t * search_proc_entry(char * name,
254 cfs_proc_entry_t * root );
256 #define cfs_create_proc_entry create_proc_entry
257 #define cfs_free_proc_entry proc_free_entry
258 #define cfs_remove_proc_entry remove_proc_entry
260 #define register_cfs_sysctl_table(t, a) register_sysctl_table(t, a)
261 #define unregister_cfs_sysctl_table(t) unregister_sysctl_table(t, a)
265 * declaration of proc kernel process routines
269 lustre_open_file(char * filename);
272 lustre_close_file(cfs_file_t * fh);
275 lustre_do_ioctl( cfs_file_t * fh,
280 lustre_ioctl_file( cfs_file_t * fh,
281 PCFS_PROC_IOCTL devctl);
284 lustre_read_file( cfs_file_t * fh,
291 lustre_write_file( cfs_file_t * fh,
302 typedef int cfs_task_state_t;
304 #define CFS_TASK_INTERRUPTIBLE 0x00000001
305 #define CFS_TASK_UNINT 0x00000002
309 #define CFS_WAITQ_MAGIC 'CWQM'
310 #define CFS_WAITLINK_MAGIC 'CWLM'
312 typedef struct cfs_waitq {
318 struct list_head waiters;
323 typedef struct cfs_waitlink cfs_waitlink_t;
325 #define CFS_WAITQ_CHANNELS (2)
327 #define CFS_WAITQ_CHAN_NORMAL (0)
328 #define CFS_WAITQ_CHAN_FORWARD (1)
332 typedef struct cfs_waitlink_channel {
333 struct list_head link;
335 cfs_waitlink_t * waitl;
336 } cfs_waitlink_channel_t;
338 struct cfs_waitlink {
345 cfs_waitlink_channel_t waitq[CFS_WAITQ_CHANNELS];
349 CFS_WAITQ_EXCLUSIVE = 1
352 #define CFS_DECL_WAITQ(name) cfs_waitq_t name
355 void cfs_waitq_init(struct cfs_waitq *waitq);
356 void cfs_waitlink_init(struct cfs_waitlink *link);
358 void cfs_waitq_add(struct cfs_waitq *waitq, struct cfs_waitlink *link);
359 void cfs_waitq_add_exclusive(struct cfs_waitq *waitq,
360 struct cfs_waitlink *link);
361 void cfs_waitq_forward(struct cfs_waitlink *link, struct cfs_waitq *waitq);
362 void cfs_waitq_del(struct cfs_waitq *waitq, struct cfs_waitlink *link);
363 int cfs_waitq_active(struct cfs_waitq *waitq);
365 void cfs_waitq_signal(struct cfs_waitq *waitq);
366 void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr);
367 void cfs_waitq_broadcast(struct cfs_waitq *waitq);
369 void cfs_waitq_wait(struct cfs_waitlink *link, cfs_task_state_t state);
370 cfs_duration_t cfs_waitq_timedwait(struct cfs_waitlink *link,
371 cfs_task_state_t state, cfs_duration_t timeout);
377 typedef int (*cfs_thread_t) (void *arg);
379 typedef struct _cfs_thread_context {
382 } cfs_thread_context_t;
384 int cfs_kernel_thread(int (*func)(void *), void *arg, int flag);
387 * thread creation flags from Linux, not used in winnt
389 #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
390 #define CLONE_VM 0x00000100 /* set if VM shared between processes */
391 #define CLONE_FS 0x00000200 /* set if fs info shared between processes */
392 #define CLONE_FILES 0x00000400 /* set if open files shared between processes */
393 #define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */
394 #define CLONE_PID 0x00001000 /* set if pid shared */
395 #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
396 #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
397 #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
398 #define CLONE_THREAD 0x00010000 /* Same thread group? */
399 #define CLONE_NEWNS 0x00020000 /* New namespace group? */
401 #define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
408 typedef sigset_t cfs_sigset_t;
414 #define MAX_SCHEDULE_TIMEOUT ((long_ptr)(~0UL>>12))
418 #define CFS_CURPROC_COMM_MAX (16)
419 typedef struct task_sruct{
425 uid_t uid,euid,suid,fsuid;
426 gid_t gid,egid,sgid,fsgid;
429 gid_t groups[NGROUPS];
430 cfs_kernel_cap_t cap_effective,
434 char comm[CFS_CURPROC_COMM_MAX];
440 * linux task struct emulator ...
443 #define TASKMAN_MAGIC 'TMAN' /* Task Manager */
444 #define TASKSLT_MAGIC 'TSLT' /* Task Slot */
446 typedef struct _TASK_MAN {
448 ULONG Magic; /* Magic and Flags */
451 spinlock_t Lock; /* Protection lock */
453 cfs_mem_cache_t * slab; /* Memory slab for task slot */
455 ULONG NumOfTasks; /* Total tasks (threads) */
456 LIST_ENTRY TaskList; /* List of task slots */
458 } TASK_MAN, *PTASK_MAN;
460 typedef struct _TASK_SLOT {
462 ULONG Magic; /* Magic and Flags */
465 LIST_ENTRY Link; /* To be linked to TaskMan */
467 event_t Event; /* Schedule event */
469 HANDLE Pid; /* Process id */
470 HANDLE Tid; /* Thread id */
471 PETHREAD Tet; /* Pointer to ethread */
473 atomic_t count; /* refer count */
474 atomic_t hits; /* times of waken event singaled */
476 KIRQL irql; /* irql for rwlock ... */
478 cfs_task_t task; /* linux task part */
480 } TASK_SLOT, *PTASK_SLOT;
483 #define current cfs_current()
484 #define set_current_state(s) do {;} while (0)
486 #define wait_event(wq, condition) \
488 cfs_waitlink_t __wait; \
490 cfs_waitlink_init(&__wait); \
492 cfs_waitq_add(&wq, &__wait); \
496 cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE); \
497 cfs_waitq_del(&wq, &__wait); \
499 cfs_waitq_del(&wq, &__wait); \
502 #define wait_event_interruptible(wq, condition, __ret) \
504 cfs_waitlink_t __wait; \
507 cfs_waitlink_init(&__wait); \
509 cfs_waitq_add(&wq, &__wait); \
513 cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE); \
514 cfs_waitq_del(&wq, &__wait); \
516 cfs_waitq_del(&wq, &__wait); \
520 int init_task_manager();
521 void cleanup_task_manager();
522 cfs_task_t * cfs_current();
523 int schedule_timeout(int64_t time);
525 int wake_up_process(cfs_task_t * task);
526 #define cfs_schedule_timeout(state, time) schedule_timeout(time)
527 void sleep_on(cfs_waitq_t *waitq);
529 #define CFS_DECL_JOURNAL_DATA
530 #define CFS_PUSH_JOURNAL do {;} while(0)
531 #define CFS_POP_JOURNAL do {;} while(0)
534 /* module related definitions */
543 #define request_module(x) (0)
545 #define EXPORT_SYMBOL(s)
546 #define MODULE_AUTHOR(s)
547 #define MODULE_DESCRIPTION(s)
548 #define MODULE_LICENSE(s)
549 #define MODULE_PARM(a, b)
550 #define MODULE_PARM_DESC(a, b)
552 #define module_init(X) int __init module_##X() {return X();}
553 #define module_exit(X) void __exit module_##X() {X();}
555 #define DECLARE_INIT(X) extern int __init module_##X(void)
556 #define DECLARE_EXIT(X) extern void __exit module_##X(void)
558 #define MODULE_INIT(X) do { int rc = module_##X(); \
559 if (rc) goto errorout; \
562 #define MODULE_EXIT(X) do { module_##X(); } while(0)
565 /* Module interfaces */
566 #define cfs_module(name, version, init, fini) \
572 * Linux kernel version definition
575 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
576 #define LINUX_VERSION_CODE (2*100+6*10+7)
582 #define SIGNAL_MASK_ASSERT()
588 #define CFS_TIMER_FLAG_INITED 0x00000001 // Initialized already
589 #define CFS_TIMER_FLAG_TIMERED 0x00000002 // KeSetTimer is called
591 typedef struct cfs_timer {
602 void (*proc)(ulong_ptr);
608 typedef void (*timer_func_t)(ulong_ptr);
610 #define cfs_init_timer(t)
612 void cfs_timer_init(cfs_timer_t *timer, void (*func)(ulong_ptr), void *arg);
613 void cfs_timer_done(cfs_timer_t *t);
614 void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline);
615 void cfs_timer_disarm(cfs_timer_t *t);
616 int cfs_timer_is_armed(cfs_timer_t *t);
617 cfs_time_t cfs_timer_deadline(cfs_timer_t *t);
620 /* deschedule for a bit... */
621 static inline void cfs_pause(cfs_duration_t ticks)
623 cfs_schedule_timeout(TASK_UNINTERRUPTIBLE, ticks);
627 static inline void cfs_enter_debugger(void)
637 * libcfs globals initialization/cleanup
641 libcfs_arch_init(void);
644 libcfs_arch_cleanup(void);
650 #define SMP_CACHE_BYTES 128
651 #define __cacheline_aligned
653 #define smp_processor_id() KeGetCurrentProcessorNumber()
654 #define smp_num_cpus NR_CPUS
655 #define num_online_cpus() smp_num_cpus
656 #define smp_call_function(f, a, n, w) do {} while(0)
663 #define in_interrupt() (0)
669 #define KERN_EMERG "<0>" /* system is unusable */
670 #define KERN_ALERT "<1>" /* action must be taken immediately */
671 #define KERN_CRIT "<2>" /* critical conditions */
672 #define KERN_ERR "<3>" /* error conditions */
673 #define KERN_WARNING "<4>" /* warning conditions */
674 #define KERN_NOTICE "<5>" /* normal but significant condition */
675 #define KERN_INFO "<6>" /* informational */
676 #define KERN_DEBUG "<7>" /* debug-level messages */
683 #define inter_module_get(n) cfs_symbol_get(n)
684 #define inter_module_put(n) cfs_symbol_put(n)
687 #define likely(exp) (exp)
690 #define unlikely(exp) (exp)
693 #define lock_kernel() do {} while(0)
694 #define unlock_kernel() do {} while(0)
696 #define CAP_SYS_ADMIN 0
697 #define CAP_SYS_ROOT 1
699 #define capable(a) (TRUE)
701 #define USERMODEHELPER(path, argv, envp) (0)
704 #define local_irq_save(x)
705 #define local_irq_restore(x)
707 #define cfs_assert ASSERT
711 #else /* !__KERNEL__ */
713 #define PAGE_CACHE_SIZE PAGE_SIZE
714 #define PAGE_CACHE_MASK PAGE_MASK
716 #define getpagesize() (PAGE_SIZE)
727 #define pthread_mutex_init(x, y) do {} while(0)
728 #define pthread_cond_init(x, y) do {} while(0)
730 #define pthread_mutex_lock(x) do {} while(0)
731 #define pthread_mutex_unlock(x) do {} while(0)
733 #define pthread_cond_wait(x,y) do {} while(0)
734 #define pthread_cond_broadcast(x) do {} while(0)
736 typedef struct file {
740 typedef struct cfs_proc_dir_entry{
742 }cfs_proc_dir_entry_t;
746 #include "../user-prim.h"
748 #include <sys/stat.h>
749 #include <sys/types.h>
751 #define strcasecmp strcmp
752 #define strncasecmp strncmp
753 #define snprintf _snprintf
757 #define getpwuid(x) (NULL)
758 #define getgrgid(x) (NULL)
760 int cfs_proc_mknod(const char *path, mode_t mode, dev_t dev);
762 int gethostname(char * name, int namelen);
764 #define setlinebuf(x) do {} while(0)
767 NTSYSAPI VOID NTAPI DebugBreak();
770 static inline void cfs_enter_debugger(void)
779 /* Maximum EA Information Length */
780 #define EA_MAX_LENGTH (sizeof(FILE_FULL_EA_INFORMATION) + 15)
784 * proc user mode routines
787 HANDLE cfs_proc_open (char * filename, int oflag);
788 int cfs_proc_close(HANDLE handle);
789 int cfs_proc_read(HANDLE handle, void *buffer, unsigned int count);
790 int cfs_proc_write(HANDLE handle, void *buffer, unsigned int count);
791 int cfs_proc_ioctl(HANDLE handle, int cmd, void *buffer);
795 * Native API definitions
805 NtReadFile(HANDLE FileHandle,
806 HANDLE Event OPTIONAL,
807 PIO_APC_ROUTINE ApcRoutine OPTIONAL,
808 PVOID ApcContext OPTIONAL,
809 PIO_STATUS_BLOCK IoStatusBlock,
812 PLARGE_INTEGER ByteOffset OPTIONAL,
813 PULONG Key OPTIONAL);
818 NtWriteFile(HANDLE FileHandle,
819 HANDLE Event OPTIONAL,
820 PIO_APC_ROUTINE ApcRoutine OPTIONAL,
821 PVOID ApcContext OPTIONAL,
822 PIO_STATUS_BLOCK IoStatusBlock,
825 PLARGE_INTEGER ByteOffset OPTIONAL,
826 PULONG Key OPTIONAL);
831 NtClose(HANDLE Handle);
836 NtCreateFile(PHANDLE FileHandle,
837 ACCESS_MASK DesiredAccess,
838 POBJECT_ATTRIBUTES ObjectAttributes,
839 PIO_STATUS_BLOCK IoStatusBlock,
840 PLARGE_INTEGER AllocationSize OPTIONAL,
841 ULONG FileAttributes,
843 ULONG CreateDisposition,
845 PVOID EaBuffer OPTIONAL,
852 NtDeviceIoControlFile(
853 IN HANDLE FileHandle,
855 IN PIO_APC_ROUTINE ApcRoutine,
857 OUT PIO_STATUS_BLOCK IoStatusBlock,
858 IN ULONG IoControlCode,
859 IN PVOID InputBuffer,
860 IN ULONG InputBufferLength,
861 OUT PVOID OutputBuffer,
862 OUT ULONG OutputBufferLength
869 IN HANDLE FileHandle,
870 IN HANDLE Event OPTIONAL,
871 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
872 IN PVOID ApcContext OPTIONAL,
873 OUT PIO_STATUS_BLOCK IoStatusBlock,
874 IN ULONG FsControlCode,
875 IN PVOID InputBuffer OPTIONAL,
876 IN ULONG InputBufferLength,
877 OUT PVOID OutputBuffer OPTIONAL,
878 IN ULONG OutputBufferLength
885 NtQueryInformationFile(
886 IN HANDLE FileHandle,
887 OUT PIO_STATUS_BLOCK IoStatusBlock,
888 OUT PVOID FileInformation,
890 IN FILE_INFORMATION_CLASS FileInformationClass
894 // Random routines ...
904 #endif /* __KERNEL__ */
908 // Inode flags (Linux uses octad number, but why ? strange!!!)
919 #define S_IFMT 0x0F000 /* 017 0000 */
920 #define S_IFSOCK 0x0C000 /* 014 0000 */
921 #define S_IFLNK 0x0A000 /* 012 0000 */
922 #define S_IFREG 0x08000 /* 010 0000 */
923 #define S_IFBLK 0x06000 /* 006 0000 */
924 #define S_IFDIR 0x04000 /* 004 0000 */
925 #define S_IFCHR 0x02000 /* 002 0000 */
926 #define S_IFIFO 0x01000 /* 001 0000 */
927 #define S_ISUID 0x00800 /* 000 4000 */
928 #define S_ISGID 0x00400 /* 000 2000 */
929 #define S_ISVTX 0x00200 /* 000 1000 */
931 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
932 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
933 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
934 #define S_ISFIL(m) (((m) & S_IFMT) == S_IFFIL)
935 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
936 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
937 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
938 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
940 #define S_IPERMISSION_MASK 0x1FF /* */
942 #define S_IRWXU 0x1C0 /* 0 0700 */
943 #define S_IRUSR 0x100 /* 0 0400 */
944 #define S_IWUSR 0x080 /* 0 0200 */
945 #define S_IXUSR 0x040 /* 0 0100 */
947 #define S_IRWXG 0x038 /* 0 0070 */
948 #define S_IRGRP 0x020 /* 0 0040 */
949 #define S_IWGRP 0x010 /* 0 0020 */
950 #define S_IXGRP 0x008 /* 0 0010 */
952 #define S_IRWXO 0x007 /* 0 0007 */
953 #define S_IROTH 0x004 /* 0 0004 */
954 #define S_IWOTH 0x002 /* 0 0002 */
955 #define S_IXOTH 0x001 /* 0 0001 */
957 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
958 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
959 #define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH)
960 #define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH)
961 #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
964 * linux ioctl coding definitions
967 #define _IOC_NRBITS 8
968 #define _IOC_TYPEBITS 8
969 #define _IOC_SIZEBITS 14
970 #define _IOC_DIRBITS 2
972 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
973 #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
974 #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
975 #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
977 #define _IOC_NRSHIFT 0
978 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
979 #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
980 #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
986 #define _IOC_WRITE 1U
989 #define _IOC(dir,type,nr,size) \
990 (((dir) << _IOC_DIRSHIFT) | \
991 ((type) << _IOC_TYPESHIFT) | \
992 ((nr) << _IOC_NRSHIFT) | \
993 ((size) << _IOC_SIZESHIFT))
995 /* used to create numbers */
996 #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
997 #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
998 #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
999 #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
1001 /* used to decode ioctl numbers.. */
1002 #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
1003 #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
1004 #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
1005 #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
1018 #define ULONG_LONG_MAX ((__u64)(0xFFFFFFFFFFFFFFFF))
1020 * Convert a string to an unsigned long long integer.
1022 * Ignores `locale' stuff. Assumes that the upper and lower case
1023 * alphabets and digits are each contiguous.
1033 int c, neg = 0, any, cutlim;
1036 * See strtol for comments as to the logic used.
1040 } while (isspace(c));
1044 } else if (c == '+')
1046 if ((base == 0 || base == 16) &&
1047 c == '0' && (*s == 'x' || *s == 'X')) {
1053 base = c == '0' ? 8 : 10;
1054 cutoff = (__u64)ULONG_LONG_MAX / (__u64)base;
1055 cutlim = (int)((__u64)ULONG_LONG_MAX % (__u64)base);
1056 for (acc = 0, any = 0;; c = *s++) {
1059 else if (isalpha(c))
1060 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
1065 if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
1074 acc = ULONG_LONG_MAX;
1078 *endptr = (char *) (any ? s - 1 : nptr);