~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/ufs/cylinder.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /fs/ufs/cylinder.c (Version linux-6.12-rc7) and /fs/ufs/cylinder.c (Version linux-5.15.171)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  *  linux/fs/ufs/cylinder.c                         3  *  linux/fs/ufs/cylinder.c
  4  *                                                  4  *
  5  * Copyright (C) 1998                               5  * Copyright (C) 1998
  6  * Daniel Pirkl <daniel.pirkl@email.cz>             6  * Daniel Pirkl <daniel.pirkl@email.cz>
  7  * Charles University, Faculty of Mathematics       7  * Charles University, Faculty of Mathematics and Physics
  8  *                                                  8  *
  9  *  ext2 - inode (block) bitmap caching inspir      9  *  ext2 - inode (block) bitmap caching inspired
 10  */                                                10  */
 11                                                    11 
 12 #include <linux/fs.h>                              12 #include <linux/fs.h>
 13 #include <linux/time.h>                            13 #include <linux/time.h>
 14 #include <linux/stat.h>                            14 #include <linux/stat.h>
 15 #include <linux/string.h>                          15 #include <linux/string.h>
 16 #include <linux/bitops.h>                          16 #include <linux/bitops.h>
 17                                                    17 
 18 #include <asm/byteorder.h>                         18 #include <asm/byteorder.h>
 19                                                    19 
 20 #include "ufs_fs.h"                                20 #include "ufs_fs.h"
 21 #include "ufs.h"                                   21 #include "ufs.h"
 22 #include "swab.h"                                  22 #include "swab.h"
 23 #include "util.h"                                  23 #include "util.h"
 24                                                    24 
 25 /*                                                 25 /*
 26  * Read cylinder group into cache. The memory      26  * Read cylinder group into cache. The memory space for ufs_cg_private_info
 27  * structure is already allocated during ufs_r     27  * structure is already allocated during ufs_read_super.
 28  */                                                28  */
 29 static void ufs_read_cylinder (struct super_bl     29 static void ufs_read_cylinder (struct super_block * sb,
 30         unsigned cgno, unsigned bitmap_nr)         30         unsigned cgno, unsigned bitmap_nr)
 31 {                                                  31 {
 32         struct ufs_sb_info * sbi = UFS_SB(sb);     32         struct ufs_sb_info * sbi = UFS_SB(sb);
 33         struct ufs_sb_private_info * uspi;         33         struct ufs_sb_private_info * uspi;
 34         struct ufs_cg_private_info * ucpi;         34         struct ufs_cg_private_info * ucpi;
 35         struct ufs_cylinder_group * ucg;           35         struct ufs_cylinder_group * ucg;
 36         unsigned i, j;                             36         unsigned i, j;
 37                                                    37 
 38         UFSD("ENTER, cgno %u, bitmap_nr %u\n",     38         UFSD("ENTER, cgno %u, bitmap_nr %u\n", cgno, bitmap_nr);
 39         uspi = sbi->s_uspi;                        39         uspi = sbi->s_uspi;
 40         ucpi = sbi->s_ucpi[bitmap_nr];             40         ucpi = sbi->s_ucpi[bitmap_nr];
 41         ucg = (struct ufs_cylinder_group *)sbi     41         ucg = (struct ufs_cylinder_group *)sbi->s_ucg[cgno]->b_data;
 42                                                    42 
 43         UCPI_UBH(ucpi)->fragment = ufs_cgcmin(     43         UCPI_UBH(ucpi)->fragment = ufs_cgcmin(cgno);
 44         UCPI_UBH(ucpi)->count = uspi->s_cgsize     44         UCPI_UBH(ucpi)->count = uspi->s_cgsize >> sb->s_blocksize_bits;
 45         /*                                         45         /*
 46          * We have already the first fragment      46          * We have already the first fragment of cylinder group block in buffer
 47          */                                        47          */
 48         UCPI_UBH(ucpi)->bh[0] = sbi->s_ucg[cgn     48         UCPI_UBH(ucpi)->bh[0] = sbi->s_ucg[cgno];
 49         for (i = 1; i < UCPI_UBH(ucpi)->count;     49         for (i = 1; i < UCPI_UBH(ucpi)->count; i++)
 50                 if (!(UCPI_UBH(ucpi)->bh[i] =      50                 if (!(UCPI_UBH(ucpi)->bh[i] = sb_bread(sb, UCPI_UBH(ucpi)->fragment + i)))
 51                         goto failed;               51                         goto failed;
 52         sbi->s_cgno[bitmap_nr] = cgno;             52         sbi->s_cgno[bitmap_nr] = cgno;
 53                                                    53                         
 54         ucpi->c_cgx     = fs32_to_cpu(sb, ucg-     54         ucpi->c_cgx     = fs32_to_cpu(sb, ucg->cg_cgx);
 55         ucpi->c_ncyl    = fs16_to_cpu(sb, ucg-     55         ucpi->c_ncyl    = fs16_to_cpu(sb, ucg->cg_ncyl);
 56         ucpi->c_niblk   = fs16_to_cpu(sb, ucg-     56         ucpi->c_niblk   = fs16_to_cpu(sb, ucg->cg_niblk);
 57         ucpi->c_ndblk   = fs32_to_cpu(sb, ucg-     57         ucpi->c_ndblk   = fs32_to_cpu(sb, ucg->cg_ndblk);
 58         ucpi->c_rotor   = fs32_to_cpu(sb, ucg-     58         ucpi->c_rotor   = fs32_to_cpu(sb, ucg->cg_rotor);
 59         ucpi->c_frotor  = fs32_to_cpu(sb, ucg-     59         ucpi->c_frotor  = fs32_to_cpu(sb, ucg->cg_frotor);
 60         ucpi->c_irotor  = fs32_to_cpu(sb, ucg-     60         ucpi->c_irotor  = fs32_to_cpu(sb, ucg->cg_irotor);
 61         ucpi->c_btotoff = fs32_to_cpu(sb, ucg-     61         ucpi->c_btotoff = fs32_to_cpu(sb, ucg->cg_btotoff);
 62         ucpi->c_boff    = fs32_to_cpu(sb, ucg-     62         ucpi->c_boff    = fs32_to_cpu(sb, ucg->cg_boff);
 63         ucpi->c_iusedoff = fs32_to_cpu(sb, ucg     63         ucpi->c_iusedoff = fs32_to_cpu(sb, ucg->cg_iusedoff);
 64         ucpi->c_freeoff = fs32_to_cpu(sb, ucg-     64         ucpi->c_freeoff = fs32_to_cpu(sb, ucg->cg_freeoff);
 65         ucpi->c_nextfreeoff = fs32_to_cpu(sb,      65         ucpi->c_nextfreeoff = fs32_to_cpu(sb, ucg->cg_nextfreeoff);
 66         ucpi->c_clustersumoff = fs32_to_cpu(sb     66         ucpi->c_clustersumoff = fs32_to_cpu(sb, ucg->cg_u.cg_44.cg_clustersumoff);
 67         ucpi->c_clusteroff = fs32_to_cpu(sb, u     67         ucpi->c_clusteroff = fs32_to_cpu(sb, ucg->cg_u.cg_44.cg_clusteroff);
 68         ucpi->c_nclusterblks = fs32_to_cpu(sb,     68         ucpi->c_nclusterblks = fs32_to_cpu(sb, ucg->cg_u.cg_44.cg_nclusterblks);
 69         UFSD("EXIT\n");                            69         UFSD("EXIT\n");
 70         return;                                    70         return; 
 71                                                    71         
 72 failed:                                            72 failed:
 73         for (j = 1; j < i; j++)                    73         for (j = 1; j < i; j++)
 74                 brelse (sbi->s_ucg[j]);            74                 brelse (sbi->s_ucg[j]);
 75         sbi->s_cgno[bitmap_nr] = UFS_CGNO_EMPT     75         sbi->s_cgno[bitmap_nr] = UFS_CGNO_EMPTY;
 76         ufs_error (sb, "ufs_read_cylinder", "c     76         ufs_error (sb, "ufs_read_cylinder", "can't read cylinder group block %u", cgno);
 77 }                                                  77 }
 78                                                    78 
 79 /*                                                 79 /*
 80  * Remove cylinder group from cache, doesn't r     80  * Remove cylinder group from cache, doesn't release memory
 81  * allocated for cylinder group (this is done      81  * allocated for cylinder group (this is done at ufs_put_super only).
 82  */                                                82  */
 83 void ufs_put_cylinder (struct super_block * sb     83 void ufs_put_cylinder (struct super_block * sb, unsigned bitmap_nr)
 84 {                                                  84 {
 85         struct ufs_sb_info * sbi = UFS_SB(sb);     85         struct ufs_sb_info * sbi = UFS_SB(sb);
 86         struct ufs_sb_private_info * uspi;         86         struct ufs_sb_private_info * uspi; 
 87         struct ufs_cg_private_info * ucpi;         87         struct ufs_cg_private_info * ucpi;
 88         struct ufs_cylinder_group * ucg;           88         struct ufs_cylinder_group * ucg;
 89         unsigned i;                                89         unsigned i;
 90                                                    90 
 91         UFSD("ENTER, bitmap_nr %u\n", bitmap_n     91         UFSD("ENTER, bitmap_nr %u\n", bitmap_nr);
 92                                                    92 
 93         uspi = sbi->s_uspi;                        93         uspi = sbi->s_uspi;
 94         if (sbi->s_cgno[bitmap_nr] == UFS_CGNO     94         if (sbi->s_cgno[bitmap_nr] == UFS_CGNO_EMPTY) {
 95                 UFSD("EXIT\n");                    95                 UFSD("EXIT\n");
 96                 return;                            96                 return;
 97         }                                          97         }
 98         ucpi = sbi->s_ucpi[bitmap_nr];             98         ucpi = sbi->s_ucpi[bitmap_nr];
 99         ucg = ubh_get_ucg(UCPI_UBH(ucpi));         99         ucg = ubh_get_ucg(UCPI_UBH(ucpi));
100                                                   100 
101         if (uspi->s_ncg > UFS_MAX_GROUP_LOADED    101         if (uspi->s_ncg > UFS_MAX_GROUP_LOADED && bitmap_nr >= sbi->s_cg_loaded) {
102                 ufs_panic (sb, "ufs_put_cylind    102                 ufs_panic (sb, "ufs_put_cylinder", "internal error");
103                 return;                           103                 return;
104         }                                         104         }
105         /*                                        105         /*
106          * rotor is not so important data, so     106          * rotor is not so important data, so we put it to disk 
107          * at the end of working with cylinder    107          * at the end of working with cylinder
108          */                                       108          */
109         ucg->cg_rotor = cpu_to_fs32(sb, ucpi->    109         ucg->cg_rotor = cpu_to_fs32(sb, ucpi->c_rotor);
110         ucg->cg_frotor = cpu_to_fs32(sb, ucpi-    110         ucg->cg_frotor = cpu_to_fs32(sb, ucpi->c_frotor);
111         ucg->cg_irotor = cpu_to_fs32(sb, ucpi-    111         ucg->cg_irotor = cpu_to_fs32(sb, ucpi->c_irotor);
112         ubh_mark_buffer_dirty (UCPI_UBH(ucpi))    112         ubh_mark_buffer_dirty (UCPI_UBH(ucpi));
113         for (i = 1; i < UCPI_UBH(ucpi)->count;    113         for (i = 1; i < UCPI_UBH(ucpi)->count; i++) {
114                 brelse (UCPI_UBH(ucpi)->bh[i])    114                 brelse (UCPI_UBH(ucpi)->bh[i]);
115         }                                         115         }
116                                                   116 
117         sbi->s_cgno[bitmap_nr] = UFS_CGNO_EMPT    117         sbi->s_cgno[bitmap_nr] = UFS_CGNO_EMPTY;
118         UFSD("EXIT\n");                           118         UFSD("EXIT\n");
119 }                                                 119 }
120                                                   120 
121 /*                                                121 /*
122  * Find cylinder group in cache and return it     122  * Find cylinder group in cache and return it as pointer.
123  * If cylinder group is not in cache, we will     123  * If cylinder group is not in cache, we will load it from disk.
124  *                                                124  *
125  * The cache is managed by LRU algorithm.         125  * The cache is managed by LRU algorithm. 
126  */                                               126  */
127 struct ufs_cg_private_info * ufs_load_cylinder    127 struct ufs_cg_private_info * ufs_load_cylinder (
128         struct super_block * sb, unsigned cgno    128         struct super_block * sb, unsigned cgno)
129 {                                                 129 {
130         struct ufs_sb_info * sbi = UFS_SB(sb);    130         struct ufs_sb_info * sbi = UFS_SB(sb);
131         struct ufs_sb_private_info * uspi;        131         struct ufs_sb_private_info * uspi;
132         struct ufs_cg_private_info * ucpi;        132         struct ufs_cg_private_info * ucpi;
133         unsigned cg, i, j;                        133         unsigned cg, i, j;
134                                                   134 
135         UFSD("ENTER, cgno %u\n", cgno);           135         UFSD("ENTER, cgno %u\n", cgno);
136                                                   136 
137         uspi = sbi->s_uspi;                       137         uspi = sbi->s_uspi;
138         if (cgno >= uspi->s_ncg) {                138         if (cgno >= uspi->s_ncg) {
139                 ufs_panic (sb, "ufs_load_cylin    139                 ufs_panic (sb, "ufs_load_cylinder", "internal error, high number of cg");
140                 return NULL;                      140                 return NULL;
141         }                                         141         }
142         /*                                        142         /*
143          * Cylinder group number cg it in cach    143          * Cylinder group number cg it in cache and it was last used
144          */                                       144          */
145         if (sbi->s_cgno[0] == cgno) {             145         if (sbi->s_cgno[0] == cgno) {
146                 UFSD("EXIT\n");                   146                 UFSD("EXIT\n");
147                 return sbi->s_ucpi[0];            147                 return sbi->s_ucpi[0];
148         }                                         148         }
149         /*                                        149         /*
150          * Number of cylinder groups is not hi    150          * Number of cylinder groups is not higher than UFS_MAX_GROUP_LOADED
151          */                                       151          */
152         if (uspi->s_ncg <= UFS_MAX_GROUP_LOADE    152         if (uspi->s_ncg <= UFS_MAX_GROUP_LOADED) {
153                 if (sbi->s_cgno[cgno] != UFS_C    153                 if (sbi->s_cgno[cgno] != UFS_CGNO_EMPTY) {
154                         if (sbi->s_cgno[cgno]     154                         if (sbi->s_cgno[cgno] != cgno) {
155                                 ufs_panic (sb,    155                                 ufs_panic (sb, "ufs_load_cylinder", "internal error, wrong number of cg in cache");
156                                 UFSD("EXIT (FA    156                                 UFSD("EXIT (FAILED)\n");
157                                 return NULL;      157                                 return NULL;
158                         }                         158                         }
159                         else {                    159                         else {
160                                 UFSD("EXIT\n")    160                                 UFSD("EXIT\n");
161                                 return sbi->s_    161                                 return sbi->s_ucpi[cgno];
162                         }                         162                         }
163                 } else {                          163                 } else {
164                         ufs_read_cylinder (sb,    164                         ufs_read_cylinder (sb, cgno, cgno);
165                         UFSD("EXIT\n");           165                         UFSD("EXIT\n");
166                         return sbi->s_ucpi[cgn    166                         return sbi->s_ucpi[cgno];
167                 }                                 167                 }
168         }                                         168         }
169         /*                                        169         /*
170          * Cylinder group number cg is in cach    170          * Cylinder group number cg is in cache but it was not last used, 
171          * we will move to the first position     171          * we will move to the first position
172          */                                       172          */
173         for (i = 0; i < sbi->s_cg_loaded && sb    173         for (i = 0; i < sbi->s_cg_loaded && sbi->s_cgno[i] != cgno; i++);
174         if (i < sbi->s_cg_loaded && sbi->s_cgn    174         if (i < sbi->s_cg_loaded && sbi->s_cgno[i] == cgno) {
175                 cg = sbi->s_cgno[i];              175                 cg = sbi->s_cgno[i];
176                 ucpi = sbi->s_ucpi[i];            176                 ucpi = sbi->s_ucpi[i];
177                 for (j = i; j > 0; j--) {         177                 for (j = i; j > 0; j--) {
178                         sbi->s_cgno[j] = sbi->    178                         sbi->s_cgno[j] = sbi->s_cgno[j-1];
179                         sbi->s_ucpi[j] = sbi->    179                         sbi->s_ucpi[j] = sbi->s_ucpi[j-1];
180                 }                                 180                 }
181                 sbi->s_cgno[0] = cg;              181                 sbi->s_cgno[0] = cg;
182                 sbi->s_ucpi[0] = ucpi;            182                 sbi->s_ucpi[0] = ucpi;
183         /*                                        183         /*
184          * Cylinder group number cg is not in     184          * Cylinder group number cg is not in cache, we will read it from disk
185          * and put it to the first position       185          * and put it to the first position
186          */                                       186          */
187         } else {                                  187         } else {
188                 if (sbi->s_cg_loaded < UFS_MAX    188                 if (sbi->s_cg_loaded < UFS_MAX_GROUP_LOADED)
189                         sbi->s_cg_loaded++;       189                         sbi->s_cg_loaded++;
190                 else                              190                 else
191                         ufs_put_cylinder (sb,     191                         ufs_put_cylinder (sb, UFS_MAX_GROUP_LOADED-1);
192                 ucpi = sbi->s_ucpi[sbi->s_cg_l    192                 ucpi = sbi->s_ucpi[sbi->s_cg_loaded - 1];
193                 for (j = sbi->s_cg_loaded - 1;    193                 for (j = sbi->s_cg_loaded - 1; j > 0; j--) {
194                         sbi->s_cgno[j] = sbi->    194                         sbi->s_cgno[j] = sbi->s_cgno[j-1];
195                         sbi->s_ucpi[j] = sbi->    195                         sbi->s_ucpi[j] = sbi->s_ucpi[j-1];
196                 }                                 196                 }
197                 sbi->s_ucpi[0] = ucpi;            197                 sbi->s_ucpi[0] = ucpi;
198                 ufs_read_cylinder (sb, cgno, 0    198                 ufs_read_cylinder (sb, cgno, 0);
199         }                                         199         }
200         UFSD("EXIT\n");                           200         UFSD("EXIT\n");
201         return sbi->s_ucpi[0];                    201         return sbi->s_ucpi[0];
202 }                                                 202 }
203                                                   203 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php