blob: 29ecaf739449c4036e6ed3ebed5499b8489079c4 [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
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080074#include <linux/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>
Tejun Heo66114ca2015-05-22 17:13:32 -040083#include <linux/backing-dev.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#include <linux/init.h>
85#include <linux/parser.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070086#include <linux/buffer_head.h>
87#include <linux/vfs.h>
vignesh babu9e8c4272007-07-15 23:41:36 -070088#include <linux/log2.h>
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -070089#include <linux/mount.h>
90#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Mike Frysingere5420592008-02-08 04:21:31 -080092#include "ufs_fs.h"
Christoph Hellwigbcd6d4e2007-10-16 23:26:51 -070093#include "ufs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#include "swab.h"
95#include "util.h"
96
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -080097static struct inode *ufs_nfs_get_inode(struct super_block *sb, u64 ino, u32 generation)
98{
99 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
100 struct inode *inode;
101
102 if (ino < UFS_ROOTINO || ino > uspi->s_ncg * uspi->s_ipg)
103 return ERR_PTR(-ESTALE);
104
105 inode = ufs_iget(sb, ino);
106 if (IS_ERR(inode))
107 return ERR_CAST(inode);
108 if (generation && inode->i_generation != generation) {
109 iput(inode);
110 return ERR_PTR(-ESTALE);
111 }
112 return inode;
113}
114
115static struct dentry *ufs_fh_to_dentry(struct super_block *sb, struct fid *fid,
116 int fh_len, int fh_type)
117{
118 return generic_fh_to_dentry(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
119}
120
121static struct dentry *ufs_fh_to_parent(struct super_block *sb, struct fid *fid,
122 int fh_len, int fh_type)
123{
124 return generic_fh_to_parent(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
125}
126
127static struct dentry *ufs_get_parent(struct dentry *child)
128{
Linus Torvalds26fe5752012-05-10 13:14:12 -0700129 struct qstr dot_dot = QSTR_INIT("..", 2);
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -0800130 ino_t ino;
131
David Howells2b0143b2015-03-17 22:25:59 +0000132 ino = ufs_inode_by_name(d_inode(child), &dot_dot);
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -0800133 if (!ino)
134 return ERR_PTR(-ENOENT);
Al Virofc640052016-04-10 01:33:30 -0400135 return d_obtain_alias(ufs_iget(child->d_sb, ino));
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -0800136}
137
138static const struct export_operations ufs_export_ops = {
139 .fh_to_dentry = ufs_fh_to_dentry,
140 .fh_to_parent = ufs_fh_to_parent,
141 .get_parent = ufs_get_parent,
142};
143
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700144#ifdef CONFIG_UFS_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/*
146 * Print contents of ufs_super_block, useful for debugging
147 */
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800148static void ufs_print_super_stuff(struct super_block *sb,
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700149 struct ufs_super_block_first *usb1,
150 struct ufs_super_block_second *usb2,
151 struct ufs_super_block_third *usb3)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152{
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800153 u32 magic = fs32_to_cpu(sb, usb3->fs_magic);
154
Fabian Fredericka9814c52014-08-08 14:20:57 -0700155 pr_debug("ufs_print_super_stuff\n");
156 pr_debug(" magic: 0x%x\n", magic);
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800157 if (fs32_to_cpu(sb, usb3->fs_magic) == UFS2_MAGIC) {
Fabian Fredericka9814c52014-08-08 14:20:57 -0700158 pr_debug(" fs_size: %llu\n", (unsigned long long)
159 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size));
160 pr_debug(" fs_dsize: %llu\n", (unsigned long long)
161 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize));
162 pr_debug(" bsize: %u\n",
163 fs32_to_cpu(sb, usb1->fs_bsize));
164 pr_debug(" fsize: %u\n",
165 fs32_to_cpu(sb, usb1->fs_fsize));
166 pr_debug(" fs_volname: %s\n", usb2->fs_un.fs_u2.fs_volname);
167 pr_debug(" fs_sblockloc: %llu\n", (unsigned long long)
168 fs64_to_cpu(sb, usb2->fs_un.fs_u2.fs_sblockloc));
169 pr_debug(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
170 fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir));
171 pr_debug(" cs_nbfree(No of free blocks): %llu\n",
172 (unsigned long long)
173 fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree));
174 pr_info(" cs_nifree(Num of free inodes): %llu\n",
175 (unsigned long long)
176 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree));
177 pr_info(" cs_nffree(Num of free frags): %llu\n",
178 (unsigned long long)
179 fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree));
180 pr_info(" fs_maxsymlinklen: %u\n",
181 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen));
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700182 } else {
Fabian Fredericka9814c52014-08-08 14:20:57 -0700183 pr_debug(" sblkno: %u\n", fs32_to_cpu(sb, usb1->fs_sblkno));
184 pr_debug(" cblkno: %u\n", fs32_to_cpu(sb, usb1->fs_cblkno));
185 pr_debug(" iblkno: %u\n", fs32_to_cpu(sb, usb1->fs_iblkno));
186 pr_debug(" dblkno: %u\n", fs32_to_cpu(sb, usb1->fs_dblkno));
187 pr_debug(" cgoffset: %u\n",
188 fs32_to_cpu(sb, usb1->fs_cgoffset));
189 pr_debug(" ~cgmask: 0x%x\n",
190 ~fs32_to_cpu(sb, usb1->fs_cgmask));
191 pr_debug(" size: %u\n", fs32_to_cpu(sb, usb1->fs_size));
192 pr_debug(" dsize: %u\n", fs32_to_cpu(sb, usb1->fs_dsize));
193 pr_debug(" ncg: %u\n", fs32_to_cpu(sb, usb1->fs_ncg));
194 pr_debug(" bsize: %u\n", fs32_to_cpu(sb, usb1->fs_bsize));
195 pr_debug(" fsize: %u\n", fs32_to_cpu(sb, usb1->fs_fsize));
196 pr_debug(" frag: %u\n", fs32_to_cpu(sb, usb1->fs_frag));
197 pr_debug(" fragshift: %u\n",
198 fs32_to_cpu(sb, usb1->fs_fragshift));
199 pr_debug(" ~fmask: %u\n", ~fs32_to_cpu(sb, usb1->fs_fmask));
200 pr_debug(" fshift: %u\n", fs32_to_cpu(sb, usb1->fs_fshift));
201 pr_debug(" sbsize: %u\n", fs32_to_cpu(sb, usb1->fs_sbsize));
202 pr_debug(" spc: %u\n", fs32_to_cpu(sb, usb1->fs_spc));
203 pr_debug(" cpg: %u\n", fs32_to_cpu(sb, usb1->fs_cpg));
204 pr_debug(" ipg: %u\n", fs32_to_cpu(sb, usb1->fs_ipg));
205 pr_debug(" fpg: %u\n", fs32_to_cpu(sb, usb1->fs_fpg));
206 pr_debug(" csaddr: %u\n", fs32_to_cpu(sb, usb1->fs_csaddr));
207 pr_debug(" cssize: %u\n", fs32_to_cpu(sb, usb1->fs_cssize));
208 pr_debug(" cgsize: %u\n", fs32_to_cpu(sb, usb1->fs_cgsize));
209 pr_debug(" fstodb: %u\n",
210 fs32_to_cpu(sb, usb1->fs_fsbtodb));
211 pr_debug(" nrpos: %u\n", fs32_to_cpu(sb, usb3->fs_nrpos));
212 pr_debug(" ndir %u\n",
213 fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir));
214 pr_debug(" nifree %u\n",
215 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree));
216 pr_debug(" nbfree %u\n",
217 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree));
218 pr_debug(" nffree %u\n",
219 fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree));
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700220 }
Fabian Fredericka9814c52014-08-08 14:20:57 -0700221 pr_debug("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
223
224/*
225 * Print contents of ufs_cylinder_group, useful for debugging
226 */
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700227static void ufs_print_cylinder_stuff(struct super_block *sb,
228 struct ufs_cylinder_group *cg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Fabian Fredericka9814c52014-08-08 14:20:57 -0700230 pr_debug("\nufs_print_cylinder_stuff\n");
231 pr_debug("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group));
232 pr_debug(" magic: %x\n", fs32_to_cpu(sb, cg->cg_magic));
233 pr_debug(" time: %u\n", fs32_to_cpu(sb, cg->cg_time));
234 pr_debug(" cgx: %u\n", fs32_to_cpu(sb, cg->cg_cgx));
235 pr_debug(" ncyl: %u\n", fs16_to_cpu(sb, cg->cg_ncyl));
236 pr_debug(" niblk: %u\n", fs16_to_cpu(sb, cg->cg_niblk));
237 pr_debug(" ndblk: %u\n", fs32_to_cpu(sb, cg->cg_ndblk));
238 pr_debug(" cs_ndir: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_ndir));
239 pr_debug(" cs_nbfree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nbfree));
240 pr_debug(" cs_nifree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nifree));
241 pr_debug(" cs_nffree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nffree));
242 pr_debug(" rotor: %u\n", fs32_to_cpu(sb, cg->cg_rotor));
243 pr_debug(" frotor: %u\n", fs32_to_cpu(sb, cg->cg_frotor));
244 pr_debug(" irotor: %u\n", fs32_to_cpu(sb, cg->cg_irotor));
245 pr_debug(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 fs32_to_cpu(sb, cg->cg_frsum[0]), fs32_to_cpu(sb, cg->cg_frsum[1]),
247 fs32_to_cpu(sb, cg->cg_frsum[2]), fs32_to_cpu(sb, cg->cg_frsum[3]),
248 fs32_to_cpu(sb, cg->cg_frsum[4]), fs32_to_cpu(sb, cg->cg_frsum[5]),
249 fs32_to_cpu(sb, cg->cg_frsum[6]), fs32_to_cpu(sb, cg->cg_frsum[7]));
Fabian Fredericka9814c52014-08-08 14:20:57 -0700250 pr_debug(" btotoff: %u\n", fs32_to_cpu(sb, cg->cg_btotoff));
251 pr_debug(" boff: %u\n", fs32_to_cpu(sb, cg->cg_boff));
252 pr_debug(" iuseoff: %u\n", fs32_to_cpu(sb, cg->cg_iusedoff));
253 pr_debug(" freeoff: %u\n", fs32_to_cpu(sb, cg->cg_freeoff));
254 pr_debug(" nextfreeoff: %u\n", fs32_to_cpu(sb, cg->cg_nextfreeoff));
255 pr_debug(" clustersumoff %u\n",
256 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clustersumoff));
257 pr_debug(" clusteroff %u\n",
258 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clusteroff));
259 pr_debug(" nclusterblks %u\n",
260 fs32_to_cpu(sb, cg->cg_u.cg_44.cg_nclusterblks));
261 pr_debug("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262}
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700263#else
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800264# define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700265# define ufs_print_cylinder_stuff(sb, cg) /**/
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700266#endif /* CONFIG_UFS_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -0800268static const struct super_operations ufs_super_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270void ufs_error (struct super_block * sb, const char * function,
271 const char * fmt, ...)
272{
273 struct ufs_sb_private_info * uspi;
274 struct ufs_super_block_first * usb1;
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700275 struct va_format vaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 va_list args;
277
278 uspi = UFS_SB(sb)->s_uspi;
Evgeniy7b4ee732006-01-14 11:42:06 +0300279 usb1 = ubh_get_usb_first(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280
281 if (!(sb->s_flags & MS_RDONLY)) {
282 usb1->fs_clean = UFS_FSBAD;
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -0700283 ubh_mark_buffer_dirty(USPI_UBH(uspi));
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300284 ufs_mark_sb_dirty(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 sb->s_flags |= MS_RDONLY;
286 }
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700287 va_start(args, fmt);
288 vaf.fmt = fmt;
289 vaf.va = &args;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 switch (UFS_SB(sb)->s_mount_opt & UFS_MOUNT_ONERROR) {
291 case UFS_MOUNT_ONERROR_PANIC:
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700292 panic("panic (device %s): %s: %pV\n",
293 sb->s_id, function, &vaf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 case UFS_MOUNT_ONERROR_LOCK:
296 case UFS_MOUNT_ONERROR_UMOUNT:
297 case UFS_MOUNT_ONERROR_REPAIR:
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700298 pr_crit("error (device %s): %s: %pV\n",
299 sb->s_id, function, &vaf);
300 }
301 va_end(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302}
303
304void ufs_panic (struct super_block * sb, const char * function,
305 const char * fmt, ...)
306{
307 struct ufs_sb_private_info * uspi;
308 struct ufs_super_block_first * usb1;
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700309 struct va_format vaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 va_list args;
311
312 uspi = UFS_SB(sb)->s_uspi;
Evgeniy7b4ee732006-01-14 11:42:06 +0300313 usb1 = ubh_get_usb_first(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315 if (!(sb->s_flags & MS_RDONLY)) {
316 usb1->fs_clean = UFS_FSBAD;
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -0700317 ubh_mark_buffer_dirty(USPI_UBH(uspi));
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300318 ufs_mark_sb_dirty(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 }
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700320 va_start(args, fmt);
321 vaf.fmt = fmt;
322 vaf.va = &args;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 sb->s_flags |= MS_RDONLY;
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700324 pr_crit("panic (device %s): %s: %pV\n",
325 sb->s_id, function, &vaf);
326 va_end(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327}
328
329void ufs_warning (struct super_block * sb, const char * function,
330 const char * fmt, ...)
331{
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700332 struct va_format vaf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 va_list args;
334
Fabian Frederick7e1e4162014-08-08 14:21:03 -0700335 va_start(args, fmt);
336 vaf.fmt = fmt;
337 vaf.va = &args;
338 pr_warn("(device %s): %s: %pV\n",
339 sb->s_id, function, &vaf);
340 va_end(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341}
342
343enum {
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -0700344 Opt_type_old = UFS_MOUNT_UFSTYPE_OLD,
345 Opt_type_sunx86 = UFS_MOUNT_UFSTYPE_SUNx86,
346 Opt_type_sun = UFS_MOUNT_UFSTYPE_SUN,
347 Opt_type_sunos = UFS_MOUNT_UFSTYPE_SUNOS,
348 Opt_type_44bsd = UFS_MOUNT_UFSTYPE_44BSD,
349 Opt_type_ufs2 = UFS_MOUNT_UFSTYPE_UFS2,
350 Opt_type_hp = UFS_MOUNT_UFSTYPE_HP,
351 Opt_type_nextstepcd = UFS_MOUNT_UFSTYPE_NEXTSTEP_CD,
352 Opt_type_nextstep = UFS_MOUNT_UFSTYPE_NEXTSTEP,
353 Opt_type_openstep = UFS_MOUNT_UFSTYPE_OPENSTEP,
354 Opt_onerror_panic = UFS_MOUNT_ONERROR_PANIC,
355 Opt_onerror_lock = UFS_MOUNT_ONERROR_LOCK,
356 Opt_onerror_umount = UFS_MOUNT_ONERROR_UMOUNT,
357 Opt_onerror_repair = UFS_MOUNT_ONERROR_REPAIR,
358 Opt_err
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359};
360
Steven Whitehousea447c092008-10-13 10:46:57 +0100361static const match_table_t tokens = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 {Opt_type_old, "ufstype=old"},
363 {Opt_type_sunx86, "ufstype=sunx86"},
364 {Opt_type_sun, "ufstype=sun"},
Mark Fortescue252e2112007-10-16 23:26:31 -0700365 {Opt_type_sunos, "ufstype=sunos"},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 {Opt_type_44bsd, "ufstype=44bsd"},
367 {Opt_type_ufs2, "ufstype=ufs2"},
368 {Opt_type_ufs2, "ufstype=5xbsd"},
369 {Opt_type_hp, "ufstype=hp"},
370 {Opt_type_nextstepcd, "ufstype=nextstep-cd"},
371 {Opt_type_nextstep, "ufstype=nextstep"},
372 {Opt_type_openstep, "ufstype=openstep"},
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -0700373/*end of possible ufs types */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 {Opt_onerror_panic, "onerror=panic"},
375 {Opt_onerror_lock, "onerror=lock"},
376 {Opt_onerror_umount, "onerror=umount"},
377 {Opt_onerror_repair, "onerror=repair"},
378 {Opt_err, NULL}
379};
380
381static int ufs_parse_options (char * options, unsigned * mount_options)
382{
383 char * p;
384
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700385 UFSD("ENTER\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
387 if (!options)
388 return 1;
389
390 while ((p = strsep(&options, ",")) != NULL) {
391 substring_t args[MAX_OPT_ARGS];
392 int token;
393 if (!*p)
394 continue;
395
396 token = match_token(p, tokens, args);
397 switch (token) {
398 case Opt_type_old:
399 ufs_clear_opt (*mount_options, UFSTYPE);
400 ufs_set_opt (*mount_options, UFSTYPE_OLD);
401 break;
402 case Opt_type_sunx86:
403 ufs_clear_opt (*mount_options, UFSTYPE);
404 ufs_set_opt (*mount_options, UFSTYPE_SUNx86);
405 break;
406 case Opt_type_sun:
407 ufs_clear_opt (*mount_options, UFSTYPE);
408 ufs_set_opt (*mount_options, UFSTYPE_SUN);
409 break;
Mark Fortescue252e2112007-10-16 23:26:31 -0700410 case Opt_type_sunos:
411 ufs_clear_opt(*mount_options, UFSTYPE);
412 ufs_set_opt(*mount_options, UFSTYPE_SUNOS);
413 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 case Opt_type_44bsd:
415 ufs_clear_opt (*mount_options, UFSTYPE);
416 ufs_set_opt (*mount_options, UFSTYPE_44BSD);
417 break;
418 case Opt_type_ufs2:
419 ufs_clear_opt(*mount_options, UFSTYPE);
420 ufs_set_opt(*mount_options, UFSTYPE_UFS2);
421 break;
422 case Opt_type_hp:
423 ufs_clear_opt (*mount_options, UFSTYPE);
424 ufs_set_opt (*mount_options, UFSTYPE_HP);
425 break;
426 case Opt_type_nextstepcd:
427 ufs_clear_opt (*mount_options, UFSTYPE);
428 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP_CD);
429 break;
430 case Opt_type_nextstep:
431 ufs_clear_opt (*mount_options, UFSTYPE);
432 ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP);
433 break;
434 case Opt_type_openstep:
435 ufs_clear_opt (*mount_options, UFSTYPE);
436 ufs_set_opt (*mount_options, UFSTYPE_OPENSTEP);
437 break;
438 case Opt_onerror_panic:
439 ufs_clear_opt (*mount_options, ONERROR);
440 ufs_set_opt (*mount_options, ONERROR_PANIC);
441 break;
442 case Opt_onerror_lock:
443 ufs_clear_opt (*mount_options, ONERROR);
444 ufs_set_opt (*mount_options, ONERROR_LOCK);
445 break;
446 case Opt_onerror_umount:
447 ufs_clear_opt (*mount_options, ONERROR);
448 ufs_set_opt (*mount_options, ONERROR_UMOUNT);
449 break;
450 case Opt_onerror_repair:
Fabian Frederickde771bd2014-08-08 14:20:59 -0700451 pr_err("Unable to do repair on error, will lock lock instead\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 ufs_clear_opt (*mount_options, ONERROR);
453 ufs_set_opt (*mount_options, ONERROR_REPAIR);
454 break;
455 default:
Fabian Frederickde771bd2014-08-08 14:20:59 -0700456 pr_err("Invalid option: \"%s\" or missing value\n", p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 return 0;
458 }
459 }
460 return 1;
461}
462
463/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300464 * Different types of UFS hold fs_cstotal in different
465 * places, and use different data structure for it.
466 * To make things simpler we just copy fs_cstotal to ufs_sb_private_info
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 */
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700468static void ufs_setup_cstotal(struct super_block *sb)
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800469{
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700470 struct ufs_sb_info *sbi = UFS_SB(sb);
471 struct ufs_sb_private_info *uspi = sbi->s_uspi;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700472 struct ufs_super_block_first *usb1;
473 struct ufs_super_block_second *usb2;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700474 struct ufs_super_block_third *usb3;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700475 unsigned mtype = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
476
477 UFSD("ENTER, mtype=%u\n", mtype);
478 usb1 = ubh_get_usb_first(uspi);
479 usb2 = ubh_get_usb_second(uspi);
480 usb3 = ubh_get_usb_third(uspi);
481
482 if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
483 (usb1->fs_flags & UFS_FLAGS_UPDATED)) ||
484 mtype == UFS_MOUNT_UFSTYPE_UFS2) {
485 /*we have statistic in different place, then usual*/
486 uspi->cs_total.cs_ndir = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir);
487 uspi->cs_total.cs_nbfree = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree);
488 uspi->cs_total.cs_nifree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree);
489 uspi->cs_total.cs_nffree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree);
490 } else {
491 uspi->cs_total.cs_ndir = fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir);
492 uspi->cs_total.cs_nbfree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree);
493 uspi->cs_total.cs_nifree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree);
494 uspi->cs_total.cs_nffree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree);
495 }
496 UFSD("EXIT\n");
497}
498
499/*
500 * Read on-disk structures associated with cylinder groups
501 */
502static int ufs_read_cylinder_structures(struct super_block *sb)
503{
504 struct ufs_sb_info *sbi = UFS_SB(sb);
505 struct ufs_sb_private_info *uspi = sbi->s_uspi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 struct ufs_buffer_head * ubh;
507 unsigned char * base, * space;
508 unsigned size, blks, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700510 UFSD("ENTER\n");
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 /*
513 * Read cs structures from (usually) first data block
514 * on the device.
515 */
516 size = uspi->s_cssize;
517 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
Arnd Bergmann788257d2011-01-24 10:14:12 +0100518 base = space = kmalloc(size, GFP_NOFS);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 if (!base)
520 goto failed;
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800521 sbi->s_csp = (struct ufs_csum *)space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 for (i = 0; i < blks; i += uspi->s_fpb) {
523 size = uspi->s_bsize;
524 if (i + uspi->s_fpb > blks)
525 size = (blks - i) * uspi->s_fsize;
526
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800527 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
Evgeniy7b4ee732006-01-14 11:42:06 +0300528
529 if (!ubh)
530 goto failed;
531
532 ubh_ubhcpymem (space, ubh, size);
Evgeniy7b4ee732006-01-14 11:42:06 +0300533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 space += size;
535 ubh_brelse (ubh);
536 ubh = NULL;
537 }
538
539 /*
540 * Read cylinder group (we read only first fragment from block
541 * at this time) and prepare internal data structures for cg caching.
542 */
Arnd Bergmann788257d2011-01-24 10:14:12 +0100543 if (!(sbi->s_ucg = kmalloc (sizeof(struct buffer_head *) * uspi->s_ncg, GFP_NOFS)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 goto failed;
545 for (i = 0; i < uspi->s_ncg; i++)
546 sbi->s_ucg[i] = NULL;
547 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
548 sbi->s_ucpi[i] = NULL;
549 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
550 }
551 for (i = 0; i < uspi->s_ncg; i++) {
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700552 UFSD("read cg %u\n", i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 if (!(sbi->s_ucg[i] = sb_bread(sb, ufs_cgcmin(i))))
554 goto failed;
555 if (!ufs_cg_chkmagic (sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data))
556 goto failed;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -0700557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 ufs_print_cylinder_stuff(sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
560 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
Arnd Bergmann788257d2011-01-24 10:14:12 +0100561 if (!(sbi->s_ucpi[i] = kmalloc (sizeof(struct ufs_cg_private_info), GFP_NOFS)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 goto failed;
563 sbi->s_cgno[i] = UFS_CGNO_EMPTY;
564 }
565 sbi->s_cg_loaded = 0;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700566 UFSD("EXIT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 return 1;
568
569failed:
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800570 kfree (base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (sbi->s_ucg) {
572 for (i = 0; i < uspi->s_ncg; i++)
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800573 if (sbi->s_ucg[i])
574 brelse (sbi->s_ucg[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 kfree (sbi->s_ucg);
576 for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
Jesper Juhlf99d49a2005-11-07 01:01:34 -0800577 kfree (sbi->s_ucpi[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 }
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700579 UFSD("EXIT (FAILED)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 return 0;
581}
582
583/*
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700584 * Sync our internal copy of fs_cstotal with disk
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 */
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700586static void ufs_put_cstotal(struct super_block *sb)
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800587{
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700588 unsigned mtype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
589 struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
590 struct ufs_super_block_first *usb1;
591 struct ufs_super_block_second *usb2;
592 struct ufs_super_block_third *usb3;
593
594 UFSD("ENTER\n");
595 usb1 = ubh_get_usb_first(uspi);
596 usb2 = ubh_get_usb_second(uspi);
597 usb3 = ubh_get_usb_third(uspi);
598
599 if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
600 (usb1->fs_flags & UFS_FLAGS_UPDATED)) ||
601 mtype == UFS_MOUNT_UFSTYPE_UFS2) {
602 /*we have statistic in different place, then usual*/
603 usb2->fs_un.fs_u2.cs_ndir =
604 cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
605 usb2->fs_un.fs_u2.cs_nbfree =
606 cpu_to_fs64(sb, uspi->cs_total.cs_nbfree);
607 usb3->fs_un1.fs_u2.cs_nifree =
608 cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
609 usb3->fs_un1.fs_u2.cs_nffree =
610 cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
611 } else {
612 usb1->fs_cstotal.cs_ndir =
613 cpu_to_fs32(sb, uspi->cs_total.cs_ndir);
614 usb1->fs_cstotal.cs_nbfree =
615 cpu_to_fs32(sb, uspi->cs_total.cs_nbfree);
616 usb1->fs_cstotal.cs_nifree =
617 cpu_to_fs32(sb, uspi->cs_total.cs_nifree);
618 usb1->fs_cstotal.cs_nffree =
619 cpu_to_fs32(sb, uspi->cs_total.cs_nffree);
620 }
621 ubh_mark_buffer_dirty(USPI_UBH(uspi));
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800622 ufs_print_super_stuff(sb, usb1, usb2, usb3);
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700623 UFSD("EXIT\n");
624}
625
626/**
627 * ufs_put_super_internal() - put on-disk intrenal structures
628 * @sb: pointer to super_block structure
629 * Put on-disk structures associated with cylinder groups
630 * and write them back to disk, also update cs_total on disk
631 */
632static void ufs_put_super_internal(struct super_block *sb)
633{
634 struct ufs_sb_info *sbi = UFS_SB(sb);
635 struct ufs_sb_private_info *uspi = sbi->s_uspi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 struct ufs_buffer_head * ubh;
637 unsigned char * base, * space;
638 unsigned blks, size, i;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700641 UFSD("ENTER\n");
Christoph Hellwig6cfd0142009-05-05 15:40:36 +0200642
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -0700643 ufs_put_cstotal(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 size = uspi->s_cssize;
645 blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
Evgeniy Dushistove295cfc2006-02-03 03:04:04 -0800646 base = space = (char*) sbi->s_csp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 for (i = 0; i < blks; i += uspi->s_fpb) {
648 size = uspi->s_bsize;
649 if (i + uspi->s_fpb > blks)
650 size = (blks - i) * uspi->s_fsize;
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
Evgeniy Dushistov3313e292007-02-12 00:54:31 -0800653
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 ubh_memcpyubh (ubh, space, size);
655 space += size;
656 ubh_mark_buffer_uptodate (ubh, 1);
657 ubh_mark_buffer_dirty (ubh);
658 ubh_brelse (ubh);
659 }
660 for (i = 0; i < sbi->s_cg_loaded; i++) {
661 ufs_put_cylinder (sb, i);
662 kfree (sbi->s_ucpi[i]);
663 }
664 for (; i < UFS_MAX_GROUP_LOADED; i++)
665 kfree (sbi->s_ucpi[i]);
666 for (i = 0; i < uspi->s_ncg; i++)
667 brelse (sbi->s_ucg[i]);
668 kfree (sbi->s_ucg);
669 kfree (base);
Christoph Hellwig6cfd0142009-05-05 15:40:36 +0200670
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700671 UFSD("EXIT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672}
673
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300674static int ufs_sync_fs(struct super_block *sb, int wait)
675{
676 struct ufs_sb_private_info * uspi;
677 struct ufs_super_block_first * usb1;
678 struct ufs_super_block_third * usb3;
679 unsigned flags;
680
Fabian Frederickcdd9eef2015-06-10 10:09:32 +1000681 mutex_lock(&UFS_SB(sb)->s_lock);
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300682
683 UFSD("ENTER\n");
684
685 flags = UFS_SB(sb)->s_flags;
686 uspi = UFS_SB(sb)->s_uspi;
687 usb1 = ubh_get_usb_first(uspi);
688 usb3 = ubh_get_usb_third(uspi);
689
690 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
691 if ((flags & UFS_ST_MASK) == UFS_ST_SUN ||
692 (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
693 (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
694 ufs_set_fs_state(sb, usb1, usb3,
695 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
696 ufs_put_cstotal(sb);
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300697
698 UFSD("EXIT\n");
Fabian Frederickcdd9eef2015-06-10 10:09:32 +1000699 mutex_unlock(&UFS_SB(sb)->s_lock);
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300700
701 return 0;
702}
703
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300704static void delayed_sync_fs(struct work_struct *work)
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300705{
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300706 struct ufs_sb_info *sbi;
707
708 sbi = container_of(work, struct ufs_sb_info, sync_work.work);
709
710 spin_lock(&sbi->work_lock);
711 sbi->work_queued = 0;
712 spin_unlock(&sbi->work_lock);
713
714 ufs_sync_fs(sbi->sb, 1);
715}
716
717void ufs_mark_sb_dirty(struct super_block *sb)
718{
719 struct ufs_sb_info *sbi = UFS_SB(sb);
720 unsigned long delay;
721
722 spin_lock(&sbi->work_lock);
723 if (!sbi->work_queued) {
724 delay = msecs_to_jiffies(dirty_writeback_interval * 10);
725 queue_delayed_work(system_long_wq, &sbi->sync_work, delay);
726 sbi->work_queued = 1;
727 }
728 spin_unlock(&sbi->work_lock);
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300729}
730
731static void ufs_put_super(struct super_block *sb)
732{
733 struct ufs_sb_info * sbi = UFS_SB(sb);
734
735 UFSD("ENTER\n");
736
737 if (!(sb->s_flags & MS_RDONLY))
738 ufs_put_super_internal(sb);
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300739 cancel_delayed_work_sync(&sbi->sync_work);
Artem Bityutskiy7bd54ef72012-07-12 16:28:07 +0300740
741 ubh_brelse_uspi (sbi->s_uspi);
742 kfree (sbi->s_uspi);
743 kfree (sbi);
744 sb->s_fs_info = NULL;
745 UFSD("EXIT\n");
746 return;
747}
748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749static int ufs_fill_super(struct super_block *sb, void *data, int silent)
750{
751 struct ufs_sb_info * sbi;
752 struct ufs_sb_private_info * uspi;
753 struct ufs_super_block_first * usb1;
754 struct ufs_super_block_second * usb2;
755 struct ufs_super_block_third * usb3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 struct ufs_buffer_head * ubh;
757 struct inode *inode;
758 unsigned block_size, super_block_size;
759 unsigned flags;
Evgeniy7b4ee732006-01-14 11:42:06 +0300760 unsigned super_block_offset;
Duane Griffin9e6766c2009-01-08 22:43:48 +0000761 unsigned maxsymlen;
David Howellsb55c4602008-02-07 00:15:48 -0800762 int ret = -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
764 uspi = NULL;
765 ubh = NULL;
766 flags = 0;
767
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700768 UFSD("ENTER\n");
Fabian Frederick02447562014-06-06 14:38:34 -0700769
770#ifndef CONFIG_UFS_FS_WRITE
771 if (!(sb->s_flags & MS_RDONLY)) {
Fabian Fredericka9814c52014-08-08 14:20:57 -0700772 pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
Fabian Frederick02447562014-06-06 14:38:34 -0700773 return -EROFS;
774 }
775#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Panagiotis Issarisf8314dc2006-09-27 01:49:37 -0700777 sbi = kzalloc(sizeof(struct ufs_sb_info), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 if (!sbi)
779 goto failed_nomem;
780 sb->s_fs_info = sbi;
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300781 sbi->sb = sb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700783 UFSD("flag %u\n", (int)(sb->s_flags & MS_RDONLY));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Fabian Fredericke4f95512015-06-17 18:15:45 +0200785 mutex_init(&sbi->s_lock);
Artem Bityutskiy9e9ad5f2012-07-12 16:28:08 +0300786 spin_lock_init(&sbi->work_lock);
787 INIT_DELAYED_WORK(&sbi->sync_work, delayed_sync_fs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 /*
789 * Set default mount options
790 * Parse mount options
791 */
792 sbi->s_mount_opt = 0;
793 ufs_set_opt (sbi->s_mount_opt, ONERROR_LOCK);
794 if (!ufs_parse_options ((char *) data, &sbi->s_mount_opt)) {
Fabian Fredericka9814c52014-08-08 14:20:57 -0700795 pr_err("wrong mount options\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 goto failed;
797 }
798 if (!(sbi->s_mount_opt & UFS_MOUNT_UFSTYPE)) {
799 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700800 pr_err("You didn't specify the type of your ufs filesystem\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 "mount -t ufs -o ufstype="
Michael Owenc690a722006-03-24 18:21:44 +0100802 "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
804 "default is ufstype=old\n");
805 ufs_set_opt (sbi->s_mount_opt, UFSTYPE_OLD);
806 }
807
Mark Fortescue252e2112007-10-16 23:26:31 -0700808 uspi = kzalloc(sizeof(struct ufs_sb_private_info), GFP_KERNEL);
809 sbi->s_uspi = uspi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 if (!uspi)
811 goto failed;
Evgeniy Dushistovf3369532007-02-08 14:20:25 -0800812 uspi->s_dirblksize = UFS_SECTOR_SIZE;
Evgeniy7b4ee732006-01-14 11:42:06 +0300813 super_block_offset=UFS_SBLOCK;
814
Richard Narron239e2502017-06-04 16:23:18 -0700815 sb->s_maxbytes = MAX_LFS_FILESIZE;
816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 switch (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) {
818 case UFS_MOUNT_UFSTYPE_44BSD:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700819 UFSD("ufstype=44bsd\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 uspi->s_fsize = block_size = 512;
821 uspi->s_fmask = ~(512 - 1);
822 uspi->s_fshift = 9;
823 uspi->s_sbsize = super_block_size = 1536;
824 uspi->s_sbbase = 0;
825 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
826 break;
827 case UFS_MOUNT_UFSTYPE_UFS2:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700828 UFSD("ufstype=ufs2\n");
Evgeniy7b4ee732006-01-14 11:42:06 +0300829 super_block_offset=SBLOCK_UFS2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 uspi->s_fsize = block_size = 512;
831 uspi->s_fmask = ~(512 - 1);
832 uspi->s_fshift = 9;
833 uspi->s_sbsize = super_block_size = 1536;
834 uspi->s_sbbase = 0;
835 flags |= UFS_TYPE_UFS2 | UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 break;
837
838 case UFS_MOUNT_UFSTYPE_SUN:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700839 UFSD("ufstype=sun\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840 uspi->s_fsize = block_size = 1024;
841 uspi->s_fmask = ~(1024 - 1);
842 uspi->s_fshift = 10;
843 uspi->s_sbsize = super_block_size = 2048;
844 uspi->s_sbbase = 0;
Mark Fortescue252e2112007-10-16 23:26:31 -0700845 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUN | UFS_CG_SUN;
847 break;
848
Mark Fortescue252e2112007-10-16 23:26:31 -0700849 case UFS_MOUNT_UFSTYPE_SUNOS:
Fabian Frederickd4beaab2014-08-08 14:21:05 -0700850 UFSD("ufstype=sunos\n");
Mark Fortescue252e2112007-10-16 23:26:31 -0700851 uspi->s_fsize = block_size = 1024;
852 uspi->s_fmask = ~(1024 - 1);
853 uspi->s_fshift = 10;
854 uspi->s_sbsize = 2048;
855 super_block_size = 2048;
856 uspi->s_sbbase = 0;
857 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
858 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_SUNOS | UFS_CG_SUN;
859 break;
860
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 case UFS_MOUNT_UFSTYPE_SUNx86:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700862 UFSD("ufstype=sunx86\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 uspi->s_fsize = block_size = 1024;
864 uspi->s_fmask = ~(1024 - 1);
865 uspi->s_fshift = 10;
866 uspi->s_sbsize = super_block_size = 2048;
867 uspi->s_sbbase = 0;
Mark Fortescue252e2112007-10-16 23:26:31 -0700868 uspi->s_maxsymlinklen = 0; /* Not supported on disk */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUNx86 | UFS_CG_SUN;
870 break;
871
872 case UFS_MOUNT_UFSTYPE_OLD:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700873 UFSD("ufstype=old\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 uspi->s_fsize = block_size = 1024;
875 uspi->s_fmask = ~(1024 - 1);
876 uspi->s_fshift = 10;
877 uspi->s_sbsize = super_block_size = 2048;
878 uspi->s_sbbase = 0;
879 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
880 if (!(sb->s_flags & MS_RDONLY)) {
881 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700882 pr_info("ufstype=old is supported read-only\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 sb->s_flags |= MS_RDONLY;
884 }
885 break;
886
887 case UFS_MOUNT_UFSTYPE_NEXTSTEP:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700888 UFSD("ufstype=nextstep\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 uspi->s_fsize = block_size = 1024;
890 uspi->s_fmask = ~(1024 - 1);
891 uspi->s_fshift = 10;
892 uspi->s_sbsize = super_block_size = 2048;
893 uspi->s_sbbase = 0;
Evgeniy Dushistov0c664f92007-12-04 23:45:06 -0800894 uspi->s_dirblksize = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
896 if (!(sb->s_flags & MS_RDONLY)) {
897 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700898 pr_info("ufstype=nextstep is supported read-only\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 sb->s_flags |= MS_RDONLY;
900 }
901 break;
902
903 case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700904 UFSD("ufstype=nextstep-cd\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 uspi->s_fsize = block_size = 2048;
906 uspi->s_fmask = ~(2048 - 1);
907 uspi->s_fshift = 11;
908 uspi->s_sbsize = super_block_size = 2048;
909 uspi->s_sbbase = 0;
Evgeniy Dushistov0c664f92007-12-04 23:45:06 -0800910 uspi->s_dirblksize = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
912 if (!(sb->s_flags & MS_RDONLY)) {
913 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700914 pr_info("ufstype=nextstep-cd is supported read-only\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 sb->s_flags |= MS_RDONLY;
916 }
917 break;
918
919 case UFS_MOUNT_UFSTYPE_OPENSTEP:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700920 UFSD("ufstype=openstep\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 uspi->s_fsize = block_size = 1024;
922 uspi->s_fmask = ~(1024 - 1);
923 uspi->s_fshift = 10;
924 uspi->s_sbsize = super_block_size = 2048;
925 uspi->s_sbbase = 0;
Evgeniy Dushistovf3369532007-02-08 14:20:25 -0800926 uspi->s_dirblksize = 1024;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
928 if (!(sb->s_flags & MS_RDONLY)) {
929 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700930 pr_info("ufstype=openstep is supported read-only\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 sb->s_flags |= MS_RDONLY;
932 }
933 break;
934
935 case UFS_MOUNT_UFSTYPE_HP:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -0700936 UFSD("ufstype=hp\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 uspi->s_fsize = block_size = 1024;
938 uspi->s_fmask = ~(1024 - 1);
939 uspi->s_fshift = 10;
940 uspi->s_sbsize = super_block_size = 2048;
941 uspi->s_sbbase = 0;
942 flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
943 if (!(sb->s_flags & MS_RDONLY)) {
944 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700945 pr_info("ufstype=hp is supported read-only\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 sb->s_flags |= MS_RDONLY;
947 }
948 break;
949 default:
950 if (!silent)
Fabian Fredericka9814c52014-08-08 14:20:57 -0700951 pr_err("unknown ufstype\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 goto failed;
953 }
954
955again:
956 if (!sb_set_blocksize(sb, block_size)) {
Fabian Frederickde771bd2014-08-08 14:20:59 -0700957 pr_err("failed to set blocksize\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 goto failed;
959 }
960
961 /*
962 * read ufs super block from device
963 */
Evgeniy7b4ee732006-01-14 11:42:06 +0300964
965 ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + super_block_offset/block_size, super_block_size);
966
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 if (!ubh)
968 goto failed;
969
Evgeniy7b4ee732006-01-14 11:42:06 +0300970 usb1 = ubh_get_usb_first(uspi);
971 usb2 = ubh_get_usb_second(uspi);
972 usb3 = ubh_get_usb_third(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Mark Fortescue252e2112007-10-16 23:26:31 -0700974 /* Sort out mod used on SunOS 4.1.3 for fs_state */
975 uspi->s_postblformat = fs32_to_cpu(sb, usb3->fs_postblformat);
976 if (((flags & UFS_ST_MASK) == UFS_ST_SUNOS) &&
977 (uspi->s_postblformat != UFS_42POSTBLFMT)) {
978 flags &= ~UFS_ST_MASK;
979 flags |= UFS_ST_SUN;
980 }
981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 /*
983 * Check ufs magic number
984 */
985 sbi->s_bytesex = BYTESEX_LE;
986 switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
987 case UFS_MAGIC:
Thomas Stewartd27d7a92010-05-26 14:42:33 -0700988 case UFS_MAGIC_BW:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 case UFS2_MAGIC:
990 case UFS_MAGIC_LFN:
991 case UFS_MAGIC_FEA:
992 case UFS_MAGIC_4GB:
993 goto magic_found;
994 }
995 sbi->s_bytesex = BYTESEX_BE;
996 switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
997 case UFS_MAGIC:
Thomas Stewartd27d7a92010-05-26 14:42:33 -0700998 case UFS_MAGIC_BW:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 case UFS2_MAGIC:
1000 case UFS_MAGIC_LFN:
1001 case UFS_MAGIC_FEA:
1002 case UFS_MAGIC_4GB:
1003 goto magic_found;
1004 }
1005
1006 if ((((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP)
1007 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD)
1008 || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_OPENSTEP))
1009 && uspi->s_sbbase < 256) {
1010 ubh_brelse_uspi(uspi);
1011 ubh = NULL;
1012 uspi->s_sbbase += 8;
1013 goto again;
1014 }
1015 if (!silent)
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001016 pr_err("%s(): bad magic number\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 goto failed;
1018
1019magic_found:
1020 /*
1021 * Check block and fragment sizes
1022 */
1023 uspi->s_bsize = fs32_to_cpu(sb, usb1->fs_bsize);
1024 uspi->s_fsize = fs32_to_cpu(sb, usb1->fs_fsize);
1025 uspi->s_sbsize = fs32_to_cpu(sb, usb1->fs_sbsize);
1026 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
1027 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
1028
vignesh babu9e8c4272007-07-15 23:41:36 -07001029 if (!is_power_of_2(uspi->s_fsize)) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001030 pr_err("%s(): fragment size %u is not a power of 2\n",
1031 __func__, uspi->s_fsize);
Fabian Fredericka9814c52014-08-08 14:20:57 -07001032 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
1034 if (uspi->s_fsize < 512) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001035 pr_err("%s(): fragment size %u is too small\n",
1036 __func__, uspi->s_fsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 goto failed;
1038 }
1039 if (uspi->s_fsize > 4096) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001040 pr_err("%s(): fragment size %u is too large\n",
1041 __func__, uspi->s_fsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 goto failed;
1043 }
vignesh babu9e8c4272007-07-15 23:41:36 -07001044 if (!is_power_of_2(uspi->s_bsize)) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001045 pr_err("%s(): block size %u is not a power of 2\n",
1046 __func__, uspi->s_bsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 goto failed;
1048 }
1049 if (uspi->s_bsize < 4096) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001050 pr_err("%s(): block size %u is too small\n",
1051 __func__, uspi->s_bsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 goto failed;
1053 }
1054 if (uspi->s_bsize / uspi->s_fsize > 8) {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001055 pr_err("%s(): too many fragments per block (%u)\n",
1056 __func__, uspi->s_bsize / uspi->s_fsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 goto failed;
1058 }
1059 if (uspi->s_fsize != block_size || uspi->s_sbsize != super_block_size) {
1060 ubh_brelse_uspi(uspi);
1061 ubh = NULL;
1062 block_size = uspi->s_fsize;
1063 super_block_size = uspi->s_sbsize;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001064 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 -07001065 goto again;
1066 }
1067
Andrew Mortonf664f1f2007-10-29 14:37:21 -07001068 sbi->s_flags = flags;/*after that line some functions use s_flags*/
Evgeniy Dushistov3313e292007-02-12 00:54:31 -08001069 ufs_print_super_stuff(sb, usb1, usb2, usb3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071 /*
1072 * Check, if file system was correctly unmounted.
1073 * If not, make it read only.
1074 */
Andrew Mortonf664f1f2007-10-29 14:37:21 -07001075 if (((flags & UFS_ST_MASK) == UFS_ST_44BSD) ||
1076 ((flags & UFS_ST_MASK) == UFS_ST_OLD) ||
1077 (((flags & UFS_ST_MASK) == UFS_ST_SUN ||
1078 (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
1079 (flags & UFS_ST_MASK) == UFS_ST_SUNx86) &&
1080 (ufs_get_fs_state(sb, usb1, usb3) == (UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time))))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 switch(usb1->fs_clean) {
1082 case UFS_FSCLEAN:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001083 UFSD("fs is clean\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 break;
1085 case UFS_FSSTABLE:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001086 UFSD("fs is stable\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 break;
Alex Viskovatoffb3a0fd42010-03-10 15:21:53 -08001088 case UFS_FSLOG:
1089 UFSD("fs is logging fs\n");
1090 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 case UFS_FSOSF1:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001092 UFSD("fs is DEC OSF/1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 break;
1094 case UFS_FSACTIVE:
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001095 pr_err("%s(): fs is active\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 sb->s_flags |= MS_RDONLY;
1097 break;
1098 case UFS_FSBAD:
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001099 pr_err("%s(): fs is bad\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 sb->s_flags |= MS_RDONLY;
1101 break;
1102 default:
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001103 pr_err("%s(): can't grok fs_clean 0x%x\n",
1104 __func__, usb1->fs_clean);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 sb->s_flags |= MS_RDONLY;
1106 break;
1107 }
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001108 } else {
Fabian Frederick07bc94f2014-08-08 14:21:01 -07001109 pr_err("%s(): fs needs fsck\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 sb->s_flags |= MS_RDONLY;
1111 }
1112
1113 /*
1114 * Read ufs_super_block into internal data structures
1115 */
1116 sb->s_op = &ufs_super_ops;
Alexey Dobriyanf3e2a522009-12-15 16:46:51 -08001117 sb->s_export_op = &ufs_export_ops;
Christoph Hellwig123e9ca2010-05-19 07:16:44 -04001118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 sb->s_magic = fs32_to_cpu(sb, usb3->fs_magic);
1120
1121 uspi->s_sblkno = fs32_to_cpu(sb, usb1->fs_sblkno);
1122 uspi->s_cblkno = fs32_to_cpu(sb, usb1->fs_cblkno);
1123 uspi->s_iblkno = fs32_to_cpu(sb, usb1->fs_iblkno);
1124 uspi->s_dblkno = fs32_to_cpu(sb, usb1->fs_dblkno);
1125 uspi->s_cgoffset = fs32_to_cpu(sb, usb1->fs_cgoffset);
1126 uspi->s_cgmask = fs32_to_cpu(sb, usb1->fs_cgmask);
1127
1128 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001129 uspi->s_u2_size = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size);
1130 uspi->s_u2_dsize = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize);
1131 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 uspi->s_size = fs32_to_cpu(sb, usb1->fs_size);
1133 uspi->s_dsize = fs32_to_cpu(sb, usb1->fs_dsize);
1134 }
1135
1136 uspi->s_ncg = fs32_to_cpu(sb, usb1->fs_ncg);
1137 /* s_bsize already set */
1138 /* s_fsize already set */
1139 uspi->s_fpb = fs32_to_cpu(sb, usb1->fs_frag);
1140 uspi->s_minfree = fs32_to_cpu(sb, usb1->fs_minfree);
1141 uspi->s_bmask = fs32_to_cpu(sb, usb1->fs_bmask);
1142 uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
1143 uspi->s_bshift = fs32_to_cpu(sb, usb1->fs_bshift);
1144 uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001145 UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi->s_bshift,
1146 uspi->s_fshift);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 uspi->s_fpbshift = fs32_to_cpu(sb, usb1->fs_fragshift);
1148 uspi->s_fsbtodb = fs32_to_cpu(sb, usb1->fs_fsbtodb);
1149 /* s_sbsize already set */
1150 uspi->s_csmask = fs32_to_cpu(sb, usb1->fs_csmask);
1151 uspi->s_csshift = fs32_to_cpu(sb, usb1->fs_csshift);
1152 uspi->s_nindir = fs32_to_cpu(sb, usb1->fs_nindir);
1153 uspi->s_inopb = fs32_to_cpu(sb, usb1->fs_inopb);
1154 uspi->s_nspf = fs32_to_cpu(sb, usb1->fs_nspf);
1155 uspi->s_npsect = ufs_get_fs_npsect(sb, usb1, usb3);
1156 uspi->s_interleave = fs32_to_cpu(sb, usb1->fs_interleave);
1157 uspi->s_trackskew = fs32_to_cpu(sb, usb1->fs_trackskew);
Evgeniy Dushistov3313e292007-02-12 00:54:31 -08001158
1159 if (uspi->fs_magic == UFS2_MAGIC)
1160 uspi->s_csaddr = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_csaddr);
1161 else
1162 uspi->s_csaddr = fs32_to_cpu(sb, usb1->fs_csaddr);
1163
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 uspi->s_cssize = fs32_to_cpu(sb, usb1->fs_cssize);
1165 uspi->s_cgsize = fs32_to_cpu(sb, usb1->fs_cgsize);
1166 uspi->s_ntrak = fs32_to_cpu(sb, usb1->fs_ntrak);
1167 uspi->s_nsect = fs32_to_cpu(sb, usb1->fs_nsect);
1168 uspi->s_spc = fs32_to_cpu(sb, usb1->fs_spc);
1169 uspi->s_ipg = fs32_to_cpu(sb, usb1->fs_ipg);
1170 uspi->s_fpg = fs32_to_cpu(sb, usb1->fs_fpg);
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001171 uspi->s_cpc = fs32_to_cpu(sb, usb2->fs_un.fs_u1.fs_cpc);
1172 uspi->s_contigsumsize = fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_contigsumsize);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 uspi->s_qbmask = ufs_get_fs_qbmask(sb, usb3);
1174 uspi->s_qfmask = ufs_get_fs_qfmask(sb, usb3);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 uspi->s_nrpos = fs32_to_cpu(sb, usb3->fs_nrpos);
1176 uspi->s_postbloff = fs32_to_cpu(sb, usb3->fs_postbloff);
1177 uspi->s_rotbloff = fs32_to_cpu(sb, usb3->fs_rotbloff);
1178
1179 /*
1180 * Compute another frequently used values
1181 */
1182 uspi->s_fpbmask = uspi->s_fpb - 1;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001183 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 uspi->s_apbshift = uspi->s_bshift - 3;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001185 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 uspi->s_apbshift = uspi->s_bshift - 2;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001187
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 uspi->s_2apbshift = uspi->s_apbshift * 2;
1189 uspi->s_3apbshift = uspi->s_apbshift * 3;
1190 uspi->s_apb = 1 << uspi->s_apbshift;
1191 uspi->s_2apb = 1 << uspi->s_2apbshift;
1192 uspi->s_3apb = 1 << uspi->s_3apbshift;
1193 uspi->s_apbmask = uspi->s_apb - 1;
1194 uspi->s_nspfshift = uspi->s_fshift - UFS_SECTOR_BITS;
1195 uspi->s_nspb = uspi->s_nspf << uspi->s_fpbshift;
1196 uspi->s_inopf = uspi->s_inopb >> uspi->s_fpbshift;
1197 uspi->s_bpf = uspi->s_fsize << 3;
1198 uspi->s_bpfshift = uspi->s_fshift + 3;
1199 uspi->s_bpfmask = uspi->s_bpf - 1;
Evgeniy Dushistov90b315a2008-02-08 04:20:16 -08001200 if ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_44BSD ||
1201 (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_UFS2)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 uspi->s_maxsymlinklen =
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001203 fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204
Duane Griffin9e6766c2009-01-08 22:43:48 +00001205 if (uspi->fs_magic == UFS2_MAGIC)
1206 maxsymlen = 2 * 4 * (UFS_NDADDR + UFS_NINDIR);
1207 else
1208 maxsymlen = 4 * (UFS_NDADDR + UFS_NINDIR);
1209 if (uspi->s_maxsymlinklen > maxsymlen) {
1210 ufs_warning(sb, __func__, "ufs_read_super: excessive maximum "
1211 "fast symlink size (%u)\n", uspi->s_maxsymlinklen);
1212 uspi->s_maxsymlinklen = maxsymlen;
1213 }
Al Viro8de52772012-02-06 12:45:27 -05001214 sb->s_max_links = UFS_LINK_MAX;
Duane Griffin9e6766c2009-01-08 22:43:48 +00001215
David Howellsb55c4602008-02-07 00:15:48 -08001216 inode = ufs_iget(sb, UFS_ROOTINO);
1217 if (IS_ERR(inode)) {
1218 ret = PTR_ERR(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 goto failed;
David Howellsb55c4602008-02-07 00:15:48 -08001220 }
Al Viro48fde702012-01-08 22:15:13 -05001221 sb->s_root = d_make_root(inode);
David Howellsb55c4602008-02-07 00:15:48 -08001222 if (!sb->s_root) {
1223 ret = -ENOMEM;
Al Viro48fde702012-01-08 22:15:13 -05001224 goto failed;
David Howellsb55c4602008-02-07 00:15:48 -08001225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001227 ufs_setup_cstotal(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 /*
1229 * Read cylinder group structures
1230 */
1231 if (!(sb->s_flags & MS_RDONLY))
1232 if (!ufs_read_cylinder_structures(sb))
1233 goto failed;
1234
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001235 UFSD("EXIT\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 return 0;
1237
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238failed:
Jesper Juhlf99d49a2005-11-07 01:01:34 -08001239 if (ubh)
1240 ubh_brelse_uspi (uspi);
1241 kfree (uspi);
1242 kfree(sbi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 sb->s_fs_info = NULL;
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001244 UFSD("EXIT (FAILED)\n");
David Howellsb55c4602008-02-07 00:15:48 -08001245 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246
1247failed_nomem:
Evgeniy Dushistovabf5d152006-06-25 05:47:24 -07001248 UFSD("EXIT (NOMEM)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 return -ENOMEM;
1250}
1251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
1253{
1254 struct ufs_sb_private_info * uspi;
1255 struct ufs_super_block_first * usb1;
1256 struct ufs_super_block_third * usb3;
1257 unsigned new_mount_opt, ufstype;
1258 unsigned flags;
Alessio Igor Bogani337eb002009-05-12 15:10:54 +02001259
Theodore Ts'o02b99842014-03-13 10:14:33 -04001260 sync_filesystem(sb);
Fabian Frederickcdd9eef2015-06-10 10:09:32 +10001261 mutex_lock(&UFS_SB(sb)->s_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 uspi = UFS_SB(sb)->s_uspi;
1263 flags = UFS_SB(sb)->s_flags;
Evgeniy7b4ee732006-01-14 11:42:06 +03001264 usb1 = ubh_get_usb_first(uspi);
1265 usb3 = ubh_get_usb_third(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
1267 /*
1268 * Allow the "check" option to be passed as a remount option.
1269 * It is not possible to change ufstype option during remount
1270 */
1271 ufstype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
1272 new_mount_opt = 0;
1273 ufs_set_opt (new_mount_opt, ONERROR_LOCK);
Al Virobbd68512009-05-06 10:43:07 -04001274 if (!ufs_parse_options (data, &new_mount_opt)) {
Fabian Frederickcdd9eef2015-06-10 10:09:32 +10001275 mutex_unlock(&UFS_SB(sb)->s_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 return -EINVAL;
Al Virobbd68512009-05-06 10:43:07 -04001277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 if (!(new_mount_opt & UFS_MOUNT_UFSTYPE)) {
1279 new_mount_opt |= ufstype;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001280 } else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
Fabian Fredericka9814c52014-08-08 14:20:57 -07001281 pr_err("ufstype can't be changed during remount\n");
Fabian Frederickcdd9eef2015-06-10 10:09:32 +10001282 mutex_unlock(&UFS_SB(sb)->s_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 return -EINVAL;
1284 }
1285
1286 if ((*mount_flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY)) {
1287 UFS_SB(sb)->s_mount_opt = new_mount_opt;
Fabian Frederickcdd9eef2015-06-10 10:09:32 +10001288 mutex_unlock(&UFS_SB(sb)->s_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 return 0;
1290 }
1291
1292 /*
1293 * fs was mouted as rw, remounting ro
1294 */
1295 if (*mount_flags & MS_RDONLY) {
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001296 ufs_put_super_internal(sb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 usb1->fs_time = cpu_to_fs32(sb, get_seconds());
1298 if ((flags & UFS_ST_MASK) == UFS_ST_SUN
Mark Fortescue252e2112007-10-16 23:26:31 -07001299 || (flags & UFS_ST_MASK) == UFS_ST_SUNOS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
1301 ufs_set_fs_state(sb, usb1, usb3,
1302 UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
Evgeniy Dushistov9695ef12006-06-25 05:47:22 -07001303 ubh_mark_buffer_dirty (USPI_UBH(uspi));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 sb->s_flags |= MS_RDONLY;
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001305 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 /*
1307 * fs was mounted as ro, remounting rw
1308 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309#ifndef CONFIG_UFS_FS_WRITE
Fabian Fredericka9814c52014-08-08 14:20:57 -07001310 pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
Fabian Frederickcdd9eef2015-06-10 10:09:32 +10001311 mutex_unlock(&UFS_SB(sb)->s_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 return -EINVAL;
1313#else
1314 if (ufstype != UFS_MOUNT_UFSTYPE_SUN &&
Mark Fortescue252e2112007-10-16 23:26:31 -07001315 ufstype != UFS_MOUNT_UFSTYPE_SUNOS &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 ufstype != UFS_MOUNT_UFSTYPE_44BSD &&
Evgeniy Dushistovcbcae392007-02-12 00:54:30 -08001317 ufstype != UFS_MOUNT_UFSTYPE_SUNx86 &&
1318 ufstype != UFS_MOUNT_UFSTYPE_UFS2) {
Fabian Fredericka9814c52014-08-08 14:20:57 -07001319 pr_err("this ufstype is read-only supported\n");
Fabian Frederickcdd9eef2015-06-10 10:09:32 +10001320 mutex_unlock(&UFS_SB(sb)->s_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 return -EINVAL;
1322 }
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001323 if (!ufs_read_cylinder_structures(sb)) {
Fabian Fredericka9814c52014-08-08 14:20:57 -07001324 pr_err("failed during remounting\n");
Fabian Frederickcdd9eef2015-06-10 10:09:32 +10001325 mutex_unlock(&UFS_SB(sb)->s_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 return -EPERM;
1327 }
1328 sb->s_flags &= ~MS_RDONLY;
1329#endif
1330 }
1331 UFS_SB(sb)->s_mount_opt = new_mount_opt;
Fabian Frederickcdd9eef2015-06-10 10:09:32 +10001332 mutex_unlock(&UFS_SB(sb)->s_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 return 0;
1334}
1335
Al Viro34c80b12011-12-08 21:32:45 -05001336static int ufs_show_options(struct seq_file *seq, struct dentry *root)
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -07001337{
Al Viro34c80b12011-12-08 21:32:45 -05001338 struct ufs_sb_info *sbi = UFS_SB(root->d_sb);
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -07001339 unsigned mval = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
Steven Whitehousea447c092008-10-13 10:46:57 +01001340 const struct match_token *tp = tokens;
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -07001341
1342 while (tp->token != Opt_onerror_panic && tp->token != mval)
1343 ++tp;
1344 BUG_ON(tp->token == Opt_onerror_panic);
1345 seq_printf(seq, ",%s", tp->pattern);
1346
1347 mval = sbi->s_mount_opt & UFS_MOUNT_ONERROR;
1348 while (tp->token != Opt_err && tp->token != mval)
1349 ++tp;
1350 BUG_ON(tp->token == Opt_err);
1351 seq_printf(seq, ",%s", tp->pattern);
1352
1353 return 0;
1354}
1355
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001356static int ufs_statfs(struct dentry *dentry, struct kstatfs *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357{
David Howells726c3342006-06-23 02:02:58 -07001358 struct super_block *sb = dentry->d_sb;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001359 struct ufs_sb_private_info *uspi= UFS_SB(sb)->s_uspi;
1360 unsigned flags = UFS_SB(sb)->s_flags;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001361 struct ufs_super_block_third *usb3;
Coly Li41d577a2009-04-02 16:59:44 -07001362 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
Al Virodff7cfd2015-06-16 04:27:05 -04001364 mutex_lock(&UFS_SB(sb)->s_lock);
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001365 usb3 = ubh_get_usb_third(uspi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
1368 buf->f_type = UFS2_MAGIC;
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001369 buf->f_blocks = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize);
Evgeniy Dushistov647b7e82006-06-25 05:47:29 -07001370 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 buf->f_type = UFS_MAGIC;
1372 buf->f_blocks = uspi->s_dsize;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 }
Evgeniy Dushistovee3ffd62006-06-25 05:47:30 -07001374 buf->f_bfree = ufs_blkstofrags(uspi->cs_total.cs_nbfree) +
1375 uspi->cs_total.cs_nffree;
1376 buf->f_ffree = uspi->cs_total.cs_nifree;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 buf->f_bsize = sb->s_blocksize;
1378 buf->f_bavail = (buf->f_bfree > (((long)buf->f_blocks / 100) * uspi->s_minfree))
1379 ? (buf->f_bfree - (((long)buf->f_blocks / 100) * uspi->s_minfree)) : 0;
1380 buf->f_files = uspi->s_ncg * uspi->s_ipg;
1381 buf->f_namelen = UFS_MAXNAMLEN;
Coly Li41d577a2009-04-02 16:59:44 -07001382 buf->f_fsid.val[0] = (u32)id;
1383 buf->f_fsid.val[1] = (u32)(id >> 32);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
Al Virodff7cfd2015-06-16 04:27:05 -04001385 mutex_unlock(&UFS_SB(sb)->s_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
1387 return 0;
1388}
1389
Christoph Lametere18b8902006-12-06 20:33:20 -08001390static struct kmem_cache * ufs_inode_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391
1392static struct inode *ufs_alloc_inode(struct super_block *sb)
1393{
1394 struct ufs_inode_info *ei;
Fabian Frederick61da3ae2015-02-17 13:45:28 -08001395
1396 ei = kmem_cache_alloc(ufs_inode_cachep, GFP_NOFS);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 if (!ei)
1398 return NULL;
Fabian Frederick61da3ae2015-02-17 13:45:28 -08001399
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 ei->vfs_inode.i_version = 1;
Al Viro724bb092015-06-17 12:02:56 -04001401 seqlock_init(&ei->meta_lock);
1402 mutex_init(&ei->truncate_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 return &ei->vfs_inode;
1404}
1405
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +11001406static void ufs_i_callback(struct rcu_head *head)
1407{
1408 struct inode *inode = container_of(head, struct inode, i_rcu);
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +11001409 kmem_cache_free(ufs_inode_cachep, UFS_I(inode));
1410}
1411
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412static void ufs_destroy_inode(struct inode *inode)
1413{
Nick Pigginfa0d7e3d2011-01-07 17:49:49 +11001414 call_rcu(&inode->i_rcu, ufs_i_callback);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415}
1416
Alexey Dobriyan51cc5062008-07-25 19:45:34 -07001417static void init_once(void *foo)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418{
1419 struct ufs_inode_info *ei = (struct ufs_inode_info *) foo;
1420
Christoph Lametera35afb82007-05-16 22:10:57 -07001421 inode_init_once(&ei->vfs_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422}
Paul Mundt20c2df82007-07-20 10:11:58 +09001423
Fabian Frederick76ee4732014-04-07 15:39:55 -07001424static int __init init_inodecache(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425{
1426 ufs_inode_cachep = kmem_cache_create("ufs_inode_cache",
1427 sizeof(struct ufs_inode_info),
Paul Jacksonfffb60f2006-03-24 03:16:06 -08001428 0, (SLAB_RECLAIM_ACCOUNT|
Vladimir Davydov5d097052016-01-14 15:18:21 -08001429 SLAB_MEM_SPREAD|SLAB_ACCOUNT),
Paul Mundt20c2df82007-07-20 10:11:58 +09001430 init_once);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 if (ufs_inode_cachep == NULL)
1432 return -ENOMEM;
1433 return 0;
1434}
1435
1436static void destroy_inodecache(void)
1437{
Kirill A. Shutemov8c0a8532012-09-26 11:33:07 +10001438 /*
1439 * Make sure all delayed rcu free inodes are flushed before we
1440 * destroy cache.
1441 */
1442 rcu_barrier();
Alexey Dobriyan1a1d92c2006-09-27 01:49:40 -07001443 kmem_cache_destroy(ufs_inode_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444}
1445
Josef 'Jeff' Sipekee9b6d62007-02-12 00:55:41 -08001446static const struct super_operations ufs_super_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 .alloc_inode = ufs_alloc_inode,
1448 .destroy_inode = ufs_destroy_inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 .write_inode = ufs_write_inode,
Al Viro58e82682010-06-05 19:40:56 -04001450 .evict_inode = ufs_evict_inode,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 .put_super = ufs_put_super,
Christoph Hellwig8c800652009-06-08 10:08:05 +02001452 .sync_fs = ufs_sync_fs,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 .statfs = ufs_statfs,
1454 .remount_fs = ufs_remount,
Evgeniy Dushistov2a9807c2007-10-16 23:26:32 -07001455 .show_options = ufs_show_options,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456};
1457
Al Viro152a0832010-07-25 00:46:55 +04001458static struct dentry *ufs_mount(struct file_system_type *fs_type,
1459 int flags, const char *dev_name, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460{
Al Viro152a0832010-07-25 00:46:55 +04001461 return mount_bdev(fs_type, flags, dev_name, data, ufs_fill_super);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462}
1463
1464static struct file_system_type ufs_fs_type = {
1465 .owner = THIS_MODULE,
1466 .name = "ufs",
Al Viro152a0832010-07-25 00:46:55 +04001467 .mount = ufs_mount,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 .kill_sb = kill_block_super,
1469 .fs_flags = FS_REQUIRES_DEV,
1470};
Eric W. Biederman7f78e032013-03-02 19:39:14 -08001471MODULE_ALIAS_FS("ufs");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
1473static int __init init_ufs_fs(void)
1474{
1475 int err = init_inodecache();
1476 if (err)
1477 goto out1;
1478 err = register_filesystem(&ufs_fs_type);
1479 if (err)
1480 goto out;
1481 return 0;
1482out:
1483 destroy_inodecache();
1484out1:
1485 return err;
1486}
1487
1488static void __exit exit_ufs_fs(void)
1489{
1490 unregister_filesystem(&ufs_fs_type);
1491 destroy_inodecache();
1492}
1493
1494module_init(init_ufs_fs)
1495module_exit(exit_ufs_fs)
1496MODULE_LICENSE("GPL");