xfs_iops.c 18 KB

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