inode.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128
  1. /*
  2. * inode.c
  3. *
  4. * PURPOSE
  5. * Inode handling routines for the OSTA-UDF(tm) filesystem.
  6. *
  7. * COPYRIGHT
  8. * This file is distributed under the terms of the GNU General Public
  9. * License (GPL). Copies of the GPL can be obtained from:
  10. * ftp://prep.ai.mit.edu/pub/gnu/GPL
  11. * Each contributing author retains all rights to their own work.
  12. *
  13. * (C) 1998 Dave Boynton
  14. * (C) 1998-2004 Ben Fennema
  15. * (C) 1999-2000 Stelias Computing Inc
  16. *
  17. * HISTORY
  18. *
  19. * 10/04/98 dgb Added rudimentary directory functions
  20. * 10/07/98 Fully working udf_block_map! It works!
  21. * 11/25/98 bmap altered to better support extents
  22. * 12/06/98 blf partition support in udf_iget, udf_block_map
  23. * and udf_read_inode
  24. * 12/12/98 rewrote udf_block_map to handle next extents and descs across
  25. * block boundaries (which is not actually allowed)
  26. * 12/20/98 added support for strategy 4096
  27. * 03/07/99 rewrote udf_block_map (again)
  28. * New funcs, inode_bmap, udf_next_aext
  29. * 04/19/99 Support for writing device EA's for major/minor #
  30. */
  31. #include "udfdecl.h"
  32. #include <linux/mm.h>
  33. #include <linux/smp_lock.h>
  34. #include <linux/module.h>
  35. #include <linux/pagemap.h>
  36. #include <linux/buffer_head.h>
  37. #include <linux/writeback.h>
  38. #include <linux/slab.h>
  39. #include "udf_i.h"
  40. #include "udf_sb.h"
  41. MODULE_AUTHOR("Ben Fennema");
  42. MODULE_DESCRIPTION("Universal Disk Format Filesystem");
  43. MODULE_LICENSE("GPL");
  44. #define EXTENT_MERGE_SIZE 5
  45. static mode_t udf_convert_permissions(struct fileEntry *);
  46. static int udf_update_inode(struct inode *, int);
  47. static void udf_fill_inode(struct inode *, struct buffer_head *);
  48. static int udf_alloc_i_data(struct inode *inode, size_t size);
  49. static struct buffer_head *inode_getblk(struct inode *, sector_t, int *,
  50. long *, int *);
  51. static int8_t udf_insert_aext(struct inode *, struct extent_position,
  52. kernel_lb_addr, uint32_t);
  53. static void udf_split_extents(struct inode *, int *, int, int,
  54. kernel_long_ad[EXTENT_MERGE_SIZE], int *);
  55. static void udf_prealloc_extents(struct inode *, int, int,
  56. kernel_long_ad[EXTENT_MERGE_SIZE], int *);
  57. static void udf_merge_extents(struct inode *,
  58. kernel_long_ad[EXTENT_MERGE_SIZE], int *);
  59. static void udf_update_extents(struct inode *,
  60. kernel_long_ad[EXTENT_MERGE_SIZE], int, int,
  61. struct extent_position *);
  62. static int udf_get_block(struct inode *, sector_t, struct buffer_head *, int);
  63. /*
  64. * udf_delete_inode
  65. *
  66. * PURPOSE
  67. * Clean-up before the specified inode is destroyed.
  68. *
  69. * DESCRIPTION
  70. * This routine is called when the kernel destroys an inode structure
  71. * ie. when iput() finds i_count == 0.
  72. *
  73. * HISTORY
  74. * July 1, 1997 - Andrew E. Mileski
  75. * Written, tested, and released.
  76. *
  77. * Called at the last iput() if i_nlink is zero.
  78. */
  79. void udf_delete_inode(struct inode *inode)
  80. {
  81. truncate_inode_pages(&inode->i_data, 0);
  82. if (is_bad_inode(inode))
  83. goto no_delete;
  84. inode->i_size = 0;
  85. udf_truncate(inode);
  86. lock_kernel();
  87. udf_update_inode(inode, IS_SYNC(inode));
  88. udf_free_inode(inode);
  89. unlock_kernel();
  90. return;
  91. no_delete:
  92. clear_inode(inode);
  93. }
  94. /*
  95. * If we are going to release inode from memory, we discard preallocation and
  96. * truncate last inode extent to proper length. We could use drop_inode() but
  97. * it's called under inode_lock and thus we cannot mark inode dirty there. We
  98. * use clear_inode() but we have to make sure to write inode as it's not written
  99. * automatically.
  100. */
  101. void udf_clear_inode(struct inode *inode)
  102. {
  103. if (!(inode->i_sb->s_flags & MS_RDONLY)) {
  104. lock_kernel();
  105. /* Discard preallocation for directories, symlinks, etc. */
  106. udf_discard_prealloc(inode);
  107. udf_truncate_tail_extent(inode);
  108. unlock_kernel();
  109. write_inode_now(inode, 1);
  110. }
  111. kfree(UDF_I(inode)->i_ext.i_data);
  112. UDF_I(inode)->i_ext.i_data = NULL;
  113. }
  114. static int udf_writepage(struct page *page, struct writeback_control *wbc)
  115. {
  116. return block_write_full_page(page, udf_get_block, wbc);
  117. }
  118. static int udf_readpage(struct file *file, struct page *page)
  119. {
  120. return block_read_full_page(page, udf_get_block);
  121. }
  122. static int udf_write_begin(struct file *file, struct address_space *mapping,
  123. loff_t pos, unsigned len, unsigned flags,
  124. struct page **pagep, void **fsdata)
  125. {
  126. *pagep = NULL;
  127. return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
  128. udf_get_block);
  129. }
  130. static sector_t udf_bmap(struct address_space *mapping, sector_t block)
  131. {
  132. return generic_block_bmap(mapping, block, udf_get_block);
  133. }
  134. const struct address_space_operations udf_aops = {
  135. .readpage = udf_readpage,
  136. .writepage = udf_writepage,
  137. .sync_page = block_sync_page,
  138. .write_begin = udf_write_begin,
  139. .write_end = generic_write_end,
  140. .bmap = udf_bmap,
  141. };
  142. void udf_expand_file_adinicb(struct inode *inode, int newsize, int *err)
  143. {
  144. struct page *page;
  145. char *kaddr;
  146. struct writeback_control udf_wbc = {
  147. .sync_mode = WB_SYNC_NONE,
  148. .nr_to_write = 1,
  149. };
  150. /* from now on we have normal address_space methods */
  151. inode->i_data.a_ops = &udf_aops;
  152. if (!UDF_I(inode)->i_lenAlloc) {
  153. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  154. UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
  155. else
  156. UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_LONG;
  157. mark_inode_dirty(inode);
  158. return;
  159. }
  160. page = grab_cache_page(inode->i_mapping, 0);
  161. BUG_ON(!PageLocked(page));
  162. if (!PageUptodate(page)) {
  163. kaddr = kmap(page);
  164. memset(kaddr + UDF_I(inode)->i_lenAlloc, 0x00,
  165. PAGE_CACHE_SIZE - UDF_I(inode)->i_lenAlloc);
  166. memcpy(kaddr, UDF_I(inode)->i_ext.i_data +
  167. UDF_I(inode)->i_lenEAttr, UDF_I(inode)->i_lenAlloc);
  168. flush_dcache_page(page);
  169. SetPageUptodate(page);
  170. kunmap(page);
  171. }
  172. memset(UDF_I(inode)->i_ext.i_data + UDF_I(inode)->i_lenEAttr, 0x00,
  173. UDF_I(inode)->i_lenAlloc);
  174. UDF_I(inode)->i_lenAlloc = 0;
  175. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  176. UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_SHORT;
  177. else
  178. UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_LONG;
  179. inode->i_data.a_ops->writepage(page, &udf_wbc);
  180. page_cache_release(page);
  181. mark_inode_dirty(inode);
  182. }
  183. struct buffer_head *udf_expand_dir_adinicb(struct inode *inode, int *block,
  184. int *err)
  185. {
  186. int newblock;
  187. struct buffer_head *dbh = NULL;
  188. kernel_lb_addr eloc;
  189. uint32_t elen;
  190. uint8_t alloctype;
  191. struct extent_position epos;
  192. struct udf_fileident_bh sfibh, dfibh;
  193. loff_t f_pos = udf_ext0_offset(inode) >> 2;
  194. int size = (udf_ext0_offset(inode) + inode->i_size) >> 2;
  195. struct fileIdentDesc cfi, *sfi, *dfi;
  196. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_USE_SHORT_AD))
  197. alloctype = ICBTAG_FLAG_AD_SHORT;
  198. else
  199. alloctype = ICBTAG_FLAG_AD_LONG;
  200. if (!inode->i_size) {
  201. UDF_I(inode)->i_alloc_type = alloctype;
  202. mark_inode_dirty(inode);
  203. return NULL;
  204. }
  205. /* alloc block, and copy data to it */
  206. *block = udf_new_block(inode->i_sb, inode,
  207. UDF_I(inode)->i_location.partitionReferenceNum,
  208. UDF_I(inode)->i_location.logicalBlockNum, err);
  209. if (!(*block))
  210. return NULL;
  211. newblock = udf_get_pblock(inode->i_sb, *block,
  212. UDF_I(inode)->i_location.partitionReferenceNum,
  213. 0);
  214. if (!newblock)
  215. return NULL;
  216. dbh = udf_tgetblk(inode->i_sb, newblock);
  217. if (!dbh)
  218. return NULL;
  219. lock_buffer(dbh);
  220. memset(dbh->b_data, 0x00, inode->i_sb->s_blocksize);
  221. set_buffer_uptodate(dbh);
  222. unlock_buffer(dbh);
  223. mark_buffer_dirty_inode(dbh, inode);
  224. sfibh.soffset = sfibh.eoffset =
  225. (f_pos & ((inode->i_sb->s_blocksize - 1) >> 2)) << 2;
  226. sfibh.sbh = sfibh.ebh = NULL;
  227. dfibh.soffset = dfibh.eoffset = 0;
  228. dfibh.sbh = dfibh.ebh = dbh;
  229. while ((f_pos < size)) {
  230. UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
  231. sfi = udf_fileident_read(inode, &f_pos, &sfibh, &cfi, NULL,
  232. NULL, NULL, NULL);
  233. if (!sfi) {
  234. brelse(dbh);
  235. return NULL;
  236. }
  237. UDF_I(inode)->i_alloc_type = alloctype;
  238. sfi->descTag.tagLocation = cpu_to_le32(*block);
  239. dfibh.soffset = dfibh.eoffset;
  240. dfibh.eoffset += (sfibh.eoffset - sfibh.soffset);
  241. dfi = (struct fileIdentDesc *)(dbh->b_data + dfibh.soffset);
  242. if (udf_write_fi(inode, sfi, dfi, &dfibh, sfi->impUse,
  243. sfi->fileIdent +
  244. le16_to_cpu(sfi->lengthOfImpUse))) {
  245. UDF_I(inode)->i_alloc_type = ICBTAG_FLAG_AD_IN_ICB;
  246. brelse(dbh);
  247. return NULL;
  248. }
  249. }
  250. mark_buffer_dirty_inode(dbh, inode);
  251. memset(UDF_I(inode)->i_ext.i_data + UDF_I(inode)->i_lenEAttr, 0,
  252. UDF_I(inode)->i_lenAlloc);
  253. UDF_I(inode)->i_lenAlloc = 0;
  254. eloc.logicalBlockNum = *block;
  255. eloc.partitionReferenceNum =
  256. UDF_I(inode)->i_location.partitionReferenceNum;
  257. elen = inode->i_size;
  258. UDF_I(inode)->i_lenExtents = elen;
  259. epos.bh = NULL;
  260. epos.block = UDF_I(inode)->i_location;
  261. epos.offset = udf_file_entry_alloc_offset(inode);
  262. udf_add_aext(inode, &epos, eloc, elen, 0);
  263. /* UniqueID stuff */
  264. brelse(epos.bh);
  265. mark_inode_dirty(inode);
  266. return dbh;
  267. }
  268. static int udf_get_block(struct inode *inode, sector_t block,
  269. struct buffer_head *bh_result, int create)
  270. {
  271. int err, new;
  272. struct buffer_head *bh;
  273. unsigned long phys;
  274. if (!create) {
  275. phys = udf_block_map(inode, block);
  276. if (phys)
  277. map_bh(bh_result, inode->i_sb, phys);
  278. return 0;
  279. }
  280. err = -EIO;
  281. new = 0;
  282. bh = NULL;
  283. lock_kernel();
  284. if (block < 0)
  285. goto abort_negative;
  286. if (block == UDF_I(inode)->i_next_alloc_block + 1) {
  287. UDF_I(inode)->i_next_alloc_block++;
  288. UDF_I(inode)->i_next_alloc_goal++;
  289. }
  290. err = 0;
  291. bh = inode_getblk(inode, block, &err, &phys, &new);
  292. BUG_ON(bh);
  293. if (err)
  294. goto abort;
  295. BUG_ON(!phys);
  296. if (new)
  297. set_buffer_new(bh_result);
  298. map_bh(bh_result, inode->i_sb, phys);
  299. abort:
  300. unlock_kernel();
  301. return err;
  302. abort_negative:
  303. udf_warning(inode->i_sb, "udf_get_block", "block < 0");
  304. goto abort;
  305. }
  306. static struct buffer_head *udf_getblk(struct inode *inode, long block,
  307. int create, int *err)
  308. {
  309. struct buffer_head *bh;
  310. struct buffer_head dummy;
  311. dummy.b_state = 0;
  312. dummy.b_blocknr = -1000;
  313. *err = udf_get_block(inode, block, &dummy, create);
  314. if (!*err && buffer_mapped(&dummy)) {
  315. bh = sb_getblk(inode->i_sb, dummy.b_blocknr);
  316. if (buffer_new(&dummy)) {
  317. lock_buffer(bh);
  318. memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
  319. set_buffer_uptodate(bh);
  320. unlock_buffer(bh);
  321. mark_buffer_dirty_inode(bh, inode);
  322. }
  323. return bh;
  324. }
  325. return NULL;
  326. }
  327. /* Extend the file by 'blocks' blocks, return the number of extents added */
  328. int udf_extend_file(struct inode *inode, struct extent_position *last_pos,
  329. kernel_long_ad *last_ext, sector_t blocks)
  330. {
  331. sector_t add;
  332. int count = 0, fake = !(last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
  333. struct super_block *sb = inode->i_sb;
  334. kernel_lb_addr prealloc_loc = {};
  335. int prealloc_len = 0;
  336. /* The previous extent is fake and we should not extend by anything
  337. * - there's nothing to do... */
  338. if (!blocks && fake)
  339. return 0;
  340. /* Round the last extent up to a multiple of block size */
  341. if (last_ext->extLength & (sb->s_blocksize - 1)) {
  342. last_ext->extLength =
  343. (last_ext->extLength & UDF_EXTENT_FLAG_MASK) |
  344. (((last_ext->extLength & UDF_EXTENT_LENGTH_MASK) +
  345. sb->s_blocksize - 1) & ~(sb->s_blocksize - 1));
  346. UDF_I(inode)->i_lenExtents =
  347. (UDF_I(inode)->i_lenExtents + sb->s_blocksize - 1) &
  348. ~(sb->s_blocksize - 1);
  349. }
  350. /* Last extent are just preallocated blocks? */
  351. if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
  352. EXT_NOT_RECORDED_ALLOCATED) {
  353. /* Save the extent so that we can reattach it to the end */
  354. prealloc_loc = last_ext->extLocation;
  355. prealloc_len = last_ext->extLength;
  356. /* Mark the extent as a hole */
  357. last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  358. (last_ext->extLength & UDF_EXTENT_LENGTH_MASK);
  359. last_ext->extLocation.logicalBlockNum = 0;
  360. last_ext->extLocation.partitionReferenceNum = 0;
  361. }
  362. /* Can we merge with the previous extent? */
  363. if ((last_ext->extLength & UDF_EXTENT_FLAG_MASK) ==
  364. EXT_NOT_RECORDED_NOT_ALLOCATED) {
  365. add = ((1 << 30) - sb->s_blocksize -
  366. (last_ext->extLength & UDF_EXTENT_LENGTH_MASK)) >>
  367. sb->s_blocksize_bits;
  368. if (add > blocks)
  369. add = blocks;
  370. blocks -= add;
  371. last_ext->extLength += add << sb->s_blocksize_bits;
  372. }
  373. if (fake) {
  374. udf_add_aext(inode, last_pos, last_ext->extLocation,
  375. last_ext->extLength, 1);
  376. count++;
  377. } else
  378. udf_write_aext(inode, last_pos, last_ext->extLocation,
  379. last_ext->extLength, 1);
  380. /* Managed to do everything necessary? */
  381. if (!blocks)
  382. goto out;
  383. /* All further extents will be NOT_RECORDED_NOT_ALLOCATED */
  384. last_ext->extLocation.logicalBlockNum = 0;
  385. last_ext->extLocation.partitionReferenceNum = 0;
  386. add = (1 << (30-sb->s_blocksize_bits)) - 1;
  387. last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  388. (add << sb->s_blocksize_bits);
  389. /* Create enough extents to cover the whole hole */
  390. while (blocks > add) {
  391. blocks -= add;
  392. if (udf_add_aext(inode, last_pos, last_ext->extLocation,
  393. last_ext->extLength, 1) == -1)
  394. return -1;
  395. count++;
  396. }
  397. if (blocks) {
  398. last_ext->extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  399. (blocks << sb->s_blocksize_bits);
  400. if (udf_add_aext(inode, last_pos, last_ext->extLocation,
  401. last_ext->extLength, 1) == -1)
  402. return -1;
  403. count++;
  404. }
  405. out:
  406. /* Do we have some preallocated blocks saved? */
  407. if (prealloc_len) {
  408. if (udf_add_aext(inode, last_pos, prealloc_loc,
  409. prealloc_len, 1) == -1)
  410. return -1;
  411. last_ext->extLocation = prealloc_loc;
  412. last_ext->extLength = prealloc_len;
  413. count++;
  414. }
  415. /* last_pos should point to the last written extent... */
  416. if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
  417. last_pos->offset -= sizeof(short_ad);
  418. else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG)
  419. last_pos->offset -= sizeof(long_ad);
  420. else
  421. return -1;
  422. return count;
  423. }
  424. static struct buffer_head *inode_getblk(struct inode *inode, sector_t block,
  425. int *err, long *phys, int *new)
  426. {
  427. static sector_t last_block;
  428. struct buffer_head *result = NULL;
  429. kernel_long_ad laarr[EXTENT_MERGE_SIZE];
  430. struct extent_position prev_epos, cur_epos, next_epos;
  431. int count = 0, startnum = 0, endnum = 0;
  432. uint32_t elen = 0, tmpelen;
  433. kernel_lb_addr eloc, tmpeloc;
  434. int c = 1;
  435. loff_t lbcount = 0, b_off = 0;
  436. uint32_t newblocknum, newblock;
  437. sector_t offset = 0;
  438. int8_t etype;
  439. int goal = 0, pgoal = UDF_I(inode)->i_location.logicalBlockNum;
  440. int lastblock = 0;
  441. prev_epos.offset = udf_file_entry_alloc_offset(inode);
  442. prev_epos.block = UDF_I(inode)->i_location;
  443. prev_epos.bh = NULL;
  444. cur_epos = next_epos = prev_epos;
  445. b_off = (loff_t)block << inode->i_sb->s_blocksize_bits;
  446. /* find the extent which contains the block we are looking for.
  447. alternate between laarr[0] and laarr[1] for locations of the
  448. current extent, and the previous extent */
  449. do {
  450. if (prev_epos.bh != cur_epos.bh) {
  451. brelse(prev_epos.bh);
  452. get_bh(cur_epos.bh);
  453. prev_epos.bh = cur_epos.bh;
  454. }
  455. if (cur_epos.bh != next_epos.bh) {
  456. brelse(cur_epos.bh);
  457. get_bh(next_epos.bh);
  458. cur_epos.bh = next_epos.bh;
  459. }
  460. lbcount += elen;
  461. prev_epos.block = cur_epos.block;
  462. cur_epos.block = next_epos.block;
  463. prev_epos.offset = cur_epos.offset;
  464. cur_epos.offset = next_epos.offset;
  465. etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 1);
  466. if (etype == -1)
  467. break;
  468. c = !c;
  469. laarr[c].extLength = (etype << 30) | elen;
  470. laarr[c].extLocation = eloc;
  471. if (etype != (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
  472. pgoal = eloc.logicalBlockNum +
  473. ((elen + inode->i_sb->s_blocksize - 1) >>
  474. inode->i_sb->s_blocksize_bits);
  475. count++;
  476. } while (lbcount + elen <= b_off);
  477. b_off -= lbcount;
  478. offset = b_off >> inode->i_sb->s_blocksize_bits;
  479. /*
  480. * Move prev_epos and cur_epos into indirect extent if we are at
  481. * the pointer to it
  482. */
  483. udf_next_aext(inode, &prev_epos, &tmpeloc, &tmpelen, 0);
  484. udf_next_aext(inode, &cur_epos, &tmpeloc, &tmpelen, 0);
  485. /* if the extent is allocated and recorded, return the block
  486. if the extent is not a multiple of the blocksize, round up */
  487. if (etype == (EXT_RECORDED_ALLOCATED >> 30)) {
  488. if (elen & (inode->i_sb->s_blocksize - 1)) {
  489. elen = EXT_RECORDED_ALLOCATED |
  490. ((elen + inode->i_sb->s_blocksize - 1) &
  491. ~(inode->i_sb->s_blocksize - 1));
  492. etype = udf_write_aext(inode, &cur_epos, eloc, elen, 1);
  493. }
  494. brelse(prev_epos.bh);
  495. brelse(cur_epos.bh);
  496. brelse(next_epos.bh);
  497. newblock = udf_get_lb_pblock(inode->i_sb, eloc, offset);
  498. *phys = newblock;
  499. return NULL;
  500. }
  501. last_block = block;
  502. /* Are we beyond EOF? */
  503. if (etype == -1) {
  504. int ret;
  505. if (count) {
  506. if (c)
  507. laarr[0] = laarr[1];
  508. startnum = 1;
  509. } else {
  510. /* Create a fake extent when there's not one */
  511. memset(&laarr[0].extLocation, 0x00,
  512. sizeof(kernel_lb_addr));
  513. laarr[0].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED;
  514. /* Will udf_extend_file() create real extent from
  515. a fake one? */
  516. startnum = (offset > 0);
  517. }
  518. /* Create extents for the hole between EOF and offset */
  519. ret = udf_extend_file(inode, &prev_epos, laarr, offset);
  520. if (ret == -1) {
  521. brelse(prev_epos.bh);
  522. brelse(cur_epos.bh);
  523. brelse(next_epos.bh);
  524. /* We don't really know the error here so we just make
  525. * something up */
  526. *err = -ENOSPC;
  527. return NULL;
  528. }
  529. c = 0;
  530. offset = 0;
  531. count += ret;
  532. /* We are not covered by a preallocated extent? */
  533. if ((laarr[0].extLength & UDF_EXTENT_FLAG_MASK) !=
  534. EXT_NOT_RECORDED_ALLOCATED) {
  535. /* Is there any real extent? - otherwise we overwrite
  536. * the fake one... */
  537. if (count)
  538. c = !c;
  539. laarr[c].extLength = EXT_NOT_RECORDED_NOT_ALLOCATED |
  540. inode->i_sb->s_blocksize;
  541. memset(&laarr[c].extLocation, 0x00,
  542. sizeof(kernel_lb_addr));
  543. count++;
  544. endnum++;
  545. }
  546. endnum = c + 1;
  547. lastblock = 1;
  548. } else {
  549. endnum = startnum = ((count > 2) ? 2 : count);
  550. /* if the current extent is in position 0,
  551. swap it with the previous */
  552. if (!c && count != 1) {
  553. laarr[2] = laarr[0];
  554. laarr[0] = laarr[1];
  555. laarr[1] = laarr[2];
  556. c = 1;
  557. }
  558. /* if the current block is located in an extent,
  559. read the next extent */
  560. etype = udf_next_aext(inode, &next_epos, &eloc, &elen, 0);
  561. if (etype != -1) {
  562. laarr[c + 1].extLength = (etype << 30) | elen;
  563. laarr[c + 1].extLocation = eloc;
  564. count++;
  565. startnum++;
  566. endnum++;
  567. } else
  568. lastblock = 1;
  569. }
  570. /* if the current extent is not recorded but allocated, get the
  571. * block in the extent corresponding to the requested block */
  572. if ((laarr[c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30))
  573. newblocknum = laarr[c].extLocation.logicalBlockNum + offset;
  574. else { /* otherwise, allocate a new block */
  575. if (UDF_I(inode)->i_next_alloc_block == block)
  576. goal = UDF_I(inode)->i_next_alloc_goal;
  577. if (!goal) {
  578. if (!(goal = pgoal)) /* XXX: what was intended here? */
  579. goal = UDF_I(inode)->
  580. i_location.logicalBlockNum + 1;
  581. }
  582. newblocknum = udf_new_block(inode->i_sb, inode,
  583. UDF_I(inode)->i_location.partitionReferenceNum,
  584. goal, err);
  585. if (!newblocknum) {
  586. brelse(prev_epos.bh);
  587. *err = -ENOSPC;
  588. return NULL;
  589. }
  590. UDF_I(inode)->i_lenExtents += inode->i_sb->s_blocksize;
  591. }
  592. /* if the extent the requsted block is located in contains multiple
  593. * blocks, split the extent into at most three extents. blocks prior
  594. * to requested block, requested block, and blocks after requested
  595. * block */
  596. udf_split_extents(inode, &c, offset, newblocknum, laarr, &endnum);
  597. #ifdef UDF_PREALLOCATE
  598. /* preallocate blocks */
  599. udf_prealloc_extents(inode, c, lastblock, laarr, &endnum);
  600. #endif
  601. /* merge any continuous blocks in laarr */
  602. udf_merge_extents(inode, laarr, &endnum);
  603. /* write back the new extents, inserting new extents if the new number
  604. * of extents is greater than the old number, and deleting extents if
  605. * the new number of extents is less than the old number */
  606. udf_update_extents(inode, laarr, startnum, endnum, &prev_epos);
  607. brelse(prev_epos.bh);
  608. newblock = udf_get_pblock(inode->i_sb, newblocknum,
  609. UDF_I(inode)->i_location.partitionReferenceNum, 0);
  610. if (!newblock)
  611. return NULL;
  612. *phys = newblock;
  613. *err = 0;
  614. *new = 1;
  615. UDF_I(inode)->i_next_alloc_block = block;
  616. UDF_I(inode)->i_next_alloc_goal = newblocknum;
  617. inode->i_ctime = current_fs_time(inode->i_sb);
  618. if (IS_SYNC(inode))
  619. udf_sync_inode(inode);
  620. else
  621. mark_inode_dirty(inode);
  622. return result;
  623. }
  624. static void udf_split_extents(struct inode *inode, int *c, int offset,
  625. int newblocknum,
  626. kernel_long_ad laarr[EXTENT_MERGE_SIZE],
  627. int *endnum)
  628. {
  629. unsigned long blocksize = inode->i_sb->s_blocksize;
  630. unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
  631. if ((laarr[*c].extLength >> 30) == (EXT_NOT_RECORDED_ALLOCATED >> 30) ||
  632. (laarr[*c].extLength >> 30) ==
  633. (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
  634. int curr = *c;
  635. int blen = ((laarr[curr].extLength & UDF_EXTENT_LENGTH_MASK) +
  636. blocksize - 1) >> blocksize_bits;
  637. int8_t etype = (laarr[curr].extLength >> 30);
  638. if (blen == 1)
  639. ;
  640. else if (!offset || blen == offset + 1) {
  641. laarr[curr + 2] = laarr[curr + 1];
  642. laarr[curr + 1] = laarr[curr];
  643. } else {
  644. laarr[curr + 3] = laarr[curr + 1];
  645. laarr[curr + 2] = laarr[curr + 1] = laarr[curr];
  646. }
  647. if (offset) {
  648. if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
  649. udf_free_blocks(inode->i_sb, inode,
  650. laarr[curr].extLocation,
  651. 0, offset);
  652. laarr[curr].extLength =
  653. EXT_NOT_RECORDED_NOT_ALLOCATED |
  654. (offset << blocksize_bits);
  655. laarr[curr].extLocation.logicalBlockNum = 0;
  656. laarr[curr].extLocation.
  657. partitionReferenceNum = 0;
  658. } else
  659. laarr[curr].extLength = (etype << 30) |
  660. (offset << blocksize_bits);
  661. curr++;
  662. (*c)++;
  663. (*endnum)++;
  664. }
  665. laarr[curr].extLocation.logicalBlockNum = newblocknum;
  666. if (etype == (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))
  667. laarr[curr].extLocation.partitionReferenceNum =
  668. UDF_I(inode)->i_location.partitionReferenceNum;
  669. laarr[curr].extLength = EXT_RECORDED_ALLOCATED |
  670. blocksize;
  671. curr++;
  672. if (blen != offset + 1) {
  673. if (etype == (EXT_NOT_RECORDED_ALLOCATED >> 30))
  674. laarr[curr].extLocation.logicalBlockNum +=
  675. offset + 1;
  676. laarr[curr].extLength = (etype << 30) |
  677. ((blen - (offset + 1)) << blocksize_bits);
  678. curr++;
  679. (*endnum)++;
  680. }
  681. }
  682. }
  683. static void udf_prealloc_extents(struct inode *inode, int c, int lastblock,
  684. kernel_long_ad laarr[EXTENT_MERGE_SIZE],
  685. int *endnum)
  686. {
  687. int start, length = 0, currlength = 0, i;
  688. if (*endnum >= (c + 1)) {
  689. if (!lastblock)
  690. return;
  691. else
  692. start = c;
  693. } else {
  694. if ((laarr[c + 1].extLength >> 30) ==
  695. (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
  696. start = c + 1;
  697. length = currlength =
  698. (((laarr[c + 1].extLength &
  699. UDF_EXTENT_LENGTH_MASK) +
  700. inode->i_sb->s_blocksize - 1) >>
  701. inode->i_sb->s_blocksize_bits);
  702. } else
  703. start = c;
  704. }
  705. for (i = start + 1; i <= *endnum; i++) {
  706. if (i == *endnum) {
  707. if (lastblock)
  708. length += UDF_DEFAULT_PREALLOC_BLOCKS;
  709. } else if ((laarr[i].extLength >> 30) ==
  710. (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) {
  711. length += (((laarr[i].extLength &
  712. UDF_EXTENT_LENGTH_MASK) +
  713. inode->i_sb->s_blocksize - 1) >>
  714. inode->i_sb->s_blocksize_bits);
  715. } else
  716. break;
  717. }
  718. if (length) {
  719. int next = laarr[start].extLocation.logicalBlockNum +
  720. (((laarr[start].extLength & UDF_EXTENT_LENGTH_MASK) +
  721. inode->i_sb->s_blocksize - 1) >>
  722. inode->i_sb->s_blocksize_bits);
  723. int numalloc = udf_prealloc_blocks(inode->i_sb, inode,
  724. laarr[start].extLocation.partitionReferenceNum,
  725. next, (UDF_DEFAULT_PREALLOC_BLOCKS > length ?
  726. length : UDF_DEFAULT_PREALLOC_BLOCKS) -
  727. currlength);
  728. if (numalloc) {
  729. if (start == (c + 1))
  730. laarr[start].extLength +=
  731. (numalloc <<
  732. inode->i_sb->s_blocksize_bits);
  733. else {
  734. memmove(&laarr[c + 2], &laarr[c + 1],
  735. sizeof(long_ad) * (*endnum - (c + 1)));
  736. (*endnum)++;
  737. laarr[c + 1].extLocation.logicalBlockNum = next;
  738. laarr[c + 1].extLocation.partitionReferenceNum =
  739. laarr[c].extLocation.
  740. partitionReferenceNum;
  741. laarr[c + 1].extLength =
  742. EXT_NOT_RECORDED_ALLOCATED |
  743. (numalloc <<
  744. inode->i_sb->s_blocksize_bits);
  745. start = c + 1;
  746. }
  747. for (i = start + 1; numalloc && i < *endnum; i++) {
  748. int elen = ((laarr[i].extLength &
  749. UDF_EXTENT_LENGTH_MASK) +
  750. inode->i_sb->s_blocksize - 1) >>
  751. inode->i_sb->s_blocksize_bits;
  752. if (elen > numalloc) {
  753. laarr[i].extLength -=
  754. (numalloc <<
  755. inode->i_sb->s_blocksize_bits);
  756. numalloc = 0;
  757. } else {
  758. numalloc -= elen;
  759. if (*endnum > (i + 1))
  760. memmove(&laarr[i],
  761. &laarr[i + 1],
  762. sizeof(long_ad) *
  763. (*endnum - (i + 1)));
  764. i--;
  765. (*endnum)--;
  766. }
  767. }
  768. UDF_I(inode)->i_lenExtents +=
  769. numalloc << inode->i_sb->s_blocksize_bits;
  770. }
  771. }
  772. }
  773. static void udf_merge_extents(struct inode *inode,
  774. kernel_long_ad laarr[EXTENT_MERGE_SIZE],
  775. int *endnum)
  776. {
  777. int i;
  778. unsigned long blocksize = inode->i_sb->s_blocksize;
  779. unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
  780. for (i = 0; i < (*endnum - 1); i++) {
  781. kernel_long_ad *li /*l[i]*/ = &laarr[i];
  782. kernel_long_ad *lip1 /*l[i plus 1]*/ = &laarr[i + 1];
  783. if (((li->extLength >> 30) == (lip1->extLength >> 30)) &&
  784. (((li->extLength >> 30) ==
  785. (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30)) ||
  786. ((lip1->extLocation.logicalBlockNum -
  787. li->extLocation.logicalBlockNum) ==
  788. (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
  789. blocksize - 1) >> blocksize_bits)))) {
  790. if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
  791. (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
  792. blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
  793. lip1->extLength = (lip1->extLength -
  794. (li->extLength &
  795. UDF_EXTENT_LENGTH_MASK) +
  796. UDF_EXTENT_LENGTH_MASK) &
  797. ~(blocksize - 1);
  798. li->extLength = (li->extLength &
  799. UDF_EXTENT_FLAG_MASK) +
  800. (UDF_EXTENT_LENGTH_MASK + 1) -
  801. blocksize;
  802. lip1->extLocation.logicalBlockNum =
  803. li->extLocation.logicalBlockNum +
  804. ((li->extLength &
  805. UDF_EXTENT_LENGTH_MASK) >>
  806. blocksize_bits);
  807. } else {
  808. li->extLength = lip1->extLength +
  809. (((li->extLength &
  810. UDF_EXTENT_LENGTH_MASK) +
  811. blocksize - 1) & ~(blocksize - 1));
  812. if (*endnum > (i + 2))
  813. memmove(&laarr[i + 1], &laarr[i + 2],
  814. sizeof(long_ad) *
  815. (*endnum - (i + 2)));
  816. i--;
  817. (*endnum)--;
  818. }
  819. } else if (((li->extLength >> 30) ==
  820. (EXT_NOT_RECORDED_ALLOCATED >> 30)) &&
  821. ((lip1->extLength >> 30) ==
  822. (EXT_NOT_RECORDED_NOT_ALLOCATED >> 30))) {
  823. udf_free_blocks(inode->i_sb, inode, li->extLocation, 0,
  824. ((li->extLength &
  825. UDF_EXTENT_LENGTH_MASK) +
  826. blocksize - 1) >> blocksize_bits);
  827. li->extLocation.logicalBlockNum = 0;
  828. li->extLocation.partitionReferenceNum = 0;
  829. if (((li->extLength & UDF_EXTENT_LENGTH_MASK) +
  830. (lip1->extLength & UDF_EXTENT_LENGTH_MASK) +
  831. blocksize - 1) & ~UDF_EXTENT_LENGTH_MASK) {
  832. lip1->extLength = (lip1->extLength -
  833. (li->extLength &
  834. UDF_EXTENT_LENGTH_MASK) +
  835. UDF_EXTENT_LENGTH_MASK) &
  836. ~(blocksize - 1);
  837. li->extLength = (li->extLength &
  838. UDF_EXTENT_FLAG_MASK) +
  839. (UDF_EXTENT_LENGTH_MASK + 1) -
  840. blocksize;
  841. } else {
  842. li->extLength = lip1->extLength +
  843. (((li->extLength &
  844. UDF_EXTENT_LENGTH_MASK) +
  845. blocksize - 1) & ~(blocksize - 1));
  846. if (*endnum > (i + 2))
  847. memmove(&laarr[i + 1], &laarr[i + 2],
  848. sizeof(long_ad) *
  849. (*endnum - (i + 2)));
  850. i--;
  851. (*endnum)--;
  852. }
  853. } else if ((li->extLength >> 30) ==
  854. (EXT_NOT_RECORDED_ALLOCATED >> 30)) {
  855. udf_free_blocks(inode->i_sb, inode,
  856. li->extLocation, 0,
  857. ((li->extLength &
  858. UDF_EXTENT_LENGTH_MASK) +
  859. blocksize - 1) >> blocksize_bits);
  860. li->extLocation.logicalBlockNum = 0;
  861. li->extLocation.partitionReferenceNum = 0;
  862. li->extLength = (li->extLength &
  863. UDF_EXTENT_LENGTH_MASK) |
  864. EXT_NOT_RECORDED_NOT_ALLOCATED;
  865. }
  866. }
  867. }
  868. static void udf_update_extents(struct inode *inode,
  869. kernel_long_ad laarr[EXTENT_MERGE_SIZE],
  870. int startnum, int endnum,
  871. struct extent_position *epos)
  872. {
  873. int start = 0, i;
  874. kernel_lb_addr tmploc;
  875. uint32_t tmplen;
  876. if (startnum > endnum) {
  877. for (i = 0; i < (startnum - endnum); i++)
  878. udf_delete_aext(inode, *epos, laarr[i].extLocation,
  879. laarr[i].extLength);
  880. } else if (startnum < endnum) {
  881. for (i = 0; i < (endnum - startnum); i++) {
  882. udf_insert_aext(inode, *epos, laarr[i].extLocation,
  883. laarr[i].extLength);
  884. udf_next_aext(inode, epos, &laarr[i].extLocation,
  885. &laarr[i].extLength, 1);
  886. start++;
  887. }
  888. }
  889. for (i = start; i < endnum; i++) {
  890. udf_next_aext(inode, epos, &tmploc, &tmplen, 0);
  891. udf_write_aext(inode, epos, laarr[i].extLocation,
  892. laarr[i].extLength, 1);
  893. }
  894. }
  895. struct buffer_head *udf_bread(struct inode *inode, int block,
  896. int create, int *err)
  897. {
  898. struct buffer_head *bh = NULL;
  899. bh = udf_getblk(inode, block, create, err);
  900. if (!bh)
  901. return NULL;
  902. if (buffer_uptodate(bh))
  903. return bh;
  904. ll_rw_block(READ, 1, &bh);
  905. wait_on_buffer(bh);
  906. if (buffer_uptodate(bh))
  907. return bh;
  908. brelse(bh);
  909. *err = -EIO;
  910. return NULL;
  911. }
  912. void udf_truncate(struct inode *inode)
  913. {
  914. int offset;
  915. int err;
  916. if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
  917. S_ISLNK(inode->i_mode)))
  918. return;
  919. if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
  920. return;
  921. lock_kernel();
  922. if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB) {
  923. if (inode->i_sb->s_blocksize <
  924. (udf_file_entry_alloc_offset(inode) +
  925. inode->i_size)) {
  926. udf_expand_file_adinicb(inode, inode->i_size, &err);
  927. if (UDF_I(inode)->i_alloc_type ==
  928. ICBTAG_FLAG_AD_IN_ICB) {
  929. inode->i_size = UDF_I(inode)->i_lenAlloc;
  930. unlock_kernel();
  931. return;
  932. } else
  933. udf_truncate_extents(inode);
  934. } else {
  935. offset = inode->i_size & (inode->i_sb->s_blocksize - 1);
  936. memset(UDF_I(inode)->i_ext.i_data +
  937. UDF_I(inode)->i_lenEAttr + offset,
  938. 0x00, inode->i_sb->s_blocksize -
  939. offset - udf_file_entry_alloc_offset(inode));
  940. UDF_I(inode)->i_lenAlloc = inode->i_size;
  941. }
  942. } else {
  943. block_truncate_page(inode->i_mapping, inode->i_size,
  944. udf_get_block);
  945. udf_truncate_extents(inode);
  946. }
  947. inode->i_mtime = inode->i_ctime = current_fs_time(inode->i_sb);
  948. if (IS_SYNC(inode))
  949. udf_sync_inode(inode);
  950. else
  951. mark_inode_dirty(inode);
  952. unlock_kernel();
  953. }
  954. static void __udf_read_inode(struct inode *inode)
  955. {
  956. struct buffer_head *bh = NULL;
  957. struct fileEntry *fe;
  958. uint16_t ident;
  959. /*
  960. * Set defaults, but the inode is still incomplete!
  961. * Note: get_new_inode() sets the following on a new inode:
  962. * i_sb = sb
  963. * i_no = ino
  964. * i_flags = sb->s_flags
  965. * i_state = 0
  966. * clean_inode(): zero fills and sets
  967. * i_count = 1
  968. * i_nlink = 1
  969. * i_op = NULL;
  970. */
  971. bh = udf_read_ptagged(inode->i_sb, UDF_I(inode)->i_location, 0, &ident);
  972. if (!bh) {
  973. printk(KERN_ERR "udf: udf_read_inode(ino %ld) failed !bh\n",
  974. inode->i_ino);
  975. make_bad_inode(inode);
  976. return;
  977. }
  978. if (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE &&
  979. ident != TAG_IDENT_USE) {
  980. printk(KERN_ERR "udf: udf_read_inode(ino %ld) "
  981. "failed ident=%d\n", inode->i_ino, ident);
  982. brelse(bh);
  983. make_bad_inode(inode);
  984. return;
  985. }
  986. fe = (struct fileEntry *)bh->b_data;
  987. if (fe->icbTag.strategyType == cpu_to_le16(4096)) {
  988. struct buffer_head *ibh = NULL, *nbh = NULL;
  989. struct indirectEntry *ie;
  990. ibh = udf_read_ptagged(inode->i_sb, UDF_I(inode)->i_location, 1,
  991. &ident);
  992. if (ident == TAG_IDENT_IE) {
  993. if (ibh) {
  994. kernel_lb_addr loc;
  995. ie = (struct indirectEntry *)ibh->b_data;
  996. loc = lelb_to_cpu(ie->indirectICB.extLocation);
  997. if (ie->indirectICB.extLength &&
  998. (nbh = udf_read_ptagged(inode->i_sb, loc, 0,
  999. &ident))) {
  1000. if (ident == TAG_IDENT_FE ||
  1001. ident == TAG_IDENT_EFE) {
  1002. memcpy(&UDF_I(inode)->i_location,
  1003. &loc,
  1004. sizeof(kernel_lb_addr));
  1005. brelse(bh);
  1006. brelse(ibh);
  1007. brelse(nbh);
  1008. __udf_read_inode(inode);
  1009. return;
  1010. } else {
  1011. brelse(nbh);
  1012. brelse(ibh);
  1013. }
  1014. } else {
  1015. brelse(ibh);
  1016. }
  1017. }
  1018. } else {
  1019. brelse(ibh);
  1020. }
  1021. } else if (fe->icbTag.strategyType != cpu_to_le16(4)) {
  1022. printk(KERN_ERR "udf: unsupported strategy type: %d\n",
  1023. le16_to_cpu(fe->icbTag.strategyType));
  1024. brelse(bh);
  1025. make_bad_inode(inode);
  1026. return;
  1027. }
  1028. udf_fill_inode(inode, bh);
  1029. brelse(bh);
  1030. }
  1031. static void udf_fill_inode(struct inode *inode, struct buffer_head *bh)
  1032. {
  1033. struct fileEntry *fe;
  1034. struct extendedFileEntry *efe;
  1035. time_t convtime;
  1036. long convtime_usec;
  1037. int offset;
  1038. struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
  1039. fe = (struct fileEntry *)bh->b_data;
  1040. efe = (struct extendedFileEntry *)bh->b_data;
  1041. if (fe->icbTag.strategyType == cpu_to_le16(4))
  1042. UDF_I(inode)->i_strat4096 = 0;
  1043. else /* if (fe->icbTag.strategyType == cpu_to_le16(4096)) */
  1044. UDF_I(inode)->i_strat4096 = 1;
  1045. UDF_I(inode)->i_alloc_type = le16_to_cpu(fe->icbTag.flags) &
  1046. ICBTAG_FLAG_AD_MASK;
  1047. UDF_I(inode)->i_unique = 0;
  1048. UDF_I(inode)->i_lenEAttr = 0;
  1049. UDF_I(inode)->i_lenExtents = 0;
  1050. UDF_I(inode)->i_lenAlloc = 0;
  1051. UDF_I(inode)->i_next_alloc_block = 0;
  1052. UDF_I(inode)->i_next_alloc_goal = 0;
  1053. if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_EFE)) {
  1054. UDF_I(inode)->i_efe = 1;
  1055. UDF_I(inode)->i_use = 0;
  1056. if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
  1057. sizeof(struct extendedFileEntry))) {
  1058. make_bad_inode(inode);
  1059. return;
  1060. }
  1061. memcpy(UDF_I(inode)->i_ext.i_data,
  1062. bh->b_data + sizeof(struct extendedFileEntry),
  1063. inode->i_sb->s_blocksize -
  1064. sizeof(struct extendedFileEntry));
  1065. } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_FE)) {
  1066. UDF_I(inode)->i_efe = 0;
  1067. UDF_I(inode)->i_use = 0;
  1068. if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
  1069. sizeof(struct fileEntry))) {
  1070. make_bad_inode(inode);
  1071. return;
  1072. }
  1073. memcpy(UDF_I(inode)->i_ext.i_data,
  1074. bh->b_data + sizeof(struct fileEntry),
  1075. inode->i_sb->s_blocksize - sizeof(struct fileEntry));
  1076. } else if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_USE)) {
  1077. UDF_I(inode)->i_efe = 0;
  1078. UDF_I(inode)->i_use = 1;
  1079. UDF_I(inode)->i_lenAlloc = le32_to_cpu(
  1080. ((struct unallocSpaceEntry *)bh->b_data)->
  1081. lengthAllocDescs);
  1082. if (udf_alloc_i_data(inode, inode->i_sb->s_blocksize -
  1083. sizeof(struct unallocSpaceEntry))) {
  1084. make_bad_inode(inode);
  1085. return;
  1086. }
  1087. memcpy(UDF_I(inode)->i_ext.i_data,
  1088. bh->b_data + sizeof(struct unallocSpaceEntry),
  1089. inode->i_sb->s_blocksize -
  1090. sizeof(struct unallocSpaceEntry));
  1091. return;
  1092. }
  1093. inode->i_uid = le32_to_cpu(fe->uid);
  1094. if (inode->i_uid == -1 ||
  1095. UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_IGNORE) ||
  1096. UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_SET))
  1097. inode->i_uid = UDF_SB(inode->i_sb)->s_uid;
  1098. inode->i_gid = le32_to_cpu(fe->gid);
  1099. if (inode->i_gid == -1 ||
  1100. UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_IGNORE) ||
  1101. UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_SET))
  1102. inode->i_gid = UDF_SB(inode->i_sb)->s_gid;
  1103. inode->i_nlink = le16_to_cpu(fe->fileLinkCount);
  1104. if (!inode->i_nlink)
  1105. inode->i_nlink = 1;
  1106. inode->i_size = le64_to_cpu(fe->informationLength);
  1107. UDF_I(inode)->i_lenExtents = inode->i_size;
  1108. inode->i_mode = udf_convert_permissions(fe);
  1109. inode->i_mode &= ~UDF_SB(inode->i_sb)->s_umask;
  1110. if (UDF_I(inode)->i_efe == 0) {
  1111. inode->i_blocks = le64_to_cpu(fe->logicalBlocksRecorded) <<
  1112. (inode->i_sb->s_blocksize_bits - 9);
  1113. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1114. lets_to_cpu(fe->accessTime))) {
  1115. inode->i_atime.tv_sec = convtime;
  1116. inode->i_atime.tv_nsec = convtime_usec * 1000;
  1117. } else {
  1118. inode->i_atime = sbi->s_record_time;
  1119. }
  1120. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1121. lets_to_cpu(fe->modificationTime))) {
  1122. inode->i_mtime.tv_sec = convtime;
  1123. inode->i_mtime.tv_nsec = convtime_usec * 1000;
  1124. } else {
  1125. inode->i_mtime = sbi->s_record_time;
  1126. }
  1127. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1128. lets_to_cpu(fe->attrTime))) {
  1129. inode->i_ctime.tv_sec = convtime;
  1130. inode->i_ctime.tv_nsec = convtime_usec * 1000;
  1131. } else {
  1132. inode->i_ctime = sbi->s_record_time;
  1133. }
  1134. UDF_I(inode)->i_unique = le64_to_cpu(fe->uniqueID);
  1135. UDF_I(inode)->i_lenEAttr = le32_to_cpu(fe->lengthExtendedAttr);
  1136. UDF_I(inode)->i_lenAlloc = le32_to_cpu(fe->lengthAllocDescs);
  1137. offset = sizeof(struct fileEntry) + UDF_I(inode)->i_lenEAttr;
  1138. } else {
  1139. inode->i_blocks = le64_to_cpu(efe->logicalBlocksRecorded) <<
  1140. (inode->i_sb->s_blocksize_bits - 9);
  1141. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1142. lets_to_cpu(efe->accessTime))) {
  1143. inode->i_atime.tv_sec = convtime;
  1144. inode->i_atime.tv_nsec = convtime_usec * 1000;
  1145. } else {
  1146. inode->i_atime = sbi->s_record_time;
  1147. }
  1148. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1149. lets_to_cpu(efe->modificationTime))) {
  1150. inode->i_mtime.tv_sec = convtime;
  1151. inode->i_mtime.tv_nsec = convtime_usec * 1000;
  1152. } else {
  1153. inode->i_mtime = sbi->s_record_time;
  1154. }
  1155. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1156. lets_to_cpu(efe->createTime))) {
  1157. UDF_I(inode)->i_crtime.tv_sec = convtime;
  1158. UDF_I(inode)->i_crtime.tv_nsec = convtime_usec * 1000;
  1159. } else {
  1160. UDF_I(inode)->i_crtime = sbi->s_record_time;
  1161. }
  1162. if (udf_stamp_to_time(&convtime, &convtime_usec,
  1163. lets_to_cpu(efe->attrTime))) {
  1164. inode->i_ctime.tv_sec = convtime;
  1165. inode->i_ctime.tv_nsec = convtime_usec * 1000;
  1166. } else {
  1167. inode->i_ctime = sbi->s_record_time;
  1168. }
  1169. UDF_I(inode)->i_unique = le64_to_cpu(efe->uniqueID);
  1170. UDF_I(inode)->i_lenEAttr = le32_to_cpu(efe->lengthExtendedAttr);
  1171. UDF_I(inode)->i_lenAlloc = le32_to_cpu(efe->lengthAllocDescs);
  1172. offset = sizeof(struct extendedFileEntry) +
  1173. UDF_I(inode)->i_lenEAttr;
  1174. }
  1175. switch (fe->icbTag.fileType) {
  1176. case ICBTAG_FILE_TYPE_DIRECTORY:
  1177. inode->i_op = &udf_dir_inode_operations;
  1178. inode->i_fop = &udf_dir_operations;
  1179. inode->i_mode |= S_IFDIR;
  1180. inc_nlink(inode);
  1181. break;
  1182. case ICBTAG_FILE_TYPE_REALTIME:
  1183. case ICBTAG_FILE_TYPE_REGULAR:
  1184. case ICBTAG_FILE_TYPE_UNDEF:
  1185. if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_IN_ICB)
  1186. inode->i_data.a_ops = &udf_adinicb_aops;
  1187. else
  1188. inode->i_data.a_ops = &udf_aops;
  1189. inode->i_op = &udf_file_inode_operations;
  1190. inode->i_fop = &udf_file_operations;
  1191. inode->i_mode |= S_IFREG;
  1192. break;
  1193. case ICBTAG_FILE_TYPE_BLOCK:
  1194. inode->i_mode |= S_IFBLK;
  1195. break;
  1196. case ICBTAG_FILE_TYPE_CHAR:
  1197. inode->i_mode |= S_IFCHR;
  1198. break;
  1199. case ICBTAG_FILE_TYPE_FIFO:
  1200. init_special_inode(inode, inode->i_mode | S_IFIFO, 0);
  1201. break;
  1202. case ICBTAG_FILE_TYPE_SOCKET:
  1203. init_special_inode(inode, inode->i_mode | S_IFSOCK, 0);
  1204. break;
  1205. case ICBTAG_FILE_TYPE_SYMLINK:
  1206. inode->i_data.a_ops = &udf_symlink_aops;
  1207. inode->i_op = &page_symlink_inode_operations;
  1208. inode->i_mode = S_IFLNK | S_IRWXUGO;
  1209. break;
  1210. default:
  1211. printk(KERN_ERR "udf: udf_fill_inode(ino %ld) failed unknown "
  1212. "file type=%d\n", inode->i_ino,
  1213. fe->icbTag.fileType);
  1214. make_bad_inode(inode);
  1215. return;
  1216. }
  1217. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
  1218. struct deviceSpec *dsea =
  1219. (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
  1220. if (dsea) {
  1221. init_special_inode(inode, inode->i_mode,
  1222. MKDEV(le32_to_cpu(dsea->majorDeviceIdent),
  1223. le32_to_cpu(dsea->minorDeviceIdent)));
  1224. /* Developer ID ??? */
  1225. } else
  1226. make_bad_inode(inode);
  1227. }
  1228. }
  1229. static int udf_alloc_i_data(struct inode *inode, size_t size)
  1230. {
  1231. UDF_I(inode)->i_ext.i_data = kmalloc(size, GFP_KERNEL);
  1232. if (!UDF_I(inode)->i_ext.i_data) {
  1233. printk(KERN_ERR "udf:udf_alloc_i_data (ino %ld) "
  1234. "no free memory\n", inode->i_ino);
  1235. return -ENOMEM;
  1236. }
  1237. return 0;
  1238. }
  1239. static mode_t udf_convert_permissions(struct fileEntry *fe)
  1240. {
  1241. mode_t mode;
  1242. uint32_t permissions;
  1243. uint32_t flags;
  1244. permissions = le32_to_cpu(fe->permissions);
  1245. flags = le16_to_cpu(fe->icbTag.flags);
  1246. mode = ((permissions) & S_IRWXO) |
  1247. ((permissions >> 2) & S_IRWXG) |
  1248. ((permissions >> 4) & S_IRWXU) |
  1249. ((flags & ICBTAG_FLAG_SETUID) ? S_ISUID : 0) |
  1250. ((flags & ICBTAG_FLAG_SETGID) ? S_ISGID : 0) |
  1251. ((flags & ICBTAG_FLAG_STICKY) ? S_ISVTX : 0);
  1252. return mode;
  1253. }
  1254. /*
  1255. * udf_write_inode
  1256. *
  1257. * PURPOSE
  1258. * Write out the specified inode.
  1259. *
  1260. * DESCRIPTION
  1261. * This routine is called whenever an inode is synced.
  1262. * Currently this routine is just a placeholder.
  1263. *
  1264. * HISTORY
  1265. * July 1, 1997 - Andrew E. Mileski
  1266. * Written, tested, and released.
  1267. */
  1268. int udf_write_inode(struct inode *inode, int sync)
  1269. {
  1270. int ret;
  1271. lock_kernel();
  1272. ret = udf_update_inode(inode, sync);
  1273. unlock_kernel();
  1274. return ret;
  1275. }
  1276. int udf_sync_inode(struct inode *inode)
  1277. {
  1278. return udf_update_inode(inode, 1);
  1279. }
  1280. static int udf_update_inode(struct inode *inode, int do_sync)
  1281. {
  1282. struct buffer_head *bh = NULL;
  1283. struct fileEntry *fe;
  1284. struct extendedFileEntry *efe;
  1285. uint32_t udfperms;
  1286. uint16_t icbflags;
  1287. uint16_t crclen;
  1288. kernel_timestamp cpu_time;
  1289. int err = 0;
  1290. struct udf_sb_info *sbi = UDF_SB(inode->i_sb);
  1291. unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
  1292. bh = udf_tread(inode->i_sb,
  1293. udf_get_lb_pblock(inode->i_sb,
  1294. UDF_I(inode)->i_location, 0));
  1295. if (!bh) {
  1296. udf_debug("bread failure\n");
  1297. return -EIO;
  1298. }
  1299. memset(bh->b_data, 0x00, inode->i_sb->s_blocksize);
  1300. fe = (struct fileEntry *)bh->b_data;
  1301. efe = (struct extendedFileEntry *)bh->b_data;
  1302. if (fe->descTag.tagIdent == cpu_to_le16(TAG_IDENT_USE)) {
  1303. struct unallocSpaceEntry *use =
  1304. (struct unallocSpaceEntry *)bh->b_data;
  1305. use->lengthAllocDescs = cpu_to_le32(UDF_I(inode)->i_lenAlloc);
  1306. memcpy(bh->b_data + sizeof(struct unallocSpaceEntry),
  1307. UDF_I(inode)->i_ext.i_data, inode->i_sb->s_blocksize -
  1308. sizeof(struct unallocSpaceEntry));
  1309. crclen = sizeof(struct unallocSpaceEntry) +
  1310. UDF_I(inode)->i_lenAlloc - sizeof(tag);
  1311. use->descTag.tagLocation = cpu_to_le32(
  1312. UDF_I(inode)->i_location.
  1313. logicalBlockNum);
  1314. use->descTag.descCRCLength = cpu_to_le16(crclen);
  1315. use->descTag.descCRC = cpu_to_le16(udf_crc((char *)use +
  1316. sizeof(tag), crclen,
  1317. 0));
  1318. use->descTag.tagChecksum = udf_tag_checksum(&use->descTag);
  1319. mark_buffer_dirty(bh);
  1320. brelse(bh);
  1321. return err;
  1322. }
  1323. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_UID_FORGET))
  1324. fe->uid = cpu_to_le32(-1);
  1325. else
  1326. fe->uid = cpu_to_le32(inode->i_uid);
  1327. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_GID_FORGET))
  1328. fe->gid = cpu_to_le32(-1);
  1329. else
  1330. fe->gid = cpu_to_le32(inode->i_gid);
  1331. udfperms = ((inode->i_mode & S_IRWXO)) |
  1332. ((inode->i_mode & S_IRWXG) << 2) |
  1333. ((inode->i_mode & S_IRWXU) << 4);
  1334. udfperms |= (le32_to_cpu(fe->permissions) &
  1335. (FE_PERM_O_DELETE | FE_PERM_O_CHATTR |
  1336. FE_PERM_G_DELETE | FE_PERM_G_CHATTR |
  1337. FE_PERM_U_DELETE | FE_PERM_U_CHATTR));
  1338. fe->permissions = cpu_to_le32(udfperms);
  1339. if (S_ISDIR(inode->i_mode))
  1340. fe->fileLinkCount = cpu_to_le16(inode->i_nlink - 1);
  1341. else
  1342. fe->fileLinkCount = cpu_to_le16(inode->i_nlink);
  1343. fe->informationLength = cpu_to_le64(inode->i_size);
  1344. if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
  1345. regid *eid;
  1346. struct deviceSpec *dsea =
  1347. (struct deviceSpec *)udf_get_extendedattr(inode, 12, 1);
  1348. if (!dsea) {
  1349. dsea = (struct deviceSpec *)
  1350. udf_add_extendedattr(inode,
  1351. sizeof(struct deviceSpec) +
  1352. sizeof(regid), 12, 0x3);
  1353. dsea->attrType = cpu_to_le32(12);
  1354. dsea->attrSubtype = 1;
  1355. dsea->attrLength = cpu_to_le32(
  1356. sizeof(struct deviceSpec) +
  1357. sizeof(regid));
  1358. dsea->impUseLength = cpu_to_le32(sizeof(regid));
  1359. }
  1360. eid = (regid *)dsea->impUse;
  1361. memset(eid, 0, sizeof(regid));
  1362. strcpy(eid->ident, UDF_ID_DEVELOPER);
  1363. eid->identSuffix[0] = UDF_OS_CLASS_UNIX;
  1364. eid->identSuffix[1] = UDF_OS_ID_LINUX;
  1365. dsea->majorDeviceIdent = cpu_to_le32(imajor(inode));
  1366. dsea->minorDeviceIdent = cpu_to_le32(iminor(inode));
  1367. }
  1368. if (UDF_I(inode)->i_efe == 0) {
  1369. memcpy(bh->b_data + sizeof(struct fileEntry),
  1370. UDF_I(inode)->i_ext.i_data,
  1371. inode->i_sb->s_blocksize - sizeof(struct fileEntry));
  1372. fe->logicalBlocksRecorded = cpu_to_le64(
  1373. (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
  1374. (blocksize_bits - 9));
  1375. if (udf_time_to_stamp(&cpu_time, inode->i_atime))
  1376. fe->accessTime = cpu_to_lets(cpu_time);
  1377. if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
  1378. fe->modificationTime = cpu_to_lets(cpu_time);
  1379. if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
  1380. fe->attrTime = cpu_to_lets(cpu_time);
  1381. memset(&(fe->impIdent), 0, sizeof(regid));
  1382. strcpy(fe->impIdent.ident, UDF_ID_DEVELOPER);
  1383. fe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1384. fe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1385. fe->uniqueID = cpu_to_le64(UDF_I(inode)->i_unique);
  1386. fe->lengthExtendedAttr = cpu_to_le32(UDF_I(inode)->i_lenEAttr);
  1387. fe->lengthAllocDescs = cpu_to_le32(UDF_I(inode)->i_lenAlloc);
  1388. fe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_FE);
  1389. crclen = sizeof(struct fileEntry);
  1390. } else {
  1391. memcpy(bh->b_data + sizeof(struct extendedFileEntry),
  1392. UDF_I(inode)->i_ext.i_data,
  1393. inode->i_sb->s_blocksize -
  1394. sizeof(struct extendedFileEntry));
  1395. efe->objectSize = cpu_to_le64(inode->i_size);
  1396. efe->logicalBlocksRecorded = cpu_to_le64(
  1397. (inode->i_blocks + (1 << (blocksize_bits - 9)) - 1) >>
  1398. (blocksize_bits - 9));
  1399. if (UDF_I(inode)->i_crtime.tv_sec > inode->i_atime.tv_sec ||
  1400. (UDF_I(inode)->i_crtime.tv_sec == inode->i_atime.tv_sec &&
  1401. UDF_I(inode)->i_crtime.tv_nsec > inode->i_atime.tv_nsec))
  1402. UDF_I(inode)->i_crtime = inode->i_atime;
  1403. if (UDF_I(inode)->i_crtime.tv_sec > inode->i_mtime.tv_sec ||
  1404. (UDF_I(inode)->i_crtime.tv_sec == inode->i_mtime.tv_sec &&
  1405. UDF_I(inode)->i_crtime.tv_nsec > inode->i_mtime.tv_nsec))
  1406. UDF_I(inode)->i_crtime = inode->i_mtime;
  1407. if (UDF_I(inode)->i_crtime.tv_sec > inode->i_ctime.tv_sec ||
  1408. (UDF_I(inode)->i_crtime.tv_sec == inode->i_ctime.tv_sec &&
  1409. UDF_I(inode)->i_crtime.tv_nsec > inode->i_ctime.tv_nsec))
  1410. UDF_I(inode)->i_crtime = inode->i_ctime;
  1411. if (udf_time_to_stamp(&cpu_time, inode->i_atime))
  1412. efe->accessTime = cpu_to_lets(cpu_time);
  1413. if (udf_time_to_stamp(&cpu_time, inode->i_mtime))
  1414. efe->modificationTime = cpu_to_lets(cpu_time);
  1415. if (udf_time_to_stamp(&cpu_time, UDF_I(inode)->i_crtime))
  1416. efe->createTime = cpu_to_lets(cpu_time);
  1417. if (udf_time_to_stamp(&cpu_time, inode->i_ctime))
  1418. efe->attrTime = cpu_to_lets(cpu_time);
  1419. memset(&(efe->impIdent), 0, sizeof(regid));
  1420. strcpy(efe->impIdent.ident, UDF_ID_DEVELOPER);
  1421. efe->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1422. efe->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1423. efe->uniqueID = cpu_to_le64(UDF_I(inode)->i_unique);
  1424. efe->lengthExtendedAttr = cpu_to_le32(UDF_I(inode)->i_lenEAttr);
  1425. efe->lengthAllocDescs = cpu_to_le32(UDF_I(inode)->i_lenAlloc);
  1426. efe->descTag.tagIdent = cpu_to_le16(TAG_IDENT_EFE);
  1427. crclen = sizeof(struct extendedFileEntry);
  1428. }
  1429. if (UDF_I(inode)->i_strat4096) {
  1430. fe->icbTag.strategyType = cpu_to_le16(4096);
  1431. fe->icbTag.strategyParameter = cpu_to_le16(1);
  1432. fe->icbTag.numEntries = cpu_to_le16(2);
  1433. } else {
  1434. fe->icbTag.strategyType = cpu_to_le16(4);
  1435. fe->icbTag.numEntries = cpu_to_le16(1);
  1436. }
  1437. if (S_ISDIR(inode->i_mode))
  1438. fe->icbTag.fileType = ICBTAG_FILE_TYPE_DIRECTORY;
  1439. else if (S_ISREG(inode->i_mode))
  1440. fe->icbTag.fileType = ICBTAG_FILE_TYPE_REGULAR;
  1441. else if (S_ISLNK(inode->i_mode))
  1442. fe->icbTag.fileType = ICBTAG_FILE_TYPE_SYMLINK;
  1443. else if (S_ISBLK(inode->i_mode))
  1444. fe->icbTag.fileType = ICBTAG_FILE_TYPE_BLOCK;
  1445. else if (S_ISCHR(inode->i_mode))
  1446. fe->icbTag.fileType = ICBTAG_FILE_TYPE_CHAR;
  1447. else if (S_ISFIFO(inode->i_mode))
  1448. fe->icbTag.fileType = ICBTAG_FILE_TYPE_FIFO;
  1449. else if (S_ISSOCK(inode->i_mode))
  1450. fe->icbTag.fileType = ICBTAG_FILE_TYPE_SOCKET;
  1451. icbflags = UDF_I(inode)->i_alloc_type |
  1452. ((inode->i_mode & S_ISUID) ? ICBTAG_FLAG_SETUID : 0) |
  1453. ((inode->i_mode & S_ISGID) ? ICBTAG_FLAG_SETGID : 0) |
  1454. ((inode->i_mode & S_ISVTX) ? ICBTAG_FLAG_STICKY : 0) |
  1455. (le16_to_cpu(fe->icbTag.flags) &
  1456. ~(ICBTAG_FLAG_AD_MASK | ICBTAG_FLAG_SETUID |
  1457. ICBTAG_FLAG_SETGID | ICBTAG_FLAG_STICKY));
  1458. fe->icbTag.flags = cpu_to_le16(icbflags);
  1459. if (sbi->s_udfrev >= 0x0200)
  1460. fe->descTag.descVersion = cpu_to_le16(3);
  1461. else
  1462. fe->descTag.descVersion = cpu_to_le16(2);
  1463. fe->descTag.tagSerialNum = cpu_to_le16(sbi->s_serial_number);
  1464. fe->descTag.tagLocation = cpu_to_le32(
  1465. UDF_I(inode)->i_location.logicalBlockNum);
  1466. crclen += UDF_I(inode)->i_lenEAttr + UDF_I(inode)->i_lenAlloc -
  1467. sizeof(tag);
  1468. fe->descTag.descCRCLength = cpu_to_le16(crclen);
  1469. fe->descTag.descCRC = cpu_to_le16(udf_crc((char *)fe + sizeof(tag),
  1470. crclen, 0));
  1471. fe->descTag.tagChecksum = udf_tag_checksum(&fe->descTag);
  1472. /* write the data blocks */
  1473. mark_buffer_dirty(bh);
  1474. if (do_sync) {
  1475. sync_dirty_buffer(bh);
  1476. if (buffer_req(bh) && !buffer_uptodate(bh)) {
  1477. printk(KERN_WARNING "IO error syncing udf inode "
  1478. "[%s:%08lx]\n", inode->i_sb->s_id,
  1479. inode->i_ino);
  1480. err = -EIO;
  1481. }
  1482. }
  1483. brelse(bh);
  1484. return err;
  1485. }
  1486. struct inode *udf_iget(struct super_block *sb, kernel_lb_addr ino)
  1487. {
  1488. unsigned long block = udf_get_lb_pblock(sb, ino, 0);
  1489. struct inode *inode = iget_locked(sb, block);
  1490. if (!inode)
  1491. return NULL;
  1492. if (inode->i_state & I_NEW) {
  1493. memcpy(&UDF_I(inode)->i_location, &ino, sizeof(kernel_lb_addr));
  1494. __udf_read_inode(inode);
  1495. unlock_new_inode(inode);
  1496. }
  1497. if (is_bad_inode(inode))
  1498. goto out_iput;
  1499. if (ino.logicalBlockNum >= UDF_SB(sb)->
  1500. s_partmaps[ino.partitionReferenceNum].s_partition_len) {
  1501. udf_debug("block=%d, partition=%d out of range\n",
  1502. ino.logicalBlockNum, ino.partitionReferenceNum);
  1503. make_bad_inode(inode);
  1504. goto out_iput;
  1505. }
  1506. return inode;
  1507. out_iput:
  1508. iput(inode);
  1509. return NULL;
  1510. }
  1511. int8_t udf_add_aext(struct inode *inode, struct extent_position *epos,
  1512. kernel_lb_addr eloc, uint32_t elen, int inc)
  1513. {
  1514. int adsize;
  1515. short_ad *sad = NULL;
  1516. long_ad *lad = NULL;
  1517. struct allocExtDesc *aed;
  1518. int8_t etype;
  1519. uint8_t *ptr;
  1520. if (!epos->bh)
  1521. ptr = UDF_I(inode)->i_ext.i_data + epos->offset -
  1522. udf_file_entry_alloc_offset(inode) +
  1523. UDF_I(inode)->i_lenEAttr;
  1524. else
  1525. ptr = epos->bh->b_data + epos->offset;
  1526. if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
  1527. adsize = sizeof(short_ad);
  1528. else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG)
  1529. adsize = sizeof(long_ad);
  1530. else
  1531. return -1;
  1532. if (epos->offset + (2 * adsize) > inode->i_sb->s_blocksize) {
  1533. char *sptr, *dptr;
  1534. struct buffer_head *nbh;
  1535. int err, loffset;
  1536. kernel_lb_addr obloc = epos->block;
  1537. epos->block.logicalBlockNum = udf_new_block(inode->i_sb, NULL,
  1538. obloc.partitionReferenceNum,
  1539. obloc.logicalBlockNum, &err);
  1540. if (!epos->block.logicalBlockNum)
  1541. return -1;
  1542. nbh = udf_tgetblk(inode->i_sb, udf_get_lb_pblock(inode->i_sb,
  1543. epos->block,
  1544. 0));
  1545. if (!nbh)
  1546. return -1;
  1547. lock_buffer(nbh);
  1548. memset(nbh->b_data, 0x00, inode->i_sb->s_blocksize);
  1549. set_buffer_uptodate(nbh);
  1550. unlock_buffer(nbh);
  1551. mark_buffer_dirty_inode(nbh, inode);
  1552. aed = (struct allocExtDesc *)(nbh->b_data);
  1553. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT))
  1554. aed->previousAllocExtLocation =
  1555. cpu_to_le32(obloc.logicalBlockNum);
  1556. if (epos->offset + adsize > inode->i_sb->s_blocksize) {
  1557. loffset = epos->offset;
  1558. aed->lengthAllocDescs = cpu_to_le32(adsize);
  1559. sptr = ptr - adsize;
  1560. dptr = nbh->b_data + sizeof(struct allocExtDesc);
  1561. memcpy(dptr, sptr, adsize);
  1562. epos->offset = sizeof(struct allocExtDesc) + adsize;
  1563. } else {
  1564. loffset = epos->offset + adsize;
  1565. aed->lengthAllocDescs = cpu_to_le32(0);
  1566. sptr = ptr;
  1567. epos->offset = sizeof(struct allocExtDesc);
  1568. if (epos->bh) {
  1569. aed = (struct allocExtDesc *)epos->bh->b_data;
  1570. aed->lengthAllocDescs =
  1571. cpu_to_le32(le32_to_cpu(
  1572. aed->lengthAllocDescs) + adsize);
  1573. } else {
  1574. UDF_I(inode)->i_lenAlloc += adsize;
  1575. mark_inode_dirty(inode);
  1576. }
  1577. }
  1578. if (UDF_SB(inode->i_sb)->s_udfrev >= 0x0200)
  1579. udf_new_tag(nbh->b_data, TAG_IDENT_AED, 3, 1,
  1580. epos->block.logicalBlockNum, sizeof(tag));
  1581. else
  1582. udf_new_tag(nbh->b_data, TAG_IDENT_AED, 2, 1,
  1583. epos->block.logicalBlockNum, sizeof(tag));
  1584. switch (UDF_I(inode)->i_alloc_type) {
  1585. case ICBTAG_FLAG_AD_SHORT:
  1586. sad = (short_ad *)sptr;
  1587. sad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
  1588. inode->i_sb->s_blocksize);
  1589. sad->extPosition =
  1590. cpu_to_le32(epos->block.logicalBlockNum);
  1591. break;
  1592. case ICBTAG_FLAG_AD_LONG:
  1593. lad = (long_ad *)sptr;
  1594. lad->extLength = cpu_to_le32(EXT_NEXT_EXTENT_ALLOCDECS |
  1595. inode->i_sb->s_blocksize);
  1596. lad->extLocation = cpu_to_lelb(epos->block);
  1597. memset(lad->impUse, 0x00, sizeof(lad->impUse));
  1598. break;
  1599. }
  1600. if (epos->bh) {
  1601. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
  1602. UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
  1603. udf_update_tag(epos->bh->b_data, loffset);
  1604. else
  1605. udf_update_tag(epos->bh->b_data,
  1606. sizeof(struct allocExtDesc));
  1607. mark_buffer_dirty_inode(epos->bh, inode);
  1608. brelse(epos->bh);
  1609. } else {
  1610. mark_inode_dirty(inode);
  1611. }
  1612. epos->bh = nbh;
  1613. }
  1614. etype = udf_write_aext(inode, epos, eloc, elen, inc);
  1615. if (!epos->bh) {
  1616. UDF_I(inode)->i_lenAlloc += adsize;
  1617. mark_inode_dirty(inode);
  1618. } else {
  1619. aed = (struct allocExtDesc *)epos->bh->b_data;
  1620. aed->lengthAllocDescs =
  1621. cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) +
  1622. adsize);
  1623. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
  1624. UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
  1625. udf_update_tag(epos->bh->b_data,
  1626. epos->offset + (inc ? 0 : adsize));
  1627. else
  1628. udf_update_tag(epos->bh->b_data,
  1629. sizeof(struct allocExtDesc));
  1630. mark_buffer_dirty_inode(epos->bh, inode);
  1631. }
  1632. return etype;
  1633. }
  1634. int8_t udf_write_aext(struct inode *inode, struct extent_position *epos,
  1635. kernel_lb_addr eloc, uint32_t elen, int inc)
  1636. {
  1637. int adsize;
  1638. uint8_t *ptr;
  1639. short_ad *sad;
  1640. long_ad *lad;
  1641. if (!epos->bh)
  1642. ptr = UDF_I(inode)->i_ext.i_data + epos->offset -
  1643. udf_file_entry_alloc_offset(inode) +
  1644. UDF_I(inode)->i_lenEAttr;
  1645. else
  1646. ptr = epos->bh->b_data + epos->offset;
  1647. switch (UDF_I(inode)->i_alloc_type) {
  1648. case ICBTAG_FLAG_AD_SHORT:
  1649. sad = (short_ad *)ptr;
  1650. sad->extLength = cpu_to_le32(elen);
  1651. sad->extPosition = cpu_to_le32(eloc.logicalBlockNum);
  1652. adsize = sizeof(short_ad);
  1653. break;
  1654. case ICBTAG_FLAG_AD_LONG:
  1655. lad = (long_ad *)ptr;
  1656. lad->extLength = cpu_to_le32(elen);
  1657. lad->extLocation = cpu_to_lelb(eloc);
  1658. memset(lad->impUse, 0x00, sizeof(lad->impUse));
  1659. adsize = sizeof(long_ad);
  1660. break;
  1661. default:
  1662. return -1;
  1663. }
  1664. if (epos->bh) {
  1665. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
  1666. UDF_SB(inode->i_sb)->s_udfrev >= 0x0201) {
  1667. struct allocExtDesc *aed =
  1668. (struct allocExtDesc *)epos->bh->b_data;
  1669. udf_update_tag(epos->bh->b_data,
  1670. le32_to_cpu(aed->lengthAllocDescs) +
  1671. sizeof(struct allocExtDesc));
  1672. }
  1673. mark_buffer_dirty_inode(epos->bh, inode);
  1674. } else {
  1675. mark_inode_dirty(inode);
  1676. }
  1677. if (inc)
  1678. epos->offset += adsize;
  1679. return (elen >> 30);
  1680. }
  1681. int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
  1682. kernel_lb_addr *eloc, uint32_t *elen, int inc)
  1683. {
  1684. int8_t etype;
  1685. while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
  1686. (EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
  1687. int block;
  1688. epos->block = *eloc;
  1689. epos->offset = sizeof(struct allocExtDesc);
  1690. brelse(epos->bh);
  1691. block = udf_get_lb_pblock(inode->i_sb, epos->block, 0);
  1692. epos->bh = udf_tread(inode->i_sb, block);
  1693. if (!epos->bh) {
  1694. udf_debug("reading block %d failed!\n", block);
  1695. return -1;
  1696. }
  1697. }
  1698. return etype;
  1699. }
  1700. int8_t udf_current_aext(struct inode *inode, struct extent_position *epos,
  1701. kernel_lb_addr *eloc, uint32_t *elen, int inc)
  1702. {
  1703. int alen;
  1704. int8_t etype;
  1705. uint8_t *ptr;
  1706. short_ad *sad;
  1707. long_ad *lad;
  1708. if (!epos->bh) {
  1709. if (!epos->offset)
  1710. epos->offset = udf_file_entry_alloc_offset(inode);
  1711. ptr = UDF_I(inode)->i_ext.i_data + epos->offset -
  1712. udf_file_entry_alloc_offset(inode) +
  1713. UDF_I(inode)->i_lenEAttr;
  1714. alen = udf_file_entry_alloc_offset(inode) +
  1715. UDF_I(inode)->i_lenAlloc;
  1716. } else {
  1717. if (!epos->offset)
  1718. epos->offset = sizeof(struct allocExtDesc);
  1719. ptr = epos->bh->b_data + epos->offset;
  1720. alen = sizeof(struct allocExtDesc) +
  1721. le32_to_cpu(((struct allocExtDesc *)epos->bh->b_data)->
  1722. lengthAllocDescs);
  1723. }
  1724. switch (UDF_I(inode)->i_alloc_type) {
  1725. case ICBTAG_FLAG_AD_SHORT:
  1726. sad = udf_get_fileshortad(ptr, alen, &epos->offset, inc);
  1727. if (!sad)
  1728. return -1;
  1729. etype = le32_to_cpu(sad->extLength) >> 30;
  1730. eloc->logicalBlockNum = le32_to_cpu(sad->extPosition);
  1731. eloc->partitionReferenceNum =
  1732. UDF_I(inode)->i_location.partitionReferenceNum;
  1733. *elen = le32_to_cpu(sad->extLength) & UDF_EXTENT_LENGTH_MASK;
  1734. break;
  1735. case ICBTAG_FLAG_AD_LONG:
  1736. lad = udf_get_filelongad(ptr, alen, &epos->offset, inc);
  1737. if (!lad)
  1738. return -1;
  1739. etype = le32_to_cpu(lad->extLength) >> 30;
  1740. *eloc = lelb_to_cpu(lad->extLocation);
  1741. *elen = le32_to_cpu(lad->extLength) & UDF_EXTENT_LENGTH_MASK;
  1742. break;
  1743. default:
  1744. udf_debug("alloc_type = %d unsupported\n",
  1745. UDF_I(inode)->i_alloc_type);
  1746. return -1;
  1747. }
  1748. return etype;
  1749. }
  1750. static int8_t udf_insert_aext(struct inode *inode, struct extent_position epos,
  1751. kernel_lb_addr neloc, uint32_t nelen)
  1752. {
  1753. kernel_lb_addr oeloc;
  1754. uint32_t oelen;
  1755. int8_t etype;
  1756. if (epos.bh)
  1757. get_bh(epos.bh);
  1758. while ((etype = udf_next_aext(inode, &epos, &oeloc, &oelen, 0)) != -1) {
  1759. udf_write_aext(inode, &epos, neloc, nelen, 1);
  1760. neloc = oeloc;
  1761. nelen = (etype << 30) | oelen;
  1762. }
  1763. udf_add_aext(inode, &epos, neloc, nelen, 1);
  1764. brelse(epos.bh);
  1765. return (nelen >> 30);
  1766. }
  1767. int8_t udf_delete_aext(struct inode *inode, struct extent_position epos,
  1768. kernel_lb_addr eloc, uint32_t elen)
  1769. {
  1770. struct extent_position oepos;
  1771. int adsize;
  1772. int8_t etype;
  1773. struct allocExtDesc *aed;
  1774. if (epos.bh) {
  1775. get_bh(epos.bh);
  1776. get_bh(epos.bh);
  1777. }
  1778. if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_SHORT)
  1779. adsize = sizeof(short_ad);
  1780. else if (UDF_I(inode)->i_alloc_type == ICBTAG_FLAG_AD_LONG)
  1781. adsize = sizeof(long_ad);
  1782. else
  1783. adsize = 0;
  1784. oepos = epos;
  1785. if (udf_next_aext(inode, &epos, &eloc, &elen, 1) == -1)
  1786. return -1;
  1787. while ((etype = udf_next_aext(inode, &epos, &eloc, &elen, 1)) != -1) {
  1788. udf_write_aext(inode, &oepos, eloc, (etype << 30) | elen, 1);
  1789. if (oepos.bh != epos.bh) {
  1790. oepos.block = epos.block;
  1791. brelse(oepos.bh);
  1792. get_bh(epos.bh);
  1793. oepos.bh = epos.bh;
  1794. oepos.offset = epos.offset - adsize;
  1795. }
  1796. }
  1797. memset(&eloc, 0x00, sizeof(kernel_lb_addr));
  1798. elen = 0;
  1799. if (epos.bh != oepos.bh) {
  1800. udf_free_blocks(inode->i_sb, inode, epos.block, 0, 1);
  1801. udf_write_aext(inode, &oepos, eloc, elen, 1);
  1802. udf_write_aext(inode, &oepos, eloc, elen, 1);
  1803. if (!oepos.bh) {
  1804. UDF_I(inode)->i_lenAlloc -= (adsize * 2);
  1805. mark_inode_dirty(inode);
  1806. } else {
  1807. aed = (struct allocExtDesc *)oepos.bh->b_data;
  1808. aed->lengthAllocDescs =
  1809. cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
  1810. (2 * adsize));
  1811. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
  1812. UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
  1813. udf_update_tag(oepos.bh->b_data,
  1814. oepos.offset - (2 * adsize));
  1815. else
  1816. udf_update_tag(oepos.bh->b_data,
  1817. sizeof(struct allocExtDesc));
  1818. mark_buffer_dirty_inode(oepos.bh, inode);
  1819. }
  1820. } else {
  1821. udf_write_aext(inode, &oepos, eloc, elen, 1);
  1822. if (!oepos.bh) {
  1823. UDF_I(inode)->i_lenAlloc -= adsize;
  1824. mark_inode_dirty(inode);
  1825. } else {
  1826. aed = (struct allocExtDesc *)oepos.bh->b_data;
  1827. aed->lengthAllocDescs =
  1828. cpu_to_le32(le32_to_cpu(aed->lengthAllocDescs) -
  1829. adsize);
  1830. if (!UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_STRICT) ||
  1831. UDF_SB(inode->i_sb)->s_udfrev >= 0x0201)
  1832. udf_update_tag(oepos.bh->b_data,
  1833. epos.offset - adsize);
  1834. else
  1835. udf_update_tag(oepos.bh->b_data,
  1836. sizeof(struct allocExtDesc));
  1837. mark_buffer_dirty_inode(oepos.bh, inode);
  1838. }
  1839. }
  1840. brelse(epos.bh);
  1841. brelse(oepos.bh);
  1842. return (elen >> 30);
  1843. }
  1844. int8_t inode_bmap(struct inode *inode, sector_t block,
  1845. struct extent_position *pos, kernel_lb_addr *eloc,
  1846. uint32_t *elen, sector_t *offset)
  1847. {
  1848. unsigned char blocksize_bits = inode->i_sb->s_blocksize_bits;
  1849. loff_t lbcount = 0, bcount =
  1850. (loff_t) block << blocksize_bits;
  1851. int8_t etype;
  1852. if (block < 0) {
  1853. printk(KERN_ERR "udf: inode_bmap: block < 0\n");
  1854. return -1;
  1855. }
  1856. pos->offset = 0;
  1857. pos->block = UDF_I(inode)->i_location;
  1858. pos->bh = NULL;
  1859. *elen = 0;
  1860. do {
  1861. etype = udf_next_aext(inode, pos, eloc, elen, 1);
  1862. if (etype == -1) {
  1863. *offset = (bcount - lbcount) >> blocksize_bits;
  1864. UDF_I(inode)->i_lenExtents = lbcount;
  1865. return -1;
  1866. }
  1867. lbcount += *elen;
  1868. } while (lbcount <= bcount);
  1869. *offset = (bcount + *elen - lbcount) >> blocksize_bits;
  1870. return etype;
  1871. }
  1872. long udf_block_map(struct inode *inode, sector_t block)
  1873. {
  1874. kernel_lb_addr eloc;
  1875. uint32_t elen;
  1876. sector_t offset;
  1877. struct extent_position epos = {};
  1878. int ret;
  1879. lock_kernel();
  1880. if (inode_bmap(inode, block, &epos, &eloc, &elen, &offset) ==
  1881. (EXT_RECORDED_ALLOCATED >> 30))
  1882. ret = udf_get_lb_pblock(inode->i_sb, eloc, offset);
  1883. else
  1884. ret = 0;
  1885. unlock_kernel();
  1886. brelse(epos.bh);
  1887. if (UDF_QUERY_FLAG(inode->i_sb, UDF_FLAG_VARCONV))
  1888. return udf_fixed_to_variable(ret);
  1889. else
  1890. return ret;
  1891. }