Linux Headquarters
[ Register ]
[ About us ] [ Home Page ]

Advertisement
[ Kernel ] [ Documentation ] [ Links ] [ Books ]

Advertisement

Kernel v2.4.1 /fs/fat/cache.c

Filename:/fs/fat/cache.c
Lines Added:25
Lines Deleted:4
Also changed in: (Previous) 2.4.1-pre12  2.4.1-pre11  2.4.1-pre10  2.4.1-pre9  2.4.1-pre8  2.4.0-ac12 
(Following) 2.4.4-ac16  2.4.4-ac17  2.4.4-ac18  2.4.5-pre6  2.4.5  2.4.5-ac6 

Location
[  2.4.1
  [  fs
    [  fat
       o  cache.c

Patch

diff -u --recursive --new-file v2.4.0/linux/fs/fat/cache.c linux/fs/fat/cache.c
--- v2.4.0/linux/fs/fat/cache.c   Fri Dec 29 14:07:23 2000
+++ linux/fs/fat/cache.c   Mon Jan 15 18:58:04 2001
@@ -24,6 +24,7 @@
 #endif
 
 static struct fat_cache *fat_cache,cache[FAT_CACHE];
+static spinlock_t fat_cache_lock = SPIN_LOCK_UNLOCKED;
 
 /* Returns the this'th FAT entry, -1 if it is an end-of-file entry. If
    new_value is != -1, that FAT entry is replaced by it. */
@@ -133,13 +134,16 @@
    return next;
 }
 
-
 void fat_cache_init(void)
 {
    static int initialized = 0;
    int count;
 
-   if (initialized) return;
+   spin_lock(&fat_cache_lock);
+   if (initialized) {
+      spin_unlock(&fat_cache_lock);
+      return;
+      }
    fat_cache = &cache[0];
    for (count = 0; count < FAT_CACHE; count++) {
       cache[count].device = 0;
@@ -147,6 +151,7 @@
           &cache[count+1];
    }
    initialized = 1;
+   spin_unlock(&fat_cache_lock);
 }
 
 
@@ -157,6 +162,7 @@
 
    if (!first)
       return;
+   spin_lock(&fat_cache_lock);
    for (walk = fat_cache; walk; walk = walk->next)
       if (inode->i_dev == walk->device
           && walk->start_cluster == first
@@ -166,8 +172,12 @@
 #ifdef DEBUG
 printk("cache hit: %d (%d)\n",walk->file_cluster,*d_clu);
 #endif
-         if ((*f_clu = walk->file_cluster) == cluster) return;
+         if ((*f_clu = walk->file_cluster) == cluster) { 
+            spin_unlock(&fat_cache_lock);
+            return;
+         }
       }
+   spin_unlock(&fat_cache_lock);
 #ifdef DEBUG
 printk("cache miss\n");
 #endif
@@ -197,6 +207,7 @@
    int first = MSDOS_I(inode)->i_start;
 
    last = NULL;
+   spin_lock(&fat_cache_lock);
    for (walk = fat_cache; walk->next; walk = (last = walk)->next)
       if (inode->i_dev == walk->device
           && walk->start_cluster == first
@@ -204,17 +215,22 @@
          if (walk->disk_cluster != d_clu) {
             printk("FAT cache corruption inode=%ld\n",
                inode->i_ino);
+            spin_unlock(&fat_cache_lock);
             fat_cache_inval_inode(inode);
             return;
          }
          /* update LRU */
-         if (last == NULL) return;
+         if (last == NULL) {
+            spin_unlock(&fat_cache_lock);
+            return;
+         }
          last->next = walk->next;
          walk->next = fat_cache;
          fat_cache = walk;
 #ifdef DEBUG
 list_cache();
 #endif
+         spin_unlock(&fat_cache_lock);
          return;
       }
    walk->device = inode->i_dev;
@@ -224,6 +240,7 @@
    last->next = NULL;
    walk->next = fat_cache;
    fat_cache = walk;
+   spin_unlock(&fat_cache_lock);
 #ifdef DEBUG
 list_cache();
 #endif
@@ -238,10 +255,12 @@
    struct fat_cache *walk;
    int first = MSDOS_I(inode)->i_start;
 
+   spin_lock(&fat_cache_lock);
    for (walk = fat_cache; walk; walk = walk->next)
       if (walk->device == inode->i_dev
           && walk->start_cluster == first)
          walk->device = 0;
+   spin_unlock(&fat_cache_lock);
 }
 
 
@@ -249,9 +268,11 @@
 {
    struct fat_cache *walk;
 
+   spin_lock(&fat_cache_lock);
    for (walk = fat_cache; walk; walk = walk->next)
       if (walk->device == device)
          walk->device = 0;
+   spin_unlock(&fat_cache_lock);
 }
 
 


Comments: webmaster (at) linuxhq.com.
Advertising: banners (at) linuxhq.com.
Compilation ©1998-2008 Linux Headquarters, Inc.