Annotation of Gnu-Mach/linux/dev/glue/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: 
                     60: #define MACH_INCLUDE
                     61: #include <linux/types.h>
                     62: #include <linux/config.h>
                     63: #include <linux/errno.h>
                     64: #include <linux/mm.h>
                     65: #include <linux/fs.h>
                     66: #include <linux/blk.h>
                     67: #include <linux/proc_fs.h>
                     68: #include <linux/kernel_stat.h>
                     69: 
                     70: extern boolean_t vm_map_lookup_entry (register vm_map_t, register vm_offset_t,
                     71:                                      vm_map_entry_t *);
                     72: extern int printf (const char *, ...);
                     73: 
                     74: int (*dispatch_scsi_info_ptr) (int ino, char *buffer, char **start,
                     75:                               off_t offset, int length, int inout) = 0;
                     76: 
                     77: struct kernel_stat kstat;
                     78: 
                     79: int
                     80: linux_to_mach_error (int err)
                     81: {
                     82:   switch (err)
                     83:     {
                     84:     case 0:
                     85:       return D_SUCCESS;
                     86: 
                     87:     case -LINUX_EPERM:
                     88:       return D_INVALID_OPERATION;
                     89: 
                     90:     case -LINUX_EIO:
                     91:       return D_IO_ERROR;
                     92: 
                     93:     case -LINUX_ENXIO:
                     94:       return D_NO_SUCH_DEVICE;
                     95: 
                     96:     case -LINUX_EACCES:
                     97:       return D_INVALID_OPERATION;
                     98: 
                     99:     case -LINUX_EFAULT:
                    100:       return D_INVALID_SIZE;
                    101: 
                    102:     case -LINUX_EBUSY:
                    103:       return D_ALREADY_OPEN;
                    104: 
                    105:     case -LINUX_EINVAL:
                    106:       return D_INVALID_SIZE;
                    107: 
                    108:     case -LINUX_EROFS:
                    109:       return D_READ_ONLY;
                    110: 
                    111:     case -LINUX_EWOULDBLOCK:
                    112:       return D_WOULD_BLOCK;
                    113: 
                    114:     case -LINUX_ENOMEM:
                    115:       return D_NO_MEMORY;
                    116: 
                    117:     default:
                    118:       printf ("linux_to_mach_error: unknown code %d\n", err);
                    119:       return D_IO_ERROR;
                    120:     }
                    121: }
                    122: 
                    123: int
                    124: issig ()
                    125: {
                    126:   return current_thread ()->wait_result != THREAD_AWAKENED;
                    127: }
                    128: 
                    129: int
                    130: block_fsync (struct inode *inode, struct file *filp)
                    131: {
                    132:   return 0;
                    133: }
                    134: 
                    135: int
                    136: verify_area (int rw, const void *p, unsigned long size)
                    137: {
                    138:   vm_prot_t prot = (rw == VERIFY_WRITE) ? VM_PROT_WRITE : VM_PROT_READ;
                    139:   vm_offset_t addr = trunc_page ((vm_offset_t) p);
                    140:   vm_size_t len = round_page ((vm_size_t) size);
                    141:   vm_map_entry_t entry;
                    142: 
                    143:   vm_map_lock_read (current_map ());
                    144: 
                    145:   while (1)
                    146:     {
                    147:       if (!vm_map_lookup_entry (current_map (), addr, &entry)
                    148:          || (entry->protection & prot) != prot)
                    149:        {
                    150:          vm_map_unlock_read (current_map ());
                    151:          return -LINUX_EFAULT;
                    152:        }
                    153:       if (entry->vme_end - entry->vme_start >= len)
                    154:        break;
                    155:       len -= entry->vme_end - entry->vme_start;
                    156:       addr += entry->vme_end - entry->vme_start;
                    157:     }
                    158: 
                    159:   vm_map_unlock_read (current_map ());
                    160:   return 0;
                    161: }
                    162: 
                    163: /*
                    164:  * Print device name (in decimal, hexadecimal or symbolic) -
                    165:  * at present hexadecimal only.
                    166:  * Note: returns pointer to static data!
                    167:  */
                    168: char *
                    169: kdevname (kdev_t dev)
                    170: {
                    171:   static char buffer[32];
                    172:   linux_sprintf (buffer, "%02x:%02x", MAJOR (dev), MINOR (dev));
                    173:   return buffer;
                    174: }
                    175: 
                    176: /* RO fail safe mechanism */
                    177: 
                    178: static long ro_bits[MAX_BLKDEV][8];
                    179: 
                    180: int
                    181: is_read_only (kdev_t dev)
                    182: {
                    183:   int minor, major;
                    184: 
                    185:   major = MAJOR (dev);
                    186:   minor = MINOR (dev);
                    187:   if (major < 0 || major >= MAX_BLKDEV)
                    188:     return 0;
                    189:   return ro_bits[major][minor >> 5] & (1 << (minor & 31));
                    190: }
                    191: 
                    192: void
                    193: set_device_ro (kdev_t dev, int flag)
                    194: {
                    195:   int minor, major;
                    196: 
                    197:   major = MAJOR (dev);
                    198:   minor = MINOR (dev);
                    199:   if (major < 0 || major >= MAX_BLKDEV)
                    200:     return;
                    201:   if (flag)
                    202:     ro_bits[major][minor >> 5] |= 1 << (minor & 31);
                    203:   else
                    204:     ro_bits[major][minor >> 5] &= ~(1 << (minor & 31));
                    205: }
                    206: 
                    207: /*
                    208:  *  linux/lib/string.c
                    209:  *
                    210:  *  Copyright (C) 1991, 1992  Linus Torvalds
                    211:  */
                    212: 
                    213: /*
                    214:  * stupid library routines.. The optimized versions should generally be found
                    215:  * as inline code in <asm-xx/string.h>
                    216:  *
                    217:  * These are buggy as well..
                    218:  */
                    219: 
                    220: #include <linux/types.h>
                    221: #include <linux/string.h>
                    222: 
                    223: char *___strtok = NULL;
                    224: 
                    225: #ifndef __HAVE_ARCH_STRSPN
                    226: size_t 
                    227: strspn (const char *s, const char *accept)
                    228: {
                    229:   const char *p;
                    230:   const char *a;
                    231:   size_t count = 0;
                    232: 
                    233:   for (p = s; *p != '\0'; ++p)
                    234:     {
                    235:       for (a = accept; *a != '\0'; ++a)
                    236:        {
                    237:          if (*p == *a)
                    238:            break;
                    239:        }
                    240:       if (*a == '\0')
                    241:        return count;
                    242:       ++count;
                    243:     }
                    244: 
                    245:   return count;
                    246: }
                    247: #endif
                    248: 
                    249: #ifndef __HAVE_ARCH_STRPBRK
                    250: char *
                    251: strpbrk (const char *cs, const char *ct)
                    252: {
                    253:   const char *sc1, *sc2;
                    254: 
                    255:   for (sc1 = cs; *sc1 != '\0'; ++sc1)
                    256:     {
                    257:       for (sc2 = ct; *sc2 != '\0'; ++sc2)
                    258:        {
                    259:          if (*sc1 == *sc2)
                    260:            return (char *) sc1;
                    261:        }
                    262:     }
                    263:   return NULL;
                    264: }
                    265: #endif
                    266: 
                    267: #ifndef __HAVE_ARCH_STRTOK
                    268: char *
                    269: strtok (char *s, const char *ct)
                    270: {
                    271:   char *sbegin, *send;
                    272: 
                    273:   sbegin = s ? s : ___strtok;
                    274:   if (!sbegin)
                    275:     {
                    276:       return NULL;
                    277:     }
                    278:   sbegin += strspn (sbegin, ct);
                    279:   if (*sbegin == '\0')
                    280:     {
                    281:       ___strtok = NULL;
                    282:       return (NULL);
                    283:     }
                    284:   send = strpbrk (sbegin, ct);
                    285:   if (send && *send != '\0')
                    286:     *send++ = '\0';
                    287:   ___strtok = send;
                    288:   return (sbegin);
                    289: }
                    290: #endif
                    291: 
                    292: 
                    293: #ifndef __HAVE_ARCH_STRSTR
                    294: char *
                    295: strstr (const char *s1, const char *s2)
                    296: {
                    297:   int l1, l2;
                    298:   
                    299:   l2 = strlen (s2);
                    300:   if (! l2)
                    301:     return (char *) s1;
                    302:   l1 = strlen (s1);
                    303:   while (l1 >= l2)
                    304:     {
                    305:       l1--;
                    306:       if (! memcmp (s1,s2,l2))
                    307:        return (char *) s1;
                    308:       s1++;
                    309:     }
                    310:   return NULL;
                    311: }
                    312: #endif
                    313: 
                    314: struct proc_dir_entry proc_scsi;
                    315: struct inode_operations proc_scsi_inode_operations;
                    316: struct proc_dir_entry proc_net;
                    317: struct inode_operations proc_net_inode_operations;
                    318: 
                    319: int
                    320: proc_register (struct proc_dir_entry *xxx1, struct proc_dir_entry *xxx2)
                    321: {
                    322:   return 0;
                    323: }
                    324: 
                    325: int
                    326: proc_unregister (struct proc_dir_entry *xxx1, int xxx2)
                    327: {
                    328:   return 0;
                    329: }
                    330: 
                    331: void
                    332: add_blkdev_randomness (int major)
                    333: {
                    334: }
                    335: 
                    336: void
                    337: do_gettimeofday (struct timeval *tv)
                    338: {
                    339:   host_get_time (1, tv);
                    340: }
                    341: 
                    342: int
                    343: dev_get_info (char *buffer, char **start, off_t offset, int length, int dummy)
                    344: {
                    345:   return 0;
                    346: }

unix.superglobalmegacorp.com

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