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 [sun.com URL with a
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
50 * libcfs proc device object
54 #define LUSTRE_PROC_DEVICE L"\\Device\\lproc" /* proc fs emulator device object */
55 #define LUSTRE_PROC_SYMLNK L"\\DosDevices\\lproc" /* proc fs user-visible device */
59 * Device IO Control Code Definitions
62 #define FILE_DEVICE_LIBCFS ('LC')
64 #define FILE_DEVICE_LIBCFS ('LC')
66 #define FUNC_LIBCFS_VERSION 0x101 // get version of current libcfs
67 #define FUNC_LIBCFS_IOCTL 0x102 // Device i/o control to proc fs
70 #define IOCTL_LIBCFS_VERSION \
71 CTL_CODE (FILE_DEVICE_LIBCFS, FUNC_LIBCFS_VERSION, METHOD_BUFFERED, FILE_ANY_ACCESS)
72 #define IOCTL_LIBCFS_ENTRY \
73 CTL_CODE(FILE_DEVICE_LIBCFS, FUNC_LIBCFS_IOCTL, METHOD_BUFFERED, FILE_ANY_ACCESS)
77 typedef struct _CFS_PROC_IOCTL {
79 ULONG cmd; // ioctl command identifier
80 ULONG len; // length of data
82 // UCHAR data[]; // content of the real ioctl
84 } CFS_PROC_IOCTL, *PCFS_PROC_IOCTL;
90 #include <libcfs/list.h>
93 * Symbol functions for libcfs
95 * OSX has no facility for use to register symbol.
96 * So we have to implement it.
98 #define CFS_SYMBOL_LEN 64
101 char name[CFS_SYMBOL_LEN];
104 struct list_head sym_list;
107 extern int cfs_symbol_register(const char *, const void *);
108 extern void cfs_symbol_unregister(const char *);
109 extern void * cfs_symbol_get(const char *);
110 extern void cfs_symbol_put(const char *);
111 extern void cfs_symbol_clean();
115 typedef struct file_operations cfs_file_operations_t;
116 typedef struct file cfs_file_t;
119 * Pseudo device register
126 cfs_file_operations_t * fops;
129 int cfs_psdev_register(cfs_psdev_t * psdev);
130 int cfs_psdev_deregister(cfs_psdev_t * psdev);
134 * Proc emulator file system APIs
137 typedef int cfs_read_proc_t(char *page, char **start, off_t off,
138 int count, int *eof, void *data);
139 typedef int cfs_write_proc_t(struct file *file, const char *buffer,
140 ulong_ptr count, void *data);
142 #define CFS_PROC_ENTRY_MAGIC 'CPEM'
144 #define CFS_PROC_FLAG_DIRECTORY 0x00000001 // directory node
145 #define CFS_PROC_FLAG_ATTACHED 0x00000002 // node is attached to proc
146 #define CFS_PROC_FLAG_MISCDEV 0x00000004 // miscellaneous device
148 typedef struct cfs_proc_entry
150 ULONG magic; // Magic
151 ULONG flags; // Flags
153 struct _dir_entry { // proc directory entry
154 PRTL_SPLAY_LINKS root;
157 struct _file_entry { // proc file / leaf entry
158 cfs_read_proc_t * read_proc;
159 cfs_write_proc_t * write_proc;
163 unsigned short nlink;
166 struct file_operations * proc_fops;
169 // proc_dir_entry ended.
171 RTL_SPLAY_LINKS s_link; // splay link
174 // Maximum length of proc entry name is 0x20
179 } cfs_proc_entry_t, cfs_proc_dir_entry_t;
181 typedef cfs_proc_entry_t cfs_proc_dir_entry_t;
183 #define PROC_BLOCK_SIZE PAGE_SIZE
189 typedef struct ctl_table cfs_sysctl_table_t;
190 typedef struct ctl_table_header cfs_sysctl_table_header_t;
193 typedef int ctl_handler (
194 cfs_sysctl_table_t *table,
196 void *oldval, size_t *oldlenp,
197 void *newval, size_t newlen,
200 typedef int proc_handler (
201 cfs_sysctl_table_t *ctl,
202 int write, struct file * filp,
203 void *buffer, size_t *lenp );
206 int proc_dointvec(cfs_sysctl_table_t *table, int write, struct file *filp,
207 void *buffer, size_t *lenp);
209 int proc_dostring(cfs_sysctl_table_t *table, int write, struct file *filp,
210 void *buffer, size_t *lenp);
212 int sysctl_string(cfs_sysctl_table_t *table, int *name, int nlen,
213 void *oldval, size_t *oldlenp,
214 void *newval, size_t newlen, void **context);
218 * System io control definitions
221 #define CTL_MAXNAME 10
223 #define CTL_ANY -1 /* Matches any name */
228 CTL_KERN=1, /* General kernel info and control */
229 CTL_VM=2, /* VM management */
230 CTL_NET=3, /* Networking */
231 CTL_PROC=4, /* Process info */
232 CTL_FS=5, /* Filesystems */
233 CTL_DEBUG=6, /* Debugging */
234 CTL_DEV=7, /* Devices */
235 CTL_BUS=8, /* Busses */
236 CTL_ABI=9, /* Binary emulation */
237 CTL_CPU=10 /* CPU stuff (speed scaling, etc) */
240 /* sysctl table definitons */
248 cfs_sysctl_table_t *child;
249 proc_handler *proc_handler; /* text formatting callback */
250 ctl_handler *strategy; /* read / write callback functions */
251 cfs_proc_entry_t *de; /* proc entry block */
257 /* the mantaner of the cfs_sysctl_table trees */
258 struct ctl_table_header
260 cfs_sysctl_table_t * ctl_table;
261 struct list_head ctl_entry;
265 cfs_proc_entry_t * create_proc_entry(char *name, mode_t mod,
266 cfs_proc_entry_t *parent);
267 void proc_free_entry(cfs_proc_entry_t *de);
268 void remove_proc_entry(char *name, cfs_proc_entry_t *entry);
269 cfs_proc_entry_t * search_proc_entry(char * name,
270 cfs_proc_entry_t * root );
272 #define cfs_create_proc_entry create_proc_entry
273 #define cfs_free_proc_entry proc_free_entry
274 #define cfs_remove_proc_entry remove_proc_entry
276 #define register_cfs_sysctl_table(t, a) register_sysctl_table(t, a)
277 #define unregister_cfs_sysctl_table(t) unregister_sysctl_table(t, a)
281 * declaration of proc kernel process routines
285 lustre_open_file(char * filename);
288 lustre_close_file(cfs_file_t * fh);
291 lustre_do_ioctl( cfs_file_t * fh,
296 lustre_ioctl_file( cfs_file_t * fh,
297 PCFS_PROC_IOCTL devctl);
300 lustre_read_file( cfs_file_t * fh,
307 lustre_write_file( cfs_file_t * fh,
318 typedef int cfs_task_state_t;
320 #define CFS_TASK_INTERRUPTIBLE 0x00000001
321 #define CFS_TASK_UNINT 0x00000002
325 #define CFS_WAITQ_MAGIC 'CWQM'
326 #define CFS_WAITLINK_MAGIC 'CWLM'
328 typedef struct cfs_waitq {
334 struct list_head waiters;
339 typedef struct cfs_waitlink cfs_waitlink_t;
341 #define CFS_WAITQ_CHANNELS (2)
343 #define CFS_WAITQ_CHAN_NORMAL (0)
344 #define CFS_WAITQ_CHAN_FORWARD (1)
348 typedef struct cfs_waitlink_channel {
349 struct list_head link;
351 cfs_waitlink_t * waitl;
352 } cfs_waitlink_channel_t;
354 struct cfs_waitlink {
361 cfs_waitlink_channel_t waitq[CFS_WAITQ_CHANNELS];
365 CFS_WAITQ_EXCLUSIVE = 1
368 #define CFS_DECL_WAITQ(name) cfs_waitq_t name
371 void cfs_waitq_init(struct cfs_waitq *waitq);
372 void cfs_waitlink_init(struct cfs_waitlink *link);
374 void cfs_waitq_add(struct cfs_waitq *waitq, struct cfs_waitlink *link);
375 void cfs_waitq_add_exclusive(struct cfs_waitq *waitq,
376 struct cfs_waitlink *link);
377 void cfs_waitq_forward(struct cfs_waitlink *link, struct cfs_waitq *waitq);
378 void cfs_waitq_del(struct cfs_waitq *waitq, struct cfs_waitlink *link);
379 int cfs_waitq_active(struct cfs_waitq *waitq);
381 void cfs_waitq_signal(struct cfs_waitq *waitq);
382 void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr);
383 void cfs_waitq_broadcast(struct cfs_waitq *waitq);
385 void cfs_waitq_wait(struct cfs_waitlink *link, cfs_task_state_t state);
386 cfs_duration_t cfs_waitq_timedwait(struct cfs_waitlink *link,
387 cfs_task_state_t state, cfs_duration_t timeout);
393 typedef int (*cfs_thread_t) (void *arg);
395 typedef struct _cfs_thread_context {
398 } cfs_thread_context_t;
400 int cfs_kernel_thread(int (*func)(void *), void *arg, int flag);
403 * thread creation flags from Linux, not used in winnt
405 #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
406 #define CLONE_VM 0x00000100 /* set if VM shared between processes */
407 #define CLONE_FS 0x00000200 /* set if fs info shared between processes */
408 #define CLONE_FILES 0x00000400 /* set if open files shared between processes */
409 #define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */
410 #define CLONE_PID 0x00001000 /* set if pid shared */
411 #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
412 #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
413 #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
414 #define CLONE_THREAD 0x00010000 /* Same thread group? */
415 #define CLONE_NEWNS 0x00020000 /* New namespace group? */
417 #define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
424 typedef sigset_t cfs_sigset_t;
430 #define MAX_SCHEDULE_TIMEOUT ((long_ptr)(~0UL>>12))
434 #define CFS_CURPROC_COMM_MAX (16)
435 typedef struct task_sruct{
441 uid_t uid,euid,suid,fsuid;
442 gid_t gid,egid,sgid,fsgid;
445 gid_t groups[NGROUPS];
446 cfs_kernel_cap_t cap_effective,
450 char comm[CFS_CURPROC_COMM_MAX];
456 * linux task struct emulator ...
459 #define TASKMAN_MAGIC 'TMAN' /* Task Manager */
460 #define TASKSLT_MAGIC 'TSLT' /* Task Slot */
462 typedef struct _TASK_MAN {
464 ULONG Magic; /* Magic and Flags */
467 spinlock_t Lock; /* Protection lock */
469 cfs_mem_cache_t * slab; /* Memory slab for task slot */
471 ULONG NumOfTasks; /* Total tasks (threads) */
472 LIST_ENTRY TaskList; /* List of task slots */
474 } TASK_MAN, *PTASK_MAN;
476 typedef struct _TASK_SLOT {
478 ULONG Magic; /* Magic and Flags */
481 LIST_ENTRY Link; /* To be linked to TaskMan */
483 event_t Event; /* Schedule event */
485 HANDLE Pid; /* Process id */
486 HANDLE Tid; /* Thread id */
487 PETHREAD Tet; /* Pointer to ethread */
489 atomic_t count; /* refer count */
490 atomic_t hits; /* times of waken event singaled */
492 KIRQL irql; /* irql for rwlock ... */
494 cfs_task_t task; /* linux task part */
496 } TASK_SLOT, *PTASK_SLOT;
499 #define current cfs_current()
500 #define set_current_state(s) do {;} while (0)
502 #define wait_event(wq, condition) \
504 cfs_waitlink_t __wait; \
506 cfs_waitlink_init(&__wait); \
508 cfs_waitq_add(&wq, &__wait); \
512 cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE); \
513 cfs_waitq_del(&wq, &__wait); \
515 cfs_waitq_del(&wq, &__wait); \
518 #define wait_event_interruptible(wq, condition, __ret) \
520 cfs_waitlink_t __wait; \
523 cfs_waitlink_init(&__wait); \
525 cfs_waitq_add(&wq, &__wait); \
529 cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE); \
530 cfs_waitq_del(&wq, &__wait); \
532 cfs_waitq_del(&wq, &__wait); \
536 int init_task_manager();
537 void cleanup_task_manager();
538 cfs_task_t * cfs_current();
539 int schedule_timeout(int64_t time);
541 int wake_up_process(cfs_task_t * task);
542 #define cfs_schedule_timeout(state, time) schedule_timeout(time)
543 void sleep_on(cfs_waitq_t *waitq);
545 #define CFS_DECL_JOURNAL_DATA
546 #define CFS_PUSH_JOURNAL do {;} while(0)
547 #define CFS_POP_JOURNAL do {;} while(0)
550 /* module related definitions */
559 #define request_module(x) (0)
561 #define EXPORT_SYMBOL(s)
562 #define MODULE_AUTHOR(s)
563 #define MODULE_DESCRIPTION(s)
564 #define MODULE_LICENSE(s)
565 #define MODULE_PARM(a, b)
566 #define MODULE_PARM_DESC(a, b)
568 #define module_init(X) int __init module_##X() {return X();}
569 #define module_exit(X) void __exit module_##X() {X();}
571 #define DECLARE_INIT(X) extern int __init module_##X(void)
572 #define DECLARE_EXIT(X) extern void __exit module_##X(void)
574 #define MODULE_INIT(X) do { int rc = module_##X(); \
575 if (rc) goto errorout; \
578 #define MODULE_EXIT(X) do { module_##X(); } while(0)
581 /* Module interfaces */
582 #define cfs_module(name, version, init, fini) \
588 * Linux kernel version definition
591 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
592 #define LINUX_VERSION_CODE (2*100+6*10+7)
598 #define SIGNAL_MASK_ASSERT()
604 #define CFS_TIMER_FLAG_INITED 0x00000001 // Initialized already
605 #define CFS_TIMER_FLAG_TIMERED 0x00000002 // KeSetTimer is called
607 typedef struct cfs_timer {
618 void (*proc)(ulong_ptr);
624 typedef void (*timer_func_t)(ulong_ptr);
626 #define cfs_init_timer(t)
628 void cfs_timer_init(cfs_timer_t *timer, void (*func)(ulong_ptr), void *arg);
629 void cfs_timer_done(cfs_timer_t *t);
630 void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline);
631 void cfs_timer_disarm(cfs_timer_t *t);
632 int cfs_timer_is_armed(cfs_timer_t *t);
633 cfs_time_t cfs_timer_deadline(cfs_timer_t *t);
636 /* deschedule for a bit... */
637 static inline void cfs_pause(cfs_duration_t ticks)
639 cfs_schedule_timeout(TASK_UNINTERRUPTIBLE, ticks);
643 static inline void cfs_enter_debugger(void)
653 * libcfs globals initialization/cleanup
657 libcfs_arch_init(void);
660 libcfs_arch_cleanup(void);
666 #define SMP_CACHE_BYTES 128
667 #define __cacheline_aligned
669 #define smp_processor_id() KeGetCurrentProcessorNumber()
670 #define smp_num_cpus NR_CPUS
671 #define num_online_cpus() smp_num_cpus
672 #define smp_call_function(f, a, n, w) do {} while(0)
679 #define in_interrupt() (0)
685 #define KERN_EMERG "<0>" /* system is unusable */
686 #define KERN_ALERT "<1>" /* action must be taken immediately */
687 #define KERN_CRIT "<2>" /* critical conditions */
688 #define KERN_ERR "<3>" /* error conditions */
689 #define KERN_WARNING "<4>" /* warning conditions */
690 #define KERN_NOTICE "<5>" /* normal but significant condition */
691 #define KERN_INFO "<6>" /* informational */
692 #define KERN_DEBUG "<7>" /* debug-level messages */
699 #define inter_module_get(n) cfs_symbol_get(n)
700 #define inter_module_put(n) cfs_symbol_put(n)
703 #define likely(exp) (exp)
706 #define unlikely(exp) (exp)
709 #define lock_kernel() do {} while(0)
710 #define unlock_kernel() do {} while(0)
712 #define CAP_SYS_ADMIN 0
713 #define CAP_SYS_ROOT 1
715 #define capable(a) (TRUE)
717 #define USERMODEHELPER(path, argv, envp) (0)
720 #define local_irq_save(x)
721 #define local_irq_restore(x)
723 #define cfs_assert ASSERT
727 #else /* !__KERNEL__ */
729 #define PAGE_CACHE_SIZE PAGE_SIZE
730 #define PAGE_CACHE_MASK PAGE_MASK
732 #define getpagesize() (PAGE_SIZE)
743 #define pthread_mutex_init(x, y) do {} while(0)
744 #define pthread_cond_init(x, y) do {} while(0)
746 #define pthread_mutex_lock(x) do {} while(0)
747 #define pthread_mutex_unlock(x) do {} while(0)
749 #define pthread_cond_wait(x,y) do {} while(0)
750 #define pthread_cond_broadcast(x) do {} while(0)
752 typedef struct file {
756 typedef struct cfs_proc_dir_entry{
758 }cfs_proc_dir_entry_t;
762 #include "../user-prim.h"
764 #include <sys/stat.h>
765 #include <sys/types.h>
767 #define strcasecmp strcmp
768 #define strncasecmp strncmp
769 #define snprintf _snprintf
773 #define getpwuid(x) (NULL)
774 #define getgrgid(x) (NULL)
776 int cfs_proc_mknod(const char *path, mode_t mode, dev_t dev);
778 int gethostname(char * name, int namelen);
780 #define setlinebuf(x) do {} while(0)
783 NTSYSAPI VOID NTAPI DebugBreak();
786 static inline void cfs_enter_debugger(void)
795 /* Maximum EA Information Length */
796 #define EA_MAX_LENGTH (sizeof(FILE_FULL_EA_INFORMATION) + 15)
800 * proc user mode routines
803 HANDLE cfs_proc_open (char * filename, int oflag);
804 int cfs_proc_close(HANDLE handle);
805 int cfs_proc_read(HANDLE handle, void *buffer, unsigned int count);
806 int cfs_proc_write(HANDLE handle, void *buffer, unsigned int count);
807 int cfs_proc_ioctl(HANDLE handle, int cmd, void *buffer);
811 * Native API definitions
821 NtReadFile(HANDLE FileHandle,
822 HANDLE Event OPTIONAL,
823 PIO_APC_ROUTINE ApcRoutine OPTIONAL,
824 PVOID ApcContext OPTIONAL,
825 PIO_STATUS_BLOCK IoStatusBlock,
828 PLARGE_INTEGER ByteOffset OPTIONAL,
829 PULONG Key OPTIONAL);
834 NtWriteFile(HANDLE FileHandle,
835 HANDLE Event OPTIONAL,
836 PIO_APC_ROUTINE ApcRoutine OPTIONAL,
837 PVOID ApcContext OPTIONAL,
838 PIO_STATUS_BLOCK IoStatusBlock,
841 PLARGE_INTEGER ByteOffset OPTIONAL,
842 PULONG Key OPTIONAL);
847 NtClose(HANDLE Handle);
852 NtCreateFile(PHANDLE FileHandle,
853 ACCESS_MASK DesiredAccess,
854 POBJECT_ATTRIBUTES ObjectAttributes,
855 PIO_STATUS_BLOCK IoStatusBlock,
856 PLARGE_INTEGER AllocationSize OPTIONAL,
857 ULONG FileAttributes,
859 ULONG CreateDisposition,
861 PVOID EaBuffer OPTIONAL,
868 NtDeviceIoControlFile(
869 IN HANDLE FileHandle,
871 IN PIO_APC_ROUTINE ApcRoutine,
873 OUT PIO_STATUS_BLOCK IoStatusBlock,
874 IN ULONG IoControlCode,
875 IN PVOID InputBuffer,
876 IN ULONG InputBufferLength,
877 OUT PVOID OutputBuffer,
878 OUT ULONG OutputBufferLength
885 IN HANDLE FileHandle,
886 IN HANDLE Event OPTIONAL,
887 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
888 IN PVOID ApcContext OPTIONAL,
889 OUT PIO_STATUS_BLOCK IoStatusBlock,
890 IN ULONG FsControlCode,
891 IN PVOID InputBuffer OPTIONAL,
892 IN ULONG InputBufferLength,
893 OUT PVOID OutputBuffer OPTIONAL,
894 IN ULONG OutputBufferLength
901 NtQueryInformationFile(
902 IN HANDLE FileHandle,
903 OUT PIO_STATUS_BLOCK IoStatusBlock,
904 OUT PVOID FileInformation,
906 IN FILE_INFORMATION_CLASS FileInformationClass
910 // Random routines ...
920 #endif /* __KERNEL__ */
924 // Inode flags (Linux uses octad number, but why ? strange!!!)
935 #define S_IFMT 0x0F000 /* 017 0000 */
936 #define S_IFSOCK 0x0C000 /* 014 0000 */
937 #define S_IFLNK 0x0A000 /* 012 0000 */
938 #define S_IFREG 0x08000 /* 010 0000 */
939 #define S_IFBLK 0x06000 /* 006 0000 */
940 #define S_IFDIR 0x04000 /* 004 0000 */
941 #define S_IFCHR 0x02000 /* 002 0000 */
942 #define S_IFIFO 0x01000 /* 001 0000 */
943 #define S_ISUID 0x00800 /* 000 4000 */
944 #define S_ISGID 0x00400 /* 000 2000 */
945 #define S_ISVTX 0x00200 /* 000 1000 */
947 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
948 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
949 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
950 #define S_ISFIL(m) (((m) & S_IFMT) == S_IFFIL)
951 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
952 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
953 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
954 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
956 #define S_IPERMISSION_MASK 0x1FF /* */
958 #define S_IRWXU 0x1C0 /* 0 0700 */
959 #define S_IRUSR 0x100 /* 0 0400 */
960 #define S_IWUSR 0x080 /* 0 0200 */
961 #define S_IXUSR 0x040 /* 0 0100 */
963 #define S_IRWXG 0x038 /* 0 0070 */
964 #define S_IRGRP 0x020 /* 0 0040 */
965 #define S_IWGRP 0x010 /* 0 0020 */
966 #define S_IXGRP 0x008 /* 0 0010 */
968 #define S_IRWXO 0x007 /* 0 0007 */
969 #define S_IROTH 0x004 /* 0 0004 */
970 #define S_IWOTH 0x002 /* 0 0002 */
971 #define S_IXOTH 0x001 /* 0 0001 */
973 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
974 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
975 #define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH)
976 #define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH)
977 #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
980 * linux ioctl coding definitions
983 #define _IOC_NRBITS 8
984 #define _IOC_TYPEBITS 8
985 #define _IOC_SIZEBITS 14
986 #define _IOC_DIRBITS 2
988 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
989 #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
990 #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
991 #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
993 #define _IOC_NRSHIFT 0
994 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
995 #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
996 #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
1001 #define _IOC_NONE 0U
1002 #define _IOC_WRITE 1U
1003 #define _IOC_READ 2U
1005 #define _IOC(dir,type,nr,size) \
1006 (((dir) << _IOC_DIRSHIFT) | \
1007 ((type) << _IOC_TYPESHIFT) | \
1008 ((nr) << _IOC_NRSHIFT) | \
1009 ((size) << _IOC_SIZESHIFT))
1011 /* used to create numbers */
1012 #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
1013 #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
1014 #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
1015 #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
1017 /* used to decode ioctl numbers.. */
1018 #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
1019 #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
1020 #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
1021 #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
1034 #define ULONG_LONG_MAX ((__u64)(0xFFFFFFFFFFFFFFFF))
1036 * Convert a string to an unsigned long long integer.
1038 * Ignores `locale' stuff. Assumes that the upper and lower case
1039 * alphabets and digits are each contiguous.
1049 int c, neg = 0, any, cutlim;
1052 * See strtol for comments as to the logic used.
1056 } while (isspace(c));
1060 } else if (c == '+')
1062 if ((base == 0 || base == 16) &&
1063 c == '0' && (*s == 'x' || *s == 'X')) {
1069 base = c == '0' ? 8 : 10;
1070 cutoff = (__u64)ULONG_LONG_MAX / (__u64)base;
1071 cutlim = (int)((__u64)ULONG_LONG_MAX % (__u64)base);
1072 for (acc = 0, any = 0;; c = *s++) {
1075 else if (isalpha(c))
1076 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
1081 if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
1090 acc = ULONG_LONG_MAX;
1094 *endptr = (char *) (any ? s - 1 : nptr);