xfs_iops.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871
  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|I_CLEAR)))
  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|I_CLEAR)))
  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. xfs_itrace_entry(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. /*
  469. * block_truncate_page can return an error, but we can't propagate it
  470. * at all here. Leave a complaint + stack trace in the syslog because
  471. * this could be bad. If it is bad, we need to propagate the error further.
  472. */
  473. STATIC void
  474. xfs_vn_truncate(
  475. struct inode *inode)
  476. {
  477. int error;
  478. error = block_truncate_page(inode->i_mapping, inode->i_size,
  479. xfs_get_blocks);
  480. WARN_ON(error);
  481. }
  482. STATIC long
  483. xfs_vn_fallocate(
  484. struct inode *inode,
  485. int mode,
  486. loff_t offset,
  487. loff_t len)
  488. {
  489. long error;
  490. loff_t new_size = 0;
  491. xfs_flock64_t bf;
  492. xfs_inode_t *ip = XFS_I(inode);
  493. /* preallocation on directories not yet supported */
  494. error = -ENODEV;
  495. if (S_ISDIR(inode->i_mode))
  496. goto out_error;
  497. bf.l_whence = 0;
  498. bf.l_start = offset;
  499. bf.l_len = len;
  500. xfs_ilock(ip, XFS_IOLOCK_EXCL);
  501. /* check the new inode size is valid before allocating */
  502. if (!(mode & FALLOC_FL_KEEP_SIZE) &&
  503. offset + len > i_size_read(inode)) {
  504. new_size = offset + len;
  505. error = inode_newsize_ok(inode, new_size);
  506. if (error)
  507. goto out_unlock;
  508. }
  509. error = -xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf,
  510. 0, XFS_ATTR_NOLOCK);
  511. if (error)
  512. goto out_unlock;
  513. /* Change file size if needed */
  514. if (new_size) {
  515. struct iattr iattr;
  516. iattr.ia_valid = ATTR_SIZE;
  517. iattr.ia_size = new_size;
  518. error = -xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK);
  519. }
  520. out_unlock:
  521. xfs_iunlock(ip, XFS_IOLOCK_EXCL);
  522. out_error:
  523. return error;
  524. }
  525. #define XFS_FIEMAP_FLAGS (FIEMAP_FLAG_SYNC|FIEMAP_FLAG_XATTR)
  526. /*
  527. * Call fiemap helper to fill in user data.
  528. * Returns positive errors to xfs_getbmap.
  529. */
  530. STATIC int
  531. xfs_fiemap_format(
  532. void **arg,
  533. struct getbmapx *bmv,
  534. int *full)
  535. {
  536. int error;
  537. struct fiemap_extent_info *fieinfo = *arg;
  538. u32 fiemap_flags = 0;
  539. u64 logical, physical, length;
  540. /* Do nothing for a hole */
  541. if (bmv->bmv_block == -1LL)
  542. return 0;
  543. logical = BBTOB(bmv->bmv_offset);
  544. physical = BBTOB(bmv->bmv_block);
  545. length = BBTOB(bmv->bmv_length);
  546. if (bmv->bmv_oflags & BMV_OF_PREALLOC)
  547. fiemap_flags |= FIEMAP_EXTENT_UNWRITTEN;
  548. else if (bmv->bmv_oflags & BMV_OF_DELALLOC) {
  549. fiemap_flags |= FIEMAP_EXTENT_DELALLOC;
  550. physical = 0; /* no block yet */
  551. }
  552. if (bmv->bmv_oflags & BMV_OF_LAST)
  553. fiemap_flags |= FIEMAP_EXTENT_LAST;
  554. error = fiemap_fill_next_extent(fieinfo, logical, physical,
  555. length, fiemap_flags);
  556. if (error > 0) {
  557. error = 0;
  558. *full = 1; /* user array now full */
  559. }
  560. return -error;
  561. }
  562. STATIC int
  563. xfs_vn_fiemap(
  564. struct inode *inode,
  565. struct fiemap_extent_info *fieinfo,
  566. u64 start,
  567. u64 length)
  568. {
  569. xfs_inode_t *ip = XFS_I(inode);
  570. struct getbmapx bm;
  571. int error;
  572. error = fiemap_check_flags(fieinfo, XFS_FIEMAP_FLAGS);
  573. if (error)
  574. return error;
  575. /* Set up bmap header for xfs internal routine */
  576. bm.bmv_offset = BTOBB(start);
  577. /* Special case for whole file */
  578. if (length == FIEMAP_MAX_OFFSET)
  579. bm.bmv_length = -1LL;
  580. else
  581. bm.bmv_length = BTOBB(length);
  582. /* We add one because in getbmap world count includes the header */
  583. bm.bmv_count = !fieinfo->fi_extents_max ? MAXEXTNUM :
  584. fieinfo->fi_extents_max + 1;
  585. bm.bmv_count = min_t(__s32, bm.bmv_count,
  586. (PAGE_SIZE * 16 / sizeof(struct getbmapx)));
  587. bm.bmv_iflags = BMV_IF_PREALLOC;
  588. if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR)
  589. bm.bmv_iflags |= BMV_IF_ATTRFORK;
  590. if (!(fieinfo->fi_flags & FIEMAP_FLAG_SYNC))
  591. bm.bmv_iflags |= BMV_IF_DELALLOC;
  592. error = xfs_getbmap(ip, &bm, xfs_fiemap_format, fieinfo);
  593. if (error)
  594. return -error;
  595. return 0;
  596. }
  597. static const struct inode_operations xfs_inode_operations = {
  598. .check_acl = xfs_check_acl,
  599. .truncate = xfs_vn_truncate,
  600. .getattr = xfs_vn_getattr,
  601. .setattr = xfs_vn_setattr,
  602. .setxattr = generic_setxattr,
  603. .getxattr = generic_getxattr,
  604. .removexattr = generic_removexattr,
  605. .listxattr = xfs_vn_listxattr,
  606. .fallocate = xfs_vn_fallocate,
  607. .fiemap = xfs_vn_fiemap,
  608. };
  609. static const struct inode_operations xfs_dir_inode_operations = {
  610. .create = xfs_vn_create,
  611. .lookup = xfs_vn_lookup,
  612. .link = xfs_vn_link,
  613. .unlink = xfs_vn_unlink,
  614. .symlink = xfs_vn_symlink,
  615. .mkdir = xfs_vn_mkdir,
  616. /*
  617. * Yes, XFS uses the same method for rmdir and unlink.
  618. *
  619. * There are some subtile differences deeper in the code,
  620. * but we use S_ISDIR to check for those.
  621. */
  622. .rmdir = xfs_vn_unlink,
  623. .mknod = xfs_vn_mknod,
  624. .rename = xfs_vn_rename,
  625. .check_acl = xfs_check_acl,
  626. .getattr = xfs_vn_getattr,
  627. .setattr = xfs_vn_setattr,
  628. .setxattr = generic_setxattr,
  629. .getxattr = generic_getxattr,
  630. .removexattr = generic_removexattr,
  631. .listxattr = xfs_vn_listxattr,
  632. };
  633. static const struct inode_operations xfs_dir_ci_inode_operations = {
  634. .create = xfs_vn_create,
  635. .lookup = xfs_vn_ci_lookup,
  636. .link = xfs_vn_link,
  637. .unlink = xfs_vn_unlink,
  638. .symlink = xfs_vn_symlink,
  639. .mkdir = xfs_vn_mkdir,
  640. /*
  641. * Yes, XFS uses the same method for rmdir and unlink.
  642. *
  643. * There are some subtile differences deeper in the code,
  644. * but we use S_ISDIR to check for those.
  645. */
  646. .rmdir = xfs_vn_unlink,
  647. .mknod = xfs_vn_mknod,
  648. .rename = xfs_vn_rename,
  649. .check_acl = xfs_check_acl,
  650. .getattr = xfs_vn_getattr,
  651. .setattr = xfs_vn_setattr,
  652. .setxattr = generic_setxattr,
  653. .getxattr = generic_getxattr,
  654. .removexattr = generic_removexattr,
  655. .listxattr = xfs_vn_listxattr,
  656. };
  657. static const struct inode_operations xfs_symlink_inode_operations = {
  658. .readlink = generic_readlink,
  659. .follow_link = xfs_vn_follow_link,
  660. .put_link = xfs_vn_put_link,
  661. .check_acl = xfs_check_acl,
  662. .getattr = xfs_vn_getattr,
  663. .setattr = xfs_vn_setattr,
  664. .setxattr = generic_setxattr,
  665. .getxattr = generic_getxattr,
  666. .removexattr = generic_removexattr,
  667. .listxattr = xfs_vn_listxattr,
  668. };
  669. STATIC void
  670. xfs_diflags_to_iflags(
  671. struct inode *inode,
  672. struct xfs_inode *ip)
  673. {
  674. if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
  675. inode->i_flags |= S_IMMUTABLE;
  676. else
  677. inode->i_flags &= ~S_IMMUTABLE;
  678. if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
  679. inode->i_flags |= S_APPEND;
  680. else
  681. inode->i_flags &= ~S_APPEND;
  682. if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
  683. inode->i_flags |= S_SYNC;
  684. else
  685. inode->i_flags &= ~S_SYNC;
  686. if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
  687. inode->i_flags |= S_NOATIME;
  688. else
  689. inode->i_flags &= ~S_NOATIME;
  690. }
  691. /*
  692. * Initialize the Linux inode, set up the operation vectors and
  693. * unlock the inode.
  694. *
  695. * When reading existing inodes from disk this is called directly
  696. * from xfs_iget, when creating a new inode it is called from
  697. * xfs_ialloc after setting up the inode.
  698. *
  699. * We are always called with an uninitialised linux inode here.
  700. * We need to initialise the necessary fields and take a reference
  701. * on it.
  702. */
  703. void
  704. xfs_setup_inode(
  705. struct xfs_inode *ip)
  706. {
  707. struct inode *inode = &ip->i_vnode;
  708. inode->i_ino = ip->i_ino;
  709. inode->i_state = I_NEW;
  710. inode_add_to_lists(ip->i_mount->m_super, inode);
  711. inode->i_mode = ip->i_d.di_mode;
  712. inode->i_nlink = ip->i_d.di_nlink;
  713. inode->i_uid = ip->i_d.di_uid;
  714. inode->i_gid = ip->i_d.di_gid;
  715. switch (inode->i_mode & S_IFMT) {
  716. case S_IFBLK:
  717. case S_IFCHR:
  718. inode->i_rdev =
  719. MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
  720. sysv_minor(ip->i_df.if_u2.if_rdev));
  721. break;
  722. default:
  723. inode->i_rdev = 0;
  724. break;
  725. }
  726. inode->i_generation = ip->i_d.di_gen;
  727. i_size_write(inode, ip->i_d.di_size);
  728. inode->i_atime.tv_sec = ip->i_d.di_atime.t_sec;
  729. inode->i_atime.tv_nsec = ip->i_d.di_atime.t_nsec;
  730. inode->i_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
  731. inode->i_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
  732. inode->i_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
  733. inode->i_ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
  734. xfs_diflags_to_iflags(inode, ip);
  735. switch (inode->i_mode & S_IFMT) {
  736. case S_IFREG:
  737. inode->i_op = &xfs_inode_operations;
  738. inode->i_fop = &xfs_file_operations;
  739. inode->i_mapping->a_ops = &xfs_address_space_operations;
  740. break;
  741. case S_IFDIR:
  742. if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
  743. inode->i_op = &xfs_dir_ci_inode_operations;
  744. else
  745. inode->i_op = &xfs_dir_inode_operations;
  746. inode->i_fop = &xfs_dir_file_operations;
  747. break;
  748. case S_IFLNK:
  749. inode->i_op = &xfs_symlink_inode_operations;
  750. if (!(ip->i_df.if_flags & XFS_IFINLINE))
  751. inode->i_mapping->a_ops = &xfs_address_space_operations;
  752. break;
  753. default:
  754. inode->i_op = &xfs_inode_operations;
  755. init_special_inode(inode, inode->i_mode, inode->i_rdev);
  756. break;
  757. }
  758. xfs_iflags_clear(ip, XFS_INEW);
  759. barrier();
  760. unlock_new_inode(inode);
  761. }