inode.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*
  2. * linux/fs/minix/inode.c
  3. *
  4. * Copyright (C) 1991, 1992 Linus Torvalds
  5. *
  6. * Copyright (C) 1996 Gertjan van Wingerde
  7. * Minix V2 fs support.
  8. *
  9. * Modified for 680x0 by Andreas Schwab
  10. * Updated to filesystem version 3 by Daniel Aragones
  11. */
  12. #include <linux/module.h>
  13. #include "minix.h"
  14. #include <linux/buffer_head.h>
  15. #include <linux/slab.h>
  16. #include <linux/init.h>
  17. #include <linux/highuid.h>
  18. #include <linux/vfs.h>
  19. #include <linux/writeback.h>
  20. static int minix_write_inode(struct inode *inode,
  21. struct writeback_control *wbc);
  22. static int minix_statfs(struct dentry *dentry, struct kstatfs *buf);
  23. static int minix_remount (struct super_block * sb, int * flags, char * data);
  24. static void minix_evict_inode(struct inode *inode)
  25. {
  26. truncate_inode_pages_final(&inode->i_data);
  27. if (!inode->i_nlink) {
  28. inode->i_size = 0;
  29. minix_truncate(inode);
  30. }
  31. invalidate_inode_buffers(inode);
  32. clear_inode(inode);
  33. if (!inode->i_nlink)
  34. minix_free_inode(inode);
  35. }
  36. static void minix_put_super(struct super_block *sb)
  37. {
  38. int i;
  39. struct minix_sb_info *sbi = minix_sb(sb);
  40. if (!(sb->s_flags & MS_RDONLY)) {
  41. if (sbi->s_version != MINIX_V3) /* s_state is now out from V3 sb */
  42. sbi->s_ms->s_state = sbi->s_mount_state;
  43. mark_buffer_dirty(sbi->s_sbh);
  44. }
  45. for (i = 0; i < sbi->s_imap_blocks; i++)
  46. brelse(sbi->s_imap[i]);
  47. for (i = 0; i < sbi->s_zmap_blocks; i++)
  48. brelse(sbi->s_zmap[i]);
  49. brelse (sbi->s_sbh);
  50. kfree(sbi->s_imap);
  51. sb->s_fs_info = NULL;
  52. kfree(sbi);
  53. }
  54. static struct kmem_cache * minix_inode_cachep;
  55. static struct inode *minix_alloc_inode(struct super_block *sb)
  56. {
  57. struct minix_inode_info *ei;
  58. ei = kmem_cache_alloc(minix_inode_cachep, GFP_KERNEL);
  59. if (!ei)
  60. return NULL;
  61. return &ei->vfs_inode;
  62. }
  63. static void minix_i_callback(struct rcu_head *head)
  64. {
  65. struct inode *inode = container_of(head, struct inode, i_rcu);
  66. kmem_cache_free(minix_inode_cachep, minix_i(inode));
  67. }
  68. static void minix_destroy_inode(struct inode *inode)
  69. {
  70. call_rcu(&inode->i_rcu, minix_i_callback);
  71. }
  72. static void init_once(void *foo)
  73. {
  74. struct minix_inode_info *ei = (struct minix_inode_info *) foo;
  75. inode_init_once(&ei->vfs_inode);
  76. }
  77. static int __init init_inodecache(void)
  78. {
  79. minix_inode_cachep = kmem_cache_create("minix_inode_cache",
  80. sizeof(struct minix_inode_info),
  81. 0, (SLAB_RECLAIM_ACCOUNT|
  82. SLAB_MEM_SPREAD),
  83. init_once);
  84. if (minix_inode_cachep == NULL)
  85. return -ENOMEM;
  86. return 0;
  87. }
  88. static void destroy_inodecache(void)
  89. {
  90. /*
  91. * Make sure all delayed rcu free inodes are flushed before we
  92. * destroy cache.
  93. */
  94. rcu_barrier();
  95. kmem_cache_destroy(minix_inode_cachep);
  96. }
  97. static const struct super_operations minix_sops = {
  98. .alloc_inode = minix_alloc_inode,
  99. .destroy_inode = minix_destroy_inode,
  100. .write_inode = minix_write_inode,
  101. .evict_inode = minix_evict_inode,
  102. .put_super = minix_put_super,
  103. .statfs = minix_statfs,
  104. .remount_fs = minix_remount,
  105. };
  106. static int minix_remount (struct super_block * sb, int * flags, char * data)
  107. {
  108. struct minix_sb_info * sbi = minix_sb(sb);
  109. struct minix_super_block * ms;
  110. sync_filesystem(sb);
  111. ms = sbi->s_ms;
  112. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  113. return 0;
  114. if (*flags & MS_RDONLY) {
  115. if (ms->s_state & MINIX_VALID_FS ||
  116. !(sbi->s_mount_state & MINIX_VALID_FS))
  117. return 0;
  118. /* Mounting a rw partition read-only. */
  119. if (sbi->s_version != MINIX_V3)
  120. ms->s_state = sbi->s_mount_state;
  121. mark_buffer_dirty(sbi->s_sbh);
  122. } else {
  123. /* Mount a partition which is read-only, read-write. */
  124. if (sbi->s_version != MINIX_V3) {
  125. sbi->s_mount_state = ms->s_state;
  126. ms->s_state &= ~MINIX_VALID_FS;
  127. } else {
  128. sbi->s_mount_state = MINIX_VALID_FS;
  129. }
  130. mark_buffer_dirty(sbi->s_sbh);
  131. if (!(sbi->s_mount_state & MINIX_VALID_FS))
  132. printk("MINIX-fs warning: remounting unchecked fs, "
  133. "running fsck is recommended\n");
  134. else if ((sbi->s_mount_state & MINIX_ERROR_FS))
  135. printk("MINIX-fs warning: remounting fs with errors, "
  136. "running fsck is recommended\n");
  137. }
  138. return 0;
  139. }
  140. static int minix_fill_super(struct super_block *s, void *data, int silent)
  141. {
  142. struct buffer_head *bh;
  143. struct buffer_head **map;
  144. struct minix_super_block *ms;
  145. struct minix3_super_block *m3s = NULL;
  146. unsigned long i, block;
  147. struct inode *root_inode;
  148. struct minix_sb_info *sbi;
  149. int ret = -EINVAL;
  150. sbi = kzalloc(sizeof(struct minix_sb_info), GFP_KERNEL);
  151. if (!sbi)
  152. return -ENOMEM;
  153. s->s_fs_info = sbi;
  154. BUILD_BUG_ON(32 != sizeof (struct minix_inode));
  155. BUILD_BUG_ON(64 != sizeof(struct minix2_inode));
  156. if (!sb_set_blocksize(s, BLOCK_SIZE))
  157. goto out_bad_hblock;
  158. if (!(bh = sb_bread(s, 1)))
  159. goto out_bad_sb;
  160. ms = (struct minix_super_block *) bh->b_data;
  161. sbi->s_ms = ms;
  162. sbi->s_sbh = bh;
  163. sbi->s_mount_state = ms->s_state;
  164. sbi->s_ninodes = ms->s_ninodes;
  165. sbi->s_nzones = ms->s_nzones;
  166. sbi->s_imap_blocks = ms->s_imap_blocks;
  167. sbi->s_zmap_blocks = ms->s_zmap_blocks;
  168. sbi->s_firstdatazone = ms->s_firstdatazone;
  169. sbi->s_log_zone_size = ms->s_log_zone_size;
  170. sbi->s_max_size = ms->s_max_size;
  171. s->s_magic = ms->s_magic;
  172. if (s->s_magic == MINIX_SUPER_MAGIC) {
  173. sbi->s_version = MINIX_V1;
  174. sbi->s_dirsize = 16;
  175. sbi->s_namelen = 14;
  176. s->s_max_links = MINIX_LINK_MAX;
  177. } else if (s->s_magic == MINIX_SUPER_MAGIC2) {
  178. sbi->s_version = MINIX_V1;
  179. sbi->s_dirsize = 32;
  180. sbi->s_namelen = 30;
  181. s->s_max_links = MINIX_LINK_MAX;
  182. } else if (s->s_magic == MINIX2_SUPER_MAGIC) {
  183. sbi->s_version = MINIX_V2;
  184. sbi->s_nzones = ms->s_zones;
  185. sbi->s_dirsize = 16;
  186. sbi->s_namelen = 14;
  187. s->s_max_links = MINIX2_LINK_MAX;
  188. } else if (s->s_magic == MINIX2_SUPER_MAGIC2) {
  189. sbi->s_version = MINIX_V2;
  190. sbi->s_nzones = ms->s_zones;
  191. sbi->s_dirsize = 32;
  192. sbi->s_namelen = 30;
  193. s->s_max_links = MINIX2_LINK_MAX;
  194. } else if ( *(__u16 *)(bh->b_data + 24) == MINIX3_SUPER_MAGIC) {
  195. m3s = (struct minix3_super_block *) bh->b_data;
  196. s->s_magic = m3s->s_magic;
  197. sbi->s_imap_blocks = m3s->s_imap_blocks;
  198. sbi->s_zmap_blocks = m3s->s_zmap_blocks;
  199. sbi->s_firstdatazone = m3s->s_firstdatazone;
  200. sbi->s_log_zone_size = m3s->s_log_zone_size;
  201. sbi->s_max_size = m3s->s_max_size;
  202. sbi->s_ninodes = m3s->s_ninodes;
  203. sbi->s_nzones = m3s->s_zones;
  204. sbi->s_dirsize = 64;
  205. sbi->s_namelen = 60;
  206. sbi->s_version = MINIX_V3;
  207. sbi->s_mount_state = MINIX_VALID_FS;
  208. sb_set_blocksize(s, m3s->s_blocksize);
  209. s->s_max_links = MINIX2_LINK_MAX;
  210. } else
  211. goto out_no_fs;
  212. /*
  213. * Allocate the buffer map to keep the superblock small.
  214. */
  215. if (sbi->s_imap_blocks == 0 || sbi->s_zmap_blocks == 0)
  216. goto out_illegal_sb;
  217. i = (sbi->s_imap_blocks + sbi->s_zmap_blocks) * sizeof(bh);
  218. map = kzalloc(i, GFP_KERNEL);
  219. if (!map)
  220. goto out_no_map;
  221. sbi->s_imap = &map[0];
  222. sbi->s_zmap = &map[sbi->s_imap_blocks];
  223. block=2;
  224. for (i=0 ; i < sbi->s_imap_blocks ; i++) {
  225. if (!(sbi->s_imap[i]=sb_bread(s, block)))
  226. goto out_no_bitmap;
  227. block++;
  228. }
  229. for (i=0 ; i < sbi->s_zmap_blocks ; i++) {
  230. if (!(sbi->s_zmap[i]=sb_bread(s, block)))
  231. goto out_no_bitmap;
  232. block++;
  233. }
  234. minix_set_bit(0,sbi->s_imap[0]->b_data);
  235. minix_set_bit(0,sbi->s_zmap[0]->b_data);
  236. /* Apparently minix can create filesystems that allocate more blocks for
  237. * the bitmaps than needed. We simply ignore that, but verify it didn't
  238. * create one with not enough blocks and bail out if so.
  239. */
  240. block = minix_blocks_needed(sbi->s_ninodes, s->s_blocksize);
  241. if (sbi->s_imap_blocks < block) {
  242. printk("MINIX-fs: file system does not have enough "
  243. "imap blocks allocated. Refusing to mount.\n");
  244. goto out_no_bitmap;
  245. }
  246. block = minix_blocks_needed(
  247. (sbi->s_nzones - sbi->s_firstdatazone + 1),
  248. s->s_blocksize);
  249. if (sbi->s_zmap_blocks < block) {
  250. printk("MINIX-fs: file system does not have enough "
  251. "zmap blocks allocated. Refusing to mount.\n");
  252. goto out_no_bitmap;
  253. }
  254. /* set up enough so that it can read an inode */
  255. s->s_op = &minix_sops;
  256. root_inode = minix_iget(s, MINIX_ROOT_INO);
  257. if (IS_ERR(root_inode)) {
  258. ret = PTR_ERR(root_inode);
  259. goto out_no_root;
  260. }
  261. ret = -ENOMEM;
  262. s->s_root = d_make_root(root_inode);
  263. if (!s->s_root)
  264. goto out_no_root;
  265. if (!(s->s_flags & MS_RDONLY)) {
  266. if (sbi->s_version != MINIX_V3) /* s_state is now out from V3 sb */
  267. ms->s_state &= ~MINIX_VALID_FS;
  268. mark_buffer_dirty(bh);
  269. }
  270. if (!(sbi->s_mount_state & MINIX_VALID_FS))
  271. printk("MINIX-fs: mounting unchecked file system, "
  272. "running fsck is recommended\n");
  273. else if (sbi->s_mount_state & MINIX_ERROR_FS)
  274. printk("MINIX-fs: mounting file system with errors, "
  275. "running fsck is recommended\n");
  276. return 0;
  277. out_no_root:
  278. if (!silent)
  279. printk("MINIX-fs: get root inode failed\n");
  280. goto out_freemap;
  281. out_no_bitmap:
  282. printk("MINIX-fs: bad superblock or unable to read bitmaps\n");
  283. out_freemap:
  284. for (i = 0; i < sbi->s_imap_blocks; i++)
  285. brelse(sbi->s_imap[i]);
  286. for (i = 0; i < sbi->s_zmap_blocks; i++)
  287. brelse(sbi->s_zmap[i]);
  288. kfree(sbi->s_imap);
  289. goto out_release;
  290. out_no_map:
  291. ret = -ENOMEM;
  292. if (!silent)
  293. printk("MINIX-fs: can't allocate map\n");
  294. goto out_release;
  295. out_illegal_sb:
  296. if (!silent)
  297. printk("MINIX-fs: bad superblock\n");
  298. goto out_release;
  299. out_no_fs:
  300. if (!silent)
  301. printk("VFS: Can't find a Minix filesystem V1 | V2 | V3 "
  302. "on device %s.\n", s->s_id);
  303. out_release:
  304. brelse(bh);
  305. goto out;
  306. out_bad_hblock:
  307. printk("MINIX-fs: blocksize too small for device\n");
  308. goto out;
  309. out_bad_sb:
  310. printk("MINIX-fs: unable to read superblock\n");
  311. out:
  312. s->s_fs_info = NULL;
  313. kfree(sbi);
  314. return ret;
  315. }
  316. static int minix_statfs(struct dentry *dentry, struct kstatfs *buf)
  317. {
  318. struct super_block *sb = dentry->d_sb;
  319. struct minix_sb_info *sbi = minix_sb(sb);
  320. u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
  321. buf->f_type = sb->s_magic;
  322. buf->f_bsize = sb->s_blocksize;
  323. buf->f_blocks = (sbi->s_nzones - sbi->s_firstdatazone) << sbi->s_log_zone_size;
  324. buf->f_bfree = minix_count_free_blocks(sb);
  325. buf->f_bavail = buf->f_bfree;
  326. buf->f_files = sbi->s_ninodes;
  327. buf->f_ffree = minix_count_free_inodes(sb);
  328. buf->f_namelen = sbi->s_namelen;
  329. buf->f_fsid.val[0] = (u32)id;
  330. buf->f_fsid.val[1] = (u32)(id >> 32);
  331. return 0;
  332. }
  333. static int minix_get_block(struct inode *inode, sector_t block,
  334. struct buffer_head *bh_result, int create)
  335. {
  336. if (INODE_VERSION(inode) == MINIX_V1)
  337. return V1_minix_get_block(inode, block, bh_result, create);
  338. else
  339. return V2_minix_get_block(inode, block, bh_result, create);
  340. }
  341. static int minix_writepage(struct page *page, struct writeback_control *wbc)
  342. {
  343. return block_write_full_page(page, minix_get_block, wbc);
  344. }
  345. static int minix_readpage(struct file *file, struct page *page)
  346. {
  347. return block_read_full_page(page,minix_get_block);
  348. }
  349. int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len)
  350. {
  351. return __block_write_begin(page, pos, len, minix_get_block);
  352. }
  353. static void minix_write_failed(struct address_space *mapping, loff_t to)
  354. {
  355. struct inode *inode = mapping->host;
  356. if (to > inode->i_size) {
  357. truncate_pagecache(inode, inode->i_size);
  358. minix_truncate(inode);
  359. }
  360. }
  361. static int minix_write_begin(struct file *file, struct address_space *mapping,
  362. loff_t pos, unsigned len, unsigned flags,
  363. struct page **pagep, void **fsdata)
  364. {
  365. int ret;
  366. ret = block_write_begin(mapping, pos, len, flags, pagep,
  367. minix_get_block);
  368. if (unlikely(ret))
  369. minix_write_failed(mapping, pos + len);
  370. return ret;
  371. }
  372. static sector_t minix_bmap(struct address_space *mapping, sector_t block)
  373. {
  374. return generic_block_bmap(mapping,block,minix_get_block);
  375. }
  376. static const struct address_space_operations minix_aops = {
  377. .readpage = minix_readpage,
  378. .writepage = minix_writepage,
  379. .write_begin = minix_write_begin,
  380. .write_end = generic_write_end,
  381. .bmap = minix_bmap
  382. };
  383. static const struct inode_operations minix_symlink_inode_operations = {
  384. .readlink = generic_readlink,
  385. .follow_link = page_follow_link_light,
  386. .put_link = page_put_link,
  387. .getattr = minix_getattr,
  388. };
  389. void minix_set_inode(struct inode *inode, dev_t rdev)
  390. {
  391. if (S_ISREG(inode->i_mode)) {
  392. inode->i_op = &minix_file_inode_operations;
  393. inode->i_fop = &minix_file_operations;
  394. inode->i_mapping->a_ops = &minix_aops;
  395. } else if (S_ISDIR(inode->i_mode)) {
  396. inode->i_op = &minix_dir_inode_operations;
  397. inode->i_fop = &minix_dir_operations;
  398. inode->i_mapping->a_ops = &minix_aops;
  399. } else if (S_ISLNK(inode->i_mode)) {
  400. inode->i_op = &minix_symlink_inode_operations;
  401. inode->i_mapping->a_ops = &minix_aops;
  402. } else
  403. init_special_inode(inode, inode->i_mode, rdev);
  404. }
  405. /*
  406. * The minix V1 function to read an inode.
  407. */
  408. static struct inode *V1_minix_iget(struct inode *inode)
  409. {
  410. struct buffer_head * bh;
  411. struct minix_inode * raw_inode;
  412. struct minix_inode_info *minix_inode = minix_i(inode);
  413. int i;
  414. raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
  415. if (!raw_inode) {
  416. iget_failed(inode);
  417. return ERR_PTR(-EIO);
  418. }
  419. inode->i_mode = raw_inode->i_mode;
  420. i_uid_write(inode, raw_inode->i_uid);
  421. i_gid_write(inode, raw_inode->i_gid);
  422. set_nlink(inode, raw_inode->i_nlinks);
  423. inode->i_size = raw_inode->i_size;
  424. inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec = raw_inode->i_time;
  425. inode->i_mtime.tv_nsec = 0;
  426. inode->i_atime.tv_nsec = 0;
  427. inode->i_ctime.tv_nsec = 0;
  428. inode->i_blocks = 0;
  429. for (i = 0; i < 9; i++)
  430. minix_inode->u.i1_data[i] = raw_inode->i_zone[i];
  431. minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0]));
  432. brelse(bh);
  433. unlock_new_inode(inode);
  434. return inode;
  435. }
  436. /*
  437. * The minix V2 function to read an inode.
  438. */
  439. static struct inode *V2_minix_iget(struct inode *inode)
  440. {
  441. struct buffer_head * bh;
  442. struct minix2_inode * raw_inode;
  443. struct minix_inode_info *minix_inode = minix_i(inode);
  444. int i;
  445. raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
  446. if (!raw_inode) {
  447. iget_failed(inode);
  448. return ERR_PTR(-EIO);
  449. }
  450. inode->i_mode = raw_inode->i_mode;
  451. i_uid_write(inode, raw_inode->i_uid);
  452. i_gid_write(inode, raw_inode->i_gid);
  453. set_nlink(inode, raw_inode->i_nlinks);
  454. inode->i_size = raw_inode->i_size;
  455. inode->i_mtime.tv_sec = raw_inode->i_mtime;
  456. inode->i_atime.tv_sec = raw_inode->i_atime;
  457. inode->i_ctime.tv_sec = raw_inode->i_ctime;
  458. inode->i_mtime.tv_nsec = 0;
  459. inode->i_atime.tv_nsec = 0;
  460. inode->i_ctime.tv_nsec = 0;
  461. inode->i_blocks = 0;
  462. for (i = 0; i < 10; i++)
  463. minix_inode->u.i2_data[i] = raw_inode->i_zone[i];
  464. minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0]));
  465. brelse(bh);
  466. unlock_new_inode(inode);
  467. return inode;
  468. }
  469. /*
  470. * The global function to read an inode.
  471. */
  472. struct inode *minix_iget(struct super_block *sb, unsigned long ino)
  473. {
  474. struct inode *inode;
  475. inode = iget_locked(sb, ino);
  476. if (!inode)
  477. return ERR_PTR(-ENOMEM);
  478. if (!(inode->i_state & I_NEW))
  479. return inode;
  480. if (INODE_VERSION(inode) == MINIX_V1)
  481. return V1_minix_iget(inode);
  482. else
  483. return V2_minix_iget(inode);
  484. }
  485. /*
  486. * The minix V1 function to synchronize an inode.
  487. */
  488. static struct buffer_head * V1_minix_update_inode(struct inode * inode)
  489. {
  490. struct buffer_head * bh;
  491. struct minix_inode * raw_inode;
  492. struct minix_inode_info *minix_inode = minix_i(inode);
  493. int i;
  494. raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
  495. if (!raw_inode)
  496. return NULL;
  497. raw_inode->i_mode = inode->i_mode;
  498. raw_inode->i_uid = fs_high2lowuid(i_uid_read(inode));
  499. raw_inode->i_gid = fs_high2lowgid(i_gid_read(inode));
  500. raw_inode->i_nlinks = inode->i_nlink;
  501. raw_inode->i_size = inode->i_size;
  502. raw_inode->i_time = inode->i_mtime.tv_sec;
  503. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
  504. raw_inode->i_zone[0] = old_encode_dev(inode->i_rdev);
  505. else for (i = 0; i < 9; i++)
  506. raw_inode->i_zone[i] = minix_inode->u.i1_data[i];
  507. mark_buffer_dirty(bh);
  508. return bh;
  509. }
  510. /*
  511. * The minix V2 function to synchronize an inode.
  512. */
  513. static struct buffer_head * V2_minix_update_inode(struct inode * inode)
  514. {
  515. struct buffer_head * bh;
  516. struct minix2_inode * raw_inode;
  517. struct minix_inode_info *minix_inode = minix_i(inode);
  518. int i;
  519. raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
  520. if (!raw_inode)
  521. return NULL;
  522. raw_inode->i_mode = inode->i_mode;
  523. raw_inode->i_uid = fs_high2lowuid(i_uid_read(inode));
  524. raw_inode->i_gid = fs_high2lowgid(i_gid_read(inode));
  525. raw_inode->i_nlinks = inode->i_nlink;
  526. raw_inode->i_size = inode->i_size;
  527. raw_inode->i_mtime = inode->i_mtime.tv_sec;
  528. raw_inode->i_atime = inode->i_atime.tv_sec;
  529. raw_inode->i_ctime = inode->i_ctime.tv_sec;
  530. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
  531. raw_inode->i_zone[0] = old_encode_dev(inode->i_rdev);
  532. else for (i = 0; i < 10; i++)
  533. raw_inode->i_zone[i] = minix_inode->u.i2_data[i];
  534. mark_buffer_dirty(bh);
  535. return bh;
  536. }
  537. static int minix_write_inode(struct inode *inode, struct writeback_control *wbc)
  538. {
  539. int err = 0;
  540. struct buffer_head *bh;
  541. if (INODE_VERSION(inode) == MINIX_V1)
  542. bh = V1_minix_update_inode(inode);
  543. else
  544. bh = V2_minix_update_inode(inode);
  545. if (!bh)
  546. return -EIO;
  547. if (wbc->sync_mode == WB_SYNC_ALL && buffer_dirty(bh)) {
  548. sync_dirty_buffer(bh);
  549. if (buffer_req(bh) && !buffer_uptodate(bh)) {
  550. printk("IO error syncing minix inode [%s:%08lx]\n",
  551. inode->i_sb->s_id, inode->i_ino);
  552. err = -EIO;
  553. }
  554. }
  555. brelse (bh);
  556. return err;
  557. }
  558. int minix_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
  559. {
  560. struct super_block *sb = dentry->d_sb;
  561. generic_fillattr(d_inode(dentry), stat);
  562. if (INODE_VERSION(d_inode(dentry)) == MINIX_V1)
  563. stat->blocks = (BLOCK_SIZE / 512) * V1_minix_blocks(stat->size, sb);
  564. else
  565. stat->blocks = (sb->s_blocksize / 512) * V2_minix_blocks(stat->size, sb);
  566. stat->blksize = sb->s_blocksize;
  567. return 0;
  568. }
  569. /*
  570. * The function that is called for file truncation.
  571. */
  572. void minix_truncate(struct inode * inode)
  573. {
  574. if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)))
  575. return;
  576. if (INODE_VERSION(inode) == MINIX_V1)
  577. V1_minix_truncate(inode);
  578. else
  579. V2_minix_truncate(inode);
  580. }
  581. static struct dentry *minix_mount(struct file_system_type *fs_type,
  582. int flags, const char *dev_name, void *data)
  583. {
  584. return mount_bdev(fs_type, flags, dev_name, data, minix_fill_super);
  585. }
  586. static struct file_system_type minix_fs_type = {
  587. .owner = THIS_MODULE,
  588. .name = "minix",
  589. .mount = minix_mount,
  590. .kill_sb = kill_block_super,
  591. .fs_flags = FS_REQUIRES_DEV,
  592. };
  593. MODULE_ALIAS_FS("minix");
  594. static int __init init_minix_fs(void)
  595. {
  596. int err = init_inodecache();
  597. if (err)
  598. goto out1;
  599. err = register_filesystem(&minix_fs_type);
  600. if (err)
  601. goto out;
  602. return 0;
  603. out:
  604. destroy_inodecache();
  605. out1:
  606. return err;
  607. }
  608. static void __exit exit_minix_fs(void)
  609. {
  610. unregister_filesystem(&minix_fs_type);
  611. destroy_inodecache();
  612. }
  613. module_init(init_minix_fs)
  614. module_exit(exit_minix_fs)
  615. MODULE_LICENSE("GPL");