fs.c (2264B)
1 /* $Id: //depot/blt/srv/vfs/fs.c#1 $ 2 ** 3 ** Copyright 1998 Sidney Cammeresi 4 ** All rights reserved. 5 ** 6 ** Redistribution and use in source and binary forms, with or without 7 ** modification, are permitted provided that the following conditions 8 ** are met: 9 ** 1. Redistributions of source code must retain the above copyright 10 ** notice, this list of conditions, and the following disclaimer. 11 ** 2. Redistributions in binary form must reproduce the above copyright 12 ** notice, this list of conditions, and the following disclaimer in the 13 ** documentation and/or other materials provided with the distribution. 14 ** 3. The name of the author may not be used to endorse or promote products 15 ** derived from this software without specific prior written permission. 16 ** 17 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <string.h> 30 #include "vfs-int.h" 31 32 int fs_register (struct fs_type *driver) 33 { 34 struct fs_type *p; 35 36 if (fs_drivers == NULL) 37 { 38 fs_drivers = driver; 39 fs_drivers->next = NULL; 40 return 0; 41 } 42 else 43 { 44 p = fs_drivers; 45 while (p->next != NULL) 46 { 47 if (!strcmp (p->name, driver->name)) 48 return 1; 49 p = p->next; 50 } 51 p->next = driver; 52 driver->next = NULL; 53 return 0; 54 } 55 } 56 57 struct superblock *fs_find (const char *node) 58 { 59 int len, bestlen; 60 struct superblock *super, *best; 61 62 super = mount_list; 63 len = bestlen = 0; 64 best = NULL; 65 while (super != NULL) 66 { 67 if (!strncmp (super->sb_dir, node, len = strlen (super->sb_dir))) 68 if (len > bestlen) 69 { 70 best = super; 71 bestlen = len; 72 } 73 super = super->sb_next; 74 } 75 return best; 76 } 77