super.c 65 KB

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