xfs_iops.c 19 KB

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