super.c 44 KB

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