~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/hfs/part_tbl.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  linux/fs/hfs/part_tbl.c
  3  *
  4  * Copyright (C) 1996-1997  Paul H. Hargrove
  5  * (C) 2003 Ardis Technologies <roman@ardistech.com>
  6  * This file may be distributed under the terms of the GNU General Public License.
  7  *
  8  * Original code to handle the new style Mac partition table based on
  9  * a patch contributed by Holger Schemel (aeglos@valinor.owl.de).
 10  */
 11 
 12 #include "hfs_fs.h"
 13 
 14 /*
 15  * The new style Mac partition map
 16  *
 17  * For each partition on the media there is a physical block (512-byte
 18  * block) containing one of these structures.  These blocks are
 19  * contiguous starting at block 1.
 20  */
 21 struct new_pmap {
 22         __be16  pmSig;          /* signature */
 23         __be16  reSigPad;       /* padding */
 24         __be32  pmMapBlkCnt;    /* partition blocks count */
 25         __be32  pmPyPartStart;  /* physical block start of partition */
 26         __be32  pmPartBlkCnt;   /* physical block count of partition */
 27         u8      pmPartName[32]; /* (null terminated?) string
 28                                    giving the name of this
 29                                    partition */
 30         u8      pmPartType[32]; /* (null terminated?) string
 31                                    giving the type of this
 32                                    partition */
 33         /* a bunch more stuff we don't need */
 34 } __packed;
 35 
 36 /*
 37  * The old style Mac partition map
 38  *
 39  * The partition map consists for a 2-byte signature followed by an
 40  * array of these structures.  The map is terminated with an all-zero
 41  * one of these.
 42  */
 43 struct old_pmap {
 44         __be16          pdSig;  /* Signature bytes */
 45         struct  old_pmap_entry {
 46                 __be32  pdStart;
 47                 __be32  pdSize;
 48                 __be32  pdFSID;
 49         }       pdEntry[42];
 50 } __packed;
 51 
 52 /*
 53  * hfs_part_find()
 54  *
 55  * Parse the partition map looking for the
 56  * start and length of the 'part'th HFS partition.
 57  */
 58 int hfs_part_find(struct super_block *sb,
 59                   sector_t *part_start, sector_t *part_size)
 60 {
 61         struct buffer_head *bh;
 62         __be16 *data;
 63         int i, size, res;
 64 
 65         res = -ENOENT;
 66         bh = sb_bread512(sb, *part_start + HFS_PMAP_BLK, data);
 67         if (!bh)
 68                 return -EIO;
 69 
 70         switch (be16_to_cpu(*data)) {
 71         case HFS_OLD_PMAP_MAGIC:
 72           {
 73                 struct old_pmap *pm;
 74                 struct old_pmap_entry *p;
 75 
 76                 pm = (struct old_pmap *)bh->b_data;
 77                 p = pm->pdEntry;
 78                 size = 42;
 79                 for (i = 0; i < size; p++, i++) {
 80                         if (p->pdStart && p->pdSize &&
 81                             p->pdFSID == cpu_to_be32(0x54465331)/*"TFS1"*/ &&
 82                             (HFS_SB(sb)->part < 0 || HFS_SB(sb)->part == i)) {
 83                                 *part_start += be32_to_cpu(p->pdStart);
 84                                 *part_size = be32_to_cpu(p->pdSize);
 85                                 res = 0;
 86                         }
 87                 }
 88                 break;
 89           }
 90         case HFS_NEW_PMAP_MAGIC:
 91           {
 92                 struct new_pmap *pm;
 93 
 94                 pm = (struct new_pmap *)bh->b_data;
 95                 size = be32_to_cpu(pm->pmMapBlkCnt);
 96                 for (i = 0; i < size;) {
 97                         if (!memcmp(pm->pmPartType,"Apple_HFS", 9) &&
 98                             (HFS_SB(sb)->part < 0 || HFS_SB(sb)->part == i)) {
 99                                 *part_start += be32_to_cpu(pm->pmPyPartStart);
100                                 *part_size = be32_to_cpu(pm->pmPartBlkCnt);
101                                 res = 0;
102                                 break;
103                         }
104                         brelse(bh);
105                         bh = sb_bread512(sb, *part_start + HFS_PMAP_BLK + ++i, pm);
106                         if (!bh)
107                                 return -EIO;
108                         if (pm->pmSig != cpu_to_be16(HFS_NEW_PMAP_MAGIC))
109                                 break;
110                 }
111                 break;
112           }
113         }
114         brelse(bh);
115 
116         return res;
117 }
118 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php