blob: da73801301d588bf14eb4e107e42609bedbfb51b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Gertjan van Wingerdef762dd62009-03-21 23:18:57 +010044 * Gertjan van Wingerde <gwingerde@gmail.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 *
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 * UFS2 (of FreeBSD 5.x) support added by
62 * Niraj Kumar <niraj17@iitbombay.org>, Jan 2004
63 *
Evgeniy Dushistovcbcae392007-02-12 00:54:30 -080064 * UFS2 write support added by
65 * Evgeniy Dushistov <dushistov@mail.ru>, 2007
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 */
67
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -080068#include <linux/exportfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#include <linux/module.h>
70#include <linux/bitops.h>
71
72#include <stdarg.h>
73
74#include <asm/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76#include <linux/errno.h>
77#include <linux/fs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#include <linux/slab.h>
79#include <linux/time.h>
80#include <linux/stat.h>
81#include <linux/string.h>
82#include <linux/blkdev.h>
83#include <linux/init.h>
84#include <linux/parser.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#include <linux/buffer_head.h>
86#include <linux/vfs.h>
vignesh babu9e8c4272007-07-15 23:41:36 -070087#include <linux/log2.h>
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -070088#include <linux/mount.h>
89#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Mike Frysingere5420592008-02-08 04:21:31 -080091#include "ufs_fs.h"
Christoph Hellwigbcd6d4e2007-10-16 23:26:51 -070092#include "ufs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#include "swab.h"
94#include "util.h"
95
Arnd Bergmann788257d2011-01-24 10:14:12 +010096void lock_ufs(struct super_block *sb)
97{
98#if defined(CONFIG_SMP) || defined (CONFIG_PREEMPT)
99 struct ufs_sb_info *sbi = UFS_SB(sb);
100
101 mutex_lock(&sbi->mutex);
102 sbi->mutex_owner = current;
103#endif
104}
105
106void unlock_ufs(struct super_block *sb)
107{
108#if defined(CONFIG_SMP) || defined (CONFIG_PREEMPT)
109 struct ufs_sb_info *sbi = UFS_SB(sb);
110
111 sbi->mutex_owner = NULL;
112 mutex_unlock(&sbi->mutex);
113#endif
114}
115
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -0800116static struct inode *ufs_nfs_get_inode(struct super_block *sb, u64 ino, u32 generation)
117{
118 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
119 struct inode *inode;
120
121 if (ino < UFS_ROOTINO || ino > uspi->s_ncg * uspi->s_ipg)
122 return ERR_PTR(-ESTALE);
123
124 inode = ufs_iget(sb, ino);
125 if (IS_ERR(inode))
126 return ERR_CAST(inode);
127 if (generation && inode->i_generation != generation) {
128 iput(inode);
129 return ERR_PTR(-ESTALE);
130 }
131 return inode;
132}
133
134static struct dentry *ufs_fh_to_dentry(struct super_block *sb, struct fid *fid,
135 int fh_len, int fh_type)
136{
137 return generic_fh_to_dentry(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
138}
139
140static struct dentry *ufs_fh_to_parent(struct super_block *sb, struct fid *fid,
141 int fh_len, int fh_type)
142{
143 return generic_fh_to_parent(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
144}
145
146static struct dentry *ufs_get_parent(struct dentry *child)
147{
Linus Torvalds26fe5752012-05-10 13:14:12 -0700148 struct qstr dot_dot = QSTR_INIT("..", 2);
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -0800149 ino_t ino;
150
151 ino = ufs_inode_by_name(child->d_inode, &dot_dot);
152 if (!ino)
153 return ERR_PTR(-ENOENT);
154 return d_obtain_alias(ufs_iget(child->d_inode->i_sb, ino));
155}
156
157static const struct export_operations ufs_export_ops = {
158 .fh_to_dentry = ufs_fh_to_dentry,
159 .fh_to_parent = ufs_fh_to_parent,
160 .get_parent = ufs_get_parent,
161};
162
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700163#ifdef CONFIG_UFS_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164/*
165 * Print contents of ufs_super_block, useful for debugging
166 */
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800167static void ufs_print_super_stuff(struct super_block *sb,
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700168 struct ufs_super_block_first *usb1,
169 struct ufs_super_block_second *usb2,
170 struct ufs_super_block_third *usb3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171{
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800172 u32 magic = fs32_to_cpu(sb, usb3->fs_magic);
173
Fabian Fredericka9814c52014-08-08 14:20:57 -0700174 pr_debug("ufs_print_super_stuff\n");
175 pr_debug(" magic: 0x%x\n", magic);
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800176 if (fs32_to_cpu(sb, usb3->fs_magic) == UFS2_MAGIC) {
Fabian Fredericka9814c52014-08-08 14:20:57 -0700177 pr_debug(" fs_size: %llu\n", (unsigned long long)
178 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size));
179 pr_debug(" fs_dsize: %llu\n", (unsigned long long)
180 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize));
181 pr_debug(" bsize: %u\n",
182 fs32_to_cpu(sb, usb1->fs_bsize));
183 pr_debug(" fsize: %u\n",
184 fs32_to_cpu(sb, usb1->fs_fsize));
185 pr_debug(" fs_volname: %s\n", usb2->fs_un.fs_u2.fs_volname);
186 pr_debug(" fs_sblockloc: %llu\n", (unsigned long long)
187 fs64_to_cpu(sb, usb2->fs_un.fs_u2.fs_sblockloc));
188 pr_debug(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
189 fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir));
190 pr_debug(" cs_nbfree(No of free blocks): %llu\n",
191 (unsigned long long)
192 fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree));
193 pr_info(" cs_nifree(Num of free inodes): %llu\n",
194 (unsigned long long)
195 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree));
196 pr_info(" cs_nffree(Num of free frags): %llu\n",
197 (unsigned long long)
198 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree));
199 pr_info(" fs_maxsymlinklen: %u\n",
200 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen));
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700201 } else {
Fabian Fredericka9814c52014-08-08 14:20:57 -0700202 pr_debug(" sblkno: %u\n", fs32_to_cpu(sb, usb1->fs_sblkno));
203 pr_debug(" cblkno: %u\n", fs32_to_cpu(sb, usb1->fs_cblkno));
204 pr_debug(" iblkno: %u\n", fs32_to_cpu(sb, usb1->fs_iblkno));
205 pr_debug(" dblkno: %u\n", fs32_to_cpu(sb, usb1->fs_dblkno));
206 pr_debug(" cgoffset: %u\n",
207 fs32_to_cpu(sb, usb1->fs_cgoffset));
208 pr_debug(" ~cgmask: 0x%x\n",
209 ~fs32_to_cpu(sb, usb1->fs_cgmask));
210 pr_debug(" size: %u\n", fs32_to_cpu(sb, usb1->fs_size));
211 pr_debug(" dsize: %u\n", fs32_to_cpu(sb, usb1->fs_dsize));
212 pr_debug(" ncg: %u\n", fs32_to_cpu(sb, usb1->fs_ncg));
213 pr_debug(" bsize: %u\n", fs32_to_cpu(sb, usb1->fs_bsize));
214 pr_debug(" fsize: %u\n", fs32_to_cpu(sb, usb1->fs_fsize));
215 pr_debug(" frag: %u\n", fs32_to_cpu(sb, usb1->fs_frag));
216 pr_debug(" fragshift: %u\n",
217 fs32_to_cpu(sb, usb1->fs_fragshift));
218 pr_debug(" ~fmask: %u\n", ~fs32_to_cpu(sb, usb1->fs_fmask));
219 pr_debug(" fshift: %u\n", fs32_to_cpu(sb, usb1->fs_fshift));
220 pr_debug(" sbsize: %u\n", fs32_to_cpu(sb, usb1->fs_sbsize));
221 pr_debug(" spc: %u\n", fs32_to_cpu(sb, usb1->fs_spc));
222 pr_debug(" cpg: %u\n", fs32_to_cpu(sb, usb1->fs_cpg));
223 pr_debug(" ipg: %u\n", fs32_to_cpu(sb, usb1->fs_ipg));
224 pr_debug(" fpg: %u\n", fs32_to_cpu(sb, usb1->fs_fpg));
225 pr_debug(" csaddr: %u\n", fs32_to_cpu(sb, usb1->fs_csaddr));
226 pr_debug(" cssize: %u\n", fs32_to_cpu(sb, usb1->fs_cssize));
227 pr_debug(" cgsize: %u\n", fs32_to_cpu(sb, usb1->fs_cgsize));
228 pr_debug(" fstodb: %u\n",
229 fs32_to_cpu(sb, usb1->fs_fsbtodb));
230 pr_debug(" nrpos: %u\n", fs32_to_cpu(sb, usb3->fs_nrpos));
231 pr_debug(" ndir %u\n",
232 fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir));
233 pr_debug(" nifree %u\n",
234 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree));
235 pr_debug(" nbfree %u\n",
236 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree));
237 pr_debug(" nffree %u\n",
238 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree));
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700239 }
Fabian Fredericka9814c52014-08-08 14:20:57 -0700240 pr_debug("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241}
242
243/*
244 * Print contents of ufs_cylinder_group, useful for debugging
245 */
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700246static void ufs_print_cylinder_stuff(struct super_block *sb,
247 struct ufs_cylinder_group *cg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
Fabian Fredericka9814c52014-08-08 14:20:57 -0700249 pr_debug("\nufs_print_cylinder_stuff\n");
250 pr_debug("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group));
251 pr_debug(" magic: %x\n", fs32_to_cpu(sb, cg->cg_magic));
252 pr_debug(" time: %u\n", fs32_to_cpu(sb, cg->cg_time));
253 pr_debug(" cgx: %u\n", fs32_to_cpu(sb, cg->cg_cgx));
254 pr_debug(" ncyl: %u\n", fs16_to_cpu(sb, cg->cg_ncyl));
255 pr_debug(" niblk: %u\n", fs16_to_cpu(sb, cg->cg_niblk));
256 pr_debug(" ndblk: %u\n", fs32_to_cpu(sb, cg->cg_ndblk));
257 pr_debug(" cs_ndir: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_ndir));
258 pr_debug(" cs_nbfree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nbfree));
259 pr_debug(" cs_nifree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nifree));
260 pr_debug(" cs_nffree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nffree));
261 pr_debug(" rotor: %u\n", fs32_to_cpu(sb, cg->cg_rotor));
262 pr_debug(" frotor: %u\n", fs32_to_cpu(sb, cg->cg_frotor));
263 pr_debug(" irotor: %u\n", fs32_to_cpu(sb, cg->cg_irotor));
264 pr_debug(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 fs32_to_cpu(sb, cg->cg_frsum[0]), fs32_to_cpu(sb, cg->cg_frsum[1]),
266 fs32_to_cpu(sb, cg->cg_frsum[2]), fs32_to_cpu(sb, cg->cg_frsum[3]),
267 fs32_to_cpu(sb, cg->cg_frsum[4]), fs32_to_cpu(sb, cg->cg_frsum[5]),
268 fs32_to_cpu(sb, cg->cg_frsum[6]), fs32_to_cpu(sb, cg->cg_frsum[7]));
Fabian Fredericka9814c52014-08-08 14:20:57 -0700269 pr_debug(" btotoff: %u\n", fs32_to_cpu(sb, cg->cg_btotoff));
270 pr_debug(" boff: %u\n", fs32_to_cpu(sb, cg->cg_boff));
271 pr_debug(" iuseoff: %u\n", fs32_to_cpu(sb, cg->cg_iusedoff));
272 pr_debug(" freeoff: %u\n", fs32_to_cpu(sb, cg->cg_freeoff));
273 pr_debug(" nextfreeoff: %u\n", fs32_to_cpu(sb, cg->cg_nextfreeoff));
274 pr_debug(" clustersumoff %u\n",
275 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clustersumoff));
276 pr_debug(" clusteroff %u\n",
277 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clusteroff));
278 pr_debug(" nclusterblks %u\n",
279 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_nclusterblks));
280 pr_debug("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281}
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700282#else
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800283# define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700284# define ufs_print_cylinder_stuff(sb, cg) /**/
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700285#endif /* CONFIG_UFS_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800287static const struct super_operations ufs_super_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289void ufs_error (struct super_block * sb, const char * function,
290 const char * fmt, ...)
291{
292 struct ufs_sb_private_info * uspi;
293 struct ufs_super_block_first * usb1;
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700294 struct va_format vaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 va_list args;
296
297 uspi = UFS_SB(sb)->s_uspi;
Evgeniy7b4ee732006-01-14 11:42:06 +0300298 usb1 = ubh_get_usb_first(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
300 if (!(sb->s_flags & MS_RDONLY)) {
301 usb1->fs_clean = UFS_FSBAD;
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -0700302 ubh_mark_buffer_dirty(USPI_UBH(uspi));
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300303 ufs_mark_sb_dirty(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 sb->s_flags |= MS_RDONLY;
305 }
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700306 va_start(args, fmt);
307 vaf.fmt = fmt;
308 vaf.va = &args;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 switch (UFS_SB(sb)->s_mount_opt & UFS_MOUNT_ONERROR) {
310 case UFS_MOUNT_ONERROR_PANIC:
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700311 panic("panic (device %s): %s: %pV\n",
312 sb->s_id, function, &vaf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
314 case UFS_MOUNT_ONERROR_LOCK:
315 case UFS_MOUNT_ONERROR_UMOUNT:
316 case UFS_MOUNT_ONERROR_REPAIR:
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700317 pr_crit("error (device %s): %s: %pV\n",
318 sb->s_id, function, &vaf);
319 }
320 va_end(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321}
322
323void ufs_panic (struct super_block * sb, const char * function,
324 const char * fmt, ...)
325{
326 struct ufs_sb_private_info * uspi;
327 struct ufs_super_block_first * usb1;
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700328 struct va_format vaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 va_list args;
330
331 uspi = UFS_SB(sb)->s_uspi;
Evgeniy7b4ee732006-01-14 11:42:06 +0300332 usb1 = ubh_get_usb_first(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 if (!(sb->s_flags & MS_RDONLY)) {
335 usb1->fs_clean = UFS_FSBAD;
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -0700336 ubh_mark_buffer_dirty(USPI_UBH(uspi));
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300337 ufs_mark_sb_dirty(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 }
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700339 va_start(args, fmt);
340 vaf.fmt = fmt;
341 vaf.va = &args;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 sb->s_flags |= MS_RDONLY;
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700343 pr_crit("panic (device %s): %s: %pV\n",
344 sb->s_id, function, &vaf);
345 va_end(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346}
347
348void ufs_warning (struct super_block * sb, const char * function,
349 const char * fmt, ...)
350{
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700351 struct va_format vaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 va_list args;
353
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700354 va_start(args, fmt);
355 vaf.fmt = fmt;
356 vaf.va = &args;
357 pr_warn("(device %s): %s: %pV\n",
358 sb->s_id, function, &vaf);
359 va_end(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360}
361
362enum {
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -0700363 Opt_type_old = UFS_MOUNT_UFSTYPE_OLD,
364 Opt_type_sunx86 = UFS_MOUNT_UFSTYPE_SUNx86,
365 Opt_type_sun = UFS_MOUNT_UFSTYPE_SUN,
366 Opt_type_sunos = UFS_MOUNT_UFSTYPE_SUNOS,
367 Opt_type_44bsd = UFS_MOUNT_UFSTYPE_44BSD,
368 Opt_type_ufs2 = UFS_MOUNT_UFSTYPE_UFS2,
369 Opt_type_hp = UFS_MOUNT_UFSTYPE_HP,
370 Opt_type_nextstepcd = UFS_MOUNT_UFSTYPE_NEXTSTEP_CD,
371 Opt_type_nextstep = UFS_MOUNT_UFSTYPE_NEXTSTEP,
372 Opt_type_openstep = UFS_MOUNT_UFSTYPE_OPENSTEP,
373 Opt_onerror_panic = UFS_MOUNT_ONERROR_PANIC,
374 Opt_onerror_lock = UFS_MOUNT_ONERROR_LOCK,
375 Opt_onerror_umount = UFS_MOUNT_ONERROR_UMOUNT,
376 Opt_onerror_repair = UFS_MOUNT_ONERROR_REPAIR,
377 Opt_err
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378};
379
Steven Whitehousea447c092008-10-13 10:46:57 +0100380static const match_table_t tokens = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 {Opt_type_old, "ufstype=old"},
382 {Opt_type_sunx86, "ufstype=sunx86"},
383 {Opt_type_sun, "ufstype=sun"},
Mark Fortescue252e2112007-10-16 23:26:31 -0700384 {Opt_type_sunos, "ufstype=sunos"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 {Opt_type_44bsd, "ufstype=44bsd"},
386 {Opt_type_ufs2, "ufstype=ufs2"},
387 {Opt_type_ufs2, "ufstype=5xbsd"},
388 {Opt_type_hp, "ufstype=hp"},
389 {Opt_type_nextstepcd, "ufstype=nextstep-cd"},
390 {Opt_type_nextstep, "ufstype=nextstep"},
391 {Opt_type_openstep, "ufstype=openstep"},
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -0700392/*end of possible ufs types */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 {Opt_onerror_panic, "onerror=panic"},
394 {Opt_onerror_lock, "onerror=lock"},
395 {Opt_onerror_umount, "onerror=umount"},
396 {Opt_onerror_repair, "onerror=repair"},
397 {Opt_err, NULL}
398};
399
400static int ufs_parse_options (char * options, unsigned * mount_options)
401{
402 char * p;
403
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700404 UFSD("ENTER\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406 if (!options)
407 return 1;
408
409 while ((p = strsep(&options, ",")) != NULL) {
410 substring_t args[MAX_OPT_ARGS];
411 int token;
412 if (!*p)
413 continue;
414
415 token = match_token(p, tokens, args);
416 switch (token) {
417 case Opt_type_old:
418 ufs_clear_opt (*mount_options, UFSTYPE);
419 ufs_set_opt (*mount_options, UFSTYPE_OLD);
420 break;
421 case Opt_type_sunx86:
422 ufs_clear_opt (*mount_options, UFSTYPE);
423 ufs_set_opt (*mount_options, UFSTYPE_SUNx86);
424 break;
425 case Opt_type_sun:
426 ufs_clear_opt (*mount_options, UFSTYPE);
427 ufs_set_opt (*mount_options, UFSTYPE_SUN);
428 break;
Mark Fortescue252e2112007-10-16 23:26:31 -0700429 case Opt_type_sunos:
430 ufs_clear_opt(*mount_options, UFSTYPE);
431 ufs_set_opt(*mount_options, UFSTYPE_SUNOS);
432 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 case Opt_type_44bsd:
434 ufs_clear_opt (*mount_options, UFSTYPE);
435 ufs_set_opt (*mount_options, UFSTYPE_44BSD);
436 break;
437 case Opt_type_ufs2:
438 ufs_clear_opt(*mount_options, UFSTYPE);
439 ufs_set_opt(*mount_options, UFSTYPE_UFS2);
440 break;
441 case Opt_type_hp:
442 ufs_clear_opt (*mount_options, UFSTYPE);
443 ufs_set_opt (*mount_options, UFSTYPE_HP);
444 break;
445 case Opt_type_nextstepcd:
446 ufs_clear_opt (*mount_options, UFSTYPE);
447 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP_CD);
448 break;
449 case Opt_type_nextstep:
450 ufs_clear_opt (*mount_options, UFSTYPE);
451 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP);
452 break;
453 case Opt_type_openstep:
454 ufs_clear_opt (*mount_options, UFSTYPE);
455 ufs_set_opt (*mount_options, UFSTYPE_OPENSTEP);
456 break;
457 case Opt_onerror_panic:
458 ufs_clear_opt (*mount_options, ONERROR);
459 ufs_set_opt (*mount_options, ONERROR_PANIC);
460 break;
461 case Opt_onerror_lock:
462 ufs_clear_opt (*mount_options, ONERROR);
463 ufs_set_opt (*mount_options, ONERROR_LOCK);
464 break;
465 case Opt_onerror_umount:
466 ufs_clear_opt (*mount_options, ONERROR);
467 ufs_set_opt (*mount_options, ONERROR_UMOUNT);
468 break;
469 case Opt_onerror_repair:
Fabian Frederickde771bd2014-08-08 14:20:59 -0700470 pr_err("Unable to do repair on error, will lock lock instead\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 ufs_clear_opt (*mount_options, ONERROR);
472 ufs_set_opt (*mount_options, ONERROR_REPAIR);
473 break;
474 default:
Fabian Frederickde771bd2014-08-08 14:20:59 -0700475 pr_err("Invalid option: \"%s\" or missing value\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return 0;
477 }
478 }
479 return 1;
480}
481
482/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300483 * Different types of UFS hold fs_cstotal in different
484 * places, and use different data structure for it.
485 * To make things simpler we just copy fs_cstotal to ufs_sb_private_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 */
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700487static void ufs_setup_cstotal(struct super_block *sb)
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800488{
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700489 struct ufs_sb_info *sbi = UFS_SB(sb);
490 struct ufs_sb_private_info *uspi = sbi->s_uspi;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700491 struct ufs_super_block_first *usb1;
492 struct ufs_super_block_second *usb2;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700493 struct ufs_super_block_third *usb3;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700494 unsigned mtype = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
495
496 UFSD("ENTER, mtype=%u\n", mtype);
497 usb1 = ubh_get_usb_first(uspi);
498 usb2 = ubh_get_usb_second(uspi);
499 usb3 = ubh_get_usb_third(uspi);
500
501 if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
502 (usb1->fs_flags & UFS_FLAGS_UPDATED)) ||
503 mtype == UFS_MOUNT_UFSTYPE_UFS2) {
504 /*we have statistic in different place, then usual*/
505 uspi->cs_total.cs_ndir = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir);
506 uspi->cs_total.cs_nbfree = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree);
507 uspi->cs_total.cs_nifree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree);
508 uspi->cs_total.cs_nffree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree);
509 } else {
510 uspi->cs_total.cs_ndir = fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir);
511 uspi->cs_total.cs_nbfree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree);
512 uspi->cs_total.cs_nifree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree);
513 uspi->cs_total.cs_nffree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree);
514 }
515 UFSD("EXIT\n");
516}
517
518/*
519 * Read on-disk structures associated with cylinder groups
520 */
521static int ufs_read_cylinder_structures(struct super_block *sb)
522{
523 struct ufs_sb_info *sbi = UFS_SB(sb);
524 struct ufs_sb_private_info *uspi = sbi->s_uspi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 struct ufs_buffer_head * ubh;
526 unsigned char * base, * space;
527 unsigned size, blks, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700529 UFSD("ENTER\n");
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 /*
532 * Read cs structures from (usually) first data block
533 * on the device.
534 */
535 size = uspi->s_cssize;
536 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
Arnd Bergmann788257d2011-01-24 10:14:12 +0100537 base = space = kmalloc(size, GFP_NOFS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 if (!base)
539 goto failed;
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800540 sbi->s_csp = (struct ufs_csum *)space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 for (i = 0; i < blks; i += uspi->s_fpb) {
542 size = uspi->s_bsize;
543 if (i + uspi->s_fpb > blks)
544 size = (blks - i) * uspi->s_fsize;
545
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800546 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
Evgeniy7b4ee732006-01-14 11:42:06 +0300547
548 if (!ubh)
549 goto failed;
550
551 ubh_ubhcpymem (space, ubh, size);
Evgeniy7b4ee732006-01-14 11:42:06 +0300552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 space += size;
554 ubh_brelse (ubh);
555 ubh = NULL;
556 }
557
558 /*
559 * Read cylinder group (we read only first fragment from block
560 * at this time) and prepare internal data structures for cg caching.
561 */
Arnd Bergmann788257d2011-01-24 10:14:12 +0100562 if (!(sbi->s_ucg = kmalloc (sizeof(struct buffer_head *) * uspi->s_ncg, GFP_NOFS)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 goto failed;
564 for (i = 0; i < uspi->s_ncg; i++)
565 sbi->s_ucg[i] = NULL;
566 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
567 sbi->s_ucpi[i] = NULL;
568 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
569 }
570 for (i = 0; i < uspi->s_ncg; i++) {
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700571 UFSD("read cg %u\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 if (!(sbi->s_ucg[i] = sb_bread(sb, ufs_cgcmin(i))))
573 goto failed;
574 if (!ufs_cg_chkmagic (sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data))
575 goto failed;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 ufs_print_cylinder_stuff(sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 }
579 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
Arnd Bergmann788257d2011-01-24 10:14:12 +0100580 if (!(sbi->s_ucpi[i] = kmalloc (sizeof(struct ufs_cg_private_info), GFP_NOFS)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 goto failed;
582 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
583 }
584 sbi->s_cg_loaded = 0;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700585 UFSD("EXIT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 return 1;
587
588failed:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800589 kfree (base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 if (sbi->s_ucg) {
591 for (i = 0; i < uspi->s_ncg; i++)
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800592 if (sbi->s_ucg[i])
593 brelse (sbi->s_ucg[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 kfree (sbi->s_ucg);
595 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800596 kfree (sbi->s_ucpi[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 }
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700598 UFSD("EXIT (FAILED)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 return 0;
600}
601
602/*
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700603 * Sync our internal copy of fs_cstotal with disk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 */
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700605static void ufs_put_cstotal(struct super_block *sb)
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800606{
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700607 unsigned mtype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
608 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
609 struct ufs_super_block_first *usb1;
610 struct ufs_super_block_second *usb2;
611 struct ufs_super_block_third *usb3;
612
613 UFSD("ENTER\n");
614 usb1 = ubh_get_usb_first(uspi);
615 usb2 = ubh_get_usb_second(uspi);
616 usb3 = ubh_get_usb_third(uspi);
617
618 if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
619 (usb1->fs_flags & UFS_FLAGS_UPDATED)) ||
620 mtype == UFS_MOUNT_UFSTYPE_UFS2) {
621 /*we have statistic in different place, then usual*/
622 usb2->fs_un.fs_u2.cs_ndir =
623 cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
624 usb2->fs_un.fs_u2.cs_nbfree =
625 cpu_to_fs64(sb, uspi->cs_total.cs_nbfree);
626 usb3->fs_un1.fs_u2.cs_nifree =
627 cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
628 usb3->fs_un1.fs_u2.cs_nffree =
629 cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
630 } else {
631 usb1->fs_cstotal.cs_ndir =
632 cpu_to_fs32(sb, uspi->cs_total.cs_ndir);
633 usb1->fs_cstotal.cs_nbfree =
634 cpu_to_fs32(sb, uspi->cs_total.cs_nbfree);
635 usb1->fs_cstotal.cs_nifree =
636 cpu_to_fs32(sb, uspi->cs_total.cs_nifree);
637 usb1->fs_cstotal.cs_nffree =
638 cpu_to_fs32(sb, uspi->cs_total.cs_nffree);
639 }
640 ubh_mark_buffer_dirty(USPI_UBH(uspi));
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800641 ufs_print_super_stuff(sb, usb1, usb2, usb3);
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700642 UFSD("EXIT\n");
643}
644
645/**
646 * ufs_put_super_internal() - put on-disk intrenal structures
647 * @sb: pointer to super_block structure
648 * Put on-disk structures associated with cylinder groups
649 * and write them back to disk, also update cs_total on disk
650 */
651static void ufs_put_super_internal(struct super_block *sb)
652{
653 struct ufs_sb_info *sbi = UFS_SB(sb);
654 struct ufs_sb_private_info *uspi = sbi->s_uspi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 struct ufs_buffer_head * ubh;
656 unsigned char * base, * space;
657 unsigned blks, size, i;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700658
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700660 UFSD("ENTER\n");
Christoph Hellwig6cfd0142009-05-05 15:40:36 +0200661
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700662 ufs_put_cstotal(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 size = uspi->s_cssize;
664 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800665 base = space = (char*) sbi->s_csp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 for (i = 0; i < blks; i += uspi->s_fpb) {
667 size = uspi->s_bsize;
668 if (i + uspi->s_fpb > blks)
669 size = (blks - i) * uspi->s_fsize;
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800670
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 ubh_memcpyubh (ubh, space, size);
674 space += size;
675 ubh_mark_buffer_uptodate (ubh, 1);
676 ubh_mark_buffer_dirty (ubh);
677 ubh_brelse (ubh);
678 }
679 for (i = 0; i < sbi->s_cg_loaded; i++) {
680 ufs_put_cylinder (sb, i);
681 kfree (sbi->s_ucpi[i]);
682 }
683 for (; i < UFS_MAX_GROUP_LOADED; i++)
684 kfree (sbi->s_ucpi[i]);
685 for (i = 0; i < uspi->s_ncg; i++)
686 brelse (sbi->s_ucg[i]);
687 kfree (sbi->s_ucg);
688 kfree (base);
Christoph Hellwig6cfd0142009-05-05 15:40:36 +0200689
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700690 UFSD("EXIT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691}
692
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300693static int ufs_sync_fs(struct super_block *sb, int wait)
694{
695 struct ufs_sb_private_info * uspi;
696 struct ufs_super_block_first * usb1;
697 struct ufs_super_block_third * usb3;
698 unsigned flags;
699
700 lock_ufs(sb);
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300701
702 UFSD("ENTER\n");
703
704 flags = UFS_SB(sb)->s_flags;
705 uspi = UFS_SB(sb)->s_uspi;
706 usb1 = ubh_get_usb_first(uspi);
707 usb3 = ubh_get_usb_third(uspi);
708
709 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
710 if ((flags & UFS_ST_MASK) == UFS_ST_SUN ||
711 (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
712 (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
713 ufs_set_fs_state(sb, usb1, usb3,
714 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
715 ufs_put_cstotal(sb);
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300716
717 UFSD("EXIT\n");
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300718 unlock_ufs(sb);
719
720 return 0;
721}
722
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300723static void delayed_sync_fs(struct work_struct *work)
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300724{
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300725 struct ufs_sb_info *sbi;
726
727 sbi = container_of(work, struct ufs_sb_info, sync_work.work);
728
729 spin_lock(&sbi->work_lock);
730 sbi->work_queued = 0;
731 spin_unlock(&sbi->work_lock);
732
733 ufs_sync_fs(sbi->sb, 1);
734}
735
736void ufs_mark_sb_dirty(struct super_block *sb)
737{
738 struct ufs_sb_info *sbi = UFS_SB(sb);
739 unsigned long delay;
740
741 spin_lock(&sbi->work_lock);
742 if (!sbi->work_queued) {
743 delay = msecs_to_jiffies(dirty_writeback_interval * 10);
744 queue_delayed_work(system_long_wq, &sbi->sync_work, delay);
745 sbi->work_queued = 1;
746 }
747 spin_unlock(&sbi->work_lock);
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300748}
749
750static void ufs_put_super(struct super_block *sb)
751{
752 struct ufs_sb_info * sbi = UFS_SB(sb);
753
754 UFSD("ENTER\n");
755
756 if (!(sb->s_flags & MS_RDONLY))
757 ufs_put_super_internal(sb);
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300758 cancel_delayed_work_sync(&sbi->sync_work);
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300759
760 ubh_brelse_uspi (sbi->s_uspi);
761 kfree (sbi->s_uspi);
Fabian Frederick02447562014-06-06 14:38:34 -0700762 mutex_destroy(&sbi->mutex);
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300763 kfree (sbi);
764 sb->s_fs_info = NULL;
765 UFSD("EXIT\n");
766 return;
767}
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769static int ufs_fill_super(struct super_block *sb, void *data, int silent)
770{
771 struct ufs_sb_info * sbi;
772 struct ufs_sb_private_info * uspi;
773 struct ufs_super_block_first * usb1;
774 struct ufs_super_block_second * usb2;
775 struct ufs_super_block_third * usb3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 struct ufs_buffer_head * ubh;
777 struct inode *inode;
778 unsigned block_size, super_block_size;
779 unsigned flags;
Evgeniy7b4ee732006-01-14 11:42:06 +0300780 unsigned super_block_offset;
Duane Griffin9e6766c2009-01-08 22:43:48 +0000781 unsigned maxsymlen;
David Howellsb55c4602008-02-07 00:15:48 -0800782 int ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
784 uspi = NULL;
785 ubh = NULL;
786 flags = 0;
787
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700788 UFSD("ENTER\n");
Fabian Frederick02447562014-06-06 14:38:34 -0700789
790#ifndef CONFIG_UFS_FS_WRITE
791 if (!(sb->s_flags & MS_RDONLY)) {
Fabian Fredericka9814c52014-08-08 14:20:57 -0700792 pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
Fabian Frederick02447562014-06-06 14:38:34 -0700793 return -EROFS;
794 }
795#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
Panagiotis Issarisf8314dc2006-09-27 01:49:37 -0700797 sbi = kzalloc(sizeof(struct ufs_sb_info), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 if (!sbi)
799 goto failed_nomem;
800 sb->s_fs_info = sbi;
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300801 sbi->sb = sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700803 UFSD("flag %u\n", (int)(sb->s_flags & MS_RDONLY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
Arnd Bergmann788257d2011-01-24 10:14:12 +0100805 mutex_init(&sbi->mutex);
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300806 spin_lock_init(&sbi->work_lock);
807 INIT_DELAYED_WORK(&sbi->sync_work, delayed_sync_fs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 /*
809 * Set default mount options
810 * Parse mount options
811 */
812 sbi->s_mount_opt = 0;
813 ufs_set_opt (sbi->s_mount_opt, ONERROR_LOCK);
814 if (!ufs_parse_options ((char *) data, &sbi->s_mount_opt)) {
Fabian Fredericka9814c52014-08-08 14:20:57 -0700815 pr_err("wrong mount options\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 goto failed;
817 }
818 if (!(sbi->s_mount_opt & UFS_MOUNT_UFSTYPE)) {
819 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700820 pr_err("You didn't specify the type of your ufs filesystem\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 "mount -t ufs -o ufstype="
Michael Owenc690a722006-03-24 18:21:44 +0100822 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
824 "default is ufstype=old\n");
825 ufs_set_opt (sbi->s_mount_opt, UFSTYPE_OLD);
826 }
827
Mark Fortescue252e2112007-10-16 23:26:31 -0700828 uspi = kzalloc(sizeof(struct ufs_sb_private_info), GFP_KERNEL);
829 sbi->s_uspi = uspi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 if (!uspi)
831 goto failed;
Evgeniy Dushistovf3369532007-02-08 14:20:25 -0800832 uspi->s_dirblksize = UFS_SECTOR_SIZE;
Evgeniy7b4ee732006-01-14 11:42:06 +0300833 super_block_offset=UFS_SBLOCK;
834
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 /* Keep 2Gig file limit. Some UFS variants need to override
836 this but as I don't know which I'll let those in the know loosen
837 the rules */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 switch (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) {
839 case UFS_MOUNT_UFSTYPE_44BSD:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700840 UFSD("ufstype=44bsd\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 uspi->s_fsize = block_size = 512;
842 uspi->s_fmask = ~(512 - 1);
843 uspi->s_fshift = 9;
844 uspi->s_sbsize = super_block_size = 1536;
845 uspi->s_sbbase = 0;
846 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
847 break;
848 case UFS_MOUNT_UFSTYPE_UFS2:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700849 UFSD("ufstype=ufs2\n");
Evgeniy7b4ee732006-01-14 11:42:06 +0300850 super_block_offset=SBLOCK_UFS2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 uspi->s_fsize = block_size = 512;
852 uspi->s_fmask = ~(512 - 1);
853 uspi->s_fshift = 9;
854 uspi->s_sbsize = super_block_size = 1536;
855 uspi->s_sbbase = 0;
856 flags |= UFS_TYPE_UFS2 | UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 break;
858
859 case UFS_MOUNT_UFSTYPE_SUN:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700860 UFSD("ufstype=sun\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 uspi->s_fsize = block_size = 1024;
862 uspi->s_fmask = ~(1024 - 1);
863 uspi->s_fshift = 10;
864 uspi->s_sbsize = super_block_size = 2048;
865 uspi->s_sbbase = 0;
Mark Fortescue252e2112007-10-16 23:26:31 -0700866 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUN | UFS_CG_SUN;
868 break;
869
Mark Fortescue252e2112007-10-16 23:26:31 -0700870 case UFS_MOUNT_UFSTYPE_SUNOS:
Fabian Frederickd4beaab2014-08-08 14:21:05 -0700871 UFSD("ufstype=sunos\n");
Mark Fortescue252e2112007-10-16 23:26:31 -0700872 uspi->s_fsize = block_size = 1024;
873 uspi->s_fmask = ~(1024 - 1);
874 uspi->s_fshift = 10;
875 uspi->s_sbsize = 2048;
876 super_block_size = 2048;
877 uspi->s_sbbase = 0;
878 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
879 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_SUNOS | UFS_CG_SUN;
880 break;
881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 case UFS_MOUNT_UFSTYPE_SUNx86:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700883 UFSD("ufstype=sunx86\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 uspi->s_fsize = block_size = 1024;
885 uspi->s_fmask = ~(1024 - 1);
886 uspi->s_fshift = 10;
887 uspi->s_sbsize = super_block_size = 2048;
888 uspi->s_sbbase = 0;
Mark Fortescue252e2112007-10-16 23:26:31 -0700889 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUNx86 | UFS_CG_SUN;
891 break;
892
893 case UFS_MOUNT_UFSTYPE_OLD:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700894 UFSD("ufstype=old\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 uspi->s_fsize = block_size = 1024;
896 uspi->s_fmask = ~(1024 - 1);
897 uspi->s_fshift = 10;
898 uspi->s_sbsize = super_block_size = 2048;
899 uspi->s_sbbase = 0;
900 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
901 if (!(sb->s_flags & MS_RDONLY)) {
902 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700903 pr_info("ufstype=old is supported read-only\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 sb->s_flags |= MS_RDONLY;
905 }
906 break;
907
908 case UFS_MOUNT_UFSTYPE_NEXTSTEP:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700909 UFSD("ufstype=nextstep\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 uspi->s_fsize = block_size = 1024;
911 uspi->s_fmask = ~(1024 - 1);
912 uspi->s_fshift = 10;
913 uspi->s_sbsize = super_block_size = 2048;
914 uspi->s_sbbase = 0;
Evgeniy Dushistov0c664f92007-12-04 23:45:06 -0800915 uspi->s_dirblksize = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
917 if (!(sb->s_flags & MS_RDONLY)) {
918 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700919 pr_info("ufstype=nextstep is supported read-only\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 sb->s_flags |= MS_RDONLY;
921 }
922 break;
923
924 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700925 UFSD("ufstype=nextstep-cd\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 uspi->s_fsize = block_size = 2048;
927 uspi->s_fmask = ~(2048 - 1);
928 uspi->s_fshift = 11;
929 uspi->s_sbsize = super_block_size = 2048;
930 uspi->s_sbbase = 0;
Evgeniy Dushistov0c664f92007-12-04 23:45:06 -0800931 uspi->s_dirblksize = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
933 if (!(sb->s_flags & MS_RDONLY)) {
934 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700935 pr_info("ufstype=nextstep-cd is supported read-only\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 sb->s_flags |= MS_RDONLY;
937 }
938 break;
939
940 case UFS_MOUNT_UFSTYPE_OPENSTEP:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700941 UFSD("ufstype=openstep\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942 uspi->s_fsize = block_size = 1024;
943 uspi->s_fmask = ~(1024 - 1);
944 uspi->s_fshift = 10;
945 uspi->s_sbsize = super_block_size = 2048;
946 uspi->s_sbbase = 0;
Evgeniy Dushistovf3369532007-02-08 14:20:25 -0800947 uspi->s_dirblksize = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
949 if (!(sb->s_flags & MS_RDONLY)) {
950 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700951 pr_info("ufstype=openstep is supported read-only\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 sb->s_flags |= MS_RDONLY;
953 }
954 break;
955
956 case UFS_MOUNT_UFSTYPE_HP:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700957 UFSD("ufstype=hp\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 uspi->s_fsize = block_size = 1024;
959 uspi->s_fmask = ~(1024 - 1);
960 uspi->s_fshift = 10;
961 uspi->s_sbsize = super_block_size = 2048;
962 uspi->s_sbbase = 0;
963 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
964 if (!(sb->s_flags & MS_RDONLY)) {
965 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700966 pr_info("ufstype=hp is supported read-only\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 sb->s_flags |= MS_RDONLY;
968 }
969 break;
970 default:
971 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700972 pr_err("unknown ufstype\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 goto failed;
974 }
975
976again:
977 if (!sb_set_blocksize(sb, block_size)) {
Fabian Frederickde771bd2014-08-08 14:20:59 -0700978 pr_err("failed to set blocksize\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 goto failed;
980 }
981
982 /*
983 * read ufs super block from device
984 */
Evgeniy7b4ee732006-01-14 11:42:06 +0300985
986 ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + super_block_offset/block_size, super_block_size);
987
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 if (!ubh)
989 goto failed;
990
Evgeniy7b4ee732006-01-14 11:42:06 +0300991 usb1 = ubh_get_usb_first(uspi);
992 usb2 = ubh_get_usb_second(uspi);
993 usb3 = ubh_get_usb_third(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Mark Fortescue252e2112007-10-16 23:26:31 -0700995 /* Sort out mod used on SunOS 4.1.3 for fs_state */
996 uspi->s_postblformat = fs32_to_cpu(sb, usb3->fs_postblformat);
997 if (((flags & UFS_ST_MASK) == UFS_ST_SUNOS) &&
998 (uspi->s_postblformat != UFS_42POSTBLFMT)) {
999 flags &= ~UFS_ST_MASK;
1000 flags |= UFS_ST_SUN;
1001 }
1002
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 /*
1004 * Check ufs magic number
1005 */
1006 sbi->s_bytesex = BYTESEX_LE;
1007 switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
1008 case UFS_MAGIC:
Thomas Stewartd27d7a92010-05-26 14:42:33 -07001009 case UFS_MAGIC_BW:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 case UFS2_MAGIC:
1011 case UFS_MAGIC_LFN:
1012 case UFS_MAGIC_FEA:
1013 case UFS_MAGIC_4GB:
1014 goto magic_found;
1015 }
1016 sbi->s_bytesex = BYTESEX_BE;
1017 switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
1018 case UFS_MAGIC:
Thomas Stewartd27d7a92010-05-26 14:42:33 -07001019 case UFS_MAGIC_BW:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 case UFS2_MAGIC:
1021 case UFS_MAGIC_LFN:
1022 case UFS_MAGIC_FEA:
1023 case UFS_MAGIC_4GB:
1024 goto magic_found;
1025 }
1026
1027 if ((((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP)
1028 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD)
1029 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_OPENSTEP))
1030 && uspi->s_sbbase < 256) {
1031 ubh_brelse_uspi(uspi);
1032 ubh = NULL;
1033 uspi->s_sbbase += 8;
1034 goto again;
1035 }
1036 if (!silent)
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001037 pr_err("%s(): bad magic number\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 goto failed;
1039
1040magic_found:
1041 /*
1042 * Check block and fragment sizes
1043 */
1044 uspi->s_bsize = fs32_to_cpu(sb, usb1->fs_bsize);
1045 uspi->s_fsize = fs32_to_cpu(sb, usb1->fs_fsize);
1046 uspi->s_sbsize = fs32_to_cpu(sb, usb1->fs_sbsize);
1047 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
1048 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
1049
vignesh babu9e8c4272007-07-15 23:41:36 -07001050 if (!is_power_of_2(uspi->s_fsize)) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001051 pr_err("%s(): fragment size %u is not a power of 2\n",
1052 __func__, uspi->s_fsize);
Fabian Fredericka9814c52014-08-08 14:20:57 -07001053 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 }
1055 if (uspi->s_fsize < 512) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001056 pr_err("%s(): fragment size %u is too small\n",
1057 __func__, uspi->s_fsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 goto failed;
1059 }
1060 if (uspi->s_fsize > 4096) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001061 pr_err("%s(): fragment size %u is too large\n",
1062 __func__, uspi->s_fsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 goto failed;
1064 }
vignesh babu9e8c4272007-07-15 23:41:36 -07001065 if (!is_power_of_2(uspi->s_bsize)) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001066 pr_err("%s(): block size %u is not a power of 2\n",
1067 __func__, uspi->s_bsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 goto failed;
1069 }
1070 if (uspi->s_bsize < 4096) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001071 pr_err("%s(): block size %u is too small\n",
1072 __func__, uspi->s_bsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 goto failed;
1074 }
1075 if (uspi->s_bsize / uspi->s_fsize > 8) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001076 pr_err("%s(): too many fragments per block (%u)\n",
1077 __func__, uspi->s_bsize / uspi->s_fsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 goto failed;
1079 }
1080 if (uspi->s_fsize != block_size || uspi->s_sbsize != super_block_size) {
1081 ubh_brelse_uspi(uspi);
1082 ubh = NULL;
1083 block_size = uspi->s_fsize;
1084 super_block_size = uspi->s_sbsize;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001085 UFSD("another value of block_size or super_block_size %u, %u\n", block_size, super_block_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 goto again;
1087 }
1088
Andrew Mortonf664f1f2007-10-29 14:37:21 -07001089 sbi->s_flags = flags;/*after that line some functions use s_flags*/
Evgeniy Dushistov3313e292007-02-12 00:54:31 -08001090 ufs_print_super_stuff(sb, usb1, usb2, usb3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092 /*
1093 * Check, if file system was correctly unmounted.
1094 * If not, make it read only.
1095 */
Andrew Mortonf664f1f2007-10-29 14:37:21 -07001096 if (((flags & UFS_ST_MASK) == UFS_ST_44BSD) ||
1097 ((flags & UFS_ST_MASK) == UFS_ST_OLD) ||
1098 (((flags & UFS_ST_MASK) == UFS_ST_SUN ||
1099 (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
1100 (flags & UFS_ST_MASK) == UFS_ST_SUNx86) &&
1101 (ufs_get_fs_state(sb, usb1, usb3) == (UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time))))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 switch(usb1->fs_clean) {
1103 case UFS_FSCLEAN:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001104 UFSD("fs is clean\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 break;
1106 case UFS_FSSTABLE:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001107 UFSD("fs is stable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 break;
Alex Viskovatoffb3a0fd42010-03-10 15:21:53 -08001109 case UFS_FSLOG:
1110 UFSD("fs is logging fs\n");
1111 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 case UFS_FSOSF1:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001113 UFSD("fs is DEC OSF/1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 break;
1115 case UFS_FSACTIVE:
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001116 pr_err("%s(): fs is active\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 sb->s_flags |= MS_RDONLY;
1118 break;
1119 case UFS_FSBAD:
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001120 pr_err("%s(): fs is bad\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 sb->s_flags |= MS_RDONLY;
1122 break;
1123 default:
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001124 pr_err("%s(): can't grok fs_clean 0x%x\n",
1125 __func__, usb1->fs_clean);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 sb->s_flags |= MS_RDONLY;
1127 break;
1128 }
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001129 } else {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001130 pr_err("%s(): fs needs fsck\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 sb->s_flags |= MS_RDONLY;
1132 }
1133
1134 /*
1135 * Read ufs_super_block into internal data structures
1136 */
1137 sb->s_op = &ufs_super_ops;
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -08001138 sb->s_export_op = &ufs_export_ops;
Christoph Hellwig123e9ca2010-05-19 07:16:44 -04001139
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 sb->s_magic = fs32_to_cpu(sb, usb3->fs_magic);
1141
1142 uspi->s_sblkno = fs32_to_cpu(sb, usb1->fs_sblkno);
1143 uspi->s_cblkno = fs32_to_cpu(sb, usb1->fs_cblkno);
1144 uspi->s_iblkno = fs32_to_cpu(sb, usb1->fs_iblkno);
1145 uspi->s_dblkno = fs32_to_cpu(sb, usb1->fs_dblkno);
1146 uspi->s_cgoffset = fs32_to_cpu(sb, usb1->fs_cgoffset);
1147 uspi->s_cgmask = fs32_to_cpu(sb, usb1->fs_cgmask);
1148
1149 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001150 uspi->s_u2_size = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size);
1151 uspi->s_u2_dsize = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize);
1152 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 uspi->s_size = fs32_to_cpu(sb, usb1->fs_size);
1154 uspi->s_dsize = fs32_to_cpu(sb, usb1->fs_dsize);
1155 }
1156
1157 uspi->s_ncg = fs32_to_cpu(sb, usb1->fs_ncg);
1158 /* s_bsize already set */
1159 /* s_fsize already set */
1160 uspi->s_fpb = fs32_to_cpu(sb, usb1->fs_frag);
1161 uspi->s_minfree = fs32_to_cpu(sb, usb1->fs_minfree);
1162 uspi->s_bmask = fs32_to_cpu(sb, usb1->fs_bmask);
1163 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
1164 uspi->s_bshift = fs32_to_cpu(sb, usb1->fs_bshift);
1165 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001166 UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi->s_bshift,
1167 uspi->s_fshift);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 uspi->s_fpbshift = fs32_to_cpu(sb, usb1->fs_fragshift);
1169 uspi->s_fsbtodb = fs32_to_cpu(sb, usb1->fs_fsbtodb);
1170 /* s_sbsize already set */
1171 uspi->s_csmask = fs32_to_cpu(sb, usb1->fs_csmask);
1172 uspi->s_csshift = fs32_to_cpu(sb, usb1->fs_csshift);
1173 uspi->s_nindir = fs32_to_cpu(sb, usb1->fs_nindir);
1174 uspi->s_inopb = fs32_to_cpu(sb, usb1->fs_inopb);
1175 uspi->s_nspf = fs32_to_cpu(sb, usb1->fs_nspf);
1176 uspi->s_npsect = ufs_get_fs_npsect(sb, usb1, usb3);
1177 uspi->s_interleave = fs32_to_cpu(sb, usb1->fs_interleave);
1178 uspi->s_trackskew = fs32_to_cpu(sb, usb1->fs_trackskew);
Evgeniy Dushistov3313e292007-02-12 00:54:31 -08001179
1180 if (uspi->fs_magic == UFS2_MAGIC)
1181 uspi->s_csaddr = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_csaddr);
1182 else
1183 uspi->s_csaddr = fs32_to_cpu(sb, usb1->fs_csaddr);
1184
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 uspi->s_cssize = fs32_to_cpu(sb, usb1->fs_cssize);
1186 uspi->s_cgsize = fs32_to_cpu(sb, usb1->fs_cgsize);
1187 uspi->s_ntrak = fs32_to_cpu(sb, usb1->fs_ntrak);
1188 uspi->s_nsect = fs32_to_cpu(sb, usb1->fs_nsect);
1189 uspi->s_spc = fs32_to_cpu(sb, usb1->fs_spc);
1190 uspi->s_ipg = fs32_to_cpu(sb, usb1->fs_ipg);
1191 uspi->s_fpg = fs32_to_cpu(sb, usb1->fs_fpg);
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001192 uspi->s_cpc = fs32_to_cpu(sb, usb2->fs_un.fs_u1.fs_cpc);
1193 uspi->s_contigsumsize = fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_contigsumsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 uspi->s_qbmask = ufs_get_fs_qbmask(sb, usb3);
1195 uspi->s_qfmask = ufs_get_fs_qfmask(sb, usb3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 uspi->s_nrpos = fs32_to_cpu(sb, usb3->fs_nrpos);
1197 uspi->s_postbloff = fs32_to_cpu(sb, usb3->fs_postbloff);
1198 uspi->s_rotbloff = fs32_to_cpu(sb, usb3->fs_rotbloff);
1199
1200 /*
1201 * Compute another frequently used values
1202 */
1203 uspi->s_fpbmask = uspi->s_fpb - 1;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001204 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 uspi->s_apbshift = uspi->s_bshift - 3;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001206 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 uspi->s_apbshift = uspi->s_bshift - 2;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001208
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 uspi->s_2apbshift = uspi->s_apbshift * 2;
1210 uspi->s_3apbshift = uspi->s_apbshift * 3;
1211 uspi->s_apb = 1 << uspi->s_apbshift;
1212 uspi->s_2apb = 1 << uspi->s_2apbshift;
1213 uspi->s_3apb = 1 << uspi->s_3apbshift;
1214 uspi->s_apbmask = uspi->s_apb - 1;
1215 uspi->s_nspfshift = uspi->s_fshift - UFS_SECTOR_BITS;
1216 uspi->s_nspb = uspi->s_nspf << uspi->s_fpbshift;
1217 uspi->s_inopf = uspi->s_inopb >> uspi->s_fpbshift;
1218 uspi->s_bpf = uspi->s_fsize << 3;
1219 uspi->s_bpfshift = uspi->s_fshift + 3;
1220 uspi->s_bpfmask = uspi->s_bpf - 1;
Evgeniy Dushistov90b315a2008-02-08 04:20:16 -08001221 if ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_44BSD ||
1222 (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_UFS2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 uspi->s_maxsymlinklen =
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001224 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
Duane Griffin9e6766c2009-01-08 22:43:48 +00001226 if (uspi->fs_magic == UFS2_MAGIC)
1227 maxsymlen = 2 * 4 * (UFS_NDADDR + UFS_NINDIR);
1228 else
1229 maxsymlen = 4 * (UFS_NDADDR + UFS_NINDIR);
1230 if (uspi->s_maxsymlinklen > maxsymlen) {
1231 ufs_warning(sb, __func__, "ufs_read_super: excessive maximum "
1232 "fast symlink size (%u)\n", uspi->s_maxsymlinklen);
1233 uspi->s_maxsymlinklen = maxsymlen;
1234 }
Al Viro8de52772012-02-06 12:45:27 -05001235 sb->s_max_links = UFS_LINK_MAX;
Duane Griffin9e6766c2009-01-08 22:43:48 +00001236
David Howellsb55c4602008-02-07 00:15:48 -08001237 inode = ufs_iget(sb, UFS_ROOTINO);
1238 if (IS_ERR(inode)) {
1239 ret = PTR_ERR(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 goto failed;
David Howellsb55c4602008-02-07 00:15:48 -08001241 }
Al Viro48fde702012-01-08 22:15:13 -05001242 sb->s_root = d_make_root(inode);
David Howellsb55c4602008-02-07 00:15:48 -08001243 if (!sb->s_root) {
1244 ret = -ENOMEM;
Al Viro48fde702012-01-08 22:15:13 -05001245 goto failed;
David Howellsb55c4602008-02-07 00:15:48 -08001246 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001248 ufs_setup_cstotal(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 /*
1250 * Read cylinder group structures
1251 */
1252 if (!(sb->s_flags & MS_RDONLY))
1253 if (!ufs_read_cylinder_structures(sb))
1254 goto failed;
1255
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001256 UFSD("EXIT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 return 0;
1258
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259failed:
Fabian Frederick02447562014-06-06 14:38:34 -07001260 mutex_destroy(&sbi->mutex);
Jesper Juhlf99d49a2005-11-07 01:01:34 -08001261 if (ubh)
1262 ubh_brelse_uspi (uspi);
1263 kfree (uspi);
1264 kfree(sbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 sb->s_fs_info = NULL;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001266 UFSD("EXIT (FAILED)\n");
David Howellsb55c4602008-02-07 00:15:48 -08001267 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
1269failed_nomem:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001270 UFSD("EXIT (NOMEM)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 return -ENOMEM;
1272}
1273
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1275{
1276 struct ufs_sb_private_info * uspi;
1277 struct ufs_super_block_first * usb1;
1278 struct ufs_super_block_third * usb3;
1279 unsigned new_mount_opt, ufstype;
1280 unsigned flags;
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001281
Theodore Ts'o02b99842014-03-13 10:14:33 -04001282 sync_filesystem(sb);
Arnd Bergmann788257d2011-01-24 10:14:12 +01001283 lock_ufs(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 uspi = UFS_SB(sb)->s_uspi;
1285 flags = UFS_SB(sb)->s_flags;
Evgeniy7b4ee732006-01-14 11:42:06 +03001286 usb1 = ubh_get_usb_first(uspi);
1287 usb3 = ubh_get_usb_third(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 /*
1290 * Allow the "check" option to be passed as a remount option.
1291 * It is not possible to change ufstype option during remount
1292 */
1293 ufstype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
1294 new_mount_opt = 0;
1295 ufs_set_opt (new_mount_opt, ONERROR_LOCK);
Al Virobbd68512009-05-06 10:43:07 -04001296 if (!ufs_parse_options (data, &new_mount_opt)) {
Arnd Bergmann788257d2011-01-24 10:14:12 +01001297 unlock_ufs(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 return -EINVAL;
Al Virobbd68512009-05-06 10:43:07 -04001299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 if (!(new_mount_opt & UFS_MOUNT_UFSTYPE)) {
1301 new_mount_opt |= ufstype;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001302 } else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
Fabian Fredericka9814c52014-08-08 14:20:57 -07001303 pr_err("ufstype can't be changed during remount\n");
Arnd Bergmann788257d2011-01-24 10:14:12 +01001304 unlock_ufs(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 return -EINVAL;
1306 }
1307
1308 if ((*mount_flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
1309 UFS_SB(sb)->s_mount_opt = new_mount_opt;
Arnd Bergmann788257d2011-01-24 10:14:12 +01001310 unlock_ufs(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 return 0;
1312 }
1313
1314 /*
1315 * fs was mouted as rw, remounting ro
1316 */
1317 if (*mount_flags & MS_RDONLY) {
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001318 ufs_put_super_internal(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
1320 if ((flags & UFS_ST_MASK) == UFS_ST_SUN
Mark Fortescue252e2112007-10-16 23:26:31 -07001321 || (flags & UFS_ST_MASK) == UFS_ST_SUNOS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
1323 ufs_set_fs_state(sb, usb1, usb3,
1324 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -07001325 ubh_mark_buffer_dirty (USPI_UBH(uspi));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 sb->s_flags |= MS_RDONLY;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001327 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 /*
1329 * fs was mounted as ro, remounting rw
1330 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331#ifndef CONFIG_UFS_FS_WRITE
Fabian Fredericka9814c52014-08-08 14:20:57 -07001332 pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
Arnd Bergmann788257d2011-01-24 10:14:12 +01001333 unlock_ufs(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 return -EINVAL;
1335#else
1336 if (ufstype != UFS_MOUNT_UFSTYPE_SUN &&
Mark Fortescue252e2112007-10-16 23:26:31 -07001337 ufstype != UFS_MOUNT_UFSTYPE_SUNOS &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 ufstype != UFS_MOUNT_UFSTYPE_44BSD &&
Evgeniy Dushistovcbcae392007-02-12 00:54:30 -08001339 ufstype != UFS_MOUNT_UFSTYPE_SUNx86 &&
1340 ufstype != UFS_MOUNT_UFSTYPE_UFS2) {
Fabian Fredericka9814c52014-08-08 14:20:57 -07001341 pr_err("this ufstype is read-only supported\n");
Arnd Bergmann788257d2011-01-24 10:14:12 +01001342 unlock_ufs(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 return -EINVAL;
1344 }
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001345 if (!ufs_read_cylinder_structures(sb)) {
Fabian Fredericka9814c52014-08-08 14:20:57 -07001346 pr_err("failed during remounting\n");
Arnd Bergmann788257d2011-01-24 10:14:12 +01001347 unlock_ufs(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 return -EPERM;
1349 }
1350 sb->s_flags &= ~MS_RDONLY;
1351#endif
1352 }
1353 UFS_SB(sb)->s_mount_opt = new_mount_opt;
Arnd Bergmann788257d2011-01-24 10:14:12 +01001354 unlock_ufs(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 return 0;
1356}
1357
Al Viro34c80b12011-12-08 21:32:45 -05001358static int ufs_show_options(struct seq_file *seq, struct dentry *root)
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -07001359{
Al Viro34c80b12011-12-08 21:32:45 -05001360 struct ufs_sb_info *sbi = UFS_SB(root->d_sb);
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -07001361 unsigned mval = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
Steven Whitehousea447c092008-10-13 10:46:57 +01001362 const struct match_token *tp = tokens;
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -07001363
1364 while (tp->token != Opt_onerror_panic && tp->token != mval)
1365 ++tp;
1366 BUG_ON(tp->token == Opt_onerror_panic);
1367 seq_printf(seq, ",%s", tp->pattern);
1368
1369 mval = sbi->s_mount_opt & UFS_MOUNT_ONERROR;
1370 while (tp->token != Opt_err && tp->token != mval)
1371 ++tp;
1372 BUG_ON(tp->token == Opt_err);
1373 seq_printf(seq, ",%s", tp->pattern);
1374
1375 return 0;
1376}
1377
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001378static int ufs_statfs(struct dentry *dentry, struct kstatfs *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379{
David Howells726c3342006-06-23 02:02:58 -07001380 struct super_block *sb = dentry->d_sb;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001381 struct ufs_sb_private_info *uspi= UFS_SB(sb)->s_uspi;
1382 unsigned flags = UFS_SB(sb)->s_flags;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001383 struct ufs_super_block_third *usb3;
Coly Li41d577a2009-04-02 16:59:44 -07001384 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Arnd Bergmann788257d2011-01-24 10:14:12 +01001386 lock_ufs(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001388 usb3 = ubh_get_usb_third(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
1391 buf->f_type = UFS2_MAGIC;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001392 buf->f_blocks = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize);
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001393 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 buf->f_type = UFS_MAGIC;
1395 buf->f_blocks = uspi->s_dsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 }
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001397 buf->f_bfree = ufs_blkstofrags(uspi->cs_total.cs_nbfree) +
1398 uspi->cs_total.cs_nffree;
1399 buf->f_ffree = uspi->cs_total.cs_nifree;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 buf->f_bsize = sb->s_blocksize;
1401 buf->f_bavail = (buf->f_bfree > (((long)buf->f_blocks / 100) * uspi->s_minfree))
1402 ? (buf->f_bfree - (((long)buf->f_blocks / 100) * uspi->s_minfree)) : 0;
1403 buf->f_files = uspi->s_ncg * uspi->s_ipg;
1404 buf->f_namelen = UFS_MAXNAMLEN;
Coly Li41d577a2009-04-02 16:59:44 -07001405 buf->f_fsid.val[0] = (u32)id;
1406 buf->f_fsid.val[1] = (u32)(id >> 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Arnd Bergmann788257d2011-01-24 10:14:12 +01001408 unlock_ufs(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
1410 return 0;
1411}
1412
Christoph Lametere18b8902006-12-06 20:33:20 -08001413static struct kmem_cache * ufs_inode_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
1415static struct inode *ufs_alloc_inode(struct super_block *sb)
1416{
1417 struct ufs_inode_info *ei;
Arnd Bergmann788257d2011-01-24 10:14:12 +01001418 ei = (struct ufs_inode_info *)kmem_cache_alloc(ufs_inode_cachep, GFP_NOFS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 if (!ei)
1420 return NULL;
1421 ei->vfs_inode.i_version = 1;
1422 return &ei->vfs_inode;
1423}
1424
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +11001425static void ufs_i_callback(struct rcu_head *head)
1426{
1427 struct inode *inode = container_of(head, struct inode, i_rcu);
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +11001428 kmem_cache_free(ufs_inode_cachep, UFS_I(inode));
1429}
1430
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431static void ufs_destroy_inode(struct inode *inode)
1432{
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +11001433 call_rcu(&inode->i_rcu, ufs_i_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434}
1435
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001436static void init_once(void *foo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437{
1438 struct ufs_inode_info *ei = (struct ufs_inode_info *) foo;
1439
Christoph Lametera35afb82007-05-16 22:10:57 -07001440 inode_init_once(&ei->vfs_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441}
Paul Mundt20c2df82007-07-20 10:11:58 +09001442
Fabian Frederick76ee4732014-04-07 15:39:55 -07001443static int __init init_inodecache(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444{
1445 ufs_inode_cachep = kmem_cache_create("ufs_inode_cache",
1446 sizeof(struct ufs_inode_info),
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001447 0, (SLAB_RECLAIM_ACCOUNT|
1448 SLAB_MEM_SPREAD),
Paul Mundt20c2df82007-07-20 10:11:58 +09001449 init_once);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 if (ufs_inode_cachep == NULL)
1451 return -ENOMEM;
1452 return 0;
1453}
1454
1455static void destroy_inodecache(void)
1456{
Kirill A. Shutemov8c0a8532012-09-26 11:33:07 +10001457 /*
1458 * Make sure all delayed rcu free inodes are flushed before we
1459 * destroy cache.
1460 */
1461 rcu_barrier();
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001462 kmem_cache_destroy(ufs_inode_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463}
1464
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -08001465static const struct super_operations ufs_super_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 .alloc_inode = ufs_alloc_inode,
1467 .destroy_inode = ufs_destroy_inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 .write_inode = ufs_write_inode,
Al Viro58e82682010-06-05 19:40:56 -04001469 .evict_inode = ufs_evict_inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 .put_super = ufs_put_super,
Christoph Hellwig8c800652009-06-08 10:08:05 +02001471 .sync_fs = ufs_sync_fs,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 .statfs = ufs_statfs,
1473 .remount_fs = ufs_remount,
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -07001474 .show_options = ufs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475};
1476
Al Viro152a0832010-07-25 00:46:55 +04001477static struct dentry *ufs_mount(struct file_system_type *fs_type,
1478 int flags, const char *dev_name, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479{
Al Viro152a0832010-07-25 00:46:55 +04001480 return mount_bdev(fs_type, flags, dev_name, data, ufs_fill_super);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481}
1482
1483static struct file_system_type ufs_fs_type = {
1484 .owner = THIS_MODULE,
1485 .name = "ufs",
Al Viro152a0832010-07-25 00:46:55 +04001486 .mount = ufs_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 .kill_sb = kill_block_super,
1488 .fs_flags = FS_REQUIRES_DEV,
1489};
Eric W. Biederman7f78e032013-03-02 19:39:14 -08001490MODULE_ALIAS_FS("ufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
1492static int __init init_ufs_fs(void)
1493{
1494 int err = init_inodecache();
1495 if (err)
1496 goto out1;
1497 err = register_filesystem(&ufs_fs_type);
1498 if (err)
1499 goto out;
1500 return 0;
1501out:
1502 destroy_inodecache();
1503out1:
1504 return err;
1505}
1506
1507static void __exit exit_ufs_fs(void)
1508{
1509 unregister_filesystem(&ufs_fs_type);
1510 destroy_inodecache();
1511}
1512
1513module_init(init_ufs_fs)
1514module_exit(exit_ufs_fs)
1515MODULE_LICENSE("GPL");