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

Linux Cross Reference
Linux/fs/ufs/super.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  linux/fs/ufs/super.c
  3  *
  4  * Copyright (C) 1998
  5  * Daniel Pirkl <daniel.pirkl@email.cz>
  6  * Charles University, Faculty of Mathematics and Physics
  7  */
  8 
  9 /* Derived from
 10  *
 11  *  linux/fs/ext2/super.c
 12  *
 13  * Copyright (C) 1992, 1993, 1994, 1995
 14  * Remy Card (card@masi.ibp.fr)
 15  * Laboratoire MASI - Institut Blaise Pascal
 16  * Universite Pierre et Marie Curie (Paris VI)
 17  *
 18  *  from
 19  *
 20  *  linux/fs/minix/inode.c
 21  *
 22  *  Copyright (C) 1991, 1992  Linus Torvalds
 23  *
 24  *  Big-endian to little-endian byte-swapping/bitmaps by
 25  *        David S. Miller (davem@caip.rutgers.edu), 1995
 26  */
 27  
 28 /*
 29  * Inspired by
 30  *
 31  *  linux/fs/ufs/super.c
 32  *
 33  * Copyright (C) 1996
 34  * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
 35  * Laboratory for Computer Science Research Computing Facility
 36  * Rutgers, The State University of New Jersey
 37  *
 38  * Copyright (C) 1996  Eddie C. Dost  (ecd@skynet.be)
 39  *
 40  * Kernel module support added on 96/04/26 by
 41  * Stefan Reinauer <stepan@home.culture.mipt.ru>
 42  *
 43  * Module usage counts added on 96/04/29 by
 44  * Gertjan van Wingerde <gertjan@cs.vu.nl>
 45  *
 46  * Clean swab support on 19970406 by
 47  * Francois-Rene Rideau <fare@tunes.org>
 48  *
 49  * 4.4BSD (FreeBSD) support added on February 1st 1998 by
 50  * Niels Kristian Bech Jensen <nkbj@image.dk> partially based
 51  * on code by Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>.
 52  *
 53  * NeXTstep support added on February 5th 1998 by
 54  * Niels Kristian Bech Jensen <nkbj@image.dk>.
 55  *
 56  * write support Daniel Pirkl <daniel.pirkl@email.cz> 1998
 57  * 
 58  * HP/UX hfs filesystem support added by
 59  * Martin K. Petersen <mkp@mkp.net>, August 1999
 60  *
 61  */
 62 
 63 
 64 #include <linux/config.h>
 65 #include <linux/module.h>
 66 
 67 #include <stdarg.h>
 68 
 69 #include <asm/bitops.h>
 70 #include <asm/uaccess.h>
 71 #include <asm/system.h>
 72 
 73 #include <linux/errno.h>
 74 #include <linux/fs.h>
 75 #include <linux/ufs_fs.h>
 76 #include <linux/malloc.h>
 77 #include <linux/sched.h>
 78 #include <linux/stat.h>
 79 #include <linux/string.h>
 80 #include <linux/locks.h>
 81 #include <linux/blkdev.h>
 82 #include <linux/init.h>
 83 
 84 #include "swab.h"
 85 #include "util.h"
 86 
 87 #undef UFS_SUPER_DEBUG
 88 #undef UFS_SUPER_DEBUG_MORE
 89 
 90 #ifdef UFS_SUPER_DEBUG
 91 #define UFSD(x) printk("(%s, %d), %s: ", __FILE__, __LINE__, __FUNCTION__); printk x;
 92 #else
 93 #define UFSD(x)
 94 #endif
 95 
 96 #ifdef UFS_SUPER_DEBUG_MORE
 97 /*
 98  * Print contents of ufs_super_block, useful for debugging
 99  */
100 void ufs_print_super_stuff(struct ufs_super_block_first * usb1,
101         struct ufs_super_block_second * usb2, 
102         struct ufs_super_block_third * usb3, unsigned swab)
103 {
104         printk("ufs_print_super_stuff\n");
105         printk("size of usb:     %u\n", sizeof(struct ufs_super_block));
106         printk("  magic:         0x%x\n", SWAB32(usb3->fs_magic));
107         printk("  sblkno:        %u\n", SWAB32(usb1->fs_sblkno));
108         printk("  cblkno:        %u\n", SWAB32(usb1->fs_cblkno));
109         printk("  iblkno:        %u\n", SWAB32(usb1->fs_iblkno));
110         printk("  dblkno:        %u\n", SWAB32(usb1->fs_dblkno));
111         printk("  cgoffset:      %u\n", SWAB32(usb1->fs_cgoffset));
112         printk("  ~cgmask:       0x%x\n", ~SWAB32(usb1->fs_cgmask));
113         printk("  size:          %u\n", SWAB32(usb1->fs_size));
114         printk("  dsize:         %u\n", SWAB32(usb1->fs_dsize));
115         printk("  ncg:           %u\n", SWAB32(usb1->fs_ncg));
116         printk("  bsize:         %u\n", SWAB32(usb1->fs_bsize));
117         printk("  fsize:         %u\n", SWAB32(usb1->fs_fsize));
118         printk("  frag:          %u\n", SWAB32(usb1->fs_frag));
119         printk("  fragshift:     %u\n", SWAB32(usb1->fs_fragshift));
120         printk("  ~fmask:        %u\n", ~SWAB32(usb1->fs_fmask));
121         printk("  fshift:        %u\n", SWAB32(usb1->fs_fshift));
122         printk("  sbsize:        %u\n", SWAB32(usb1->fs_sbsize));
123         printk("  spc:           %u\n", SWAB32(usb1->fs_spc));
124         printk("  cpg:           %u\n", SWAB32(usb1->fs_cpg));
125         printk("  ipg:           %u\n", SWAB32(usb1->fs_ipg));
126         printk("  fpg:           %u\n", SWAB32(usb1->fs_fpg));
127         printk("  csaddr:        %u\n", SWAB32(usb1->fs_csaddr));
128         printk("  cssize:        %u\n", SWAB32(usb1->fs_cssize));
129         printk("  cgsize:        %u\n", SWAB32(usb1->fs_cgsize));
130         printk("  fstodb:        %u\n", SWAB32(usb1->fs_fsbtodb));
131         printk("  contigsumsize: %d\n", SWAB32(usb3->fs_u2.fs_44.fs_contigsumsize));
132         printk("  postblformat:  %u\n", SWAB32(usb3->fs_postblformat));
133         printk("  nrpos:         %u\n", SWAB32(usb3->fs_nrpos));
134         printk("  ndir           %u\n", SWAB32(usb1->fs_cstotal.cs_ndir));
135         printk("  nifree         %u\n", SWAB32(usb1->fs_cstotal.cs_nifree));
136         printk("  nbfree         %u\n", SWAB32(usb1->fs_cstotal.cs_nbfree));
137         printk("  nffree         %u\n", SWAB32(usb1->fs_cstotal.cs_nffree));
138         printk("\n");
139 }
140 
141 
142 /*
143  * Print contents of ufs_cylinder_group, useful for debugging
144  */
145 void ufs_print_cylinder_stuff(struct ufs_cylinder_group *cg, unsigned swab)
146 {
147         printk("\nufs_print_cylinder_stuff\n");
148         printk("size of ucg: %u\n", sizeof(struct ufs_cylinder_group));
149         printk("  magic:        %x\n", SWAB32(cg->cg_magic));
150         printk("  time:         %u\n", SWAB32(cg->cg_time));
151         printk("  cgx:          %u\n", SWAB32(cg->cg_cgx));
152         printk("  ncyl:         %u\n", SWAB16(cg->cg_ncyl));
153         printk("  niblk:        %u\n", SWAB16(cg->cg_niblk));
154         printk("  ndblk:        %u\n", SWAB32(cg->cg_ndblk));
155         printk("  cs_ndir:      %u\n", SWAB32(cg->cg_cs.cs_ndir));
156         printk("  cs_nbfree:    %u\n", SWAB32(cg->cg_cs.cs_nbfree));
157         printk("  cs_nifree:    %u\n", SWAB32(cg->cg_cs.cs_nifree));
158         printk("  cs_nffree:    %u\n", SWAB32(cg->cg_cs.cs_nffree));
159         printk("  rotor:        %u\n", SWAB32(cg->cg_rotor));
160         printk("  frotor:       %u\n", SWAB32(cg->cg_frotor));
161         printk("  irotor:       %u\n", SWAB32(cg->cg_irotor));
162         printk("  frsum:        %u, %u, %u, %u, %u, %u, %u, %u\n",
163             SWAB32(cg->cg_frsum[0]), SWAB32(cg->cg_frsum[1]),
164             SWAB32(cg->cg_frsum[2]), SWAB32(cg->cg_frsum[3]),
165             SWAB32(cg->cg_frsum[4]), SWAB32(cg->cg_frsum[5]),
166             SWAB32(cg->cg_frsum[6]), SWAB32(cg->cg_frsum[7]));
167         printk("  btotoff:      %u\n", SWAB32(cg->cg_btotoff));
168         printk("  boff:         %u\n", SWAB32(cg->cg_boff));
169         printk("  iuseoff:      %u\n", SWAB32(cg->cg_iusedoff));
170         printk("  freeoff:      %u\n", SWAB32(cg->cg_freeoff));
171         printk("  nextfreeoff:  %u\n", SWAB32(cg->cg_nextfreeoff));
172         printk("  clustersumoff %u\n", SWAB32(cg->cg_u.cg_44.cg_clustersumoff));
173         printk("  clusteroff    %u\n", SWAB32(cg->cg_u.cg_44.cg_clusteroff));
174         printk("  nclusterblks  %u\n", SWAB32(cg->cg_u.cg_44.cg_nclusterblks));
175         printk("\n");
176 }
177 #endif /* UFS_SUPER_DEBUG_MORE */
178 
179 static struct super_operations ufs_super_ops;
180 
181 static char error_buf[1024];
182 
183 void ufs_error (struct super_block * sb, const char * function,
184         const char * fmt, ...)
185 {
186         struct ufs_sb_private_info * uspi;
187         struct ufs_super_block_first * usb1;
188         va_list args;
189 
190         uspi = sb->u.ufs_sb.s_uspi;
191         usb1 = ubh_get_usb_first(USPI_UBH);
192         
193         if (!(sb->s_flags & MS_RDONLY)) {
194                 usb1->fs_clean = UFS_FSBAD;
195                 ubh_mark_buffer_dirty(USPI_UBH);
196                 sb->s_dirt = 1;
197                 sb->s_flags |= MS_RDONLY;
198         }
199         va_start (args, fmt);
200         vsprintf (error_buf, fmt, args);
201         va_end (args);
202         switch (sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_ONERROR) {
203         case UFS_MOUNT_ONERROR_PANIC:
204                 panic ("UFS-fs panic (device %s): %s: %s\n", 
205                         kdevname(sb->s_dev), function, error_buf);
206 
207         case UFS_MOUNT_ONERROR_LOCK:
208         case UFS_MOUNT_ONERROR_UMOUNT:
209         case UFS_MOUNT_ONERROR_REPAIR:
210                 printk (KERN_CRIT "UFS-fs error (device %s): %s: %s\n",
211                         kdevname(sb->s_dev), function, error_buf);
212         }               
213 }
214 
215 void ufs_panic (struct super_block * sb, const char * function,
216         const char * fmt, ...)
217 {
218         struct ufs_sb_private_info * uspi;
219         struct ufs_super_block_first * usb1;
220         va_list args;
221         
222         uspi = sb->u.ufs_sb.s_uspi;
223         usb1 = ubh_get_usb_first(USPI_UBH);
224         
225         if (!(sb->s_flags & MS_RDONLY)) {
226                 usb1->fs_clean = UFS_FSBAD;
227                 ubh_mark_buffer_dirty(USPI_UBH);
228                 sb->s_dirt = 1;
229         }
230         va_start (args, fmt);
231         vsprintf (error_buf, fmt, args);
232         va_end (args);
233         /* this is to prevent panic from syncing this filesystem */
234         if (sb->s_lock)
235                 sb->s_lock = 0;
236         sb->s_flags |= MS_RDONLY;
237         printk (KERN_CRIT "UFS-fs panic (device %s): %s: %s\n",
238                 kdevname(sb->s_dev), function, error_buf);
239 }
240 
241 void ufs_warning (struct super_block * sb, const char * function,
242         const char * fmt, ...)
243 {
244         va_list args;
245 
246         va_start (args, fmt);
247         vsprintf (error_buf, fmt, args);
248         va_end (args);
249         printk (KERN_WARNING "UFS-fs warning (device %s): %s: %s\n",
250                 kdevname(sb->s_dev), function, error_buf);
251 }
252 
253 static int ufs_parse_options (char * options, unsigned * mount_options)
254 {
255         char * this_char;
256         char * value;
257         
258         UFSD(("ENTER\n"))
259         
260         if (!options)
261                 return 1;
262                 
263         for (this_char = strtok (options, ",");
264              this_char != NULL;
265              this_char = strtok (NULL, ",")) {
266              
267                 if ((value = strchr (this_char, '=')) != NULL)
268                         *value++ = 0;
269                 if (!strcmp (this_char, "ufstype")) {
270                         ufs_clear_opt (*mount_options, UFSTYPE);
271                         if (!strcmp (value, "old"))
272                                 ufs_set_opt (*mount_options, UFSTYPE_OLD);
273                         else if (!strcmp (value, "sun"))
274                                 ufs_set_opt (*mount_options, UFSTYPE_SUN);
275                         else if (!strcmp (value, "44bsd"))
276                                 ufs_set_opt (*mount_options, UFSTYPE_44BSD);
277                         else if (!strcmp (value, "nextstep"))
278                                 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP);
279                         else if (!strcmp (value, "nextstep-cd"))
280                                 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP_CD);
281                         else if (!strcmp (value, "openstep"))
282                                 ufs_set_opt (*mount_options, UFSTYPE_OPENSTEP);
283                         else if (!strcmp (value, "sunx86"))
284                                 ufs_set_opt (*mount_options, UFSTYPE_SUNx86);
285                         else if (!strcmp (value, "hp"))
286                                 ufs_set_opt (*mount_options, UFSTYPE_HP);
287                         else {
288                                 printk ("UFS-fs: Invalid type option: %s\n", value);
289                                 return 0;
290                         }
291                 }
292                 else if (!strcmp (this_char, "onerror")) {
293                         ufs_clear_opt (*mount_options, ONERROR);
294                         if (!strcmp (value, "panic"))
295                                 ufs_set_opt (*mount_options, ONERROR_PANIC);
296                         else if (!strcmp (value, "lock"))
297                                 ufs_set_opt (*mount_options, ONERROR_LOCK);
298                         else if (!strcmp (value, "umount"))
299                                 ufs_set_opt (*mount_options, ONERROR_UMOUNT);
300                         else if (!strcmp (value, "repair")) {
301                                 printk("UFS-fs: Unable to do repair on error, "
302                                         "will lock lock instead \n");
303                                 ufs_set_opt (*mount_options, ONERROR_REPAIR);
304                         }
305                         else {
306                                 printk ("UFS-fs: Invalid action onerror: %s\n", value);
307                                 return 0;
308                         }
309                 }
310                 else {
311                         printk("UFS-fs: Invalid option: %s\n", this_char);
312                         return 0;
313                 }
314         }
315         return 1;
316 }
317 
318 /*
319  * Read on-disk structures associated with cylinder groups
320  */
321 int ufs_read_cylinder_structures (struct super_block * sb) {
322         struct ufs_sb_private_info * uspi;
323         struct ufs_buffer_head * ubh;
324         unsigned char * base, * space;
325         unsigned size, blks, i;
326         unsigned swab;
327         
328         UFSD(("ENTER\n"))
329         
330         uspi = sb->u.ufs_sb.s_uspi;
331         swab = sb->u.ufs_sb.s_swab;
332         
333         /*
334          * Read cs structures from (usually) first data block
335          * on the device. 
336          */
337         size = uspi->s_cssize;
338         blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
339         base = space = kmalloc(size, GFP_KERNEL);
340         if (!base)
341                 goto failed; 
342         for (i = 0; i < blks; i += uspi->s_fpb) {
343                 size = uspi->s_bsize;
344                 if (i + uspi->s_fpb > blks)
345                         size = (blks - i) * uspi->s_fsize;
346                 ubh = ubh_bread(sb->s_dev, uspi->s_csaddr + i, size);
347                 if (!ubh)
348                         goto failed;
349                 ubh_ubhcpymem (space, ubh, size);
350                 sb->u.ufs_sb.s_csp[ufs_fragstoblks(i)] = (struct ufs_csum *)space;
351                 space += size;
352                 ubh_brelse (ubh);
353                 ubh = NULL;
354         }
355 
356         /*
357          * Read cylinder group (we read only first fragment from block
358          * at this time) and prepare internal data structures for cg caching.
359          */
360         if (!(sb->u.ufs_sb.s_ucg = kmalloc (sizeof(struct buffer_head *) * uspi->s_ncg, GFP_KERNEL)))
361                 goto failed;
362         for (i = 0; i < uspi->s_ncg; i++) 
363                 sb->u.ufs_sb.s_ucg[i] = NULL;
364         for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
365                 sb->u.ufs_sb.s_ucpi[i] = NULL;
366                 sb->u.ufs_sb.s_cgno[i] = UFS_CGNO_EMPTY;
367         }
368         for (i = 0; i < uspi->s_ncg; i++) {
369                 UFSD(("read cg %u\n", i))
370                 if (!(sb->u.ufs_sb.s_ucg[i] = bread (sb->s_dev, ufs_cgcmin(i), sb->s_blocksize)))
371                         goto failed;
372                 if (!ufs_cg_chkmagic ((struct ufs_cylinder_group *) sb->u.ufs_sb.s_ucg[i]->b_data))
373                         goto failed;
374 #ifdef UFS_SUPER_DEBUG_MORE
375                 ufs_print_cylinder_stuff((struct ufs_cylinder_group *) sb->u.ufs_sb.s_ucg[i]->b_data, swab);
376 #endif
377         }
378         for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
379                 if (!(sb->u.ufs_sb.s_ucpi[i] = kmalloc (sizeof(struct ufs_cg_private_info), GFP_KERNEL)))
380                         goto failed;
381                 sb->u.ufs_sb.s_cgno[i] = UFS_CGNO_EMPTY;
382         }
383         sb->u.ufs_sb.s_cg_loaded = 0;
384         UFSD(("EXIT\n"))
385         return 1;
386 
387 failed:
388         if (base) kfree (base);
389         if (sb->u.ufs_sb.s_ucg) {
390                 for (i = 0; i < uspi->s_ncg; i++)
391                         if (sb->u.ufs_sb.s_ucg[i]) brelse (sb->u.ufs_sb.s_ucg[i]);
392                 kfree (sb->u.ufs_sb.s_ucg);
393                 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
394                         if (sb->u.ufs_sb.s_ucpi[i]) kfree (sb->u.ufs_sb.s_ucpi[i]);
395         }
396         UFSD(("EXIT (FAILED)\n"))
397         return 0;
398 }
399 
400 /*
401  * Put on-disk structures associated with cylinder groups and 
402  * write them back to disk
403  */
404 void ufs_put_cylinder_structures (struct super_block * sb) {
405         struct ufs_sb_private_info * uspi;
406         struct ufs_buffer_head * ubh;
407         unsigned char * base, * space;
408         unsigned blks, size, i;
409         
410         UFSD(("ENTER\n"))
411         
412         uspi = sb->u.ufs_sb.s_uspi;
413 
414         size = uspi->s_cssize;
415         blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
416         base = space = (char*) sb->u.ufs_sb.s_csp[0];
417         for (i = 0; i < blks; i += uspi->s_fpb) {
418                 size = uspi->s_bsize;
419                 if (i + uspi->s_fpb > blks)
420                         size = (blks - i) * uspi->s_fsize;
421                 ubh = ubh_bread (sb->s_dev, uspi->s_csaddr + i, size);
422                 ubh_memcpyubh (ubh, space, size);
423                 space += size;
424                 ubh_mark_buffer_uptodate (ubh, 1);
425                 ubh_mark_buffer_dirty (ubh);
426                 ubh_brelse (ubh);
427         }
428         for (i = 0; i < sb->u.ufs_sb.s_cg_loaded; i++) {
429                 ufs_put_cylinder (sb, i);
430                 kfree (sb->u.ufs_sb.s_ucpi[i]);
431         }
432         for (; i < UFS_MAX_GROUP_LOADED; i++) 
433                 kfree (sb->u.ufs_sb.s_ucpi[i]);
434         for (i = 0; i < uspi->s_ncg; i++) 
435                 brelse (sb->u.ufs_sb.s_ucg[i]);
436         kfree (sb->u.ufs_sb.s_ucg);
437         kfree (base);
438         UFSD(("EXIT\n"))
439 }
440 
441 struct super_block * ufs_read_super (struct super_block * sb, void * data,
442         int silent)
443 {
444         struct ufs_sb_private_info * uspi;
445         struct ufs_super_block_first * usb1;
446         struct ufs_super_block_second * usb2;
447         struct ufs_super_block_third * usb3;
448         struct ufs_buffer_head * ubh;   
449         unsigned block_size, super_block_size;
450         unsigned flags, swab;
451 
452         uspi = NULL;
453         ubh = NULL;
454         flags = 0;
455         swab = 0;
456         
457         UFSD(("ENTER\n"))
458                 
459         UFSD(("flag %u\n", (int)(sb->s_flags & MS_RDONLY)))
460         
461 #ifndef CONFIG_UFS_FS_WRITE
462         if (!(sb->s_flags & MS_RDONLY)) {
463                 printk("ufs was compiled with read-only support, "
464                 "can't be mounted as read-write\n");
465                 goto failed;
466         }
467 #endif
468         /*
469          * Set default mount options
470          * Parse mount options
471          */
472         sb->u.ufs_sb.s_mount_opt = 0;
473         ufs_set_opt (sb->u.ufs_sb.s_mount_opt, ONERROR_LOCK);
474         if (!ufs_parse_options ((char *) data, &sb->u.ufs_sb.s_mount_opt)) {
475                 printk("wrong mount options\n");
476                 goto failed;
477         }
478         if (!(sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE)) {
479                 printk("You didn't specify the type of your ufs filesystem\n\n"
480                 "mount -t ufs -o ufstype="
481                 "sun|sunx86|44bsd|old|hp|nextstep|netxstep-cd|openstep ...\n\n"
482                 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
483                 "default is ufstype=old\n");
484                 ufs_set_opt (sb->u.ufs_sb.s_mount_opt, UFSTYPE_OLD);
485         }
486 
487         sb->u.ufs_sb.s_uspi = uspi =
488                 kmalloc (sizeof(struct ufs_sb_private_info), GFP_KERNEL);
489         if (!uspi)
490                 goto failed;
491 
492         switch (sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE) {
493         case UFS_MOUNT_UFSTYPE_44BSD:
494                 UFSD(("ufstype=44bsd\n"))
495                 uspi->s_fsize = block_size = 512;
496                 uspi->s_fmask = ~(512 - 1);
497                 uspi->s_fshift = 9;
498                 uspi->s_sbsize = super_block_size = 1536;
499                 uspi->s_sbbase = 0;
500                 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
501                 break;
502                 
503         case UFS_MOUNT_UFSTYPE_SUN:
504                 UFSD(("ufstype=sun\n"))
505                 uspi->s_fsize = block_size = 1024;
506                 uspi->s_fmask = ~(1024 - 1);
507                 uspi->s_fshift = 10;
508                 uspi->s_sbsize = super_block_size = 2048;
509                 uspi->s_sbbase = 0;
510                 uspi->s_maxsymlinklen = 56;
511                 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUN | UFS_CG_SUN;
512                 break;
513 
514         case UFS_MOUNT_UFSTYPE_SUNx86:
515                 UFSD(("ufstype=sunx86\n"))
516                 uspi->s_fsize = block_size = 1024;
517                 uspi->s_fmask = ~(1024 - 1);
518                 uspi->s_fshift = 10;
519                 uspi->s_sbsize = super_block_size = 2048;
520                 uspi->s_sbbase = 0;
521                 uspi->s_maxsymlinklen = 56;
522                 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUNx86 | UFS_CG_SUN;
523                 break;
524 
525         case UFS_MOUNT_UFSTYPE_OLD:
526                 UFSD(("ufstype=old\n"))
527                 uspi->s_fsize = block_size = 1024;
528                 uspi->s_fmask = ~(1024 - 1);
529                 uspi->s_fshift = 10;
530                 uspi->s_sbsize = super_block_size = 2048;
531                 uspi->s_sbbase = 0;
532                 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
533                 if (!(sb->s_flags & MS_RDONLY)) {
534                         printk(KERN_INFO "ufstype=old is supported read-only\n"); 
535                         sb->s_flags |= MS_RDONLY;
536                 }
537                 break;
538         
539         case UFS_MOUNT_UFSTYPE_NEXTSTEP:
540                 UFSD(("ufstype=nextstep\n"))
541                 uspi->s_fsize = block_size = 1024;
542                 uspi->s_fmask = ~(1024 - 1);
543                 uspi->s_fshift = 10;
544                 uspi->s_sbsize = super_block_size = 2048;
545                 uspi->s_sbbase = 0;
546                 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
547                 if (!(sb->s_flags & MS_RDONLY)) {
548                         printk(KERN_INFO "ufstype=nextstep is supported read-only\n");
549                         sb->s_flags |= MS_RDONLY;
550                 }
551                 break;
552         
553         case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD:
554                 UFSD(("ufstype=nextstep-cd\n"))
555                 uspi->s_fsize = block_size = 2048;
556                 uspi->s_fmask = ~(2048 - 1);
557                 uspi->s_fshift = 11;
558                 uspi->s_sbsize = super_block_size = 2048;
559                 uspi->s_sbbase = 0;
560                 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
561                 if (!(sb->s_flags & MS_RDONLY)) {
562                         printk(KERN_INFO "ufstype=nextstep-cd is supported read-only\n");
563                         sb->s_flags |= MS_RDONLY;
564                 }
565                 break;
566         
567         case UFS_MOUNT_UFSTYPE_OPENSTEP:
568                 UFSD(("ufstype=openstep\n"))
569                 uspi->s_fsize = block_size = 1024;
570                 uspi->s_fmask = ~(1024 - 1);
571                 uspi->s_fshift = 10;
572                 uspi->s_sbsize = super_block_size = 2048;
573                 uspi->s_sbbase = 0;
574                 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
575                 if (!(sb->s_flags & MS_RDONLY)) {
576                         printk(KERN_INFO "ufstype=openstep is supported read-only\n");
577                         sb->s_flags |= MS_RDONLY;
578                 }
579                 break;
580         
581         case UFS_MOUNT_UFSTYPE_HP:
582                 UFSD(("ufstype=hp\n"))
583                 uspi->s_fsize = block_size = 1024;
584                 uspi->s_fmask = ~(1024 - 1);
585                 uspi->s_fshift = 10;
586                 uspi->s_sbsize = super_block_size = 2048;
587                 uspi->s_sbbase = 0;
588                 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
589                 if (!(sb->s_flags & MS_RDONLY)) {
590                         printk(KERN_INFO "ufstype=hp is supported read-only\n");
591                         sb->s_flags |= MS_RDONLY;
592                 }
593                 break;
594         default:
595                 printk("unknown ufstype\n");
596                 goto failed;
597         }
598         
599 again:  
600         set_blocksize (sb->s_dev, block_size);
601 
602         /*
603          * read ufs super block from device
604          */
605         ubh = ubh_bread_uspi (uspi, sb->s_dev, uspi->s_sbbase + UFS_SBLOCK/block_size, super_block_size);
606         if (!ubh) 
607                 goto failed;
608         
609         usb1 = ubh_get_usb_first(USPI_UBH);
610         usb2 = ubh_get_usb_second(USPI_UBH);
611         usb3 = ubh_get_usb_third(USPI_UBH);
612 
613         /*
614          * Check ufs magic number
615          */
616 #if defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN) /* sane bytesex */
617         switch (usb3->fs_magic) {
618                 case UFS_MAGIC:
619                 case UFS_MAGIC_LFN:
620                 case UFS_MAGIC_FEA:
621                 case UFS_MAGIC_4GB:
622                         swab = UFS_NATIVE_ENDIAN;
623                         goto magic_found;
624                 case UFS_CIGAM:
625                 case UFS_CIGAM_LFN:
626                 case UFS_CIGAM_FEA:
627                 case UFS_CIGAM_4GB:
628                         swab = UFS_SWABBED_ENDIAN;
629                         goto magic_found;
630         }
631 #else /* bytesex perversion */
632         switch (le32_to_cpup(&usb3->fs_magic)) {
633                 case UFS_MAGIC:
634                 case UFS_MAGIC_LFN:
635                 case UFS_MAGIC_FEA:
636                 case UFS_MAGIC_4GB:
637                         swab = UFS_LITTLE_ENDIAN;
638                         goto magic_found;
639                 case UFS_CIGAM:
640                 case UFS_CIGAM_LFN:
641                 case UFS_CIGAM_FEA:
642                 case UFS_CIGAM_4GB:
643                         swab = UFS_BIG_ENDIAN;
644                         goto magic_found;
645         }
646 #endif
647 
648         if ((((sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP) 
649           || ((sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD) 
650           || ((sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_OPENSTEP)) 
651           && uspi->s_sbbase < 256) {
652                 ubh_brelse_uspi(uspi);
653                 ubh = NULL;
654                 uspi->s_sbbase += 8;
655                 goto again;
656         }
657         printk("ufs_read_super: bad magic number\n");
658         goto failed;
659 
660 magic_found:
661         /*
662          * Check block and fragment sizes
663          */
664         uspi->s_bsize = SWAB32(usb1->fs_bsize);
665         uspi->s_fsize = SWAB32(usb1->fs_fsize);
666         uspi->s_sbsize = SWAB32(usb1->fs_sbsize);
667         uspi->s_fmask = SWAB32(usb1->fs_fmask);
668         uspi->s_fshift = SWAB32(usb1->fs_fshift);
669 
670         if (uspi->s_bsize != 4096 && uspi->s_bsize != 8192 
671           && uspi->s_bsize != 32768) {
672                 printk("ufs_read_super: fs_bsize %u != {4096, 8192, 32768}\n", uspi->s_bsize);
673                 goto failed;
674         }
675         if (uspi->s_fsize != 512 && uspi->s_fsize != 1024 
676           && uspi->s_fsize != 2048 && uspi->s_fsize != 4096) {
677                 printk("ufs_read_super: fs_fsize %u != {512, 1024, 2048. 4096}\n", uspi->s_fsize);
678                 goto failed;
679         }
680         if (uspi->s_fsize != block_size || uspi->s_sbsize != super_block_size) {
681                 ubh_brelse_uspi(uspi);
682                 ubh = NULL;
683                 block_size = uspi->s_fsize;
684                 super_block_size = uspi->s_sbsize;
685                 UFSD(("another value of block_size or super_block_size %u, %u\n", block_size, super_block_size))
686                 goto again;
687         }
688 
689 #ifdef UFS_SUPER_DEBUG_MORE
690         ufs_print_super_stuff (usb1, usb2, usb3, swab);
691 #endif
692 
693         /*
694          * Check, if file system was correctly unmounted.
695          * If not, make it read only.
696          */
697         if (((flags & UFS_ST_MASK) == UFS_ST_44BSD) ||
698           ((flags & UFS_ST_MASK) == UFS_ST_OLD) ||
699           (((flags & UFS_ST_MASK) == UFS_ST_SUN || 
700           (flags & UFS_ST_MASK) == UFS_ST_SUNx86) && 
701           (ufs_get_fs_state(usb1, usb3) == (UFS_FSOK - SWAB32(usb1->fs_time))))) {
702                 switch(usb1->fs_clean) {
703                 case UFS_FSCLEAN:
704                         UFSD(("fs is clean\n"))
705                         break;
706                 case UFS_FSSTABLE:
707                         UFSD(("fs is stable\n"))
708                         break;
709                 case UFS_FSOSF1:
710                         UFSD(("fs is DEC OSF/1\n"))
711                         break;
712                 case UFS_FSACTIVE:
713                         printk("ufs_read_super: fs is active\n");
714                         sb->s_flags |= MS_RDONLY;
715                         break;
716                 case UFS_FSBAD:
717                         printk("ufs_read_super: fs is bad\n");
718                         sb->s_flags |= MS_RDONLY;
719                         break;
720                 default:
721                         printk("ufs_read_super: can't grok fs_clean 0x%x\n", usb1->fs_clean);
722                         sb->s_flags |= MS_RDONLY;
723                         break;
724                 }
725         }
726         else {
727                 printk("ufs_read_super: fs needs fsck\n");
728                 sb->s_flags |= MS_RDONLY;
729         }
730 
731         /*
732          * Read ufs_super_block into internal data structures
733          */
734         sb->s_blocksize =  SWAB32(usb1->fs_fsize);
735         sb->s_blocksize_bits = SWAB32(usb1->fs_fshift);
736         sb->s_op = &ufs_super_ops;
737         sb->dq_op = NULL; /***/
738         sb->s_magic = SWAB32(usb3->fs_magic);
739 
740         uspi->s_sblkno = SWAB32(usb1->fs_sblkno);
741         uspi->s_cblkno = SWAB32(usb1->fs_cblkno);
742         uspi->s_iblkno = SWAB32(usb1->fs_iblkno);
743         uspi->s_dblkno = SWAB32(usb1->fs_dblkno);
744         uspi->s_cgoffset = SWAB32(usb1->fs_cgoffset);
745         uspi->s_cgmask = SWAB32(usb1->fs_cgmask);
746         uspi->s_size = SWAB32(usb1->fs_size);
747         uspi->s_dsize = SWAB32(usb1->fs_dsize);
748         uspi->s_ncg = SWAB32(usb1->fs_ncg);
749         /* s_bsize already set */
750         /* s_fsize already set */
751         uspi->s_fpb = SWAB32(usb1->fs_frag);
752         uspi->s_minfree = SWAB32(usb1->fs_minfree);
753         uspi->s_bmask = SWAB32(usb1->fs_bmask);
754         uspi->s_fmask = SWAB32(usb1->fs_fmask);
755         uspi->s_bshift = SWAB32(usb1->fs_bshift);
756         uspi->s_fshift = SWAB32(usb1->fs_fshift);
757         uspi->s_fpbshift = SWAB32(usb1->fs_fragshift);
758         uspi->s_fsbtodb = SWAB32(usb1->fs_fsbtodb);
759         /* s_sbsize already set */
760         uspi->s_csmask = SWAB32(usb1->fs_csmask);
761         uspi->s_csshift = SWAB32(usb1->fs_csshift);
762         uspi->s_nindir = SWAB32(usb1->fs_nindir);
763         uspi->s_inopb = SWAB32(usb1->fs_inopb);
764         uspi->s_nspf = SWAB32(usb1->fs_nspf);
765         uspi->s_npsect = ufs_get_fs_npsect(usb1, usb3);
766         uspi->s_interleave = SWAB32(usb1->fs_interleave);
767         uspi->s_trackskew = SWAB32(usb1->fs_trackskew);
768         uspi->s_csaddr = SWAB32(usb1->fs_csaddr);
769         uspi->s_cssize = SWAB32(usb1->fs_cssize);
770         uspi->s_cgsize = SWAB32(usb1->fs_cgsize);
771         uspi->s_ntrak = SWAB32(usb1->fs_ntrak);
772         uspi->s_nsect = SWAB32(usb1->fs_nsect);
773         uspi->s_spc = SWAB32(usb1->fs_spc);
774         uspi->s_ipg = SWAB32(usb1->fs_ipg);
775         uspi->s_fpg = SWAB32(usb1->fs_fpg);
776         uspi->s_cpc = SWAB32(usb2->fs_cpc);
777         uspi->s_contigsumsize = SWAB32(usb3->fs_u2.fs_44.fs_contigsumsize);
778         uspi->s_qbmask = ufs_get_fs_qbmask(usb3);
779         uspi->s_qfmask = ufs_get_fs_qfmask(usb3);
780         uspi->s_postblformat = SWAB32(usb3->fs_postblformat);
781         uspi->s_nrpos = SWAB32(usb3->fs_nrpos);
782         uspi->s_postbloff = SWAB32(usb3->fs_postbloff);
783         uspi->s_rotbloff = SWAB32(usb3->fs_rotbloff);
784 
785         /*
786          * Compute another frequently used values
787          */
788         uspi->s_fpbmask = uspi->s_fpb - 1;
789         uspi->s_apbshift = uspi->s_bshift - 2;
790         uspi->s_2apbshift = uspi->s_apbshift * 2;
791         uspi->s_3apbshift = uspi->s_apbshift * 3;
792         uspi->s_apb = 1 << uspi->s_apbshift;
793         uspi->s_2apb = 1 << uspi->s_2apbshift;
794         uspi->s_3apb = 1 << uspi->s_3apbshift;
795         uspi->s_apbmask = uspi->s_apb - 1;
796         uspi->s_nspfshift = uspi->s_fshift - UFS_SECTOR_BITS;
797         uspi->s_nspb = uspi->s_nspf << uspi->s_fpbshift;
798         uspi->s_inopf = uspi->s_inopb >> uspi->s_fpbshift;
799         uspi->s_bpf = uspi->s_fsize << 3;
800         uspi->s_bpfshift = uspi->s_fshift + 3;
801         uspi->s_bpfmask = uspi->s_bpf - 1;
802         if ((sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE) ==
803             UFS_MOUNT_UFSTYPE_44BSD)
804                 uspi->s_maxsymlinklen =
805                     SWAB32(usb3->fs_u2.fs_44.fs_maxsymlinklen);
806         
807         sb->u.ufs_sb.s_flags = flags;
808         sb->u.ufs_sb.s_swab = swab;
809                                                                           
810         sb->s_root = d_alloc_root(iget(sb, UFS_ROOTINO));
811 
812 
813         /*
814          * Read cylinder group structures
815          */
816         if (!(sb->s_flags & MS_RDONLY))
817                 if (!ufs_read_cylinder_structures(sb))
818                         goto failed;
819 
820         UFSD(("EXIT\n"))
821         return(sb);
822 
823 failed:
824         if (ubh) ubh_brelse_uspi (uspi);
825         if (uspi) kfree (uspi);
826         UFSD(("EXIT (FAILED)\n"))
827         return(NULL);
828 }
829 
830 void ufs_write_super (struct super_block * sb) {
831         struct ufs_sb_private_info * uspi;
832         struct ufs_super_block_first * usb1;
833         struct ufs_super_block_third * usb3;
834         unsigned flags, swab;
835 
836         UFSD(("ENTER\n"))
837         swab = sb->u.ufs_sb.s_swab;
838         flags = sb->u.ufs_sb.s_flags;
839         uspi = sb->u.ufs_sb.s_uspi;
840         usb1 = ubh_get_usb_first(USPI_UBH);
841         usb3 = ubh_get_usb_third(USPI_UBH);
842 
843         if (!(sb->s_flags & MS_RDONLY)) {
844                 usb1->fs_time = SWAB32(CURRENT_TIME);
845                 if ((flags & UFS_ST_MASK) == UFS_ST_SUN 
846                   || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
847                         ufs_set_fs_state(usb1, usb3, UFS_FSOK - SWAB32(usb1->fs_time));
848                 ubh_mark_buffer_dirty (USPI_UBH);
849         }
850         sb->s_dirt = 0;
851         UFSD(("EXIT\n"))
852 }
853 
854 void ufs_put_super (struct super_block * sb)
855 {
856         struct ufs_sb_private_info * uspi;
857         unsigned swab;
858                 
859         UFSD(("ENTER\n"))
860 
861         uspi = sb->u.ufs_sb.s_uspi;
862         swab = sb->u.ufs_sb.s_swab;
863 
864         if (!(sb->s_flags & MS_RDONLY))
865                 ufs_put_cylinder_structures (sb);
866         
867         ubh_brelse_uspi (uspi);
868         kfree (sb->u.ufs_sb.s_uspi);
869         return;
870 }
871 
872 
873 int ufs_remount (struct super_block * sb, int * mount_flags, char * data)
874 {
875         struct ufs_sb_private_info * uspi;
876         struct ufs_super_block_first * usb1;
877         struct ufs_super_block_third * usb3;
878         unsigned new_mount_opt, ufstype;
879         unsigned flags, swab;
880         
881         uspi = sb->u.ufs_sb.s_uspi;
882         flags = sb->u.ufs_sb.s_flags;
883         swab = sb->u.ufs_sb.s_swab;
884         usb1 = ubh_get_usb_first(USPI_UBH);
885         usb3 = ubh_get_usb_third(USPI_UBH);
886         
887         /*
888          * Allow the "check" option to be passed as a remount option.
889          * It is not possible to change ufstype option during remount
890          */
891         ufstype = sb->u.ufs_sb.s_mount_opt & UFS_MOUNT_UFSTYPE;
892         new_mount_opt = 0;
893         ufs_set_opt (new_mount_opt, ONERROR_LOCK);
894         if (!ufs_parse_options (data, &new_mount_opt))
895                 return -EINVAL;
896         if (!(new_mount_opt & UFS_MOUNT_UFSTYPE)) {
897                 new_mount_opt |= ufstype;
898         }
899         else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
900                 printk("ufstype can't be changed during remount\n");
901                 return -EINVAL;
902         }
903 
904         if ((*mount_flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
905                 sb->u.ufs_sb.s_mount_opt = new_mount_opt;
906                 return 0;
907         }
908         
909         /*
910          * fs was mouted as rw, remounting ro
911          */
912         if (*mount_flags & MS_RDONLY) {
913                 ufs_put_cylinder_structures(sb);
914                 usb1->fs_time = SWAB32(CURRENT_TIME);
915                 if ((flags & UFS_ST_MASK) == UFS_ST_SUN
916                   || (flags & UFS_ST_MASK) == UFS_ST_SUNx86) 
917                         ufs_set_fs_state(usb1, usb3, UFS_FSOK - SWAB32(usb1->fs_time));
918                 ubh_mark_buffer_dirty (USPI_UBH);
919                 sb->s_dirt = 0;
920                 sb->s_flags |= MS_RDONLY;
921         }
922         /*
923          * fs was mounted as ro, remounting rw
924          */
925         else {
926 #ifndef CONFIG_UFS_FS_WRITE
927                 printk("ufs was compiled with read-only support, "
928                 "can't be mounted as read-write\n");
929                 return -EINVAL;
930 #else
931                 if (ufstype != UFS_MOUNT_UFSTYPE_SUN && 
932                     ufstype != UFS_MOUNT_UFSTYPE_44BSD &&
933                     ufstype != UFS_MOUNT_UFSTYPE_SUNx86) {
934                         printk("this ufstype is read-only supported\n");
935                         return -EINVAL;
936                 }
937                 if (!ufs_read_cylinder_structures (sb)) {
938                         printk("failed during remounting\n");
939                         return -EPERM;
940                 }
941                 sb->s_flags &= ~MS_RDONLY;
942 #endif
943         }
944         sb->u.ufs_sb.s_mount_opt = new_mount_opt;
945         return 0;
946 }
947 
948 int ufs_statfs (struct super_block * sb, struct statfs * buf)
949 {
950         struct ufs_sb_private_info * uspi;
951         struct ufs_super_block_first * usb1;
952         unsigned swab;
953 
954         swab = sb->u.ufs_sb.s_swab;
955         uspi = sb->u.ufs_sb.s_uspi;
956         usb1 = ubh_get_usb_first (USPI_UBH);
957         
958         buf->f_type = UFS_MAGIC;
959         buf->f_bsize = sb->s_blocksize;
960         buf->f_blocks = uspi->s_dsize;
961         buf->f_bfree = ufs_blkstofrags(SWAB32(usb1->fs_cstotal.cs_nbfree)) +
962                 SWAB32(usb1->fs_cstotal.cs_nffree);
963         buf->f_bavail = (buf->f_bfree > ((buf->f_blocks / 100) * uspi->s_minfree))
964                 ? (buf->f_bfree - ((buf->f_blocks / 100) * uspi->s_minfree)) : 0;
965         buf->f_files = uspi->s_ncg * uspi->s_ipg;
966         buf->f_ffree = SWAB32(usb1->fs_cstotal.cs_nifree);
967         buf->f_namelen = UFS_MAXNAMLEN;
968         return 0;
969 }
970 
971 static struct super_operations ufs_super_ops = {
972         read_inode:     ufs_read_inode,
973         write_inode:    ufs_write_inode,
974         delete_inode:   ufs_delete_inode,
975         put_super:      ufs_put_super,
976         write_super:    ufs_write_super,
977         statfs:         ufs_statfs,
978         remount_fs:     ufs_remount,
979 };
980 
981 static DECLARE_FSTYPE_DEV(ufs_fs_type, "ufs", ufs_read_super);
982 
983 static int __init init_ufs_fs(void)
984 {
985         return register_filesystem(&ufs_fs_type);
986 }
987 
988 static void __exit exit_ufs_fs(void)
989 {
990         unregister_filesystem(&ufs_fs_type);
991 }
992 
993 EXPORT_NO_SYMBOLS;
994 
995 module_init(init_ufs_fs)
996 module_exit(exit_ufs_fs)
997 

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

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.