Annotation of Gnu-Mach/i386/i386at/gpl/linux/linux_misc.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Miscellaneous routines and data for Linux emulation.
                      3:  *
                      4:  * Copyright (C) 1996 The University of Utah and the Computer Systems
                      5:  * Laboratory at the University of Utah (CSL)
                      6:  *
                      7:  * This program is free software; you can redistribute it and/or modify
                      8:  * it under the terms of the GNU General Public License as published by
                      9:  * the Free Software Foundation; either version 2, or (at your option)
                     10:  * any later version.
                     11:  *
                     12:  * This program 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.
                     16:  *
                     17:  * You should have received a copy of the GNU General Public License
                     18:  * along with this program; if not, write to the Free Software
                     19:  * Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
                     20:  *
                     21:  *      Author: Shantanu Goel, University of Utah CSL
                     22:  */
                     23: 
                     24: /*
                     25:  *  linux/fs/proc/scsi.c  
                     26:  *  (c) 1995 Michael Neuffer [email protected]
                     27:  *
                     28:  *  The original version was derived from linux/fs/proc/net.c,
                     29:  *  which is Copyright (C) 1991, 1992 Linus Torvalds. 
                     30:  *  Much has been rewritten, but some of the code still remains.
                     31:  *
                     32:  *  /proc/scsi directory handling functions
                     33:  *
                     34:  *  last change: 95/07/04    
                     35:  *
                     36:  *  Initial version: March '95
                     37:  *  95/05/15 Added subdirectories for each driver and show every
                     38:  *          registered HBA as a single file. 
                     39:  *  95/05/30 Added rudimentary write support for parameter passing
                     40:  *  95/07/04 Fixed bugs in directory handling
                     41:  *  95/09/13 Update to support the new proc-dir tree
                     42:  *
                     43:  *  TODO: Improve support to write to the driver files
                     44:  *       Add some more comments
                     45:  */
                     46: 
                     47: /*
                     48:  *  linux/fs/buffer.c
                     49:  *
                     50:  *  Copyright (C) 1991, 1992  Linus Torvalds
                     51:  */
                     52: 
                     53: #include <sys/types.h>
                     54: #include <mach/vm_param.h>
                     55: #include <kern/thread.h>
                     56: #include <vm/vm_map.h>
                     57: #include <vm/vm_page.h>
                     58: #include <device/device_types.h>
                     59: #include <i386at/gpl/linux/linux_emul.h>
                     60: 
                     61: #define MACH_INCLUDE
                     62: #include <linux/errno.h>
                     63: #include <linux/mm.h>
                     64: #include <linux/fs.h>
                     65: #include <linux/blk.h>
                     66: #include <linux/proc_fs.h>
                     67: #include <linux/kernel_stat.h>
                     68: 
                     69: int (*dispatch_scsi_info_ptr) (int ino, char *buffer, char **start,
                     70:                               off_t offset, int length, int inout) = 0;
                     71: 
                     72: struct kernel_stat kstat;
                     73: 
                     74: int
                     75: linux_to_mach_error (int err)
                     76: {
                     77:   switch (err)
                     78:     {
                     79:     case 0:
                     80:       return D_SUCCESS;
                     81: 
                     82:     case -LINUX_EPERM:
                     83:       return D_INVALID_OPERATION;
                     84: 
                     85:     case -LINUX_EIO:
                     86:       return D_IO_ERROR;
                     87: 
                     88:     case -LINUX_ENXIO:
                     89:       return D_NO_SUCH_DEVICE;
                     90: 
                     91:     case -LINUX_EACCES:
                     92:       return D_INVALID_OPERATION;
                     93: 
                     94:     case -LINUX_EFAULT:
                     95:       return D_INVALID_SIZE;
                     96: 
                     97:     case -LINUX_EBUSY:
                     98:       return D_ALREADY_OPEN;
                     99: 
                    100:     case -LINUX_EINVAL:
                    101:       return D_INVALID_SIZE;
                    102: 
                    103:     case -LINUX_EROFS:
                    104:       return D_READ_ONLY;
                    105: 
                    106:     case -LINUX_EWOULDBLOCK:
                    107:       return D_WOULD_BLOCK;
                    108: 
                    109:     default:
                    110:       printf ("linux_to_mach_error: unknown code %d\n", err);
                    111:       return D_IO_ERROR;
                    112:     }
                    113: }
                    114: 
                    115: int
                    116: issig ()
                    117: {
                    118:   return current_thread ()->wait_result != THREAD_AWAKENED;
                    119: }
                    120: 
                    121: int
                    122: block_fsync (struct inode *inode, struct file *filp)
                    123: {
                    124:   return 0;
                    125: }
                    126: 
                    127: int
                    128: verify_area (int rw, const void *p, unsigned long size)
                    129: {
                    130:   vm_prot_t prot = (rw == VERIFY_WRITE) ? VM_PROT_WRITE : VM_PROT_READ;
                    131:   vm_offset_t addr = trunc_page ((vm_offset_t) p);
                    132:   vm_size_t len = round_page ((vm_size_t) size);
                    133:   vm_map_entry_t entry;
                    134: 
                    135:   vm_map_lock_read (current_map ());
                    136: 
                    137:   while (1)
                    138:     {
                    139:       if (! vm_map_lookup_entry (current_map (), addr, &entry)
                    140:          || (entry->protection & prot) != prot)
                    141:        {
                    142:          vm_map_unlock_read (current_map ());
                    143:          return -LINUX_EFAULT;
                    144:        }
                    145:       if (entry->vme_end - entry->vme_start >= len)
                    146:        break;
                    147:       len -= entry->vme_end - entry->vme_start;
                    148:       addr += entry->vme_end - entry->vme_start;
                    149:     }
                    150: 
                    151:   vm_map_unlock_read (current_map ());
                    152:   return 0;
                    153: }
                    154: 
                    155: /*
                    156:  * Print device name (in decimal, hexadecimal or symbolic) -
                    157:  * at present hexadecimal only.
                    158:  * Note: returns pointer to static data!
                    159:  */
                    160: char *
                    161: kdevname(kdev_t dev)
                    162: {
                    163:        static char buffer[32];
                    164:        sprintf(buffer, "%02x:%02x", MAJOR(dev), MINOR(dev));
                    165:        return buffer;
                    166: }
                    167: 
                    168: /* RO fail safe mechanism */
                    169: 
                    170: static long ro_bits[MAX_BLKDEV][8];
                    171: 
                    172: int
                    173: is_read_only(kdev_t dev)
                    174: {
                    175:        int minor,major;
                    176: 
                    177:        major = MAJOR(dev);
                    178:        minor = MINOR(dev);
                    179:        if (major < 0 || major >= MAX_BLKDEV) return 0;
                    180:        return ro_bits[major][minor >> 5] & (1 << (minor & 31));
                    181: }
                    182: 
                    183: void
                    184: set_device_ro(kdev_t dev,int flag)
                    185: {
                    186:        int minor,major;
                    187: 
                    188:        major = MAJOR(dev);
                    189:        minor = MINOR(dev);
                    190:        if (major < 0 || major >= MAX_BLKDEV) return;
                    191:        if (flag) ro_bits[major][minor >> 5] |= 1 << (minor & 31);
                    192:        else ro_bits[major][minor >> 5] &= ~(1 << (minor & 31));
                    193: }
                    194: 
                    195: /*
                    196:  *  linux/lib/string.c
                    197:  *
                    198:  *  Copyright (C) 1991, 1992  Linus Torvalds
                    199:  */
                    200: 
                    201: /*
                    202:  * stupid library routines.. The optimized versions should generally be found
                    203:  * as inline code in <asm-xx/string.h>
                    204:  *
                    205:  * These are buggy as well..
                    206:  */
                    207:  
                    208: #include <linux/types.h>
                    209: #include <linux/string.h>
                    210: 
                    211: char * ___strtok = NULL;
                    212: 
                    213: #ifndef __HAVE_ARCH_STRSPN
                    214: size_t strspn(const char *s, const char *accept)
                    215: {
                    216:        const char *p;
                    217:        const char *a;
                    218:        size_t count = 0;
                    219: 
                    220:        for (p = s; *p != '\0'; ++p) {
                    221:                for (a = accept; *a != '\0'; ++a) {
                    222:                        if (*p == *a)
                    223:                                break;
                    224:                }
                    225:                if (*a == '\0')
                    226:                        return count;
                    227:                ++count;
                    228:        }
                    229: 
                    230:        return count;
                    231: }
                    232: #endif
                    233: 
                    234: #ifndef __HAVE_ARCH_STRPBRK
                    235: char * strpbrk(const char * cs,const char * ct)
                    236: {
                    237:        const char *sc1,*sc2;
                    238: 
                    239:        for( sc1 = cs; *sc1 != '\0'; ++sc1) {
                    240:                for( sc2 = ct; *sc2 != '\0'; ++sc2) {
                    241:                        if (*sc1 == *sc2)
                    242:                                return (char *) sc1;
                    243:                }
                    244:        }
                    245:        return NULL;
                    246: }
                    247: #endif
                    248: 
                    249: #ifndef __HAVE_ARCH_STRTOK
                    250: char * strtok(char * s,const char * ct)
                    251: {
                    252:        char *sbegin, *send;
                    253: 
                    254:        sbegin  = s ? s : ___strtok;
                    255:        if (!sbegin) {
                    256:                return NULL;
                    257:        }
                    258:        sbegin += strspn(sbegin,ct);
                    259:        if (*sbegin == '\0') {
                    260:                ___strtok = NULL;
                    261:                return( NULL );
                    262:        }
                    263:        send = strpbrk( sbegin, ct);
                    264:        if (send && *send != '\0')
                    265:                *send++ = '\0';
                    266:        ___strtok = send;
                    267:        return (sbegin);
                    268: }
                    269: #endif
                    270: 
                    271: struct proc_dir_entry proc_scsi;
                    272: struct inode_operations proc_scsi_inode_operations;
                    273: struct proc_dir_entry proc_net;
                    274: struct inode_operations proc_net_inode_operations;
                    275: 
                    276: int
                    277: proc_register (struct proc_dir_entry *xxx1, struct proc_dir_entry *xxx2)
                    278: {
                    279:   return 0;
                    280: }
                    281: 
                    282: int
                    283: proc_unregister (struct proc_dir_entry *xxx1, int xxx2)
                    284: {
                    285:   return 0;
                    286: }
                    287: 
                    288: void
                    289: add_blkdev_randomness (int major)
                    290: {
                    291: }
                    292: 
                    293: void
                    294: do_gettimeofday (struct timeval *tv)
                    295: {
                    296:   host_get_time (1, tv);
                    297: }
                    298: 
                    299: int
                    300: dev_get_info (char *buffer, char **start, off_t offset, int length, int dummy)
                    301: {
                    302:   return 0;
                    303: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.