super.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  1. /*
  2. * linux/fs/ufs/super.c
  3. *
  4. * Copyright (C) 1998
  5. * Daniel Pirkl <daniel.pirkl@email.cz>
  6. * Charles University, Faculty of Mathematics and Physics
  7. */
  8. /* Derived from
  9. *
  10. * linux/fs/ext2/super.c
  11. *
  12. * Copyright (C) 1992, 1993, 1994, 1995
  13. * Remy Card (card@masi.ibp.fr)
  14. * Laboratoire MASI - Institut Blaise Pascal
  15. * Universite Pierre et Marie Curie (Paris VI)
  16. *
  17. * from
  18. *
  19. * linux/fs/minix/inode.c
  20. *
  21. * Copyright (C) 1991, 1992 Linus Torvalds
  22. *
  23. * Big-endian to little-endian byte-swapping/bitmaps by
  24. * David S. Miller (davem@caip.rutgers.edu), 1995
  25. */
  26. /*
  27. * Inspired by
  28. *
  29. * linux/fs/ufs/super.c
  30. *
  31. * Copyright (C) 1996
  32. * Adrian Rodriguez (adrian@franklins-tower.rutgers.edu)
  33. * Laboratory for Computer Science Research Computing Facility
  34. * Rutgers, The State University of New Jersey
  35. *
  36. * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
  37. *
  38. * Kernel module support added on 96/04/26 by
  39. * Stefan Reinauer <stepan@home.culture.mipt.ru>
  40. *
  41. * Module usage counts added on 96/04/29 by
  42. * Gertjan van Wingerde <gwingerde@gmail.com>
  43. *
  44. * Clean swab support on 19970406 by
  45. * Francois-Rene Rideau <fare@tunes.org>
  46. *
  47. * 4.4BSD (FreeBSD) support added on February 1st 1998 by
  48. * Niels Kristian Bech Jensen <nkbj@image.dk> partially based
  49. * on code by Martin von Loewis <martin@mira.isdn.cs.tu-berlin.de>.
  50. *
  51. * NeXTstep support added on February 5th 1998 by
  52. * Niels Kristian Bech Jensen <nkbj@image.dk>.
  53. *
  54. * write support Daniel Pirkl <daniel.pirkl@email.cz> 1998
  55. *
  56. * HP/UX hfs filesystem support added by
  57. * Martin K. Petersen <mkp@mkp.net>, August 1999
  58. *
  59. * UFS2 (of FreeBSD 5.x) support added by
  60. * Niraj Kumar <niraj17@iitbombay.org>, Jan 2004
  61. *
  62. * UFS2 write support added by
  63. * Evgeniy Dushistov <dushistov@mail.ru>, 2007
  64. */
  65. #include <linux/exportfs.h>
  66. #include <linux/module.h>
  67. #include <linux/bitops.h>
  68. #include <stdarg.h>
  69. #include <linux/uaccess.h>
  70. #include <linux/errno.h>
  71. #include <linux/fs.h>
  72. #include <linux/slab.h>
  73. #include <linux/time.h>
  74. #include <linux/stat.h>
  75. #include <linux/string.h>
  76. #include <linux/blkdev.h>
  77. #include <linux/backing-dev.h>
  78. #include <linux/init.h>
  79. #include <linux/parser.h>
  80. #include <linux/buffer_head.h>
  81. #include <linux/vfs.h>
  82. #include <linux/log2.h>
  83. #include <linux/mount.h>
  84. #include <linux/seq_file.h>
  85. #include <linux/iversion.h>
  86. #include "ufs_fs.h"
  87. #include "ufs.h"
  88. #include "swab.h"
  89. #include "util.h"
  90. static struct inode *ufs_nfs_get_inode(struct super_block *sb, u64 ino, u32 generation)
  91. {
  92. struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
  93. struct inode *inode;
  94. if (ino < UFS_ROOTINO || ino > uspi->s_ncg * uspi->s_ipg)
  95. return ERR_PTR(-ESTALE);
  96. inode = ufs_iget(sb, ino);
  97. if (IS_ERR(inode))
  98. return ERR_CAST(inode);
  99. if (generation && inode->i_generation != generation) {
  100. iput(inode);
  101. return ERR_PTR(-ESTALE);
  102. }
  103. return inode;
  104. }
  105. static struct dentry *ufs_fh_to_dentry(struct super_block *sb, struct fid *fid,
  106. int fh_len, int fh_type)
  107. {
  108. return generic_fh_to_dentry(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
  109. }
  110. static struct dentry *ufs_fh_to_parent(struct super_block *sb, struct fid *fid,
  111. int fh_len, int fh_type)
  112. {
  113. return generic_fh_to_parent(sb, fid, fh_len, fh_type, ufs_nfs_get_inode);
  114. }
  115. static struct dentry *ufs_get_parent(struct dentry *child)
  116. {
  117. struct qstr dot_dot = QSTR_INIT("..", 2);
  118. ino_t ino;
  119. ino = ufs_inode_by_name(d_inode(child), &dot_dot);
  120. if (!ino)
  121. return ERR_PTR(-ENOENT);
  122. return d_obtain_alias(ufs_iget(child->d_sb, ino));
  123. }
  124. static const struct export_operations ufs_export_ops = {
  125. .fh_to_dentry = ufs_fh_to_dentry,
  126. .fh_to_parent = ufs_fh_to_parent,
  127. .get_parent = ufs_get_parent,
  128. };
  129. #ifdef CONFIG_UFS_DEBUG
  130. /*
  131. * Print contents of ufs_super_block, useful for debugging
  132. */
  133. static void ufs_print_super_stuff(struct super_block *sb,
  134. struct ufs_super_block_first *usb1,
  135. struct ufs_super_block_second *usb2,
  136. struct ufs_super_block_third *usb3)
  137. {
  138. u32 magic = fs32_to_cpu(sb, usb3->fs_magic);
  139. pr_debug("ufs_print_super_stuff\n");
  140. pr_debug(" magic: 0x%x\n", magic);
  141. if (fs32_to_cpu(sb, usb3->fs_magic) == UFS2_MAGIC) {
  142. pr_debug(" fs_size: %llu\n", (unsigned long long)
  143. fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size));
  144. pr_debug(" fs_dsize: %llu\n", (unsigned long long)
  145. fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize));
  146. pr_debug(" bsize: %u\n",
  147. fs32_to_cpu(sb, usb1->fs_bsize));
  148. pr_debug(" fsize: %u\n",
  149. fs32_to_cpu(sb, usb1->fs_fsize));
  150. pr_debug(" fs_volname: %s\n", usb2->fs_un.fs_u2.fs_volname);
  151. pr_debug(" fs_sblockloc: %llu\n", (unsigned long long)
  152. fs64_to_cpu(sb, usb2->fs_un.fs_u2.fs_sblockloc));
  153. pr_debug(" cs_ndir(No of dirs): %llu\n", (unsigned long long)
  154. fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir));
  155. pr_debug(" cs_nbfree(No of free blocks): %llu\n",
  156. (unsigned long long)
  157. fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree));
  158. pr_info(" cs_nifree(Num of free inodes): %llu\n",
  159. (unsigned long long)
  160. fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree));
  161. pr_info(" cs_nffree(Num of free frags): %llu\n",
  162. (unsigned long long)
  163. fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree));
  164. pr_info(" fs_maxsymlinklen: %u\n",
  165. fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen));
  166. } else {
  167. pr_debug(" sblkno: %u\n", fs32_to_cpu(sb, usb1->fs_sblkno));
  168. pr_debug(" cblkno: %u\n", fs32_to_cpu(sb, usb1->fs_cblkno));
  169. pr_debug(" iblkno: %u\n", fs32_to_cpu(sb, usb1->fs_iblkno));
  170. pr_debug(" dblkno: %u\n", fs32_to_cpu(sb, usb1->fs_dblkno));
  171. pr_debug(" cgoffset: %u\n",
  172. fs32_to_cpu(sb, usb1->fs_cgoffset));
  173. pr_debug(" ~cgmask: 0x%x\n",
  174. ~fs32_to_cpu(sb, usb1->fs_cgmask));
  175. pr_debug(" size: %u\n", fs32_to_cpu(sb, usb1->fs_size));
  176. pr_debug(" dsize: %u\n", fs32_to_cpu(sb, usb1->fs_dsize));
  177. pr_debug(" ncg: %u\n", fs32_to_cpu(sb, usb1->fs_ncg));
  178. pr_debug(" bsize: %u\n", fs32_to_cpu(sb, usb1->fs_bsize));
  179. pr_debug(" fsize: %u\n", fs32_to_cpu(sb, usb1->fs_fsize));
  180. pr_debug(" frag: %u\n", fs32_to_cpu(sb, usb1->fs_frag));
  181. pr_debug(" fragshift: %u\n",
  182. fs32_to_cpu(sb, usb1->fs_fragshift));
  183. pr_debug(" ~fmask: %u\n", ~fs32_to_cpu(sb, usb1->fs_fmask));
  184. pr_debug(" fshift: %u\n", fs32_to_cpu(sb, usb1->fs_fshift));
  185. pr_debug(" sbsize: %u\n", fs32_to_cpu(sb, usb1->fs_sbsize));
  186. pr_debug(" spc: %u\n", fs32_to_cpu(sb, usb1->fs_spc));
  187. pr_debug(" cpg: %u\n", fs32_to_cpu(sb, usb1->fs_cpg));
  188. pr_debug(" ipg: %u\n", fs32_to_cpu(sb, usb1->fs_ipg));
  189. pr_debug(" fpg: %u\n", fs32_to_cpu(sb, usb1->fs_fpg));
  190. pr_debug(" csaddr: %u\n", fs32_to_cpu(sb, usb1->fs_csaddr));
  191. pr_debug(" cssize: %u\n", fs32_to_cpu(sb, usb1->fs_cssize));
  192. pr_debug(" cgsize: %u\n", fs32_to_cpu(sb, usb1->fs_cgsize));
  193. pr_debug(" fstodb: %u\n",
  194. fs32_to_cpu(sb, usb1->fs_fsbtodb));
  195. pr_debug(" nrpos: %u\n", fs32_to_cpu(sb, usb3->fs_nrpos));
  196. pr_debug(" ndir %u\n",
  197. fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir));
  198. pr_debug(" nifree %u\n",
  199. fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree));
  200. pr_debug(" nbfree %u\n",
  201. fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree));
  202. pr_debug(" nffree %u\n",
  203. fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree));
  204. }
  205. pr_debug("\n");
  206. }
  207. /*
  208. * Print contents of ufs_cylinder_group, useful for debugging
  209. */
  210. static void ufs_print_cylinder_stuff(struct super_block *sb,
  211. struct ufs_cylinder_group *cg)
  212. {
  213. pr_debug("\nufs_print_cylinder_stuff\n");
  214. pr_debug("size of ucg: %zu\n", sizeof(struct ufs_cylinder_group));
  215. pr_debug(" magic: %x\n", fs32_to_cpu(sb, cg->cg_magic));
  216. pr_debug(" time: %u\n", fs32_to_cpu(sb, cg->cg_time));
  217. pr_debug(" cgx: %u\n", fs32_to_cpu(sb, cg->cg_cgx));
  218. pr_debug(" ncyl: %u\n", fs16_to_cpu(sb, cg->cg_ncyl));
  219. pr_debug(" niblk: %u\n", fs16_to_cpu(sb, cg->cg_niblk));
  220. pr_debug(" ndblk: %u\n", fs32_to_cpu(sb, cg->cg_ndblk));
  221. pr_debug(" cs_ndir: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_ndir));
  222. pr_debug(" cs_nbfree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nbfree));
  223. pr_debug(" cs_nifree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nifree));
  224. pr_debug(" cs_nffree: %u\n", fs32_to_cpu(sb, cg->cg_cs.cs_nffree));
  225. pr_debug(" rotor: %u\n", fs32_to_cpu(sb, cg->cg_rotor));
  226. pr_debug(" frotor: %u\n", fs32_to_cpu(sb, cg->cg_frotor));
  227. pr_debug(" irotor: %u\n", fs32_to_cpu(sb, cg->cg_irotor));
  228. pr_debug(" frsum: %u, %u, %u, %u, %u, %u, %u, %u\n",
  229. fs32_to_cpu(sb, cg->cg_frsum[0]), fs32_to_cpu(sb, cg->cg_frsum[1]),
  230. fs32_to_cpu(sb, cg->cg_frsum[2]), fs32_to_cpu(sb, cg->cg_frsum[3]),
  231. fs32_to_cpu(sb, cg->cg_frsum[4]), fs32_to_cpu(sb, cg->cg_frsum[5]),
  232. fs32_to_cpu(sb, cg->cg_frsum[6]), fs32_to_cpu(sb, cg->cg_frsum[7]));
  233. pr_debug(" btotoff: %u\n", fs32_to_cpu(sb, cg->cg_btotoff));
  234. pr_debug(" boff: %u\n", fs32_to_cpu(sb, cg->cg_boff));
  235. pr_debug(" iuseoff: %u\n", fs32_to_cpu(sb, cg->cg_iusedoff));
  236. pr_debug(" freeoff: %u\n", fs32_to_cpu(sb, cg->cg_freeoff));
  237. pr_debug(" nextfreeoff: %u\n", fs32_to_cpu(sb, cg->cg_nextfreeoff));
  238. pr_debug(" clustersumoff %u\n",
  239. fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clustersumoff));
  240. pr_debug(" clusteroff %u\n",
  241. fs32_to_cpu(sb, cg->cg_u.cg_44.cg_clusteroff));
  242. pr_debug(" nclusterblks %u\n",
  243. fs32_to_cpu(sb, cg->cg_u.cg_44.cg_nclusterblks));
  244. pr_debug("\n");
  245. }
  246. #else
  247. # define ufs_print_super_stuff(sb, usb1, usb2, usb3) /**/
  248. # define ufs_print_cylinder_stuff(sb, cg) /**/
  249. #endif /* CONFIG_UFS_DEBUG */
  250. static const struct super_operations ufs_super_ops;
  251. void ufs_error (struct super_block * sb, const char * function,
  252. const char * fmt, ...)
  253. {
  254. struct ufs_sb_private_info * uspi;
  255. struct ufs_super_block_first * usb1;
  256. struct va_format vaf;
  257. va_list args;
  258. uspi = UFS_SB(sb)->s_uspi;
  259. usb1 = ubh_get_usb_first(uspi);
  260. if (!sb_rdonly(sb)) {
  261. usb1->fs_clean = UFS_FSBAD;
  262. ubh_mark_buffer_dirty(USPI_UBH(uspi));
  263. ufs_mark_sb_dirty(sb);
  264. sb->s_flags |= SB_RDONLY;
  265. }
  266. va_start(args, fmt);
  267. vaf.fmt = fmt;
  268. vaf.va = &args;
  269. switch (UFS_SB(sb)->s_mount_opt & UFS_MOUNT_ONERROR) {
  270. case UFS_MOUNT_ONERROR_PANIC:
  271. panic("panic (device %s): %s: %pV\n",
  272. sb->s_id, function, &vaf);
  273. case UFS_MOUNT_ONERROR_LOCK:
  274. case UFS_MOUNT_ONERROR_UMOUNT:
  275. case UFS_MOUNT_ONERROR_REPAIR:
  276. pr_crit("error (device %s): %s: %pV\n",
  277. sb->s_id, function, &vaf);
  278. }
  279. va_end(args);
  280. }
  281. void ufs_panic (struct super_block * sb, const char * function,
  282. const char * fmt, ...)
  283. {
  284. struct ufs_sb_private_info * uspi;
  285. struct ufs_super_block_first * usb1;
  286. struct va_format vaf;
  287. va_list args;
  288. uspi = UFS_SB(sb)->s_uspi;
  289. usb1 = ubh_get_usb_first(uspi);
  290. if (!sb_rdonly(sb)) {
  291. usb1->fs_clean = UFS_FSBAD;
  292. ubh_mark_buffer_dirty(USPI_UBH(uspi));
  293. ufs_mark_sb_dirty(sb);
  294. }
  295. va_start(args, fmt);
  296. vaf.fmt = fmt;
  297. vaf.va = &args;
  298. sb->s_flags |= SB_RDONLY;
  299. pr_crit("panic (device %s): %s: %pV\n",
  300. sb->s_id, function, &vaf);
  301. va_end(args);
  302. }
  303. void ufs_warning (struct super_block * sb, const char * function,
  304. const char * fmt, ...)
  305. {
  306. struct va_format vaf;
  307. va_list args;
  308. va_start(args, fmt);
  309. vaf.fmt = fmt;
  310. vaf.va = &args;
  311. pr_warn("(device %s): %s: %pV\n",
  312. sb->s_id, function, &vaf);
  313. va_end(args);
  314. }
  315. enum {
  316. Opt_type_old = UFS_MOUNT_UFSTYPE_OLD,
  317. Opt_type_sunx86 = UFS_MOUNT_UFSTYPE_SUNx86,
  318. Opt_type_sun = UFS_MOUNT_UFSTYPE_SUN,
  319. Opt_type_sunos = UFS_MOUNT_UFSTYPE_SUNOS,
  320. Opt_type_44bsd = UFS_MOUNT_UFSTYPE_44BSD,
  321. Opt_type_ufs2 = UFS_MOUNT_UFSTYPE_UFS2,
  322. Opt_type_hp = UFS_MOUNT_UFSTYPE_HP,
  323. Opt_type_nextstepcd = UFS_MOUNT_UFSTYPE_NEXTSTEP_CD,
  324. Opt_type_nextstep = UFS_MOUNT_UFSTYPE_NEXTSTEP,
  325. Opt_type_openstep = UFS_MOUNT_UFSTYPE_OPENSTEP,
  326. Opt_onerror_panic = UFS_MOUNT_ONERROR_PANIC,
  327. Opt_onerror_lock = UFS_MOUNT_ONERROR_LOCK,
  328. Opt_onerror_umount = UFS_MOUNT_ONERROR_UMOUNT,
  329. Opt_onerror_repair = UFS_MOUNT_ONERROR_REPAIR,
  330. Opt_err
  331. };
  332. static const match_table_t tokens = {
  333. {Opt_type_old, "ufstype=old"},
  334. {Opt_type_sunx86, "ufstype=sunx86"},
  335. {Opt_type_sun, "ufstype=sun"},
  336. {Opt_type_sunos, "ufstype=sunos"},
  337. {Opt_type_44bsd, "ufstype=44bsd"},
  338. {Opt_type_ufs2, "ufstype=ufs2"},
  339. {Opt_type_ufs2, "ufstype=5xbsd"},
  340. {Opt_type_hp, "ufstype=hp"},
  341. {Opt_type_nextstepcd, "ufstype=nextstep-cd"},
  342. {Opt_type_nextstep, "ufstype=nextstep"},
  343. {Opt_type_openstep, "ufstype=openstep"},
  344. /*end of possible ufs types */
  345. {Opt_onerror_panic, "onerror=panic"},
  346. {Opt_onerror_lock, "onerror=lock"},
  347. {Opt_onerror_umount, "onerror=umount"},
  348. {Opt_onerror_repair, "onerror=repair"},
  349. {Opt_err, NULL}
  350. };
  351. static int ufs_parse_options (char * options, unsigned * mount_options)
  352. {
  353. char * p;
  354. UFSD("ENTER\n");
  355. if (!options)
  356. return 1;
  357. while ((p = strsep(&options, ",")) != NULL) {
  358. substring_t args[MAX_OPT_ARGS];
  359. int token;
  360. if (!*p)
  361. continue;
  362. token = match_token(p, tokens, args);
  363. switch (token) {
  364. case Opt_type_old:
  365. ufs_clear_opt (*mount_options, UFSTYPE);
  366. ufs_set_opt (*mount_options, UFSTYPE_OLD);
  367. break;
  368. case Opt_type_sunx86:
  369. ufs_clear_opt (*mount_options, UFSTYPE);
  370. ufs_set_opt (*mount_options, UFSTYPE_SUNx86);
  371. break;
  372. case Opt_type_sun:
  373. ufs_clear_opt (*mount_options, UFSTYPE);
  374. ufs_set_opt (*mount_options, UFSTYPE_SUN);
  375. break;
  376. case Opt_type_sunos:
  377. ufs_clear_opt(*mount_options, UFSTYPE);
  378. ufs_set_opt(*mount_options, UFSTYPE_SUNOS);
  379. break;
  380. case Opt_type_44bsd:
  381. ufs_clear_opt (*mount_options, UFSTYPE);
  382. ufs_set_opt (*mount_options, UFSTYPE_44BSD);
  383. break;
  384. case Opt_type_ufs2:
  385. ufs_clear_opt(*mount_options, UFSTYPE);
  386. ufs_set_opt(*mount_options, UFSTYPE_UFS2);
  387. break;
  388. case Opt_type_hp:
  389. ufs_clear_opt (*mount_options, UFSTYPE);
  390. ufs_set_opt (*mount_options, UFSTYPE_HP);
  391. break;
  392. case Opt_type_nextstepcd:
  393. ufs_clear_opt (*mount_options, UFSTYPE);
  394. ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP_CD);
  395. break;
  396. case Opt_type_nextstep:
  397. ufs_clear_opt (*mount_options, UFSTYPE);
  398. ufs_set_opt (*mount_options, UFSTYPE_NEXTSTEP);
  399. break;
  400. case Opt_type_openstep:
  401. ufs_clear_opt (*mount_options, UFSTYPE);
  402. ufs_set_opt (*mount_options, UFSTYPE_OPENSTEP);
  403. break;
  404. case Opt_onerror_panic:
  405. ufs_clear_opt (*mount_options, ONERROR);
  406. ufs_set_opt (*mount_options, ONERROR_PANIC);
  407. break;
  408. case Opt_onerror_lock:
  409. ufs_clear_opt (*mount_options, ONERROR);
  410. ufs_set_opt (*mount_options, ONERROR_LOCK);
  411. break;
  412. case Opt_onerror_umount:
  413. ufs_clear_opt (*mount_options, ONERROR);
  414. ufs_set_opt (*mount_options, ONERROR_UMOUNT);
  415. break;
  416. case Opt_onerror_repair:
  417. pr_err("Unable to do repair on error, will lock lock instead\n");
  418. ufs_clear_opt (*mount_options, ONERROR);
  419. ufs_set_opt (*mount_options, ONERROR_REPAIR);
  420. break;
  421. default:
  422. pr_err("Invalid option: \"%s\" or missing value\n", p);
  423. return 0;
  424. }
  425. }
  426. return 1;
  427. }
  428. /*
  429. * Different types of UFS hold fs_cstotal in different
  430. * places, and use different data structure for it.
  431. * To make things simpler we just copy fs_cstotal to ufs_sb_private_info
  432. */
  433. static void ufs_setup_cstotal(struct super_block *sb)
  434. {
  435. struct ufs_sb_info *sbi = UFS_SB(sb);
  436. struct ufs_sb_private_info *uspi = sbi->s_uspi;
  437. struct ufs_super_block_first *usb1;
  438. struct ufs_super_block_second *usb2;
  439. struct ufs_super_block_third *usb3;
  440. unsigned mtype = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
  441. UFSD("ENTER, mtype=%u\n", mtype);
  442. usb1 = ubh_get_usb_first(uspi);
  443. usb2 = ubh_get_usb_second(uspi);
  444. usb3 = ubh_get_usb_third(uspi);
  445. if ((mtype == UFS_MOUNT_UFSTYPE_44BSD &&
  446. (usb2->fs_un.fs_u2.fs_maxbsize == usb1->fs_bsize)) ||
  447. mtype == UFS_MOUNT_UFSTYPE_UFS2) {
  448. /*we have statistic in different place, then usual*/
  449. uspi->cs_total.cs_ndir = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_ndir);
  450. uspi->cs_total.cs_nbfree = fs64_to_cpu(sb, usb2->fs_un.fs_u2.cs_nbfree);
  451. uspi->cs_total.cs_nifree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nifree);
  452. uspi->cs_total.cs_nffree = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.cs_nffree);
  453. } else {
  454. uspi->cs_total.cs_ndir = fs32_to_cpu(sb, usb1->fs_cstotal.cs_ndir);
  455. uspi->cs_total.cs_nbfree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nbfree);
  456. uspi->cs_total.cs_nifree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nifree);
  457. uspi->cs_total.cs_nffree = fs32_to_cpu(sb, usb1->fs_cstotal.cs_nffree);
  458. }
  459. UFSD("EXIT\n");
  460. }
  461. /*
  462. * Read on-disk structures associated with cylinder groups
  463. */
  464. static int ufs_read_cylinder_structures(struct super_block *sb)
  465. {
  466. struct ufs_sb_info *sbi = UFS_SB(sb);
  467. struct ufs_sb_private_info *uspi = sbi->s_uspi;
  468. struct ufs_buffer_head * ubh;
  469. unsigned char * base, * space;
  470. unsigned size, blks, i;
  471. UFSD("ENTER\n");
  472. /*
  473. * Read cs structures from (usually) first data block
  474. * on the device.
  475. */
  476. size = uspi->s_cssize;
  477. blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
  478. base = space = kmalloc(size, GFP_NOFS);
  479. if (!base)
  480. goto failed;
  481. sbi->s_csp = (struct ufs_csum *)space;
  482. for (i = 0; i < blks; i += uspi->s_fpb) {
  483. size = uspi->s_bsize;
  484. if (i + uspi->s_fpb > blks)
  485. size = (blks - i) * uspi->s_fsize;
  486. ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
  487. if (!ubh)
  488. goto failed;
  489. ubh_ubhcpymem (space, ubh, size);
  490. space += size;
  491. ubh_brelse (ubh);
  492. ubh = NULL;
  493. }
  494. /*
  495. * Read cylinder group (we read only first fragment from block
  496. * at this time) and prepare internal data structures for cg caching.
  497. */
  498. sbi->s_ucg = kmalloc_array(uspi->s_ncg, sizeof(struct buffer_head *),
  499. GFP_NOFS);
  500. if (!sbi->s_ucg)
  501. goto failed;
  502. for (i = 0; i < uspi->s_ncg; i++)
  503. sbi->s_ucg[i] = NULL;
  504. for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
  505. sbi->s_ucpi[i] = NULL;
  506. sbi->s_cgno[i] = UFS_CGNO_EMPTY;
  507. }
  508. for (i = 0; i < uspi->s_ncg; i++) {
  509. UFSD("read cg %u\n", i);
  510. if (!(sbi->s_ucg[i] = sb_bread(sb, ufs_cgcmin(i))))
  511. goto failed;
  512. if (!ufs_cg_chkmagic (sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data))
  513. goto failed;
  514. ufs_print_cylinder_stuff(sb, (struct ufs_cylinder_group *) sbi->s_ucg[i]->b_data);
  515. }
  516. for (i = 0; i < UFS_MAX_GROUP_LOADED; i++) {
  517. if (!(sbi->s_ucpi[i] = kmalloc (sizeof(struct ufs_cg_private_info), GFP_NOFS)))
  518. goto failed;
  519. sbi->s_cgno[i] = UFS_CGNO_EMPTY;
  520. }
  521. sbi->s_cg_loaded = 0;
  522. UFSD("EXIT\n");
  523. return 1;
  524. failed:
  525. kfree (base);
  526. if (sbi->s_ucg) {
  527. for (i = 0; i < uspi->s_ncg; i++)
  528. if (sbi->s_ucg[i])
  529. brelse (sbi->s_ucg[i]);
  530. kfree (sbi->s_ucg);
  531. for (i = 0; i < UFS_MAX_GROUP_LOADED; i++)
  532. kfree (sbi->s_ucpi[i]);
  533. }
  534. UFSD("EXIT (FAILED)\n");
  535. return 0;
  536. }
  537. /*
  538. * Sync our internal copy of fs_cstotal with disk
  539. */
  540. static void ufs_put_cstotal(struct super_block *sb)
  541. {
  542. unsigned mtype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
  543. struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
  544. struct ufs_super_block_first *usb1;
  545. struct ufs_super_block_second *usb2;
  546. struct ufs_super_block_third *usb3;
  547. UFSD("ENTER\n");
  548. usb1 = ubh_get_usb_first(uspi);
  549. usb2 = ubh_get_usb_second(uspi);
  550. usb3 = ubh_get_usb_third(uspi);
  551. if (mtype == UFS_MOUNT_UFSTYPE_UFS2) {
  552. /*we have statistic in different place, then usual*/
  553. usb2->fs_un.fs_u2.cs_ndir =
  554. cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
  555. usb2->fs_un.fs_u2.cs_nbfree =
  556. cpu_to_fs64(sb, uspi->cs_total.cs_nbfree);
  557. usb3->fs_un1.fs_u2.cs_nifree =
  558. cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
  559. usb3->fs_un1.fs_u2.cs_nffree =
  560. cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
  561. goto out;
  562. }
  563. if (mtype == UFS_MOUNT_UFSTYPE_44BSD &&
  564. (usb2->fs_un.fs_u2.fs_maxbsize == usb1->fs_bsize)) {
  565. /* store stats in both old and new places */
  566. usb2->fs_un.fs_u2.cs_ndir =
  567. cpu_to_fs64(sb, uspi->cs_total.cs_ndir);
  568. usb2->fs_un.fs_u2.cs_nbfree =
  569. cpu_to_fs64(sb, uspi->cs_total.cs_nbfree);
  570. usb3->fs_un1.fs_u2.cs_nifree =
  571. cpu_to_fs64(sb, uspi->cs_total.cs_nifree);
  572. usb3->fs_un1.fs_u2.cs_nffree =
  573. cpu_to_fs64(sb, uspi->cs_total.cs_nffree);
  574. }
  575. usb1->fs_cstotal.cs_ndir = cpu_to_fs32(sb, uspi->cs_total.cs_ndir);
  576. usb1->fs_cstotal.cs_nbfree = cpu_to_fs32(sb, uspi->cs_total.cs_nbfree);
  577. usb1->fs_cstotal.cs_nifree = cpu_to_fs32(sb, uspi->cs_total.cs_nifree);
  578. usb1->fs_cstotal.cs_nffree = cpu_to_fs32(sb, uspi->cs_total.cs_nffree);
  579. out:
  580. ubh_mark_buffer_dirty(USPI_UBH(uspi));
  581. ufs_print_super_stuff(sb, usb1, usb2, usb3);
  582. UFSD("EXIT\n");
  583. }
  584. /**
  585. * ufs_put_super_internal() - put on-disk intrenal structures
  586. * @sb: pointer to super_block structure
  587. * Put on-disk structures associated with cylinder groups
  588. * and write them back to disk, also update cs_total on disk
  589. */
  590. static void ufs_put_super_internal(struct super_block *sb)
  591. {
  592. struct ufs_sb_info *sbi = UFS_SB(sb);
  593. struct ufs_sb_private_info *uspi = sbi->s_uspi;
  594. struct ufs_buffer_head * ubh;
  595. unsigned char * base, * space;
  596. unsigned blks, size, i;
  597. UFSD("ENTER\n");
  598. ufs_put_cstotal(sb);
  599. size = uspi->s_cssize;
  600. blks = (size + uspi->s_fsize - 1) >> uspi->s_fshift;
  601. base = space = (char*) sbi->s_csp;
  602. for (i = 0; i < blks; i += uspi->s_fpb) {
  603. size = uspi->s_bsize;
  604. if (i + uspi->s_fpb > blks)
  605. size = (blks - i) * uspi->s_fsize;
  606. ubh = ubh_bread(sb, uspi->s_csaddr + i, size);
  607. ubh_memcpyubh (ubh, space, size);
  608. space += size;
  609. ubh_mark_buffer_uptodate (ubh, 1);
  610. ubh_mark_buffer_dirty (ubh);
  611. ubh_brelse (ubh);
  612. }
  613. for (i = 0; i < sbi->s_cg_loaded; i++) {
  614. ufs_put_cylinder (sb, i);
  615. kfree (sbi->s_ucpi[i]);
  616. }
  617. for (; i < UFS_MAX_GROUP_LOADED; i++)
  618. kfree (sbi->s_ucpi[i]);
  619. for (i = 0; i < uspi->s_ncg; i++)
  620. brelse (sbi->s_ucg[i]);
  621. kfree (sbi->s_ucg);
  622. kfree (base);
  623. UFSD("EXIT\n");
  624. }
  625. static int ufs_sync_fs(struct super_block *sb, int wait)
  626. {
  627. struct ufs_sb_private_info * uspi;
  628. struct ufs_super_block_first * usb1;
  629. struct ufs_super_block_third * usb3;
  630. unsigned flags;
  631. mutex_lock(&UFS_SB(sb)->s_lock);
  632. UFSD("ENTER\n");
  633. flags = UFS_SB(sb)->s_flags;
  634. uspi = UFS_SB(sb)->s_uspi;
  635. usb1 = ubh_get_usb_first(uspi);
  636. usb3 = ubh_get_usb_third(uspi);
  637. usb1->fs_time = ufs_get_seconds(sb);
  638. if ((flags & UFS_ST_MASK) == UFS_ST_SUN ||
  639. (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
  640. (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
  641. ufs_set_fs_state(sb, usb1, usb3,
  642. UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
  643. ufs_put_cstotal(sb);
  644. UFSD("EXIT\n");
  645. mutex_unlock(&UFS_SB(sb)->s_lock);
  646. return 0;
  647. }
  648. static void delayed_sync_fs(struct work_struct *work)
  649. {
  650. struct ufs_sb_info *sbi;
  651. sbi = container_of(work, struct ufs_sb_info, sync_work.work);
  652. spin_lock(&sbi->work_lock);
  653. sbi->work_queued = 0;
  654. spin_unlock(&sbi->work_lock);
  655. ufs_sync_fs(sbi->sb, 1);
  656. }
  657. void ufs_mark_sb_dirty(struct super_block *sb)
  658. {
  659. struct ufs_sb_info *sbi = UFS_SB(sb);
  660. unsigned long delay;
  661. spin_lock(&sbi->work_lock);
  662. if (!sbi->work_queued) {
  663. delay = msecs_to_jiffies(dirty_writeback_interval * 10);
  664. queue_delayed_work(system_long_wq, &sbi->sync_work, delay);
  665. sbi->work_queued = 1;
  666. }
  667. spin_unlock(&sbi->work_lock);
  668. }
  669. static void ufs_put_super(struct super_block *sb)
  670. {
  671. struct ufs_sb_info * sbi = UFS_SB(sb);
  672. UFSD("ENTER\n");
  673. if (!sb_rdonly(sb))
  674. ufs_put_super_internal(sb);
  675. cancel_delayed_work_sync(&sbi->sync_work);
  676. ubh_brelse_uspi (sbi->s_uspi);
  677. kfree (sbi->s_uspi);
  678. kfree (sbi);
  679. sb->s_fs_info = NULL;
  680. UFSD("EXIT\n");
  681. return;
  682. }
  683. static u64 ufs_max_bytes(struct super_block *sb)
  684. {
  685. struct ufs_sb_private_info *uspi = UFS_SB(sb)->s_uspi;
  686. int bits = uspi->s_apbshift;
  687. u64 res;
  688. if (bits > 21)
  689. res = ~0ULL;
  690. else
  691. res = UFS_NDADDR + (1LL << bits) + (1LL << (2*bits)) +
  692. (1LL << (3*bits));
  693. if (res >= (MAX_LFS_FILESIZE >> uspi->s_bshift))
  694. return MAX_LFS_FILESIZE;
  695. return res << uspi->s_bshift;
  696. }
  697. static int ufs_fill_super(struct super_block *sb, void *data, int silent)
  698. {
  699. struct ufs_sb_info * sbi;
  700. struct ufs_sb_private_info * uspi;
  701. struct ufs_super_block_first * usb1;
  702. struct ufs_super_block_second * usb2;
  703. struct ufs_super_block_third * usb3;
  704. struct ufs_buffer_head * ubh;
  705. struct inode *inode;
  706. unsigned block_size, super_block_size;
  707. unsigned flags;
  708. unsigned super_block_offset;
  709. unsigned maxsymlen;
  710. int ret = -EINVAL;
  711. uspi = NULL;
  712. ubh = NULL;
  713. flags = 0;
  714. UFSD("ENTER\n");
  715. #ifndef CONFIG_UFS_FS_WRITE
  716. if (!sb_rdonly(sb)) {
  717. pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
  718. return -EROFS;
  719. }
  720. #endif
  721. sbi = kzalloc(sizeof(struct ufs_sb_info), GFP_KERNEL);
  722. if (!sbi)
  723. goto failed_nomem;
  724. sb->s_fs_info = sbi;
  725. sbi->sb = sb;
  726. UFSD("flag %u\n", (int)(sb_rdonly(sb)));
  727. mutex_init(&sbi->s_lock);
  728. spin_lock_init(&sbi->work_lock);
  729. INIT_DELAYED_WORK(&sbi->sync_work, delayed_sync_fs);
  730. /*
  731. * Set default mount options
  732. * Parse mount options
  733. */
  734. sbi->s_mount_opt = 0;
  735. ufs_set_opt (sbi->s_mount_opt, ONERROR_LOCK);
  736. if (!ufs_parse_options ((char *) data, &sbi->s_mount_opt)) {
  737. pr_err("wrong mount options\n");
  738. goto failed;
  739. }
  740. if (!(sbi->s_mount_opt & UFS_MOUNT_UFSTYPE)) {
  741. if (!silent)
  742. pr_err("You didn't specify the type of your ufs filesystem\n\n"
  743. "mount -t ufs -o ufstype="
  744. "sun|sunx86|44bsd|ufs2|5xbsd|old|hp|nextstep|nextstep-cd|openstep ...\n\n"
  745. ">>>WARNING<<< Wrong ufstype may corrupt your filesystem, "
  746. "default is ufstype=old\n");
  747. ufs_set_opt (sbi->s_mount_opt, UFSTYPE_OLD);
  748. }
  749. uspi = kzalloc(sizeof(struct ufs_sb_private_info), GFP_KERNEL);
  750. sbi->s_uspi = uspi;
  751. if (!uspi)
  752. goto failed;
  753. uspi->s_dirblksize = UFS_SECTOR_SIZE;
  754. super_block_offset=UFS_SBLOCK;
  755. sb->s_maxbytes = MAX_LFS_FILESIZE;
  756. switch (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) {
  757. case UFS_MOUNT_UFSTYPE_44BSD:
  758. UFSD("ufstype=44bsd\n");
  759. uspi->s_fsize = block_size = 512;
  760. uspi->s_fmask = ~(512 - 1);
  761. uspi->s_fshift = 9;
  762. uspi->s_sbsize = super_block_size = 1536;
  763. uspi->s_sbbase = 0;
  764. flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
  765. break;
  766. case UFS_MOUNT_UFSTYPE_UFS2:
  767. UFSD("ufstype=ufs2\n");
  768. super_block_offset=SBLOCK_UFS2;
  769. uspi->s_fsize = block_size = 512;
  770. uspi->s_fmask = ~(512 - 1);
  771. uspi->s_fshift = 9;
  772. uspi->s_sbsize = super_block_size = 1536;
  773. uspi->s_sbbase = 0;
  774. flags |= UFS_TYPE_UFS2 | UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
  775. break;
  776. case UFS_MOUNT_UFSTYPE_SUN:
  777. UFSD("ufstype=sun\n");
  778. uspi->s_fsize = block_size = 1024;
  779. uspi->s_fmask = ~(1024 - 1);
  780. uspi->s_fshift = 10;
  781. uspi->s_sbsize = super_block_size = 2048;
  782. uspi->s_sbbase = 0;
  783. uspi->s_maxsymlinklen = 0; /* Not supported on disk */
  784. flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUN | UFS_CG_SUN;
  785. break;
  786. case UFS_MOUNT_UFSTYPE_SUNOS:
  787. UFSD("ufstype=sunos\n");
  788. uspi->s_fsize = block_size = 1024;
  789. uspi->s_fmask = ~(1024 - 1);
  790. uspi->s_fshift = 10;
  791. uspi->s_sbsize = 2048;
  792. super_block_size = 2048;
  793. uspi->s_sbbase = 0;
  794. uspi->s_maxsymlinklen = 0; /* Not supported on disk */
  795. flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_SUNOS | UFS_CG_SUN;
  796. break;
  797. case UFS_MOUNT_UFSTYPE_SUNx86:
  798. UFSD("ufstype=sunx86\n");
  799. uspi->s_fsize = block_size = 1024;
  800. uspi->s_fmask = ~(1024 - 1);
  801. uspi->s_fshift = 10;
  802. uspi->s_sbsize = super_block_size = 2048;
  803. uspi->s_sbbase = 0;
  804. uspi->s_maxsymlinklen = 0; /* Not supported on disk */
  805. flags |= UFS_DE_OLD | UFS_UID_EFT | UFS_ST_SUNx86 | UFS_CG_SUN;
  806. break;
  807. case UFS_MOUNT_UFSTYPE_OLD:
  808. UFSD("ufstype=old\n");
  809. uspi->s_fsize = block_size = 1024;
  810. uspi->s_fmask = ~(1024 - 1);
  811. uspi->s_fshift = 10;
  812. uspi->s_sbsize = super_block_size = 2048;
  813. uspi->s_sbbase = 0;
  814. flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
  815. if (!sb_rdonly(sb)) {
  816. if (!silent)
  817. pr_info("ufstype=old is supported read-only\n");
  818. sb->s_flags |= SB_RDONLY;
  819. }
  820. break;
  821. case UFS_MOUNT_UFSTYPE_NEXTSTEP:
  822. UFSD("ufstype=nextstep\n");
  823. uspi->s_fsize = block_size = 1024;
  824. uspi->s_fmask = ~(1024 - 1);
  825. uspi->s_fshift = 10;
  826. uspi->s_sbsize = super_block_size = 2048;
  827. uspi->s_sbbase = 0;
  828. uspi->s_dirblksize = 1024;
  829. flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
  830. if (!sb_rdonly(sb)) {
  831. if (!silent)
  832. pr_info("ufstype=nextstep is supported read-only\n");
  833. sb->s_flags |= SB_RDONLY;
  834. }
  835. break;
  836. case UFS_MOUNT_UFSTYPE_NEXTSTEP_CD:
  837. UFSD("ufstype=nextstep-cd\n");
  838. uspi->s_fsize = block_size = 2048;
  839. uspi->s_fmask = ~(2048 - 1);
  840. uspi->s_fshift = 11;
  841. uspi->s_sbsize = super_block_size = 2048;
  842. uspi->s_sbbase = 0;
  843. uspi->s_dirblksize = 1024;
  844. flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
  845. if (!sb_rdonly(sb)) {
  846. if (!silent)
  847. pr_info("ufstype=nextstep-cd is supported read-only\n");
  848. sb->s_flags |= SB_RDONLY;
  849. }
  850. break;
  851. case UFS_MOUNT_UFSTYPE_OPENSTEP:
  852. UFSD("ufstype=openstep\n");
  853. uspi->s_fsize = block_size = 1024;
  854. uspi->s_fmask = ~(1024 - 1);
  855. uspi->s_fshift = 10;
  856. uspi->s_sbsize = super_block_size = 2048;
  857. uspi->s_sbbase = 0;
  858. uspi->s_dirblksize = 1024;
  859. flags |= UFS_DE_44BSD | UFS_UID_44BSD | UFS_ST_44BSD | UFS_CG_44BSD;
  860. if (!sb_rdonly(sb)) {
  861. if (!silent)
  862. pr_info("ufstype=openstep is supported read-only\n");
  863. sb->s_flags |= SB_RDONLY;
  864. }
  865. break;
  866. case UFS_MOUNT_UFSTYPE_HP:
  867. UFSD("ufstype=hp\n");
  868. uspi->s_fsize = block_size = 1024;
  869. uspi->s_fmask = ~(1024 - 1);
  870. uspi->s_fshift = 10;
  871. uspi->s_sbsize = super_block_size = 2048;
  872. uspi->s_sbbase = 0;
  873. flags |= UFS_DE_OLD | UFS_UID_OLD | UFS_ST_OLD | UFS_CG_OLD;
  874. if (!sb_rdonly(sb)) {
  875. if (!silent)
  876. pr_info("ufstype=hp is supported read-only\n");
  877. sb->s_flags |= SB_RDONLY;
  878. }
  879. break;
  880. default:
  881. if (!silent)
  882. pr_err("unknown ufstype\n");
  883. goto failed;
  884. }
  885. again:
  886. if (!sb_set_blocksize(sb, block_size)) {
  887. pr_err("failed to set blocksize\n");
  888. goto failed;
  889. }
  890. /*
  891. * read ufs super block from device
  892. */
  893. ubh = ubh_bread_uspi(uspi, sb, uspi->s_sbbase + super_block_offset/block_size, super_block_size);
  894. if (!ubh)
  895. goto failed;
  896. usb1 = ubh_get_usb_first(uspi);
  897. usb2 = ubh_get_usb_second(uspi);
  898. usb3 = ubh_get_usb_third(uspi);
  899. /* Sort out mod used on SunOS 4.1.3 for fs_state */
  900. uspi->s_postblformat = fs32_to_cpu(sb, usb3->fs_postblformat);
  901. if (((flags & UFS_ST_MASK) == UFS_ST_SUNOS) &&
  902. (uspi->s_postblformat != UFS_42POSTBLFMT)) {
  903. flags &= ~UFS_ST_MASK;
  904. flags |= UFS_ST_SUN;
  905. }
  906. if ((flags & UFS_ST_MASK) == UFS_ST_44BSD &&
  907. uspi->s_postblformat == UFS_42POSTBLFMT) {
  908. if (!silent)
  909. pr_err("this is not a 44bsd filesystem");
  910. goto failed;
  911. }
  912. /*
  913. * Check ufs magic number
  914. */
  915. sbi->s_bytesex = BYTESEX_LE;
  916. switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
  917. case UFS_MAGIC:
  918. case UFS_MAGIC_BW:
  919. case UFS2_MAGIC:
  920. case UFS_MAGIC_LFN:
  921. case UFS_MAGIC_FEA:
  922. case UFS_MAGIC_4GB:
  923. goto magic_found;
  924. }
  925. sbi->s_bytesex = BYTESEX_BE;
  926. switch ((uspi->fs_magic = fs32_to_cpu(sb, usb3->fs_magic))) {
  927. case UFS_MAGIC:
  928. case UFS_MAGIC_BW:
  929. case UFS2_MAGIC:
  930. case UFS_MAGIC_LFN:
  931. case UFS_MAGIC_FEA:
  932. case UFS_MAGIC_4GB:
  933. goto magic_found;
  934. }
  935. if ((((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP)
  936. || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_NEXTSTEP_CD)
  937. || ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_OPENSTEP))
  938. && uspi->s_sbbase < 256) {
  939. ubh_brelse_uspi(uspi);
  940. ubh = NULL;
  941. uspi->s_sbbase += 8;
  942. goto again;
  943. }
  944. if (!silent)
  945. pr_err("%s(): bad magic number\n", __func__);
  946. goto failed;
  947. magic_found:
  948. /*
  949. * Check block and fragment sizes
  950. */
  951. uspi->s_bsize = fs32_to_cpu(sb, usb1->fs_bsize);
  952. uspi->s_fsize = fs32_to_cpu(sb, usb1->fs_fsize);
  953. uspi->s_sbsize = fs32_to_cpu(sb, usb1->fs_sbsize);
  954. uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
  955. uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
  956. if (!is_power_of_2(uspi->s_fsize)) {
  957. pr_err("%s(): fragment size %u is not a power of 2\n",
  958. __func__, uspi->s_fsize);
  959. goto failed;
  960. }
  961. if (uspi->s_fsize < 512) {
  962. pr_err("%s(): fragment size %u is too small\n",
  963. __func__, uspi->s_fsize);
  964. goto failed;
  965. }
  966. if (uspi->s_fsize > 4096) {
  967. pr_err("%s(): fragment size %u is too large\n",
  968. __func__, uspi->s_fsize);
  969. goto failed;
  970. }
  971. if (!is_power_of_2(uspi->s_bsize)) {
  972. pr_err("%s(): block size %u is not a power of 2\n",
  973. __func__, uspi->s_bsize);
  974. goto failed;
  975. }
  976. if (uspi->s_bsize < 4096) {
  977. pr_err("%s(): block size %u is too small\n",
  978. __func__, uspi->s_bsize);
  979. goto failed;
  980. }
  981. if (uspi->s_bsize / uspi->s_fsize > 8) {
  982. pr_err("%s(): too many fragments per block (%u)\n",
  983. __func__, uspi->s_bsize / uspi->s_fsize);
  984. goto failed;
  985. }
  986. if (uspi->s_fsize != block_size || uspi->s_sbsize != super_block_size) {
  987. ubh_brelse_uspi(uspi);
  988. ubh = NULL;
  989. block_size = uspi->s_fsize;
  990. super_block_size = uspi->s_sbsize;
  991. UFSD("another value of block_size or super_block_size %u, %u\n", block_size, super_block_size);
  992. goto again;
  993. }
  994. sbi->s_flags = flags;/*after that line some functions use s_flags*/
  995. ufs_print_super_stuff(sb, usb1, usb2, usb3);
  996. /*
  997. * Check, if file system was correctly unmounted.
  998. * If not, make it read only.
  999. */
  1000. if (((flags & UFS_ST_MASK) == UFS_ST_44BSD) ||
  1001. ((flags & UFS_ST_MASK) == UFS_ST_OLD) ||
  1002. (((flags & UFS_ST_MASK) == UFS_ST_SUN ||
  1003. (flags & UFS_ST_MASK) == UFS_ST_SUNOS ||
  1004. (flags & UFS_ST_MASK) == UFS_ST_SUNx86) &&
  1005. (ufs_get_fs_state(sb, usb1, usb3) == (UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time))))) {
  1006. switch(usb1->fs_clean) {
  1007. case UFS_FSCLEAN:
  1008. UFSD("fs is clean\n");
  1009. break;
  1010. case UFS_FSSTABLE:
  1011. UFSD("fs is stable\n");
  1012. break;
  1013. case UFS_FSLOG:
  1014. UFSD("fs is logging fs\n");
  1015. break;
  1016. case UFS_FSOSF1:
  1017. UFSD("fs is DEC OSF/1\n");
  1018. break;
  1019. case UFS_FSACTIVE:
  1020. pr_err("%s(): fs is active\n", __func__);
  1021. sb->s_flags |= SB_RDONLY;
  1022. break;
  1023. case UFS_FSBAD:
  1024. pr_err("%s(): fs is bad\n", __func__);
  1025. sb->s_flags |= SB_RDONLY;
  1026. break;
  1027. default:
  1028. pr_err("%s(): can't grok fs_clean 0x%x\n",
  1029. __func__, usb1->fs_clean);
  1030. sb->s_flags |= SB_RDONLY;
  1031. break;
  1032. }
  1033. } else {
  1034. pr_err("%s(): fs needs fsck\n", __func__);
  1035. sb->s_flags |= SB_RDONLY;
  1036. }
  1037. /*
  1038. * Read ufs_super_block into internal data structures
  1039. */
  1040. sb->s_op = &ufs_super_ops;
  1041. sb->s_export_op = &ufs_export_ops;
  1042. sb->s_magic = fs32_to_cpu(sb, usb3->fs_magic);
  1043. uspi->s_sblkno = fs32_to_cpu(sb, usb1->fs_sblkno);
  1044. uspi->s_cblkno = fs32_to_cpu(sb, usb1->fs_cblkno);
  1045. uspi->s_iblkno = fs32_to_cpu(sb, usb1->fs_iblkno);
  1046. uspi->s_dblkno = fs32_to_cpu(sb, usb1->fs_dblkno);
  1047. uspi->s_cgoffset = fs32_to_cpu(sb, usb1->fs_cgoffset);
  1048. uspi->s_cgmask = fs32_to_cpu(sb, usb1->fs_cgmask);
  1049. if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2) {
  1050. uspi->s_size = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_size);
  1051. uspi->s_dsize = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_dsize);
  1052. } else {
  1053. uspi->s_size = fs32_to_cpu(sb, usb1->fs_size);
  1054. uspi->s_dsize = fs32_to_cpu(sb, usb1->fs_dsize);
  1055. }
  1056. uspi->s_ncg = fs32_to_cpu(sb, usb1->fs_ncg);
  1057. /* s_bsize already set */
  1058. /* s_fsize already set */
  1059. uspi->s_fpb = fs32_to_cpu(sb, usb1->fs_frag);
  1060. uspi->s_minfree = fs32_to_cpu(sb, usb1->fs_minfree);
  1061. uspi->s_bmask = fs32_to_cpu(sb, usb1->fs_bmask);
  1062. uspi->s_fmask = fs32_to_cpu(sb, usb1->fs_fmask);
  1063. uspi->s_bshift = fs32_to_cpu(sb, usb1->fs_bshift);
  1064. uspi->s_fshift = fs32_to_cpu(sb, usb1->fs_fshift);
  1065. UFSD("uspi->s_bshift = %d,uspi->s_fshift = %d", uspi->s_bshift,
  1066. uspi->s_fshift);
  1067. uspi->s_fpbshift = fs32_to_cpu(sb, usb1->fs_fragshift);
  1068. uspi->s_fsbtodb = fs32_to_cpu(sb, usb1->fs_fsbtodb);
  1069. /* s_sbsize already set */
  1070. uspi->s_csmask = fs32_to_cpu(sb, usb1->fs_csmask);
  1071. uspi->s_csshift = fs32_to_cpu(sb, usb1->fs_csshift);
  1072. uspi->s_nindir = fs32_to_cpu(sb, usb1->fs_nindir);
  1073. uspi->s_inopb = fs32_to_cpu(sb, usb1->fs_inopb);
  1074. uspi->s_nspf = fs32_to_cpu(sb, usb1->fs_nspf);
  1075. uspi->s_npsect = ufs_get_fs_npsect(sb, usb1, usb3);
  1076. uspi->s_interleave = fs32_to_cpu(sb, usb1->fs_interleave);
  1077. uspi->s_trackskew = fs32_to_cpu(sb, usb1->fs_trackskew);
  1078. if (uspi->fs_magic == UFS2_MAGIC)
  1079. uspi->s_csaddr = fs64_to_cpu(sb, usb3->fs_un1.fs_u2.fs_csaddr);
  1080. else
  1081. uspi->s_csaddr = fs32_to_cpu(sb, usb1->fs_csaddr);
  1082. uspi->s_cssize = fs32_to_cpu(sb, usb1->fs_cssize);
  1083. uspi->s_cgsize = fs32_to_cpu(sb, usb1->fs_cgsize);
  1084. uspi->s_ntrak = fs32_to_cpu(sb, usb1->fs_ntrak);
  1085. uspi->s_nsect = fs32_to_cpu(sb, usb1->fs_nsect);
  1086. uspi->s_spc = fs32_to_cpu(sb, usb1->fs_spc);
  1087. uspi->s_ipg = fs32_to_cpu(sb, usb1->fs_ipg);
  1088. uspi->s_fpg = fs32_to_cpu(sb, usb1->fs_fpg);
  1089. uspi->s_cpc = fs32_to_cpu(sb, usb2->fs_un.fs_u1.fs_cpc);
  1090. uspi->s_contigsumsize = fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_contigsumsize);
  1091. uspi->s_qbmask = ufs_get_fs_qbmask(sb, usb3);
  1092. uspi->s_qfmask = ufs_get_fs_qfmask(sb, usb3);
  1093. uspi->s_nrpos = fs32_to_cpu(sb, usb3->fs_nrpos);
  1094. uspi->s_postbloff = fs32_to_cpu(sb, usb3->fs_postbloff);
  1095. uspi->s_rotbloff = fs32_to_cpu(sb, usb3->fs_rotbloff);
  1096. uspi->s_root_blocks = mul_u64_u32_div(uspi->s_dsize,
  1097. uspi->s_minfree, 100);
  1098. if (uspi->s_minfree <= 5) {
  1099. uspi->s_time_to_space = ~0ULL;
  1100. uspi->s_space_to_time = 0;
  1101. usb1->fs_optim = cpu_to_fs32(sb, UFS_OPTSPACE);
  1102. } else {
  1103. uspi->s_time_to_space = (uspi->s_root_blocks / 2) + 1;
  1104. uspi->s_space_to_time = mul_u64_u32_div(uspi->s_dsize,
  1105. uspi->s_minfree - 2, 100) - 1;
  1106. }
  1107. /*
  1108. * Compute another frequently used values
  1109. */
  1110. uspi->s_fpbmask = uspi->s_fpb - 1;
  1111. if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
  1112. uspi->s_apbshift = uspi->s_bshift - 3;
  1113. else
  1114. uspi->s_apbshift = uspi->s_bshift - 2;
  1115. uspi->s_2apbshift = uspi->s_apbshift * 2;
  1116. uspi->s_3apbshift = uspi->s_apbshift * 3;
  1117. uspi->s_apb = 1 << uspi->s_apbshift;
  1118. uspi->s_2apb = 1 << uspi->s_2apbshift;
  1119. uspi->s_3apb = 1 << uspi->s_3apbshift;
  1120. uspi->s_apbmask = uspi->s_apb - 1;
  1121. uspi->s_nspfshift = uspi->s_fshift - UFS_SECTOR_BITS;
  1122. uspi->s_nspb = uspi->s_nspf << uspi->s_fpbshift;
  1123. uspi->s_inopf = uspi->s_inopb >> uspi->s_fpbshift;
  1124. uspi->s_bpf = uspi->s_fsize << 3;
  1125. uspi->s_bpfshift = uspi->s_fshift + 3;
  1126. uspi->s_bpfmask = uspi->s_bpf - 1;
  1127. if ((sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_44BSD ||
  1128. (sbi->s_mount_opt & UFS_MOUNT_UFSTYPE) == UFS_MOUNT_UFSTYPE_UFS2)
  1129. uspi->s_maxsymlinklen =
  1130. fs32_to_cpu(sb, usb3->fs_un2.fs_44.fs_maxsymlinklen);
  1131. if (uspi->fs_magic == UFS2_MAGIC)
  1132. maxsymlen = 2 * 4 * (UFS_NDADDR + UFS_NINDIR);
  1133. else
  1134. maxsymlen = 4 * (UFS_NDADDR + UFS_NINDIR);
  1135. if (uspi->s_maxsymlinklen > maxsymlen) {
  1136. ufs_warning(sb, __func__, "ufs_read_super: excessive maximum "
  1137. "fast symlink size (%u)\n", uspi->s_maxsymlinklen);
  1138. uspi->s_maxsymlinklen = maxsymlen;
  1139. }
  1140. sb->s_maxbytes = ufs_max_bytes(sb);
  1141. sb->s_max_links = UFS_LINK_MAX;
  1142. inode = ufs_iget(sb, UFS_ROOTINO);
  1143. if (IS_ERR(inode)) {
  1144. ret = PTR_ERR(inode);
  1145. goto failed;
  1146. }
  1147. sb->s_root = d_make_root(inode);
  1148. if (!sb->s_root) {
  1149. ret = -ENOMEM;
  1150. goto failed;
  1151. }
  1152. ufs_setup_cstotal(sb);
  1153. /*
  1154. * Read cylinder group structures
  1155. */
  1156. if (!sb_rdonly(sb))
  1157. if (!ufs_read_cylinder_structures(sb))
  1158. goto failed;
  1159. UFSD("EXIT\n");
  1160. return 0;
  1161. failed:
  1162. if (ubh)
  1163. ubh_brelse_uspi (uspi);
  1164. kfree (uspi);
  1165. kfree(sbi);
  1166. sb->s_fs_info = NULL;
  1167. UFSD("EXIT (FAILED)\n");
  1168. return ret;
  1169. failed_nomem:
  1170. UFSD("EXIT (NOMEM)\n");
  1171. return -ENOMEM;
  1172. }
  1173. static int ufs_remount (struct super_block *sb, int *mount_flags, char *data)
  1174. {
  1175. struct ufs_sb_private_info * uspi;
  1176. struct ufs_super_block_first * usb1;
  1177. struct ufs_super_block_third * usb3;
  1178. unsigned new_mount_opt, ufstype;
  1179. unsigned flags;
  1180. sync_filesystem(sb);
  1181. mutex_lock(&UFS_SB(sb)->s_lock);
  1182. uspi = UFS_SB(sb)->s_uspi;
  1183. flags = UFS_SB(sb)->s_flags;
  1184. usb1 = ubh_get_usb_first(uspi);
  1185. usb3 = ubh_get_usb_third(uspi);
  1186. /*
  1187. * Allow the "check" option to be passed as a remount option.
  1188. * It is not possible to change ufstype option during remount
  1189. */
  1190. ufstype = UFS_SB(sb)->s_mount_opt & UFS_MOUNT_UFSTYPE;
  1191. new_mount_opt = 0;
  1192. ufs_set_opt (new_mount_opt, ONERROR_LOCK);
  1193. if (!ufs_parse_options (data, &new_mount_opt)) {
  1194. mutex_unlock(&UFS_SB(sb)->s_lock);
  1195. return -EINVAL;
  1196. }
  1197. if (!(new_mount_opt & UFS_MOUNT_UFSTYPE)) {
  1198. new_mount_opt |= ufstype;
  1199. } else if ((new_mount_opt & UFS_MOUNT_UFSTYPE) != ufstype) {
  1200. pr_err("ufstype can't be changed during remount\n");
  1201. mutex_unlock(&UFS_SB(sb)->s_lock);
  1202. return -EINVAL;
  1203. }
  1204. if ((bool)(*mount_flags & SB_RDONLY) == sb_rdonly(sb)) {
  1205. UFS_SB(sb)->s_mount_opt = new_mount_opt;
  1206. mutex_unlock(&UFS_SB(sb)->s_lock);
  1207. return 0;
  1208. }
  1209. /*
  1210. * fs was mouted as rw, remounting ro
  1211. */
  1212. if (*mount_flags & SB_RDONLY) {
  1213. ufs_put_super_internal(sb);
  1214. usb1->fs_time = ufs_get_seconds(sb);
  1215. if ((flags & UFS_ST_MASK) == UFS_ST_SUN
  1216. || (flags & UFS_ST_MASK) == UFS_ST_SUNOS
  1217. || (flags & UFS_ST_MASK) == UFS_ST_SUNx86)
  1218. ufs_set_fs_state(sb, usb1, usb3,
  1219. UFS_FSOK - fs32_to_cpu(sb, usb1->fs_time));
  1220. ubh_mark_buffer_dirty (USPI_UBH(uspi));
  1221. sb->s_flags |= SB_RDONLY;
  1222. } else {
  1223. /*
  1224. * fs was mounted as ro, remounting rw
  1225. */
  1226. #ifndef CONFIG_UFS_FS_WRITE
  1227. pr_err("ufs was compiled with read-only support, can't be mounted as read-write\n");
  1228. mutex_unlock(&UFS_SB(sb)->s_lock);
  1229. return -EINVAL;
  1230. #else
  1231. if (ufstype != UFS_MOUNT_UFSTYPE_SUN &&
  1232. ufstype != UFS_MOUNT_UFSTYPE_SUNOS &&
  1233. ufstype != UFS_MOUNT_UFSTYPE_44BSD &&
  1234. ufstype != UFS_MOUNT_UFSTYPE_SUNx86 &&
  1235. ufstype != UFS_MOUNT_UFSTYPE_UFS2) {
  1236. pr_err("this ufstype is read-only supported\n");
  1237. mutex_unlock(&UFS_SB(sb)->s_lock);
  1238. return -EINVAL;
  1239. }
  1240. if (!ufs_read_cylinder_structures(sb)) {
  1241. pr_err("failed during remounting\n");
  1242. mutex_unlock(&UFS_SB(sb)->s_lock);
  1243. return -EPERM;
  1244. }
  1245. sb->s_flags &= ~SB_RDONLY;
  1246. #endif
  1247. }
  1248. UFS_SB(sb)->s_mount_opt = new_mount_opt;
  1249. mutex_unlock(&UFS_SB(sb)->s_lock);
  1250. return 0;
  1251. }
  1252. static int ufs_show_options(struct seq_file *seq, struct dentry *root)
  1253. {
  1254. struct ufs_sb_info *sbi = UFS_SB(root->d_sb);
  1255. unsigned mval = sbi->s_mount_opt & UFS_MOUNT_UFSTYPE;
  1256. const struct match_token *tp = tokens;
  1257. while (tp->token != Opt_onerror_panic && tp->token != mval)
  1258. ++tp;
  1259. BUG_ON(tp->token == Opt_onerror_panic);
  1260. seq_printf(seq, ",%s", tp->pattern);
  1261. mval = sbi->s_mount_opt & UFS_MOUNT_ONERROR;
  1262. while (tp->token != Opt_err && tp->token != mval)
  1263. ++tp;
  1264. BUG_ON(tp->token == Opt_err);
  1265. seq_printf(seq, ",%s", tp->pattern);
  1266. return 0;
  1267. }
  1268. static int ufs_statfs(struct dentry *dentry, struct kstatfs *buf)
  1269. {
  1270. struct super_block *sb = dentry->d_sb;
  1271. struct ufs_sb_private_info *uspi= UFS_SB(sb)->s_uspi;
  1272. unsigned flags = UFS_SB(sb)->s_flags;
  1273. struct ufs_super_block_third *usb3;
  1274. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  1275. mutex_lock(&UFS_SB(sb)->s_lock);
  1276. usb3 = ubh_get_usb_third(uspi);
  1277. if ((flags & UFS_TYPE_MASK) == UFS_TYPE_UFS2)
  1278. buf->f_type = UFS2_MAGIC;
  1279. else
  1280. buf->f_type = UFS_MAGIC;
  1281. buf->f_blocks = uspi->s_dsize;
  1282. buf->f_bfree = ufs_freefrags(uspi);
  1283. buf->f_ffree = uspi->cs_total.cs_nifree;
  1284. buf->f_bsize = sb->s_blocksize;
  1285. buf->f_bavail = (buf->f_bfree > uspi->s_root_blocks)
  1286. ? (buf->f_bfree - uspi->s_root_blocks) : 0;
  1287. buf->f_files = uspi->s_ncg * uspi->s_ipg;
  1288. buf->f_namelen = UFS_MAXNAMLEN;
  1289. buf->f_fsid.val[0] = (u32)id;
  1290. buf->f_fsid.val[1] = (u32)(id >> 32);
  1291. mutex_unlock(&UFS_SB(sb)->s_lock);
  1292. return 0;
  1293. }
  1294. static struct kmem_cache * ufs_inode_cachep;
  1295. static struct inode *ufs_alloc_inode(struct super_block *sb)
  1296. {
  1297. struct ufs_inode_info *ei;
  1298. ei = kmem_cache_alloc(ufs_inode_cachep, GFP_NOFS);
  1299. if (!ei)
  1300. return NULL;
  1301. inode_set_iversion(&ei->vfs_inode, 1);
  1302. seqlock_init(&ei->meta_lock);
  1303. mutex_init(&ei->truncate_mutex);
  1304. return &ei->vfs_inode;
  1305. }
  1306. static void ufs_i_callback(struct rcu_head *head)
  1307. {
  1308. struct inode *inode = container_of(head, struct inode, i_rcu);
  1309. kmem_cache_free(ufs_inode_cachep, UFS_I(inode));
  1310. }
  1311. static void ufs_destroy_inode(struct inode *inode)
  1312. {
  1313. call_rcu(&inode->i_rcu, ufs_i_callback);
  1314. }
  1315. static void init_once(void *foo)
  1316. {
  1317. struct ufs_inode_info *ei = (struct ufs_inode_info *) foo;
  1318. inode_init_once(&ei->vfs_inode);
  1319. }
  1320. static int __init init_inodecache(void)
  1321. {
  1322. ufs_inode_cachep = kmem_cache_create_usercopy("ufs_inode_cache",
  1323. sizeof(struct ufs_inode_info), 0,
  1324. (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|
  1325. SLAB_ACCOUNT),
  1326. offsetof(struct ufs_inode_info, i_u1.i_symlink),
  1327. sizeof_field(struct ufs_inode_info,
  1328. i_u1.i_symlink),
  1329. init_once);
  1330. if (ufs_inode_cachep == NULL)
  1331. return -ENOMEM;
  1332. return 0;
  1333. }
  1334. static void destroy_inodecache(void)
  1335. {
  1336. /*
  1337. * Make sure all delayed rcu free inodes are flushed before we
  1338. * destroy cache.
  1339. */
  1340. rcu_barrier();
  1341. kmem_cache_destroy(ufs_inode_cachep);
  1342. }
  1343. static const struct super_operations ufs_super_ops = {
  1344. .alloc_inode = ufs_alloc_inode,
  1345. .destroy_inode = ufs_destroy_inode,
  1346. .write_inode = ufs_write_inode,
  1347. .evict_inode = ufs_evict_inode,
  1348. .put_super = ufs_put_super,
  1349. .sync_fs = ufs_sync_fs,
  1350. .statfs = ufs_statfs,
  1351. .remount_fs = ufs_remount,
  1352. .show_options = ufs_show_options,
  1353. };
  1354. static struct dentry *ufs_mount(struct file_system_type *fs_type,
  1355. int flags, const char *dev_name, void *data)
  1356. {
  1357. return mount_bdev(fs_type, flags, dev_name, data, ufs_fill_super);
  1358. }
  1359. static struct file_system_type ufs_fs_type = {
  1360. .owner = THIS_MODULE,
  1361. .name = "ufs",
  1362. .mount = ufs_mount,
  1363. .kill_sb = kill_block_super,
  1364. .fs_flags = FS_REQUIRES_DEV,
  1365. };
  1366. MODULE_ALIAS_FS("ufs");
  1367. static int __init init_ufs_fs(void)
  1368. {
  1369. int err = init_inodecache();
  1370. if (err)
  1371. goto out1;
  1372. err = register_filesystem(&ufs_fs_type);
  1373. if (err)
  1374. goto out;
  1375. return 0;
  1376. out:
  1377. destroy_inodecache();
  1378. out1:
  1379. return err;
  1380. }
  1381. static void __exit exit_ufs_fs(void)
  1382. {
  1383. unregister_filesystem(&ufs_fs_type);
  1384. destroy_inodecache();
  1385. }
  1386. module_init(init_ufs_fs)
  1387. module_exit(exit_ufs_fs)
  1388. MODULE_LICENSE("GPL");