super.c 43 KB

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