super.c 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293
  1. /*
  2. * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
  3. *
  4. * Trivial changes by Alan Cox to add the LFS fixes
  5. *
  6. * Trivial Changes:
  7. * Rights granted to Hans Reiser to redistribute under other terms providing
  8. * he accepts all liability including but not limited to patent, fitness
  9. * for purpose, and direct or indirect claims arising from failure to perform.
  10. *
  11. * NO WARRANTY
  12. */
  13. #include <linux/module.h>
  14. #include <linux/vmalloc.h>
  15. #include <linux/time.h>
  16. #include <asm/uaccess.h>
  17. #include <linux/reiserfs_fs.h>
  18. #include <linux/reiserfs_acl.h>
  19. #include <linux/reiserfs_xattr.h>
  20. #include <linux/smp_lock.h>
  21. #include <linux/init.h>
  22. #include <linux/blkdev.h>
  23. #include <linux/buffer_head.h>
  24. #include <linux/vfs.h>
  25. #include <linux/namespace.h>
  26. #include <linux/mount.h>
  27. #include <linux/namei.h>
  28. #include <linux/quotaops.h>
  29. struct file_system_type reiserfs_fs_type;
  30. static const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
  31. static const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
  32. static const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
  33. int is_reiserfs_3_5(struct reiserfs_super_block *rs)
  34. {
  35. return !strncmp(rs->s_v1.s_magic, reiserfs_3_5_magic_string,
  36. strlen(reiserfs_3_5_magic_string));
  37. }
  38. int is_reiserfs_3_6(struct reiserfs_super_block *rs)
  39. {
  40. return !strncmp(rs->s_v1.s_magic, reiserfs_3_6_magic_string,
  41. strlen(reiserfs_3_6_magic_string));
  42. }
  43. int is_reiserfs_jr(struct reiserfs_super_block *rs)
  44. {
  45. return !strncmp(rs->s_v1.s_magic, reiserfs_jr_magic_string,
  46. strlen(reiserfs_jr_magic_string));
  47. }
  48. static int is_any_reiserfs_magic_string(struct reiserfs_super_block *rs)
  49. {
  50. return (is_reiserfs_3_5(rs) || is_reiserfs_3_6(rs) ||
  51. is_reiserfs_jr(rs));
  52. }
  53. static int reiserfs_remount(struct super_block *s, int *flags, char *data);
  54. static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf);
  55. static int reiserfs_sync_fs(struct super_block *s, int wait)
  56. {
  57. if (!(s->s_flags & MS_RDONLY)) {
  58. struct reiserfs_transaction_handle th;
  59. reiserfs_write_lock(s);
  60. if (!journal_begin(&th, s, 1))
  61. if (!journal_end_sync(&th, s, 1))
  62. reiserfs_flush_old_commits(s);
  63. s->s_dirt = 0; /* Even if it's not true.
  64. * We'll loop forever in sync_supers otherwise */
  65. reiserfs_write_unlock(s);
  66. } else {
  67. s->s_dirt = 0;
  68. }
  69. return 0;
  70. }
  71. static void reiserfs_write_super(struct super_block *s)
  72. {
  73. reiserfs_sync_fs(s, 1);
  74. }
  75. static void reiserfs_write_super_lockfs(struct super_block *s)
  76. {
  77. struct reiserfs_transaction_handle th;
  78. reiserfs_write_lock(s);
  79. if (!(s->s_flags & MS_RDONLY)) {
  80. int err = journal_begin(&th, s, 1);
  81. if (err) {
  82. reiserfs_block_writes(&th);
  83. } else {
  84. reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
  85. 1);
  86. journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
  87. reiserfs_block_writes(&th);
  88. journal_end_sync(&th, s, 1);
  89. }
  90. }
  91. s->s_dirt = 0;
  92. reiserfs_write_unlock(s);
  93. }
  94. static void reiserfs_unlockfs(struct super_block *s)
  95. {
  96. reiserfs_allow_writes(s);
  97. }
  98. extern const struct in_core_key MAX_IN_CORE_KEY;
  99. /* this is used to delete "save link" when there are no items of a
  100. file it points to. It can either happen if unlink is completed but
  101. "save unlink" removal, or if file has both unlink and truncate
  102. pending and as unlink completes first (because key of "save link"
  103. protecting unlink is bigger that a key lf "save link" which
  104. protects truncate), so there left no items to make truncate
  105. completion on */
  106. static int remove_save_link_only(struct super_block *s,
  107. struct reiserfs_key *key, int oid_free)
  108. {
  109. struct reiserfs_transaction_handle th;
  110. int err;
  111. /* we are going to do one balancing */
  112. err = journal_begin(&th, s, JOURNAL_PER_BALANCE_CNT);
  113. if (err)
  114. return err;
  115. reiserfs_delete_solid_item(&th, NULL, key);
  116. if (oid_free)
  117. /* removals are protected by direct items */
  118. reiserfs_release_objectid(&th, le32_to_cpu(key->k_objectid));
  119. return journal_end(&th, s, JOURNAL_PER_BALANCE_CNT);
  120. }
  121. #ifdef CONFIG_QUOTA
  122. static int reiserfs_quota_on_mount(struct super_block *, int);
  123. #endif
  124. /* look for uncompleted unlinks and truncates and complete them */
  125. static int finish_unfinished(struct super_block *s)
  126. {
  127. INITIALIZE_PATH(path);
  128. struct cpu_key max_cpu_key, obj_key;
  129. struct reiserfs_key save_link_key;
  130. int retval = 0;
  131. struct item_head *ih;
  132. struct buffer_head *bh;
  133. int item_pos;
  134. char *item;
  135. int done;
  136. struct inode *inode;
  137. int truncate;
  138. #ifdef CONFIG_QUOTA
  139. int i;
  140. int ms_active_set;
  141. #endif
  142. /* compose key to look for "save" links */
  143. max_cpu_key.version = KEY_FORMAT_3_5;
  144. max_cpu_key.on_disk_key.k_dir_id = ~0U;
  145. max_cpu_key.on_disk_key.k_objectid = ~0U;
  146. set_cpu_key_k_offset(&max_cpu_key, ~0U);
  147. max_cpu_key.key_length = 3;
  148. #ifdef CONFIG_QUOTA
  149. /* Needed for iput() to work correctly and not trash data */
  150. if (s->s_flags & MS_ACTIVE) {
  151. ms_active_set = 0;
  152. } else {
  153. ms_active_set = 1;
  154. s->s_flags |= MS_ACTIVE;
  155. }
  156. /* Turn on quotas so that they are updated correctly */
  157. for (i = 0; i < MAXQUOTAS; i++) {
  158. if (REISERFS_SB(s)->s_qf_names[i]) {
  159. int ret = reiserfs_quota_on_mount(s, i);
  160. if (ret < 0)
  161. reiserfs_warning(s,
  162. "reiserfs: cannot turn on journalled quota: error %d",
  163. ret);
  164. }
  165. }
  166. #endif
  167. done = 0;
  168. REISERFS_SB(s)->s_is_unlinked_ok = 1;
  169. while (!retval) {
  170. retval = search_item(s, &max_cpu_key, &path);
  171. if (retval != ITEM_NOT_FOUND) {
  172. reiserfs_warning(s,
  173. "vs-2140: finish_unfinished: search_by_key returned %d",
  174. retval);
  175. break;
  176. }
  177. bh = get_last_bh(&path);
  178. item_pos = get_item_pos(&path);
  179. if (item_pos != B_NR_ITEMS(bh)) {
  180. reiserfs_warning(s,
  181. "vs-2060: finish_unfinished: wrong position found");
  182. break;
  183. }
  184. item_pos--;
  185. ih = B_N_PITEM_HEAD(bh, item_pos);
  186. if (le32_to_cpu(ih->ih_key.k_dir_id) != MAX_KEY_OBJECTID)
  187. /* there are no "save" links anymore */
  188. break;
  189. save_link_key = ih->ih_key;
  190. if (is_indirect_le_ih(ih))
  191. truncate = 1;
  192. else
  193. truncate = 0;
  194. /* reiserfs_iget needs k_dirid and k_objectid only */
  195. item = B_I_PITEM(bh, ih);
  196. obj_key.on_disk_key.k_dir_id = le32_to_cpu(*(__le32 *) item);
  197. obj_key.on_disk_key.k_objectid =
  198. le32_to_cpu(ih->ih_key.k_objectid);
  199. obj_key.on_disk_key.k_offset = 0;
  200. obj_key.on_disk_key.k_type = 0;
  201. pathrelse(&path);
  202. inode = reiserfs_iget(s, &obj_key);
  203. if (!inode) {
  204. /* the unlink almost completed, it just did not manage to remove
  205. "save" link and release objectid */
  206. reiserfs_warning(s,
  207. "vs-2180: finish_unfinished: iget failed for %K",
  208. &obj_key);
  209. retval = remove_save_link_only(s, &save_link_key, 1);
  210. continue;
  211. }
  212. if (!truncate && inode->i_nlink) {
  213. /* file is not unlinked */
  214. reiserfs_warning(s,
  215. "vs-2185: finish_unfinished: file %K is not unlinked",
  216. &obj_key);
  217. retval = remove_save_link_only(s, &save_link_key, 0);
  218. continue;
  219. }
  220. DQUOT_INIT(inode);
  221. if (truncate && S_ISDIR(inode->i_mode)) {
  222. /* We got a truncate request for a dir which is impossible.
  223. The only imaginable way is to execute unfinished truncate request
  224. then boot into old kernel, remove the file and create dir with
  225. the same key. */
  226. reiserfs_warning(s,
  227. "green-2101: impossible truncate on a directory %k. Please report",
  228. INODE_PKEY(inode));
  229. retval = remove_save_link_only(s, &save_link_key, 0);
  230. truncate = 0;
  231. iput(inode);
  232. continue;
  233. }
  234. if (truncate) {
  235. REISERFS_I(inode)->i_flags |=
  236. i_link_saved_truncate_mask;
  237. /* not completed truncate found. New size was committed together
  238. with "save" link */
  239. reiserfs_info(s, "Truncating %k to %Ld ..",
  240. INODE_PKEY(inode), inode->i_size);
  241. reiserfs_truncate_file(inode,
  242. 0
  243. /*don't update modification time */
  244. );
  245. retval = remove_save_link(inode, truncate);
  246. } else {
  247. REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
  248. /* not completed unlink (rmdir) found */
  249. reiserfs_info(s, "Removing %k..", INODE_PKEY(inode));
  250. /* removal gets completed in iput */
  251. retval = 0;
  252. }
  253. iput(inode);
  254. printk("done\n");
  255. done++;
  256. }
  257. REISERFS_SB(s)->s_is_unlinked_ok = 0;
  258. #ifdef CONFIG_QUOTA
  259. /* Turn quotas off */
  260. for (i = 0; i < MAXQUOTAS; i++) {
  261. if (sb_dqopt(s)->files[i])
  262. vfs_quota_off_mount(s, i);
  263. }
  264. if (ms_active_set)
  265. /* Restore the flag back */
  266. s->s_flags &= ~MS_ACTIVE;
  267. #endif
  268. pathrelse(&path);
  269. if (done)
  270. reiserfs_info(s, "There were %d uncompleted unlinks/truncates. "
  271. "Completed\n", done);
  272. return retval;
  273. }
  274. /* to protect file being unlinked from getting lost we "safe" link files
  275. being unlinked. This link will be deleted in the same transaction with last
  276. item of file. mounting the filesytem we scan all these links and remove
  277. files which almost got lost */
  278. void add_save_link(struct reiserfs_transaction_handle *th,
  279. struct inode *inode, int truncate)
  280. {
  281. INITIALIZE_PATH(path);
  282. int retval;
  283. struct cpu_key key;
  284. struct item_head ih;
  285. __le32 link;
  286. BUG_ON(!th->t_trans_id);
  287. /* file can only get one "save link" of each kind */
  288. RFALSE(truncate &&
  289. (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask),
  290. "saved link already exists for truncated inode %lx",
  291. (long)inode->i_ino);
  292. RFALSE(!truncate &&
  293. (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask),
  294. "saved link already exists for unlinked inode %lx",
  295. (long)inode->i_ino);
  296. /* setup key of "save" link */
  297. key.version = KEY_FORMAT_3_5;
  298. key.on_disk_key.k_dir_id = MAX_KEY_OBJECTID;
  299. key.on_disk_key.k_objectid = inode->i_ino;
  300. if (!truncate) {
  301. /* unlink, rmdir, rename */
  302. set_cpu_key_k_offset(&key, 1 + inode->i_sb->s_blocksize);
  303. set_cpu_key_k_type(&key, TYPE_DIRECT);
  304. /* item head of "safe" link */
  305. make_le_item_head(&ih, &key, key.version,
  306. 1 + inode->i_sb->s_blocksize, TYPE_DIRECT,
  307. 4 /*length */ , 0xffff /*free space */ );
  308. } else {
  309. /* truncate */
  310. if (S_ISDIR(inode->i_mode))
  311. reiserfs_warning(inode->i_sb,
  312. "green-2102: Adding a truncate savelink for a directory %k! Please report",
  313. INODE_PKEY(inode));
  314. set_cpu_key_k_offset(&key, 1);
  315. set_cpu_key_k_type(&key, TYPE_INDIRECT);
  316. /* item head of "safe" link */
  317. make_le_item_head(&ih, &key, key.version, 1, TYPE_INDIRECT,
  318. 4 /*length */ , 0 /*free space */ );
  319. }
  320. key.key_length = 3;
  321. /* look for its place in the tree */
  322. retval = search_item(inode->i_sb, &key, &path);
  323. if (retval != ITEM_NOT_FOUND) {
  324. if (retval != -ENOSPC)
  325. reiserfs_warning(inode->i_sb, "vs-2100: add_save_link:"
  326. "search_by_key (%K) returned %d", &key,
  327. retval);
  328. pathrelse(&path);
  329. return;
  330. }
  331. /* body of "save" link */
  332. link = INODE_PKEY(inode)->k_dir_id;
  333. /* put "save" link inot tree, don't charge quota to anyone */
  334. retval =
  335. reiserfs_insert_item(th, &path, &key, &ih, NULL, (char *)&link);
  336. if (retval) {
  337. if (retval != -ENOSPC)
  338. reiserfs_warning(inode->i_sb,
  339. "vs-2120: add_save_link: insert_item returned %d",
  340. retval);
  341. } else {
  342. if (truncate)
  343. REISERFS_I(inode)->i_flags |=
  344. i_link_saved_truncate_mask;
  345. else
  346. REISERFS_I(inode)->i_flags |= i_link_saved_unlink_mask;
  347. }
  348. }
  349. /* this opens transaction unlike add_save_link */
  350. int remove_save_link(struct inode *inode, int truncate)
  351. {
  352. struct reiserfs_transaction_handle th;
  353. struct reiserfs_key key;
  354. int err;
  355. /* we are going to do one balancing only */
  356. err = journal_begin(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
  357. if (err)
  358. return err;
  359. /* setup key of "save" link */
  360. key.k_dir_id = cpu_to_le32(MAX_KEY_OBJECTID);
  361. key.k_objectid = INODE_PKEY(inode)->k_objectid;
  362. if (!truncate) {
  363. /* unlink, rmdir, rename */
  364. set_le_key_k_offset(KEY_FORMAT_3_5, &key,
  365. 1 + inode->i_sb->s_blocksize);
  366. set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_DIRECT);
  367. } else {
  368. /* truncate */
  369. set_le_key_k_offset(KEY_FORMAT_3_5, &key, 1);
  370. set_le_key_k_type(KEY_FORMAT_3_5, &key, TYPE_INDIRECT);
  371. }
  372. if ((truncate &&
  373. (REISERFS_I(inode)->i_flags & i_link_saved_truncate_mask)) ||
  374. (!truncate &&
  375. (REISERFS_I(inode)->i_flags & i_link_saved_unlink_mask)))
  376. /* don't take quota bytes from anywhere */
  377. reiserfs_delete_solid_item(&th, NULL, &key);
  378. if (!truncate) {
  379. reiserfs_release_objectid(&th, inode->i_ino);
  380. REISERFS_I(inode)->i_flags &= ~i_link_saved_unlink_mask;
  381. } else
  382. REISERFS_I(inode)->i_flags &= ~i_link_saved_truncate_mask;
  383. return journal_end(&th, inode->i_sb, JOURNAL_PER_BALANCE_CNT);
  384. }
  385. static void reiserfs_put_super(struct super_block *s)
  386. {
  387. int i;
  388. struct reiserfs_transaction_handle th;
  389. th.t_trans_id = 0;
  390. if (REISERFS_SB(s)->xattr_root) {
  391. d_invalidate(REISERFS_SB(s)->xattr_root);
  392. dput(REISERFS_SB(s)->xattr_root);
  393. }
  394. if (REISERFS_SB(s)->priv_root) {
  395. d_invalidate(REISERFS_SB(s)->priv_root);
  396. dput(REISERFS_SB(s)->priv_root);
  397. }
  398. /* change file system state to current state if it was mounted with read-write permissions */
  399. if (!(s->s_flags & MS_RDONLY)) {
  400. if (!journal_begin(&th, s, 10)) {
  401. reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s),
  402. 1);
  403. set_sb_umount_state(SB_DISK_SUPER_BLOCK(s),
  404. REISERFS_SB(s)->s_mount_state);
  405. journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
  406. }
  407. }
  408. /* note, journal_release checks for readonly mount, and can decide not
  409. ** to do a journal_end
  410. */
  411. journal_release(&th, s);
  412. for (i = 0; i < SB_BMAP_NR(s); i++)
  413. brelse(SB_AP_BITMAP(s)[i].bh);
  414. vfree(SB_AP_BITMAP(s));
  415. brelse(SB_BUFFER_WITH_SB(s));
  416. print_statistics(s);
  417. if (REISERFS_SB(s)->reserved_blocks != 0) {
  418. reiserfs_warning(s,
  419. "green-2005: reiserfs_put_super: reserved blocks left %d",
  420. REISERFS_SB(s)->reserved_blocks);
  421. }
  422. reiserfs_proc_info_done(s);
  423. kfree(s->s_fs_info);
  424. s->s_fs_info = NULL;
  425. return;
  426. }
  427. static kmem_cache_t *reiserfs_inode_cachep;
  428. static struct inode *reiserfs_alloc_inode(struct super_block *sb)
  429. {
  430. struct reiserfs_inode_info *ei;
  431. ei = (struct reiserfs_inode_info *)
  432. kmem_cache_alloc(reiserfs_inode_cachep, SLAB_KERNEL);
  433. if (!ei)
  434. return NULL;
  435. return &ei->vfs_inode;
  436. }
  437. static void reiserfs_destroy_inode(struct inode *inode)
  438. {
  439. kmem_cache_free(reiserfs_inode_cachep, REISERFS_I(inode));
  440. }
  441. static void init_once(void *foo, kmem_cache_t * cachep, unsigned long flags)
  442. {
  443. struct reiserfs_inode_info *ei = (struct reiserfs_inode_info *)foo;
  444. if ((flags & (SLAB_CTOR_VERIFY | SLAB_CTOR_CONSTRUCTOR)) ==
  445. SLAB_CTOR_CONSTRUCTOR) {
  446. INIT_LIST_HEAD(&ei->i_prealloc_list);
  447. inode_init_once(&ei->vfs_inode);
  448. ei->i_acl_access = NULL;
  449. ei->i_acl_default = NULL;
  450. }
  451. }
  452. static int init_inodecache(void)
  453. {
  454. reiserfs_inode_cachep = kmem_cache_create("reiser_inode_cache",
  455. sizeof(struct
  456. reiserfs_inode_info),
  457. 0, (SLAB_RECLAIM_ACCOUNT|
  458. SLAB_MEM_SPREAD),
  459. init_once, NULL);
  460. if (reiserfs_inode_cachep == NULL)
  461. return -ENOMEM;
  462. return 0;
  463. }
  464. static void destroy_inodecache(void)
  465. {
  466. kmem_cache_destroy(reiserfs_inode_cachep);
  467. }
  468. /* we don't mark inodes dirty, we just log them */
  469. static void reiserfs_dirty_inode(struct inode *inode)
  470. {
  471. struct reiserfs_transaction_handle th;
  472. int err = 0;
  473. if (inode->i_sb->s_flags & MS_RDONLY) {
  474. reiserfs_warning(inode->i_sb,
  475. "clm-6006: writing inode %lu on readonly FS",
  476. inode->i_ino);
  477. return;
  478. }
  479. reiserfs_write_lock(inode->i_sb);
  480. /* this is really only used for atime updates, so they don't have
  481. ** to be included in O_SYNC or fsync
  482. */
  483. err = journal_begin(&th, inode->i_sb, 1);
  484. if (err) {
  485. reiserfs_write_unlock(inode->i_sb);
  486. return;
  487. }
  488. reiserfs_update_sd(&th, inode);
  489. journal_end(&th, inode->i_sb, 1);
  490. reiserfs_write_unlock(inode->i_sb);
  491. }
  492. static void reiserfs_clear_inode(struct inode *inode)
  493. {
  494. struct posix_acl *acl;
  495. acl = REISERFS_I(inode)->i_acl_access;
  496. if (acl && !IS_ERR(acl))
  497. posix_acl_release(acl);
  498. REISERFS_I(inode)->i_acl_access = NULL;
  499. acl = REISERFS_I(inode)->i_acl_default;
  500. if (acl && !IS_ERR(acl))
  501. posix_acl_release(acl);
  502. REISERFS_I(inode)->i_acl_default = NULL;
  503. }
  504. #ifdef CONFIG_QUOTA
  505. static ssize_t reiserfs_quota_write(struct super_block *, int, const char *,
  506. size_t, loff_t);
  507. static ssize_t reiserfs_quota_read(struct super_block *, int, char *, size_t,
  508. loff_t);
  509. #endif
  510. static struct super_operations reiserfs_sops = {
  511. .alloc_inode = reiserfs_alloc_inode,
  512. .destroy_inode = reiserfs_destroy_inode,
  513. .write_inode = reiserfs_write_inode,
  514. .dirty_inode = reiserfs_dirty_inode,
  515. .delete_inode = reiserfs_delete_inode,
  516. .clear_inode = reiserfs_clear_inode,
  517. .put_super = reiserfs_put_super,
  518. .write_super = reiserfs_write_super,
  519. .sync_fs = reiserfs_sync_fs,
  520. .write_super_lockfs = reiserfs_write_super_lockfs,
  521. .unlockfs = reiserfs_unlockfs,
  522. .statfs = reiserfs_statfs,
  523. .remount_fs = reiserfs_remount,
  524. #ifdef CONFIG_QUOTA
  525. .quota_read = reiserfs_quota_read,
  526. .quota_write = reiserfs_quota_write,
  527. #endif
  528. };
  529. #ifdef CONFIG_QUOTA
  530. #define QTYPE2NAME(t) ((t)==USRQUOTA?"user":"group")
  531. static int reiserfs_dquot_initialize(struct inode *, int);
  532. static int reiserfs_dquot_drop(struct inode *);
  533. static int reiserfs_write_dquot(struct dquot *);
  534. static int reiserfs_acquire_dquot(struct dquot *);
  535. static int reiserfs_release_dquot(struct dquot *);
  536. static int reiserfs_mark_dquot_dirty(struct dquot *);
  537. static int reiserfs_write_info(struct super_block *, int);
  538. static int reiserfs_quota_on(struct super_block *, int, int, char *);
  539. static struct dquot_operations reiserfs_quota_operations = {
  540. .initialize = reiserfs_dquot_initialize,
  541. .drop = reiserfs_dquot_drop,
  542. .alloc_space = dquot_alloc_space,
  543. .alloc_inode = dquot_alloc_inode,
  544. .free_space = dquot_free_space,
  545. .free_inode = dquot_free_inode,
  546. .transfer = dquot_transfer,
  547. .write_dquot = reiserfs_write_dquot,
  548. .acquire_dquot = reiserfs_acquire_dquot,
  549. .release_dquot = reiserfs_release_dquot,
  550. .mark_dirty = reiserfs_mark_dquot_dirty,
  551. .write_info = reiserfs_write_info,
  552. };
  553. static struct quotactl_ops reiserfs_qctl_operations = {
  554. .quota_on = reiserfs_quota_on,
  555. .quota_off = vfs_quota_off,
  556. .quota_sync = vfs_quota_sync,
  557. .get_info = vfs_get_dqinfo,
  558. .set_info = vfs_set_dqinfo,
  559. .get_dqblk = vfs_get_dqblk,
  560. .set_dqblk = vfs_set_dqblk,
  561. };
  562. #endif
  563. static struct export_operations reiserfs_export_ops = {
  564. .encode_fh = reiserfs_encode_fh,
  565. .decode_fh = reiserfs_decode_fh,
  566. .get_parent = reiserfs_get_parent,
  567. .get_dentry = reiserfs_get_dentry,
  568. };
  569. /* this struct is used in reiserfs_getopt () for containing the value for those
  570. mount options that have values rather than being toggles. */
  571. typedef struct {
  572. char *value;
  573. int setmask; /* bitmask which is to set on mount_options bitmask when this
  574. value is found, 0 is no bits are to be changed. */
  575. int clrmask; /* bitmask which is to clear on mount_options bitmask when this
  576. value is found, 0 is no bits are to be changed. This is
  577. applied BEFORE setmask */
  578. } arg_desc_t;
  579. /* Set this bit in arg_required to allow empty arguments */
  580. #define REISERFS_OPT_ALLOWEMPTY 31
  581. /* this struct is used in reiserfs_getopt() for describing the set of reiserfs
  582. mount options */
  583. typedef struct {
  584. char *option_name;
  585. int arg_required; /* 0 if argument is not required, not 0 otherwise */
  586. const arg_desc_t *values; /* list of values accepted by an option */
  587. int setmask; /* bitmask which is to set on mount_options bitmask when this
  588. value is found, 0 is no bits are to be changed. */
  589. int clrmask; /* bitmask which is to clear on mount_options bitmask when this
  590. value is found, 0 is no bits are to be changed. This is
  591. applied BEFORE setmask */
  592. } opt_desc_t;
  593. /* possible values for -o data= */
  594. static const arg_desc_t logging_mode[] = {
  595. {"ordered", 1 << REISERFS_DATA_ORDERED,
  596. (1 << REISERFS_DATA_LOG | 1 << REISERFS_DATA_WRITEBACK)},
  597. {"journal", 1 << REISERFS_DATA_LOG,
  598. (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_WRITEBACK)},
  599. {"writeback", 1 << REISERFS_DATA_WRITEBACK,
  600. (1 << REISERFS_DATA_ORDERED | 1 << REISERFS_DATA_LOG)},
  601. {.value = NULL}
  602. };
  603. /* possible values for -o barrier= */
  604. static const arg_desc_t barrier_mode[] = {
  605. {"none", 1 << REISERFS_BARRIER_NONE, 1 << REISERFS_BARRIER_FLUSH},
  606. {"flush", 1 << REISERFS_BARRIER_FLUSH, 1 << REISERFS_BARRIER_NONE},
  607. {.value = NULL}
  608. };
  609. /* possible values for "-o block-allocator=" and bits which are to be set in
  610. s_mount_opt of reiserfs specific part of in-core super block */
  611. static const arg_desc_t balloc[] = {
  612. {"noborder", 1 << REISERFS_NO_BORDER, 0},
  613. {"border", 0, 1 << REISERFS_NO_BORDER},
  614. {"no_unhashed_relocation", 1 << REISERFS_NO_UNHASHED_RELOCATION, 0},
  615. {"hashed_relocation", 1 << REISERFS_HASHED_RELOCATION, 0},
  616. {"test4", 1 << REISERFS_TEST4, 0},
  617. {"notest4", 0, 1 << REISERFS_TEST4},
  618. {NULL, 0, 0}
  619. };
  620. static const arg_desc_t tails[] = {
  621. {"on", 1 << REISERFS_LARGETAIL, 1 << REISERFS_SMALLTAIL},
  622. {"off", 0, (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
  623. {"small", 1 << REISERFS_SMALLTAIL, 1 << REISERFS_LARGETAIL},
  624. {NULL, 0, 0}
  625. };
  626. static const arg_desc_t error_actions[] = {
  627. {"panic", 1 << REISERFS_ERROR_PANIC,
  628. (1 << REISERFS_ERROR_RO | 1 << REISERFS_ERROR_CONTINUE)},
  629. {"ro-remount", 1 << REISERFS_ERROR_RO,
  630. (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_CONTINUE)},
  631. #ifdef REISERFS_JOURNAL_ERROR_ALLOWS_NO_LOG
  632. {"continue", 1 << REISERFS_ERROR_CONTINUE,
  633. (1 << REISERFS_ERROR_PANIC | 1 << REISERFS_ERROR_RO)},
  634. #endif
  635. {NULL, 0, 0},
  636. };
  637. /* proceed only one option from a list *cur - string containing of mount options
  638. opts - array of options which are accepted
  639. opt_arg - if option is found and requires an argument and if it is specifed
  640. in the input - pointer to the argument is stored here
  641. bit_flags - if option requires to set a certain bit - it is set here
  642. return -1 if unknown option is found, opt->arg_required otherwise */
  643. static int reiserfs_getopt(struct super_block *s, char **cur, opt_desc_t * opts,
  644. char **opt_arg, unsigned long *bit_flags)
  645. {
  646. char *p;
  647. /* foo=bar,
  648. ^ ^ ^
  649. | | +-- option_end
  650. | +-- arg_start
  651. +-- option_start
  652. */
  653. const opt_desc_t *opt;
  654. const arg_desc_t *arg;
  655. p = *cur;
  656. /* assume argument cannot contain commas */
  657. *cur = strchr(p, ',');
  658. if (*cur) {
  659. *(*cur) = '\0';
  660. (*cur)++;
  661. }
  662. if (!strncmp(p, "alloc=", 6)) {
  663. /* Ugly special case, probably we should redo options parser so that
  664. it can understand several arguments for some options, also so that
  665. it can fill several bitfields with option values. */
  666. if (reiserfs_parse_alloc_options(s, p + 6)) {
  667. return -1;
  668. } else {
  669. return 0;
  670. }
  671. }
  672. /* for every option in the list */
  673. for (opt = opts; opt->option_name; opt++) {
  674. if (!strncmp(p, opt->option_name, strlen(opt->option_name))) {
  675. if (bit_flags) {
  676. if (opt->clrmask ==
  677. (1 << REISERFS_UNSUPPORTED_OPT))
  678. reiserfs_warning(s, "%s not supported.",
  679. p);
  680. else
  681. *bit_flags &= ~opt->clrmask;
  682. if (opt->setmask ==
  683. (1 << REISERFS_UNSUPPORTED_OPT))
  684. reiserfs_warning(s, "%s not supported.",
  685. p);
  686. else
  687. *bit_flags |= opt->setmask;
  688. }
  689. break;
  690. }
  691. }
  692. if (!opt->option_name) {
  693. reiserfs_warning(s, "unknown mount option \"%s\"", p);
  694. return -1;
  695. }
  696. p += strlen(opt->option_name);
  697. switch (*p) {
  698. case '=':
  699. if (!opt->arg_required) {
  700. reiserfs_warning(s,
  701. "the option \"%s\" does not require an argument",
  702. opt->option_name);
  703. return -1;
  704. }
  705. break;
  706. case 0:
  707. if (opt->arg_required) {
  708. reiserfs_warning(s,
  709. "the option \"%s\" requires an argument",
  710. opt->option_name);
  711. return -1;
  712. }
  713. break;
  714. default:
  715. reiserfs_warning(s, "head of option \"%s\" is only correct",
  716. opt->option_name);
  717. return -1;
  718. }
  719. /* move to the argument, or to next option if argument is not required */
  720. p++;
  721. if (opt->arg_required
  722. && !(opt->arg_required & (1 << REISERFS_OPT_ALLOWEMPTY))
  723. && !strlen(p)) {
  724. /* this catches "option=," if not allowed */
  725. reiserfs_warning(s, "empty argument for \"%s\"",
  726. opt->option_name);
  727. return -1;
  728. }
  729. if (!opt->values) {
  730. /* *=NULLopt_arg contains pointer to argument */
  731. *opt_arg = p;
  732. return opt->arg_required & ~(1 << REISERFS_OPT_ALLOWEMPTY);
  733. }
  734. /* values possible for this option are listed in opt->values */
  735. for (arg = opt->values; arg->value; arg++) {
  736. if (!strcmp(p, arg->value)) {
  737. if (bit_flags) {
  738. *bit_flags &= ~arg->clrmask;
  739. *bit_flags |= arg->setmask;
  740. }
  741. return opt->arg_required;
  742. }
  743. }
  744. reiserfs_warning(s, "bad value \"%s\" for option \"%s\"", p,
  745. opt->option_name);
  746. return -1;
  747. }
  748. /* returns 0 if something is wrong in option string, 1 - otherwise */
  749. static int reiserfs_parse_options(struct super_block *s, char *options, /* string given via mount's -o */
  750. unsigned long *mount_options,
  751. /* after the parsing phase, contains the
  752. collection of bitflags defining what
  753. mount options were selected. */
  754. unsigned long *blocks, /* strtol-ed from NNN of resize=NNN */
  755. char **jdev_name,
  756. unsigned int *commit_max_age)
  757. {
  758. int c;
  759. char *arg = NULL;
  760. char *pos;
  761. opt_desc_t opts[] = {
  762. /* Compatibility stuff, so that -o notail for old setups still work */
  763. {"tails",.arg_required = 't',.values = tails},
  764. {"notail",.clrmask =
  765. (1 << REISERFS_LARGETAIL) | (1 << REISERFS_SMALLTAIL)},
  766. {"conv",.setmask = 1 << REISERFS_CONVERT},
  767. {"attrs",.setmask = 1 << REISERFS_ATTRS},
  768. {"noattrs",.clrmask = 1 << REISERFS_ATTRS},
  769. #ifdef CONFIG_REISERFS_FS_XATTR
  770. {"user_xattr",.setmask = 1 << REISERFS_XATTRS_USER},
  771. {"nouser_xattr",.clrmask = 1 << REISERFS_XATTRS_USER},
  772. #else
  773. {"user_xattr",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
  774. {"nouser_xattr",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
  775. #endif
  776. #ifdef CONFIG_REISERFS_FS_POSIX_ACL
  777. {"acl",.setmask = 1 << REISERFS_POSIXACL},
  778. {"noacl",.clrmask = 1 << REISERFS_POSIXACL},
  779. #else
  780. {"acl",.setmask = 1 << REISERFS_UNSUPPORTED_OPT},
  781. {"noacl",.clrmask = 1 << REISERFS_UNSUPPORTED_OPT},
  782. #endif
  783. {.option_name = "nolog"},
  784. {"replayonly",.setmask = 1 << REPLAYONLY},
  785. {"block-allocator",.arg_required = 'a',.values = balloc},
  786. {"data",.arg_required = 'd',.values = logging_mode},
  787. {"barrier",.arg_required = 'b',.values = barrier_mode},
  788. {"resize",.arg_required = 'r',.values = NULL},
  789. {"jdev",.arg_required = 'j',.values = NULL},
  790. {"nolargeio",.arg_required = 'w',.values = NULL},
  791. {"commit",.arg_required = 'c',.values = NULL},
  792. {"usrquota",.setmask = 1 << REISERFS_QUOTA},
  793. {"grpquota",.setmask = 1 << REISERFS_QUOTA},
  794. {"noquota",.clrmask = 1 << REISERFS_QUOTA},
  795. {"errors",.arg_required = 'e',.values = error_actions},
  796. {"usrjquota",.arg_required =
  797. 'u' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
  798. {"grpjquota",.arg_required =
  799. 'g' | (1 << REISERFS_OPT_ALLOWEMPTY),.values = NULL},
  800. {"jqfmt",.arg_required = 'f',.values = NULL},
  801. {.option_name = NULL}
  802. };
  803. *blocks = 0;
  804. if (!options || !*options)
  805. /* use default configuration: create tails, journaling on, no
  806. conversion to newest format */
  807. return 1;
  808. for (pos = options; pos;) {
  809. c = reiserfs_getopt(s, &pos, opts, &arg, mount_options);
  810. if (c == -1)
  811. /* wrong option is given */
  812. return 0;
  813. if (c == 'r') {
  814. char *p;
  815. p = NULL;
  816. /* "resize=NNN" or "resize=auto" */
  817. if (!strcmp(arg, "auto")) {
  818. /* From JFS code, to auto-get the size. */
  819. *blocks =
  820. s->s_bdev->bd_inode->i_size >> s->
  821. s_blocksize_bits;
  822. } else {
  823. *blocks = simple_strtoul(arg, &p, 0);
  824. if (*p != '\0') {
  825. /* NNN does not look like a number */
  826. reiserfs_warning(s,
  827. "reiserfs_parse_options: bad value %s",
  828. arg);
  829. return 0;
  830. }
  831. }
  832. }
  833. if (c == 'c') {
  834. char *p = NULL;
  835. unsigned long val = simple_strtoul(arg, &p, 0);
  836. /* commit=NNN (time in seconds) */
  837. if (*p != '\0' || val >= (unsigned int)-1) {
  838. reiserfs_warning(s,
  839. "reiserfs_parse_options: bad value %s",
  840. arg);
  841. return 0;
  842. }
  843. *commit_max_age = (unsigned int)val;
  844. }
  845. if (c == 'w') {
  846. reiserfs_warning(s, "reiserfs: nolargeio option is no longer supported");
  847. return 0;
  848. }
  849. if (c == 'j') {
  850. if (arg && *arg && jdev_name) {
  851. if (*jdev_name) { //Hm, already assigned?
  852. reiserfs_warning(s,
  853. "reiserfs_parse_options: journal device was already specified to be %s",
  854. *jdev_name);
  855. return 0;
  856. }
  857. *jdev_name = arg;
  858. }
  859. }
  860. #ifdef CONFIG_QUOTA
  861. if (c == 'u' || c == 'g') {
  862. int qtype = c == 'u' ? USRQUOTA : GRPQUOTA;
  863. if (sb_any_quota_enabled(s)) {
  864. reiserfs_warning(s,
  865. "reiserfs_parse_options: cannot change journalled quota options when quota turned on.");
  866. return 0;
  867. }
  868. if (*arg) { /* Some filename specified? */
  869. if (REISERFS_SB(s)->s_qf_names[qtype]
  870. && strcmp(REISERFS_SB(s)->s_qf_names[qtype],
  871. arg)) {
  872. reiserfs_warning(s,
  873. "reiserfs_parse_options: %s quota file already specified.",
  874. QTYPE2NAME(qtype));
  875. return 0;
  876. }
  877. if (strchr(arg, '/')) {
  878. reiserfs_warning(s,
  879. "reiserfs_parse_options: quotafile must be on filesystem root.");
  880. return 0;
  881. }
  882. REISERFS_SB(s)->s_qf_names[qtype] =
  883. kmalloc(strlen(arg) + 1, GFP_KERNEL);
  884. if (!REISERFS_SB(s)->s_qf_names[qtype]) {
  885. reiserfs_warning(s,
  886. "reiserfs_parse_options: not enough memory for storing quotafile name.");
  887. return 0;
  888. }
  889. strcpy(REISERFS_SB(s)->s_qf_names[qtype], arg);
  890. *mount_options |= 1 << REISERFS_QUOTA;
  891. } else {
  892. kfree(REISERFS_SB(s)->s_qf_names[qtype]);
  893. REISERFS_SB(s)->s_qf_names[qtype] = NULL;
  894. }
  895. }
  896. if (c == 'f') {
  897. if (!strcmp(arg, "vfsold"))
  898. REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_OLD;
  899. else if (!strcmp(arg, "vfsv0"))
  900. REISERFS_SB(s)->s_jquota_fmt = QFMT_VFS_V0;
  901. else {
  902. reiserfs_warning(s,
  903. "reiserfs_parse_options: unknown quota format specified.");
  904. return 0;
  905. }
  906. }
  907. #else
  908. if (c == 'u' || c == 'g' || c == 'f') {
  909. reiserfs_warning(s,
  910. "reiserfs_parse_options: journalled quota options not supported.");
  911. return 0;
  912. }
  913. #endif
  914. }
  915. #ifdef CONFIG_QUOTA
  916. if (!REISERFS_SB(s)->s_jquota_fmt
  917. && (REISERFS_SB(s)->s_qf_names[USRQUOTA]
  918. || REISERFS_SB(s)->s_qf_names[GRPQUOTA])) {
  919. reiserfs_warning(s,
  920. "reiserfs_parse_options: journalled quota format not specified.");
  921. return 0;
  922. }
  923. /* This checking is not precise wrt the quota type but for our purposes it is sufficient */
  924. if (!(*mount_options & (1 << REISERFS_QUOTA))
  925. && sb_any_quota_enabled(s)) {
  926. reiserfs_warning(s,
  927. "reiserfs_parse_options: quota options must be present when quota is turned on.");
  928. return 0;
  929. }
  930. #endif
  931. return 1;
  932. }
  933. static void switch_data_mode(struct super_block *s, unsigned long mode)
  934. {
  935. REISERFS_SB(s)->s_mount_opt &= ~((1 << REISERFS_DATA_LOG) |
  936. (1 << REISERFS_DATA_ORDERED) |
  937. (1 << REISERFS_DATA_WRITEBACK));
  938. REISERFS_SB(s)->s_mount_opt |= (1 << mode);
  939. }
  940. static void handle_data_mode(struct super_block *s, unsigned long mount_options)
  941. {
  942. if (mount_options & (1 << REISERFS_DATA_LOG)) {
  943. if (!reiserfs_data_log(s)) {
  944. switch_data_mode(s, REISERFS_DATA_LOG);
  945. reiserfs_info(s, "switching to journaled data mode\n");
  946. }
  947. } else if (mount_options & (1 << REISERFS_DATA_ORDERED)) {
  948. if (!reiserfs_data_ordered(s)) {
  949. switch_data_mode(s, REISERFS_DATA_ORDERED);
  950. reiserfs_info(s, "switching to ordered data mode\n");
  951. }
  952. } else if (mount_options & (1 << REISERFS_DATA_WRITEBACK)) {
  953. if (!reiserfs_data_writeback(s)) {
  954. switch_data_mode(s, REISERFS_DATA_WRITEBACK);
  955. reiserfs_info(s, "switching to writeback data mode\n");
  956. }
  957. }
  958. }
  959. static void handle_barrier_mode(struct super_block *s, unsigned long bits)
  960. {
  961. int flush = (1 << REISERFS_BARRIER_FLUSH);
  962. int none = (1 << REISERFS_BARRIER_NONE);
  963. int all_barrier = flush | none;
  964. if (bits & all_barrier) {
  965. REISERFS_SB(s)->s_mount_opt &= ~all_barrier;
  966. if (bits & flush) {
  967. REISERFS_SB(s)->s_mount_opt |= flush;
  968. printk("reiserfs: enabling write barrier flush mode\n");
  969. } else if (bits & none) {
  970. REISERFS_SB(s)->s_mount_opt |= none;
  971. printk("reiserfs: write barriers turned off\n");
  972. }
  973. }
  974. }
  975. static void handle_attrs(struct super_block *s)
  976. {
  977. struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
  978. if (reiserfs_attrs(s)) {
  979. if (old_format_only(s)) {
  980. reiserfs_warning(s,
  981. "reiserfs: cannot support attributes on 3.5.x disk format");
  982. REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
  983. return;
  984. }
  985. if (!(le32_to_cpu(rs->s_flags) & reiserfs_attrs_cleared)) {
  986. reiserfs_warning(s,
  987. "reiserfs: cannot support attributes until flag is set in super-block");
  988. REISERFS_SB(s)->s_mount_opt &= ~(1 << REISERFS_ATTRS);
  989. }
  990. }
  991. }
  992. static int reiserfs_remount(struct super_block *s, int *mount_flags, char *arg)
  993. {
  994. struct reiserfs_super_block *rs;
  995. struct reiserfs_transaction_handle th;
  996. unsigned long blocks;
  997. unsigned long mount_options = REISERFS_SB(s)->s_mount_opt;
  998. unsigned long safe_mask = 0;
  999. unsigned int commit_max_age = (unsigned int)-1;
  1000. struct reiserfs_journal *journal = SB_JOURNAL(s);
  1001. int err;
  1002. #ifdef CONFIG_QUOTA
  1003. int i;
  1004. #endif
  1005. rs = SB_DISK_SUPER_BLOCK(s);
  1006. if (!reiserfs_parse_options
  1007. (s, arg, &mount_options, &blocks, NULL, &commit_max_age)) {
  1008. #ifdef CONFIG_QUOTA
  1009. for (i = 0; i < MAXQUOTAS; i++) {
  1010. kfree(REISERFS_SB(s)->s_qf_names[i]);
  1011. REISERFS_SB(s)->s_qf_names[i] = NULL;
  1012. }
  1013. #endif
  1014. return -EINVAL;
  1015. }
  1016. handle_attrs(s);
  1017. /* Add options that are safe here */
  1018. safe_mask |= 1 << REISERFS_SMALLTAIL;
  1019. safe_mask |= 1 << REISERFS_LARGETAIL;
  1020. safe_mask |= 1 << REISERFS_NO_BORDER;
  1021. safe_mask |= 1 << REISERFS_NO_UNHASHED_RELOCATION;
  1022. safe_mask |= 1 << REISERFS_HASHED_RELOCATION;
  1023. safe_mask |= 1 << REISERFS_TEST4;
  1024. safe_mask |= 1 << REISERFS_ATTRS;
  1025. safe_mask |= 1 << REISERFS_XATTRS_USER;
  1026. safe_mask |= 1 << REISERFS_POSIXACL;
  1027. safe_mask |= 1 << REISERFS_BARRIER_FLUSH;
  1028. safe_mask |= 1 << REISERFS_BARRIER_NONE;
  1029. safe_mask |= 1 << REISERFS_ERROR_RO;
  1030. safe_mask |= 1 << REISERFS_ERROR_CONTINUE;
  1031. safe_mask |= 1 << REISERFS_ERROR_PANIC;
  1032. safe_mask |= 1 << REISERFS_QUOTA;
  1033. /* Update the bitmask, taking care to keep
  1034. * the bits we're not allowed to change here */
  1035. REISERFS_SB(s)->s_mount_opt =
  1036. (REISERFS_SB(s)->
  1037. s_mount_opt & ~safe_mask) | (mount_options & safe_mask);
  1038. if (commit_max_age != 0 && commit_max_age != (unsigned int)-1) {
  1039. journal->j_max_commit_age = commit_max_age;
  1040. journal->j_max_trans_age = commit_max_age;
  1041. } else if (commit_max_age == 0) {
  1042. /* 0 means restore defaults. */
  1043. journal->j_max_commit_age = journal->j_default_max_commit_age;
  1044. journal->j_max_trans_age = JOURNAL_MAX_TRANS_AGE;
  1045. }
  1046. if (blocks) {
  1047. int rc = reiserfs_resize(s, blocks);
  1048. if (rc != 0)
  1049. return rc;
  1050. }
  1051. if (*mount_flags & MS_RDONLY) {
  1052. reiserfs_xattr_init(s, *mount_flags);
  1053. /* remount read-only */
  1054. if (s->s_flags & MS_RDONLY)
  1055. /* it is read-only already */
  1056. return 0;
  1057. /* try to remount file system with read-only permissions */
  1058. if (sb_umount_state(rs) == REISERFS_VALID_FS
  1059. || REISERFS_SB(s)->s_mount_state != REISERFS_VALID_FS) {
  1060. return 0;
  1061. }
  1062. err = journal_begin(&th, s, 10);
  1063. if (err)
  1064. return err;
  1065. /* Mounting a rw partition read-only. */
  1066. reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
  1067. set_sb_umount_state(rs, REISERFS_SB(s)->s_mount_state);
  1068. journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
  1069. } else {
  1070. /* remount read-write */
  1071. if (!(s->s_flags & MS_RDONLY)) {
  1072. reiserfs_xattr_init(s, *mount_flags);
  1073. return 0; /* We are read-write already */
  1074. }
  1075. if (reiserfs_is_journal_aborted(journal))
  1076. return journal->j_errno;
  1077. handle_data_mode(s, mount_options);
  1078. handle_barrier_mode(s, mount_options);
  1079. REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
  1080. s->s_flags &= ~MS_RDONLY; /* now it is safe to call journal_begin */
  1081. err = journal_begin(&th, s, 10);
  1082. if (err)
  1083. return err;
  1084. /* Mount a partition which is read-only, read-write */
  1085. reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
  1086. REISERFS_SB(s)->s_mount_state = sb_umount_state(rs);
  1087. s->s_flags &= ~MS_RDONLY;
  1088. set_sb_umount_state(rs, REISERFS_ERROR_FS);
  1089. /* mark_buffer_dirty (SB_BUFFER_WITH_SB (s), 1); */
  1090. journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
  1091. REISERFS_SB(s)->s_mount_state = REISERFS_VALID_FS;
  1092. }
  1093. /* this will force a full flush of all journal lists */
  1094. SB_JOURNAL(s)->j_must_wait = 1;
  1095. err = journal_end(&th, s, 10);
  1096. if (err)
  1097. return err;
  1098. s->s_dirt = 0;
  1099. if (!(*mount_flags & MS_RDONLY)) {
  1100. finish_unfinished(s);
  1101. reiserfs_xattr_init(s, *mount_flags);
  1102. }
  1103. return 0;
  1104. }
  1105. /* load_bitmap_info_data - Sets up the reiserfs_bitmap_info structure from disk.
  1106. * @sb - superblock for this filesystem
  1107. * @bi - the bitmap info to be loaded. Requires that bi->bh is valid.
  1108. *
  1109. * This routine counts how many free bits there are, finding the first zero
  1110. * as a side effect. Could also be implemented as a loop of test_bit() calls, or
  1111. * a loop of find_first_zero_bit() calls. This implementation is similar to
  1112. * find_first_zero_bit(), but doesn't return after it finds the first bit.
  1113. * Should only be called on fs mount, but should be fairly efficient anyways.
  1114. *
  1115. * bi->first_zero_hint is considered unset if it == 0, since the bitmap itself
  1116. * will * invariably occupt block 0 represented in the bitmap. The only
  1117. * exception to this is when free_count also == 0, since there will be no
  1118. * free blocks at all.
  1119. */
  1120. static void load_bitmap_info_data(struct super_block *sb,
  1121. struct reiserfs_bitmap_info *bi)
  1122. {
  1123. unsigned long *cur = (unsigned long *)bi->bh->b_data;
  1124. while ((char *)cur < (bi->bh->b_data + sb->s_blocksize)) {
  1125. /* No need to scan if all 0's or all 1's.
  1126. * Since we're only counting 0's, we can simply ignore all 1's */
  1127. if (*cur == 0) {
  1128. if (bi->first_zero_hint == 0) {
  1129. bi->first_zero_hint =
  1130. ((char *)cur - bi->bh->b_data) << 3;
  1131. }
  1132. bi->free_count += sizeof(unsigned long) * 8;
  1133. } else if (*cur != ~0L) {
  1134. int b;
  1135. for (b = 0; b < sizeof(unsigned long) * 8; b++) {
  1136. if (!reiserfs_test_le_bit(b, cur)) {
  1137. bi->free_count++;
  1138. if (bi->first_zero_hint == 0)
  1139. bi->first_zero_hint =
  1140. (((char *)cur -
  1141. bi->bh->b_data) << 3) + b;
  1142. }
  1143. }
  1144. }
  1145. cur++;
  1146. }
  1147. #ifdef CONFIG_REISERFS_CHECK
  1148. // This outputs a lot of unneded info on big FSes
  1149. // reiserfs_warning ("bitmap loaded from block %d: %d free blocks",
  1150. // bi->bh->b_blocknr, bi->free_count);
  1151. #endif
  1152. }
  1153. static int read_bitmaps(struct super_block *s)
  1154. {
  1155. int i, bmap_nr;
  1156. SB_AP_BITMAP(s) =
  1157. vmalloc(sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
  1158. if (SB_AP_BITMAP(s) == 0)
  1159. return 1;
  1160. memset(SB_AP_BITMAP(s), 0,
  1161. sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(s));
  1162. for (i = 0, bmap_nr =
  1163. REISERFS_DISK_OFFSET_IN_BYTES / s->s_blocksize + 1;
  1164. i < SB_BMAP_NR(s); i++, bmap_nr = s->s_blocksize * 8 * i) {
  1165. SB_AP_BITMAP(s)[i].bh = sb_getblk(s, bmap_nr);
  1166. if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh))
  1167. ll_rw_block(READ, 1, &SB_AP_BITMAP(s)[i].bh);
  1168. }
  1169. for (i = 0; i < SB_BMAP_NR(s); i++) {
  1170. wait_on_buffer(SB_AP_BITMAP(s)[i].bh);
  1171. if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
  1172. reiserfs_warning(s, "sh-2029: reiserfs read_bitmaps: "
  1173. "bitmap block (#%lu) reading failed",
  1174. SB_AP_BITMAP(s)[i].bh->b_blocknr);
  1175. for (i = 0; i < SB_BMAP_NR(s); i++)
  1176. brelse(SB_AP_BITMAP(s)[i].bh);
  1177. vfree(SB_AP_BITMAP(s));
  1178. SB_AP_BITMAP(s) = NULL;
  1179. return 1;
  1180. }
  1181. load_bitmap_info_data(s, SB_AP_BITMAP(s) + i);
  1182. }
  1183. return 0;
  1184. }
  1185. static int read_old_bitmaps(struct super_block *s)
  1186. {
  1187. int i;
  1188. struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(s);
  1189. int bmp1 = (REISERFS_OLD_DISK_OFFSET_IN_BYTES / s->s_blocksize) + 1; /* first of bitmap blocks */
  1190. /* read true bitmap */
  1191. SB_AP_BITMAP(s) =
  1192. vmalloc(sizeof(struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
  1193. if (SB_AP_BITMAP(s) == 0)
  1194. return 1;
  1195. memset(SB_AP_BITMAP(s), 0,
  1196. sizeof(struct reiserfs_buffer_info *) * sb_bmap_nr(rs));
  1197. for (i = 0; i < sb_bmap_nr(rs); i++) {
  1198. SB_AP_BITMAP(s)[i].bh = sb_bread(s, bmp1 + i);
  1199. if (!SB_AP_BITMAP(s)[i].bh)
  1200. return 1;
  1201. load_bitmap_info_data(s, SB_AP_BITMAP(s) + i);
  1202. }
  1203. return 0;
  1204. }
  1205. static int read_super_block(struct super_block *s, int offset)
  1206. {
  1207. struct buffer_head *bh;
  1208. struct reiserfs_super_block *rs;
  1209. int fs_blocksize;
  1210. bh = sb_bread(s, offset / s->s_blocksize);
  1211. if (!bh) {
  1212. reiserfs_warning(s, "sh-2006: read_super_block: "
  1213. "bread failed (dev %s, block %lu, size %lu)",
  1214. reiserfs_bdevname(s), offset / s->s_blocksize,
  1215. s->s_blocksize);
  1216. return 1;
  1217. }
  1218. rs = (struct reiserfs_super_block *)bh->b_data;
  1219. if (!is_any_reiserfs_magic_string(rs)) {
  1220. brelse(bh);
  1221. return 1;
  1222. }
  1223. //
  1224. // ok, reiserfs signature (old or new) found in at the given offset
  1225. //
  1226. fs_blocksize = sb_blocksize(rs);
  1227. brelse(bh);
  1228. sb_set_blocksize(s, fs_blocksize);
  1229. bh = sb_bread(s, offset / s->s_blocksize);
  1230. if (!bh) {
  1231. reiserfs_warning(s, "sh-2007: read_super_block: "
  1232. "bread failed (dev %s, block %lu, size %lu)\n",
  1233. reiserfs_bdevname(s), offset / s->s_blocksize,
  1234. s->s_blocksize);
  1235. return 1;
  1236. }
  1237. rs = (struct reiserfs_super_block *)bh->b_data;
  1238. if (sb_blocksize(rs) != s->s_blocksize) {
  1239. reiserfs_warning(s, "sh-2011: read_super_block: "
  1240. "can't find a reiserfs filesystem on (dev %s, block %Lu, size %lu)\n",
  1241. reiserfs_bdevname(s),
  1242. (unsigned long long)bh->b_blocknr,
  1243. s->s_blocksize);
  1244. brelse(bh);
  1245. return 1;
  1246. }
  1247. if (rs->s_v1.s_root_block == cpu_to_le32(-1)) {
  1248. brelse(bh);
  1249. reiserfs_warning(s,
  1250. "Unfinished reiserfsck --rebuild-tree run detected. Please run\n"
  1251. "reiserfsck --rebuild-tree and wait for a completion. If that fails\n"
  1252. "get newer reiserfsprogs package");
  1253. return 1;
  1254. }
  1255. SB_BUFFER_WITH_SB(s) = bh;
  1256. SB_DISK_SUPER_BLOCK(s) = rs;
  1257. if (is_reiserfs_jr(rs)) {
  1258. /* magic is of non-standard journal filesystem, look at s_version to
  1259. find which format is in use */
  1260. if (sb_version(rs) == REISERFS_VERSION_2)
  1261. reiserfs_warning(s,
  1262. "read_super_block: found reiserfs format \"3.6\""
  1263. " with non-standard journal");
  1264. else if (sb_version(rs) == REISERFS_VERSION_1)
  1265. reiserfs_warning(s,
  1266. "read_super_block: found reiserfs format \"3.5\""
  1267. " with non-standard journal");
  1268. else {
  1269. reiserfs_warning(s,
  1270. "sh-2012: read_super_block: found unknown "
  1271. "format \"%u\" of reiserfs with non-standard magic",
  1272. sb_version(rs));
  1273. return 1;
  1274. }
  1275. } else
  1276. /* s_version of standard format may contain incorrect information,
  1277. so we just look at the magic string */
  1278. reiserfs_info(s,
  1279. "found reiserfs format \"%s\" with standard journal\n",
  1280. is_reiserfs_3_5(rs) ? "3.5" : "3.6");
  1281. s->s_op = &reiserfs_sops;
  1282. s->s_export_op = &reiserfs_export_ops;
  1283. #ifdef CONFIG_QUOTA
  1284. s->s_qcop = &reiserfs_qctl_operations;
  1285. s->dq_op = &reiserfs_quota_operations;
  1286. #endif
  1287. /* new format is limited by the 32 bit wide i_blocks field, want to
  1288. ** be one full block below that.
  1289. */
  1290. s->s_maxbytes = (512LL << 32) - s->s_blocksize;
  1291. return 0;
  1292. }
  1293. /* after journal replay, reread all bitmap and super blocks */
  1294. static int reread_meta_blocks(struct super_block *s)
  1295. {
  1296. int i;
  1297. ll_rw_block(READ, 1, &(SB_BUFFER_WITH_SB(s)));
  1298. wait_on_buffer(SB_BUFFER_WITH_SB(s));
  1299. if (!buffer_uptodate(SB_BUFFER_WITH_SB(s))) {
  1300. reiserfs_warning(s,
  1301. "reread_meta_blocks, error reading the super");
  1302. return 1;
  1303. }
  1304. for (i = 0; i < SB_BMAP_NR(s); i++) {
  1305. ll_rw_block(READ, 1, &(SB_AP_BITMAP(s)[i].bh));
  1306. wait_on_buffer(SB_AP_BITMAP(s)[i].bh);
  1307. if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
  1308. reiserfs_warning(s,
  1309. "reread_meta_blocks, error reading bitmap block number %d at %llu",
  1310. i,
  1311. (unsigned long long)SB_AP_BITMAP(s)[i].
  1312. bh->b_blocknr);
  1313. return 1;
  1314. }
  1315. }
  1316. return 0;
  1317. }
  1318. /////////////////////////////////////////////////////
  1319. // hash detection stuff
  1320. // if root directory is empty - we set default - Yura's - hash and
  1321. // warn about it
  1322. // FIXME: we look for only one name in a directory. If tea and yura
  1323. // bith have the same value - we ask user to send report to the
  1324. // mailing list
  1325. static __u32 find_hash_out(struct super_block *s)
  1326. {
  1327. int retval;
  1328. struct inode *inode;
  1329. struct cpu_key key;
  1330. INITIALIZE_PATH(path);
  1331. struct reiserfs_dir_entry de;
  1332. __u32 hash = DEFAULT_HASH;
  1333. inode = s->s_root->d_inode;
  1334. do { // Some serious "goto"-hater was there ;)
  1335. u32 teahash, r5hash, yurahash;
  1336. make_cpu_key(&key, inode, ~0, TYPE_DIRENTRY, 3);
  1337. retval = search_by_entry_key(s, &key, &path, &de);
  1338. if (retval == IO_ERROR) {
  1339. pathrelse(&path);
  1340. return UNSET_HASH;
  1341. }
  1342. if (retval == NAME_NOT_FOUND)
  1343. de.de_entry_num--;
  1344. set_de_name_and_namelen(&de);
  1345. if (deh_offset(&(de.de_deh[de.de_entry_num])) == DOT_DOT_OFFSET) {
  1346. /* allow override in this case */
  1347. if (reiserfs_rupasov_hash(s)) {
  1348. hash = YURA_HASH;
  1349. }
  1350. reiserfs_warning(s, "FS seems to be empty, autodetect "
  1351. "is using the default hash");
  1352. break;
  1353. }
  1354. r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
  1355. teahash = GET_HASH_VALUE(keyed_hash(de.de_name, de.de_namelen));
  1356. yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
  1357. if (((teahash == r5hash)
  1358. &&
  1359. (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num])))
  1360. == r5hash)) || ((teahash == yurahash)
  1361. && (yurahash ==
  1362. GET_HASH_VALUE(deh_offset
  1363. (&
  1364. (de.
  1365. de_deh[de.
  1366. de_entry_num])))))
  1367. || ((r5hash == yurahash)
  1368. && (yurahash ==
  1369. GET_HASH_VALUE(deh_offset
  1370. (&(de.de_deh[de.de_entry_num])))))) {
  1371. reiserfs_warning(s,
  1372. "Unable to automatically detect hash function. "
  1373. "Please mount with -o hash={tea,rupasov,r5}",
  1374. reiserfs_bdevname(s));
  1375. hash = UNSET_HASH;
  1376. break;
  1377. }
  1378. if (GET_HASH_VALUE(deh_offset(&(de.de_deh[de.de_entry_num]))) ==
  1379. yurahash)
  1380. hash = YURA_HASH;
  1381. else if (GET_HASH_VALUE
  1382. (deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash)
  1383. hash = TEA_HASH;
  1384. else if (GET_HASH_VALUE
  1385. (deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)
  1386. hash = R5_HASH;
  1387. else {
  1388. reiserfs_warning(s, "Unrecognised hash function");
  1389. hash = UNSET_HASH;
  1390. }
  1391. } while (0);
  1392. pathrelse(&path);
  1393. return hash;
  1394. }
  1395. // finds out which hash names are sorted with
  1396. static int what_hash(struct super_block *s)
  1397. {
  1398. __u32 code;
  1399. code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(s));
  1400. /* reiserfs_hash_detect() == true if any of the hash mount options
  1401. ** were used. We must check them to make sure the user isn't
  1402. ** using a bad hash value
  1403. */
  1404. if (code == UNSET_HASH || reiserfs_hash_detect(s))
  1405. code = find_hash_out(s);
  1406. if (code != UNSET_HASH && reiserfs_hash_detect(s)) {
  1407. /* detection has found the hash, and we must check against the
  1408. ** mount options
  1409. */
  1410. if (reiserfs_rupasov_hash(s) && code != YURA_HASH) {
  1411. reiserfs_warning(s, "Error, %s hash detected, "
  1412. "unable to force rupasov hash",
  1413. reiserfs_hashname(code));
  1414. code = UNSET_HASH;
  1415. } else if (reiserfs_tea_hash(s) && code != TEA_HASH) {
  1416. reiserfs_warning(s, "Error, %s hash detected, "
  1417. "unable to force tea hash",
  1418. reiserfs_hashname(code));
  1419. code = UNSET_HASH;
  1420. } else if (reiserfs_r5_hash(s) && code != R5_HASH) {
  1421. reiserfs_warning(s, "Error, %s hash detected, "
  1422. "unable to force r5 hash",
  1423. reiserfs_hashname(code));
  1424. code = UNSET_HASH;
  1425. }
  1426. } else {
  1427. /* find_hash_out was not called or could not determine the hash */
  1428. if (reiserfs_rupasov_hash(s)) {
  1429. code = YURA_HASH;
  1430. } else if (reiserfs_tea_hash(s)) {
  1431. code = TEA_HASH;
  1432. } else if (reiserfs_r5_hash(s)) {
  1433. code = R5_HASH;
  1434. }
  1435. }
  1436. /* if we are mounted RW, and we have a new valid hash code, update
  1437. ** the super
  1438. */
  1439. if (code != UNSET_HASH &&
  1440. !(s->s_flags & MS_RDONLY) &&
  1441. code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
  1442. set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
  1443. }
  1444. return code;
  1445. }
  1446. // return pointer to appropriate function
  1447. static hashf_t hash_function(struct super_block *s)
  1448. {
  1449. switch (what_hash(s)) {
  1450. case TEA_HASH:
  1451. reiserfs_info(s, "Using tea hash to sort names\n");
  1452. return keyed_hash;
  1453. case YURA_HASH:
  1454. reiserfs_info(s, "Using rupasov hash to sort names\n");
  1455. return yura_hash;
  1456. case R5_HASH:
  1457. reiserfs_info(s, "Using r5 hash to sort names\n");
  1458. return r5_hash;
  1459. }
  1460. return NULL;
  1461. }
  1462. // this is used to set up correct value for old partitions
  1463. static int function2code(hashf_t func)
  1464. {
  1465. if (func == keyed_hash)
  1466. return TEA_HASH;
  1467. if (func == yura_hash)
  1468. return YURA_HASH;
  1469. if (func == r5_hash)
  1470. return R5_HASH;
  1471. BUG(); // should never happen
  1472. return 0;
  1473. }
  1474. #define SWARN(silent, s, ...) \
  1475. if (!(silent)) \
  1476. reiserfs_warning (s, __VA_ARGS__)
  1477. static int reiserfs_fill_super(struct super_block *s, void *data, int silent)
  1478. {
  1479. struct inode *root_inode;
  1480. int j;
  1481. struct reiserfs_transaction_handle th;
  1482. int old_format = 0;
  1483. unsigned long blocks;
  1484. unsigned int commit_max_age = 0;
  1485. int jinit_done = 0;
  1486. struct reiserfs_iget_args args;
  1487. struct reiserfs_super_block *rs;
  1488. char *jdev_name;
  1489. struct reiserfs_sb_info *sbi;
  1490. int errval = -EINVAL;
  1491. sbi = kmalloc(sizeof(struct reiserfs_sb_info), GFP_KERNEL);
  1492. if (!sbi) {
  1493. errval = -ENOMEM;
  1494. goto error;
  1495. }
  1496. s->s_fs_info = sbi;
  1497. memset(sbi, 0, sizeof(struct reiserfs_sb_info));
  1498. /* Set default values for options: non-aggressive tails, RO on errors */
  1499. REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_SMALLTAIL);
  1500. REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_ERROR_RO);
  1501. /* no preallocation minimum, be smart in
  1502. reiserfs_file_write instead */
  1503. REISERFS_SB(s)->s_alloc_options.preallocmin = 0;
  1504. /* Preallocate by 16 blocks (17-1) at once */
  1505. REISERFS_SB(s)->s_alloc_options.preallocsize = 17;
  1506. /* Initialize the rwsem for xattr dir */
  1507. init_rwsem(&REISERFS_SB(s)->xattr_dir_sem);
  1508. /* setup default block allocator options */
  1509. reiserfs_init_alloc_options(s);
  1510. jdev_name = NULL;
  1511. if (reiserfs_parse_options
  1512. (s, (char *)data, &(sbi->s_mount_opt), &blocks, &jdev_name,
  1513. &commit_max_age) == 0) {
  1514. goto error;
  1515. }
  1516. if (blocks) {
  1517. SWARN(silent, s, "jmacd-7: reiserfs_fill_super: resize option "
  1518. "for remount only");
  1519. goto error;
  1520. }
  1521. /* try old format (undistributed bitmap, super block in 8-th 1k block of a device) */
  1522. if (!read_super_block(s, REISERFS_OLD_DISK_OFFSET_IN_BYTES))
  1523. old_format = 1;
  1524. /* try new format (64-th 1k block), which can contain reiserfs super block */
  1525. else if (read_super_block(s, REISERFS_DISK_OFFSET_IN_BYTES)) {
  1526. SWARN(silent, s,
  1527. "sh-2021: reiserfs_fill_super: can not find reiserfs on %s",
  1528. reiserfs_bdevname(s));
  1529. goto error;
  1530. }
  1531. rs = SB_DISK_SUPER_BLOCK(s);
  1532. /* Let's do basic sanity check to verify that underlying device is not
  1533. smaller than the filesystem. If the check fails then abort and scream,
  1534. because bad stuff will happen otherwise. */
  1535. if (s->s_bdev && s->s_bdev->bd_inode
  1536. && i_size_read(s->s_bdev->bd_inode) <
  1537. sb_block_count(rs) * sb_blocksize(rs)) {
  1538. SWARN(silent, s,
  1539. "Filesystem on %s cannot be mounted because it is bigger than the device",
  1540. reiserfs_bdevname(s));
  1541. SWARN(silent, s,
  1542. "You may need to run fsck or increase size of your LVM partition");
  1543. SWARN(silent, s,
  1544. "Or may be you forgot to reboot after fdisk when it told you to");
  1545. goto error;
  1546. }
  1547. sbi->s_mount_state = SB_REISERFS_STATE(s);
  1548. sbi->s_mount_state = REISERFS_VALID_FS;
  1549. if (old_format ? read_old_bitmaps(s) : read_bitmaps(s)) {
  1550. SWARN(silent, s,
  1551. "jmacd-8: reiserfs_fill_super: unable to read bitmap");
  1552. goto error;
  1553. }
  1554. #ifdef CONFIG_REISERFS_CHECK
  1555. SWARN(silent, s, "CONFIG_REISERFS_CHECK is set ON");
  1556. SWARN(silent, s, "- it is slow mode for debugging.");
  1557. #endif
  1558. /* make data=ordered the default */
  1559. if (!reiserfs_data_log(s) && !reiserfs_data_ordered(s) &&
  1560. !reiserfs_data_writeback(s)) {
  1561. REISERFS_SB(s)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
  1562. }
  1563. if (reiserfs_data_log(s)) {
  1564. reiserfs_info(s, "using journaled data mode\n");
  1565. } else if (reiserfs_data_ordered(s)) {
  1566. reiserfs_info(s, "using ordered data mode\n");
  1567. } else {
  1568. reiserfs_info(s, "using writeback data mode\n");
  1569. }
  1570. if (reiserfs_barrier_flush(s)) {
  1571. printk("reiserfs: using flush barriers\n");
  1572. }
  1573. // set_device_ro(s->s_dev, 1) ;
  1574. if (journal_init(s, jdev_name, old_format, commit_max_age)) {
  1575. SWARN(silent, s,
  1576. "sh-2022: reiserfs_fill_super: unable to initialize journal space");
  1577. goto error;
  1578. } else {
  1579. jinit_done = 1; /* once this is set, journal_release must be called
  1580. ** if we error out of the mount
  1581. */
  1582. }
  1583. if (reread_meta_blocks(s)) {
  1584. SWARN(silent, s,
  1585. "jmacd-9: reiserfs_fill_super: unable to reread meta blocks after journal init");
  1586. goto error;
  1587. }
  1588. if (replay_only(s))
  1589. goto error;
  1590. if (bdev_read_only(s->s_bdev) && !(s->s_flags & MS_RDONLY)) {
  1591. SWARN(silent, s,
  1592. "clm-7000: Detected readonly device, marking FS readonly");
  1593. s->s_flags |= MS_RDONLY;
  1594. }
  1595. args.objectid = REISERFS_ROOT_OBJECTID;
  1596. args.dirid = REISERFS_ROOT_PARENT_OBJECTID;
  1597. root_inode =
  1598. iget5_locked(s, REISERFS_ROOT_OBJECTID, reiserfs_find_actor,
  1599. reiserfs_init_locked_inode, (void *)(&args));
  1600. if (!root_inode) {
  1601. SWARN(silent, s,
  1602. "jmacd-10: reiserfs_fill_super: get root inode failed");
  1603. goto error;
  1604. }
  1605. if (root_inode->i_state & I_NEW) {
  1606. reiserfs_read_locked_inode(root_inode, &args);
  1607. unlock_new_inode(root_inode);
  1608. }
  1609. s->s_root = d_alloc_root(root_inode);
  1610. if (!s->s_root) {
  1611. iput(root_inode);
  1612. goto error;
  1613. }
  1614. // define and initialize hash function
  1615. sbi->s_hash_function = hash_function(s);
  1616. if (sbi->s_hash_function == NULL) {
  1617. dput(s->s_root);
  1618. s->s_root = NULL;
  1619. goto error;
  1620. }
  1621. if (is_reiserfs_3_5(rs)
  1622. || (is_reiserfs_jr(rs) && SB_VERSION(s) == REISERFS_VERSION_1))
  1623. set_bit(REISERFS_3_5, &(sbi->s_properties));
  1624. else
  1625. set_bit(REISERFS_3_6, &(sbi->s_properties));
  1626. if (!(s->s_flags & MS_RDONLY)) {
  1627. errval = journal_begin(&th, s, 1);
  1628. if (errval) {
  1629. dput(s->s_root);
  1630. s->s_root = NULL;
  1631. goto error;
  1632. }
  1633. reiserfs_prepare_for_journal(s, SB_BUFFER_WITH_SB(s), 1);
  1634. set_sb_umount_state(rs, REISERFS_ERROR_FS);
  1635. set_sb_fs_state(rs, 0);
  1636. if (old_format_only(s)) {
  1637. /* filesystem of format 3.5 either with standard or non-standard
  1638. journal */
  1639. if (convert_reiserfs(s)) {
  1640. /* and -o conv is given */
  1641. if (!silent)
  1642. reiserfs_info(s,
  1643. "converting 3.5 filesystem to the 3.6 format");
  1644. if (is_reiserfs_3_5(rs))
  1645. /* put magic string of 3.6 format. 2.2 will not be able to
  1646. mount this filesystem anymore */
  1647. memcpy(rs->s_v1.s_magic,
  1648. reiserfs_3_6_magic_string,
  1649. sizeof
  1650. (reiserfs_3_6_magic_string));
  1651. set_sb_version(rs, REISERFS_VERSION_2);
  1652. reiserfs_convert_objectid_map_v1(s);
  1653. set_bit(REISERFS_3_6, &(sbi->s_properties));
  1654. clear_bit(REISERFS_3_5, &(sbi->s_properties));
  1655. } else if (!silent) {
  1656. reiserfs_info(s, "using 3.5.x disk format\n");
  1657. }
  1658. }
  1659. journal_mark_dirty(&th, s, SB_BUFFER_WITH_SB(s));
  1660. errval = journal_end(&th, s, 1);
  1661. if (errval) {
  1662. dput(s->s_root);
  1663. s->s_root = NULL;
  1664. goto error;
  1665. }
  1666. if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
  1667. dput(s->s_root);
  1668. s->s_root = NULL;
  1669. goto error;
  1670. }
  1671. /* look for files which were to be removed in previous session */
  1672. finish_unfinished(s);
  1673. } else {
  1674. if (old_format_only(s) && !silent) {
  1675. reiserfs_info(s, "using 3.5.x disk format\n");
  1676. }
  1677. if ((errval = reiserfs_xattr_init(s, s->s_flags))) {
  1678. dput(s->s_root);
  1679. s->s_root = NULL;
  1680. goto error;
  1681. }
  1682. }
  1683. // mark hash in super block: it could be unset. overwrite should be ok
  1684. set_sb_hash_function_code(rs, function2code(sbi->s_hash_function));
  1685. handle_attrs(s);
  1686. reiserfs_proc_info_init(s);
  1687. init_waitqueue_head(&(sbi->s_wait));
  1688. spin_lock_init(&sbi->bitmap_lock);
  1689. return (0);
  1690. error:
  1691. if (jinit_done) { /* kill the commit thread, free journal ram */
  1692. journal_release_error(NULL, s);
  1693. }
  1694. if (SB_DISK_SUPER_BLOCK(s)) {
  1695. for (j = 0; j < SB_BMAP_NR(s); j++) {
  1696. if (SB_AP_BITMAP(s))
  1697. brelse(SB_AP_BITMAP(s)[j].bh);
  1698. }
  1699. vfree(SB_AP_BITMAP(s));
  1700. }
  1701. if (SB_BUFFER_WITH_SB(s))
  1702. brelse(SB_BUFFER_WITH_SB(s));
  1703. #ifdef CONFIG_QUOTA
  1704. for (j = 0; j < MAXQUOTAS; j++) {
  1705. kfree(sbi->s_qf_names[j]);
  1706. sbi->s_qf_names[j] = NULL;
  1707. }
  1708. #endif
  1709. kfree(sbi);
  1710. s->s_fs_info = NULL;
  1711. return errval;
  1712. }
  1713. static int reiserfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  1714. {
  1715. struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(dentry->d_sb);
  1716. buf->f_namelen = (REISERFS_MAX_NAME(s->s_blocksize));
  1717. buf->f_bfree = sb_free_blocks(rs);
  1718. buf->f_bavail = buf->f_bfree;
  1719. buf->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
  1720. buf->f_bsize = dentry->d_sb->s_blocksize;
  1721. /* changed to accommodate gcc folks. */
  1722. buf->f_type = REISERFS_SUPER_MAGIC;
  1723. return 0;
  1724. }
  1725. #ifdef CONFIG_QUOTA
  1726. static int reiserfs_dquot_initialize(struct inode *inode, int type)
  1727. {
  1728. struct reiserfs_transaction_handle th;
  1729. int ret, err;
  1730. /* We may create quota structure so we need to reserve enough blocks */
  1731. reiserfs_write_lock(inode->i_sb);
  1732. ret =
  1733. journal_begin(&th, inode->i_sb,
  1734. 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
  1735. if (ret)
  1736. goto out;
  1737. ret = dquot_initialize(inode, type);
  1738. err =
  1739. journal_end(&th, inode->i_sb,
  1740. 2 * REISERFS_QUOTA_INIT_BLOCKS(inode->i_sb));
  1741. if (!ret && err)
  1742. ret = err;
  1743. out:
  1744. reiserfs_write_unlock(inode->i_sb);
  1745. return ret;
  1746. }
  1747. static int reiserfs_dquot_drop(struct inode *inode)
  1748. {
  1749. struct reiserfs_transaction_handle th;
  1750. int ret, err;
  1751. /* We may delete quota structure so we need to reserve enough blocks */
  1752. reiserfs_write_lock(inode->i_sb);
  1753. ret =
  1754. journal_begin(&th, inode->i_sb,
  1755. 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
  1756. if (ret)
  1757. goto out;
  1758. ret = dquot_drop(inode);
  1759. err =
  1760. journal_end(&th, inode->i_sb,
  1761. 2 * REISERFS_QUOTA_DEL_BLOCKS(inode->i_sb));
  1762. if (!ret && err)
  1763. ret = err;
  1764. out:
  1765. reiserfs_write_unlock(inode->i_sb);
  1766. return ret;
  1767. }
  1768. static int reiserfs_write_dquot(struct dquot *dquot)
  1769. {
  1770. struct reiserfs_transaction_handle th;
  1771. int ret, err;
  1772. reiserfs_write_lock(dquot->dq_sb);
  1773. ret =
  1774. journal_begin(&th, dquot->dq_sb,
  1775. REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
  1776. if (ret)
  1777. goto out;
  1778. ret = dquot_commit(dquot);
  1779. err =
  1780. journal_end(&th, dquot->dq_sb,
  1781. REISERFS_QUOTA_TRANS_BLOCKS(dquot->dq_sb));
  1782. if (!ret && err)
  1783. ret = err;
  1784. out:
  1785. reiserfs_write_unlock(dquot->dq_sb);
  1786. return ret;
  1787. }
  1788. static int reiserfs_acquire_dquot(struct dquot *dquot)
  1789. {
  1790. struct reiserfs_transaction_handle th;
  1791. int ret, err;
  1792. reiserfs_write_lock(dquot->dq_sb);
  1793. ret =
  1794. journal_begin(&th, dquot->dq_sb,
  1795. REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
  1796. if (ret)
  1797. goto out;
  1798. ret = dquot_acquire(dquot);
  1799. err =
  1800. journal_end(&th, dquot->dq_sb,
  1801. REISERFS_QUOTA_INIT_BLOCKS(dquot->dq_sb));
  1802. if (!ret && err)
  1803. ret = err;
  1804. out:
  1805. reiserfs_write_unlock(dquot->dq_sb);
  1806. return ret;
  1807. }
  1808. static int reiserfs_release_dquot(struct dquot *dquot)
  1809. {
  1810. struct reiserfs_transaction_handle th;
  1811. int ret, err;
  1812. reiserfs_write_lock(dquot->dq_sb);
  1813. ret =
  1814. journal_begin(&th, dquot->dq_sb,
  1815. REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
  1816. if (ret)
  1817. goto out;
  1818. ret = dquot_release(dquot);
  1819. err =
  1820. journal_end(&th, dquot->dq_sb,
  1821. REISERFS_QUOTA_DEL_BLOCKS(dquot->dq_sb));
  1822. if (!ret && err)
  1823. ret = err;
  1824. out:
  1825. reiserfs_write_unlock(dquot->dq_sb);
  1826. return ret;
  1827. }
  1828. static int reiserfs_mark_dquot_dirty(struct dquot *dquot)
  1829. {
  1830. /* Are we journalling quotas? */
  1831. if (REISERFS_SB(dquot->dq_sb)->s_qf_names[USRQUOTA] ||
  1832. REISERFS_SB(dquot->dq_sb)->s_qf_names[GRPQUOTA]) {
  1833. dquot_mark_dquot_dirty(dquot);
  1834. return reiserfs_write_dquot(dquot);
  1835. } else
  1836. return dquot_mark_dquot_dirty(dquot);
  1837. }
  1838. static int reiserfs_write_info(struct super_block *sb, int type)
  1839. {
  1840. struct reiserfs_transaction_handle th;
  1841. int ret, err;
  1842. /* Data block + inode block */
  1843. reiserfs_write_lock(sb);
  1844. ret = journal_begin(&th, sb, 2);
  1845. if (ret)
  1846. goto out;
  1847. ret = dquot_commit_info(sb, type);
  1848. err = journal_end(&th, sb, 2);
  1849. if (!ret && err)
  1850. ret = err;
  1851. out:
  1852. reiserfs_write_unlock(sb);
  1853. return ret;
  1854. }
  1855. /*
  1856. * Turn on quotas during mount time - we need to find the quota file and such...
  1857. */
  1858. static int reiserfs_quota_on_mount(struct super_block *sb, int type)
  1859. {
  1860. return vfs_quota_on_mount(sb, REISERFS_SB(sb)->s_qf_names[type],
  1861. REISERFS_SB(sb)->s_jquota_fmt, type);
  1862. }
  1863. /*
  1864. * Standard function to be called on quota_on
  1865. */
  1866. static int reiserfs_quota_on(struct super_block *sb, int type, int format_id,
  1867. char *path)
  1868. {
  1869. int err;
  1870. struct nameidata nd;
  1871. if (!(REISERFS_SB(sb)->s_mount_opt & (1 << REISERFS_QUOTA)))
  1872. return -EINVAL;
  1873. err = path_lookup(path, LOOKUP_FOLLOW, &nd);
  1874. if (err)
  1875. return err;
  1876. /* Quotafile not on the same filesystem? */
  1877. if (nd.mnt->mnt_sb != sb) {
  1878. path_release(&nd);
  1879. return -EXDEV;
  1880. }
  1881. /* We must not pack tails for quota files on reiserfs for quota IO to work */
  1882. if (!REISERFS_I(nd.dentry->d_inode)->i_flags & i_nopack_mask) {
  1883. reiserfs_warning(sb,
  1884. "reiserfs: Quota file must have tail packing disabled.");
  1885. path_release(&nd);
  1886. return -EINVAL;
  1887. }
  1888. /* Not journalling quota? No more tests needed... */
  1889. if (!REISERFS_SB(sb)->s_qf_names[USRQUOTA] &&
  1890. !REISERFS_SB(sb)->s_qf_names[GRPQUOTA]) {
  1891. path_release(&nd);
  1892. return vfs_quota_on(sb, type, format_id, path);
  1893. }
  1894. /* Quotafile not of fs root? */
  1895. if (nd.dentry->d_parent->d_inode != sb->s_root->d_inode)
  1896. reiserfs_warning(sb,
  1897. "reiserfs: Quota file not on filesystem root. "
  1898. "Journalled quota will not work.");
  1899. path_release(&nd);
  1900. return vfs_quota_on(sb, type, format_id, path);
  1901. }
  1902. /* Read data from quotafile - avoid pagecache and such because we cannot afford
  1903. * acquiring the locks... As quota files are never truncated and quota code
  1904. * itself serializes the operations (and noone else should touch the files)
  1905. * we don't have to be afraid of races */
  1906. static ssize_t reiserfs_quota_read(struct super_block *sb, int type, char *data,
  1907. size_t len, loff_t off)
  1908. {
  1909. struct inode *inode = sb_dqopt(sb)->files[type];
  1910. unsigned long blk = off >> sb->s_blocksize_bits;
  1911. int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
  1912. size_t toread;
  1913. struct buffer_head tmp_bh, *bh;
  1914. loff_t i_size = i_size_read(inode);
  1915. if (off > i_size)
  1916. return 0;
  1917. if (off + len > i_size)
  1918. len = i_size - off;
  1919. toread = len;
  1920. while (toread > 0) {
  1921. tocopy =
  1922. sb->s_blocksize - offset <
  1923. toread ? sb->s_blocksize - offset : toread;
  1924. tmp_bh.b_state = 0;
  1925. /* Quota files are without tails so we can safely use this function */
  1926. reiserfs_write_lock(sb);
  1927. err = reiserfs_get_block(inode, blk, &tmp_bh, 0);
  1928. reiserfs_write_unlock(sb);
  1929. if (err)
  1930. return err;
  1931. if (!buffer_mapped(&tmp_bh)) /* A hole? */
  1932. memset(data, 0, tocopy);
  1933. else {
  1934. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1935. if (!bh)
  1936. return -EIO;
  1937. memcpy(data, bh->b_data + offset, tocopy);
  1938. brelse(bh);
  1939. }
  1940. offset = 0;
  1941. toread -= tocopy;
  1942. data += tocopy;
  1943. blk++;
  1944. }
  1945. return len;
  1946. }
  1947. /* Write to quotafile (we know the transaction is already started and has
  1948. * enough credits) */
  1949. static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
  1950. const char *data, size_t len, loff_t off)
  1951. {
  1952. struct inode *inode = sb_dqopt(sb)->files[type];
  1953. unsigned long blk = off >> sb->s_blocksize_bits;
  1954. int err = 0, offset = off & (sb->s_blocksize - 1), tocopy;
  1955. int journal_quota = REISERFS_SB(sb)->s_qf_names[type] != NULL;
  1956. size_t towrite = len;
  1957. struct buffer_head tmp_bh, *bh;
  1958. mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
  1959. while (towrite > 0) {
  1960. tocopy = sb->s_blocksize - offset < towrite ?
  1961. sb->s_blocksize - offset : towrite;
  1962. tmp_bh.b_state = 0;
  1963. err = reiserfs_get_block(inode, blk, &tmp_bh, GET_BLOCK_CREATE);
  1964. if (err)
  1965. goto out;
  1966. if (offset || tocopy != sb->s_blocksize)
  1967. bh = sb_bread(sb, tmp_bh.b_blocknr);
  1968. else
  1969. bh = sb_getblk(sb, tmp_bh.b_blocknr);
  1970. if (!bh) {
  1971. err = -EIO;
  1972. goto out;
  1973. }
  1974. lock_buffer(bh);
  1975. memcpy(bh->b_data + offset, data, tocopy);
  1976. flush_dcache_page(bh->b_page);
  1977. set_buffer_uptodate(bh);
  1978. unlock_buffer(bh);
  1979. reiserfs_prepare_for_journal(sb, bh, 1);
  1980. journal_mark_dirty(current->journal_info, sb, bh);
  1981. if (!journal_quota)
  1982. reiserfs_add_ordered_list(inode, bh);
  1983. brelse(bh);
  1984. offset = 0;
  1985. towrite -= tocopy;
  1986. data += tocopy;
  1987. blk++;
  1988. }
  1989. out:
  1990. if (len == towrite)
  1991. return err;
  1992. if (inode->i_size < off + len - towrite)
  1993. i_size_write(inode, off + len - towrite);
  1994. inode->i_version++;
  1995. inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  1996. mark_inode_dirty(inode);
  1997. mutex_unlock(&inode->i_mutex);
  1998. return len - towrite;
  1999. }
  2000. #endif
  2001. static int get_super_block(struct file_system_type *fs_type,
  2002. int flags, const char *dev_name,
  2003. void *data, struct vfsmount *mnt)
  2004. {
  2005. return get_sb_bdev(fs_type, flags, dev_name, data, reiserfs_fill_super,
  2006. mnt);
  2007. }
  2008. static int __init init_reiserfs_fs(void)
  2009. {
  2010. int ret;
  2011. if ((ret = init_inodecache())) {
  2012. return ret;
  2013. }
  2014. if ((ret = reiserfs_xattr_register_handlers()))
  2015. goto failed_reiserfs_xattr_register_handlers;
  2016. reiserfs_proc_info_global_init();
  2017. reiserfs_proc_register_global("version",
  2018. reiserfs_global_version_in_proc);
  2019. ret = register_filesystem(&reiserfs_fs_type);
  2020. if (ret == 0) {
  2021. return 0;
  2022. }
  2023. reiserfs_xattr_unregister_handlers();
  2024. failed_reiserfs_xattr_register_handlers:
  2025. reiserfs_proc_unregister_global("version");
  2026. reiserfs_proc_info_global_done();
  2027. destroy_inodecache();
  2028. return ret;
  2029. }
  2030. static void __exit exit_reiserfs_fs(void)
  2031. {
  2032. reiserfs_xattr_unregister_handlers();
  2033. reiserfs_proc_unregister_global("version");
  2034. reiserfs_proc_info_global_done();
  2035. unregister_filesystem(&reiserfs_fs_type);
  2036. destroy_inodecache();
  2037. }
  2038. struct file_system_type reiserfs_fs_type = {
  2039. .owner = THIS_MODULE,
  2040. .name = "reiserfs",
  2041. .get_sb = get_super_block,
  2042. .kill_sb = kill_block_super,
  2043. .fs_flags = FS_REQUIRES_DEV,
  2044. };
  2045. MODULE_DESCRIPTION("ReiserFS journaled filesystem");
  2046. MODULE_AUTHOR("Hans Reiser <reiser@namesys.com>");
  2047. MODULE_LICENSE("GPL");
  2048. module_init(init_reiserfs_fs);
  2049. module_exit(exit_reiserfs_fs);