super.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941
  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 vol descs
  37. * 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/config.h>
  42. #include <linux/blkdev.h>
  43. #include <linux/slab.h>
  44. #include <linux/kernel.h>
  45. #include <linux/module.h>
  46. #include <linux/parser.h>
  47. #include <linux/stat.h>
  48. #include <linux/cdrom.h>
  49. #include <linux/nls.h>
  50. #include <linux/smp_lock.h>
  51. #include <linux/buffer_head.h>
  52. #include <linux/vfs.h>
  53. #include <linux/vmalloc.h>
  54. #include <asm/byteorder.h>
  55. #include <linux/udf_fs.h>
  56. #include "udf_sb.h"
  57. #include "udf_i.h"
  58. #include <linux/init.h>
  59. #include <asm/uaccess.h>
  60. #define VDS_POS_PRIMARY_VOL_DESC 0
  61. #define VDS_POS_UNALLOC_SPACE_DESC 1
  62. #define VDS_POS_LOGICAL_VOL_DESC 2
  63. #define VDS_POS_PARTITION_DESC 3
  64. #define VDS_POS_IMP_USE_VOL_DESC 4
  65. #define VDS_POS_VOL_DESC_PTR 5
  66. #define VDS_POS_TERMINATING_DESC 6
  67. #define VDS_POS_LENGTH 7
  68. static char error_buf[1024];
  69. /* These are the "meat" - everything else is stuffing */
  70. static int udf_fill_super(struct super_block *, void *, int);
  71. static void udf_put_super(struct super_block *);
  72. static void udf_write_super(struct super_block *);
  73. static int udf_remount_fs(struct super_block *, int *, char *);
  74. static int udf_check_valid(struct super_block *, int, int);
  75. static int udf_vrs(struct super_block *sb, int silent);
  76. static int udf_load_partition(struct super_block *, kernel_lb_addr *);
  77. static int udf_load_logicalvol(struct super_block *, struct buffer_head *, kernel_lb_addr *);
  78. static void udf_load_logicalvolint(struct super_block *, kernel_extent_ad);
  79. static void udf_find_anchor(struct super_block *);
  80. static int udf_find_fileset(struct super_block *, kernel_lb_addr *, kernel_lb_addr *);
  81. static void udf_load_pvoldesc(struct super_block *, struct buffer_head *);
  82. static void udf_load_fileset(struct super_block *, struct buffer_head *, kernel_lb_addr *);
  83. static void udf_load_partdesc(struct super_block *, struct buffer_head *);
  84. static void udf_open_lvid(struct super_block *);
  85. static void udf_close_lvid(struct super_block *);
  86. static unsigned int udf_count_free(struct super_block *);
  87. static int udf_statfs(struct super_block *, struct kstatfs *);
  88. /* UDF filesystem type */
  89. static struct super_block *udf_get_sb(struct file_system_type *fs_type,
  90. int flags, const char *dev_name, void *data)
  91. {
  92. return get_sb_bdev(fs_type, flags, dev_name, data, udf_fill_super);
  93. }
  94. static struct file_system_type udf_fstype = {
  95. .owner = THIS_MODULE,
  96. .name = "udf",
  97. .get_sb = udf_get_sb,
  98. .kill_sb = kill_block_super,
  99. .fs_flags = FS_REQUIRES_DEV,
  100. };
  101. static kmem_cache_t * udf_inode_cachep;
  102. static struct inode *udf_alloc_inode(struct super_block *sb)
  103. {
  104. struct udf_inode_info *ei;
  105. ei = (struct udf_inode_info *)kmem_cache_alloc(udf_inode_cachep, SLAB_KERNEL);
  106. if (!ei)
  107. return NULL;
  108. return &ei->vfs_inode;
  109. }
  110. static void udf_destroy_inode(struct inode *inode)
  111. {
  112. kmem_cache_free(udf_inode_cachep, UDF_I(inode));
  113. }
  114. static void init_once(void * foo, kmem_cache_t * cachep, unsigned long flags)
  115. {
  116. struct udf_inode_info *ei = (struct udf_inode_info *) foo;
  117. if ((flags & (SLAB_CTOR_VERIFY|SLAB_CTOR_CONSTRUCTOR)) ==
  118. SLAB_CTOR_CONSTRUCTOR)
  119. {
  120. ei->i_ext.i_data = NULL;
  121. inode_init_once(&ei->vfs_inode);
  122. }
  123. }
  124. static int init_inodecache(void)
  125. {
  126. udf_inode_cachep = kmem_cache_create("udf_inode_cache",
  127. sizeof(struct udf_inode_info),
  128. 0, (SLAB_RECLAIM_ACCOUNT|
  129. SLAB_MEM_SPREAD),
  130. init_once, NULL);
  131. if (udf_inode_cachep == NULL)
  132. return -ENOMEM;
  133. return 0;
  134. }
  135. static void destroy_inodecache(void)
  136. {
  137. if (kmem_cache_destroy(udf_inode_cachep))
  138. printk(KERN_INFO "udf_inode_cache: not all structures were freed\n");
  139. }
  140. /* Superblock operations */
  141. static struct super_operations udf_sb_ops = {
  142. .alloc_inode = udf_alloc_inode,
  143. .destroy_inode = udf_destroy_inode,
  144. .write_inode = udf_write_inode,
  145. .delete_inode = udf_delete_inode,
  146. .clear_inode = udf_clear_inode,
  147. .put_super = udf_put_super,
  148. .write_super = udf_write_super,
  149. .statfs = udf_statfs,
  150. .remount_fs = udf_remount_fs,
  151. };
  152. struct udf_options
  153. {
  154. unsigned char novrs;
  155. unsigned int blocksize;
  156. unsigned int session;
  157. unsigned int lastblock;
  158. unsigned int anchor;
  159. unsigned int volume;
  160. unsigned short partition;
  161. unsigned int fileset;
  162. unsigned int rootdir;
  163. unsigned int flags;
  164. mode_t umask;
  165. gid_t gid;
  166. uid_t uid;
  167. struct nls_table *nls_map;
  168. };
  169. static int __init init_udf_fs(void)
  170. {
  171. int err;
  172. err = init_inodecache();
  173. if (err)
  174. goto out1;
  175. err = register_filesystem(&udf_fstype);
  176. if (err)
  177. goto out;
  178. return 0;
  179. out:
  180. destroy_inodecache();
  181. out1:
  182. return err;
  183. }
  184. static void __exit exit_udf_fs(void)
  185. {
  186. unregister_filesystem(&udf_fstype);
  187. destroy_inodecache();
  188. }
  189. module_init(init_udf_fs)
  190. module_exit(exit_udf_fs)
  191. /*
  192. * udf_parse_options
  193. *
  194. * PURPOSE
  195. * Parse mount options.
  196. *
  197. * DESCRIPTION
  198. * The following mount options are supported:
  199. *
  200. * gid= Set the default group.
  201. * umask= Set the default umask.
  202. * uid= Set the default user.
  203. * bs= Set the block size.
  204. * unhide Show otherwise hidden files.
  205. * undelete Show deleted files in lists.
  206. * adinicb Embed data in the inode (default)
  207. * noadinicb Don't embed data in the inode
  208. * shortad Use short ad's
  209. * longad Use long ad's (default)
  210. * nostrict Unset strict conformance
  211. * iocharset= Set the NLS character set
  212. *
  213. * The remaining are for debugging and disaster recovery:
  214. *
  215. * novrs Skip volume sequence recognition
  216. *
  217. * The following expect a offset from 0.
  218. *
  219. * session= Set the CDROM session (default= last session)
  220. * anchor= Override standard anchor location. (default= 256)
  221. * volume= Override the VolumeDesc location. (unused)
  222. * partition= Override the PartitionDesc location. (unused)
  223. * lastblock= Set the last block of the filesystem/
  224. *
  225. * The following expect a offset from the partition root.
  226. *
  227. * fileset= Override the fileset block location. (unused)
  228. * rootdir= Override the root directory location. (unused)
  229. * WARNING: overriding the rootdir to a non-directory may
  230. * yield highly unpredictable results.
  231. *
  232. * PRE-CONDITIONS
  233. * options Pointer to mount options string.
  234. * uopts Pointer to mount options variable.
  235. *
  236. * POST-CONDITIONS
  237. * <return> 1 Mount options parsed okay.
  238. * <return> 0 Error parsing mount options.
  239. *
  240. * HISTORY
  241. * July 1, 1997 - Andrew E. Mileski
  242. * Written, tested, and released.
  243. */
  244. enum {
  245. Opt_novrs, Opt_nostrict, Opt_bs, Opt_unhide, Opt_undelete,
  246. Opt_noadinicb, Opt_adinicb, Opt_shortad, Opt_longad,
  247. Opt_gid, Opt_uid, Opt_umask, Opt_session, Opt_lastblock,
  248. Opt_anchor, Opt_volume, Opt_partition, Opt_fileset,
  249. Opt_rootdir, Opt_utf8, Opt_iocharset,
  250. Opt_err, Opt_uforget, Opt_uignore, Opt_gforget, Opt_gignore
  251. };
  252. static match_table_t tokens = {
  253. {Opt_novrs, "novrs"},
  254. {Opt_nostrict, "nostrict"},
  255. {Opt_bs, "bs=%u"},
  256. {Opt_unhide, "unhide"},
  257. {Opt_undelete, "undelete"},
  258. {Opt_noadinicb, "noadinicb"},
  259. {Opt_adinicb, "adinicb"},
  260. {Opt_shortad, "shortad"},
  261. {Opt_longad, "longad"},
  262. {Opt_uforget, "uid=forget"},
  263. {Opt_uignore, "uid=ignore"},
  264. {Opt_gforget, "gid=forget"},
  265. {Opt_gignore, "gid=ignore"},
  266. {Opt_gid, "gid=%u"},
  267. {Opt_uid, "uid=%u"},
  268. {Opt_umask, "umask=%o"},
  269. {Opt_session, "session=%u"},
  270. {Opt_lastblock, "lastblock=%u"},
  271. {Opt_anchor, "anchor=%u"},
  272. {Opt_volume, "volume=%u"},
  273. {Opt_partition, "partition=%u"},
  274. {Opt_fileset, "fileset=%u"},
  275. {Opt_rootdir, "rootdir=%u"},
  276. {Opt_utf8, "utf8"},
  277. {Opt_iocharset, "iocharset=%s"},
  278. {Opt_err, NULL}
  279. };
  280. static int
  281. udf_parse_options(char *options, struct udf_options *uopt)
  282. {
  283. char *p;
  284. int option;
  285. uopt->novrs = 0;
  286. uopt->blocksize = 2048;
  287. uopt->partition = 0xFFFF;
  288. uopt->session = 0xFFFFFFFF;
  289. uopt->lastblock = 0;
  290. uopt->anchor = 0;
  291. uopt->volume = 0xFFFFFFFF;
  292. uopt->rootdir = 0xFFFFFFFF;
  293. uopt->fileset = 0xFFFFFFFF;
  294. uopt->nls_map = NULL;
  295. if (!options)
  296. return 1;
  297. while ((p = strsep(&options, ",")) != NULL)
  298. {
  299. substring_t args[MAX_OPT_ARGS];
  300. int token;
  301. if (!*p)
  302. continue;
  303. token = match_token(p, tokens, args);
  304. switch (token)
  305. {
  306. case Opt_novrs:
  307. uopt->novrs = 1;
  308. case Opt_bs:
  309. if (match_int(&args[0], &option))
  310. return 0;
  311. uopt->blocksize = option;
  312. break;
  313. case Opt_unhide:
  314. uopt->flags |= (1 << UDF_FLAG_UNHIDE);
  315. break;
  316. case Opt_undelete:
  317. uopt->flags |= (1 << UDF_FLAG_UNDELETE);
  318. break;
  319. case Opt_noadinicb:
  320. uopt->flags &= ~(1 << UDF_FLAG_USE_AD_IN_ICB);
  321. break;
  322. case Opt_adinicb:
  323. uopt->flags |= (1 << UDF_FLAG_USE_AD_IN_ICB);
  324. break;
  325. case Opt_shortad:
  326. uopt->flags |= (1 << UDF_FLAG_USE_SHORT_AD);
  327. break;
  328. case Opt_longad:
  329. uopt->flags &= ~(1 << UDF_FLAG_USE_SHORT_AD);
  330. break;
  331. case Opt_gid:
  332. if (match_int(args, &option))
  333. return 0;
  334. uopt->gid = option;
  335. break;
  336. case Opt_uid:
  337. if (match_int(args, &option))
  338. return 0;
  339. uopt->uid = option;
  340. break;
  341. case Opt_umask:
  342. if (match_octal(args, &option))
  343. return 0;
  344. uopt->umask = option;
  345. break;
  346. case Opt_nostrict:
  347. uopt->flags &= ~(1 << UDF_FLAG_STRICT);
  348. break;
  349. case Opt_session:
  350. if (match_int(args, &option))
  351. return 0;
  352. uopt->session = option;
  353. break;
  354. case Opt_lastblock:
  355. if (match_int(args, &option))
  356. return 0;
  357. uopt->lastblock = option;
  358. break;
  359. case Opt_anchor:
  360. if (match_int(args, &option))
  361. return 0;
  362. uopt->anchor = option;
  363. break;
  364. case Opt_volume:
  365. if (match_int(args, &option))
  366. return 0;
  367. uopt->volume = option;
  368. break;
  369. case Opt_partition:
  370. if (match_int(args, &option))
  371. return 0;
  372. uopt->partition = option;
  373. break;
  374. case Opt_fileset:
  375. if (match_int(args, &option))
  376. return 0;
  377. uopt->fileset = option;
  378. break;
  379. case Opt_rootdir:
  380. if (match_int(args, &option))
  381. return 0;
  382. uopt->rootdir = option;
  383. break;
  384. case Opt_utf8:
  385. uopt->flags |= (1 << UDF_FLAG_UTF8);
  386. break;
  387. #ifdef CONFIG_UDF_NLS
  388. case Opt_iocharset:
  389. uopt->nls_map = load_nls(args[0].from);
  390. uopt->flags |= (1 << UDF_FLAG_NLS_MAP);
  391. break;
  392. #endif
  393. case Opt_uignore:
  394. uopt->flags |= (1 << UDF_FLAG_UID_IGNORE);
  395. break;
  396. case Opt_uforget:
  397. uopt->flags |= (1 << UDF_FLAG_UID_FORGET);
  398. break;
  399. case Opt_gignore:
  400. uopt->flags |= (1 << UDF_FLAG_GID_IGNORE);
  401. break;
  402. case Opt_gforget:
  403. uopt->flags |= (1 << UDF_FLAG_GID_FORGET);
  404. break;
  405. default:
  406. printk(KERN_ERR "udf: bad mount option \"%s\" "
  407. "or missing value\n", p);
  408. return 0;
  409. }
  410. }
  411. return 1;
  412. }
  413. void
  414. udf_write_super(struct super_block *sb)
  415. {
  416. lock_kernel();
  417. if (!(sb->s_flags & MS_RDONLY))
  418. udf_open_lvid(sb);
  419. sb->s_dirt = 0;
  420. unlock_kernel();
  421. }
  422. static int
  423. udf_remount_fs(struct super_block *sb, int *flags, char *options)
  424. {
  425. struct udf_options uopt;
  426. uopt.flags = UDF_SB(sb)->s_flags ;
  427. uopt.uid = UDF_SB(sb)->s_uid ;
  428. uopt.gid = UDF_SB(sb)->s_gid ;
  429. uopt.umask = UDF_SB(sb)->s_umask ;
  430. if ( !udf_parse_options(options, &uopt) )
  431. return -EINVAL;
  432. UDF_SB(sb)->s_flags = uopt.flags;
  433. UDF_SB(sb)->s_uid = uopt.uid;
  434. UDF_SB(sb)->s_gid = uopt.gid;
  435. UDF_SB(sb)->s_umask = uopt.umask;
  436. if (UDF_SB_LVIDBH(sb)) {
  437. int write_rev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
  438. if (write_rev > UDF_MAX_WRITE_VERSION)
  439. *flags |= MS_RDONLY;
  440. }
  441. if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
  442. return 0;
  443. if (*flags & MS_RDONLY)
  444. udf_close_lvid(sb);
  445. else
  446. udf_open_lvid(sb);
  447. return 0;
  448. }
  449. /*
  450. * udf_set_blocksize
  451. *
  452. * PURPOSE
  453. * Set the block size to be used in all transfers.
  454. *
  455. * DESCRIPTION
  456. * To allow room for a DMA transfer, it is best to guess big when unsure.
  457. * This routine picks 2048 bytes as the blocksize when guessing. This
  458. * should be adequate until devices with larger block sizes become common.
  459. *
  460. * Note that the Linux kernel can currently only deal with blocksizes of
  461. * 512, 1024, 2048, 4096, and 8192 bytes.
  462. *
  463. * PRE-CONDITIONS
  464. * sb Pointer to _locked_ superblock.
  465. *
  466. * POST-CONDITIONS
  467. * sb->s_blocksize Blocksize.
  468. * sb->s_blocksize_bits log2 of blocksize.
  469. * <return> 0 Blocksize is valid.
  470. * <return> 1 Blocksize is invalid.
  471. *
  472. * HISTORY
  473. * July 1, 1997 - Andrew E. Mileski
  474. * Written, tested, and released.
  475. */
  476. static int
  477. udf_set_blocksize(struct super_block *sb, int bsize)
  478. {
  479. if (!sb_min_blocksize(sb, bsize)) {
  480. udf_debug("Bad block size (%d)\n", bsize);
  481. printk(KERN_ERR "udf: bad block size (%d)\n", bsize);
  482. return 0;
  483. }
  484. return sb->s_blocksize;
  485. }
  486. static int
  487. udf_vrs(struct super_block *sb, int silent)
  488. {
  489. struct volStructDesc *vsd = NULL;
  490. int sector = 32768;
  491. int sectorsize;
  492. struct buffer_head *bh = NULL;
  493. int iso9660=0;
  494. int nsr02=0;
  495. int nsr03=0;
  496. /* Block size must be a multiple of 512 */
  497. if (sb->s_blocksize & 511)
  498. return 0;
  499. if (sb->s_blocksize < sizeof(struct volStructDesc))
  500. sectorsize = sizeof(struct volStructDesc);
  501. else
  502. sectorsize = sb->s_blocksize;
  503. sector += (UDF_SB_SESSION(sb) << sb->s_blocksize_bits);
  504. udf_debug("Starting at sector %u (%ld byte sectors)\n",
  505. (sector >> sb->s_blocksize_bits), sb->s_blocksize);
  506. /* Process the sequence (if applicable) */
  507. for (;!nsr02 && !nsr03; sector += sectorsize)
  508. {
  509. /* Read a block */
  510. bh = udf_tread(sb, sector >> sb->s_blocksize_bits);
  511. if (!bh)
  512. break;
  513. /* Look for ISO descriptors */
  514. vsd = (struct volStructDesc *)(bh->b_data +
  515. (sector & (sb->s_blocksize - 1)));
  516. if (vsd->stdIdent[0] == 0)
  517. {
  518. udf_release_data(bh);
  519. break;
  520. }
  521. else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN))
  522. {
  523. iso9660 = sector;
  524. switch (vsd->structType)
  525. {
  526. case 0:
  527. udf_debug("ISO9660 Boot Record found\n");
  528. break;
  529. case 1:
  530. udf_debug("ISO9660 Primary Volume Descriptor found\n");
  531. break;
  532. case 2:
  533. udf_debug("ISO9660 Supplementary Volume Descriptor found\n");
  534. break;
  535. case 3:
  536. udf_debug("ISO9660 Volume Partition Descriptor found\n");
  537. break;
  538. case 255:
  539. udf_debug("ISO9660 Volume Descriptor Set Terminator found\n");
  540. break;
  541. default:
  542. udf_debug("ISO9660 VRS (%u) found\n", vsd->structType);
  543. break;
  544. }
  545. }
  546. else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN))
  547. {
  548. }
  549. else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, VSD_STD_ID_LEN))
  550. {
  551. udf_release_data(bh);
  552. break;
  553. }
  554. else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN))
  555. {
  556. nsr02 = sector;
  557. }
  558. else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN))
  559. {
  560. nsr03 = sector;
  561. }
  562. udf_release_data(bh);
  563. }
  564. if (nsr03)
  565. return nsr03;
  566. else if (nsr02)
  567. return nsr02;
  568. else if (sector - (UDF_SB_SESSION(sb) << sb->s_blocksize_bits) == 32768)
  569. return -1;
  570. else
  571. return 0;
  572. }
  573. /*
  574. * udf_find_anchor
  575. *
  576. * PURPOSE
  577. * Find an anchor volume descriptor.
  578. *
  579. * PRE-CONDITIONS
  580. * sb Pointer to _locked_ superblock.
  581. * lastblock Last block on media.
  582. *
  583. * POST-CONDITIONS
  584. * <return> 1 if not found, 0 if ok
  585. *
  586. * HISTORY
  587. * July 1, 1997 - Andrew E. Mileski
  588. * Written, tested, and released.
  589. */
  590. static void
  591. udf_find_anchor(struct super_block *sb)
  592. {
  593. int lastblock = UDF_SB_LASTBLOCK(sb);
  594. struct buffer_head *bh = NULL;
  595. uint16_t ident;
  596. uint32_t location;
  597. int i;
  598. if (lastblock)
  599. {
  600. int varlastblock = udf_variable_to_fixed(lastblock);
  601. int last[] = { lastblock, lastblock - 2,
  602. lastblock - 150, lastblock - 152,
  603. varlastblock, varlastblock - 2,
  604. varlastblock - 150, varlastblock - 152 };
  605. lastblock = 0;
  606. /* Search for an anchor volume descriptor pointer */
  607. /* according to spec, anchor is in either:
  608. * block 256
  609. * lastblock-256
  610. * lastblock
  611. * however, if the disc isn't closed, it could be 512 */
  612. for (i = 0; !lastblock && i < ARRAY_SIZE(last); i++) {
  613. if (last[i] < 0 || !(bh = sb_bread(sb, last[i])))
  614. {
  615. ident = location = 0;
  616. }
  617. else
  618. {
  619. ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
  620. location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
  621. udf_release_data(bh);
  622. }
  623. if (ident == TAG_IDENT_AVDP)
  624. {
  625. if (location == last[i] - UDF_SB_SESSION(sb))
  626. {
  627. lastblock = UDF_SB_ANCHOR(sb)[0] = last[i] - UDF_SB_SESSION(sb);
  628. UDF_SB_ANCHOR(sb)[1] = last[i] - 256 - UDF_SB_SESSION(sb);
  629. }
  630. else if (location == udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb))
  631. {
  632. UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
  633. lastblock = UDF_SB_ANCHOR(sb)[0] = udf_variable_to_fixed(last[i]) - UDF_SB_SESSION(sb);
  634. UDF_SB_ANCHOR(sb)[1] = lastblock - 256 - UDF_SB_SESSION(sb);
  635. }
  636. else
  637. udf_debug("Anchor found at block %d, location mismatch %d.\n",
  638. last[i], location);
  639. }
  640. else if (ident == TAG_IDENT_FE || ident == TAG_IDENT_EFE)
  641. {
  642. lastblock = last[i];
  643. UDF_SB_ANCHOR(sb)[3] = 512;
  644. }
  645. else
  646. {
  647. if (last[i] < 256 || !(bh = sb_bread(sb, last[i] - 256)))
  648. {
  649. ident = location = 0;
  650. }
  651. else
  652. {
  653. ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
  654. location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
  655. udf_release_data(bh);
  656. }
  657. if (ident == TAG_IDENT_AVDP &&
  658. location == last[i] - 256 - UDF_SB_SESSION(sb))
  659. {
  660. lastblock = last[i];
  661. UDF_SB_ANCHOR(sb)[1] = last[i] - 256;
  662. }
  663. else
  664. {
  665. if (last[i] < 312 + UDF_SB_SESSION(sb) || !(bh = sb_bread(sb, last[i] - 312 - UDF_SB_SESSION(sb))))
  666. {
  667. ident = location = 0;
  668. }
  669. else
  670. {
  671. ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
  672. location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
  673. udf_release_data(bh);
  674. }
  675. if (ident == TAG_IDENT_AVDP &&
  676. location == udf_variable_to_fixed(last[i]) - 256)
  677. {
  678. UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
  679. lastblock = udf_variable_to_fixed(last[i]);
  680. UDF_SB_ANCHOR(sb)[1] = lastblock - 256;
  681. }
  682. }
  683. }
  684. }
  685. }
  686. if (!lastblock)
  687. {
  688. /* We havn't found the lastblock. check 312 */
  689. if ((bh = sb_bread(sb, 312 + UDF_SB_SESSION(sb))))
  690. {
  691. ident = le16_to_cpu(((tag *)bh->b_data)->tagIdent);
  692. location = le32_to_cpu(((tag *)bh->b_data)->tagLocation);
  693. udf_release_data(bh);
  694. if (ident == TAG_IDENT_AVDP && location == 256)
  695. UDF_SET_FLAG(sb, UDF_FLAG_VARCONV);
  696. }
  697. }
  698. for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
  699. if (UDF_SB_ANCHOR(sb)[i])
  700. {
  701. if (!(bh = udf_read_tagged(sb,
  702. UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident)))
  703. {
  704. UDF_SB_ANCHOR(sb)[i] = 0;
  705. }
  706. else
  707. {
  708. udf_release_data(bh);
  709. if ((ident != TAG_IDENT_AVDP) && (i ||
  710. (ident != TAG_IDENT_FE && ident != TAG_IDENT_EFE)))
  711. {
  712. UDF_SB_ANCHOR(sb)[i] = 0;
  713. }
  714. }
  715. }
  716. }
  717. UDF_SB_LASTBLOCK(sb) = lastblock;
  718. }
  719. static int
  720. udf_find_fileset(struct super_block *sb, kernel_lb_addr *fileset, kernel_lb_addr *root)
  721. {
  722. struct buffer_head *bh = NULL;
  723. long lastblock;
  724. uint16_t ident;
  725. if (fileset->logicalBlockNum != 0xFFFFFFFF ||
  726. fileset->partitionReferenceNum != 0xFFFF)
  727. {
  728. bh = udf_read_ptagged(sb, *fileset, 0, &ident);
  729. if (!bh)
  730. return 1;
  731. else if (ident != TAG_IDENT_FSD)
  732. {
  733. udf_release_data(bh);
  734. return 1;
  735. }
  736. }
  737. if (!bh) /* Search backwards through the partitions */
  738. {
  739. kernel_lb_addr newfileset;
  740. return 1;
  741. for (newfileset.partitionReferenceNum=UDF_SB_NUMPARTS(sb)-1;
  742. (newfileset.partitionReferenceNum != 0xFFFF &&
  743. fileset->logicalBlockNum == 0xFFFFFFFF &&
  744. fileset->partitionReferenceNum == 0xFFFF);
  745. newfileset.partitionReferenceNum--)
  746. {
  747. lastblock = UDF_SB_PARTLEN(sb, newfileset.partitionReferenceNum);
  748. newfileset.logicalBlockNum = 0;
  749. do
  750. {
  751. bh = udf_read_ptagged(sb, newfileset, 0, &ident);
  752. if (!bh)
  753. {
  754. newfileset.logicalBlockNum ++;
  755. continue;
  756. }
  757. switch (ident)
  758. {
  759. case TAG_IDENT_SBD:
  760. {
  761. struct spaceBitmapDesc *sp;
  762. sp = (struct spaceBitmapDesc *)bh->b_data;
  763. newfileset.logicalBlockNum += 1 +
  764. ((le32_to_cpu(sp->numOfBytes) + sizeof(struct spaceBitmapDesc) - 1)
  765. >> sb->s_blocksize_bits);
  766. udf_release_data(bh);
  767. break;
  768. }
  769. case TAG_IDENT_FSD:
  770. {
  771. *fileset = newfileset;
  772. break;
  773. }
  774. default:
  775. {
  776. newfileset.logicalBlockNum ++;
  777. udf_release_data(bh);
  778. bh = NULL;
  779. break;
  780. }
  781. }
  782. }
  783. while (newfileset.logicalBlockNum < lastblock &&
  784. fileset->logicalBlockNum == 0xFFFFFFFF &&
  785. fileset->partitionReferenceNum == 0xFFFF);
  786. }
  787. }
  788. if ((fileset->logicalBlockNum != 0xFFFFFFFF ||
  789. fileset->partitionReferenceNum != 0xFFFF) && bh)
  790. {
  791. udf_debug("Fileset at block=%d, partition=%d\n",
  792. fileset->logicalBlockNum, fileset->partitionReferenceNum);
  793. UDF_SB_PARTITION(sb) = fileset->partitionReferenceNum;
  794. udf_load_fileset(sb, bh, root);
  795. udf_release_data(bh);
  796. return 0;
  797. }
  798. return 1;
  799. }
  800. static void
  801. udf_load_pvoldesc(struct super_block *sb, struct buffer_head *bh)
  802. {
  803. struct primaryVolDesc *pvoldesc;
  804. time_t recording;
  805. long recording_usec;
  806. struct ustr instr;
  807. struct ustr outstr;
  808. pvoldesc = (struct primaryVolDesc *)bh->b_data;
  809. if ( udf_stamp_to_time(&recording, &recording_usec,
  810. lets_to_cpu(pvoldesc->recordingDateAndTime)) )
  811. {
  812. kernel_timestamp ts;
  813. ts = lets_to_cpu(pvoldesc->recordingDateAndTime);
  814. udf_debug("recording time %ld/%ld, %04u/%02u/%02u %02u:%02u (%x)\n",
  815. recording, recording_usec,
  816. ts.year, ts.month, ts.day, ts.hour, ts.minute, ts.typeAndTimezone);
  817. UDF_SB_RECORDTIME(sb).tv_sec = recording;
  818. UDF_SB_RECORDTIME(sb).tv_nsec = recording_usec * 1000;
  819. }
  820. if ( !udf_build_ustr(&instr, pvoldesc->volIdent, 32) )
  821. {
  822. if (udf_CS0toUTF8(&outstr, &instr))
  823. {
  824. strncpy( UDF_SB_VOLIDENT(sb), outstr.u_name,
  825. outstr.u_len > 31 ? 31 : outstr.u_len);
  826. udf_debug("volIdent[] = '%s'\n", UDF_SB_VOLIDENT(sb));
  827. }
  828. }
  829. if ( !udf_build_ustr(&instr, pvoldesc->volSetIdent, 128) )
  830. {
  831. if (udf_CS0toUTF8(&outstr, &instr))
  832. udf_debug("volSetIdent[] = '%s'\n", outstr.u_name);
  833. }
  834. }
  835. static void
  836. udf_load_fileset(struct super_block *sb, struct buffer_head *bh, kernel_lb_addr *root)
  837. {
  838. struct fileSetDesc *fset;
  839. fset = (struct fileSetDesc *)bh->b_data;
  840. *root = lelb_to_cpu(fset->rootDirectoryICB.extLocation);
  841. UDF_SB_SERIALNUM(sb) = le16_to_cpu(fset->descTag.tagSerialNum);
  842. udf_debug("Rootdir at block=%d, partition=%d\n",
  843. root->logicalBlockNum, root->partitionReferenceNum);
  844. }
  845. static void
  846. udf_load_partdesc(struct super_block *sb, struct buffer_head *bh)
  847. {
  848. struct partitionDesc *p;
  849. int i;
  850. p = (struct partitionDesc *)bh->b_data;
  851. for (i=0; i<UDF_SB_NUMPARTS(sb); i++)
  852. {
  853. udf_debug("Searching map: (%d == %d)\n",
  854. UDF_SB_PARTMAPS(sb)[i].s_partition_num, le16_to_cpu(p->partitionNumber));
  855. if (UDF_SB_PARTMAPS(sb)[i].s_partition_num == le16_to_cpu(p->partitionNumber))
  856. {
  857. UDF_SB_PARTLEN(sb,i) = le32_to_cpu(p->partitionLength); /* blocks */
  858. UDF_SB_PARTROOT(sb,i) = le32_to_cpu(p->partitionStartingLocation);
  859. if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_READ_ONLY)
  860. UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_READ_ONLY;
  861. if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_WRITE_ONCE)
  862. UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_WRITE_ONCE;
  863. if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_REWRITABLE)
  864. UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_REWRITABLE;
  865. if (le32_to_cpu(p->accessType) == PD_ACCESS_TYPE_OVERWRITABLE)
  866. UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_OVERWRITABLE;
  867. if (!strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR02) ||
  868. !strcmp(p->partitionContents.ident, PD_PARTITION_CONTENTS_NSR03))
  869. {
  870. struct partitionHeaderDesc *phd;
  871. phd = (struct partitionHeaderDesc *)(p->partitionContentsUse);
  872. if (phd->unallocSpaceTable.extLength)
  873. {
  874. kernel_lb_addr loc = { le32_to_cpu(phd->unallocSpaceTable.extPosition), i };
  875. UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table =
  876. udf_iget(sb, loc);
  877. UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_TABLE;
  878. udf_debug("unallocSpaceTable (part %d) @ %ld\n",
  879. i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_table->i_ino);
  880. }
  881. if (phd->unallocSpaceBitmap.extLength)
  882. {
  883. UDF_SB_ALLOC_BITMAP(sb, i, s_uspace);
  884. if (UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap != NULL)
  885. {
  886. UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extLength =
  887. le32_to_cpu(phd->unallocSpaceBitmap.extLength);
  888. UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition =
  889. le32_to_cpu(phd->unallocSpaceBitmap.extPosition);
  890. UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_UNALLOC_BITMAP;
  891. udf_debug("unallocSpaceBitmap (part %d) @ %d\n",
  892. i, UDF_SB_PARTMAPS(sb)[i].s_uspace.s_bitmap->s_extPosition);
  893. }
  894. }
  895. if (phd->partitionIntegrityTable.extLength)
  896. udf_debug("partitionIntegrityTable (part %d)\n", i);
  897. if (phd->freedSpaceTable.extLength)
  898. {
  899. kernel_lb_addr loc = { le32_to_cpu(phd->freedSpaceTable.extPosition), i };
  900. UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table =
  901. udf_iget(sb, loc);
  902. UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_TABLE;
  903. udf_debug("freedSpaceTable (part %d) @ %ld\n",
  904. i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_table->i_ino);
  905. }
  906. if (phd->freedSpaceBitmap.extLength)
  907. {
  908. UDF_SB_ALLOC_BITMAP(sb, i, s_fspace);
  909. if (UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap != NULL)
  910. {
  911. UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extLength =
  912. le32_to_cpu(phd->freedSpaceBitmap.extLength);
  913. UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition =
  914. le32_to_cpu(phd->freedSpaceBitmap.extPosition);
  915. UDF_SB_PARTFLAGS(sb,i) |= UDF_PART_FLAG_FREED_BITMAP;
  916. udf_debug("freedSpaceBitmap (part %d) @ %d\n",
  917. i, UDF_SB_PARTMAPS(sb)[i].s_fspace.s_bitmap->s_extPosition);
  918. }
  919. }
  920. }
  921. break;
  922. }
  923. }
  924. if (i == UDF_SB_NUMPARTS(sb))
  925. {
  926. udf_debug("Partition (%d) not found in partition map\n", le16_to_cpu(p->partitionNumber));
  927. }
  928. else
  929. {
  930. udf_debug("Partition (%d:%d type %x) starts at physical %d, block length %d\n",
  931. le16_to_cpu(p->partitionNumber), i, UDF_SB_PARTTYPE(sb,i),
  932. UDF_SB_PARTROOT(sb,i), UDF_SB_PARTLEN(sb,i));
  933. }
  934. }
  935. static int
  936. udf_load_logicalvol(struct super_block *sb, struct buffer_head * bh, kernel_lb_addr *fileset)
  937. {
  938. struct logicalVolDesc *lvd;
  939. int i, j, offset;
  940. uint8_t type;
  941. lvd = (struct logicalVolDesc *)bh->b_data;
  942. UDF_SB_ALLOC_PARTMAPS(sb, le32_to_cpu(lvd->numPartitionMaps));
  943. for (i=0,offset=0;
  944. i<UDF_SB_NUMPARTS(sb) && offset<le32_to_cpu(lvd->mapTableLength);
  945. i++,offset+=((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapLength)
  946. {
  947. type = ((struct genericPartitionMap *)&(lvd->partitionMaps[offset]))->partitionMapType;
  948. if (type == 1)
  949. {
  950. struct genericPartitionMap1 *gpm1 = (struct genericPartitionMap1 *)&(lvd->partitionMaps[offset]);
  951. UDF_SB_PARTTYPE(sb,i) = UDF_TYPE1_MAP15;
  952. UDF_SB_PARTVSN(sb,i) = le16_to_cpu(gpm1->volSeqNum);
  953. UDF_SB_PARTNUM(sb,i) = le16_to_cpu(gpm1->partitionNum);
  954. UDF_SB_PARTFUNC(sb,i) = NULL;
  955. }
  956. else if (type == 2)
  957. {
  958. struct udfPartitionMap2 *upm2 = (struct udfPartitionMap2 *)&(lvd->partitionMaps[offset]);
  959. if (!strncmp(upm2->partIdent.ident, UDF_ID_VIRTUAL, strlen(UDF_ID_VIRTUAL)))
  960. {
  961. if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0150)
  962. {
  963. UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP15;
  964. UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt15;
  965. }
  966. else if (le16_to_cpu(((__le16 *)upm2->partIdent.identSuffix)[0]) == 0x0200)
  967. {
  968. UDF_SB_PARTTYPE(sb,i) = UDF_VIRTUAL_MAP20;
  969. UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_virt20;
  970. }
  971. }
  972. else if (!strncmp(upm2->partIdent.ident, UDF_ID_SPARABLE, strlen(UDF_ID_SPARABLE)))
  973. {
  974. uint32_t loc;
  975. uint16_t ident;
  976. struct sparingTable *st;
  977. struct sparablePartitionMap *spm = (struct sparablePartitionMap *)&(lvd->partitionMaps[offset]);
  978. UDF_SB_PARTTYPE(sb,i) = UDF_SPARABLE_MAP15;
  979. UDF_SB_TYPESPAR(sb,i).s_packet_len = le16_to_cpu(spm->packetLength);
  980. for (j=0; j<spm->numSparingTables; j++)
  981. {
  982. loc = le32_to_cpu(spm->locSparingTable[j]);
  983. UDF_SB_TYPESPAR(sb,i).s_spar_map[j] =
  984. udf_read_tagged(sb, loc, loc, &ident);
  985. if (UDF_SB_TYPESPAR(sb,i).s_spar_map[j] != NULL)
  986. {
  987. st = (struct sparingTable *)UDF_SB_TYPESPAR(sb,i).s_spar_map[j]->b_data;
  988. if (ident != 0 ||
  989. strncmp(st->sparingIdent.ident, UDF_ID_SPARING, strlen(UDF_ID_SPARING)))
  990. {
  991. udf_release_data(UDF_SB_TYPESPAR(sb,i).s_spar_map[j]);
  992. UDF_SB_TYPESPAR(sb,i).s_spar_map[j] = NULL;
  993. }
  994. }
  995. }
  996. UDF_SB_PARTFUNC(sb,i) = udf_get_pblock_spar15;
  997. }
  998. else
  999. {
  1000. udf_debug("Unknown ident: %s\n", upm2->partIdent.ident);
  1001. continue;
  1002. }
  1003. UDF_SB_PARTVSN(sb,i) = le16_to_cpu(upm2->volSeqNum);
  1004. UDF_SB_PARTNUM(sb,i) = le16_to_cpu(upm2->partitionNum);
  1005. }
  1006. udf_debug("Partition (%d:%d) type %d on volume %d\n",
  1007. i, UDF_SB_PARTNUM(sb,i), type, UDF_SB_PARTVSN(sb,i));
  1008. }
  1009. if (fileset)
  1010. {
  1011. long_ad *la = (long_ad *)&(lvd->logicalVolContentsUse[0]);
  1012. *fileset = lelb_to_cpu(la->extLocation);
  1013. udf_debug("FileSet found in LogicalVolDesc at block=%d, partition=%d\n",
  1014. fileset->logicalBlockNum,
  1015. fileset->partitionReferenceNum);
  1016. }
  1017. if (lvd->integritySeqExt.extLength)
  1018. udf_load_logicalvolint(sb, leea_to_cpu(lvd->integritySeqExt));
  1019. return 0;
  1020. }
  1021. /*
  1022. * udf_load_logicalvolint
  1023. *
  1024. */
  1025. static void
  1026. udf_load_logicalvolint(struct super_block *sb, kernel_extent_ad loc)
  1027. {
  1028. struct buffer_head *bh = NULL;
  1029. uint16_t ident;
  1030. while (loc.extLength > 0 &&
  1031. (bh = udf_read_tagged(sb, loc.extLocation,
  1032. loc.extLocation, &ident)) &&
  1033. ident == TAG_IDENT_LVID)
  1034. {
  1035. UDF_SB_LVIDBH(sb) = bh;
  1036. if (UDF_SB_LVID(sb)->nextIntegrityExt.extLength)
  1037. udf_load_logicalvolint(sb, leea_to_cpu(UDF_SB_LVID(sb)->nextIntegrityExt));
  1038. if (UDF_SB_LVIDBH(sb) != bh)
  1039. udf_release_data(bh);
  1040. loc.extLength -= sb->s_blocksize;
  1041. loc.extLocation ++;
  1042. }
  1043. if (UDF_SB_LVIDBH(sb) != bh)
  1044. udf_release_data(bh);
  1045. }
  1046. /*
  1047. * udf_process_sequence
  1048. *
  1049. * PURPOSE
  1050. * Process a main/reserve volume descriptor sequence.
  1051. *
  1052. * PRE-CONDITIONS
  1053. * sb Pointer to _locked_ superblock.
  1054. * block First block of first extent of the sequence.
  1055. * lastblock Lastblock of first extent of the sequence.
  1056. *
  1057. * HISTORY
  1058. * July 1, 1997 - Andrew E. Mileski
  1059. * Written, tested, and released.
  1060. */
  1061. static int
  1062. udf_process_sequence(struct super_block *sb, long block, long lastblock, kernel_lb_addr *fileset)
  1063. {
  1064. struct buffer_head *bh = NULL;
  1065. struct udf_vds_record vds[VDS_POS_LENGTH];
  1066. struct generic_desc *gd;
  1067. struct volDescPtr *vdp;
  1068. int done=0;
  1069. int i,j;
  1070. uint32_t vdsn;
  1071. uint16_t ident;
  1072. long next_s = 0, next_e = 0;
  1073. memset(vds, 0, sizeof(struct udf_vds_record) * VDS_POS_LENGTH);
  1074. /* Read the main descriptor sequence */
  1075. for (;(!done && block <= lastblock); block++)
  1076. {
  1077. bh = udf_read_tagged(sb, block, block, &ident);
  1078. if (!bh)
  1079. break;
  1080. /* Process each descriptor (ISO 13346 3/8.3-8.4) */
  1081. gd = (struct generic_desc *)bh->b_data;
  1082. vdsn = le32_to_cpu(gd->volDescSeqNum);
  1083. switch (ident)
  1084. {
  1085. case TAG_IDENT_PVD: /* ISO 13346 3/10.1 */
  1086. if (vdsn >= vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum)
  1087. {
  1088. vds[VDS_POS_PRIMARY_VOL_DESC].volDescSeqNum = vdsn;
  1089. vds[VDS_POS_PRIMARY_VOL_DESC].block = block;
  1090. }
  1091. break;
  1092. case TAG_IDENT_VDP: /* ISO 13346 3/10.3 */
  1093. if (vdsn >= vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum)
  1094. {
  1095. vds[VDS_POS_VOL_DESC_PTR].volDescSeqNum = vdsn;
  1096. vds[VDS_POS_VOL_DESC_PTR].block = block;
  1097. vdp = (struct volDescPtr *)bh->b_data;
  1098. next_s = le32_to_cpu(vdp->nextVolDescSeqExt.extLocation);
  1099. next_e = le32_to_cpu(vdp->nextVolDescSeqExt.extLength);
  1100. next_e = next_e >> sb->s_blocksize_bits;
  1101. next_e += next_s;
  1102. }
  1103. break;
  1104. case TAG_IDENT_IUVD: /* ISO 13346 3/10.4 */
  1105. if (vdsn >= vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum)
  1106. {
  1107. vds[VDS_POS_IMP_USE_VOL_DESC].volDescSeqNum = vdsn;
  1108. vds[VDS_POS_IMP_USE_VOL_DESC].block = block;
  1109. }
  1110. break;
  1111. case TAG_IDENT_PD: /* ISO 13346 3/10.5 */
  1112. if (!vds[VDS_POS_PARTITION_DESC].block)
  1113. vds[VDS_POS_PARTITION_DESC].block = block;
  1114. break;
  1115. case TAG_IDENT_LVD: /* ISO 13346 3/10.6 */
  1116. if (vdsn >= vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum)
  1117. {
  1118. vds[VDS_POS_LOGICAL_VOL_DESC].volDescSeqNum = vdsn;
  1119. vds[VDS_POS_LOGICAL_VOL_DESC].block = block;
  1120. }
  1121. break;
  1122. case TAG_IDENT_USD: /* ISO 13346 3/10.8 */
  1123. if (vdsn >= vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum)
  1124. {
  1125. vds[VDS_POS_UNALLOC_SPACE_DESC].volDescSeqNum = vdsn;
  1126. vds[VDS_POS_UNALLOC_SPACE_DESC].block = block;
  1127. }
  1128. break;
  1129. case TAG_IDENT_TD: /* ISO 13346 3/10.9 */
  1130. vds[VDS_POS_TERMINATING_DESC].block = block;
  1131. if (next_e)
  1132. {
  1133. block = next_s;
  1134. lastblock = next_e;
  1135. next_s = next_e = 0;
  1136. }
  1137. else
  1138. done = 1;
  1139. break;
  1140. }
  1141. udf_release_data(bh);
  1142. }
  1143. for (i=0; i<VDS_POS_LENGTH; i++)
  1144. {
  1145. if (vds[i].block)
  1146. {
  1147. bh = udf_read_tagged(sb, vds[i].block, vds[i].block, &ident);
  1148. if (i == VDS_POS_PRIMARY_VOL_DESC)
  1149. udf_load_pvoldesc(sb, bh);
  1150. else if (i == VDS_POS_LOGICAL_VOL_DESC)
  1151. udf_load_logicalvol(sb, bh, fileset);
  1152. else if (i == VDS_POS_PARTITION_DESC)
  1153. {
  1154. struct buffer_head *bh2 = NULL;
  1155. udf_load_partdesc(sb, bh);
  1156. for (j=vds[i].block+1; j<vds[VDS_POS_TERMINATING_DESC].block; j++)
  1157. {
  1158. bh2 = udf_read_tagged(sb, j, j, &ident);
  1159. gd = (struct generic_desc *)bh2->b_data;
  1160. if (ident == TAG_IDENT_PD)
  1161. udf_load_partdesc(sb, bh2);
  1162. udf_release_data(bh2);
  1163. }
  1164. }
  1165. udf_release_data(bh);
  1166. }
  1167. }
  1168. return 0;
  1169. }
  1170. /*
  1171. * udf_check_valid()
  1172. */
  1173. static int
  1174. udf_check_valid(struct super_block *sb, int novrs, int silent)
  1175. {
  1176. long block;
  1177. if (novrs)
  1178. {
  1179. udf_debug("Validity check skipped because of novrs option\n");
  1180. return 0;
  1181. }
  1182. /* Check that it is NSR02 compliant */
  1183. /* Process any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */
  1184. else if ((block = udf_vrs(sb, silent)) == -1)
  1185. {
  1186. udf_debug("Failed to read byte 32768. Assuming open disc. Skipping validity check\n");
  1187. if (!UDF_SB_LASTBLOCK(sb))
  1188. UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
  1189. return 0;
  1190. }
  1191. else
  1192. return !block;
  1193. }
  1194. static int
  1195. udf_load_partition(struct super_block *sb, kernel_lb_addr *fileset)
  1196. {
  1197. struct anchorVolDescPtr *anchor;
  1198. uint16_t ident;
  1199. struct buffer_head *bh;
  1200. long main_s, main_e, reserve_s, reserve_e;
  1201. int i, j;
  1202. if (!sb)
  1203. return 1;
  1204. for (i = 0; i < ARRAY_SIZE(UDF_SB_ANCHOR(sb)); i++) {
  1205. if (UDF_SB_ANCHOR(sb)[i] && (bh = udf_read_tagged(sb,
  1206. UDF_SB_ANCHOR(sb)[i], UDF_SB_ANCHOR(sb)[i], &ident)))
  1207. {
  1208. anchor = (struct anchorVolDescPtr *)bh->b_data;
  1209. /* Locate the main sequence */
  1210. main_s = le32_to_cpu( anchor->mainVolDescSeqExt.extLocation );
  1211. main_e = le32_to_cpu( anchor->mainVolDescSeqExt.extLength );
  1212. main_e = main_e >> sb->s_blocksize_bits;
  1213. main_e += main_s;
  1214. /* Locate the reserve sequence */
  1215. reserve_s = le32_to_cpu(anchor->reserveVolDescSeqExt.extLocation);
  1216. reserve_e = le32_to_cpu(anchor->reserveVolDescSeqExt.extLength);
  1217. reserve_e = reserve_e >> sb->s_blocksize_bits;
  1218. reserve_e += reserve_s;
  1219. udf_release_data(bh);
  1220. /* Process the main & reserve sequences */
  1221. /* responsible for finding the PartitionDesc(s) */
  1222. if (!(udf_process_sequence(sb, main_s, main_e, fileset) &&
  1223. udf_process_sequence(sb, reserve_s, reserve_e, fileset)))
  1224. {
  1225. break;
  1226. }
  1227. }
  1228. }
  1229. if (i == ARRAY_SIZE(UDF_SB_ANCHOR(sb))) {
  1230. udf_debug("No Anchor block found\n");
  1231. return 1;
  1232. } else
  1233. udf_debug("Using anchor in block %d\n", UDF_SB_ANCHOR(sb)[i]);
  1234. for (i=0; i<UDF_SB_NUMPARTS(sb); i++)
  1235. {
  1236. switch UDF_SB_PARTTYPE(sb, i)
  1237. {
  1238. case UDF_VIRTUAL_MAP15:
  1239. case UDF_VIRTUAL_MAP20:
  1240. {
  1241. kernel_lb_addr ino;
  1242. if (!UDF_SB_LASTBLOCK(sb))
  1243. {
  1244. UDF_SB_LASTBLOCK(sb) = udf_get_last_block(sb);
  1245. udf_find_anchor(sb);
  1246. }
  1247. if (!UDF_SB_LASTBLOCK(sb))
  1248. {
  1249. udf_debug("Unable to determine Lastblock (For Virtual Partition)\n");
  1250. return 1;
  1251. }
  1252. for (j=0; j<UDF_SB_NUMPARTS(sb); j++)
  1253. {
  1254. if (j != i &&
  1255. UDF_SB_PARTVSN(sb,i) == UDF_SB_PARTVSN(sb,j) &&
  1256. UDF_SB_PARTNUM(sb,i) == UDF_SB_PARTNUM(sb,j))
  1257. {
  1258. ino.partitionReferenceNum = j;
  1259. ino.logicalBlockNum = UDF_SB_LASTBLOCK(sb) -
  1260. UDF_SB_PARTROOT(sb,j);
  1261. break;
  1262. }
  1263. }
  1264. if (j == UDF_SB_NUMPARTS(sb))
  1265. return 1;
  1266. if (!(UDF_SB_VAT(sb) = udf_iget(sb, ino)))
  1267. return 1;
  1268. if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP15)
  1269. {
  1270. UDF_SB_TYPEVIRT(sb,i).s_start_offset = udf_ext0_offset(UDF_SB_VAT(sb));
  1271. UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size - 36) >> 2;
  1272. }
  1273. else if (UDF_SB_PARTTYPE(sb,i) == UDF_VIRTUAL_MAP20)
  1274. {
  1275. struct buffer_head *bh = NULL;
  1276. uint32_t pos;
  1277. pos = udf_block_map(UDF_SB_VAT(sb), 0);
  1278. bh = sb_bread(sb, pos);
  1279. UDF_SB_TYPEVIRT(sb,i).s_start_offset =
  1280. le16_to_cpu(((struct virtualAllocationTable20 *)bh->b_data + udf_ext0_offset(UDF_SB_VAT(sb)))->lengthHeader) +
  1281. udf_ext0_offset(UDF_SB_VAT(sb));
  1282. UDF_SB_TYPEVIRT(sb,i).s_num_entries = (UDF_SB_VAT(sb)->i_size -
  1283. UDF_SB_TYPEVIRT(sb,i).s_start_offset) >> 2;
  1284. udf_release_data(bh);
  1285. }
  1286. UDF_SB_PARTROOT(sb,i) = udf_get_pblock(sb, 0, i, 0);
  1287. UDF_SB_PARTLEN(sb,i) = UDF_SB_PARTLEN(sb,ino.partitionReferenceNum);
  1288. }
  1289. }
  1290. }
  1291. return 0;
  1292. }
  1293. static void udf_open_lvid(struct super_block *sb)
  1294. {
  1295. if (UDF_SB_LVIDBH(sb))
  1296. {
  1297. int i;
  1298. kernel_timestamp cpu_time;
  1299. UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1300. UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1301. if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
  1302. UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
  1303. UDF_SB_LVID(sb)->integrityType = LVID_INTEGRITY_TYPE_OPEN;
  1304. UDF_SB_LVID(sb)->descTag.descCRC =
  1305. cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
  1306. le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
  1307. UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
  1308. for (i=0; i<16; i++)
  1309. if (i != 4)
  1310. UDF_SB_LVID(sb)->descTag.tagChecksum +=
  1311. ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i];
  1312. mark_buffer_dirty(UDF_SB_LVIDBH(sb));
  1313. }
  1314. }
  1315. static void udf_close_lvid(struct super_block *sb)
  1316. {
  1317. if (UDF_SB_LVIDBH(sb) &&
  1318. UDF_SB_LVID(sb)->integrityType == LVID_INTEGRITY_TYPE_OPEN)
  1319. {
  1320. int i;
  1321. kernel_timestamp cpu_time;
  1322. UDF_SB_LVIDIU(sb)->impIdent.identSuffix[0] = UDF_OS_CLASS_UNIX;
  1323. UDF_SB_LVIDIU(sb)->impIdent.identSuffix[1] = UDF_OS_ID_LINUX;
  1324. if (udf_time_to_stamp(&cpu_time, CURRENT_TIME))
  1325. UDF_SB_LVID(sb)->recordingDateAndTime = cpu_to_lets(cpu_time);
  1326. if (UDF_MAX_WRITE_VERSION > le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev))
  1327. UDF_SB_LVIDIU(sb)->maxUDFWriteRev = cpu_to_le16(UDF_MAX_WRITE_VERSION);
  1328. if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev))
  1329. UDF_SB_LVIDIU(sb)->minUDFReadRev = cpu_to_le16(UDF_SB_UDFREV(sb));
  1330. if (UDF_SB_UDFREV(sb) > le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev))
  1331. UDF_SB_LVIDIU(sb)->minUDFWriteRev = cpu_to_le16(UDF_SB_UDFREV(sb));
  1332. UDF_SB_LVID(sb)->integrityType = cpu_to_le32(LVID_INTEGRITY_TYPE_CLOSE);
  1333. UDF_SB_LVID(sb)->descTag.descCRC =
  1334. cpu_to_le16(udf_crc((char *)UDF_SB_LVID(sb) + sizeof(tag),
  1335. le16_to_cpu(UDF_SB_LVID(sb)->descTag.descCRCLength), 0));
  1336. UDF_SB_LVID(sb)->descTag.tagChecksum = 0;
  1337. for (i=0; i<16; i++)
  1338. if (i != 4)
  1339. UDF_SB_LVID(sb)->descTag.tagChecksum +=
  1340. ((uint8_t *)&(UDF_SB_LVID(sb)->descTag))[i];
  1341. mark_buffer_dirty(UDF_SB_LVIDBH(sb));
  1342. }
  1343. }
  1344. /*
  1345. * udf_read_super
  1346. *
  1347. * PURPOSE
  1348. * Complete the specified super block.
  1349. *
  1350. * PRE-CONDITIONS
  1351. * sb Pointer to superblock to complete - never NULL.
  1352. * sb->s_dev Device to read suberblock from.
  1353. * options Pointer to mount options.
  1354. * silent Silent flag.
  1355. *
  1356. * HISTORY
  1357. * July 1, 1997 - Andrew E. Mileski
  1358. * Written, tested, and released.
  1359. */
  1360. static int udf_fill_super(struct super_block *sb, void *options, int silent)
  1361. {
  1362. int i;
  1363. struct inode *inode=NULL;
  1364. struct udf_options uopt;
  1365. kernel_lb_addr rootdir, fileset;
  1366. struct udf_sb_info *sbi;
  1367. uopt.flags = (1 << UDF_FLAG_USE_AD_IN_ICB) | (1 << UDF_FLAG_STRICT);
  1368. uopt.uid = -1;
  1369. uopt.gid = -1;
  1370. uopt.umask = 0;
  1371. sbi = kmalloc(sizeof(struct udf_sb_info), GFP_KERNEL);
  1372. if (!sbi)
  1373. return -ENOMEM;
  1374. sb->s_fs_info = sbi;
  1375. memset(UDF_SB(sb), 0x00, sizeof(struct udf_sb_info));
  1376. mutex_init(&sbi->s_alloc_mutex);
  1377. if (!udf_parse_options((char *)options, &uopt))
  1378. goto error_out;
  1379. if (uopt.flags & (1 << UDF_FLAG_UTF8) &&
  1380. uopt.flags & (1 << UDF_FLAG_NLS_MAP))
  1381. {
  1382. udf_error(sb, "udf_read_super",
  1383. "utf8 cannot be combined with iocharset\n");
  1384. goto error_out;
  1385. }
  1386. #ifdef CONFIG_UDF_NLS
  1387. if ((uopt.flags & (1 << UDF_FLAG_NLS_MAP)) && !uopt.nls_map)
  1388. {
  1389. uopt.nls_map = load_nls_default();
  1390. if (!uopt.nls_map)
  1391. uopt.flags &= ~(1 << UDF_FLAG_NLS_MAP);
  1392. else
  1393. udf_debug("Using default NLS map\n");
  1394. }
  1395. #endif
  1396. if (!(uopt.flags & (1 << UDF_FLAG_NLS_MAP)))
  1397. uopt.flags |= (1 << UDF_FLAG_UTF8);
  1398. fileset.logicalBlockNum = 0xFFFFFFFF;
  1399. fileset.partitionReferenceNum = 0xFFFF;
  1400. UDF_SB(sb)->s_flags = uopt.flags;
  1401. UDF_SB(sb)->s_uid = uopt.uid;
  1402. UDF_SB(sb)->s_gid = uopt.gid;
  1403. UDF_SB(sb)->s_umask = uopt.umask;
  1404. UDF_SB(sb)->s_nls_map = uopt.nls_map;
  1405. /* Set the block size for all transfers */
  1406. if (!udf_set_blocksize(sb, uopt.blocksize))
  1407. goto error_out;
  1408. if ( uopt.session == 0xFFFFFFFF )
  1409. UDF_SB_SESSION(sb) = udf_get_last_session(sb);
  1410. else
  1411. UDF_SB_SESSION(sb) = uopt.session;
  1412. udf_debug("Multi-session=%d\n", UDF_SB_SESSION(sb));
  1413. UDF_SB_LASTBLOCK(sb) = uopt.lastblock;
  1414. UDF_SB_ANCHOR(sb)[0] = UDF_SB_ANCHOR(sb)[1] = 0;
  1415. UDF_SB_ANCHOR(sb)[2] = uopt.anchor;
  1416. UDF_SB_ANCHOR(sb)[3] = 256;
  1417. if (udf_check_valid(sb, uopt.novrs, silent)) /* read volume recognition sequences */
  1418. {
  1419. printk("UDF-fs: No VRS found\n");
  1420. goto error_out;
  1421. }
  1422. udf_find_anchor(sb);
  1423. /* Fill in the rest of the superblock */
  1424. sb->s_op = &udf_sb_ops;
  1425. sb->dq_op = NULL;
  1426. sb->s_dirt = 0;
  1427. sb->s_magic = UDF_SUPER_MAGIC;
  1428. sb->s_time_gran = 1000;
  1429. if (udf_load_partition(sb, &fileset))
  1430. {
  1431. printk("UDF-fs: No partition found (1)\n");
  1432. goto error_out;
  1433. }
  1434. udf_debug("Lastblock=%d\n", UDF_SB_LASTBLOCK(sb));
  1435. if ( UDF_SB_LVIDBH(sb) )
  1436. {
  1437. uint16_t minUDFReadRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev);
  1438. uint16_t minUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFWriteRev);
  1439. /* uint16_t maxUDFWriteRev = le16_to_cpu(UDF_SB_LVIDIU(sb)->maxUDFWriteRev); */
  1440. if (minUDFReadRev > UDF_MAX_READ_VERSION)
  1441. {
  1442. printk("UDF-fs: minUDFReadRev=%x (max is %x)\n",
  1443. le16_to_cpu(UDF_SB_LVIDIU(sb)->minUDFReadRev),
  1444. UDF_MAX_READ_VERSION);
  1445. goto error_out;
  1446. }
  1447. else if (minUDFWriteRev > UDF_MAX_WRITE_VERSION)
  1448. {
  1449. sb->s_flags |= MS_RDONLY;
  1450. }
  1451. UDF_SB_UDFREV(sb) = minUDFWriteRev;
  1452. if (minUDFReadRev >= UDF_VERS_USE_EXTENDED_FE)
  1453. UDF_SET_FLAG(sb, UDF_FLAG_USE_EXTENDED_FE);
  1454. if (minUDFReadRev >= UDF_VERS_USE_STREAMS)
  1455. UDF_SET_FLAG(sb, UDF_FLAG_USE_STREAMS);
  1456. }
  1457. if ( !UDF_SB_NUMPARTS(sb) )
  1458. {
  1459. printk("UDF-fs: No partition found (2)\n");
  1460. goto error_out;
  1461. }
  1462. if ( udf_find_fileset(sb, &fileset, &rootdir) )
  1463. {
  1464. printk("UDF-fs: No fileset found\n");
  1465. goto error_out;
  1466. }
  1467. if (!silent)
  1468. {
  1469. kernel_timestamp ts;
  1470. udf_time_to_stamp(&ts, UDF_SB_RECORDTIME(sb));
  1471. udf_info("UDF %s (%s) Mounting volume '%s', timestamp %04u/%02u/%02u %02u:%02u (%x)\n",
  1472. UDFFS_VERSION, UDFFS_DATE,
  1473. UDF_SB_VOLIDENT(sb), ts.year, ts.month, ts.day, ts.hour, ts.minute,
  1474. ts.typeAndTimezone);
  1475. }
  1476. if (!(sb->s_flags & MS_RDONLY))
  1477. udf_open_lvid(sb);
  1478. /* Assign the root inode */
  1479. /* assign inodes by physical block number */
  1480. /* perhaps it's not extensible enough, but for now ... */
  1481. inode = udf_iget(sb, rootdir);
  1482. if (!inode)
  1483. {
  1484. printk("UDF-fs: Error in udf_iget, block=%d, partition=%d\n",
  1485. rootdir.logicalBlockNum, rootdir.partitionReferenceNum);
  1486. goto error_out;
  1487. }
  1488. /* Allocate a dentry for the root inode */
  1489. sb->s_root = d_alloc_root(inode);
  1490. if (!sb->s_root)
  1491. {
  1492. printk("UDF-fs: Couldn't allocate root dentry\n");
  1493. iput(inode);
  1494. goto error_out;
  1495. }
  1496. sb->s_maxbytes = MAX_LFS_FILESIZE;
  1497. return 0;
  1498. error_out:
  1499. if (UDF_SB_VAT(sb))
  1500. iput(UDF_SB_VAT(sb));
  1501. if (UDF_SB_NUMPARTS(sb))
  1502. {
  1503. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
  1504. iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
  1505. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
  1506. iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
  1507. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
  1508. UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace);
  1509. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
  1510. UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace);
  1511. if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15)
  1512. {
  1513. for (i=0; i<4; i++)
  1514. udf_release_data(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
  1515. }
  1516. }
  1517. #ifdef CONFIG_UDF_NLS
  1518. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1519. unload_nls(UDF_SB(sb)->s_nls_map);
  1520. #endif
  1521. if (!(sb->s_flags & MS_RDONLY))
  1522. udf_close_lvid(sb);
  1523. udf_release_data(UDF_SB_LVIDBH(sb));
  1524. UDF_SB_FREE(sb);
  1525. kfree(sbi);
  1526. sb->s_fs_info = NULL;
  1527. return -EINVAL;
  1528. }
  1529. void udf_error(struct super_block *sb, const char *function,
  1530. const char *fmt, ...)
  1531. {
  1532. va_list args;
  1533. if (!(sb->s_flags & MS_RDONLY))
  1534. {
  1535. /* mark sb error */
  1536. sb->s_dirt = 1;
  1537. }
  1538. va_start(args, fmt);
  1539. vsprintf(error_buf, fmt, args);
  1540. va_end(args);
  1541. printk (KERN_CRIT "UDF-fs error (device %s): %s: %s\n",
  1542. sb->s_id, function, error_buf);
  1543. }
  1544. void udf_warning(struct super_block *sb, const char *function,
  1545. const char *fmt, ...)
  1546. {
  1547. va_list args;
  1548. va_start (args, fmt);
  1549. vsprintf(error_buf, fmt, args);
  1550. va_end(args);
  1551. printk(KERN_WARNING "UDF-fs warning (device %s): %s: %s\n",
  1552. sb->s_id, function, error_buf);
  1553. }
  1554. /*
  1555. * udf_put_super
  1556. *
  1557. * PURPOSE
  1558. * Prepare for destruction of the superblock.
  1559. *
  1560. * DESCRIPTION
  1561. * Called before the filesystem is unmounted.
  1562. *
  1563. * HISTORY
  1564. * July 1, 1997 - Andrew E. Mileski
  1565. * Written, tested, and released.
  1566. */
  1567. static void
  1568. udf_put_super(struct super_block *sb)
  1569. {
  1570. int i;
  1571. if (UDF_SB_VAT(sb))
  1572. iput(UDF_SB_VAT(sb));
  1573. if (UDF_SB_NUMPARTS(sb))
  1574. {
  1575. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
  1576. iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
  1577. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
  1578. iput(UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
  1579. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
  1580. UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_uspace);
  1581. if (UDF_SB_PARTFLAGS(sb, UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
  1582. UDF_SB_FREE_BITMAP(sb,UDF_SB_PARTITION(sb),s_fspace);
  1583. if (UDF_SB_PARTTYPE(sb, UDF_SB_PARTITION(sb)) == UDF_SPARABLE_MAP15)
  1584. {
  1585. for (i=0; i<4; i++)
  1586. udf_release_data(UDF_SB_TYPESPAR(sb, UDF_SB_PARTITION(sb)).s_spar_map[i]);
  1587. }
  1588. }
  1589. #ifdef CONFIG_UDF_NLS
  1590. if (UDF_QUERY_FLAG(sb, UDF_FLAG_NLS_MAP))
  1591. unload_nls(UDF_SB(sb)->s_nls_map);
  1592. #endif
  1593. if (!(sb->s_flags & MS_RDONLY))
  1594. udf_close_lvid(sb);
  1595. udf_release_data(UDF_SB_LVIDBH(sb));
  1596. UDF_SB_FREE(sb);
  1597. kfree(sb->s_fs_info);
  1598. sb->s_fs_info = NULL;
  1599. }
  1600. /*
  1601. * udf_stat_fs
  1602. *
  1603. * PURPOSE
  1604. * Return info about the filesystem.
  1605. *
  1606. * DESCRIPTION
  1607. * Called by sys_statfs()
  1608. *
  1609. * HISTORY
  1610. * July 1, 1997 - Andrew E. Mileski
  1611. * Written, tested, and released.
  1612. */
  1613. static int
  1614. udf_statfs(struct super_block *sb, struct kstatfs *buf)
  1615. {
  1616. buf->f_type = UDF_SUPER_MAGIC;
  1617. buf->f_bsize = sb->s_blocksize;
  1618. buf->f_blocks = UDF_SB_PARTLEN(sb, UDF_SB_PARTITION(sb));
  1619. buf->f_bfree = udf_count_free(sb);
  1620. buf->f_bavail = buf->f_bfree;
  1621. buf->f_files = (UDF_SB_LVIDBH(sb) ?
  1622. (le32_to_cpu(UDF_SB_LVIDIU(sb)->numFiles) +
  1623. le32_to_cpu(UDF_SB_LVIDIU(sb)->numDirs)) : 0) + buf->f_bfree;
  1624. buf->f_ffree = buf->f_bfree;
  1625. /* __kernel_fsid_t f_fsid */
  1626. buf->f_namelen = UDF_NAME_LEN-2;
  1627. return 0;
  1628. }
  1629. static unsigned char udf_bitmap_lookup[16] = {
  1630. 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
  1631. };
  1632. static unsigned int
  1633. udf_count_free_bitmap(struct super_block *sb, struct udf_bitmap *bitmap)
  1634. {
  1635. struct buffer_head *bh = NULL;
  1636. unsigned int accum = 0;
  1637. int index;
  1638. int block = 0, newblock;
  1639. kernel_lb_addr loc;
  1640. uint32_t bytes;
  1641. uint8_t value;
  1642. uint8_t *ptr;
  1643. uint16_t ident;
  1644. struct spaceBitmapDesc *bm;
  1645. lock_kernel();
  1646. loc.logicalBlockNum = bitmap->s_extPosition;
  1647. loc.partitionReferenceNum = UDF_SB_PARTITION(sb);
  1648. bh = udf_read_ptagged(sb, loc, 0, &ident);
  1649. if (!bh)
  1650. {
  1651. printk(KERN_ERR "udf: udf_count_free failed\n");
  1652. goto out;
  1653. }
  1654. else if (ident != TAG_IDENT_SBD)
  1655. {
  1656. udf_release_data(bh);
  1657. printk(KERN_ERR "udf: udf_count_free failed\n");
  1658. goto out;
  1659. }
  1660. bm = (struct spaceBitmapDesc *)bh->b_data;
  1661. bytes = le32_to_cpu(bm->numOfBytes);
  1662. index = sizeof(struct spaceBitmapDesc); /* offset in first block only */
  1663. ptr = (uint8_t *)bh->b_data;
  1664. while ( bytes > 0 )
  1665. {
  1666. while ((bytes > 0) && (index < sb->s_blocksize))
  1667. {
  1668. value = ptr[index];
  1669. accum += udf_bitmap_lookup[ value & 0x0f ];
  1670. accum += udf_bitmap_lookup[ value >> 4 ];
  1671. index++;
  1672. bytes--;
  1673. }
  1674. if ( bytes )
  1675. {
  1676. udf_release_data(bh);
  1677. newblock = udf_get_lb_pblock(sb, loc, ++block);
  1678. bh = udf_tread(sb, newblock);
  1679. if (!bh)
  1680. {
  1681. udf_debug("read failed\n");
  1682. goto out;
  1683. }
  1684. index = 0;
  1685. ptr = (uint8_t *)bh->b_data;
  1686. }
  1687. }
  1688. udf_release_data(bh);
  1689. out:
  1690. unlock_kernel();
  1691. return accum;
  1692. }
  1693. static unsigned int
  1694. udf_count_free_table(struct super_block *sb, struct inode * table)
  1695. {
  1696. unsigned int accum = 0;
  1697. uint32_t extoffset, elen;
  1698. kernel_lb_addr bloc, eloc;
  1699. int8_t etype;
  1700. struct buffer_head *bh = NULL;
  1701. lock_kernel();
  1702. bloc = UDF_I_LOCATION(table);
  1703. extoffset = sizeof(struct unallocSpaceEntry);
  1704. while ((etype = udf_next_aext(table, &bloc, &extoffset, &eloc, &elen, &bh, 1)) != -1)
  1705. {
  1706. accum += (elen >> table->i_sb->s_blocksize_bits);
  1707. }
  1708. udf_release_data(bh);
  1709. unlock_kernel();
  1710. return accum;
  1711. }
  1712. static unsigned int
  1713. udf_count_free(struct super_block *sb)
  1714. {
  1715. unsigned int accum = 0;
  1716. if (UDF_SB_LVIDBH(sb))
  1717. {
  1718. if (le32_to_cpu(UDF_SB_LVID(sb)->numOfPartitions) > UDF_SB_PARTITION(sb))
  1719. {
  1720. accum = le32_to_cpu(UDF_SB_LVID(sb)->freeSpaceTable[UDF_SB_PARTITION(sb)]);
  1721. if (accum == 0xFFFFFFFF)
  1722. accum = 0;
  1723. }
  1724. }
  1725. if (accum)
  1726. return accum;
  1727. if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_BITMAP)
  1728. {
  1729. accum += udf_count_free_bitmap(sb,
  1730. UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_bitmap);
  1731. }
  1732. if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_BITMAP)
  1733. {
  1734. accum += udf_count_free_bitmap(sb,
  1735. UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_bitmap);
  1736. }
  1737. if (accum)
  1738. return accum;
  1739. if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_UNALLOC_TABLE)
  1740. {
  1741. accum += udf_count_free_table(sb,
  1742. UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_uspace.s_table);
  1743. }
  1744. if (UDF_SB_PARTFLAGS(sb,UDF_SB_PARTITION(sb)) & UDF_PART_FLAG_FREED_TABLE)
  1745. {
  1746. accum += udf_count_free_table(sb,
  1747. UDF_SB_PARTMAPS(sb)[UDF_SB_PARTITION(sb)].s_fspace.s_table);
  1748. }
  1749. return accum;
  1750. }