super.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283
  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. int last_count = 0;
  669. last[last_count++] = lastblock;
  670. if (lastblock >= 1)
  671. last[last_count++] = lastblock - 1;
  672. last[last_count++] = lastblock + 1;
  673. if (lastblock >= 2)
  674. last[last_count++] = lastblock - 2;
  675. if (lastblock >= 150)
  676. last[last_count++] = lastblock - 150;
  677. if (lastblock >= 152)
  678. last[last_count++] = lastblock - 152;
  679. /* according to spec, anchor is in either:
  680. * block 256
  681. * lastblock-256
  682. * lastblock
  683. * however, if the disc isn't closed, it could be 512 */
  684. for (i = 0; i < last_count; i++) {
  685. if (last[i] >= sb->s_bdev->bd_inode->i_size >>
  686. sb->s_blocksize_bits)
  687. continue;
  688. if (udf_check_anchor_block(sb, last[i])) {
  689. sbi->s_anchor[0] = last[i];
  690. sbi->s_anchor[1] = last[i] - 256;
  691. return last[i];
  692. }
  693. if (last[i] < 256)
  694. continue;
  695. if (udf_check_anchor_block(sb, last[i] - 256)) {
  696. sbi->s_anchor[1] = last[i] - 256;
  697. return last[i];
  698. }
  699. }
  700. if (udf_check_anchor_block(sb, sbi->s_session + 256)) {
  701. sbi->s_anchor[0] = sbi->s_session + 256;
  702. return last[0];
  703. }
  704. if (udf_check_anchor_block(sb, sbi->s_session + 512)) {
  705. sbi->s_anchor[0] = sbi->s_session + 512;
  706. return last[0];
  707. }
  708. return 0;
  709. }
  710. /*
  711. * Find an anchor volume descriptor. The function expects sbi->s_lastblock to
  712. * be the last block on the media.
  713. *
  714. * Return 1 if not found, 0 if ok
  715. *
  716. */
  717. static void udf_find_anchor(struct super_block *sb)
  718. {
  719. sector_t lastblock;
  720. struct buffer_head *bh = NULL;
  721. uint16_t ident;
  722. int i;
  723. struct udf_sb_info *sbi = UDF_SB(sb);
  724. lastblock = udf_scan_anchors(sb, sbi->s_last_block);
  725. if (lastblock)
  726. goto check_anchor;
  727. /* No anchor found? Try VARCONV conversion of block numbers */
  728. UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
  729. /* Firstly, we try to not convert number of the last block */
  730. lastblock = udf_scan_anchors(sb,
  731. udf_variable_to_fixed(sbi->s_last_block));
  732. if (lastblock)
  733. goto check_anchor;
  734. /* Secondly, we try with converted number of the last block */
  735. lastblock = udf_scan_anchors(sb, sbi->s_last_block);
  736. if (!lastblock) {
  737. /* VARCONV didn't help. Clear it. */
  738. UDF_CLEAR_FLAG(sb, UDF_FLAG_VARCONV);
  739. }
  740. check_anchor:
  741. /*
  742. * Check located anchors and the anchor block supplied via
  743. * mount options
  744. */
  745. for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
  746. if (!sbi->s_anchor[i])
  747. continue;
  748. bh = udf_read_tagged(sb, sbi->s_anchor[i],
  749. sbi->s_anchor[i], &ident);
  750. if (!bh)
  751. sbi->s_anchor[i] = 0;
  752. else {
  753. brelse(bh);
  754. if (ident != TAG_IDENT_AVDP)
  755. sbi->s_anchor[i] = 0;
  756. }
  757. }
  758. sbi->s_last_block = lastblock;
  759. }
  760. static int udf_find_fileset(struct super_block *sb,
  761. struct kernel_lb_addr *fileset,
  762. struct kernel_lb_addr *root)
  763. {
  764. struct buffer_head *bh = NULL;
  765. long lastblock;
  766. uint16_t ident;
  767. struct udf_sb_info *sbi;
  768. if (fileset->logicalBlockNum != 0xFFFFFFFF ||
  769. fileset->partitionReferenceNum != 0xFFFF) {
  770. bh = udf_read_ptagged(sb, fileset, 0, &ident);
  771. if (!bh) {
  772. return 1;
  773. } else if (ident != TAG_IDENT_FSD) {
  774. brelse(bh);
  775. return 1;
  776. }
  777. }
  778. sbi = UDF_SB(sb);
  779. if (!bh) {
  780. /* Search backwards through the partitions */
  781. struct kernel_lb_addr newfileset;
  782. /* --> cvg: FIXME - is it reasonable? */
  783. return 1;
  784. for (newfileset.partitionReferenceNum = sbi->s_partitions - 1;
  785. (newfileset.partitionReferenceNum != 0xFFFF &&
  786. fileset->logicalBlockNum == 0xFFFFFFFF &&
  787. fileset->partitionReferenceNum == 0xFFFF);
  788. newfileset.partitionReferenceNum--) {
  789. lastblock = sbi->s_partmaps
  790. [newfileset.partitionReferenceNum]
  791. .s_partition_len;
  792. newfileset.logicalBlockNum = 0;
  793. do {
  794. bh = udf_read_ptagged(sb, &newfileset, 0,
  795. &ident);
  796. if (!bh) {
  797. newfileset.logicalBlockNum++;
  798. continue;
  799. }
  800. switch (ident) {
  801. case TAG_IDENT_SBD:
  802. {
  803. struct spaceBitmapDesc *sp;
  804. sp = (struct spaceBitmapDesc *)
  805. bh->b_data;
  806. newfileset.logicalBlockNum += 1 +
  807. ((le32_to_cpu(sp->numOfBytes) +
  808. sizeof(struct spaceBitmapDesc)
  809. - 1) >> sb->s_blocksize_bits);
  810. brelse(bh);
  811. break;
  812. }
  813. case TAG_IDENT_FSD:
  814. *fileset = newfileset;
  815. break;
  816. default:
  817. newfileset.logicalBlockNum++;
  818. brelse(bh);
  819. bh = NULL;
  820. break;
  821. }
  822. } while (newfileset.logicalBlockNum < lastblock &&
  823. fileset->logicalBlockNum == 0xFFFFFFFF &&
  824. fileset->partitionReferenceNum == 0xFFFF);
  825. }
  826. }
  827. if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
  828. fileset->partitionReferenceNum != 0xFFFF) && bh) {
  829. udf_debug("Fileset at block=%d, partition=%d\n",
  830. fileset->logicalBlockNum,
  831. fileset->partitionReferenceNum);
  832. sbi->s_partition = fileset->partitionReferenceNum;
  833. udf_load_fileset(sb, bh, root);
  834. brelse(bh);
  835. return 0;
  836. }
  837. return 1;
  838. }
  839. static int udf_load_pvoldesc(struct super_block *sb, sector_t block)
  840. {
  841. struct primaryVolDesc *pvoldesc;
  842. struct ustr *instr, *outstr;
  843. struct buffer_head *bh;
  844. uint16_t ident;
  845. int ret = 1;
  846. instr = kmalloc(sizeof(struct ustr), GFP_NOFS);
  847. if (!instr)
  848. return 1;
  849. outstr = kmalloc(sizeof(struct ustr), GFP_NOFS);
  850. if (!outstr)
  851. goto out1;
  852. bh = udf_read_tagged(sb, block, block, &ident);
  853. if (!bh)
  854. goto out2;
  855. BUG_ON(ident != TAG_IDENT_PVD);
  856. pvoldesc = (struct primaryVolDesc *)bh->b_data;
  857. if (udf_disk_stamp_to_time(&UDF_SB(sb)->s_record_time,
  858. pvoldesc->recordingDateAndTime)) {
  859. #ifdef UDFFS_DEBUG
  860. struct timestamp *ts = &pvoldesc->recordingDateAndTime;
  861. udf_debug("recording time %04u/%02u/%02u"
  862. " %02u:%02u (%x)\n",
  863. le16_to_cpu(ts->year), ts->month, ts->day, ts->hour,
  864. ts->minute, le16_to_cpu(ts->typeAndTimezone));
  865. #endif
  866. }
  867. if (!udf_build_ustr(instr, pvoldesc->volIdent, 32))
  868. if (udf_CS0toUTF8(outstr, instr)) {
  869. strncpy(UDF_SB(sb)->s_volume_ident, outstr->u_name,
  870. outstr->u_len > 31 ? 31 : outstr->u_len);
  871. udf_debug("volIdent[] = '%s'\n",
  872. UDF_SB(sb)->s_volume_ident);
  873. }
  874. if (!udf_build_ustr(instr, pvoldesc->volSetIdent, 128))
  875. if (udf_CS0toUTF8(outstr, instr))
  876. udf_debug("volSetIdent[] = '%s'\n", outstr->u_name);
  877. brelse(bh);
  878. ret = 0;
  879. out2:
  880. kfree(outstr);
  881. out1:
  882. kfree(instr);
  883. return ret;
  884. }
  885. static int udf_load_metadata_files(struct super_block *sb, int partition)
  886. {
  887. struct udf_sb_info *sbi = UDF_SB(sb);
  888. struct udf_part_map *map;
  889. struct udf_meta_data *mdata;
  890. struct kernel_lb_addr addr;
  891. int fe_error = 0;
  892. map = &sbi->s_partmaps[partition];
  893. mdata = &map->s_type_specific.s_metadata;
  894. /* metadata address */
  895. addr.logicalBlockNum = mdata->s_meta_file_loc;
  896. addr.partitionReferenceNum = map->s_partition_num;
  897. udf_debug("Metadata file location: block = %d part = %d\n",
  898. addr.logicalBlockNum, addr.partitionReferenceNum);
  899. mdata->s_metadata_fe = udf_iget(sb, &addr);
  900. if (mdata->s_metadata_fe == NULL) {
  901. udf_warning(sb, __func__, "metadata inode efe not found, "
  902. "will try mirror inode.");
  903. fe_error = 1;
  904. } else if (UDF_I(mdata->s_metadata_fe)->i_alloc_type !=
  905. ICBTAG_FLAG_AD_SHORT) {
  906. udf_warning(sb, __func__, "metadata inode efe does not have "
  907. "short allocation descriptors!");
  908. fe_error = 1;
  909. iput(mdata->s_metadata_fe);
  910. mdata->s_metadata_fe = NULL;
  911. }
  912. /* mirror file entry */
  913. addr.logicalBlockNum = mdata->s_mirror_file_loc;
  914. addr.partitionReferenceNum = map->s_partition_num;
  915. udf_debug("Mirror metadata file location: block = %d part = %d\n",
  916. addr.logicalBlockNum, addr.partitionReferenceNum);
  917. mdata->s_mirror_fe = udf_iget(sb, &addr);
  918. if (mdata->s_mirror_fe == NULL) {
  919. if (fe_error) {
  920. udf_error(sb, __func__, "mirror inode efe not found "
  921. "and metadata inode is missing too, exiting...");
  922. goto error_exit;
  923. } else
  924. udf_warning(sb, __func__, "mirror inode efe not found,"
  925. " but metadata inode is OK");
  926. } else if (UDF_I(mdata->s_mirror_fe)->i_alloc_type !=
  927. ICBTAG_FLAG_AD_SHORT) {
  928. udf_warning(sb, __func__, "mirror inode efe does not have "
  929. "short allocation descriptors!");
  930. iput(mdata->s_mirror_fe);
  931. mdata->s_mirror_fe = NULL;
  932. if (fe_error)
  933. goto error_exit;
  934. }
  935. /*
  936. * bitmap file entry
  937. * Note:
  938. * Load only if bitmap file location differs from 0xFFFFFFFF (DCN-5102)
  939. */
  940. if (mdata->s_bitmap_file_loc != 0xFFFFFFFF) {
  941. addr.logicalBlockNum = mdata->s_bitmap_file_loc;
  942. addr.partitionReferenceNum = map->s_partition_num;
  943. udf_debug("Bitmap file location: block = %d part = %d\n",
  944. addr.logicalBlockNum, addr.partitionReferenceNum);
  945. mdata->s_bitmap_fe = udf_iget(sb, &addr);
  946. if (mdata->s_bitmap_fe == NULL) {
  947. if (sb->s_flags & MS_RDONLY)
  948. udf_warning(sb, __func__, "bitmap inode efe "
  949. "not found but it's ok since the disc"
  950. " is mounted read-only");
  951. else {
  952. udf_error(sb, __func__, "bitmap inode efe not "
  953. "found and attempted read-write mount");
  954. goto error_exit;
  955. }
  956. }
  957. }
  958. udf_debug("udf_load_metadata_files Ok\n");
  959. return 0;
  960. error_exit:
  961. return 1;
  962. }
  963. static void udf_load_fileset(struct super_block *sb, struct buffer_head *bh,
  964. struct kernel_lb_addr *root)
  965. {
  966. struct fileSetDesc *fset;
  967. fset = (struct fileSetDesc *)bh->b_data;
  968. *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
  969. UDF_SB(sb)->s_serial_number = le16_to_cpu(fset->descTag.tagSerialNum);
  970. udf_debug("Rootdir at block=%d, partition=%d\n",
  971. root->logicalBlockNum, root->partitionReferenceNum);
  972. }
  973. int udf_compute_nr_groups(struct super_block *sb, u32 partition)
  974. {
  975. struct udf_part_map *map = &UDF_SB(sb)->s_partmaps[partition];
  976. return DIV_ROUND_UP(map->s_partition_len +
  977. (sizeof(struct spaceBitmapDesc) << 3),
  978. sb->s_blocksize * 8);
  979. }
  980. static struct udf_bitmap *udf_sb_alloc_bitmap(struct super_block *sb, u32 index)
  981. {
  982. struct udf_bitmap *bitmap;
  983. int nr_groups;
  984. int size;
  985. nr_groups = udf_compute_nr_groups(sb, index);
  986. size = sizeof(struct udf_bitmap) +
  987. (sizeof(struct buffer_head *) * nr_groups);
  988. if (size <= PAGE_SIZE)
  989. bitmap = kmalloc(size, GFP_KERNEL);
  990. else
  991. bitmap = vmalloc(size); /* TODO: get rid of vmalloc */
  992. if (bitmap == NULL) {
  993. udf_error(sb, __func__,
  994. "Unable to allocate space for bitmap "
  995. "and %d buffer_head pointers", nr_groups);
  996. return NULL;
  997. }
  998. memset(bitmap, 0x00, size);
  999. bitmap->s_block_bitmap = (struct buffer_head **)(bitmap + 1);
  1000. bitmap->s_nr_groups = nr_groups;
  1001. return bitmap;
  1002. }
  1003. static int udf_fill_partdesc_info(struct super_block *sb,
  1004. struct partitionDesc *p, int p_index)
  1005. {
  1006. struct udf_part_map *map;
  1007. struct udf_sb_info *sbi = UDF_SB(sb);
  1008. struct partitionHeaderDesc *phd;
  1009. map = &sbi->s_partmaps[p_index];
  1010. map->s_partition_len = le32_to_cpu(p->partitionLength); /* blocks */
  1011. map->s_partition_root = le32_to_cpu(p->partitionStartingLocation);
  1012. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_READ_ONLY))
  1013. map->s_partition_flags |= UDF_PART_FLAG_READ_ONLY;
  1014. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_WRITE_ONCE))
  1015. map->s_partition_flags |= UDF_PART_FLAG_WRITE_ONCE;
  1016. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_REWRITABLE))
  1017. map->s_partition_flags |= UDF_PART_FLAG_REWRITABLE;
  1018. if (p->accessType == cpu_to_le32(PD_ACCESS_TYPE_OVERWRITABLE))
  1019. map->s_partition_flags |= UDF_PART_FLAG_OVERWRITABLE;
  1020. udf_debug("Partition (%d type %x) starts at physical %d, "
  1021. "block length %d\n", p_index,
  1022. map->s_partition_type, map->s_partition_root,
  1023. map->s_partition_len);
  1024. if (strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) &&
  1025. strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
  1026. return 0;
  1027. phd = (struct partitionHeaderDesc *)p->partitionContentsUse;
  1028. if (phd->unallocSpaceTable.extLength) {
  1029. struct kernel_lb_addr loc = {
  1030. .logicalBlockNum = le32_to_cpu(
  1031. phd->unallocSpaceTable.extPosition),
  1032. .partitionReferenceNum = p_index,
  1033. };
  1034. map->s_uspace.s_table = udf_iget(sb, &loc);
  1035. if (!map->s_uspace.s_table) {
  1036. udf_debug("cannot load unallocSpaceTable (part %d)\n",
  1037. p_index);
  1038. return 1;
  1039. }
  1040. map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_TABLE;
  1041. udf_debug("unallocSpaceTable (part %d) @ %ld\n",
  1042. p_index, map->s_uspace.s_table->i_ino);
  1043. }
  1044. if (phd->unallocSpaceBitmap.extLength) {
  1045. struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
  1046. if (!bitmap)
  1047. return 1;
  1048. map->s_uspace.s_bitmap = bitmap;
  1049. bitmap->s_extLength = le32_to_cpu(
  1050. phd->unallocSpaceBitmap.extLength);
  1051. bitmap->s_extPosition = le32_to_cpu(
  1052. phd->unallocSpaceBitmap.extPosition);
  1053. map->s_partition_flags |= UDF_PART_FLAG_UNALLOC_BITMAP;
  1054. udf_debug("unallocSpaceBitmap (part %d) @ %d\n", p_index,
  1055. bitmap->s_extPosition);
  1056. }
  1057. if (phd->partitionIntegrityTable.extLength)
  1058. udf_debug("partitionIntegrityTable (part %d)\n", p_index);
  1059. if (phd->freedSpaceTable.extLength) {
  1060. struct kernel_lb_addr loc = {
  1061. .logicalBlockNum = le32_to_cpu(
  1062. phd->freedSpaceTable.extPosition),
  1063. .partitionReferenceNum = p_index,
  1064. };
  1065. map->s_fspace.s_table = udf_iget(sb, &loc);
  1066. if (!map->s_fspace.s_table) {
  1067. udf_debug("cannot load freedSpaceTable (part %d)\n",
  1068. p_index);
  1069. return 1;
  1070. }
  1071. map->s_partition_flags |= UDF_PART_FLAG_FREED_TABLE;
  1072. udf_debug("freedSpaceTable (part %d) @ %ld\n",
  1073. p_index, map->s_fspace.s_table->i_ino);
  1074. }
  1075. if (phd->freedSpaceBitmap.extLength) {
  1076. struct udf_bitmap *bitmap = udf_sb_alloc_bitmap(sb, p_index);
  1077. if (!bitmap)
  1078. return 1;
  1079. map->s_fspace.s_bitmap = bitmap;
  1080. bitmap->s_extLength = le32_to_cpu(
  1081. phd->freedSpaceBitmap.extLength);
  1082. bitmap->s_extPosition = le32_to_cpu(
  1083. phd->freedSpaceBitmap.extPosition);
  1084. map->s_partition_flags |= UDF_PART_FLAG_FREED_BITMAP;
  1085. udf_debug("freedSpaceBitmap (part %d) @ %d\n", p_index,
  1086. bitmap->s_extPosition);
  1087. }
  1088. return 0;
  1089. }
  1090. static int udf_load_vat(struct super_block *sb, int p_index, int type1_index)
  1091. {
  1092. struct udf_sb_info *sbi = UDF_SB(sb);
  1093. struct udf_part_map *map = &sbi->s_partmaps[p_index];
  1094. struct kernel_lb_addr ino;
  1095. struct buffer_head *bh = NULL;
  1096. struct udf_inode_info *vati;
  1097. uint32_t pos;
  1098. struct virtualAllocationTable20 *vat20;
  1099. /* VAT file entry is in the last recorded block */
  1100. ino.partitionReferenceNum = type1_index;
  1101. ino.logicalBlockNum = sbi->s_last_block - map->s_partition_root;
  1102. sbi->s_vat_inode = udf_iget(sb, &ino);
  1103. if (!sbi->s_vat_inode)
  1104. return 1;
  1105. if (map->s_partition_type == UDF_VIRTUAL_MAP15) {
  1106. map->s_type_specific.s_virtual.s_start_offset = 0;
  1107. map->s_type_specific.s_virtual.s_num_entries =
  1108. (sbi->s_vat_inode->i_size - 36) >> 2;
  1109. } else if (map->s_partition_type == UDF_VIRTUAL_MAP20) {
  1110. vati = UDF_I(sbi->s_vat_inode);
  1111. if (vati->i_alloc_type != ICBTAG_FLAG_AD_IN_ICB) {
  1112. pos = udf_block_map(sbi->s_vat_inode, 0);
  1113. bh = sb_bread(sb, pos);
  1114. if (!bh)
  1115. return 1;
  1116. vat20 = (struct virtualAllocationTable20 *)bh->b_data;
  1117. } else {
  1118. vat20 = (struct virtualAllocationTable20 *)
  1119. vati->i_ext.i_data;
  1120. }
  1121. map->s_type_specific.s_virtual.s_start_offset =
  1122. le16_to_cpu(vat20->lengthHeader);
  1123. map->s_type_specific.s_virtual.s_num_entries =
  1124. (sbi->s_vat_inode->i_size -
  1125. map->s_type_specific.s_virtual.
  1126. s_start_offset) >> 2;
  1127. brelse(bh);
  1128. }
  1129. return 0;
  1130. }
  1131. static int udf_load_partdesc(struct super_block *sb, sector_t block)
  1132. {
  1133. struct buffer_head *bh;
  1134. struct partitionDesc *p;
  1135. struct udf_part_map *map;
  1136. struct udf_sb_info *sbi = UDF_SB(sb);
  1137. int i, type1_idx;
  1138. uint16_t partitionNumber;
  1139. uint16_t ident;
  1140. int ret = 0;
  1141. bh = udf_read_tagged(sb, block, block, &ident);
  1142. if (!bh)
  1143. return 1;
  1144. if (ident != TAG_IDENT_PD)
  1145. goto out_bh;
  1146. p = (struct partitionDesc *)bh->b_data;
  1147. partitionNumber = le16_to_cpu(p->partitionNumber);
  1148. /* First scan for TYPE1, SPARABLE and METADATA partitions */
  1149. for (i = 0; i < sbi->s_partitions; i++) {
  1150. map = &sbi->s_partmaps[i];
  1151. udf_debug("Searching map: (%d == %d)\n",
  1152. map->s_partition_num, partitionNumber);
  1153. if (map->s_partition_num == partitionNumber &&
  1154. (map->s_partition_type == UDF_TYPE1_MAP15 ||
  1155. map->s_partition_type == UDF_SPARABLE_MAP15))
  1156. break;
  1157. }
  1158. if (i >= sbi->s_partitions) {
  1159. udf_debug("Partition (%d) not found in partition map\n",
  1160. partitionNumber);
  1161. goto out_bh;
  1162. }
  1163. ret = udf_fill_partdesc_info(sb, p, i);
  1164. /*
  1165. * Now rescan for VIRTUAL or METADATA partitions when SPARABLE and
  1166. * PHYSICAL partitions are already set up
  1167. */
  1168. type1_idx = i;
  1169. for (i = 0; i < sbi->s_partitions; i++) {
  1170. map = &sbi->s_partmaps[i];
  1171. if (map->s_partition_num == partitionNumber &&
  1172. (map->s_partition_type == UDF_VIRTUAL_MAP15 ||
  1173. map->s_partition_type == UDF_VIRTUAL_MAP20 ||
  1174. map->s_partition_type == UDF_METADATA_MAP25))
  1175. break;
  1176. }
  1177. if (i >= sbi->s_partitions)
  1178. goto out_bh;
  1179. ret = udf_fill_partdesc_info(sb, p, i);
  1180. if (ret)
  1181. goto out_bh;
  1182. if (map->s_partition_type == UDF_METADATA_MAP25) {
  1183. ret = udf_load_metadata_files(sb, i);
  1184. if (ret) {
  1185. printk(KERN_ERR "UDF-fs: error loading MetaData "
  1186. "partition map %d\n", i);
  1187. goto out_bh;
  1188. }
  1189. } else {
  1190. ret = udf_load_vat(sb, i, type1_idx);
  1191. if (ret)
  1192. goto out_bh;
  1193. /*
  1194. * Mark filesystem read-only if we have a partition with
  1195. * virtual map since we don't handle writing to it (we
  1196. * overwrite blocks instead of relocating them).
  1197. */
  1198. sb->s_flags |= MS_RDONLY;
  1199. printk(KERN_NOTICE "UDF-fs: Filesystem marked read-only "
  1200. "because writing to pseudooverwrite partition is "
  1201. "not implemented.\n");
  1202. }
  1203. out_bh:
  1204. /* In case loading failed, we handle cleanup in udf_fill_super */
  1205. brelse(bh);
  1206. return ret;
  1207. }
  1208. static int udf_load_logicalvol(struct super_block *sb, sector_t block,
  1209. struct kernel_lb_addr *fileset)
  1210. {
  1211. struct logicalVolDesc *lvd;
  1212. int i, j, offset;
  1213. uint8_t type;
  1214. struct udf_sb_info *sbi = UDF_SB(sb);
  1215. struct genericPartitionMap *gpm;
  1216. uint16_t ident;
  1217. struct buffer_head *bh;
  1218. int ret = 0;
  1219. bh = udf_read_tagged(sb, block, block, &ident);
  1220. if (!bh)
  1221. return 1;
  1222. BUG_ON(ident != TAG_IDENT_LVD);
  1223. lvd = (struct logicalVolDesc *)bh->b_data;
  1224. i = udf_sb_alloc_partition_maps(sb, le32_to_cpu(lvd->numPartitionMaps));
  1225. if (i != 0) {
  1226. ret = i;
  1227. goto out_bh;
  1228. }
  1229. for (i = 0, offset = 0;
  1230. i < sbi->s_partitions && offset < le32_to_cpu(lvd->mapTableLength);
  1231. i++, offset += gpm->partitionMapLength) {
  1232. struct udf_part_map *map = &sbi->s_partmaps[i];
  1233. gpm = (struct genericPartitionMap *)
  1234. &(lvd->partitionMaps[offset]);
  1235. type = gpm->partitionMapType;
  1236. if (type == 1) {
  1237. struct genericPartitionMap1 *gpm1 =
  1238. (struct genericPartitionMap1 *)gpm;
  1239. map->s_partition_type = UDF_TYPE1_MAP15;
  1240. map->s_volumeseqnum = le16_to_cpu(gpm1->volSeqNum);
  1241. map->s_partition_num = le16_to_cpu(gpm1->partitionNum);
  1242. map->s_partition_func = NULL;
  1243. } else if (type == 2) {
  1244. struct udfPartitionMap2 *upm2 =
  1245. (struct udfPartitionMap2 *)gpm;
  1246. if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL,
  1247. strlen(UDF_ID_VIRTUAL))) {
  1248. u16 suf =
  1249. le16_to_cpu(((__le16 *)upm2->partIdent.
  1250. identSuffix)[0]);
  1251. if (suf < 0x0200) {
  1252. map->s_partition_type =
  1253. UDF_VIRTUAL_MAP15;
  1254. map->s_partition_func =
  1255. udf_get_pblock_virt15;
  1256. } else {
  1257. map->s_partition_type =
  1258. UDF_VIRTUAL_MAP20;
  1259. map->s_partition_func =
  1260. udf_get_pblock_virt20;
  1261. }
  1262. } else if (!strncmp(upm2->partIdent.ident,
  1263. UDF_ID_SPARABLE,
  1264. strlen(UDF_ID_SPARABLE))) {
  1265. uint32_t loc;
  1266. struct sparingTable *st;
  1267. struct sparablePartitionMap *spm =
  1268. (struct sparablePartitionMap *)gpm;
  1269. map->s_partition_type = UDF_SPARABLE_MAP15;
  1270. map->s_type_specific.s_sparing.s_packet_len =
  1271. le16_to_cpu(spm->packetLength);
  1272. for (j = 0; j < spm->numSparingTables; j++) {
  1273. struct buffer_head *bh2;
  1274. loc = le32_to_cpu(
  1275. spm->locSparingTable[j]);
  1276. bh2 = udf_read_tagged(sb, loc, loc,
  1277. &ident);
  1278. map->s_type_specific.s_sparing.
  1279. s_spar_map[j] = bh2;
  1280. if (bh2 == NULL)
  1281. continue;
  1282. st = (struct sparingTable *)bh2->b_data;
  1283. if (ident != 0 || strncmp(
  1284. st->sparingIdent.ident,
  1285. UDF_ID_SPARING,
  1286. strlen(UDF_ID_SPARING))) {
  1287. brelse(bh2);
  1288. map->s_type_specific.s_sparing.
  1289. s_spar_map[j] = NULL;
  1290. }
  1291. }
  1292. map->s_partition_func = udf_get_pblock_spar15;
  1293. } else if (!strncmp(upm2->partIdent.ident,
  1294. UDF_ID_METADATA,
  1295. strlen(UDF_ID_METADATA))) {
  1296. struct udf_meta_data *mdata =
  1297. &map->s_type_specific.s_metadata;
  1298. struct metadataPartitionMap *mdm =
  1299. (struct metadataPartitionMap *)
  1300. &(lvd->partitionMaps[offset]);
  1301. udf_debug("Parsing Logical vol part %d "
  1302. "type %d id=%s\n", i, type,
  1303. UDF_ID_METADATA);
  1304. map->s_partition_type = UDF_METADATA_MAP25;
  1305. map->s_partition_func = udf_get_pblock_meta25;
  1306. mdata->s_meta_file_loc =
  1307. le32_to_cpu(mdm->metadataFileLoc);
  1308. mdata->s_mirror_file_loc =
  1309. le32_to_cpu(mdm->metadataMirrorFileLoc);
  1310. mdata->s_bitmap_file_loc =
  1311. le32_to_cpu(mdm->metadataBitmapFileLoc);
  1312. mdata->s_alloc_unit_size =
  1313. le32_to_cpu(mdm->allocUnitSize);
  1314. mdata->s_align_unit_size =
  1315. le16_to_cpu(mdm->alignUnitSize);
  1316. mdata->s_dup_md_flag =
  1317. mdm->flags & 0x01;
  1318. udf_debug("Metadata Ident suffix=0x%x\n",
  1319. (le16_to_cpu(
  1320. ((__le16 *)
  1321. mdm->partIdent.identSuffix)[0])));
  1322. udf_debug("Metadata part num=%d\n",
  1323. le16_to_cpu(mdm->partitionNum));
  1324. udf_debug("Metadata part alloc unit size=%d\n",
  1325. le32_to_cpu(mdm->allocUnitSize));
  1326. udf_debug("Metadata file loc=%d\n",
  1327. le32_to_cpu(mdm->metadataFileLoc));
  1328. udf_debug("Mirror file loc=%d\n",
  1329. le32_to_cpu(mdm->metadataMirrorFileLoc));
  1330. udf_debug("Bitmap file loc=%d\n",
  1331. le32_to_cpu(mdm->metadataBitmapFileLoc));
  1332. udf_debug("Duplicate Flag: %d %d\n",
  1333. mdata->s_dup_md_flag, mdm->flags);
  1334. } else {
  1335. udf_debug("Unknown ident: %s\n",
  1336. upm2->partIdent.ident);
  1337. continue;
  1338. }
  1339. map->s_volumeseqnum = le16_to_cpu(upm2->volSeqNum);
  1340. map->s_partition_num = le16_to_cpu(upm2->partitionNum);
  1341. }
  1342. udf_debug("Partition (%d:%d) type %d on volume %d\n",
  1343. i, map->s_partition_num, type,
  1344. map->s_volumeseqnum);
  1345. }
  1346. if (fileset) {
  1347. struct long_ad *la = (struct long_ad *)&(lvd->logicalVolContentsUse[0]);
  1348. *fileset = lelb_to_cpu(la->extLocation);
  1349. udf_debug("FileSet found in LogicalVolDesc at block=%d, "
  1350. "partition=%d\n", fileset->logicalBlockNum,
  1351. fileset->partitionReferenceNum);
  1352. }
  1353. if (lvd->integritySeqExt.extLength)
  1354. udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
  1355. out_bh:
  1356. brelse(bh);
  1357. return ret;
  1358. }
  1359. /*
  1360. * udf_load_logicalvolint
  1361. *
  1362. */
  1363. static void udf_load_logicalvolint(struct super_block *sb, struct kernel_extent_ad loc)
  1364. {
  1365. struct buffer_head *bh = NULL;
  1366. uint16_t ident;
  1367. struct udf_sb_info *sbi = UDF_SB(sb);
  1368. struct logicalVolIntegrityDesc *lvid;
  1369. while (loc.extLength > 0 &&
  1370. (bh = udf_read_tagged(sb, loc.extLocation,
  1371. loc.extLocation, &ident)) &&
  1372. ident == TAG_IDENT_LVID) {
  1373. sbi->s_lvid_bh = bh;
  1374. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1375. if (lvid->nextIntegrityExt.extLength)
  1376. udf_load_logicalvolint(sb,
  1377. leea_to_cpu(lvid->nextIntegrityExt));
  1378. if (sbi->s_lvid_bh != bh)
  1379. brelse(bh);
  1380. loc.extLength -= sb->s_blocksize;
  1381. loc.extLocation++;
  1382. }
  1383. if (sbi->s_lvid_bh != bh)
  1384. brelse(bh);
  1385. }
  1386. /*
  1387. * udf_process_sequence
  1388. *
  1389. * PURPOSE
  1390. * Process a main/reserve volume descriptor sequence.
  1391. *
  1392. * PRE-CONDITIONS
  1393. * sb Pointer to _locked_ superblock.
  1394. * block First block of first extent of the sequence.
  1395. * lastblock Lastblock of first extent of the sequence.
  1396. *
  1397. * HISTORY
  1398. * July 1, 1997 - Andrew E. Mileski
  1399. * Written, tested, and released.
  1400. */
  1401. static noinline int udf_process_sequence(struct super_block *sb, long block,
  1402. long lastblock, struct kernel_lb_addr *fileset)
  1403. {
  1404. struct buffer_head *bh = NULL;
  1405. struct udf_vds_record vds[VDS_POS_LENGTH];
  1406. struct udf_vds_record *curr;
  1407. struct generic_desc *gd;
  1408. struct volDescPtr *vdp;
  1409. int done = 0;
  1410. uint32_t vdsn;
  1411. uint16_t ident;
  1412. long next_s = 0, next_e = 0;
  1413. memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
  1414. /*
  1415. * Read the main descriptor sequence and find which descriptors
  1416. * are in it.
  1417. */
  1418. for (; (!done && block <= lastblock); block++) {
  1419. bh = udf_read_tagged(sb, block, block, &ident);
  1420. if (!bh) {
  1421. printk(KERN_ERR "udf: Block %Lu of volume descriptor "
  1422. "sequence is corrupted or we could not read "
  1423. "it.\n", (unsigned long long)block);
  1424. return 1;
  1425. }
  1426. /* Process each descriptor (ISO 13346 3/8.3-8.4) */
  1427. gd = (struct generic_desc *)bh->b_data;
  1428. vdsn = le32_to_cpu(gd->volDescSeqNum);
  1429. switch (ident) {
  1430. case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
  1431. curr = &vds[VDS_POS_PRIMARY_VOL_DESC];
  1432. if (vdsn >= curr->volDescSeqNum) {
  1433. curr->volDescSeqNum = vdsn;
  1434. curr->block = block;
  1435. }
  1436. break;
  1437. case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
  1438. curr = &vds[VDS_POS_VOL_DESC_PTR];
  1439. if (vdsn >= curr->volDescSeqNum) {
  1440. curr->volDescSeqNum = vdsn;
  1441. curr->block = block;
  1442. vdp = (struct volDescPtr *)bh->b_data;
  1443. next_s = le32_to_cpu(
  1444. vdp->nextVolDescSeqExt.extLocation);
  1445. next_e = le32_to_cpu(
  1446. vdp->nextVolDescSeqExt.extLength);
  1447. next_e = next_e >> sb->s_blocksize_bits;
  1448. next_e += next_s;
  1449. }
  1450. break;
  1451. case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
  1452. curr = &vds[VDS_POS_IMP_USE_VOL_DESC];
  1453. if (vdsn >= curr->volDescSeqNum) {
  1454. curr->volDescSeqNum = vdsn;
  1455. curr->block = block;
  1456. }
  1457. break;
  1458. case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
  1459. curr = &vds[VDS_POS_PARTITION_DESC];
  1460. if (!curr->block)
  1461. curr->block = block;
  1462. break;
  1463. case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
  1464. curr = &vds[VDS_POS_LOGICAL_VOL_DESC];
  1465. if (vdsn >= curr->volDescSeqNum) {
  1466. curr->volDescSeqNum = vdsn;
  1467. curr->block = block;
  1468. }
  1469. break;
  1470. case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
  1471. curr = &vds[VDS_POS_UNALLOC_SPACE_DESC];
  1472. if (vdsn >= curr->volDescSeqNum) {
  1473. curr->volDescSeqNum = vdsn;
  1474. curr->block = block;
  1475. }
  1476. break;
  1477. case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
  1478. vds[VDS_POS_TERMINATING_DESC].block = block;
  1479. if (next_e) {
  1480. block = next_s;
  1481. lastblock = next_e;
  1482. next_s = next_e = 0;
  1483. } else
  1484. done = 1;
  1485. break;
  1486. }
  1487. brelse(bh);
  1488. }
  1489. /*
  1490. * Now read interesting descriptors again and process them
  1491. * in a suitable order
  1492. */
  1493. if (!vds[VDS_POS_PRIMARY_VOL_DESC].block) {
  1494. printk(KERN_ERR "udf: Primary Volume Descriptor not found!\n");
  1495. return 1;
  1496. }
  1497. if (udf_load_pvoldesc(sb, vds[VDS_POS_PRIMARY_VOL_DESC].block))
  1498. return 1;
  1499. if (vds[VDS_POS_LOGICAL_VOL_DESC].block && udf_load_logicalvol(sb,
  1500. vds[VDS_POS_LOGICAL_VOL_DESC].block, fileset))
  1501. return 1;
  1502. if (vds[VDS_POS_PARTITION_DESC].block) {
  1503. /*
  1504. * We rescan the whole descriptor sequence to find
  1505. * partition descriptor blocks and process them.
  1506. */
  1507. for (block = vds[VDS_POS_PARTITION_DESC].block;
  1508. block < vds[VDS_POS_TERMINATING_DESC].block;
  1509. block++)
  1510. if (udf_load_partdesc(sb, block))
  1511. return 1;
  1512. }
  1513. return 0;
  1514. }
  1515. /*
  1516. * udf_check_valid()
  1517. */
  1518. static int udf_check_valid(struct super_block *sb, int novrs, int silent)
  1519. {
  1520. long block;
  1521. struct udf_sb_info *sbi = UDF_SB(sb);
  1522. if (novrs) {
  1523. udf_debug("Validity check skipped because of novrs option\n");
  1524. return 0;
  1525. }
  1526. /* Check that it is NSR02 compliant */
  1527. /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
  1528. block = udf_vrs(sb, silent);
  1529. if (block == -1)
  1530. udf_debug("Failed to read byte 32768. Assuming open "
  1531. "disc. Skipping validity check\n");
  1532. if (block && !sbi->s_last_block)
  1533. sbi->s_last_block = udf_get_last_block(sb);
  1534. return !block;
  1535. }
  1536. static int udf_load_sequence(struct super_block *sb, struct kernel_lb_addr *fileset)
  1537. {
  1538. struct anchorVolDescPtr *anchor;
  1539. uint16_t ident;
  1540. struct buffer_head *bh;
  1541. long main_s, main_e, reserve_s, reserve_e;
  1542. int i;
  1543. struct udf_sb_info *sbi;
  1544. if (!sb)
  1545. return 1;
  1546. sbi = UDF_SB(sb);
  1547. for (i = 0; i < ARRAY_SIZE(sbi->s_anchor); i++) {
  1548. if (!sbi->s_anchor[i])
  1549. continue;
  1550. bh = udf_read_tagged(sb, sbi->s_anchor[i], sbi->s_anchor[i],
  1551. &ident);
  1552. if (!bh)
  1553. continue;
  1554. anchor = (struct anchorVolDescPtr *)bh->b_data;
  1555. /* Locate the main sequence */
  1556. main_s = le32_to_cpu(anchor->mainVolDescSeqExt.extLocation);
  1557. main_e = le32_to_cpu(anchor->mainVolDescSeqExt.extLength);
  1558. main_e = main_e >> sb->s_blocksize_bits;
  1559. main_e += main_s;
  1560. /* Locate the reserve sequence */
  1561. reserve_s = le32_to_cpu(
  1562. anchor->reserveVolDescSeqExt.extLocation);
  1563. reserve_e = le32_to_cpu(
  1564. anchor->reserveVolDescSeqExt.extLength);
  1565. reserve_e = reserve_e >> sb->s_blocksize_bits;
  1566. reserve_e += reserve_s;
  1567. brelse(bh);
  1568. /* Process the main & reserve sequences */
  1569. /* responsible for finding the PartitionDesc(s) */
  1570. if (!(udf_process_sequence(sb, main_s, main_e,
  1571. fileset) &&
  1572. udf_process_sequence(sb, reserve_s, reserve_e,
  1573. fileset)))
  1574. break;
  1575. }
  1576. if (i == ARRAY_SIZE(sbi->s_anchor)) {
  1577. udf_debug("No Anchor block found\n");
  1578. return 1;
  1579. }
  1580. udf_debug("Using anchor in block %d\n", sbi->s_anchor[i]);
  1581. return 0;
  1582. }
  1583. static void udf_open_lvid(struct super_block *sb)
  1584. {
  1585. struct udf_sb_info *sbi = UDF_SB(sb);
  1586. struct buffer_head *bh = sbi->s_lvid_bh;
  1587. struct logicalVolIntegrityDesc *lvid;
  1588. struct logicalVolIntegrityDescImpUse *lvidiu;
  1589. if (!bh)
  1590. return;
  1591. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1592. lvidiu = udf_sb_lvidiu(sbi);
  1593. lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1594. lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1595. udf_time_to_disk_stamp(&lvid->recordingDateAndTime,
  1596. CURRENT_TIME);
  1597. lvid->integrityType = LVID_INTEGRITY_TYPE_OPEN;
  1598. lvid->descTag.descCRC = cpu_to_le16(
  1599. crc_itu_t(0, (char *)lvid + sizeof(struct tag),
  1600. le16_to_cpu(lvid->descTag.descCRCLength)));
  1601. lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
  1602. mark_buffer_dirty(bh);
  1603. }
  1604. static void udf_close_lvid(struct super_block *sb)
  1605. {
  1606. struct udf_sb_info *sbi = UDF_SB(sb);
  1607. struct buffer_head *bh = sbi->s_lvid_bh;
  1608. struct logicalVolIntegrityDesc *lvid;
  1609. struct logicalVolIntegrityDescImpUse *lvidiu;
  1610. if (!bh)
  1611. return;
  1612. lvid = (struct logicalVolIntegrityDesc *)bh->b_data;
  1613. if (lvid->integrityType != LVID_INTEGRITY_TYPE_OPEN)
  1614. return;
  1615. lvidiu = udf_sb_lvidiu(sbi);
  1616. lvidiu->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1617. lvidiu->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1618. udf_time_to_disk_stamp(&lvid->recordingDateAndTime, CURRENT_TIME);
  1619. if (UDF_MAX_WRITE_VERSION > le16_to_cpu(lvidiu->maxUDFWriteRev))
  1620. lvidiu->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
  1621. if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFReadRev))
  1622. lvidiu->minUDFReadRev = cpu_to_le16(sbi->s_udfrev);
  1623. if (sbi->s_udfrev > le16_to_cpu(lvidiu->minUDFWriteRev))
  1624. lvidiu->minUDFWriteRev = cpu_to_le16(sbi->s_udfrev);
  1625. lvid->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
  1626. lvid->descTag.descCRC = cpu_to_le16(
  1627. crc_itu_t(0, (char *)lvid + sizeof(struct tag),
  1628. le16_to_cpu(lvid->descTag.descCRCLength)));
  1629. lvid->descTag.tagChecksum = udf_tag_checksum(&lvid->descTag);
  1630. mark_buffer_dirty(bh);
  1631. }
  1632. static void udf_sb_free_bitmap(struct udf_bitmap *bitmap)
  1633. {
  1634. int i;
  1635. int nr_groups = bitmap->s_nr_groups;
  1636. int size = sizeof(struct udf_bitmap) + (sizeof(struct buffer_head *) *
  1637. nr_groups);
  1638. for (i = 0; i < nr_groups; i++)
  1639. if (bitmap->s_block_bitmap[i])
  1640. brelse(bitmap->s_block_bitmap[i]);
  1641. if (size <= PAGE_SIZE)
  1642. kfree(bitmap);
  1643. else
  1644. vfree(bitmap);
  1645. }
  1646. static void udf_free_partition(struct udf_part_map *map)
  1647. {
  1648. int i;
  1649. struct udf_meta_data *mdata;
  1650. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE)
  1651. iput(map->s_uspace.s_table);
  1652. if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE)
  1653. iput(map->s_fspace.s_table);
  1654. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP)
  1655. udf_sb_free_bitmap(map->s_uspace.s_bitmap);
  1656. if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP)
  1657. udf_sb_free_bitmap(map->s_fspace.s_bitmap);
  1658. if (map->s_partition_type == UDF_SPARABLE_MAP15)
  1659. for (i = 0; i < 4; i++)
  1660. brelse(map->s_type_specific.s_sparing.s_spar_map[i]);
  1661. else if (map->s_partition_type == UDF_METADATA_MAP25) {
  1662. mdata = &map->s_type_specific.s_metadata;
  1663. iput(mdata->s_metadata_fe);
  1664. mdata->s_metadata_fe = NULL;
  1665. iput(mdata->s_mirror_fe);
  1666. mdata->s_mirror_fe = NULL;
  1667. iput(mdata->s_bitmap_fe);
  1668. mdata->s_bitmap_fe = NULL;
  1669. }
  1670. }
  1671. static int udf_fill_super(struct super_block *sb, void *options, int silent)
  1672. {
  1673. int i;
  1674. struct inode *inode = NULL;
  1675. struct udf_options uopt;
  1676. struct kernel_lb_addr rootdir, fileset;
  1677. struct udf_sb_info *sbi;
  1678. uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
  1679. uopt.uid = -1;
  1680. uopt.gid = -1;
  1681. uopt.umask = 0;
  1682. uopt.fmode = UDF_INVALID_MODE;
  1683. uopt.dmode = UDF_INVALID_MODE;
  1684. sbi = kzalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
  1685. if (!sbi)
  1686. return -ENOMEM;
  1687. sb->s_fs_info = sbi;
  1688. mutex_init(&sbi->s_alloc_mutex);
  1689. if (!udf_parse_options((char *)options, &uopt, false))
  1690. goto error_out;
  1691. if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
  1692. uopt.flags & (1 << UDF_FLAG_NLS_MAP)) {
  1693. udf_error(sb, "udf_read_super",
  1694. "utf8 cannot be combined with iocharset\n");
  1695. goto error_out;
  1696. }
  1697. #ifdef CONFIG_UDF_NLS
  1698. if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map) {
  1699. uopt.nls_map = load_nls_default();
  1700. if (!uopt.nls_map)
  1701. uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
  1702. else
  1703. udf_debug("Using default NLS map\n");
  1704. }
  1705. #endif
  1706. if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
  1707. uopt.flags |= (1 << UDF_FLAG_UTF8);
  1708. fileset.logicalBlockNum = 0xFFFFFFFF;
  1709. fileset.partitionReferenceNum = 0xFFFF;
  1710. sbi->s_flags = uopt.flags;
  1711. sbi->s_uid = uopt.uid;
  1712. sbi->s_gid = uopt.gid;
  1713. sbi->s_umask = uopt.umask;
  1714. sbi->s_fmode = uopt.fmode;
  1715. sbi->s_dmode = uopt.dmode;
  1716. sbi->s_nls_map = uopt.nls_map;
  1717. /* Set the block size for all transfers */
  1718. if (!sb_min_blocksize(sb, uopt.blocksize)) {
  1719. udf_debug("Bad block size (%d)\n", uopt.blocksize);
  1720. printk(KERN_ERR "udf: bad block size (%d)\n", uopt.blocksize);
  1721. goto error_out;
  1722. }
  1723. if (uopt.session == 0xFFFFFFFF)
  1724. sbi->s_session = udf_get_last_session(sb);
  1725. else
  1726. sbi->s_session = uopt.session;
  1727. udf_debug("Multi-session=%d\n", sbi->s_session);
  1728. sbi->s_last_block = uopt.lastblock;
  1729. sbi->s_anchor[0] = sbi->s_anchor[1] = 0;
  1730. sbi->s_anchor[2] = uopt.anchor;
  1731. if (udf_check_valid(sb, uopt.novrs, silent)) {
  1732. /* read volume recognition sequences */
  1733. printk(KERN_WARNING "UDF-fs: No VRS found\n");
  1734. goto error_out;
  1735. }
  1736. udf_find_anchor(sb);
  1737. /* Fill in the rest of the superblock */
  1738. sb->s_op = &udf_sb_ops;
  1739. sb->s_export_op = &udf_export_ops;
  1740. sb->dq_op = NULL;
  1741. sb->s_dirt = 0;
  1742. sb->s_magic = UDF_SUPER_MAGIC;
  1743. sb->s_time_gran = 1000;
  1744. if (udf_load_sequence(sb, &fileset)) {
  1745. printk(KERN_WARNING "UDF-fs: No partition found (1)\n");
  1746. goto error_out;
  1747. }
  1748. udf_debug("Lastblock=%d\n", sbi->s_last_block);
  1749. if (sbi->s_lvid_bh) {
  1750. struct logicalVolIntegrityDescImpUse *lvidiu =
  1751. udf_sb_lvidiu(sbi);
  1752. uint16_t minUDFReadRev = le16_to_cpu(lvidiu->minUDFReadRev);
  1753. uint16_t minUDFWriteRev = le16_to_cpu(lvidiu->minUDFWriteRev);
  1754. /* uint16_t maxUDFWriteRev =
  1755. le16_to_cpu(lvidiu->maxUDFWriteRev); */
  1756. if (minUDFReadRev > UDF_MAX_READ_VERSION) {
  1757. printk(KERN_ERR "UDF-fs: minUDFReadRev=%x "
  1758. "(max is %x)\n",
  1759. le16_to_cpu(lvidiu->minUDFReadRev),
  1760. UDF_MAX_READ_VERSION);
  1761. goto error_out;
  1762. } else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
  1763. sb->s_flags |= MS_RDONLY;
  1764. sbi->s_udfrev = minUDFWriteRev;
  1765. if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
  1766. UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
  1767. if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
  1768. UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
  1769. }
  1770. if (!sbi->s_partitions) {
  1771. printk(KERN_WARNING "UDF-fs: No partition found (2)\n");
  1772. goto error_out;
  1773. }
  1774. if (sbi->s_partmaps[sbi->s_partition].s_partition_flags &
  1775. UDF_PART_FLAG_READ_ONLY) {
  1776. printk(KERN_NOTICE "UDF-fs: Partition marked readonly; "
  1777. "forcing readonly mount\n");
  1778. sb->s_flags |= MS_RDONLY;
  1779. }
  1780. if (udf_find_fileset(sb, &fileset, &rootdir)) {
  1781. printk(KERN_WARNING "UDF-fs: No fileset found\n");
  1782. goto error_out;
  1783. }
  1784. if (!silent) {
  1785. struct timestamp ts;
  1786. udf_time_to_disk_stamp(&ts, sbi->s_record_time);
  1787. udf_info("UDF: Mounting volume '%s', "
  1788. "timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
  1789. sbi->s_volume_ident, le16_to_cpu(ts.year), ts.month, ts.day,
  1790. ts.hour, ts.minute, le16_to_cpu(ts.typeAndTimezone));
  1791. }
  1792. if (!(sb->s_flags & MS_RDONLY))
  1793. udf_open_lvid(sb);
  1794. /* Assign the root inode */
  1795. /* assign inodes by physical block number */
  1796. /* perhaps it's not extensible enough, but for now ... */
  1797. inode = udf_iget(sb, &rootdir);
  1798. if (!inode) {
  1799. printk(KERN_ERR "UDF-fs: Error in udf_iget, block=%d, "
  1800. "partition=%d\n",
  1801. rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
  1802. goto error_out;
  1803. }
  1804. /* Allocate a dentry for the root inode */
  1805. sb->s_root = d_alloc_root(inode);
  1806. if (!sb->s_root) {
  1807. printk(KERN_ERR "UDF-fs: Couldn't allocate root dentry\n");
  1808. iput(inode);
  1809. goto error_out;
  1810. }
  1811. sb->s_maxbytes = MAX_LFS_FILESIZE;
  1812. return 0;
  1813. error_out:
  1814. if (sbi->s_vat_inode)
  1815. iput(sbi->s_vat_inode);
  1816. if (sbi->s_partitions)
  1817. for (i = 0; i < sbi->s_partitions; i++)
  1818. udf_free_partition(&sbi->s_partmaps[i]);
  1819. #ifdef CONFIG_UDF_NLS
  1820. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1821. unload_nls(sbi->s_nls_map);
  1822. #endif
  1823. if (!(sb->s_flags & MS_RDONLY))
  1824. udf_close_lvid(sb);
  1825. brelse(sbi->s_lvid_bh);
  1826. kfree(sbi->s_partmaps);
  1827. kfree(sbi);
  1828. sb->s_fs_info = NULL;
  1829. return -EINVAL;
  1830. }
  1831. static void udf_error(struct super_block *sb, const char *function,
  1832. const char *fmt, ...)
  1833. {
  1834. va_list args;
  1835. if (!(sb->s_flags & MS_RDONLY)) {
  1836. /* mark sb error */
  1837. sb->s_dirt = 1;
  1838. }
  1839. va_start(args, fmt);
  1840. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1841. va_end(args);
  1842. printk(KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
  1843. sb->s_id, function, error_buf);
  1844. }
  1845. void udf_warning(struct super_block *sb, const char *function,
  1846. const char *fmt, ...)
  1847. {
  1848. va_list args;
  1849. va_start(args, fmt);
  1850. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  1851. va_end(args);
  1852. printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
  1853. sb->s_id, function, error_buf);
  1854. }
  1855. static void udf_put_super(struct super_block *sb)
  1856. {
  1857. int i;
  1858. struct udf_sb_info *sbi;
  1859. sbi = UDF_SB(sb);
  1860. if (sbi->s_vat_inode)
  1861. iput(sbi->s_vat_inode);
  1862. if (sbi->s_partitions)
  1863. for (i = 0; i < sbi->s_partitions; i++)
  1864. udf_free_partition(&sbi->s_partmaps[i]);
  1865. #ifdef CONFIG_UDF_NLS
  1866. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1867. unload_nls(sbi->s_nls_map);
  1868. #endif
  1869. if (!(sb->s_flags & MS_RDONLY))
  1870. udf_close_lvid(sb);
  1871. brelse(sbi->s_lvid_bh);
  1872. kfree(sbi->s_partmaps);
  1873. kfree(sb->s_fs_info);
  1874. sb->s_fs_info = NULL;
  1875. }
  1876. static int udf_statfs(struct dentry *dentry, struct kstatfs *buf)
  1877. {
  1878. struct super_block *sb = dentry->d_sb;
  1879. struct udf_sb_info *sbi = UDF_SB(sb);
  1880. struct logicalVolIntegrityDescImpUse *lvidiu;
  1881. if (sbi->s_lvid_bh != NULL)
  1882. lvidiu = udf_sb_lvidiu(sbi);
  1883. else
  1884. lvidiu = NULL;
  1885. buf->f_type = UDF_SUPER_MAGIC;
  1886. buf->f_bsize = sb->s_blocksize;
  1887. buf->f_blocks = sbi->s_partmaps[sbi->s_partition].s_partition_len;
  1888. buf->f_bfree = udf_count_free(sb);
  1889. buf->f_bavail = buf->f_bfree;
  1890. buf->f_files = (lvidiu != NULL ? (le32_to_cpu(lvidiu->numFiles) +
  1891. le32_to_cpu(lvidiu->numDirs)) : 0)
  1892. + buf->f_bfree;
  1893. buf->f_ffree = buf->f_bfree;
  1894. /* __kernel_fsid_t f_fsid */
  1895. buf->f_namelen = UDF_NAME_LEN - 2;
  1896. return 0;
  1897. }
  1898. static unsigned int udf_count_free_bitmap(struct super_block *sb,
  1899. struct udf_bitmap *bitmap)
  1900. {
  1901. struct buffer_head *bh = NULL;
  1902. unsigned int accum = 0;
  1903. int index;
  1904. int block = 0, newblock;
  1905. struct kernel_lb_addr loc;
  1906. uint32_t bytes;
  1907. uint8_t *ptr;
  1908. uint16_t ident;
  1909. struct spaceBitmapDesc *bm;
  1910. lock_kernel();
  1911. loc.logicalBlockNum = bitmap->s_extPosition;
  1912. loc.partitionReferenceNum = UDF_SB(sb)->s_partition;
  1913. bh = udf_read_ptagged(sb, &loc, 0, &ident);
  1914. if (!bh) {
  1915. printk(KERN_ERR "udf: udf_count_free failed\n");
  1916. goto out;
  1917. } else if (ident != TAG_IDENT_SBD) {
  1918. brelse(bh);
  1919. printk(KERN_ERR "udf: udf_count_free failed\n");
  1920. goto out;
  1921. }
  1922. bm = (struct spaceBitmapDesc *)bh->b_data;
  1923. bytes = le32_to_cpu(bm->numOfBytes);
  1924. index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
  1925. ptr = (uint8_t *)bh->b_data;
  1926. while (bytes > 0) {
  1927. u32 cur_bytes = min_t(u32, bytes, sb->s_blocksize - index);
  1928. accum += bitmap_weight((const unsigned long *)(ptr + index),
  1929. cur_bytes * 8);
  1930. bytes -= cur_bytes;
  1931. if (bytes) {
  1932. brelse(bh);
  1933. newblock = udf_get_lb_pblock(sb, &loc, ++block);
  1934. bh = udf_tread(sb, newblock);
  1935. if (!bh) {
  1936. udf_debug("read failed\n");
  1937. goto out;
  1938. }
  1939. index = 0;
  1940. ptr = (uint8_t *)bh->b_data;
  1941. }
  1942. }
  1943. brelse(bh);
  1944. out:
  1945. unlock_kernel();
  1946. return accum;
  1947. }
  1948. static unsigned int udf_count_free_table(struct super_block *sb,
  1949. struct inode *table)
  1950. {
  1951. unsigned int accum = 0;
  1952. uint32_t elen;
  1953. struct kernel_lb_addr eloc;
  1954. int8_t etype;
  1955. struct extent_position epos;
  1956. lock_kernel();
  1957. epos.block = UDF_I(table)->i_location;
  1958. epos.offset = sizeof(struct unallocSpaceEntry);
  1959. epos.bh = NULL;
  1960. while ((etype = udf_next_aext(table, &epos, &eloc, &elen, 1)) != -1)
  1961. accum += (elen >> table->i_sb->s_blocksize_bits);
  1962. brelse(epos.bh);
  1963. unlock_kernel();
  1964. return accum;
  1965. }
  1966. static unsigned int udf_count_free(struct super_block *sb)
  1967. {
  1968. unsigned int accum = 0;
  1969. struct udf_sb_info *sbi;
  1970. struct udf_part_map *map;
  1971. sbi = UDF_SB(sb);
  1972. if (sbi->s_lvid_bh) {
  1973. struct logicalVolIntegrityDesc *lvid =
  1974. (struct logicalVolIntegrityDesc *)
  1975. sbi->s_lvid_bh->b_data;
  1976. if (le32_to_cpu(lvid->numOfPartitions) > sbi->s_partition) {
  1977. accum = le32_to_cpu(
  1978. lvid->freeSpaceTable[sbi->s_partition]);
  1979. if (accum == 0xFFFFFFFF)
  1980. accum = 0;
  1981. }
  1982. }
  1983. if (accum)
  1984. return accum;
  1985. map = &sbi->s_partmaps[sbi->s_partition];
  1986. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_BITMAP) {
  1987. accum += udf_count_free_bitmap(sb,
  1988. map->s_uspace.s_bitmap);
  1989. }
  1990. if (map->s_partition_flags & UDF_PART_FLAG_FREED_BITMAP) {
  1991. accum += udf_count_free_bitmap(sb,
  1992. map->s_fspace.s_bitmap);
  1993. }
  1994. if (accum)
  1995. return accum;
  1996. if (map->s_partition_flags & UDF_PART_FLAG_UNALLOC_TABLE) {
  1997. accum += udf_count_free_table(sb,
  1998. map->s_uspace.s_table);
  1999. }
  2000. if (map->s_partition_flags & UDF_PART_FLAG_FREED_TABLE) {
  2001. accum += udf_count_free_table(sb,
  2002. map->s_fspace.s_table);
  2003. }
  2004. return accum;
  2005. }