xfs_iops.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. /*
  2. * Copyright (c) 2000-2005 Silicon Graphics, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it would be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write the Free Software Foundation,
  16. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "xfs.h"
  19. #include "xfs_fs.h"
  20. #include "xfs_acl.h"
  21. #include "xfs_bit.h"
  22. #include "xfs_log.h"
  23. #include "xfs_inum.h"
  24. #include "xfs_trans.h"
  25. #include "xfs_sb.h"
  26. #include "xfs_ag.h"
  27. #include "xfs_alloc.h"
  28. #include "xfs_quota.h"
  29. #include "xfs_mount.h"
  30. #include "xfs_bmap_btree.h"
  31. #include "xfs_dinode.h"
  32. #include "xfs_inode.h"
  33. #include "xfs_bmap.h"
  34. #include "xfs_rtalloc.h"
  35. #include "xfs_error.h"
  36. #include "xfs_itable.h"
  37. #include "xfs_rw.h"
  38. #include "xfs_attr.h"
  39. #include "xfs_buf_item.h"
  40. #include "xfs_utils.h"
  41. #include "xfs_vnodeops.h"
  42. #include "xfs_trace.h"
  43. #include <linux/capability.h>
  44. #include <linux/xattr.h>
  45. #include <linux/namei.h>
  46. #include <linux/posix_acl.h>
  47. #include <linux/security.h>
  48. #include <linux/fiemap.h>
  49. #include <linux/slab.h>
  50. /*
  51. * Bring the timestamps in the XFS inode uptodate.
  52. *
  53. * Used before writing the inode to disk.
  54. */
  55. void
  56. xfs_synchronize_times(
  57. xfs_inode_t *ip)
  58. {
  59. struct inode *inode = VFS_I(ip);
  60. ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec;
  61. ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec;
  62. ip->i_d.di_ctime.t_sec = (__int32_t)inode->i_ctime.tv_sec;
  63. ip->i_d.di_ctime.t_nsec = (__int32_t)inode->i_ctime.tv_nsec;
  64. ip->i_d.di_mtime.t_sec = (__int32_t)inode->i_mtime.tv_sec;
  65. ip->i_d.di_mtime.t_nsec = (__int32_t)inode->i_mtime.tv_nsec;
  66. }
  67. /*
  68. * If the linux inode is valid, mark it dirty.
  69. * Used when commiting a dirty inode into a transaction so that
  70. * the inode will get written back by the linux code
  71. */
  72. void
  73. xfs_mark_inode_dirty_sync(
  74. xfs_inode_t *ip)
  75. {
  76. struct inode *inode = VFS_I(ip);
  77. if (!(inode->i_state & (I_WILL_FREE|I_FREEING)))
  78. mark_inode_dirty_sync(inode);
  79. }
  80. void
  81. xfs_mark_inode_dirty(
  82. xfs_inode_t *ip)
  83. {
  84. struct inode *inode = VFS_I(ip);
  85. if (!(inode->i_state & (I_WILL_FREE|I_FREEING)))
  86. mark_inode_dirty(inode);
  87. }
  88. /*
  89. * Hook in SELinux. This is not quite correct yet, what we really need
  90. * here (as we do for default ACLs) is a mechanism by which creation of
  91. * these attrs can be journalled at inode creation time (along with the
  92. * inode, of course, such that log replay can't cause these to be lost).
  93. */
  94. STATIC int
  95. xfs_init_security(
  96. struct inode *inode,
  97. struct inode *dir,
  98. const struct qstr *qstr)
  99. {
  100. struct xfs_inode *ip = XFS_I(inode);
  101. size_t length;
  102. void *value;
  103. unsigned char *name;
  104. int error;
  105. error = security_inode_init_security(inode, dir, qstr, (char **)&name,
  106. &value, &length);
  107. if (error) {
  108. if (error == -EOPNOTSUPP)
  109. return 0;
  110. return -error;
  111. }
  112. error = xfs_attr_set(ip, name, value, length, ATTR_SECURE);
  113. kfree(name);
  114. kfree(value);
  115. return error;
  116. }
  117. static void
  118. xfs_dentry_to_name(
  119. struct xfs_name *namep,
  120. struct dentry *dentry)
  121. {
  122. namep->name = dentry->d_name.name;
  123. namep->len = dentry->d_name.len;
  124. }
  125. STATIC void
  126. xfs_cleanup_inode(
  127. struct inode *dir,
  128. struct inode *inode,
  129. struct dentry *dentry)
  130. {
  131. struct xfs_name teardown;
  132. /* Oh, the horror.
  133. * If we can't add the ACL or we fail in
  134. * xfs_init_security we must back out.
  135. * ENOSPC can hit here, among other things.
  136. */
  137. xfs_dentry_to_name(&teardown, dentry);
  138. xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
  139. iput(inode);
  140. }
  141. STATIC int
  142. xfs_vn_mknod(
  143. struct inode *dir,
  144. struct dentry *dentry,
  145. int mode,
  146. dev_t rdev)
  147. {
  148. struct inode *inode;
  149. struct xfs_inode *ip = NULL;
  150. struct posix_acl *default_acl = NULL;
  151. struct xfs_name name;
  152. int error;
  153. /*
  154. * Irix uses Missed'em'V split, but doesn't want to see
  155. * the upper 5 bits of (14bit) major.
  156. */
  157. if (S_ISCHR(mode) || S_ISBLK(mode)) {
  158. if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
  159. return -EINVAL;
  160. rdev = sysv_encode_dev(rdev);
  161. } else {
  162. rdev = 0;
  163. }
  164. if (IS_POSIXACL(dir)) {
  165. default_acl = xfs_get_acl(dir, ACL_TYPE_DEFAULT);
  166. if (IS_ERR(default_acl))
  167. return -PTR_ERR(default_acl);
  168. if (!default_acl)
  169. mode &= ~current_umask();
  170. }
  171. xfs_dentry_to_name(&name, dentry);
  172. error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip);
  173. if (unlikely(error))
  174. goto out_free_acl;
  175. inode = VFS_I(ip);
  176. error = xfs_init_security(inode, dir, &dentry->d_name);
  177. if (unlikely(error))
  178. goto out_cleanup_inode;
  179. if (default_acl) {
  180. error = -xfs_inherit_acl(inode, default_acl);
  181. if (unlikely(error))
  182. goto out_cleanup_inode;
  183. posix_acl_release(default_acl);
  184. }
  185. d_instantiate(dentry, inode);
  186. return -error;
  187. out_cleanup_inode:
  188. xfs_cleanup_inode(dir, inode, dentry);
  189. out_free_acl:
  190. posix_acl_release(default_acl);
  191. return -error;
  192. }
  193. STATIC int
  194. xfs_vn_create(
  195. struct inode *dir,
  196. struct dentry *dentry,
  197. int mode,
  198. struct nameidata *nd)
  199. {
  200. return xfs_vn_mknod(dir, dentry, mode, 0);
  201. }
  202. STATIC int
  203. xfs_vn_mkdir(
  204. struct inode *dir,
  205. struct dentry *dentry,
  206. int mode)
  207. {
  208. return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
  209. }
  210. STATIC struct dentry *
  211. xfs_vn_lookup(
  212. struct inode *dir,
  213. struct dentry *dentry,
  214. struct nameidata *nd)
  215. {
  216. struct xfs_inode *cip;
  217. struct xfs_name name;
  218. int error;
  219. if (dentry->d_name.len >= MAXNAMELEN)
  220. return ERR_PTR(-ENAMETOOLONG);
  221. xfs_dentry_to_name(&name, dentry);
  222. error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
  223. if (unlikely(error)) {
  224. if (unlikely(error != ENOENT))
  225. return ERR_PTR(-error);
  226. d_add(dentry, NULL);
  227. return NULL;
  228. }
  229. return d_splice_alias(VFS_I(cip), dentry);
  230. }
  231. STATIC struct dentry *
  232. xfs_vn_ci_lookup(
  233. struct inode *dir,
  234. struct dentry *dentry,
  235. struct nameidata *nd)
  236. {
  237. struct xfs_inode *ip;
  238. struct xfs_name xname;
  239. struct xfs_name ci_name;
  240. struct qstr dname;
  241. int error;
  242. if (dentry->d_name.len >= MAXNAMELEN)
  243. return ERR_PTR(-ENAMETOOLONG);
  244. xfs_dentry_to_name(&xname, dentry);
  245. error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name);
  246. if (unlikely(error)) {
  247. if (unlikely(error != ENOENT))
  248. return ERR_PTR(-error);
  249. /*
  250. * call d_add(dentry, NULL) here when d_drop_negative_children
  251. * is called in xfs_vn_mknod (ie. allow negative dentries
  252. * with CI filesystems).
  253. */
  254. return NULL;
  255. }
  256. /* if exact match, just splice and exit */
  257. if (!ci_name.name)
  258. return d_splice_alias(VFS_I(ip), dentry);
  259. /* else case-insensitive match... */
  260. dname.name = ci_name.name;
  261. dname.len = ci_name.len;
  262. dentry = d_add_ci(dentry, VFS_I(ip), &dname);
  263. kmem_free(ci_name.name);
  264. return dentry;
  265. }
  266. STATIC int
  267. xfs_vn_link(
  268. struct dentry *old_dentry,
  269. struct inode *dir,
  270. struct dentry *dentry)
  271. {
  272. struct inode *inode = old_dentry->d_inode;
  273. struct xfs_name name;
  274. int error;
  275. xfs_dentry_to_name(&name, dentry);
  276. error = xfs_link(XFS_I(dir), XFS_I(inode), &name);
  277. if (unlikely(error))
  278. return -error;
  279. ihold(inode);
  280. d_instantiate(dentry, inode);
  281. return 0;
  282. }
  283. STATIC int
  284. xfs_vn_unlink(
  285. struct inode *dir,
  286. struct dentry *dentry)
  287. {
  288. struct xfs_name name;
  289. int error;
  290. xfs_dentry_to_name(&name, dentry);
  291. error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
  292. if (error)
  293. return error;
  294. /*
  295. * With unlink, the VFS makes the dentry "negative": no inode,
  296. * but still hashed. This is incompatible with case-insensitive
  297. * mode, so invalidate (unhash) the dentry in CI-mode.
  298. */
  299. if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
  300. d_invalidate(dentry);
  301. return 0;
  302. }
  303. STATIC int
  304. xfs_vn_symlink(
  305. struct inode *dir,
  306. struct dentry *dentry,
  307. const char *symname)
  308. {
  309. struct inode *inode;
  310. struct xfs_inode *cip = NULL;
  311. struct xfs_name name;
  312. int error;
  313. mode_t mode;
  314. mode = S_IFLNK |
  315. (irix_symlink_mode ? 0777 & ~current_umask() : S_IRWXUGO);
  316. xfs_dentry_to_name(&name, dentry);
  317. error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip);
  318. if (unlikely(error))
  319. goto out;
  320. inode = VFS_I(cip);
  321. error = xfs_init_security(inode, dir, &dentry->d_name);
  322. if (unlikely(error))
  323. goto out_cleanup_inode;
  324. d_instantiate(dentry, inode);
  325. return 0;
  326. out_cleanup_inode:
  327. xfs_cleanup_inode(dir, inode, dentry);
  328. out:
  329. return -error;
  330. }
  331. STATIC int
  332. xfs_vn_rename(
  333. struct inode *odir,
  334. struct dentry *odentry,
  335. struct inode *ndir,
  336. struct dentry *ndentry)
  337. {
  338. struct inode *new_inode = ndentry->d_inode;
  339. struct xfs_name oname;
  340. struct xfs_name nname;
  341. xfs_dentry_to_name(&oname, odentry);
  342. xfs_dentry_to_name(&nname, ndentry);
  343. return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
  344. XFS_I(ndir), &nname, new_inode ?
  345. XFS_I(new_inode) : NULL);
  346. }
  347. /*
  348. * careful here - this function can get called recursively, so
  349. * we need to be very careful about how much stack we use.
  350. * uio is kmalloced for this reason...
  351. */
  352. STATIC void *
  353. xfs_vn_follow_link(
  354. struct dentry *dentry,
  355. struct nameidata *nd)
  356. {
  357. char *link;
  358. int error = -ENOMEM;
  359. link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
  360. if (!link)
  361. goto out_err;
  362. error = -xfs_readlink(XFS_I(dentry->d_inode), link);
  363. if (unlikely(error))
  364. goto out_kfree;
  365. nd_set_link(nd, link);
  366. return NULL;
  367. out_kfree:
  368. kfree(link);
  369. out_err:
  370. nd_set_link(nd, ERR_PTR(error));
  371. return NULL;
  372. }
  373. STATIC void
  374. xfs_vn_put_link(
  375. struct dentry *dentry,
  376. struct nameidata *nd,
  377. void *p)
  378. {
  379. char *s = nd_get_link(nd);
  380. if (!IS_ERR(s))
  381. kfree(s);
  382. }
  383. STATIC int
  384. xfs_vn_getattr(
  385. struct vfsmount *mnt,
  386. struct dentry *dentry,
  387. struct kstat *stat)
  388. {
  389. struct inode *inode = dentry->d_inode;
  390. struct xfs_inode *ip = XFS_I(inode);
  391. struct xfs_mount *mp = ip->i_mount;
  392. trace_xfs_getattr(ip);
  393. if (XFS_FORCED_SHUTDOWN(mp))
  394. return XFS_ERROR(EIO);
  395. stat->size = XFS_ISIZE(ip);
  396. stat->dev = inode->i_sb->s_dev;
  397. stat->mode = ip->i_d.di_mode;
  398. stat->nlink = ip->i_d.di_nlink;
  399. stat->uid = ip->i_d.di_uid;
  400. stat->gid = ip->i_d.di_gid;
  401. stat->ino = ip->i_ino;
  402. stat->atime = inode->i_atime;
  403. stat->mtime = inode->i_mtime;
  404. stat->ctime = inode->i_ctime;
  405. stat->blocks =
  406. XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
  407. switch (inode->i_mode & S_IFMT) {
  408. case S_IFBLK:
  409. case S_IFCHR:
  410. stat->blksize = BLKDEV_IOSIZE;
  411. stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
  412. sysv_minor(ip->i_df.if_u2.if_rdev));
  413. break;
  414. default:
  415. if (XFS_IS_REALTIME_INODE(ip)) {
  416. /*
  417. * If the file blocks are being allocated from a
  418. * realtime volume, then return the inode's realtime
  419. * extent size or the realtime volume's extent size.
  420. */
  421. stat->blksize =
  422. xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
  423. } else
  424. stat->blksize = xfs_preferred_iosize(mp);
  425. stat->rdev = 0;
  426. break;
  427. }
  428. return 0;
  429. }
  430. STATIC int
  431. xfs_vn_setattr(
  432. struct dentry *dentry,
  433. struct iattr *iattr)
  434. {
  435. return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0);
  436. }
  437. #define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR)
  438. /*
  439. * Call fiemap helper to fill in user data.
  440. * Returns positive errors to xfs_getbmap.
  441. */
  442. STATIC int
  443. xfs_fiemap_format(
  444. void **arg,
  445. struct getbmapx *bmv,
  446. int *full)
  447. {
  448. int error;
  449. struct fiemap_extent_info *fieinfo = *arg;
  450. u32 fiemap_flags = 0;
  451. u64 logical, physical, length;
  452. /* Do nothing for a hole */
  453. if (bmv->bmv_block == -1LL)
  454. return 0;
  455. logical = BBTOB(bmv->bmv_offset);
  456. physical = BBTOB(bmv->bmv_block);
  457. length = BBTOB(bmv->bmv_length);
  458. if (bmv->bmv_oflags & BMV_OF_PREALLOC)
  459. fiemap_flags |= FIEMAP_EXTENT_UNWRITTEN;
  460. else if (bmv->bmv_oflags & BMV_OF_DELALLOC) {
  461. fiemap_flags |= FIEMAP_EXTENT_DELALLOC;
  462. physical = 0; /* no block yet */
  463. }
  464. if (bmv->bmv_oflags & BMV_OF_LAST)
  465. fiemap_flags |= FIEMAP_EXTENT_LAST;
  466. error = fiemap_fill_next_extent(fieinfo, logical, physical,
  467. length, fiemap_flags);
  468. if (error > 0) {
  469. error = 0;
  470. *full = 1; /* user array now full */
  471. }
  472. return -error;
  473. }
  474. STATIC int
  475. xfs_vn_fiemap(
  476. struct inode *inode,
  477. struct fiemap_extent_info *fieinfo,
  478. u64 start,
  479. u64 length)
  480. {
  481. xfs_inode_t *ip = XFS_I(inode);
  482. struct getbmapx bm;
  483. int error;
  484. error = fiemap_check_flags(fieinfo, XFS_FIEMAP_FLAGS);
  485. if (error)
  486. return error;
  487. /* Set up bmap header for xfs internal routine */
  488. bm.bmv_offset = BTOBB(start);
  489. /* Special case for whole file */
  490. if (length == FIEMAP_MAX_OFFSET)
  491. bm.bmv_length = -1LL;
  492. else
  493. bm.bmv_length = BTOBB(length);
  494. /* We add one because in getbmap world count includes the header */
  495. bm.bmv_count = !fieinfo->fi_extents_max ? MAXEXTNUM :
  496. fieinfo->fi_extents_max + 1;
  497. bm.bmv_count = min_t(__s32, bm.bmv_count,
  498. (PAGE_SIZE * 16 / sizeof(struct getbmapx)));
  499. bm.bmv_iflags = BMV_IF_PREALLOC | BMV_IF_NO_HOLES;
  500. if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR)
  501. bm.bmv_iflags |= BMV_IF_ATTRFORK;
  502. if (!(fieinfo->fi_flags & FIEMAP_FLAG_SYNC))
  503. bm.bmv_iflags |= BMV_IF_DELALLOC;
  504. error = xfs_getbmap(ip, &bm, xfs_fiemap_format, fieinfo);
  505. if (error)
  506. return -error;
  507. return 0;
  508. }
  509. static const struct inode_operations xfs_inode_operations = {
  510. .check_acl = xfs_check_acl,
  511. .getattr = xfs_vn_getattr,
  512. .setattr = xfs_vn_setattr,
  513. .setxattr = generic_setxattr,
  514. .getxattr = generic_getxattr,
  515. .removexattr = generic_removexattr,
  516. .listxattr = xfs_vn_listxattr,
  517. .fiemap = xfs_vn_fiemap,
  518. };
  519. static const struct inode_operations xfs_dir_inode_operations = {
  520. .create = xfs_vn_create,
  521. .lookup = xfs_vn_lookup,
  522. .link = xfs_vn_link,
  523. .unlink = xfs_vn_unlink,
  524. .symlink = xfs_vn_symlink,
  525. .mkdir = xfs_vn_mkdir,
  526. /*
  527. * Yes, XFS uses the same method for rmdir and unlink.
  528. *
  529. * There are some subtile differences deeper in the code,
  530. * but we use S_ISDIR to check for those.
  531. */
  532. .rmdir = xfs_vn_unlink,
  533. .mknod = xfs_vn_mknod,
  534. .rename = xfs_vn_rename,
  535. .check_acl = xfs_check_acl,
  536. .getattr = xfs_vn_getattr,
  537. .setattr = xfs_vn_setattr,
  538. .setxattr = generic_setxattr,
  539. .getxattr = generic_getxattr,
  540. .removexattr = generic_removexattr,
  541. .listxattr = xfs_vn_listxattr,
  542. };
  543. static const struct inode_operations xfs_dir_ci_inode_operations = {
  544. .create = xfs_vn_create,
  545. .lookup = xfs_vn_ci_lookup,
  546. .link = xfs_vn_link,
  547. .unlink = xfs_vn_unlink,
  548. .symlink = xfs_vn_symlink,
  549. .mkdir = xfs_vn_mkdir,
  550. /*
  551. * Yes, XFS uses the same method for rmdir and unlink.
  552. *
  553. * There are some subtile differences deeper in the code,
  554. * but we use S_ISDIR to check for those.
  555. */
  556. .rmdir = xfs_vn_unlink,
  557. .mknod = xfs_vn_mknod,
  558. .rename = xfs_vn_rename,
  559. .check_acl = xfs_check_acl,
  560. .getattr = xfs_vn_getattr,
  561. .setattr = xfs_vn_setattr,
  562. .setxattr = generic_setxattr,
  563. .getxattr = generic_getxattr,
  564. .removexattr = generic_removexattr,
  565. .listxattr = xfs_vn_listxattr,
  566. };
  567. static const struct inode_operations xfs_symlink_inode_operations = {
  568. .readlink = generic_readlink,
  569. .follow_link = xfs_vn_follow_link,
  570. .put_link = xfs_vn_put_link,
  571. .check_acl = xfs_check_acl,
  572. .getattr = xfs_vn_getattr,
  573. .setattr = xfs_vn_setattr,
  574. .setxattr = generic_setxattr,
  575. .getxattr = generic_getxattr,
  576. .removexattr = generic_removexattr,
  577. .listxattr = xfs_vn_listxattr,
  578. };
  579. STATIC void
  580. xfs_diflags_to_iflags(
  581. struct inode *inode,
  582. struct xfs_inode *ip)
  583. {
  584. if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
  585. inode->i_flags |= S_IMMUTABLE;
  586. else
  587. inode->i_flags &= ~S_IMMUTABLE;
  588. if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
  589. inode->i_flags |= S_APPEND;
  590. else
  591. inode->i_flags &= ~S_APPEND;
  592. if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
  593. inode->i_flags |= S_SYNC;
  594. else
  595. inode->i_flags &= ~S_SYNC;
  596. if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
  597. inode->i_flags |= S_NOATIME;
  598. else
  599. inode->i_flags &= ~S_NOATIME;
  600. }
  601. /*
  602. * Initialize the Linux inode, set up the operation vectors and
  603. * unlock the inode.
  604. *
  605. * When reading existing inodes from disk this is called directly
  606. * from xfs_iget, when creating a new inode it is called from
  607. * xfs_ialloc after setting up the inode.
  608. *
  609. * We are always called with an uninitialised linux inode here.
  610. * We need to initialise the necessary fields and take a reference
  611. * on it.
  612. */
  613. void
  614. xfs_setup_inode(
  615. struct xfs_inode *ip)
  616. {
  617. struct inode *inode = &ip->i_vnode;
  618. inode->i_ino = ip->i_ino;
  619. inode->i_state = I_NEW;
  620. inode_sb_list_add(inode);
  621. /* make the inode look hashed for the writeback code */
  622. hlist_add_fake(&inode->i_hash);
  623. inode->i_mode = ip->i_d.di_mode;
  624. inode->i_nlink = ip->i_d.di_nlink;
  625. inode->i_uid = ip->i_d.di_uid;
  626. inode->i_gid = ip->i_d.di_gid;
  627. switch (inode->i_mode & S_IFMT) {
  628. case S_IFBLK:
  629. case S_IFCHR:
  630. inode->i_rdev =
  631. MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
  632. sysv_minor(ip->i_df.if_u2.if_rdev));
  633. break;
  634. default:
  635. inode->i_rdev = 0;
  636. break;
  637. }
  638. inode->i_generation = ip->i_d.di_gen;
  639. i_size_write(inode, ip->i_d.di_size);
  640. inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
  641. inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
  642. inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
  643. inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
  644. inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
  645. inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
  646. xfs_diflags_to_iflags(inode, ip);
  647. switch (inode->i_mode & S_IFMT) {
  648. case S_IFREG:
  649. inode->i_op = &xfs_inode_operations;
  650. inode->i_fop = &xfs_file_operations;
  651. inode->i_mapping->a_ops = &xfs_address_space_operations;
  652. break;
  653. case S_IFDIR:
  654. if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
  655. inode->i_op = &xfs_dir_ci_inode_operations;
  656. else
  657. inode->i_op = &xfs_dir_inode_operations;
  658. inode->i_fop = &xfs_dir_file_operations;
  659. break;
  660. case S_IFLNK:
  661. inode->i_op = &xfs_symlink_inode_operations;
  662. if (!(ip->i_df.if_flags & XFS_IFINLINE))
  663. inode->i_mapping->a_ops = &xfs_address_space_operations;
  664. break;
  665. default:
  666. inode->i_op = &xfs_inode_operations;
  667. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  668. break;
  669. }
  670. xfs_iflags_clear(ip, XFS_INEW);
  671. barrier();
  672. unlock_new_inode(inode);
  673. }