inode.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  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_rdonly(sb)) {
  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|SLAB_ACCOUNT),
  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 ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
  113. return 0;
  114. if (*flags & SB_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 (!sb_rdonly(s)) {
  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. .get_link = page_get_link,
  385. .getattr = minix_getattr,
  386. };
  387. void minix_set_inode(struct inode *inode, dev_t rdev)
  388. {
  389. if (S_ISREG(inode->i_mode)) {
  390. inode->i_op = &minix_file_inode_operations;
  391. inode->i_fop = &minix_file_operations;
  392. inode->i_mapping->a_ops = &minix_aops;
  393. } else if (S_ISDIR(inode->i_mode)) {
  394. inode->i_op = &minix_dir_inode_operations;
  395. inode->i_fop = &minix_dir_operations;
  396. inode->i_mapping->a_ops = &minix_aops;
  397. } else if (S_ISLNK(inode->i_mode)) {
  398. inode->i_op = &minix_symlink_inode_operations;
  399. inode_nohighmem(inode);
  400. inode->i_mapping->a_ops = &minix_aops;
  401. } else
  402. init_special_inode(inode, inode->i_mode, rdev);
  403. }
  404. /*
  405. * The minix V1 function to read an inode.
  406. */
  407. static struct inode *V1_minix_iget(struct inode *inode)
  408. {
  409. struct buffer_head * bh;
  410. struct minix_inode * raw_inode;
  411. struct minix_inode_info *minix_inode = minix_i(inode);
  412. int i;
  413. raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
  414. if (!raw_inode) {
  415. iget_failed(inode);
  416. return ERR_PTR(-EIO);
  417. }
  418. inode->i_mode = raw_inode->i_mode;
  419. i_uid_write(inode, raw_inode->i_uid);
  420. i_gid_write(inode, raw_inode->i_gid);
  421. set_nlink(inode, raw_inode->i_nlinks);
  422. inode->i_size = raw_inode->i_size;
  423. inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec = raw_inode->i_time;
  424. inode->i_mtime.tv_nsec = 0;
  425. inode->i_atime.tv_nsec = 0;
  426. inode->i_ctime.tv_nsec = 0;
  427. inode->i_blocks = 0;
  428. for (i = 0; i < 9; i++)
  429. minix_inode->u.i1_data[i] = raw_inode->i_zone[i];
  430. minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0]));
  431. brelse(bh);
  432. unlock_new_inode(inode);
  433. return inode;
  434. }
  435. /*
  436. * The minix V2 function to read an inode.
  437. */
  438. static struct inode *V2_minix_iget(struct inode *inode)
  439. {
  440. struct buffer_head * bh;
  441. struct minix2_inode * raw_inode;
  442. struct minix_inode_info *minix_inode = minix_i(inode);
  443. int i;
  444. raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
  445. if (!raw_inode) {
  446. iget_failed(inode);
  447. return ERR_PTR(-EIO);
  448. }
  449. inode->i_mode = raw_inode->i_mode;
  450. i_uid_write(inode, raw_inode->i_uid);
  451. i_gid_write(inode, raw_inode->i_gid);
  452. set_nlink(inode, raw_inode->i_nlinks);
  453. inode->i_size = raw_inode->i_size;
  454. inode->i_mtime.tv_sec = raw_inode->i_mtime;
  455. inode->i_atime.tv_sec = raw_inode->i_atime;
  456. inode->i_ctime.tv_sec = raw_inode->i_ctime;
  457. inode->i_mtime.tv_nsec = 0;
  458. inode->i_atime.tv_nsec = 0;
  459. inode->i_ctime.tv_nsec = 0;
  460. inode->i_blocks = 0;
  461. for (i = 0; i < 10; i++)
  462. minix_inode->u.i2_data[i] = raw_inode->i_zone[i];
  463. minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0]));
  464. brelse(bh);
  465. unlock_new_inode(inode);
  466. return inode;
  467. }
  468. /*
  469. * The global function to read an inode.
  470. */
  471. struct inode *minix_iget(struct super_block *sb, unsigned long ino)
  472. {
  473. struct inode *inode;
  474. inode = iget_locked(sb, ino);
  475. if (!inode)
  476. return ERR_PTR(-ENOMEM);
  477. if (!(inode->i_state & I_NEW))
  478. return inode;
  479. if (INODE_VERSION(inode) == MINIX_V1)
  480. return V1_minix_iget(inode);
  481. else
  482. return V2_minix_iget(inode);
  483. }
  484. /*
  485. * The minix V1 function to synchronize an inode.
  486. */
  487. static struct buffer_head * V1_minix_update_inode(struct inode * inode)
  488. {
  489. struct buffer_head * bh;
  490. struct minix_inode * raw_inode;
  491. struct minix_inode_info *minix_inode = minix_i(inode);
  492. int i;
  493. raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
  494. if (!raw_inode)
  495. return NULL;
  496. raw_inode->i_mode = inode->i_mode;
  497. raw_inode->i_uid = fs_high2lowuid(i_uid_read(inode));
  498. raw_inode->i_gid = fs_high2lowgid(i_gid_read(inode));
  499. raw_inode->i_nlinks = inode->i_nlink;
  500. raw_inode->i_size = inode->i_size;
  501. raw_inode->i_time = inode->i_mtime.tv_sec;
  502. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
  503. raw_inode->i_zone[0] = old_encode_dev(inode->i_rdev);
  504. else for (i = 0; i < 9; i++)
  505. raw_inode->i_zone[i] = minix_inode->u.i1_data[i];
  506. mark_buffer_dirty(bh);
  507. return bh;
  508. }
  509. /*
  510. * The minix V2 function to synchronize an inode.
  511. */
  512. static struct buffer_head * V2_minix_update_inode(struct inode * inode)
  513. {
  514. struct buffer_head * bh;
  515. struct minix2_inode * raw_inode;
  516. struct minix_inode_info *minix_inode = minix_i(inode);
  517. int i;
  518. raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
  519. if (!raw_inode)
  520. return NULL;
  521. raw_inode->i_mode = inode->i_mode;
  522. raw_inode->i_uid = fs_high2lowuid(i_uid_read(inode));
  523. raw_inode->i_gid = fs_high2lowgid(i_gid_read(inode));
  524. raw_inode->i_nlinks = inode->i_nlink;
  525. raw_inode->i_size = inode->i_size;
  526. raw_inode->i_mtime = inode->i_mtime.tv_sec;
  527. raw_inode->i_atime = inode->i_atime.tv_sec;
  528. raw_inode->i_ctime = inode->i_ctime.tv_sec;
  529. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
  530. raw_inode->i_zone[0] = old_encode_dev(inode->i_rdev);
  531. else for (i = 0; i < 10; i++)
  532. raw_inode->i_zone[i] = minix_inode->u.i2_data[i];
  533. mark_buffer_dirty(bh);
  534. return bh;
  535. }
  536. static int minix_write_inode(struct inode *inode, struct writeback_control *wbc)
  537. {
  538. int err = 0;
  539. struct buffer_head *bh;
  540. if (INODE_VERSION(inode) == MINIX_V1)
  541. bh = V1_minix_update_inode(inode);
  542. else
  543. bh = V2_minix_update_inode(inode);
  544. if (!bh)
  545. return -EIO;
  546. if (wbc->sync_mode == WB_SYNC_ALL && buffer_dirty(bh)) {
  547. sync_dirty_buffer(bh);
  548. if (buffer_req(bh) && !buffer_uptodate(bh)) {
  549. printk("IO error syncing minix inode [%s:%08lx]\n",
  550. inode->i_sb->s_id, inode->i_ino);
  551. err = -EIO;
  552. }
  553. }
  554. brelse (bh);
  555. return err;
  556. }
  557. int minix_getattr(const struct path *path, struct kstat *stat,
  558. u32 request_mask, unsigned int flags)
  559. {
  560. struct super_block *sb = path->dentry->d_sb;
  561. struct inode *inode = d_inode(path->dentry);
  562. generic_fillattr(inode, stat);
  563. if (INODE_VERSION(inode) == MINIX_V1)
  564. stat->blocks = (BLOCK_SIZE / 512) * V1_minix_blocks(stat->size, sb);
  565. else
  566. stat->blocks = (sb->s_blocksize / 512) * V2_minix_blocks(stat->size, sb);
  567. stat->blksize = sb->s_blocksize;
  568. return 0;
  569. }
  570. /*
  571. * The function that is called for file truncation.
  572. */
  573. void minix_truncate(struct inode * inode)
  574. {
  575. if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)))
  576. return;
  577. if (INODE_VERSION(inode) == MINIX_V1)
  578. V1_minix_truncate(inode);
  579. else
  580. V2_minix_truncate(inode);
  581. }
  582. static struct dentry *minix_mount(struct file_system_type *fs_type,
  583. int flags, const char *dev_name, void *data)
  584. {
  585. return mount_bdev(fs_type, flags, dev_name, data, minix_fill_super);
  586. }
  587. static struct file_system_type minix_fs_type = {
  588. .owner = THIS_MODULE,
  589. .name = "minix",
  590. .mount = minix_mount,
  591. .kill_sb = kill_block_super,
  592. .fs_flags = FS_REQUIRES_DEV,
  593. };
  594. MODULE_ALIAS_FS("minix");
  595. static int __init init_minix_fs(void)
  596. {
  597. int err = init_inodecache();
  598. if (err)
  599. goto out1;
  600. err = register_filesystem(&minix_fs_type);
  601. if (err)
  602. goto out;
  603. return 0;
  604. out:
  605. destroy_inodecache();
  606. out1:
  607. return err;
  608. }
  609. static void __exit exit_minix_fs(void)
  610. {
  611. unregister_filesystem(&minix_fs_type);
  612. destroy_inodecache();
  613. }
  614. module_init(init_minix_fs)
  615. module_exit(exit_minix_fs)
  616. MODULE_LICENSE("GPL");