super.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278
  1. /*
  2. * super.c
  3. *
  4. * PURPOSE
  5. * Super block routines for the OSTA-UDF(tm) filesystem.
  6. *
  7. * DESCRIPTION
  8. * OSTA-UDF(tm) = Optical Storage Technology Association
  9. * Universal Disk Format.
  10. *
  11. * This code is based on version 2.00 of the UDF specification,
  12. * and revision 3 of the ECMA 167 standard [equivalent to ISO 13346].
  13. * http://www.osta.org/
  14. * http://www.ecma.ch/
  15. * http://www.iso.org/
  16. *
  17. * COPYRIGHT
  18. * This file is distributed under the terms of the GNU General Public
  19. * License (GPL). Copies of the GPL can be obtained from:
  20. * ftp://prep.ai.mit.edu/pub/gnu/GPL
  21. * Each contributing author retains all rights to their own work.
  22. *
  23. * (C) 1998 Dave Boynton
  24. * (C) 1998-2004 Ben Fennema
  25. * (C) 2000 Stelias Computing Inc
  26. *
  27. * HISTORY
  28. *
  29. * 09/24/98 dgb changed to allow compiling outside of kernel, and
  30. * added some debugging.
  31. * 10/01/98 dgb updated to allow (some) possibility of compiling w/2.0.34
  32. * 10/16/98 attempting some multi-session support
  33. * 10/17/98 added freespace count for "df"
  34. * 11/11/98 gr added novrs option
  35. * 11/26/98 dgb added fileset,anchor mount options
  36. * 12/06/98 blf really hosed things royally. vat/sparing support. sequenced
  37. * vol descs. rewrote option handling based on isofs
  38. * 12/20/98 find the free space bitmap (if it exists)
  39. */
  40. #include "udfdecl.h"
  41. #include <linux/blkdev.h>
  42. #include <linux/slab.h>
  43. #include <linux/kernel.h>
  44. #include <linux/module.h>
  45. #include <linux/parser.h>
  46. #include <linux/stat.h>
  47. #include <linux/cdrom.h>
  48. #include <linux/nls.h>
  49. #include <linux/smp_lock.h>
  50. #include <linux/buffer_head.h>
  51. #include <linux/vfs.h>
  52. #include <linux/vmalloc.h>
  53. #include <linux/errno.h>
  54. #include <linux/mount.h>
  55. #include <linux/seq_file.h>
  56. #include <linux/bitmap.h>
  57. #include <linux/crc-itu-t.h>
  58. #include <asm/byteorder.h>
  59. #include "udf_sb.h"
  60. #include "udf_i.h"
  61. #include <linux/init.h>
  62. #include <asm/uaccess.h>
  63. #define VDS_POS_PRIMARY_VOL_DESC 0
  64. #define VDS_POS_UNALLOC_SPACE_DESC 1
  65. #define VDS_POS_LOGICAL_VOL_DESC 2
  66. #define VDS_POS_PARTITION_DESC 3
  67. #define VDS_POS_IMP_USE_VOL_DESC 4
  68. #define VDS_POS_VOL_DESC_PTR 5
  69. #define VDS_POS_TERMINATING_DESC 6
  70. #define VDS_POS_LENGTH 7
  71. #define UDF_DEFAULT_BLOCKSIZE 2048
  72. static char error_buf[1024];
  73. /* These are the "meat" - everything else is stuffing */
  74. static int udf_fill_super(struct super_block *, void *, int);
  75. static void udf_put_super(struct super_block *);
  76. static void udf_write_super(struct super_block *);
  77. static int udf_remount_fs(struct super_block *, int *, char *);
  78. static int udf_check_valid(struct super_block *, int, int);
  79. static int udf_vrs(struct super_block *sb, int silent);
  80. static void udf_load_logicalvolint(struct super_block *, struct kernel_extent_ad);
  81. static void udf_find_anchor(struct super_block *);
  82. static int udf_find_fileset(struct super_block *, struct kernel_lb_addr *,
  83. struct kernel_lb_addr *);
  84. static void udf_load_fileset(struct super_block *, struct buffer_head *,
  85. struct kernel_lb_addr *);
  86. static void udf_open_lvid(struct super_block *);
  87. static void udf_close_lvid(struct super_block *);
  88. static unsigned int udf_count_free(struct super_block *);
  89. static int udf_statfs(struct dentry *, struct kstatfs *);
  90. static int udf_show_options(struct seq_file *, struct vfsmount *);
  91. static void udf_error(struct super_block *sb, const char *function,
  92. const char *fmt, ...);
  93. struct logicalVolIntegrityDescImpUse *udf_sb_lvidiu(struct udf_sb_info *sbi)
  94. {
  95. struct logicalVolIntegrityDesc *lvid =
  96. (struct logicalVolIntegrityDesc *)sbi->s_lvid_bh->b_data;
  97. __u32 number_of_partitions = le32_to_cpu(lvid->numOfPartitions);
  98. __u32 offset = number_of_partitions * 2 *
  99. sizeof(uint32_t)/sizeof(uint8_t);
  100. return (struct logicalVolIntegrityDescImpUse *)&(lvid->impUse[offset]);
  101. }
  102. /* UDF filesystem type */
  103. static int udf_get_sb(struct file_system_type *fs_type,
  104. int flags, const char *dev_name, void *data,
  105. struct vfsmount *mnt)
  106. {
  107. return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super, mnt);
  108. }
  109. static struct file_system_type udf_fstype = {
  110. .owner = THIS_MODULE,
  111. .name = "udf",
  112. .get_sb = udf_get_sb,
  113. .kill_sb = kill_block_super,
  114. .fs_flags = FS_REQUIRES_DEV,
  115. };
  116. static struct kmem_cache *udf_inode_cachep;
  117. static struct inode *udf_alloc_inode(struct super_block *sb)
  118. {
  119. struct udf_inode_info *ei;
  120. ei = kmem_cache_alloc(udf_inode_cachep, GFP_KERNEL);
  121. if (!ei)
  122. return NULL;
  123. ei->i_unique = 0;
  124. ei->i_lenExtents = 0;
  125. ei->i_next_alloc_block = 0;
  126. ei->i_next_alloc_goal = 0;
  127. ei->i_strat4096 = 0;
  128. return &ei->vfs_inode;
  129. }
  130. static void udf_destroy_inode(struct inode *inode)
  131. {
  132. kmem_cache_free(udf_inode_cachep, UDF_I(inode));
  133. }
  134. static void init_once(void *foo)
  135. {
  136. struct udf_inode_info *ei = (struct udf_inode_info *)foo;
  137. ei->i_ext.i_data = NULL;
  138. inode_init_once(&ei->vfs_inode);
  139. }
  140. static int init_inodecache(void)
  141. {
  142. udf_inode_cachep = kmem_cache_create("udf_inode_cache",
  143. sizeof(struct udf_inode_info),
  144. 0, (SLAB_RECLAIM_ACCOUNT |
  145. SLAB_MEM_SPREAD),
  146. init_once);
  147. if (!udf_inode_cachep)
  148. return -ENOMEM;
  149. return 0;
  150. }
  151. static void destroy_inodecache(void)
  152. {
  153. kmem_cache_destroy(udf_inode_cachep);
  154. }
  155. /* Superblock operations */
  156. static const struct super_operations udf_sb_ops = {
  157. .alloc_inode = udf_alloc_inode,
  158. .destroy_inode = udf_destroy_inode,
  159. .write_inode = udf_write_inode,
  160. .delete_inode = udf_delete_inode,
  161. .clear_inode = udf_clear_inode,
  162. .put_super = udf_put_super,
  163. .write_super = udf_write_super,
  164. .statfs = udf_statfs,
  165. .remount_fs = udf_remount_fs,
  166. .show_options = udf_show_options,
  167. };
  168. struct udf_options {
  169. unsigned char novrs;
  170. unsigned int blocksize;
  171. unsigned int session;
  172. unsigned int lastblock;
  173. unsigned int anchor;
  174. unsigned int volume;
  175. unsigned short partition;
  176. unsigned int fileset;
  177. unsigned int rootdir;
  178. unsigned int flags;
  179. mode_t umask;
  180. gid_t gid;
  181. uid_t uid;
  182. mode_t fmode;
  183. mode_t dmode;
  184. struct nls_table *nls_map;
  185. };
  186. static int __init init_udf_fs(void)
  187. {
  188. int err;
  189. err = init_inodecache();
  190. if (err)
  191. goto out1;
  192. err = register_filesystem(&udf_fstype);
  193. if (err)
  194. goto out;
  195. return 0;
  196. out:
  197. destroy_inodecache();
  198. out1:
  199. return err;
  200. }
  201. static void __exit exit_udf_fs(void)
  202. {
  203. unregister_filesystem(&udf_fstype);
  204. destroy_inodecache();
  205. }
  206. module_init(init_udf_fs)
  207. module_exit(exit_udf_fs)
  208. static int udf_sb_alloc_partition_maps(struct super_block *sb, u32 count)
  209. {
  210. struct udf_sb_info *sbi = UDF_SB(sb);
  211. sbi->s_partmaps = kcalloc(count, sizeof(struct udf_part_map),
  212. GFP_KERNEL);
  213. if (!sbi->s_partmaps) {
  214. udf_error(sb, __func__,
  215. "Unable to allocate space for %d partition maps",
  216. count);
  217. sbi->s_partitions = 0;
  218. return -ENOMEM;
  219. }
  220. sbi->s_partitions = count;
  221. return 0;
  222. }
  223. static int udf_show_options(struct seq_file *seq, struct vfsmount *mnt)
  224. {
  225. struct super_block *sb = mnt->mnt_sb;
  226. struct udf_sb_info *sbi = UDF_SB(sb);
  227. if (!UDF_QUERY_FLAG(sb, UDF_FLAG_STRICT))
  228. seq_puts(seq, ",nostrict");
  229. if (sb->s_blocksize != UDF_DEFAULT_BLOCKSIZE)
  230. seq_printf(seq, ",bs=%lu", sb->s_blocksize);
  231. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNHIDE))
  232. seq_puts(seq, ",unhide");
  233. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UNDELETE))
  234. seq_puts(seq, ",undelete");
  235. if (!UDF_QUERY_FLAG(sb, UDF_FLAG_USE_AD_IN_ICB))
  236. seq_puts(seq, ",noadinicb");
  237. if (UDF_QUERY_FLAG(sb, UDF_FLAG_USE_SHORT_AD))
  238. seq_puts(seq, ",shortad");
  239. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_FORGET))
  240. seq_puts(seq, ",uid=forget");
  241. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_IGNORE))
  242. seq_puts(seq, ",uid=ignore");
  243. if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_FORGET))
  244. seq_puts(seq, ",gid=forget");
  245. if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_IGNORE))
  246. seq_puts(seq, ",gid=ignore");
  247. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UID_SET))
  248. seq_printf(seq, ",uid=%u", sbi->s_uid);
  249. if (UDF_QUERY_FLAG(sb, UDF_FLAG_GID_SET))
  250. seq_printf(seq, ",gid=%u", sbi->s_gid);
  251. if (sbi->s_umask != 0)
  252. seq_printf(seq, ",umask=%o", sbi->s_umask);
  253. if (sbi->s_fmode != UDF_INVALID_MODE)
  254. seq_printf(seq, ",mode=%o", sbi->s_fmode);
  255. if (sbi->s_dmode != UDF_INVALID_MODE)
  256. seq_printf(seq, ",dmode=%o", sbi->s_dmode);
  257. if (UDF_QUERY_FLAG(sb, UDF_FLAG_SESSION_SET))
  258. seq_printf(seq, ",session=%u", sbi->s_session);
  259. if (UDF_QUERY_FLAG(sb, UDF_FLAG_LASTBLOCK_SET))
  260. seq_printf(seq, ",lastblock=%u", sbi->s_last_block);
  261. /*
  262. * s_anchor[2] could be zeroed out in case there is no anchor
  263. * in the specified block, but then the "anchor=N" option
  264. * originally given by the user wasn't effective, so it's OK
  265. * if we don't show it.
  266. */
  267. if (sbi->s_anchor[2] != 0)
  268. seq_printf(seq, ",anchor=%u", sbi->s_anchor[2]);
  269. /*
  270. * volume, partition, fileset and rootdir seem to be ignored
  271. * currently
  272. */
  273. if (UDF_QUERY_FLAG(sb, UDF_FLAG_UTF8))
  274. seq_puts(seq, ",utf8");
  275. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP) && sbi->s_nls_map)
  276. seq_printf(seq, ",iocharset=%s", sbi->s_nls_map->charset);
  277. return 0;
  278. }
  279. /*
  280. * udf_parse_options
  281. *
  282. * PURPOSE
  283. * Parse mount options.
  284. *
  285. * DESCRIPTION
  286. * The following mount options are supported:
  287. *
  288. * gid= Set the default group.
  289. * umask= Set the default umask.
  290. * mode= Set the default file permissions.
  291. * dmode= Set the default directory permissions.
  292. * uid= Set the default user.
  293. * bs= Set the block size.
  294. * unhide Show otherwise hidden files.
  295. * undelete Show deleted files in lists.
  296. * adinicb Embed data in the inode (default)
  297. * noadinicb Don't embed data in the inode
  298. * shortad Use short ad's
  299. * longad Use long ad's (default)
  300. * nostrict Unset strict conformance
  301. * iocharset= Set the NLS character set
  302. *
  303. * The remaining are for debugging and disaster recovery:
  304. *
  305. * novrs Skip volume sequence recognition
  306. *
  307. * The following expect a offset from 0.
  308. *
  309. * session= Set the CDROM session (default= last session)
  310. * anchor= Override standard anchor location. (default= 256)
  311. * volume= Override the VolumeDesc location. (unused)
  312. * partition= Override the PartitionDesc location. (unused)
  313. * lastblock= Set the last block of the filesystem/
  314. *
  315. * The following expect a offset from the partition root.
  316. *
  317. * fileset= Override the fileset block location. (unused)
  318. * rootdir= Override the root directory location. (unused)
  319. * WARNING: overriding the rootdir to a non-directory may
  320. * yield highly unpredictable results.
  321. *
  322. * PRE-CONDITIONS
  323. * options Pointer to mount options string.
  324. * uopts Pointer to mount options variable.
  325. *
  326. * POST-CONDITIONS
  327. * <return> 1 Mount options parsed okay.
  328. * <return> 0 Error parsing mount options.
  329. *
  330. * HISTORY
  331. * July 1, 1997 - Andrew E. Mileski
  332. * Written, tested, and released.
  333. */
  334. enum {
  335. Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
  336. Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
  337. Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
  338. Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
  339. Opt_rootdir, Opt_utf8, Opt_iocharset,
  340. Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore,
  341. Opt_fmode, Opt_dmode
  342. };
  343. static const match_table_t tokens = {
  344. {Opt_novrs, "novrs"},
  345. {Opt_nostrict, "nostrict"},
  346. {Opt_bs, "bs=%u"},
  347. {Opt_unhide, "unhide"},
  348. {Opt_undelete, "undelete"},
  349. {Opt_noadinicb, "noadinicb"},
  350. {Opt_adinicb, "adinicb"},
  351. {Opt_shortad, "shortad"},
  352. {Opt_longad, "longad"},
  353. {Opt_uforget, "uid=forget"},
  354. {Opt_uignore, "uid=ignore"},
  355. {Opt_gforget, "gid=forget"},
  356. {Opt_gignore, "gid=ignore"},
  357. {Opt_gid, "gid=%u"},
  358. {Opt_uid, "uid=%u"},
  359. {Opt_umask, "umask=%o"},
  360. {Opt_session, "session=%u"},
  361. {Opt_lastblock, "lastblock=%u"},
  362. {Opt_anchor, "anchor=%u"},
  363. {Opt_volume, "volume=%u"},
  364. {Opt_partition, "partition=%u"},
  365. {Opt_fileset, "fileset=%u"},
  366. {Opt_rootdir, "rootdir=%u"},
  367. {Opt_utf8, "utf8"},
  368. {Opt_iocharset, "iocharset=%s"},
  369. {Opt_fmode, "mode=%o"},
  370. {Opt_dmode, "dmode=%o"},
  371. {Opt_err, NULL}
  372. };
  373. static int udf_parse_options(char *options, struct udf_options *uopt,
  374. bool remount)
  375. {
  376. char *p;
  377. int option;
  378. uopt->novrs = 0;
  379. uopt->blocksize = UDF_DEFAULT_BLOCKSIZE;
  380. uopt->partition = 0xFFFF;
  381. uopt->session = 0xFFFFFFFF;
  382. uopt->lastblock = 0;
  383. uopt->anchor = 0;
  384. uopt->volume = 0xFFFFFFFF;
  385. uopt->rootdir = 0xFFFFFFFF;
  386. uopt->fileset = 0xFFFFFFFF;
  387. uopt->nls_map = NULL;
  388. if (!options)
  389. return 1;
  390. while ((p = strsep(&options, ",")) != NULL) {
  391. substring_t args[MAX_OPT_ARGS];
  392. int token;
  393. if (!*p)
  394. continue;
  395. token = match_token(p, tokens, args);
  396. switch (token) {
  397. case Opt_novrs:
  398. uopt->novrs = 1;
  399. case Opt_bs:
  400. if (match_int(&args[0], &option))
  401. return 0;
  402. uopt->blocksize = option;
  403. break;
  404. case Opt_unhide:
  405. uopt->flags |= (1 << UDF_FLAG_UNHIDE);
  406. break;
  407. case Opt_undelete:
  408. uopt->flags |= (1 << UDF_FLAG_UNDELETE);
  409. break;
  410. case Opt_noadinicb:
  411. uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
  412. break;
  413. case Opt_adinicb:
  414. uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
  415. break;
  416. case Opt_shortad:
  417. uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
  418. break;
  419. case Opt_longad:
  420. uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
  421. break;
  422. case Opt_gid:
  423. if (match_int(args, &option))
  424. return 0;
  425. uopt->gid = option;
  426. uopt->flags |= (1 << UDF_FLAG_GID_SET);
  427. break;
  428. case Opt_uid:
  429. if (match_int(args, &option))
  430. return 0;
  431. uopt->uid = option;
  432. uopt->flags |= (1 << UDF_FLAG_UID_SET);
  433. break;
  434. case Opt_umask:
  435. if (match_octal(args, &option))
  436. return 0;
  437. uopt->umask = option;
  438. break;
  439. case Opt_nostrict:
  440. uopt->flags &= ~(1 << UDF_FLAG_STRICT);
  441. break;
  442. case Opt_session:
  443. if (match_int(args, &option))
  444. return 0;
  445. uopt->session = option;
  446. if (!remount)
  447. uopt->flags |= (1 << UDF_FLAG_SESSION_SET);
  448. break;
  449. case Opt_lastblock:
  450. if (match_int(args, &option))
  451. return 0;
  452. uopt->lastblock = option;
  453. if (!remount)
  454. uopt->flags |= (1 << UDF_FLAG_LASTBLOCK_SET);
  455. break;
  456. case Opt_anchor:
  457. if (match_int(args, &option))
  458. return 0;
  459. uopt->anchor = option;
  460. break;
  461. case Opt_volume:
  462. if (match_int(args, &option))
  463. return 0;
  464. uopt->volume = option;
  465. break;
  466. case Opt_partition:
  467. if (match_int(args, &option))
  468. return 0;
  469. uopt->partition = option;
  470. break;
  471. case Opt_fileset:
  472. if (match_int(args, &option))
  473. return 0;
  474. uopt->fileset = option;
  475. break;
  476. case Opt_rootdir:
  477. if (match_int(args, &option))
  478. return 0;
  479. uopt->rootdir = option;
  480. break;
  481. case Opt_utf8:
  482. uopt->flags |= (1 << UDF_FLAG_UTF8);
  483. break;
  484. #ifdef CONFIG_UDF_NLS
  485. case Opt_iocharset:
  486. uopt->nls_map = load_nls(args[0].from);
  487. uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
  488. break;
  489. #endif
  490. case Opt_uignore:
  491. uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
  492. break;
  493. case Opt_uforget:
  494. uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
  495. break;
  496. case Opt_gignore:
  497. uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
  498. break;
  499. case Opt_gforget:
  500. uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
  501. break;
  502. case Opt_fmode:
  503. if (match_octal(args, &option))
  504. return 0;
  505. uopt->fmode = option & 0777;
  506. break;
  507. case Opt_dmode:
  508. if (match_octal(args, &option))
  509. return 0;
  510. uopt->dmode = option & 0777;
  511. break;
  512. default:
  513. printk(KERN_ERR "udf: bad mount option \"%s\" "
  514. "or missing value\n", p);
  515. return 0;
  516. }
  517. }
  518. return 1;
  519. }
  520. static void udf_write_super(struct super_block *sb)
  521. {
  522. lock_kernel();
  523. if (!(sb->s_flags & MS_RDONLY))
  524. udf_open_lvid(sb);
  525. sb->s_dirt = 0;
  526. unlock_kernel();
  527. }
  528. static int udf_remount_fs(struct super_block *sb, int *flags, char *options)
  529. {
  530. struct udf_options uopt;
  531. struct udf_sb_info *sbi = UDF_SB(sb);
  532. uopt.flags = sbi->s_flags;
  533. uopt.uid = sbi->s_uid;
  534. uopt.gid = sbi->s_gid;
  535. uopt.umask = sbi->s_umask;
  536. uopt.fmode = sbi->s_fmode;
  537. uopt.dmode = sbi->s_dmode;
  538. if (!udf_parse_options(options, &uopt, true))
  539. return -EINVAL;
  540. sbi->s_flags = uopt.flags;
  541. sbi->s_uid = uopt.uid;
  542. sbi->s_gid = uopt.gid;
  543. sbi->s_umask = uopt.umask;
  544. sbi->s_fmode = uopt.fmode;
  545. sbi->s_dmode = uopt.dmode;
  546. if (sbi->s_lvid_bh) {
  547. int write_rev = le16_to_cpu(udf_sb_lvidiu(sbi)->minUDFWriteRev);
  548. if (write_rev > UDF_MAX_WRITE_VERSION)
  549. *flags |= MS_RDONLY;
  550. }
  551. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  552. return 0;
  553. if (*flags & MS_RDONLY)
  554. udf_close_lvid(sb);
  555. else
  556. udf_open_lvid(sb);
  557. return 0;
  558. }
  559. static int udf_vrs(struct super_block *sb, int silent)
  560. {
  561. struct volStructDesc *vsd = NULL;
  562. loff_t sector = 32768;
  563. int sectorsize;
  564. struct buffer_head *bh = NULL;
  565. int iso9660 = 0;
  566. int nsr02 = 0;
  567. int nsr03 = 0;
  568. struct udf_sb_info *sbi;
  569. /* Block size must be a multiple of 512 */
  570. if (sb->s_blocksize & 511)
  571. return 0;
  572. sbi = UDF_SB(sb);
  573. if (sb->s_blocksize < sizeof(struct volStructDesc))
  574. sectorsize = sizeof(struct volStructDesc);
  575. else
  576. sectorsize = sb->s_blocksize;
  577. sector += (sbi->s_session << sb->s_blocksize_bits);
  578. udf_debug("Starting at sector %u (%ld byte sectors)\n",
  579. (unsigned int)(sector >> sb->s_blocksize_bits),
  580. sb->s_blocksize);
  581. /* Process the sequence (if applicable) */
  582. for (; !nsr02 && !nsr03; sector += sectorsize) {
  583. /* Read a block */
  584. bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
  585. if (!bh)
  586. break;
  587. /* Look for ISO descriptors */
  588. vsd = (struct volStructDesc *)(bh->b_data +
  589. (sector & (sb->s_blocksize - 1)));
  590. if (vsd->stdIdent[0] == 0) {
  591. brelse(bh);
  592. break;
  593. } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001,
  594. VSD_STD_ID_LEN)) {
  595. iso9660 = sector;
  596. switch (vsd->structType) {
  597. case 0:
  598. udf_debug("ISO9660 Boot Record found\n");
  599. break;
  600. case 1:
  601. udf_debug("ISO9660 Primary Volume Descriptor "
  602. "found\n");
  603. break;
  604. case 2:
  605. udf_debug("ISO9660 Supplementary Volume "
  606. "Descriptor found\n");
  607. break;
  608. case 3:
  609. udf_debug("ISO9660 Volume Partition Descriptor "
  610. "found\n");
  611. break;
  612. case 255:
  613. udf_debug("ISO9660 Volume Descriptor Set "
  614. "Terminator found\n");
  615. break;
  616. default:
  617. udf_debug("ISO9660 VRS (%u) found\n",
  618. vsd->structType);
  619. break;
  620. }
  621. } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01,
  622. VSD_STD_ID_LEN))
  623. ; /* nothing */
  624. else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01,
  625. VSD_STD_ID_LEN)) {
  626. brelse(bh);
  627. break;
  628. } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02,
  629. VSD_STD_ID_LEN))
  630. nsr02 = sector;
  631. else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03,
  632. VSD_STD_ID_LEN))
  633. nsr03 = sector;
  634. brelse(bh);
  635. }
  636. if (nsr03)
  637. return nsr03;
  638. else if (nsr02)
  639. return nsr02;
  640. else if (sector - (sbi->s_session << sb->s_blocksize_bits) == 32768)
  641. return -1;
  642. else
  643. return 0;
  644. }
  645. /*
  646. * Check whether there is an anchor block in the given block
  647. */
  648. static int udf_check_anchor_block(struct super_block *sb, sector_t block)
  649. {
  650. struct buffer_head *bh;
  651. uint16_t ident;
  652. if (UDF_QUERY_FLAG(sb, UDF_FLAG_VARCONV) &&
  653. udf_fixed_to_variable(block) >=
  654. sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits)
  655. return 0;
  656. bh = udf_read_tagged(sb, block, block, &ident);
  657. if (!bh)
  658. return 0;
  659. brelse(bh);
  660. return ident == TAG_IDENT_AVDP;
  661. }
  662. /* Search for an anchor volume descriptor pointer */
  663. static sector_t udf_scan_anchors(struct super_block *sb, sector_t lastblock)
  664. {
  665. sector_t last[6];
  666. int i;
  667. struct udf_sb_info *sbi = UDF_SB(sb);
  668. last[0] = lastblock;
  669. last[1] = last[0] - 1;
  670. last[2] = last[0] + 1;
  671. last[3] = last[0] - 2;
  672. last[4] = last[0] - 150;
  673. last[5] = last[0] - 152;
  674. /* according to spec, anchor is in either:
  675. * block 256
  676. * lastblock-256
  677. * lastblock
  678. * however, if the disc isn't closed, it could be 512 */
  679. for (i = 0; i < ARRAY_SIZE(last); i++) {
  680. if (last[i] >= sb->s_bdev->bd_inode->i_size >>
  681. sb->s_blocksize_bits)
  682. continue;
  683. if (udf_check_anchor_block(sb, last[i])) {
  684. sbi->s_anchor[0] = last[i];
  685. sbi->s_anchor[1] = last[i] - 256;
  686. return last[i];
  687. }
  688. if (last[i] < 256)
  689. continue;
  690. if (udf_check_anchor_block(sb, last[i] - 256)) {
  691. sbi->s_anchor[1] = last[i] - 256;
  692. return last[i];
  693. }
  694. }
  695. if (udf_check_anchor_block(sb, sbi->s_session + 256)) {
  696. sbi->s_anchor[0] = sbi->s_session + 256;
  697. return last[0];
  698. }
  699. if (udf_check_anchor_block(sb, sbi->s_session + 512)) {
  700. sbi->s_anchor[0] = sbi->s_session + 512;
  701. return last[0];
  702. }
  703. return 0;
  704. }
  705. /*
  706. * Find an anchor volume descriptor. The function expects sbi->s_lastblock to
  707. * be the last block on the media.
  708. *
  709. * Return 1 if not found, 0 if ok
  710. *
  711. */
  712. static void udf_find_anchor(struct super_block *sb)
  713. {
  714. sector_t lastblock;
  715. struct buffer_head *bh = NULL;
  716. uint16_t ident;
  717. int i;
  718. struct udf_sb_info *sbi = UDF_SB(sb);
  719. lastblock = udf_scan_anchors(sb, sbi->s_last_block);
  720. if (lastblock)
  721. goto check_anchor;
  722. /* No anchor found? Try VARCONV conversion of block numbers */
  723. UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
  724. /* Firstly, we try to not convert number of the last block */
  725. lastblock = udf_scan_anchors(sb,
  726. udf_variable_to_fixed(sbi->s_last_block));
  727. if (lastblock)
  728. goto check_anchor;
  729. /* Secondly, we try with converted number of the last block */
  730. lastblock = udf_scan_anchors(sb, sbi->s_last_block);
  731. if (!lastblock) {
  732. /* VARCONV didn't help. Clear it. */
  733. UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV);
  734. }
  735. check_anchor:
  736. /*
  737. * Check located anchors and the anchor block supplied via
  738. * mount options
  739. */
  740. for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
  741. if (!sbi->s_anchor[i])
  742. continue;
  743. bh = udf_read_tagged(sb, sbi->s_anchor[i],
  744. sbi->s_anchor[i], &ident);
  745. if (!bh)
  746. sbi->s_anchor[i] = 0;
  747. else {
  748. brelse(bh);
  749. if (ident != TAG_IDENT_AVDP)
  750. sbi->s_anchor[i] = 0;
  751. }
  752. }
  753. sbi->s_last_block = lastblock;
  754. }
  755. static int udf_find_fileset(struct super_block *sb,
  756. struct kernel_lb_addr *fileset,
  757. struct kernel_lb_addr *root)
  758. {
  759. struct buffer_head *bh = NULL;
  760. long lastblock;
  761. uint16_t ident;
  762. struct udf_sb_info *sbi;
  763. if (fileset->logicalBlockNum != 0xFFFFFFFF ||
  764. fileset->partitionReferenceNum != 0xFFFF) {
  765. bh = udf_read_ptagged(sb, fileset, 0, &ident);
  766. if (!bh) {
  767. return 1;
  768. } else if (ident != TAG_IDENT_FSD) {
  769. brelse(bh);
  770. return 1;
  771. }
  772. }
  773. sbi = UDF_SB(sb);
  774. if (!bh) {
  775. /* Search backwards through the partitions */
  776. struct kernel_lb_addr newfileset;
  777. /* --> cvg: FIXME - is it reasonable? */
  778. return 1;
  779. for (newfileset.partitionReferenceNum = sbi->s_partitions - 1;
  780. (newfileset.partitionReferenceNum != 0xFFFF &&
  781. fileset->logicalBlockNum == 0xFFFFFFFF &&
  782. fileset->partitionReferenceNum == 0xFFFF);
  783. newfileset.partitionReferenceNum--) {
  784. lastblock = sbi->s_partmaps
  785. [newfileset.partitionReferenceNum]
  786. .s_partition_len;
  787. newfileset.logicalBlockNum = 0;
  788. do {
  789. bh = udf_read_ptagged(sb, &newfileset, 0,
  790. &ident);
  791. if (!bh) {
  792. newfileset.logicalBlockNum++;
  793. continue;
  794. }
  795. switch (ident) {
  796. case TAG_IDENT_SBD:
  797. {
  798. struct spaceBitmapDesc *sp;
  799. sp = (struct spaceBitmapDesc *)
  800. bh->b_data;
  801. newfileset.logicalBlockNum += 1 +
  802. ((le32_to_cpu(sp->numOfBytes) +
  803. sizeof(struct spaceBitmapDesc)
  804. - 1) >> sb->s_blocksize_bits);
  805. brelse(bh);
  806. break;
  807. }
  808. case TAG_IDENT_FSD:
  809. *fileset = newfileset;
  810. break;
  811. default:
  812. newfileset.logicalBlockNum++;
  813. brelse(bh);
  814. bh = NULL;
  815. break;
  816. }
  817. } while (newfileset.logicalBlockNum < lastblock &&
  818. fileset->logicalBlockNum == 0xFFFFFFFF &&
  819. fileset->partitionReferenceNum == 0xFFFF);
  820. }
  821. }
  822. if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
  823. fileset->partitionReferenceNum != 0xFFFF) && bh) {
  824. udf_debug("Fileset at block=%d, partition=%d\n",
  825. fileset->logicalBlockNum,
  826. fileset->partitionReferenceNum);
  827. sbi->s_partition = fileset->partitionReferenceNum;
  828. udf_load_fileset(sb, bh, root);
  829. brelse(bh);
  830. return 0;
  831. }
  832. return 1;
  833. }
  834. static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
  835. {
  836. struct primaryVolDesc *pvoldesc;
  837. struct ustr *instr, *outstr;
  838. struct buffer_head *bh;
  839. uint16_t ident;
  840. int ret = 1;
  841. instr = kmalloc(sizeof(struct ustr), GFP_NOFS);
  842. if (!instr)
  843. return 1;
  844. outstr = kmalloc(sizeof(struct ustr), GFP_NOFS);
  845. if (!outstr)
  846. goto out1;
  847. bh = udf_read_tagged(sb, block, block, &ident);
  848. if (!bh)
  849. goto out2;
  850. BUG_ON(ident != TAG_IDENT_PVD);
  851. pvoldesc = (struct primaryVolDesc *)bh->b_data;
  852. if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
  853. pvoldesc->recordingDateAndTime)) {
  854. #ifdef UDFFS_DEBUG
  855. struct timestamp *ts = &pvoldesc->recordingDateAndTime;
  856. udf_debug("recording time %04u/%02u/%02u"
  857. " %02u:%02u (%x)\n",
  858. le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
  859. ts->minute, le16_to_cpu(ts->typeAndTimezone));
  860. #endif
  861. }
  862. if (!udf_build_ustr(instr, pvoldesc->volIdent, 32))
  863. if (udf_CS0toUTF8(outstr, instr)) {
  864. strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name,
  865. outstr->u_len > 31 ? 31 : outstr->u_len);
  866. udf_debug("volIdent[] = '%s'\n",
  867. UDF_SB(sb)->s_volume_ident);
  868. }
  869. if (!udf_build_ustr(instr, pvoldesc->volSetIdent, 128))
  870. if (udf_CS0toUTF8(outstr, instr))
  871. udf_debug("volSetIdent[] = '%s'\n", outstr->u_name);
  872. brelse(bh);
  873. ret = 0;
  874. out2:
  875. kfree(outstr);
  876. out1:
  877. kfree(instr);
  878. return ret;
  879. }
  880. static int udf_load_metadata_files(struct super_block *sb, int partition)
  881. {
  882. struct udf_sb_info *sbi = UDF_SB(sb);
  883. struct udf_part_map *map;
  884. struct udf_meta_data *mdata;
  885. struct kernel_lb_addr addr;
  886. int fe_error = 0;
  887. map = &sbi->s_partmaps[partition];
  888. mdata = &map->s_type_specific.s_metadata;
  889. /* metadata address */
  890. addr.logicalBlockNum = mdata->s_meta_file_loc;
  891. addr.partitionReferenceNum = map->s_partition_num;
  892. udf_debug("Metadata file location: block = %d part = %d\n",
  893. addr.logicalBlockNum, addr.partitionReferenceNum);
  894. mdata->s_metadata_fe = udf_iget(sb, &addr);
  895. if (mdata->s_metadata_fe == NULL) {
  896. udf_warning(sb, __func__, "metadata inode efe not found, "
  897. "will try mirror inode.");
  898. fe_error = 1;
  899. } else if (UDF_I(mdata->s_metadata_fe)->i_alloc_type !=
  900. ICBTAG_FLAG_AD_SHORT) {
  901. udf_warning(sb, __func__, "metadata inode efe does not have "
  902. "short allocation descriptors!");
  903. fe_error = 1;
  904. iput(mdata->s_metadata_fe);
  905. mdata->s_metadata_fe = NULL;
  906. }
  907. /* mirror file entry */
  908. addr.logicalBlockNum = mdata->s_mirror_file_loc;
  909. addr.partitionReferenceNum = map->s_partition_num;
  910. udf_debug("Mirror metadata file location: block = %d part = %d\n",
  911. addr.logicalBlockNum, addr.partitionReferenceNum);
  912. mdata->s_mirror_fe = udf_iget(sb, &addr);
  913. if (mdata->s_mirror_fe == NULL) {
  914. if (fe_error) {
  915. udf_error(sb, __func__, "mirror inode efe not found "
  916. "and metadata inode is missing too, exiting...");
  917. goto error_exit;
  918. } else
  919. udf_warning(sb, __func__, "mirror inode efe not found,"
  920. " but metadata inode is OK");
  921. } else if (UDF_I(mdata->s_mirror_fe)->i_alloc_type !=
  922. ICBTAG_FLAG_AD_SHORT) {
  923. udf_warning(sb, __func__, "mirror inode efe does not have "
  924. "short allocation descriptors!");
  925. iput(mdata->s_mirror_fe);
  926. mdata->s_mirror_fe = NULL;
  927. if (fe_error)
  928. goto error_exit;
  929. }
  930. /*
  931. * bitmap file entry
  932. * Note:
  933. * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
  934. */
  935. if (mdata->s_bitmap_file_loc != 0xFFFFFFFF) {
  936. addr.logicalBlockNum = mdata->s_bitmap_file_loc;
  937. addr.partitionReferenceNum = map->s_partition_num;
  938. udf_debug("Bitmap file location: block = %d part = %d\n",
  939. addr.logicalBlockNum, addr.partitionReferenceNum);
  940. mdata->s_bitmap_fe = udf_iget(sb, &addr);
  941. if (mdata->s_bitmap_fe == NULL) {
  942. if (sb->s_flags & MS_RDONLY)
  943. udf_warning(sb, __func__, "bitmap inode efe "
  944. "not found but it's ok since the disc"
  945. " is mounted read-only");
  946. else {
  947. udf_error(sb, __func__, "bitmap inode efe not "
  948. "found and attempted read-write mount");
  949. goto error_exit;
  950. }
  951. }
  952. }
  953. udf_debug("udf_load_metadata_files Ok\n");
  954. return 0;
  955. error_exit:
  956. return 1;
  957. }
  958. static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
  959. struct kernel_lb_addr *root)
  960. {
  961. struct fileSetDesc *fset;
  962. fset = (struct fileSetDesc *)bh->b_data;
  963. *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
  964. UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum);
  965. udf_debug("Rootdir at block=%d, partition=%d\n",
  966. root->logicalBlockNum, root->partitionReferenceNum);
  967. }
  968. int udf_compute_nr_groups(struct super_block *sb, u32 partition)
  969. {
  970. struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
  971. return DIV_ROUND_UP(map->s_partition_len +
  972. (sizeof(struct spaceBitmapDesc) << 3),
  973. sb->s_blocksize * 8);
  974. }
  975. static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
  976. {
  977. struct udf_bitmap *bitmap;
  978. int nr_groups;
  979. int size;
  980. nr_groups = udf_compute_nr_groups(sb, index);
  981. size = sizeof(struct udf_bitmap) +
  982. (sizeof(struct buffer_head *) * nr_groups);
  983. if (size <= PAGE_SIZE)
  984. bitmap = kmalloc(size, GFP_KERNEL);
  985. else
  986. bitmap = vmalloc(size); /* TODO: get rid of vmalloc */
  987. if (bitmap == NULL) {
  988. udf_error(sb, __func__,
  989. "Unable to allocate space for bitmap "
  990. "and %d buffer_head pointers", nr_groups);
  991. return NULL;
  992. }
  993. memset(bitmap, 0x00, size);
  994. bitmap->s_block_bitmap = (struct buffer_head **)(bitmap + 1);
  995. bitmap->s_nr_groups = nr_groups;
  996. return bitmap;
  997. }
  998. static int udf_fill_partdesc_info(struct super_block *sb,
  999. struct partitionDesc *p, int p_index)
  1000. {
  1001. struct udf_part_map *map;
  1002. struct udf_sb_info *sbi = UDF_SB(sb);
  1003. struct partitionHeaderDesc *phd;
  1004. map = &sbi->s_partmaps[p_index];
  1005. map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */
  1006. map->s_partition_root = le32_to_cpu(p->partitionStartingLocation);
  1007. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
  1008. map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
  1009. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
  1010. map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
  1011. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
  1012. map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
  1013. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
  1014. map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
  1015. udf_debug("Partition (%d type %x) starts at physical %d, "
  1016. "block length %d\n", p_index,
  1017. map->s_partition_type, map->s_partition_root,
  1018. map->s_partition_len);
  1019. if (strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) &&
  1020. strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
  1021. return 0;
  1022. phd = (struct partitionHeaderDesc *)p->partitionContentsUse;
  1023. if (phd->unallocSpaceTable.extLength) {
  1024. struct kernel_lb_addr loc = {
  1025. .logicalBlockNum = le32_to_cpu(
  1026. phd->unallocSpaceTable.extPosition),
  1027. .partitionReferenceNum = p_index,
  1028. };
  1029. map->s_uspace.s_table = udf_iget(sb, &loc);
  1030. if (!map->s_uspace.s_table) {
  1031. udf_debug("cannot load unallocSpaceTable (part %d)\n",
  1032. p_index);
  1033. return 1;
  1034. }
  1035. map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE;
  1036. udf_debug("unallocSpaceTable (part %d) @ %ld\n",
  1037. p_index, map->s_uspace.s_table->i_ino);
  1038. }
  1039. if (phd->unallocSpaceBitmap.extLength) {
  1040. struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
  1041. if (!bitmap)
  1042. return 1;
  1043. map->s_uspace.s_bitmap = bitmap;
  1044. bitmap->s_extLength = le32_to_cpu(
  1045. phd->unallocSpaceBitmap.extLength);
  1046. bitmap->s_extPosition = le32_to_cpu(
  1047. phd->unallocSpaceBitmap.extPosition);
  1048. map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
  1049. udf_debug("unallocSpaceBitmap (part %d) @ %d\n", p_index,
  1050. bitmap->s_extPosition);
  1051. }
  1052. if (phd->partitionIntegrityTable.extLength)
  1053. udf_debug("partitionIntegrityTable (part %d)\n", p_index);
  1054. if (phd->freedSpaceTable.extLength) {
  1055. struct kernel_lb_addr loc = {
  1056. .logicalBlockNum = le32_to_cpu(
  1057. phd->freedSpaceTable.extPosition),
  1058. .partitionReferenceNum = p_index,
  1059. };
  1060. map->s_fspace.s_table = udf_iget(sb, &loc);
  1061. if (!map->s_fspace.s_table) {
  1062. udf_debug("cannot load freedSpaceTable (part %d)\n",
  1063. p_index);
  1064. return 1;
  1065. }
  1066. map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE;
  1067. udf_debug("freedSpaceTable (part %d) @ %ld\n",
  1068. p_index, map->s_fspace.s_table->i_ino);
  1069. }
  1070. if (phd->freedSpaceBitmap.extLength) {
  1071. struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
  1072. if (!bitmap)
  1073. return 1;
  1074. map->s_fspace.s_bitmap = bitmap;
  1075. bitmap->s_extLength = le32_to_cpu(
  1076. phd->freedSpaceBitmap.extLength);
  1077. bitmap->s_extPosition = le32_to_cpu(
  1078. phd->freedSpaceBitmap.extPosition);
  1079. map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
  1080. udf_debug("freedSpaceBitmap (part %d) @ %d\n", p_index,
  1081. bitmap->s_extPosition);
  1082. }
  1083. return 0;
  1084. }
  1085. static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
  1086. {
  1087. struct udf_sb_info *sbi = UDF_SB(sb);
  1088. struct udf_part_map *map = &sbi->s_partmaps[p_index];
  1089. struct kernel_lb_addr ino;
  1090. struct buffer_head *bh = NULL;
  1091. struct udf_inode_info *vati;
  1092. uint32_t pos;
  1093. struct virtualAllocationTable20 *vat20;
  1094. /* VAT file entry is in the last recorded block */
  1095. ino.partitionReferenceNum = type1_index;
  1096. ino.logicalBlockNum = sbi->s_last_block - map->s_partition_root;
  1097. sbi->s_vat_inode = udf_iget(sb, &ino);
  1098. if (!sbi->s_vat_inode)
  1099. return 1;
  1100. if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
  1101. map->s_type_specific.s_virtual.s_start_offset = 0;
  1102. map->s_type_specific.s_virtual.s_num_entries =
  1103. (sbi->s_vat_inode->i_size - 36) >> 2;
  1104. } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
  1105. vati = UDF_I(sbi->s_vat_inode);
  1106. if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
  1107. pos = udf_block_map(sbi->s_vat_inode, 0);
  1108. bh = sb_bread(sb, pos);
  1109. if (!bh)
  1110. return 1;
  1111. vat20 = (struct virtualAllocationTable20 *)bh->b_data;
  1112. } else {
  1113. vat20 = (struct virtualAllocationTable20 *)
  1114. vati->i_ext.i_data;
  1115. }
  1116. map->s_type_specific.s_virtual.s_start_offset =
  1117. le16_to_cpu(vat20->lengthHeader);
  1118. map->s_type_specific.s_virtual.s_num_entries =
  1119. (sbi->s_vat_inode->i_size -
  1120. map->s_type_specific.s_virtual.
  1121. s_start_offset) >> 2;
  1122. brelse(bh);
  1123. }
  1124. return 0;
  1125. }
  1126. static int udf_load_partdesc(struct super_block *sb, sector_t block)
  1127. {
  1128. struct buffer_head *bh;
  1129. struct partitionDesc *p;
  1130. struct udf_part_map *map;
  1131. struct udf_sb_info *sbi = UDF_SB(sb);
  1132. int i, type1_idx;
  1133. uint16_t partitionNumber;
  1134. uint16_t ident;
  1135. int ret = 0;
  1136. bh = udf_read_tagged(sb, block, block, &ident);
  1137. if (!bh)
  1138. return 1;
  1139. if (ident != TAG_IDENT_PD)
  1140. goto out_bh;
  1141. p = (struct partitionDesc *)bh->b_data;
  1142. partitionNumber = le16_to_cpu(p->partitionNumber);
  1143. /* First scan for TYPE1, SPARABLE and METADATA partitions */
  1144. for (i = 0; i < sbi->s_partitions; i++) {
  1145. map = &sbi->s_partmaps[i];
  1146. udf_debug("Searching map: (%d == %d)\n",
  1147. map->s_partition_num, partitionNumber);
  1148. if (map->s_partition_num == partitionNumber &&
  1149. (map->s_partition_type == UDF_TYPE1_MAP15 ||
  1150. map->s_partition_type == UDF_SPARABLE_MAP15))
  1151. break;
  1152. }
  1153. if (i >= sbi->s_partitions) {
  1154. udf_debug("Partition (%d) not found in partition map\n",
  1155. partitionNumber);
  1156. goto out_bh;
  1157. }
  1158. ret = udf_fill_partdesc_info(sb, p, i);
  1159. /*
  1160. * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
  1161. * PHYSICAL partitions are already set up
  1162. */
  1163. type1_idx = i;
  1164. for (i = 0; i < sbi->s_partitions; i++) {
  1165. map = &sbi->s_partmaps[i];
  1166. if (map->s_partition_num == partitionNumber &&
  1167. (map->s_partition_type == UDF_VIRTUAL_MAP15 ||
  1168. map->s_partition_type == UDF_VIRTUAL_MAP20 ||
  1169. map->s_partition_type == UDF_METADATA_MAP25))
  1170. break;
  1171. }
  1172. if (i >= sbi->s_partitions)
  1173. goto out_bh;
  1174. ret = udf_fill_partdesc_info(sb, p, i);
  1175. if (ret)
  1176. goto out_bh;
  1177. if (map->s_partition_type == UDF_METADATA_MAP25) {
  1178. ret = udf_load_metadata_files(sb, i);
  1179. if (ret) {
  1180. printk(KERN_ERR "UDF-fs: error loading MetaData "
  1181. "partition map %d\n", i);
  1182. goto out_bh;
  1183. }
  1184. } else {
  1185. ret = udf_load_vat(sb, i, type1_idx);
  1186. if (ret)
  1187. goto out_bh;
  1188. /*
  1189. * Mark filesystem read-only if we have a partition with
  1190. * virtual map since we don't handle writing to it (we
  1191. * overwrite blocks instead of relocating them).
  1192. */
  1193. sb->s_flags |= MS_RDONLY;
  1194. printk(KERN_NOTICE "UDF-fs: Filesystem marked read-only "
  1195. "because writing to pseudooverwrite partition is "
  1196. "not implemented.\n");
  1197. }
  1198. out_bh:
  1199. /* In case loading failed, we handle cleanup in udf_fill_super */
  1200. brelse(bh);
  1201. return ret;
  1202. }
  1203. static int udf_load_logicalvol(struct super_block *sb, sector_t block,
  1204. struct kernel_lb_addr *fileset)
  1205. {
  1206. struct logicalVolDesc *lvd;
  1207. int i, j, offset;
  1208. uint8_t type;
  1209. struct udf_sb_info *sbi = UDF_SB(sb);
  1210. struct genericPartitionMap *gpm;
  1211. uint16_t ident;
  1212. struct buffer_head *bh;
  1213. int ret = 0;
  1214. bh = udf_read_tagged(sb, block, block, &ident);
  1215. if (!bh)
  1216. return 1;
  1217. BUG_ON(ident != TAG_IDENT_LVD);
  1218. lvd = (struct logicalVolDesc *)bh->b_data;
  1219. i = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
  1220. if (i != 0) {
  1221. ret = i;
  1222. goto out_bh;
  1223. }
  1224. for (i = 0, offset = 0;
  1225. i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength);
  1226. i++, offset += gpm->partitionMapLength) {
  1227. struct udf_part_map *map = &sbi->s_partmaps[i];
  1228. gpm = (struct genericPartitionMap *)
  1229. &(lvd->partitionMaps[offset]);
  1230. type = gpm->partitionMapType;
  1231. if (type == 1) {
  1232. struct genericPartitionMap1 *gpm1 =
  1233. (struct genericPartitionMap1 *)gpm;
  1234. map->s_partition_type = UDF_TYPE1_MAP15;
  1235. map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum);
  1236. map->s_partition_num = le16_to_cpu(gpm1->partitionNum);
  1237. map->s_partition_func = NULL;
  1238. } else if (type == 2) {
  1239. struct udfPartitionMap2 *upm2 =
  1240. (struct udfPartitionMap2 *)gpm;
  1241. if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL,
  1242. strlen(UDF_ID_VIRTUAL))) {
  1243. u16 suf =
  1244. le16_to_cpu(((__le16 *)upm2->partIdent.
  1245. identSuffix)[0]);
  1246. if (suf < 0x0200) {
  1247. map->s_partition_type =
  1248. UDF_VIRTUAL_MAP15;
  1249. map->s_partition_func =
  1250. udf_get_pblock_virt15;
  1251. } else {
  1252. map->s_partition_type =
  1253. UDF_VIRTUAL_MAP20;
  1254. map->s_partition_func =
  1255. udf_get_pblock_virt20;
  1256. }
  1257. } else if (!strncmp(upm2->partIdent.ident,
  1258. UDF_ID_SPARABLE,
  1259. strlen(UDF_ID_SPARABLE))) {
  1260. uint32_t loc;
  1261. struct sparingTable *st;
  1262. struct sparablePartitionMap *spm =
  1263. (struct sparablePartitionMap *)gpm;
  1264. map->s_partition_type = UDF_SPARABLE_MAP15;
  1265. map->s_type_specific.s_sparing.s_packet_len =
  1266. le16_to_cpu(spm->packetLength);
  1267. for (j = 0; j < spm->numSparingTables; j++) {
  1268. struct buffer_head *bh2;
  1269. loc = le32_to_cpu(
  1270. spm->locSparingTable[j]);
  1271. bh2 = udf_read_tagged(sb, loc, loc,
  1272. &ident);
  1273. map->s_type_specific.s_sparing.
  1274. s_spar_map[j] = bh2;
  1275. if (bh2 == NULL)
  1276. continue;
  1277. st = (struct sparingTable *)bh2->b_data;
  1278. if (ident != 0 || strncmp(
  1279. st->sparingIdent.ident,
  1280. UDF_ID_SPARING,
  1281. strlen(UDF_ID_SPARING))) {
  1282. brelse(bh2);
  1283. map->s_type_specific.s_sparing.
  1284. s_spar_map[j] = NULL;
  1285. }
  1286. }
  1287. map->s_partition_func = udf_get_pblock_spar15;
  1288. } else if (!strncmp(upm2->partIdent.ident,
  1289. UDF_ID_METADATA,
  1290. strlen(UDF_ID_METADATA))) {
  1291. struct udf_meta_data *mdata =
  1292. &map->s_type_specific.s_metadata;
  1293. struct metadataPartitionMap *mdm =
  1294. (struct metadataPartitionMap *)
  1295. &(lvd->partitionMaps[offset]);
  1296. udf_debug("Parsing Logical vol part %d "
  1297. "type %d id=%s\n", i, type,
  1298. UDF_ID_METADATA);
  1299. map->s_partition_type = UDF_METADATA_MAP25;
  1300. map->s_partition_func = udf_get_pblock_meta25;
  1301. mdata->s_meta_file_loc =
  1302. le32_to_cpu(mdm->metadataFileLoc);
  1303. mdata->s_mirror_file_loc =
  1304. le32_to_cpu(mdm->metadataMirrorFileLoc);
  1305. mdata->s_bitmap_file_loc =
  1306. le32_to_cpu(mdm->metadataBitmapFileLoc);
  1307. mdata->s_alloc_unit_size =
  1308. le32_to_cpu(mdm->allocUnitSize);
  1309. mdata->s_align_unit_size =
  1310. le16_to_cpu(mdm->alignUnitSize);
  1311. mdata->s_dup_md_flag =
  1312. mdm->flags & 0x01;
  1313. udf_debug("Metadata Ident suffix=0x%x\n",
  1314. (le16_to_cpu(
  1315. ((__le16 *)
  1316. mdm->partIdent.identSuffix)[0])));
  1317. udf_debug("Metadata part num=%d\n",
  1318. le16_to_cpu(mdm->partitionNum));
  1319. udf_debug("Metadata part alloc unit size=%d\n",
  1320. le32_to_cpu(mdm->allocUnitSize));
  1321. udf_debug("Metadata file loc=%d\n",
  1322. le32_to_cpu(mdm->metadataFileLoc));
  1323. udf_debug("Mirror file loc=%d\n",
  1324. le32_to_cpu(mdm->metadataMirrorFileLoc));
  1325. udf_debug("Bitmap file loc=%d\n",
  1326. le32_to_cpu(mdm->metadataBitmapFileLoc));
  1327. udf_debug("Duplicate Flag: %d %d\n",
  1328. mdata->s_dup_md_flag, mdm->flags);
  1329. } else {
  1330. udf_debug("Unknown ident: %s\n",
  1331. upm2->partIdent.ident);
  1332. continue;
  1333. }
  1334. map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum);
  1335. map->s_partition_num = le16_to_cpu(upm2->partitionNum);
  1336. }
  1337. udf_debug("Partition (%d:%d) type %d on volume %d\n",
  1338. i, map->s_partition_num, type,
  1339. map->s_volumeseqnum);
  1340. }
  1341. if (fileset) {
  1342. struct long_ad *la = (struct long_ad *)&(lvd->logicalVolContentsUse[0]);
  1343. *fileset = lelb_to_cpu(la->extLocation);
  1344. udf_debug("FileSet found in LogicalVolDesc at block=%d, "
  1345. "partition=%d\n", fileset->logicalBlockNum,
  1346. fileset->partitionReferenceNum);
  1347. }
  1348. if (lvd->integritySeqExt.extLength)
  1349. udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
  1350. out_bh:
  1351. brelse(bh);
  1352. return ret;
  1353. }
  1354. /*
  1355. * udf_load_logicalvolint
  1356. *
  1357. */
  1358. static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_ad loc)
  1359. {
  1360. struct buffer_head *bh = NULL;
  1361. uint16_t ident;
  1362. struct udf_sb_info *sbi = UDF_SB(sb);
  1363. struct logicalVolIntegrityDesc *lvid;
  1364. while (loc.extLength > 0 &&
  1365. (bh = udf_read_tagged(sb, loc.extLocation,
  1366. loc.extLocation, &ident)) &&
  1367. ident == TAG_IDENT_LVID) {
  1368. sbi->s_lvid_bh = bh;
  1369. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1370. if (lvid->nextIntegrityExt.extLength)
  1371. udf_load_logicalvolint(sb,
  1372. leea_to_cpu(lvid->nextIntegrityExt));
  1373. if (sbi->s_lvid_bh != bh)
  1374. brelse(bh);
  1375. loc.extLength -= sb->s_blocksize;
  1376. loc.extLocation++;
  1377. }
  1378. if (sbi->s_lvid_bh != bh)
  1379. brelse(bh);
  1380. }
  1381. /*
  1382. * udf_process_sequence
  1383. *
  1384. * PURPOSE
  1385. * Process a main/reserve volume descriptor sequence.
  1386. *
  1387. * PRE-CONDITIONS
  1388. * sb Pointer to _locked_ superblock.
  1389. * block First block of first extent of the sequence.
  1390. * lastblock Lastblock of first extent of the sequence.
  1391. *
  1392. * HISTORY
  1393. * July 1, 1997 - Andrew E. Mileski
  1394. * Written, tested, and released.
  1395. */
  1396. static noinline int udf_process_sequence(struct super_block *sb, long block,
  1397. long lastblock, struct kernel_lb_addr *fileset)
  1398. {
  1399. struct buffer_head *bh = NULL;
  1400. struct udf_vds_record vds[VDS_POS_LENGTH];
  1401. struct udf_vds_record *curr;
  1402. struct generic_desc *gd;
  1403. struct volDescPtr *vdp;
  1404. int done = 0;
  1405. uint32_t vdsn;
  1406. uint16_t ident;
  1407. long next_s = 0, next_e = 0;
  1408. memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
  1409. /*
  1410. * Read the main descriptor sequence and find which descriptors
  1411. * are in it.
  1412. */
  1413. for (; (!done && block <= lastblock); block++) {
  1414. bh = udf_read_tagged(sb, block, block, &ident);
  1415. if (!bh) {
  1416. printk(KERN_ERR "udf: Block %Lu of volume descriptor "
  1417. "sequence is corrupted or we could not read "
  1418. "it.\n", (unsigned long long)block);
  1419. return 1;
  1420. }
  1421. /* Process each descriptor (ISO 13346 3/8.3-8.4) */
  1422. gd = (struct generic_desc *)bh->b_data;
  1423. vdsn = le32_to_cpu(gd->volDescSeqNum);
  1424. switch (ident) {
  1425. case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
  1426. curr = &vds[VDS_POS_PRIMARY_VOL_DESC];
  1427. if (vdsn >= curr->volDescSeqNum) {
  1428. curr->volDescSeqNum = vdsn;
  1429. curr->block = block;
  1430. }
  1431. break;
  1432. case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
  1433. curr = &vds[VDS_POS_VOL_DESC_PTR];
  1434. if (vdsn >= curr->volDescSeqNum) {
  1435. curr->volDescSeqNum = vdsn;
  1436. curr->block = block;
  1437. vdp = (struct volDescPtr *)bh->b_data;
  1438. next_s = le32_to_cpu(
  1439. vdp->nextVolDescSeqExt.extLocation);
  1440. next_e = le32_to_cpu(
  1441. vdp->nextVolDescSeqExt.extLength);
  1442. next_e = next_e >> sb->s_blocksize_bits;
  1443. next_e += next_s;
  1444. }
  1445. break;
  1446. case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
  1447. curr = &vds[VDS_POS_IMP_USE_VOL_DESC];
  1448. if (vdsn >= curr->volDescSeqNum) {
  1449. curr->volDescSeqNum = vdsn;
  1450. curr->block = block;
  1451. }
  1452. break;
  1453. case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
  1454. curr = &vds[VDS_POS_PARTITION_DESC];
  1455. if (!curr->block)
  1456. curr->block = block;
  1457. break;
  1458. case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
  1459. curr = &vds[VDS_POS_LOGICAL_VOL_DESC];
  1460. if (vdsn >= curr->volDescSeqNum) {
  1461. curr->volDescSeqNum = vdsn;
  1462. curr->block = block;
  1463. }
  1464. break;
  1465. case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
  1466. curr = &vds[VDS_POS_UNALLOC_SPACE_DESC];
  1467. if (vdsn >= curr->volDescSeqNum) {
  1468. curr->volDescSeqNum = vdsn;
  1469. curr->block = block;
  1470. }
  1471. break;
  1472. case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
  1473. vds[VDS_POS_TERMINATING_DESC].block = block;
  1474. if (next_e) {
  1475. block = next_s;
  1476. lastblock = next_e;
  1477. next_s = next_e = 0;
  1478. } else
  1479. done = 1;
  1480. break;
  1481. }
  1482. brelse(bh);
  1483. }
  1484. /*
  1485. * Now read interesting descriptors again and process them
  1486. * in a suitable order
  1487. */
  1488. if (!vds[VDS_POS_PRIMARY_VOL_DESC].block) {
  1489. printk(KERN_ERR "udf: Primary Volume Descriptor not found!\n");
  1490. return 1;
  1491. }
  1492. if (udf_load_pvoldesc(sb, vds[VDS_POS_PRIMARY_VOL_DESC].block))
  1493. return 1;
  1494. if (vds[VDS_POS_LOGICAL_VOL_DESC].block && udf_load_logicalvol(sb,
  1495. vds[VDS_POS_LOGICAL_VOL_DESC].block, fileset))
  1496. return 1;
  1497. if (vds[VDS_POS_PARTITION_DESC].block) {
  1498. /*
  1499. * We rescan the whole descriptor sequence to find
  1500. * partition descriptor blocks and process them.
  1501. */
  1502. for (block = vds[VDS_POS_PARTITION_DESC].block;
  1503. block < vds[VDS_POS_TERMINATING_DESC].block;
  1504. block++)
  1505. if (udf_load_partdesc(sb, block))
  1506. return 1;
  1507. }
  1508. return 0;
  1509. }
  1510. /*
  1511. * udf_check_valid()
  1512. */
  1513. static int udf_check_valid(struct super_block *sb, int novrs, int silent)
  1514. {
  1515. long block;
  1516. struct udf_sb_info *sbi = UDF_SB(sb);
  1517. if (novrs) {
  1518. udf_debug("Validity check skipped because of novrs option\n");
  1519. return 0;
  1520. }
  1521. /* Check that it is NSR02 compliant */
  1522. /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
  1523. block = udf_vrs(sb, silent);
  1524. if (block == -1)
  1525. udf_debug("Failed to read byte 32768. Assuming open "
  1526. "disc. Skipping validity check\n");
  1527. if (block && !sbi->s_last_block)
  1528. sbi->s_last_block = udf_get_last_block(sb);
  1529. return !block;
  1530. }
  1531. static int udf_load_sequence(struct super_block *sb, struct kernel_lb_addr *fileset)
  1532. {
  1533. struct anchorVolDescPtr *anchor;
  1534. uint16_t ident;
  1535. struct buffer_head *bh;
  1536. long main_s, main_e, reserve_s, reserve_e;
  1537. int i;
  1538. struct udf_sb_info *sbi;
  1539. if (!sb)
  1540. return 1;
  1541. sbi = UDF_SB(sb);
  1542. for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
  1543. if (!sbi->s_anchor[i])
  1544. continue;
  1545. bh = udf_read_tagged(sb, sbi->s_anchor[i], sbi->s_anchor[i],
  1546. &ident);
  1547. if (!bh)
  1548. continue;
  1549. anchor = (struct anchorVolDescPtr *)bh->b_data;
  1550. /* Locate the main sequence */
  1551. main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
  1552. main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
  1553. main_e = main_e >> sb->s_blocksize_bits;
  1554. main_e += main_s;
  1555. /* Locate the reserve sequence */
  1556. reserve_s = le32_to_cpu(
  1557. anchor->reserveVolDescSeqExt.extLocation);
  1558. reserve_e = le32_to_cpu(
  1559. anchor->reserveVolDescSeqExt.extLength);
  1560. reserve_e = reserve_e >> sb->s_blocksize_bits;
  1561. reserve_e += reserve_s;
  1562. brelse(bh);
  1563. /* Process the main & reserve sequences */
  1564. /* responsible for finding the PartitionDesc(s) */
  1565. if (!(udf_process_sequence(sb, main_s, main_e,
  1566. fileset) &&
  1567. udf_process_sequence(sb, reserve_s, reserve_e,
  1568. fileset)))
  1569. break;
  1570. }
  1571. if (i == ARRAY_SIZE(sbi->s_anchor)) {
  1572. udf_debug("No Anchor block found\n");
  1573. return 1;
  1574. }
  1575. udf_debug("Using anchor in block %d\n", sbi->s_anchor[i]);
  1576. return 0;
  1577. }
  1578. static void udf_open_lvid(struct super_block *sb)
  1579. {
  1580. struct udf_sb_info *sbi = UDF_SB(sb);
  1581. struct buffer_head *bh = sbi->s_lvid_bh;
  1582. struct logicalVolIntegrityDesc *lvid;
  1583. struct logicalVolIntegrityDescImpUse *lvidiu;
  1584. if (!bh)
  1585. return;
  1586. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1587. lvidiu = udf_sb_lvidiu(sbi);
  1588. lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1589. lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1590. udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
  1591. CURRENT_TIME);
  1592. lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
  1593. lvid->descTag.descCRC = cpu_to_le16(
  1594. crc_itu_t(0, (char *)lvid + sizeof(struct tag),
  1595. le16_to_cpu(lvid->descTag.descCRCLength)));
  1596. lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
  1597. mark_buffer_dirty(bh);
  1598. }
  1599. static void udf_close_lvid(struct super_block *sb)
  1600. {
  1601. struct udf_sb_info *sbi = UDF_SB(sb);
  1602. struct buffer_head *bh = sbi->s_lvid_bh;
  1603. struct logicalVolIntegrityDesc *lvid;
  1604. struct logicalVolIntegrityDescImpUse *lvidiu;
  1605. if (!bh)
  1606. return;
  1607. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1608. if (lvid->integrityType != LVID_INTEGRITY_TYPE_OPEN)
  1609. return;
  1610. lvidiu = udf_sb_lvidiu(sbi);
  1611. lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1612. lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1613. udf_time_to_disk_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
  1614. if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
  1615. lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
  1616. if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
  1617. lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
  1618. if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
  1619. lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
  1620. lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
  1621. lvid->descTag.descCRC = cpu_to_le16(
  1622. crc_itu_t(0, (char *)lvid + sizeof(struct tag),
  1623. le16_to_cpu(lvid->descTag.descCRCLength)));
  1624. lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
  1625. mark_buffer_dirty(bh);
  1626. }
  1627. static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
  1628. {
  1629. int i;
  1630. int nr_groups = bitmap->s_nr_groups;
  1631. int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) *
  1632. nr_groups);
  1633. for (i = 0; i < nr_groups; i++)
  1634. if (bitmap->s_block_bitmap[i])
  1635. brelse(bitmap->s_block_bitmap[i]);
  1636. if (size <= PAGE_SIZE)
  1637. kfree(bitmap);
  1638. else
  1639. vfree(bitmap);
  1640. }
  1641. static void udf_free_partition(struct udf_part_map *map)
  1642. {
  1643. int i;
  1644. struct udf_meta_data *mdata;
  1645. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
  1646. iput(map->s_uspace.s_table);
  1647. if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
  1648. iput(map->s_fspace.s_table);
  1649. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
  1650. udf_sb_free_bitmap(map->s_uspace.s_bitmap);
  1651. if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
  1652. udf_sb_free_bitmap(map->s_fspace.s_bitmap);
  1653. if (map->s_partition_type == UDF_SPARABLE_MAP15)
  1654. for (i = 0; i < 4; i++)
  1655. brelse(map->s_type_specific.s_sparing.s_spar_map[i]);
  1656. else if (map->s_partition_type == UDF_METADATA_MAP25) {
  1657. mdata = &map->s_type_specific.s_metadata;
  1658. iput(mdata->s_metadata_fe);
  1659. mdata->s_metadata_fe = NULL;
  1660. iput(mdata->s_mirror_fe);
  1661. mdata->s_mirror_fe = NULL;
  1662. iput(mdata->s_bitmap_fe);
  1663. mdata->s_bitmap_fe = NULL;
  1664. }
  1665. }
  1666. static int udf_fill_super(struct super_block *sb, void *options, int silent)
  1667. {
  1668. int i;
  1669. struct inode *inode = NULL;
  1670. struct udf_options uopt;
  1671. struct kernel_lb_addr rootdir, fileset;
  1672. struct udf_sb_info *sbi;
  1673. uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
  1674. uopt.uid = -1;
  1675. uopt.gid = -1;
  1676. uopt.umask = 0;
  1677. uopt.fmode = UDF_INVALID_MODE;
  1678. uopt.dmode = UDF_INVALID_MODE;
  1679. sbi = kzalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
  1680. if (!sbi)
  1681. return -ENOMEM;
  1682. sb->s_fs_info = sbi;
  1683. mutex_init(&sbi->s_alloc_mutex);
  1684. if (!udf_parse_options((char *)options, &uopt, false))
  1685. goto error_out;
  1686. if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
  1687. uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
  1688. udf_error(sb, "udf_read_super",
  1689. "utf8 cannot be combined with iocharset\n");
  1690. goto error_out;
  1691. }
  1692. #ifdef CONFIG_UDF_NLS
  1693. if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
  1694. uopt.nls_map = load_nls_default();
  1695. if (!uopt.nls_map)
  1696. uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
  1697. else
  1698. udf_debug("Using default NLS map\n");
  1699. }
  1700. #endif
  1701. if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
  1702. uopt.flags |= (1 << UDF_FLAG_UTF8);
  1703. fileset.logicalBlockNum = 0xFFFFFFFF;
  1704. fileset.partitionReferenceNum = 0xFFFF;
  1705. sbi->s_flags = uopt.flags;
  1706. sbi->s_uid = uopt.uid;
  1707. sbi->s_gid = uopt.gid;
  1708. sbi->s_umask = uopt.umask;
  1709. sbi->s_fmode = uopt.fmode;
  1710. sbi->s_dmode = uopt.dmode;
  1711. sbi->s_nls_map = uopt.nls_map;
  1712. /* Set the block size for all transfers */
  1713. if (!sb_min_blocksize(sb, uopt.blocksize)) {
  1714. udf_debug("Bad block size (%d)\n", uopt.blocksize);
  1715. printk(KERN_ERR "udf: bad block size (%d)\n", uopt.blocksize);
  1716. goto error_out;
  1717. }
  1718. if (uopt.session == 0xFFFFFFFF)
  1719. sbi->s_session = udf_get_last_session(sb);
  1720. else
  1721. sbi->s_session = uopt.session;
  1722. udf_debug("Multi-session=%d\n", sbi->s_session);
  1723. sbi->s_last_block = uopt.lastblock;
  1724. sbi->s_anchor[0] = sbi->s_anchor[1] = 0;
  1725. sbi->s_anchor[2] = uopt.anchor;
  1726. if (udf_check_valid(sb, uopt.novrs, silent)) {
  1727. /* read volume recognition sequences */
  1728. printk(KERN_WARNING "UDF-fs: No VRS found\n");
  1729. goto error_out;
  1730. }
  1731. udf_find_anchor(sb);
  1732. /* Fill in the rest of the superblock */
  1733. sb->s_op = &udf_sb_ops;
  1734. sb->s_export_op = &udf_export_ops;
  1735. sb->dq_op = NULL;
  1736. sb->s_dirt = 0;
  1737. sb->s_magic = UDF_SUPER_MAGIC;
  1738. sb->s_time_gran = 1000;
  1739. if (udf_load_sequence(sb, &fileset)) {
  1740. printk(KERN_WARNING "UDF-fs: No partition found (1)\n");
  1741. goto error_out;
  1742. }
  1743. udf_debug("Lastblock=%d\n", sbi->s_last_block);
  1744. if (sbi->s_lvid_bh) {
  1745. struct logicalVolIntegrityDescImpUse *lvidiu =
  1746. udf_sb_lvidiu(sbi);
  1747. uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev);
  1748. uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev);
  1749. /* uint16_t maxUDFWriteRev =
  1750. le16_to_cpu(lvidiu->maxUDFWriteRev); */
  1751. if (minUDFReadRev > UDF_MAX_READ_VERSION) {
  1752. printk(KERN_ERR "UDF-fs: minUDFReadRev=%x "
  1753. "(max is %x)\n",
  1754. le16_to_cpu(lvidiu->minUDFReadRev),
  1755. UDF_MAX_READ_VERSION);
  1756. goto error_out;
  1757. } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
  1758. sb->s_flags |= MS_RDONLY;
  1759. sbi->s_udfrev = minUDFWriteRev;
  1760. if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
  1761. UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
  1762. if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
  1763. UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
  1764. }
  1765. if (!sbi->s_partitions) {
  1766. printk(KERN_WARNING "UDF-fs: No partition found (2)\n");
  1767. goto error_out;
  1768. }
  1769. if (sbi->s_partmaps[sbi->s_partition].s_partition_flags &
  1770. UDF_PART_FLAG_READ_ONLY) {
  1771. printk(KERN_NOTICE "UDF-fs: Partition marked readonly; "
  1772. "forcing readonly mount\n");
  1773. sb->s_flags |= MS_RDONLY;
  1774. }
  1775. if (udf_find_fileset(sb, &fileset, &rootdir)) {
  1776. printk(KERN_WARNING "UDF-fs: No fileset found\n");
  1777. goto error_out;
  1778. }
  1779. if (!silent) {
  1780. struct timestamp ts;
  1781. udf_time_to_disk_stamp(&ts, sbi->s_record_time);
  1782. udf_info("UDF: Mounting volume '%s', "
  1783. "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
  1784. sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day,
  1785. ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
  1786. }
  1787. if (!(sb->s_flags & MS_RDONLY))
  1788. udf_open_lvid(sb);
  1789. /* Assign the root inode */
  1790. /* assign inodes by physical block number */
  1791. /* perhaps it's not extensible enough, but for now ... */
  1792. inode = udf_iget(sb, &rootdir);
  1793. if (!inode) {
  1794. printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, "
  1795. "partition=%d\n",
  1796. rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
  1797. goto error_out;
  1798. }
  1799. /* Allocate a dentry for the root inode */
  1800. sb->s_root = d_alloc_root(inode);
  1801. if (!sb->s_root) {
  1802. printk(KERN_ERR "UDF-fs: Couldn't allocate root dentry\n");
  1803. iput(inode);
  1804. goto error_out;
  1805. }
  1806. sb->s_maxbytes = MAX_LFS_FILESIZE;
  1807. return 0;
  1808. error_out:
  1809. if (sbi->s_vat_inode)
  1810. iput(sbi->s_vat_inode);
  1811. if (sbi->s_partitions)
  1812. for (i = 0; i < sbi->s_partitions; i++)
  1813. udf_free_partition(&sbi->s_partmaps[i]);
  1814. #ifdef CONFIG_UDF_NLS
  1815. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1816. unload_nls(sbi->s_nls_map);
  1817. #endif
  1818. if (!(sb->s_flags & MS_RDONLY))
  1819. udf_close_lvid(sb);
  1820. brelse(sbi->s_lvid_bh);
  1821. kfree(sbi->s_partmaps);
  1822. kfree(sbi);
  1823. sb->s_fs_info = NULL;
  1824. return -EINVAL;
  1825. }
  1826. static void udf_error(struct super_block *sb, const char *function,
  1827. const char *fmt, ...)
  1828. {
  1829. va_list args;
  1830. if (!(sb->s_flags & MS_RDONLY)) {
  1831. /* mark sb error */
  1832. sb->s_dirt = 1;
  1833. }
  1834. va_start(args, fmt);
  1835. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1836. va_end(args);
  1837. printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
  1838. sb->s_id, function, error_buf);
  1839. }
  1840. void udf_warning(struct super_block *sb, const char *function,
  1841. const char *fmt, ...)
  1842. {
  1843. va_list args;
  1844. va_start(args, fmt);
  1845. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1846. va_end(args);
  1847. printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
  1848. sb->s_id, function, error_buf);
  1849. }
  1850. static void udf_put_super(struct super_block *sb)
  1851. {
  1852. int i;
  1853. struct udf_sb_info *sbi;
  1854. sbi = UDF_SB(sb);
  1855. if (sbi->s_vat_inode)
  1856. iput(sbi->s_vat_inode);
  1857. if (sbi->s_partitions)
  1858. for (i = 0; i < sbi->s_partitions; i++)
  1859. udf_free_partition(&sbi->s_partmaps[i]);
  1860. #ifdef CONFIG_UDF_NLS
  1861. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1862. unload_nls(sbi->s_nls_map);
  1863. #endif
  1864. if (!(sb->s_flags & MS_RDONLY))
  1865. udf_close_lvid(sb);
  1866. brelse(sbi->s_lvid_bh);
  1867. kfree(sbi->s_partmaps);
  1868. kfree(sb->s_fs_info);
  1869. sb->s_fs_info = NULL;
  1870. }
  1871. static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
  1872. {
  1873. struct super_block *sb = dentry->d_sb;
  1874. struct udf_sb_info *sbi = UDF_SB(sb);
  1875. struct logicalVolIntegrityDescImpUse *lvidiu;
  1876. if (sbi->s_lvid_bh != NULL)
  1877. lvidiu = udf_sb_lvidiu(sbi);
  1878. else
  1879. lvidiu = NULL;
  1880. buf->f_type = UDF_SUPER_MAGIC;
  1881. buf->f_bsize = sb->s_blocksize;
  1882. buf->f_blocks = sbi->s_partmaps[sbi->s_partition].s_partition_len;
  1883. buf->f_bfree = udf_count_free(sb);
  1884. buf->f_bavail = buf->f_bfree;
  1885. buf->f_files = (lvidiu != NULL ? (le32_to_cpu(lvidiu->numFiles) +
  1886. le32_to_cpu(lvidiu->numDirs)) : 0)
  1887. + buf->f_bfree;
  1888. buf->f_ffree = buf->f_bfree;
  1889. /* __kernel_fsid_t f_fsid */
  1890. buf->f_namelen = UDF_NAME_LEN - 2;
  1891. return 0;
  1892. }
  1893. static unsigned int udf_count_free_bitmap(struct super_block *sb,
  1894. struct udf_bitmap *bitmap)
  1895. {
  1896. struct buffer_head *bh = NULL;
  1897. unsigned int accum = 0;
  1898. int index;
  1899. int block = 0, newblock;
  1900. struct kernel_lb_addr loc;
  1901. uint32_t bytes;
  1902. uint8_t *ptr;
  1903. uint16_t ident;
  1904. struct spaceBitmapDesc *bm;
  1905. lock_kernel();
  1906. loc.logicalBlockNum = bitmap->s_extPosition;
  1907. loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
  1908. bh = udf_read_ptagged(sb, &loc, 0, &ident);
  1909. if (!bh) {
  1910. printk(KERN_ERR "udf: udf_count_free failed\n");
  1911. goto out;
  1912. } else if (ident != TAG_IDENT_SBD) {
  1913. brelse(bh);
  1914. printk(KERN_ERR "udf: udf_count_free failed\n");
  1915. goto out;
  1916. }
  1917. bm = (struct spaceBitmapDesc *)bh->b_data;
  1918. bytes = le32_to_cpu(bm->numOfBytes);
  1919. index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
  1920. ptr = (uint8_t *)bh->b_data;
  1921. while (bytes > 0) {
  1922. u32 cur_bytes = min_t(u32, bytes, sb->s_blocksize - index);
  1923. accum += bitmap_weight((const unsigned long *)(ptr + index),
  1924. cur_bytes * 8);
  1925. bytes -= cur_bytes;
  1926. if (bytes) {
  1927. brelse(bh);
  1928. newblock = udf_get_lb_pblock(sb, &loc, ++block);
  1929. bh = udf_tread(sb, newblock);
  1930. if (!bh) {
  1931. udf_debug("read failed\n");
  1932. goto out;
  1933. }
  1934. index = 0;
  1935. ptr = (uint8_t *)bh->b_data;
  1936. }
  1937. }
  1938. brelse(bh);
  1939. out:
  1940. unlock_kernel();
  1941. return accum;
  1942. }
  1943. static unsigned int udf_count_free_table(struct super_block *sb,
  1944. struct inode *table)
  1945. {
  1946. unsigned int accum = 0;
  1947. uint32_t elen;
  1948. struct kernel_lb_addr eloc;
  1949. int8_t etype;
  1950. struct extent_position epos;
  1951. lock_kernel();
  1952. epos.block = UDF_I(table)->i_location;
  1953. epos.offset = sizeof(struct unallocSpaceEntry);
  1954. epos.bh = NULL;
  1955. while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
  1956. accum += (elen >> table->i_sb->s_blocksize_bits);
  1957. brelse(epos.bh);
  1958. unlock_kernel();
  1959. return accum;
  1960. }
  1961. static unsigned int udf_count_free(struct super_block *sb)
  1962. {
  1963. unsigned int accum = 0;
  1964. struct udf_sb_info *sbi;
  1965. struct udf_part_map *map;
  1966. sbi = UDF_SB(sb);
  1967. if (sbi->s_lvid_bh) {
  1968. struct logicalVolIntegrityDesc *lvid =
  1969. (struct logicalVolIntegrityDesc *)
  1970. sbi->s_lvid_bh->b_data;
  1971. if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) {
  1972. accum = le32_to_cpu(
  1973. lvid->freeSpaceTable[sbi->s_partition]);
  1974. if (accum == 0xFFFFFFFF)
  1975. accum = 0;
  1976. }
  1977. }
  1978. if (accum)
  1979. return accum;
  1980. map = &sbi->s_partmaps[sbi->s_partition];
  1981. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
  1982. accum += udf_count_free_bitmap(sb,
  1983. map->s_uspace.s_bitmap);
  1984. }
  1985. if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) {
  1986. accum += udf_count_free_bitmap(sb,
  1987. map->s_fspace.s_bitmap);
  1988. }
  1989. if (accum)
  1990. return accum;
  1991. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
  1992. accum += udf_count_free_table(sb,
  1993. map->s_uspace.s_table);
  1994. }
  1995. if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) {
  1996. accum += udf_count_free_table(sb,
  1997. map->s_fspace.s_table);
  1998. }
  1999. return accum;
  2000. }