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
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
322 #define CFS_TASK_RUNNING 0x00000003
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_del(struct cfs_waitq *waitq, struct cfs_waitlink *link);
378 int cfs_waitq_active(struct cfs_waitq *waitq);
380 void cfs_waitq_signal(struct cfs_waitq *waitq);
381 void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr);
382 void cfs_waitq_broadcast(struct cfs_waitq *waitq);
384 void cfs_waitq_wait(struct cfs_waitlink *link, cfs_task_state_t state);
385 cfs_duration_t cfs_waitq_timedwait(struct cfs_waitlink *link,
386 cfs_task_state_t state, cfs_duration_t timeout);
392 typedef int (*cfs_thread_t) (void *arg);
394 typedef struct _cfs_thread_context {
397 } cfs_thread_context_t;
399 int cfs_kernel_thread(int (*func)(void *), void *arg, int flag);
402 * thread creation flags from Linux, not used in winnt
404 #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */
405 #define CLONE_VM 0x00000100 /* set if VM shared between processes */
406 #define CLONE_FS 0x00000200 /* set if fs info shared between processes */
407 #define CLONE_FILES 0x00000400 /* set if open files shared between processes */
408 #define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */
409 #define CLONE_PID 0x00001000 /* set if pid shared */
410 #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */
411 #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */
412 #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */
413 #define CLONE_THREAD 0x00010000 /* Same thread group? */
414 #define CLONE_NEWNS 0x00020000 /* New namespace group? */
416 #define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD)
423 typedef sigset_t cfs_sigset_t;
429 #define MAX_SCHEDULE_TIMEOUT ((long_ptr)(~0UL>>12))
433 #define CFS_CURPROC_COMM_MAX (16)
434 typedef struct task_sruct{
440 uid_t uid,euid,suid,fsuid;
441 gid_t gid,egid,sgid,fsgid;
444 gid_t groups[NGROUPS];
445 cfs_kernel_cap_t cap_effective,
449 char comm[CFS_CURPROC_COMM_MAX];
455 * linux task struct emulator ...
458 #define TASKMAN_MAGIC 'TMAN' /* Task Manager */
459 #define TASKSLT_MAGIC 'TSLT' /* Task Slot */
461 typedef struct _TASK_MAN {
463 ULONG Magic; /* Magic and Flags */
466 spinlock_t Lock; /* Protection lock */
468 cfs_mem_cache_t * slab; /* Memory slab for task slot */
470 ULONG NumOfTasks; /* Total tasks (threads) */
471 LIST_ENTRY TaskList; /* List of task slots */
473 } TASK_MAN, *PTASK_MAN;
475 typedef struct _TASK_SLOT {
477 ULONG Magic; /* Magic and Flags */
480 LIST_ENTRY Link; /* To be linked to TaskMan */
482 event_t Event; /* Schedule event */
484 HANDLE Pid; /* Process id */
485 HANDLE Tid; /* Thread id */
486 PETHREAD Tet; /* Pointer to ethread */
488 atomic_t count; /* refer count */
489 atomic_t hits; /* times of waken event singaled */
491 KIRQL irql; /* irql for rwlock ... */
493 cfs_task_t task; /* linux task part */
495 } TASK_SLOT, *PTASK_SLOT;
498 #define current cfs_current()
499 #define set_current_state(s) do {;} while (0)
501 #define wait_event(wq, condition) \
503 cfs_waitlink_t __wait; \
505 cfs_waitlink_init(&__wait); \
507 cfs_waitq_add(&wq, &__wait); \
511 cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE); \
512 cfs_waitq_del(&wq, &__wait); \
514 cfs_waitq_del(&wq, &__wait); \
517 #define wait_event_interruptible(wq, condition, __ret) \
519 cfs_waitlink_t __wait; \
522 cfs_waitlink_init(&__wait); \
524 cfs_waitq_add(&wq, &__wait); \
528 cfs_waitq_wait(&__wait, CFS_TASK_INTERRUPTIBLE); \
529 cfs_waitq_del(&wq, &__wait); \
531 cfs_waitq_del(&wq, &__wait); \
535 int init_task_manager();
536 void cleanup_task_manager();
537 cfs_task_t * cfs_current();
538 int schedule_timeout(int64_t time);
540 int wake_up_process(cfs_task_t * task);
541 #define cfs_schedule_timeout(state, time) schedule_timeout(time)
542 void sleep_on(cfs_waitq_t *waitq);
544 #define CFS_DECL_JOURNAL_DATA
545 #define CFS_PUSH_JOURNAL do {;} while(0)
546 #define CFS_POP_JOURNAL do {;} while(0)
549 /* module related definitions */
558 #define request_module(x) (0)
560 #define EXPORT_SYMBOL(s)
561 #define MODULE_AUTHOR(s)
562 #define MODULE_DESCRIPTION(s)
563 #define MODULE_LICENSE(s)
564 #define MODULE_PARM(a, b)
565 #define MODULE_PARM_DESC(a, b)
567 #define module_init(X) int __init module_##X() {return X();}
568 #define module_exit(X) void __exit module_##X() {X();}
570 #define DECLARE_INIT(X) extern int __init module_##X(void)
571 #define DECLARE_EXIT(X) extern void __exit module_##X(void)
573 #define MODULE_INIT(X) do { int rc = module_##X(); \
574 if (rc) goto errorout; \
577 #define MODULE_EXIT(X) do { module_##X(); } while(0)
580 /* Module interfaces */
581 #define cfs_module(name, version, init, fini) \
587 * Linux kernel version definition
590 #define KERNEL_VERSION(a,b,c) ((a)*100+(b)*10+c)
591 #define LINUX_VERSION_CODE (2*100+6*10+7)
597 #define SIGNAL_MASK_ASSERT()
603 #define CFS_TIMER_FLAG_INITED 0x00000001 // Initialized already
604 #define CFS_TIMER_FLAG_TIMERED 0x00000002 // KeSetTimer is called
606 typedef struct cfs_timer {
617 void (*proc)(ulong_ptr);
623 typedef void (*timer_func_t)(ulong_ptr);
625 #define cfs_init_timer(t)
627 void cfs_timer_init(cfs_timer_t *timer, void (*func)(ulong_ptr), void *arg);
628 void cfs_timer_done(cfs_timer_t *t);
629 void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline);
630 void cfs_timer_disarm(cfs_timer_t *t);
631 int cfs_timer_is_armed(cfs_timer_t *t);
632 cfs_time_t cfs_timer_deadline(cfs_timer_t *t);
635 /* deschedule for a bit... */
636 static inline void cfs_pause(cfs_duration_t ticks)
638 cfs_schedule_timeout(TASK_UNINTERRUPTIBLE, ticks);
642 static inline void cfs_enter_debugger(void)
652 * libcfs globals initialization/cleanup
656 libcfs_arch_init(void);
659 libcfs_arch_cleanup(void);
665 #define SMP_CACHE_BYTES 128
666 #define __cacheline_aligned
668 #define smp_processor_id() KeGetCurrentProcessorNumber()
669 #define smp_num_cpus NR_CPUS
670 #define num_online_cpus() smp_num_cpus
671 #define smp_call_function(f, a, n, w) do {} while(0)
678 #define in_interrupt() (0)
684 #define KERN_EMERG "<0>" /* system is unusable */
685 #define KERN_ALERT "<1>" /* action must be taken immediately */
686 #define KERN_CRIT "<2>" /* critical conditions */
687 #define KERN_ERR "<3>" /* error conditions */
688 #define KERN_WARNING "<4>" /* warning conditions */
689 #define KERN_NOTICE "<5>" /* normal but significant condition */
690 #define KERN_INFO "<6>" /* informational */
691 #define KERN_DEBUG "<7>" /* debug-level messages */
698 #define inter_module_get(n) cfs_symbol_get(n)
699 #define inter_module_put(n) cfs_symbol_put(n)
702 #define likely(exp) (exp)
705 #define unlikely(exp) (exp)
708 #define lock_kernel() do {} while(0)
709 #define unlock_kernel() do {} while(0)
711 #define CAP_SYS_ADMIN 0
712 #define CAP_SYS_ROOT 1
714 #define capable(a) (TRUE)
716 #define USERMODEHELPER(path, argv, envp) (0)
719 #define local_irq_save(x)
720 #define local_irq_restore(x)
722 #define cfs_assert ASSERT
726 #else /* !__KERNEL__ */
728 #define PAGE_CACHE_SIZE PAGE_SIZE
729 #define PAGE_CACHE_MASK PAGE_MASK
731 #define getpagesize() (PAGE_SIZE)
742 #define pthread_mutex_init(x, y) do {} while(0)
743 #define pthread_cond_init(x, y) do {} while(0)
745 #define pthread_mutex_lock(x) do {} while(0)
746 #define pthread_mutex_unlock(x) do {} while(0)
748 #define pthread_cond_wait(x,y) do {} while(0)
749 #define pthread_cond_broadcast(x) do {} while(0)
751 typedef struct file {
755 typedef struct cfs_proc_dir_entry{
757 }cfs_proc_dir_entry_t;
761 #include "../user-prim.h"
763 #include <sys/stat.h>
764 #include <sys/types.h>
766 #define strcasecmp strcmp
767 #define strncasecmp strncmp
768 #define snprintf _snprintf
772 #define getpwuid(x) (NULL)
773 #define getgrgid(x) (NULL)
775 int cfs_proc_mknod(const char *path, mode_t mode, dev_t dev);
777 int gethostname(char * name, int namelen);
779 #define setlinebuf(x) do {} while(0)
782 NTSYSAPI VOID NTAPI DebugBreak();
785 static inline void cfs_enter_debugger(void)
794 /* Maximum EA Information Length */
795 #define EA_MAX_LENGTH (sizeof(FILE_FULL_EA_INFORMATION) + 15)
799 * proc user mode routines
802 HANDLE cfs_proc_open (char * filename, int oflag);
803 int cfs_proc_close(HANDLE handle);
804 int cfs_proc_read(HANDLE handle, void *buffer, unsigned int count);
805 int cfs_proc_write(HANDLE handle, void *buffer, unsigned int count);
806 int cfs_proc_ioctl(HANDLE handle, int cmd, void *buffer);
810 * Native API definitions
820 NtReadFile(HANDLE FileHandle,
821 HANDLE Event OPTIONAL,
822 PIO_APC_ROUTINE ApcRoutine OPTIONAL,
823 PVOID ApcContext OPTIONAL,
824 PIO_STATUS_BLOCK IoStatusBlock,
827 PLARGE_INTEGER ByteOffset OPTIONAL,
828 PULONG Key OPTIONAL);
833 NtWriteFile(HANDLE FileHandle,
834 HANDLE Event OPTIONAL,
835 PIO_APC_ROUTINE ApcRoutine OPTIONAL,
836 PVOID ApcContext OPTIONAL,
837 PIO_STATUS_BLOCK IoStatusBlock,
840 PLARGE_INTEGER ByteOffset OPTIONAL,
841 PULONG Key OPTIONAL);
846 NtClose(HANDLE Handle);
851 NtCreateFile(PHANDLE FileHandle,
852 ACCESS_MASK DesiredAccess,
853 POBJECT_ATTRIBUTES ObjectAttributes,
854 PIO_STATUS_BLOCK IoStatusBlock,
855 PLARGE_INTEGER AllocationSize OPTIONAL,
856 ULONG FileAttributes,
858 ULONG CreateDisposition,
860 PVOID EaBuffer OPTIONAL,
867 NtDeviceIoControlFile(
868 IN HANDLE FileHandle,
870 IN PIO_APC_ROUTINE ApcRoutine,
872 OUT PIO_STATUS_BLOCK IoStatusBlock,
873 IN ULONG IoControlCode,
874 IN PVOID InputBuffer,
875 IN ULONG InputBufferLength,
876 OUT PVOID OutputBuffer,
877 OUT ULONG OutputBufferLength
884 IN HANDLE FileHandle,
885 IN HANDLE Event OPTIONAL,
886 IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,
887 IN PVOID ApcContext OPTIONAL,
888 OUT PIO_STATUS_BLOCK IoStatusBlock,
889 IN ULONG FsControlCode,
890 IN PVOID InputBuffer OPTIONAL,
891 IN ULONG InputBufferLength,
892 OUT PVOID OutputBuffer OPTIONAL,
893 IN ULONG OutputBufferLength
900 NtQueryInformationFile(
901 IN HANDLE FileHandle,
902 OUT PIO_STATUS_BLOCK IoStatusBlock,
903 OUT PVOID FileInformation,
905 IN FILE_INFORMATION_CLASS FileInformationClass
909 // Random routines ...
919 #endif /* __KERNEL__ */
923 // Inode flags (Linux uses octad number, but why ? strange!!!)
934 #define S_IFMT 0x0F000 /* 017 0000 */
935 #define S_IFSOCK 0x0C000 /* 014 0000 */
936 #define S_IFLNK 0x0A000 /* 012 0000 */
937 #define S_IFREG 0x08000 /* 010 0000 */
938 #define S_IFBLK 0x06000 /* 006 0000 */
939 #define S_IFDIR 0x04000 /* 004 0000 */
940 #define S_IFCHR 0x02000 /* 002 0000 */
941 #define S_IFIFO 0x01000 /* 001 0000 */
942 #define S_ISUID 0x00800 /* 000 4000 */
943 #define S_ISGID 0x00400 /* 000 2000 */
944 #define S_ISVTX 0x00200 /* 000 1000 */
946 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
947 #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
948 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
949 #define S_ISFIL(m) (((m) & S_IFMT) == S_IFFIL)
950 #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
951 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
952 #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
953 #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
955 #define S_IPERMISSION_MASK 0x1FF /* */
957 #define S_IRWXU 0x1C0 /* 0 0700 */
958 #define S_IRUSR 0x100 /* 0 0400 */
959 #define S_IWUSR 0x080 /* 0 0200 */
960 #define S_IXUSR 0x040 /* 0 0100 */
962 #define S_IRWXG 0x038 /* 0 0070 */
963 #define S_IRGRP 0x020 /* 0 0040 */
964 #define S_IWGRP 0x010 /* 0 0020 */
965 #define S_IXGRP 0x008 /* 0 0010 */
967 #define S_IRWXO 0x007 /* 0 0007 */
968 #define S_IROTH 0x004 /* 0 0004 */
969 #define S_IWOTH 0x002 /* 0 0002 */
970 #define S_IXOTH 0x001 /* 0 0001 */
972 #define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
973 #define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
974 #define S_IRUGO (S_IRUSR|S_IRGRP|S_IROTH)
975 #define S_IWUGO (S_IWUSR|S_IWGRP|S_IWOTH)
976 #define S_IXUGO (S_IXUSR|S_IXGRP|S_IXOTH)
979 * linux ioctl coding definitions
982 #define _IOC_NRBITS 8
983 #define _IOC_TYPEBITS 8
984 #define _IOC_SIZEBITS 14
985 #define _IOC_DIRBITS 2
987 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1)
988 #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1)
989 #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1)
990 #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1)
992 #define _IOC_NRSHIFT 0
993 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS)
994 #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS)
995 #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS)
1000 #define _IOC_NONE 0U
1001 #define _IOC_WRITE 1U
1002 #define _IOC_READ 2U
1004 #define _IOC(dir,type,nr,size) \
1005 (((dir) << _IOC_DIRSHIFT) | \
1006 ((type) << _IOC_TYPESHIFT) | \
1007 ((nr) << _IOC_NRSHIFT) | \
1008 ((size) << _IOC_SIZESHIFT))
1010 /* used to create numbers */
1011 #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0)
1012 #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size))
1013 #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size))
1014 #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size))
1016 /* used to decode ioctl numbers.. */
1017 #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK)
1018 #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK)
1019 #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK)
1020 #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK)
1033 #define ULONG_LONG_MAX ((__u64)(0xFFFFFFFFFFFFFFFF))
1035 * Convert a string to an unsigned long long integer.
1037 * Ignores `locale' stuff. Assumes that the upper and lower case
1038 * alphabets and digits are each contiguous.
1048 int c, neg = 0, any, cutlim;
1051 * See strtol for comments as to the logic used.
1055 } while (isspace(c));
1059 } else if (c == '+')
1061 if ((base == 0 || base == 16) &&
1062 c == '0' && (*s == 'x' || *s == 'X')) {
1068 base = c == '0' ? 8 : 10;
1069 cutoff = (__u64)ULONG_LONG_MAX / (__u64)base;
1070 cutlim = (int)((__u64)ULONG_LONG_MAX % (__u64)base);
1071 for (acc = 0, any = 0;; c = *s++) {
1074 else if (isalpha(c))
1075 c -= isupper(c) ? 'A' - 10 : 'a' - 10;
1080 if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
1089 acc = ULONG_LONG_MAX;
1093 *endptr = (char *) (any ? s - 1 : nptr);