xattr.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320
  1. /*
  2. * linux/fs/reiserfs/xattr.c
  3. *
  4. * Copyright (c) 2002 by Jeff Mahoney, <jeffm@suse.com>
  5. *
  6. */
  7. /*
  8. * In order to implement EA/ACLs in a clean, backwards compatible manner,
  9. * they are implemented as files in a "private" directory.
  10. * Each EA is in it's own file, with the directory layout like so (/ is assumed
  11. * to be relative to fs root). Inside the /.reiserfs_priv/xattrs directory,
  12. * directories named using the capital-hex form of the objectid and
  13. * generation number are used. Inside each directory are individual files
  14. * named with the name of the extended attribute.
  15. *
  16. * So, for objectid 12648430, we could have:
  17. * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_access
  18. * /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_default
  19. * /.reiserfs_priv/xattrs/C0FFEE.0/user.Content-Type
  20. * .. or similar.
  21. *
  22. * The file contents are the text of the EA. The size is known based on the
  23. * stat data describing the file.
  24. *
  25. * In the case of system.posix_acl_access and system.posix_acl_default, since
  26. * these are special cases for filesystem ACLs, they are interpreted by the
  27. * kernel, in addition, they are negatively and positively cached and attached
  28. * to the inode so that unnecessary lookups are avoided.
  29. */
  30. #include <linux/reiserfs_fs.h>
  31. #include <linux/capability.h>
  32. #include <linux/dcache.h>
  33. #include <linux/namei.h>
  34. #include <linux/errno.h>
  35. #include <linux/fs.h>
  36. #include <linux/file.h>
  37. #include <linux/pagemap.h>
  38. #include <linux/xattr.h>
  39. #include <linux/reiserfs_xattr.h>
  40. #include <linux/reiserfs_acl.h>
  41. #include <asm/uaccess.h>
  42. #include <net/checksum.h>
  43. #include <linux/smp_lock.h>
  44. #include <linux/stat.h>
  45. #include <asm/semaphore.h>
  46. #define FL_READONLY 128
  47. #define FL_DIR_SEM_HELD 256
  48. #define PRIVROOT_NAME ".reiserfs_priv"
  49. #define XAROOT_NAME "xattrs"
  50. static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
  51. *prefix);
  52. /* Returns the dentry referring to the root of the extended attribute
  53. * directory tree. If it has already been retrieved, it is used. If it
  54. * hasn't been created and the flags indicate creation is allowed, we
  55. * attempt to create it. On error, we return a pointer-encoded error.
  56. */
  57. static struct dentry *get_xa_root(struct super_block *sb, int flags)
  58. {
  59. struct dentry *privroot = dget(REISERFS_SB(sb)->priv_root);
  60. struct dentry *xaroot;
  61. /* This needs to be created at mount-time */
  62. if (!privroot)
  63. return ERR_PTR(-ENODATA);
  64. mutex_lock_nested(&privroot->d_inode->i_mutex, I_MUTEX_XATTR);
  65. if (REISERFS_SB(sb)->xattr_root) {
  66. xaroot = dget(REISERFS_SB(sb)->xattr_root);
  67. goto out;
  68. }
  69. xaroot = lookup_one_len(XAROOT_NAME, privroot, strlen(XAROOT_NAME));
  70. if (IS_ERR(xaroot)) {
  71. goto out;
  72. } else if (!xaroot->d_inode) {
  73. int err = -ENODATA;
  74. if (flags == 0 || flags & XATTR_CREATE)
  75. err = privroot->d_inode->i_op->mkdir(privroot->d_inode,
  76. xaroot, 0700);
  77. if (err) {
  78. dput(xaroot);
  79. xaroot = ERR_PTR(err);
  80. goto out;
  81. }
  82. }
  83. REISERFS_SB(sb)->xattr_root = dget(xaroot);
  84. out:
  85. mutex_unlock(&privroot->d_inode->i_mutex);
  86. dput(privroot);
  87. return xaroot;
  88. }
  89. /* Opens the directory corresponding to the inode's extended attribute store.
  90. * If flags allow, the tree to the directory may be created. If creation is
  91. * prohibited, -ENODATA is returned. */
  92. static struct dentry *open_xa_dir(const struct inode *inode, int flags)
  93. {
  94. struct dentry *xaroot, *xadir;
  95. char namebuf[17];
  96. xaroot = get_xa_root(inode->i_sb, flags);
  97. if (IS_ERR(xaroot))
  98. return xaroot;
  99. /* ok, we have xaroot open */
  100. snprintf(namebuf, sizeof(namebuf), "%X.%X",
  101. le32_to_cpu(INODE_PKEY(inode)->k_objectid),
  102. inode->i_generation);
  103. xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf));
  104. if (IS_ERR(xadir)) {
  105. dput(xaroot);
  106. return xadir;
  107. }
  108. if (!xadir->d_inode) {
  109. int err;
  110. if (flags == 0 || flags & XATTR_CREATE) {
  111. /* Although there is nothing else trying to create this directory,
  112. * another directory with the same hash may be created, so we need
  113. * to protect against that */
  114. err =
  115. xaroot->d_inode->i_op->mkdir(xaroot->d_inode, xadir,
  116. 0700);
  117. if (err) {
  118. dput(xaroot);
  119. dput(xadir);
  120. return ERR_PTR(err);
  121. }
  122. }
  123. if (!xadir->d_inode) {
  124. dput(xaroot);
  125. dput(xadir);
  126. return ERR_PTR(-ENODATA);
  127. }
  128. }
  129. dput(xaroot);
  130. return xadir;
  131. }
  132. /* Returns a dentry corresponding to a specific extended attribute file
  133. * for the inode. If flags allow, the file is created. Otherwise, a
  134. * valid or negative dentry, or an error is returned. */
  135. static struct dentry *get_xa_file_dentry(const struct inode *inode,
  136. const char *name, int flags)
  137. {
  138. struct dentry *xadir, *xafile;
  139. int err = 0;
  140. xadir = open_xa_dir(inode, flags);
  141. if (IS_ERR(xadir)) {
  142. return ERR_PTR(PTR_ERR(xadir));
  143. } else if (xadir && !xadir->d_inode) {
  144. dput(xadir);
  145. return ERR_PTR(-ENODATA);
  146. }
  147. xafile = lookup_one_len(name, xadir, strlen(name));
  148. if (IS_ERR(xafile)) {
  149. dput(xadir);
  150. return ERR_PTR(PTR_ERR(xafile));
  151. }
  152. if (xafile->d_inode) { /* file exists */
  153. if (flags & XATTR_CREATE) {
  154. err = -EEXIST;
  155. dput(xafile);
  156. goto out;
  157. }
  158. } else if (flags & XATTR_REPLACE || flags & FL_READONLY) {
  159. goto out;
  160. } else {
  161. /* inode->i_mutex is down, so nothing else can try to create
  162. * the same xattr */
  163. err = xadir->d_inode->i_op->create(xadir->d_inode, xafile,
  164. 0700 | S_IFREG, NULL);
  165. if (err) {
  166. dput(xafile);
  167. goto out;
  168. }
  169. }
  170. out:
  171. dput(xadir);
  172. if (err)
  173. xafile = ERR_PTR(err);
  174. return xafile;
  175. }
  176. /* Opens a file pointer to the attribute associated with inode */
  177. static struct file *open_xa_file(const struct inode *inode, const char *name,
  178. int flags)
  179. {
  180. struct dentry *xafile;
  181. struct file *fp;
  182. xafile = get_xa_file_dentry(inode, name, flags);
  183. if (IS_ERR(xafile))
  184. return ERR_PTR(PTR_ERR(xafile));
  185. else if (!xafile->d_inode) {
  186. dput(xafile);
  187. return ERR_PTR(-ENODATA);
  188. }
  189. fp = dentry_open(xafile, NULL, O_RDWR);
  190. /* dentry_open dputs the dentry if it fails */
  191. return fp;
  192. }
  193. /*
  194. * this is very similar to fs/reiserfs/dir.c:reiserfs_readdir, but
  195. * we need to drop the path before calling the filldir struct. That
  196. * would be a big performance hit to the non-xattr case, so I've copied
  197. * the whole thing for now. --clm
  198. *
  199. * the big difference is that I go backwards through the directory,
  200. * and don't mess with f->f_pos, but the idea is the same. Do some
  201. * action on each and every entry in the directory.
  202. *
  203. * we're called with i_mutex held, so there are no worries about the directory
  204. * changing underneath us.
  205. */
  206. static int __xattr_readdir(struct file *filp, void *dirent, filldir_t filldir)
  207. {
  208. struct inode *inode = filp->f_path.dentry->d_inode;
  209. struct cpu_key pos_key; /* key of current position in the directory (key of directory entry) */
  210. INITIALIZE_PATH(path_to_entry);
  211. struct buffer_head *bh;
  212. int entry_num;
  213. struct item_head *ih, tmp_ih;
  214. int search_res;
  215. char *local_buf;
  216. loff_t next_pos;
  217. char small_buf[32]; /* avoid kmalloc if we can */
  218. struct reiserfs_de_head *deh;
  219. int d_reclen;
  220. char *d_name;
  221. off_t d_off;
  222. ino_t d_ino;
  223. struct reiserfs_dir_entry de;
  224. /* form key for search the next directory entry using f_pos field of
  225. file structure */
  226. next_pos = max_reiserfs_offset(inode);
  227. while (1) {
  228. research:
  229. if (next_pos <= DOT_DOT_OFFSET)
  230. break;
  231. make_cpu_key(&pos_key, inode, next_pos, TYPE_DIRENTRY, 3);
  232. search_res =
  233. search_by_entry_key(inode->i_sb, &pos_key, &path_to_entry,
  234. &de);
  235. if (search_res == IO_ERROR) {
  236. // FIXME: we could just skip part of directory which could
  237. // not be read
  238. pathrelse(&path_to_entry);
  239. return -EIO;
  240. }
  241. if (search_res == NAME_NOT_FOUND)
  242. de.de_entry_num--;
  243. set_de_name_and_namelen(&de);
  244. entry_num = de.de_entry_num;
  245. deh = &(de.de_deh[entry_num]);
  246. bh = de.de_bh;
  247. ih = de.de_ih;
  248. if (!is_direntry_le_ih(ih)) {
  249. reiserfs_warning(inode->i_sb, "not direntry %h", ih);
  250. break;
  251. }
  252. copy_item_head(&tmp_ih, ih);
  253. /* we must have found item, that is item of this directory, */
  254. RFALSE(COMP_SHORT_KEYS(&(ih->ih_key), &pos_key),
  255. "vs-9000: found item %h does not match to dir we readdir %K",
  256. ih, &pos_key);
  257. if (deh_offset(deh) <= DOT_DOT_OFFSET) {
  258. break;
  259. }
  260. /* look for the previous entry in the directory */
  261. next_pos = deh_offset(deh) - 1;
  262. if (!de_visible(deh))
  263. /* it is hidden entry */
  264. continue;
  265. d_reclen = entry_length(bh, ih, entry_num);
  266. d_name = B_I_DEH_ENTRY_FILE_NAME(bh, ih, deh);
  267. d_off = deh_offset(deh);
  268. d_ino = deh_objectid(deh);
  269. if (!d_name[d_reclen - 1])
  270. d_reclen = strlen(d_name);
  271. if (d_reclen > REISERFS_MAX_NAME(inode->i_sb->s_blocksize)) {
  272. /* too big to send back to VFS */
  273. continue;
  274. }
  275. /* Ignore the .reiserfs_priv entry */
  276. if (reiserfs_xattrs(inode->i_sb) &&
  277. !old_format_only(inode->i_sb) &&
  278. deh_objectid(deh) ==
  279. le32_to_cpu(INODE_PKEY
  280. (REISERFS_SB(inode->i_sb)->priv_root->d_inode)->
  281. k_objectid))
  282. continue;
  283. if (d_reclen <= 32) {
  284. local_buf = small_buf;
  285. } else {
  286. local_buf = kmalloc(d_reclen, GFP_NOFS);
  287. if (!local_buf) {
  288. pathrelse(&path_to_entry);
  289. return -ENOMEM;
  290. }
  291. if (item_moved(&tmp_ih, &path_to_entry)) {
  292. kfree(local_buf);
  293. /* sigh, must retry. Do this same offset again */
  294. next_pos = d_off;
  295. goto research;
  296. }
  297. }
  298. // Note, that we copy name to user space via temporary
  299. // buffer (local_buf) because filldir will block if
  300. // user space buffer is swapped out. At that time
  301. // entry can move to somewhere else
  302. memcpy(local_buf, d_name, d_reclen);
  303. /* the filldir function might need to start transactions,
  304. * or do who knows what. Release the path now that we've
  305. * copied all the important stuff out of the deh
  306. */
  307. pathrelse(&path_to_entry);
  308. if (filldir(dirent, local_buf, d_reclen, d_off, d_ino,
  309. DT_UNKNOWN) < 0) {
  310. if (local_buf != small_buf) {
  311. kfree(local_buf);
  312. }
  313. goto end;
  314. }
  315. if (local_buf != small_buf) {
  316. kfree(local_buf);
  317. }
  318. } /* while */
  319. end:
  320. pathrelse(&path_to_entry);
  321. return 0;
  322. }
  323. /*
  324. * this could be done with dedicated readdir ops for the xattr files,
  325. * but I want to get something working asap
  326. * this is stolen from vfs_readdir
  327. *
  328. */
  329. static
  330. int xattr_readdir(struct file *file, filldir_t filler, void *buf)
  331. {
  332. struct inode *inode = file->f_path.dentry->d_inode;
  333. int res = -ENOTDIR;
  334. if (!file->f_op || !file->f_op->readdir)
  335. goto out;
  336. mutex_lock_nested(&inode->i_mutex, I_MUTEX_XATTR);
  337. // down(&inode->i_zombie);
  338. res = -ENOENT;
  339. if (!IS_DEADDIR(inode)) {
  340. lock_kernel();
  341. res = __xattr_readdir(file, buf, filler);
  342. unlock_kernel();
  343. }
  344. // up(&inode->i_zombie);
  345. mutex_unlock(&inode->i_mutex);
  346. out:
  347. return res;
  348. }
  349. /* Internal operations on file data */
  350. static inline void reiserfs_put_page(struct page *page)
  351. {
  352. kunmap(page);
  353. page_cache_release(page);
  354. }
  355. static struct page *reiserfs_get_page(struct inode *dir, unsigned long n)
  356. {
  357. struct address_space *mapping = dir->i_mapping;
  358. struct page *page;
  359. /* We can deadlock if we try to free dentries,
  360. and an unlink/rmdir has just occured - GFP_NOFS avoids this */
  361. mapping_set_gfp_mask(mapping, GFP_NOFS);
  362. page = read_mapping_page(mapping, n, NULL);
  363. if (!IS_ERR(page)) {
  364. kmap(page);
  365. if (PageError(page))
  366. goto fail;
  367. }
  368. return page;
  369. fail:
  370. reiserfs_put_page(page);
  371. return ERR_PTR(-EIO);
  372. }
  373. static inline __u32 xattr_hash(const char *msg, int len)
  374. {
  375. return csum_partial(msg, len, 0);
  376. }
  377. int reiserfs_commit_write(struct file *f, struct page *page,
  378. unsigned from, unsigned to);
  379. int reiserfs_prepare_write(struct file *f, struct page *page,
  380. unsigned from, unsigned to);
  381. /* Generic extended attribute operations that can be used by xa plugins */
  382. /*
  383. * inode->i_mutex: down
  384. */
  385. int
  386. reiserfs_xattr_set(struct inode *inode, const char *name, const void *buffer,
  387. size_t buffer_size, int flags)
  388. {
  389. int err = 0;
  390. struct file *fp;
  391. struct page *page;
  392. char *data;
  393. struct address_space *mapping;
  394. size_t file_pos = 0;
  395. size_t buffer_pos = 0;
  396. struct inode *xinode;
  397. struct iattr newattrs;
  398. __u32 xahash = 0;
  399. if (get_inode_sd_version(inode) == STAT_DATA_V1)
  400. return -EOPNOTSUPP;
  401. /* Empty xattrs are ok, they're just empty files, no hash */
  402. if (buffer && buffer_size)
  403. xahash = xattr_hash(buffer, buffer_size);
  404. open_file:
  405. fp = open_xa_file(inode, name, flags);
  406. if (IS_ERR(fp)) {
  407. err = PTR_ERR(fp);
  408. goto out;
  409. }
  410. xinode = fp->f_path.dentry->d_inode;
  411. REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
  412. /* we need to copy it off.. */
  413. if (xinode->i_nlink > 1) {
  414. fput(fp);
  415. err = reiserfs_xattr_del(inode, name);
  416. if (err < 0)
  417. goto out;
  418. /* We just killed the old one, we're not replacing anymore */
  419. if (flags & XATTR_REPLACE)
  420. flags &= ~XATTR_REPLACE;
  421. goto open_file;
  422. }
  423. /* Resize it so we're ok to write there */
  424. newattrs.ia_size = buffer_size;
  425. newattrs.ia_valid = ATTR_SIZE | ATTR_CTIME;
  426. mutex_lock_nested(&xinode->i_mutex, I_MUTEX_XATTR);
  427. err = notify_change(fp->f_path.dentry, &newattrs);
  428. if (err)
  429. goto out_filp;
  430. mapping = xinode->i_mapping;
  431. while (buffer_pos < buffer_size || buffer_pos == 0) {
  432. size_t chunk;
  433. size_t skip = 0;
  434. size_t page_offset = (file_pos & (PAGE_CACHE_SIZE - 1));
  435. if (buffer_size - buffer_pos > PAGE_CACHE_SIZE)
  436. chunk = PAGE_CACHE_SIZE;
  437. else
  438. chunk = buffer_size - buffer_pos;
  439. page = reiserfs_get_page(xinode, file_pos >> PAGE_CACHE_SHIFT);
  440. if (IS_ERR(page)) {
  441. err = PTR_ERR(page);
  442. goto out_filp;
  443. }
  444. lock_page(page);
  445. data = page_address(page);
  446. if (file_pos == 0) {
  447. struct reiserfs_xattr_header *rxh;
  448. skip = file_pos = sizeof(struct reiserfs_xattr_header);
  449. if (chunk + skip > PAGE_CACHE_SIZE)
  450. chunk = PAGE_CACHE_SIZE - skip;
  451. rxh = (struct reiserfs_xattr_header *)data;
  452. rxh->h_magic = cpu_to_le32(REISERFS_XATTR_MAGIC);
  453. rxh->h_hash = cpu_to_le32(xahash);
  454. }
  455. err = reiserfs_prepare_write(fp, page, page_offset,
  456. page_offset + chunk + skip);
  457. if (!err) {
  458. if (buffer)
  459. memcpy(data + skip, buffer + buffer_pos, chunk);
  460. err =
  461. reiserfs_commit_write(fp, page, page_offset,
  462. page_offset + chunk +
  463. skip);
  464. }
  465. unlock_page(page);
  466. reiserfs_put_page(page);
  467. buffer_pos += chunk;
  468. file_pos += chunk;
  469. skip = 0;
  470. if (err || buffer_size == 0 || !buffer)
  471. break;
  472. }
  473. /* We can't mark the inode dirty if it's not hashed. This is the case
  474. * when we're inheriting the default ACL. If we dirty it, the inode
  475. * gets marked dirty, but won't (ever) make it onto the dirty list until
  476. * it's synced explicitly to clear I_DIRTY. This is bad. */
  477. if (!hlist_unhashed(&inode->i_hash)) {
  478. inode->i_ctime = CURRENT_TIME_SEC;
  479. mark_inode_dirty(inode);
  480. }
  481. out_filp:
  482. mutex_unlock(&xinode->i_mutex);
  483. fput(fp);
  484. out:
  485. return err;
  486. }
  487. /*
  488. * inode->i_mutex: down
  489. */
  490. int
  491. reiserfs_xattr_get(const struct inode *inode, const char *name, void *buffer,
  492. size_t buffer_size)
  493. {
  494. ssize_t err = 0;
  495. struct file *fp;
  496. size_t isize;
  497. size_t file_pos = 0;
  498. size_t buffer_pos = 0;
  499. struct page *page;
  500. struct inode *xinode;
  501. __u32 hash = 0;
  502. if (name == NULL)
  503. return -EINVAL;
  504. /* We can't have xattrs attached to v1 items since they don't have
  505. * generation numbers */
  506. if (get_inode_sd_version(inode) == STAT_DATA_V1)
  507. return -EOPNOTSUPP;
  508. fp = open_xa_file(inode, name, FL_READONLY);
  509. if (IS_ERR(fp)) {
  510. err = PTR_ERR(fp);
  511. goto out;
  512. }
  513. xinode = fp->f_path.dentry->d_inode;
  514. isize = xinode->i_size;
  515. REISERFS_I(inode)->i_flags |= i_has_xattr_dir;
  516. /* Just return the size needed */
  517. if (buffer == NULL) {
  518. err = isize - sizeof(struct reiserfs_xattr_header);
  519. goto out_dput;
  520. }
  521. if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) {
  522. err = -ERANGE;
  523. goto out_dput;
  524. }
  525. while (file_pos < isize) {
  526. size_t chunk;
  527. char *data;
  528. size_t skip = 0;
  529. if (isize - file_pos > PAGE_CACHE_SIZE)
  530. chunk = PAGE_CACHE_SIZE;
  531. else
  532. chunk = isize - file_pos;
  533. page = reiserfs_get_page(xinode, file_pos >> PAGE_CACHE_SHIFT);
  534. if (IS_ERR(page)) {
  535. err = PTR_ERR(page);
  536. goto out_dput;
  537. }
  538. lock_page(page);
  539. data = page_address(page);
  540. if (file_pos == 0) {
  541. struct reiserfs_xattr_header *rxh =
  542. (struct reiserfs_xattr_header *)data;
  543. skip = file_pos = sizeof(struct reiserfs_xattr_header);
  544. chunk -= skip;
  545. /* Magic doesn't match up.. */
  546. if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) {
  547. unlock_page(page);
  548. reiserfs_put_page(page);
  549. reiserfs_warning(inode->i_sb,
  550. "Invalid magic for xattr (%s) "
  551. "associated with %k", name,
  552. INODE_PKEY(inode));
  553. err = -EIO;
  554. goto out_dput;
  555. }
  556. hash = le32_to_cpu(rxh->h_hash);
  557. }
  558. memcpy(buffer + buffer_pos, data + skip, chunk);
  559. unlock_page(page);
  560. reiserfs_put_page(page);
  561. file_pos += chunk;
  562. buffer_pos += chunk;
  563. skip = 0;
  564. }
  565. err = isize - sizeof(struct reiserfs_xattr_header);
  566. if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) !=
  567. hash) {
  568. reiserfs_warning(inode->i_sb,
  569. "Invalid hash for xattr (%s) associated "
  570. "with %k", name, INODE_PKEY(inode));
  571. err = -EIO;
  572. }
  573. out_dput:
  574. fput(fp);
  575. out:
  576. return err;
  577. }
  578. static int
  579. __reiserfs_xattr_del(struct dentry *xadir, const char *name, int namelen)
  580. {
  581. struct dentry *dentry;
  582. struct inode *dir = xadir->d_inode;
  583. int err = 0;
  584. dentry = lookup_one_len(name, xadir, namelen);
  585. if (IS_ERR(dentry)) {
  586. err = PTR_ERR(dentry);
  587. goto out;
  588. } else if (!dentry->d_inode) {
  589. err = -ENODATA;
  590. goto out_file;
  591. }
  592. /* Skip directories.. */
  593. if (S_ISDIR(dentry->d_inode->i_mode))
  594. goto out_file;
  595. if (!is_reiserfs_priv_object(dentry->d_inode)) {
  596. reiserfs_warning(dir->i_sb, "OID %08x [%.*s/%.*s] doesn't have "
  597. "priv flag set [parent is %sset].",
  598. le32_to_cpu(INODE_PKEY(dentry->d_inode)->
  599. k_objectid), xadir->d_name.len,
  600. xadir->d_name.name, namelen, name,
  601. is_reiserfs_priv_object(xadir->
  602. d_inode) ? "" :
  603. "not ");
  604. dput(dentry);
  605. return -EIO;
  606. }
  607. err = dir->i_op->unlink(dir, dentry);
  608. if (!err)
  609. d_delete(dentry);
  610. out_file:
  611. dput(dentry);
  612. out:
  613. return err;
  614. }
  615. int reiserfs_xattr_del(struct inode *inode, const char *name)
  616. {
  617. struct dentry *dir;
  618. int err;
  619. dir = open_xa_dir(inode, FL_READONLY);
  620. if (IS_ERR(dir)) {
  621. err = PTR_ERR(dir);
  622. goto out;
  623. }
  624. err = __reiserfs_xattr_del(dir, name, strlen(name));
  625. dput(dir);
  626. if (!err) {
  627. inode->i_ctime = CURRENT_TIME_SEC;
  628. mark_inode_dirty(inode);
  629. }
  630. out:
  631. return err;
  632. }
  633. /* The following are side effects of other operations that aren't explicitly
  634. * modifying extended attributes. This includes operations such as permissions
  635. * or ownership changes, object deletions, etc. */
  636. static int
  637. reiserfs_delete_xattrs_filler(void *buf, const char *name, int namelen,
  638. loff_t offset, u64 ino, unsigned int d_type)
  639. {
  640. struct dentry *xadir = (struct dentry *)buf;
  641. return __reiserfs_xattr_del(xadir, name, namelen);
  642. }
  643. /* This is called w/ inode->i_mutex downed */
  644. int reiserfs_delete_xattrs(struct inode *inode)
  645. {
  646. struct file *fp;
  647. struct dentry *dir, *root;
  648. int err = 0;
  649. /* Skip out, an xattr has no xattrs associated with it */
  650. if (is_reiserfs_priv_object(inode) ||
  651. get_inode_sd_version(inode) == STAT_DATA_V1 ||
  652. !reiserfs_xattrs(inode->i_sb)) {
  653. return 0;
  654. }
  655. reiserfs_read_lock_xattrs(inode->i_sb);
  656. dir = open_xa_dir(inode, FL_READONLY);
  657. reiserfs_read_unlock_xattrs(inode->i_sb);
  658. if (IS_ERR(dir)) {
  659. err = PTR_ERR(dir);
  660. goto out;
  661. } else if (!dir->d_inode) {
  662. dput(dir);
  663. return 0;
  664. }
  665. fp = dentry_open(dir, NULL, O_RDWR);
  666. if (IS_ERR(fp)) {
  667. err = PTR_ERR(fp);
  668. /* dentry_open dputs the dentry if it fails */
  669. goto out;
  670. }
  671. lock_kernel();
  672. err = xattr_readdir(fp, reiserfs_delete_xattrs_filler, dir);
  673. if (err) {
  674. unlock_kernel();
  675. goto out_dir;
  676. }
  677. /* Leftovers besides . and .. -- that's not good. */
  678. if (dir->d_inode->i_nlink <= 2) {
  679. root = get_xa_root(inode->i_sb, XATTR_REPLACE);
  680. reiserfs_write_lock_xattrs(inode->i_sb);
  681. err = vfs_rmdir(root->d_inode, dir);
  682. reiserfs_write_unlock_xattrs(inode->i_sb);
  683. dput(root);
  684. } else {
  685. reiserfs_warning(inode->i_sb,
  686. "Couldn't remove all entries in directory");
  687. }
  688. unlock_kernel();
  689. out_dir:
  690. fput(fp);
  691. out:
  692. if (!err)
  693. REISERFS_I(inode)->i_flags =
  694. REISERFS_I(inode)->i_flags & ~i_has_xattr_dir;
  695. return err;
  696. }
  697. struct reiserfs_chown_buf {
  698. struct inode *inode;
  699. struct dentry *xadir;
  700. struct iattr *attrs;
  701. };
  702. /* XXX: If there is a better way to do this, I'd love to hear about it */
  703. static int
  704. reiserfs_chown_xattrs_filler(void *buf, const char *name, int namelen,
  705. loff_t offset, u64 ino, unsigned int d_type)
  706. {
  707. struct reiserfs_chown_buf *chown_buf = (struct reiserfs_chown_buf *)buf;
  708. struct dentry *xafile, *xadir = chown_buf->xadir;
  709. struct iattr *attrs = chown_buf->attrs;
  710. int err = 0;
  711. xafile = lookup_one_len(name, xadir, namelen);
  712. if (IS_ERR(xafile))
  713. return PTR_ERR(xafile);
  714. else if (!xafile->d_inode) {
  715. dput(xafile);
  716. return -ENODATA;
  717. }
  718. if (!S_ISDIR(xafile->d_inode->i_mode))
  719. err = notify_change(xafile, attrs);
  720. dput(xafile);
  721. return err;
  722. }
  723. int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
  724. {
  725. struct file *fp;
  726. struct dentry *dir;
  727. int err = 0;
  728. struct reiserfs_chown_buf buf;
  729. unsigned int ia_valid = attrs->ia_valid;
  730. /* Skip out, an xattr has no xattrs associated with it */
  731. if (is_reiserfs_priv_object(inode) ||
  732. get_inode_sd_version(inode) == STAT_DATA_V1 ||
  733. !reiserfs_xattrs(inode->i_sb)) {
  734. return 0;
  735. }
  736. reiserfs_read_lock_xattrs(inode->i_sb);
  737. dir = open_xa_dir(inode, FL_READONLY);
  738. reiserfs_read_unlock_xattrs(inode->i_sb);
  739. if (IS_ERR(dir)) {
  740. if (PTR_ERR(dir) != -ENODATA)
  741. err = PTR_ERR(dir);
  742. goto out;
  743. } else if (!dir->d_inode) {
  744. dput(dir);
  745. goto out;
  746. }
  747. fp = dentry_open(dir, NULL, O_RDWR);
  748. if (IS_ERR(fp)) {
  749. err = PTR_ERR(fp);
  750. /* dentry_open dputs the dentry if it fails */
  751. goto out;
  752. }
  753. lock_kernel();
  754. attrs->ia_valid &= (ATTR_UID | ATTR_GID | ATTR_CTIME);
  755. buf.xadir = dir;
  756. buf.attrs = attrs;
  757. buf.inode = inode;
  758. err = xattr_readdir(fp, reiserfs_chown_xattrs_filler, &buf);
  759. if (err) {
  760. unlock_kernel();
  761. goto out_dir;
  762. }
  763. err = notify_change(dir, attrs);
  764. unlock_kernel();
  765. out_dir:
  766. fput(fp);
  767. out:
  768. attrs->ia_valid = ia_valid;
  769. return err;
  770. }
  771. /* Actual operations that are exported to VFS-land */
  772. /*
  773. * Inode operation getxattr()
  774. * Preliminary locking: we down dentry->d_inode->i_mutex
  775. */
  776. ssize_t
  777. reiserfs_getxattr(struct dentry * dentry, const char *name, void *buffer,
  778. size_t size)
  779. {
  780. struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
  781. int err;
  782. if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
  783. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  784. return -EOPNOTSUPP;
  785. reiserfs_read_lock_xattr_i(dentry->d_inode);
  786. reiserfs_read_lock_xattrs(dentry->d_sb);
  787. err = xah->get(dentry->d_inode, name, buffer, size);
  788. reiserfs_read_unlock_xattrs(dentry->d_sb);
  789. reiserfs_read_unlock_xattr_i(dentry->d_inode);
  790. return err;
  791. }
  792. /*
  793. * Inode operation setxattr()
  794. *
  795. * dentry->d_inode->i_mutex down
  796. */
  797. int
  798. reiserfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  799. size_t size, int flags)
  800. {
  801. struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
  802. int err;
  803. int lock;
  804. if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
  805. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  806. return -EOPNOTSUPP;
  807. reiserfs_write_lock_xattr_i(dentry->d_inode);
  808. lock = !has_xattr_dir(dentry->d_inode);
  809. if (lock)
  810. reiserfs_write_lock_xattrs(dentry->d_sb);
  811. else
  812. reiserfs_read_lock_xattrs(dentry->d_sb);
  813. err = xah->set(dentry->d_inode, name, value, size, flags);
  814. if (lock)
  815. reiserfs_write_unlock_xattrs(dentry->d_sb);
  816. else
  817. reiserfs_read_unlock_xattrs(dentry->d_sb);
  818. reiserfs_write_unlock_xattr_i(dentry->d_inode);
  819. return err;
  820. }
  821. /*
  822. * Inode operation removexattr()
  823. *
  824. * dentry->d_inode->i_mutex down
  825. */
  826. int reiserfs_removexattr(struct dentry *dentry, const char *name)
  827. {
  828. int err;
  829. struct reiserfs_xattr_handler *xah = find_xattr_handler_prefix(name);
  830. if (!xah || !reiserfs_xattrs(dentry->d_sb) ||
  831. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  832. return -EOPNOTSUPP;
  833. reiserfs_write_lock_xattr_i(dentry->d_inode);
  834. reiserfs_read_lock_xattrs(dentry->d_sb);
  835. /* Deletion pre-operation */
  836. if (xah->del) {
  837. err = xah->del(dentry->d_inode, name);
  838. if (err)
  839. goto out;
  840. }
  841. err = reiserfs_xattr_del(dentry->d_inode, name);
  842. dentry->d_inode->i_ctime = CURRENT_TIME_SEC;
  843. mark_inode_dirty(dentry->d_inode);
  844. out:
  845. reiserfs_read_unlock_xattrs(dentry->d_sb);
  846. reiserfs_write_unlock_xattr_i(dentry->d_inode);
  847. return err;
  848. }
  849. /* This is what filldir will use:
  850. * r_pos will always contain the amount of space required for the entire
  851. * list. If r_pos becomes larger than r_size, we need more space and we
  852. * return an error indicating this. If r_pos is less than r_size, then we've
  853. * filled the buffer successfully and we return success */
  854. struct reiserfs_listxattr_buf {
  855. int r_pos;
  856. int r_size;
  857. char *r_buf;
  858. struct inode *r_inode;
  859. };
  860. static int
  861. reiserfs_listxattr_filler(void *buf, const char *name, int namelen,
  862. loff_t offset, u64 ino, unsigned int d_type)
  863. {
  864. struct reiserfs_listxattr_buf *b = (struct reiserfs_listxattr_buf *)buf;
  865. int len = 0;
  866. if (name[0] != '.'
  867. || (namelen != 1 && (name[1] != '.' || namelen != 2))) {
  868. struct reiserfs_xattr_handler *xah =
  869. find_xattr_handler_prefix(name);
  870. if (!xah)
  871. return 0; /* Unsupported xattr name, skip it */
  872. /* We call ->list() twice because the operation isn't required to just
  873. * return the name back - we want to make sure we have enough space */
  874. len += xah->list(b->r_inode, name, namelen, NULL);
  875. if (len) {
  876. if (b->r_pos + len + 1 <= b->r_size) {
  877. char *p = b->r_buf + b->r_pos;
  878. p += xah->list(b->r_inode, name, namelen, p);
  879. *p++ = '\0';
  880. }
  881. b->r_pos += len + 1;
  882. }
  883. }
  884. return 0;
  885. }
  886. /*
  887. * Inode operation listxattr()
  888. *
  889. * Preliminary locking: we down dentry->d_inode->i_mutex
  890. */
  891. ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
  892. {
  893. struct file *fp;
  894. struct dentry *dir;
  895. int err = 0;
  896. struct reiserfs_listxattr_buf buf;
  897. if (!dentry->d_inode)
  898. return -EINVAL;
  899. if (!reiserfs_xattrs(dentry->d_sb) ||
  900. get_inode_sd_version(dentry->d_inode) == STAT_DATA_V1)
  901. return -EOPNOTSUPP;
  902. reiserfs_read_lock_xattr_i(dentry->d_inode);
  903. reiserfs_read_lock_xattrs(dentry->d_sb);
  904. dir = open_xa_dir(dentry->d_inode, FL_READONLY);
  905. reiserfs_read_unlock_xattrs(dentry->d_sb);
  906. if (IS_ERR(dir)) {
  907. err = PTR_ERR(dir);
  908. if (err == -ENODATA)
  909. err = 0; /* Not an error if there aren't any xattrs */
  910. goto out;
  911. }
  912. fp = dentry_open(dir, NULL, O_RDWR);
  913. if (IS_ERR(fp)) {
  914. err = PTR_ERR(fp);
  915. /* dentry_open dputs the dentry if it fails */
  916. goto out;
  917. }
  918. buf.r_buf = buffer;
  919. buf.r_size = buffer ? size : 0;
  920. buf.r_pos = 0;
  921. buf.r_inode = dentry->d_inode;
  922. REISERFS_I(dentry->d_inode)->i_flags |= i_has_xattr_dir;
  923. err = xattr_readdir(fp, reiserfs_listxattr_filler, &buf);
  924. if (err)
  925. goto out_dir;
  926. if (buf.r_pos > buf.r_size && buffer != NULL)
  927. err = -ERANGE;
  928. else
  929. err = buf.r_pos;
  930. out_dir:
  931. fput(fp);
  932. out:
  933. reiserfs_read_unlock_xattr_i(dentry->d_inode);
  934. return err;
  935. }
  936. /* This is the implementation for the xattr plugin infrastructure */
  937. static struct list_head xattr_handlers = LIST_HEAD_INIT(xattr_handlers);
  938. static DEFINE_RWLOCK(handler_lock);
  939. static struct reiserfs_xattr_handler *find_xattr_handler_prefix(const char
  940. *prefix)
  941. {
  942. struct reiserfs_xattr_handler *xah = NULL;
  943. struct list_head *p;
  944. read_lock(&handler_lock);
  945. list_for_each(p, &xattr_handlers) {
  946. xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
  947. if (strncmp(xah->prefix, prefix, strlen(xah->prefix)) == 0)
  948. break;
  949. xah = NULL;
  950. }
  951. read_unlock(&handler_lock);
  952. return xah;
  953. }
  954. static void __unregister_handlers(void)
  955. {
  956. struct reiserfs_xattr_handler *xah;
  957. struct list_head *p, *tmp;
  958. list_for_each_safe(p, tmp, &xattr_handlers) {
  959. xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
  960. if (xah->exit)
  961. xah->exit();
  962. list_del_init(p);
  963. }
  964. INIT_LIST_HEAD(&xattr_handlers);
  965. }
  966. int __init reiserfs_xattr_register_handlers(void)
  967. {
  968. int err = 0;
  969. struct reiserfs_xattr_handler *xah;
  970. struct list_head *p;
  971. write_lock(&handler_lock);
  972. /* If we're already initialized, nothing to do */
  973. if (!list_empty(&xattr_handlers)) {
  974. write_unlock(&handler_lock);
  975. return 0;
  976. }
  977. /* Add the handlers */
  978. list_add_tail(&user_handler.handlers, &xattr_handlers);
  979. list_add_tail(&trusted_handler.handlers, &xattr_handlers);
  980. #ifdef CONFIG_REISERFS_FS_SECURITY
  981. list_add_tail(&security_handler.handlers, &xattr_handlers);
  982. #endif
  983. #ifdef CONFIG_REISERFS_FS_POSIX_ACL
  984. list_add_tail(&posix_acl_access_handler.handlers, &xattr_handlers);
  985. list_add_tail(&posix_acl_default_handler.handlers, &xattr_handlers);
  986. #endif
  987. /* Run initializers, if available */
  988. list_for_each(p, &xattr_handlers) {
  989. xah = list_entry(p, struct reiserfs_xattr_handler, handlers);
  990. if (xah->init) {
  991. err = xah->init();
  992. if (err) {
  993. list_del_init(p);
  994. break;
  995. }
  996. }
  997. }
  998. /* Clean up other handlers, if any failed */
  999. if (err)
  1000. __unregister_handlers();
  1001. write_unlock(&handler_lock);
  1002. return err;
  1003. }
  1004. void reiserfs_xattr_unregister_handlers(void)
  1005. {
  1006. write_lock(&handler_lock);
  1007. __unregister_handlers();
  1008. write_unlock(&handler_lock);
  1009. }
  1010. /* This will catch lookups from the fs root to .reiserfs_priv */
  1011. static int
  1012. xattr_lookup_poison(struct dentry *dentry, struct qstr *q1, struct qstr *name)
  1013. {
  1014. struct dentry *priv_root = REISERFS_SB(dentry->d_sb)->priv_root;
  1015. if (name->len == priv_root->d_name.len &&
  1016. name->hash == priv_root->d_name.hash &&
  1017. !memcmp(name->name, priv_root->d_name.name, name->len)) {
  1018. return -ENOENT;
  1019. } else if (q1->len == name->len &&
  1020. !memcmp(q1->name, name->name, name->len))
  1021. return 0;
  1022. return 1;
  1023. }
  1024. static struct dentry_operations xattr_lookup_poison_ops = {
  1025. .d_compare = xattr_lookup_poison,
  1026. };
  1027. /* We need to take a copy of the mount flags since things like
  1028. * MS_RDONLY don't get set until *after* we're called.
  1029. * mount_flags != mount_options */
  1030. int reiserfs_xattr_init(struct super_block *s, int mount_flags)
  1031. {
  1032. int err = 0;
  1033. /* We need generation numbers to ensure that the oid mapping is correct
  1034. * v3.5 filesystems don't have them. */
  1035. if (!old_format_only(s)) {
  1036. set_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
  1037. } else if (reiserfs_xattrs_optional(s)) {
  1038. /* Old format filesystem, but optional xattrs have been enabled
  1039. * at mount time. Error out. */
  1040. reiserfs_warning(s, "xattrs/ACLs not supported on pre v3.6 "
  1041. "format filesystem. Failing mount.");
  1042. err = -EOPNOTSUPP;
  1043. goto error;
  1044. } else {
  1045. /* Old format filesystem, but no optional xattrs have been enabled. This
  1046. * means we silently disable xattrs on the filesystem. */
  1047. clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
  1048. }
  1049. /* If we don't have the privroot located yet - go find it */
  1050. if (reiserfs_xattrs(s) && !REISERFS_SB(s)->priv_root) {
  1051. struct dentry *dentry;
  1052. dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
  1053. strlen(PRIVROOT_NAME));
  1054. if (!IS_ERR(dentry)) {
  1055. if (!(mount_flags & MS_RDONLY) && !dentry->d_inode) {
  1056. struct inode *inode = dentry->d_parent->d_inode;
  1057. mutex_lock_nested(&inode->i_mutex,
  1058. I_MUTEX_XATTR);
  1059. err = inode->i_op->mkdir(inode, dentry, 0700);
  1060. mutex_unlock(&inode->i_mutex);
  1061. if (err) {
  1062. dput(dentry);
  1063. dentry = NULL;
  1064. }
  1065. if (dentry && dentry->d_inode)
  1066. reiserfs_warning(s,
  1067. "Created %s on %s - reserved for "
  1068. "xattr storage.",
  1069. PRIVROOT_NAME,
  1070. reiserfs_bdevname
  1071. (inode->i_sb));
  1072. } else if (!dentry->d_inode) {
  1073. dput(dentry);
  1074. dentry = NULL;
  1075. }
  1076. } else
  1077. err = PTR_ERR(dentry);
  1078. if (!err && dentry) {
  1079. s->s_root->d_op = &xattr_lookup_poison_ops;
  1080. reiserfs_mark_inode_private(dentry->d_inode);
  1081. REISERFS_SB(s)->priv_root = dentry;
  1082. } else if (!(mount_flags & MS_RDONLY)) { /* xattrs are unavailable */
  1083. /* If we're read-only it just means that the dir hasn't been
  1084. * created. Not an error -- just no xattrs on the fs. We'll
  1085. * check again if we go read-write */
  1086. reiserfs_warning(s, "xattrs/ACLs enabled and couldn't "
  1087. "find/create .reiserfs_priv. Failing mount.");
  1088. err = -EOPNOTSUPP;
  1089. }
  1090. }
  1091. error:
  1092. /* This is only nonzero if there was an error initializing the xattr
  1093. * directory or if there is a condition where we don't support them. */
  1094. if (err) {
  1095. clear_bit(REISERFS_XATTRS, &(REISERFS_SB(s)->s_mount_opt));
  1096. clear_bit(REISERFS_XATTRS_USER, &(REISERFS_SB(s)->s_mount_opt));
  1097. clear_bit(REISERFS_POSIXACL, &(REISERFS_SB(s)->s_mount_opt));
  1098. }
  1099. /* The super_block MS_POSIXACL must mirror the (no)acl mount option. */
  1100. s->s_flags = s->s_flags & ~MS_POSIXACL;
  1101. if (reiserfs_posixacl(s))
  1102. s->s_flags |= MS_POSIXACL;
  1103. return err;
  1104. }
  1105. static int reiserfs_check_acl(struct inode *inode, int mask)
  1106. {
  1107. struct posix_acl *acl;
  1108. int error = -EAGAIN; /* do regular unix permission checks by default */
  1109. reiserfs_read_lock_xattr_i(inode);
  1110. reiserfs_read_lock_xattrs(inode->i_sb);
  1111. acl = reiserfs_get_acl(inode, ACL_TYPE_ACCESS);
  1112. reiserfs_read_unlock_xattrs(inode->i_sb);
  1113. reiserfs_read_unlock_xattr_i(inode);
  1114. if (acl) {
  1115. if (!IS_ERR(acl)) {
  1116. error = posix_acl_permission(inode, acl, mask);
  1117. posix_acl_release(acl);
  1118. } else if (PTR_ERR(acl) != -ENODATA)
  1119. error = PTR_ERR(acl);
  1120. }
  1121. return error;
  1122. }
  1123. int reiserfs_permission(struct inode *inode, int mask, struct nameidata *nd)
  1124. {
  1125. /*
  1126. * We don't do permission checks on the internal objects.
  1127. * Permissions are determined by the "owning" object.
  1128. */
  1129. if (is_reiserfs_priv_object(inode))
  1130. return 0;
  1131. /*
  1132. * Stat data v1 doesn't support ACLs.
  1133. */
  1134. if (get_inode_sd_version(inode) == STAT_DATA_V1)
  1135. return generic_permission(inode, mask, NULL);
  1136. else
  1137. return generic_permission(inode, mask, reiserfs_check_acl);
  1138. }