Home | History | Annotate | Download | only in blkid
      1 /*
      2  * probe.h - constants and on-disk structures for extracting device data
      3  *
      4  * Copyright (C) 1999 by Andries Brouwer
      5  * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o
      6  * Copyright (C) 2001 by Andreas Dilger
      7  *
      8  * %Begin-Header%
      9  * This file may be redistributed under the terms of the
     10  * GNU Lesser General Public License.
     11  * %End-Header%
     12  */
     13 
     14 #ifndef _BLKID_PROBE_H
     15 #define _BLKID_PROBE_H
     16 
     17 #include <blkid/blkid_types.h>
     18 
     19 struct blkid_magic;
     20 
     21 #define SB_BUFFER_SIZE		0x11000
     22 
     23 struct blkid_probe {
     24 	int			fd;
     25 	blkid_cache		cache;
     26 	blkid_dev		dev;
     27 	unsigned char		*sbbuf;
     28 	size_t			sb_valid;
     29 	unsigned char		*buf;
     30 	size_t			buf_max;
     31 };
     32 
     33 typedef int (*blkid_probe_t)(struct blkid_probe *probe,
     34 			     struct blkid_magic *id, unsigned char *buf);
     35 
     36 struct blkid_magic {
     37 	const char	*bim_type;	/* type name for this magic */
     38 	long		bim_kboff;	/* kilobyte offset of superblock */
     39 	unsigned	bim_sboff;	/* byte offset within superblock */
     40 	unsigned	bim_len;	/* length of magic */
     41 	const char	*bim_magic;	/* magic string */
     42 	blkid_probe_t	bim_probe;	/* probe function */
     43 };
     44 
     45 /*
     46  * Structures for each of the content types we want to extract information
     47  * from.  We do not necessarily need the magic field here, because we have
     48  * already identified the content type before we get this far.  It may still
     49  * be useful if there are probe functions which handle multiple content types.
     50  */
     51 struct ext2_super_block {
     52 	__u32		s_inodes_count;
     53 	__u32		s_blocks_count;
     54 	__u32		s_r_blocks_count;
     55 	__u32		s_free_blocks_count;
     56 	__u32		s_free_inodes_count;
     57 	__u32		s_first_data_block;
     58 	__u32		s_log_block_size;
     59 	__u32		s_dummy3[7];
     60 	unsigned char	s_magic[2];
     61 	__u16		s_state;
     62 	__u32		s_dummy5[8];
     63 	__u32		s_feature_compat;
     64 	__u32		s_feature_incompat;
     65 	__u32		s_feature_ro_compat;
     66 	unsigned char   s_uuid[16];
     67 	char	   s_volume_name[16];
     68 	char	s_last_mounted[64];
     69 	__u32	s_algorithm_usage_bitmap;
     70 	__u8	s_prealloc_blocks;
     71 	__u8	s_prealloc_dir_blocks;
     72 	__u16	s_reserved_gdt_blocks;
     73 	__u8	s_journal_uuid[16];
     74 	__u32	s_journal_inum;
     75 	__u32	s_journal_dev;
     76 	__u32	s_last_orphan;
     77 	__u32	s_hash_seed[4];
     78 	__u8	s_def_hash_version;
     79 	__u8	s_jnl_backup_type;
     80 	__u16	s_reserved_word_pad;
     81 	__u32	s_default_mount_opts;
     82 	__u32	s_first_meta_bg;
     83 	__u32	s_mkfs_time;
     84 	__u32	s_jnl_blocks[17];
     85 	__u32	s_blocks_count_hi;
     86 	__u32	s_r_blocks_count_hi;
     87 	__u32	s_free_blocks_hi;
     88 	__u16	s_min_extra_isize;
     89 	__u16	s_want_extra_isize;
     90 	__u32	s_flags;
     91 	__u16   s_raid_stride;
     92 	__u16   s_mmp_interval;
     93 	__u64   s_mmp_block;
     94 	__u32   s_raid_stripe_width;
     95 	__u32   s_reserved[163];
     96 };
     97 
     98 /* for s_flags */
     99 #define EXT2_FLAGS_TEST_FILESYS		0x0004
    100 
    101 /* for s_feature_compat */
    102 #define EXT3_FEATURE_COMPAT_HAS_JOURNAL		0x0004
    103 
    104 /* for s_feature_ro_compat */
    105 #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER	0x0001
    106 #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE	0x0002
    107 #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR	0x0004
    108 #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE	0x0008
    109 #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM		0x0010
    110 #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK	0x0020
    111 #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE	0x0040
    112 
    113 /* for s_feature_incompat */
    114 #define EXT2_FEATURE_INCOMPAT_FILETYPE		0x0002
    115 #define EXT3_FEATURE_INCOMPAT_RECOVER		0x0004
    116 #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV	0x0008
    117 #define EXT2_FEATURE_INCOMPAT_META_BG		0x0010
    118 #define EXT4_FEATURE_INCOMPAT_EXTENTS		0x0040 /* extents support */
    119 #define EXT4_FEATURE_INCOMPAT_64BIT		0x0080
    120 #define EXT4_FEATURE_INCOMPAT_MMP		0x0100
    121 #define EXT4_FEATURE_INCOMPAT_FLEX_BG		0x0200
    122 
    123 #define EXT2_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
    124 					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
    125 					 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
    126 #define EXT2_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE| \
    127 					 EXT2_FEATURE_INCOMPAT_META_BG)
    128 #define EXT2_FEATURE_INCOMPAT_UNSUPPORTED	~EXT2_FEATURE_INCOMPAT_SUPP
    129 #define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED	~EXT2_FEATURE_RO_COMPAT_SUPP
    130 
    131 #define EXT3_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
    132 					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
    133 					 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
    134 #define EXT3_FEATURE_INCOMPAT_SUPP	(EXT2_FEATURE_INCOMPAT_FILETYPE| \
    135 					 EXT3_FEATURE_INCOMPAT_RECOVER| \
    136 					 EXT2_FEATURE_INCOMPAT_META_BG)
    137 #define EXT3_FEATURE_INCOMPAT_UNSUPPORTED	~EXT3_FEATURE_INCOMPAT_SUPP
    138 #define EXT3_FEATURE_RO_COMPAT_UNSUPPORTED	~EXT3_FEATURE_RO_COMPAT_SUPP
    139 
    140 
    141 struct xfs_super_block {
    142 	unsigned char	xs_magic[4];
    143 	__u32		xs_blocksize;
    144 	__u64		xs_dblocks;
    145 	__u64		xs_rblocks;
    146 	__u32		xs_dummy1[2];
    147 	unsigned char	xs_uuid[16];
    148 	__u32		xs_dummy2[15];
    149 	char		xs_fname[12];
    150 	__u32		xs_dummy3[2];
    151 	__u64		xs_icount;
    152 	__u64		xs_ifree;
    153 	__u64		xs_fdblocks;
    154 };
    155 
    156 struct reiserfs_super_block {
    157 	__u32		rs_blocks_count;
    158 	__u32		rs_free_blocks;
    159 	__u32		rs_root_block;
    160 	__u32		rs_journal_block;
    161 	__u32		rs_journal_dev;
    162 	__u32		rs_orig_journal_size;
    163 	__u32		rs_dummy2[5];
    164 	__u16		rs_blocksize;
    165 	__u16		rs_dummy3[3];
    166 	unsigned char	rs_magic[12];
    167 	__u32		rs_dummy4[5];
    168 	unsigned char	rs_uuid[16];
    169 	char		rs_label[16];
    170 };
    171 
    172 struct reiser4_super_block {
    173 	unsigned char	rs4_magic[16];
    174 	__u16		rs4_dummy[2];
    175 	unsigned char	rs4_uuid[16];
    176 	unsigned char	rs4_label[16];
    177 	__u64		rs4_dummy2;
    178 };
    179 
    180 struct jfs_super_block {
    181 	unsigned char	js_magic[4];
    182 	__u32		js_version;
    183 	__u64		js_size;
    184 	__u32		js_bsize;
    185 	__u32		js_dummy1;
    186 	__u32		js_pbsize;
    187 	__u32		js_dummy2[27];
    188 	unsigned char	js_uuid[16];
    189 	unsigned char	js_label[16];
    190 	unsigned char	js_loguuid[16];
    191 };
    192 
    193 struct romfs_super_block {
    194 	unsigned char	ros_magic[8];
    195 	__u32		ros_dummy1[2];
    196 	unsigned char	ros_volume[16];
    197 };
    198 
    199 struct cramfs_super_block {
    200 	__u8		magic[4];
    201 	__u32		size;
    202 	__u32		flags;
    203 	__u32		future;
    204 	__u8		signature[16];
    205 	struct cramfs_info {
    206 		__u32		crc;
    207 		__u32		edition;
    208 		__u32		blocks;
    209 		__u32		files;
    210 	} info;
    211 	__u8		name[16];
    212 };
    213 
    214 struct swap_id_block {
    215 /*	unsigned char	sws_boot[1024]; */
    216 	__u32		sws_version;
    217 	__u32		sws_lastpage;
    218 	__u32		sws_nrbad;
    219 	unsigned char	sws_uuid[16];
    220 	char		sws_volume[16];
    221 	unsigned char	sws_pad[117];
    222 	__u32		sws_badpg;
    223 };
    224 
    225 /* Yucky misaligned values */
    226 struct vfat_super_block {
    227 /* 00*/	unsigned char	vs_ignored[3];
    228 /* 03*/	unsigned char	vs_sysid[8];
    229 /* 0b*/	unsigned char	vs_sector_size[2];
    230 /* 0d*/	__u8		vs_cluster_size;
    231 /* 0e*/	__u16		vs_reserved;
    232 /* 10*/	__u8		vs_fats;
    233 /* 11*/	unsigned char	vs_dir_entries[2];
    234 /* 13*/	unsigned char	vs_sectors[2];
    235 /* 15*/	unsigned char	vs_media;
    236 /* 16*/	__u16		vs_fat_length;
    237 /* 18*/	__u16		vs_secs_track;
    238 /* 1a*/	__u16		vs_heads;
    239 /* 1c*/	__u32		vs_hidden;
    240 /* 20*/	__u32		vs_total_sect;
    241 /* 24*/	__u32		vs_fat32_length;
    242 /* 28*/	__u16		vs_flags;
    243 /* 2a*/	__u8		vs_version[2];
    244 /* 2c*/	__u32		vs_root_cluster;
    245 /* 30*/	__u16		vs_insfo_sector;
    246 /* 32*/	__u16		vs_backup_boot;
    247 /* 34*/	__u16		vs_reserved2[6];
    248 /* 40*/	unsigned char	vs_unknown[3];
    249 /* 43*/	unsigned char	vs_serno[4];
    250 /* 47*/	unsigned char	vs_label[11];
    251 /* 52*/	unsigned char   vs_magic[8];
    252 /* 5a*/	unsigned char	vs_dummy2[164];
    253 /*1fe*/	unsigned char	vs_pmagic[2];
    254 };
    255 
    256 /* Yucky misaligned values */
    257 struct msdos_super_block {
    258 /* 00*/	unsigned char	ms_ignored[3];
    259 /* 03*/	unsigned char	ms_sysid[8];
    260 /* 0b*/	unsigned char	ms_sector_size[2];
    261 /* 0d*/	__u8		ms_cluster_size;
    262 /* 0e*/	__u16		ms_reserved;
    263 /* 10*/	__u8		ms_fats;
    264 /* 11*/	unsigned char	ms_dir_entries[2];
    265 /* 13*/	unsigned char	ms_sectors[2];
    266 /* 15*/	unsigned char	ms_media;
    267 /* 16*/	__u16		ms_fat_length;
    268 /* 18*/	__u16		ms_secs_track;
    269 /* 1a*/	__u16		ms_heads;
    270 /* 1c*/	__u32		ms_hidden;
    271 /* 20*/	__u32		ms_total_sect;
    272 /* 24*/	unsigned char	ms_unknown[3];
    273 /* 27*/	unsigned char	ms_serno[4];
    274 /* 2b*/	unsigned char	ms_label[11];
    275 /* 36*/	unsigned char   ms_magic[8];
    276 /* 3d*/	unsigned char	ms_dummy2[192];
    277 /*1fe*/	unsigned char	ms_pmagic[2];
    278 };
    279 
    280 struct vfat_dir_entry {
    281 	__u8	name[11];
    282 	__u8	attr;
    283 	__u16	time_creat;
    284 	__u16	date_creat;
    285 	__u16	time_acc;
    286 	__u16	date_acc;
    287 	__u16	cluster_high;
    288 	__u16	time_write;
    289 	__u16	date_write;
    290 	__u16	cluster_low;
    291 	__u32	size;
    292 };
    293 
    294 /* maximum number of clusters */
    295 #define FAT12_MAX 0xFF4
    296 #define FAT16_MAX 0xFFF4
    297 #define FAT32_MAX 0x0FFFFFF6
    298 
    299 struct minix_super_block {
    300 	__u16		ms_ninodes;
    301 	__u16		ms_nzones;
    302 	__u16		ms_imap_blocks;
    303 	__u16		ms_zmap_blocks;
    304 	__u16		ms_firstdatazone;
    305 	__u16		ms_log_zone_size;
    306 	__u32		ms_max_size;
    307 	unsigned char	ms_magic[2];
    308 	__u16		ms_state;
    309 	__u32		ms_zones;
    310 };
    311 
    312 struct mdp_superblock_s {
    313 	__u32 md_magic;
    314 	__u32 major_version;
    315 	__u32 minor_version;
    316 	__u32 patch_version;
    317 	__u32 gvalid_words;
    318 	__u32 set_uuid0;
    319 	__u32 ctime;
    320 	__u32 level;
    321 	__u32 size;
    322 	__u32 nr_disks;
    323 	__u32 raid_disks;
    324 	__u32 md_minor;
    325 	__u32 not_persistent;
    326 	__u32 set_uuid1;
    327 	__u32 set_uuid2;
    328 	__u32 set_uuid3;
    329 };
    330 
    331 struct hfs_super_block {
    332 	char	h_magic[2];
    333 	char	h_dummy[18];
    334 	__u32	h_blksize;
    335 };
    336 
    337 struct ocfs_volume_header {
    338 	unsigned char	minor_version[4];
    339 	unsigned char	major_version[4];
    340 	unsigned char	signature[128];
    341 	char		mount[128];
    342 	unsigned char   mount_len[2];
    343 };
    344 
    345 struct ocfs_volume_label {
    346 	unsigned char	disk_lock[48];
    347 	char		label[64];
    348 	unsigned char	label_len[2];
    349 	unsigned char  vol_id[16];
    350 	unsigned char  vol_id_len[2];
    351 };
    352 
    353 #define ocfsmajor(o) ((__u32)o.major_version[0] \
    354                    + (((__u32) o.major_version[1]) << 8) \
    355                    + (((__u32) o.major_version[2]) << 16) \
    356                    + (((__u32) o.major_version[3]) << 24))
    357 #define ocfslabellen(o)	((__u32)o.label_len[0] + (((__u32) o.label_len[1]) << 8))
    358 #define ocfsmountlen(o)	((__u32)o.mount_len[0] + (((__u32) o.mount_len[1])<<8))
    359 
    360 #define OCFS_MAGIC "OracleCFS"
    361 
    362 struct ocfs2_super_block {
    363 	unsigned char  signature[8];
    364 	unsigned char  s_dummy1[184];
    365 	unsigned char  s_dummy2[80];
    366 	char	       s_label[64];
    367 	unsigned char  s_uuid[16];
    368 };
    369 
    370 #define OCFS2_MIN_BLOCKSIZE             512
    371 #define OCFS2_MAX_BLOCKSIZE             4096
    372 
    373 #define OCFS2_SUPER_BLOCK_BLKNO         2
    374 
    375 #define OCFS2_SUPER_BLOCK_SIGNATURE     "OCFSV2"
    376 
    377 struct oracle_asm_disk_label {
    378 	char dummy[32];
    379 	char dl_tag[8];
    380 	char dl_id[24];
    381 };
    382 
    383 #define ORACLE_ASM_DISK_LABEL_MARKED    "ORCLDISK"
    384 #define ORACLE_ASM_DISK_LABEL_OFFSET    32
    385 
    386 struct iso_volume_descriptor {
    387 	unsigned char	vd_type;
    388 	unsigned char	vd_id[5];
    389 	unsigned char	vd_version;
    390 	unsigned char	flags;
    391 	unsigned char	system_id[32];
    392 	unsigned char	volume_id[32];
    393 	unsigned char	unused[8];
    394 	unsigned char	space_size[8];
    395 	unsigned char	escape_sequences[8];
    396 };
    397 
    398 /* Common gfs/gfs2 constants: */
    399 #define GFS_MAGIC               0x01161970
    400 #define GFS_DEFAULT_BSIZE       4096
    401 #define GFS_SUPERBLOCK_OFFSET	(0x10 * GFS_DEFAULT_BSIZE)
    402 #define GFS_METATYPE_SB         1
    403 #define GFS_FORMAT_SB           100
    404 #define GFS_LOCKNAME_LEN        64
    405 
    406 /* gfs1 constants: */
    407 #define GFS_FORMAT_FS           1309
    408 #define GFS_FORMAT_MULTI        1401
    409 /* gfs2 constants: */
    410 #define GFS2_FORMAT_FS          1801
    411 #define GFS2_FORMAT_MULTI       1900
    412 
    413 struct gfs2_meta_header {
    414 	__u32 mh_magic;
    415 	__u32 mh_type;
    416 	__u64 __pad0;          /* Was generation number in gfs1 */
    417 	__u32 mh_format;
    418 	__u32 __pad1;          /* Was incarnation number in gfs1 */
    419 };
    420 
    421 struct gfs2_inum {
    422 	__u64 no_formal_ino;
    423 	__u64 no_addr;
    424 };
    425 
    426 struct gfs2_sb {
    427 	struct gfs2_meta_header sb_header;
    428 
    429 	__u32 sb_fs_format;
    430 	__u32 sb_multihost_format;
    431 	__u32  __pad0;  /* Was superblock flags in gfs1 */
    432 
    433 	__u32 sb_bsize;
    434 	__u32 sb_bsize_shift;
    435 	__u32 __pad1;   /* Was journal segment size in gfs1 */
    436 
    437 	struct gfs2_inum sb_master_dir; /* Was jindex dinode in gfs1 */
    438 	struct gfs2_inum __pad2; /* Was rindex dinode in gfs1 */
    439 	struct gfs2_inum sb_root_dir;
    440 
    441 	char sb_lockproto[GFS_LOCKNAME_LEN];
    442 	char sb_locktable[GFS_LOCKNAME_LEN];
    443 	/* In gfs1, quota and license dinodes followed */
    444 };
    445 
    446 struct ntfs_super_block {
    447 	__u8	jump[3];
    448 	__u8	oem_id[8];
    449 	__u8	bios_parameter_block[25];
    450 	__u16	unused[2];
    451 	__u64	number_of_sectors;
    452 	__u64	mft_cluster_location;
    453 	__u64	mft_mirror_cluster_location;
    454 	__s8	cluster_per_mft_record;
    455 	__u8	reserved1[3];
    456 	__s8	cluster_per_index_record;
    457 	__u8	reserved2[3];
    458 	__u64	volume_serial;
    459 	__u16	checksum;
    460 };
    461 
    462 struct master_file_table_record {
    463 	__u32	magic;
    464 	__u16	usa_ofs;
    465 	__u16	usa_count;
    466 	__u64	lsn;
    467 	__u16	sequence_number;
    468 	__u16	link_count;
    469 	__u16	attrs_offset;
    470 	__u16	flags;
    471 	__u32	bytes_in_use;
    472 	__u32	bytes_allocated;
    473 } __attribute__((__packed__));
    474 
    475 struct file_attribute {
    476 	__u32	type;
    477 	__u32	len;
    478 	__u8	non_resident;
    479 	__u8	name_len;
    480 	__u16	name_offset;
    481 	__u16	flags;
    482 	__u16	instance;
    483 	__u32	value_len;
    484 	__u16	value_offset;
    485 } __attribute__((__packed__));
    486 
    487 #define MFT_RECORD_VOLUME			3
    488 #define MFT_RECORD_ATTR_VOLUME_NAME		0x60
    489 #define MFT_RECORD_ATTR_VOLUME_INFO		0x70
    490 #define MFT_RECORD_ATTR_OBJECT_ID		0x40
    491 #define MFT_RECORD_ATTR_END			0xffffffffu
    492 
    493 /* HFS / HFS+ */
    494 struct hfs_finder_info {
    495         __u32        boot_folder;
    496         __u32        start_app;
    497         __u32        open_folder;
    498         __u32        os9_folder;
    499         __u32        reserved;
    500         __u32        osx_folder;
    501         __u8         id[8];
    502 } __attribute__((packed));
    503 
    504 struct hfs_mdb {
    505         __u8         signature[2];
    506         __u32        cr_date;
    507         __u32        ls_Mod;
    508         __u16        atrb;
    509         __u16        nm_fls;
    510         __u16        vbm_st;
    511         __u16        alloc_ptr;
    512         __u16        nm_al_blks;
    513         __u32        al_blk_size;
    514         __u32        clp_size;
    515         __u16        al_bl_st;
    516         __u32        nxt_cnid;
    517         __u16        free_bks;
    518         __u8         label_len;
    519         __u8         label[27];
    520         __u32        vol_bkup;
    521         __u16        vol_seq_num;
    522         __u32        wr_cnt;
    523         __u32        xt_clump_size;
    524         __u32        ct_clump_size;
    525         __u16        num_root_dirs;
    526         __u32        file_count;
    527         __u32        dir_count;
    528         struct hfs_finder_info finder_info;
    529         __u8         embed_sig[2];
    530         __u16        embed_startblock;
    531         __u16        embed_blockcount;
    532 } __attribute__((packed));
    533 
    534 /* this is lvm's label_header & pv_header combined. */
    535 
    536 #define LVM2_ID_LEN 32
    537 
    538 struct lvm2_pv_label_header {
    539 	/* label_header */
    540 	__u8	id[8];		/* LABELONE */
    541 	__u64	sector_xl;	/* Sector number of this label */
    542 	__u32	crc_xl;		/* From next field to end of sector */
    543 	__u32	offset_xl;	/* Offset from start of struct to contents */
    544 	__u8	type[8];	/* LVM2 001 */
    545 	/* pv_header */
    546 	__u8	pv_uuid[LVM2_ID_LEN];
    547 } __attribute__ ((packed));
    548 
    549 /*
    550  * Byte swap functions
    551  */
    552 #ifdef __GNUC__
    553 #define _INLINE_ static __inline__
    554 #else				/* For Watcom C */
    555 #define _INLINE_ static inline
    556 #endif
    557 
    558 static __u16 blkid_swab16(__u16 val);
    559 static __u32 blkid_swab32(__u32 val);
    560 static __u64 blkid_swab64(__u64 val);
    561 
    562 #if ((defined __GNUC__) && \
    563      (defined(__i386__) || defined(__i486__) || defined(__i586__)))
    564 
    565 #define _BLKID_HAVE_ASM_BITOPS_
    566 
    567 _INLINE_ __u32 blkid_swab32(__u32 val)
    568 {
    569 #ifdef EXT2FS_REQUIRE_486
    570 	__asm__("bswap %0" : "=r" (val) : "0" (val));
    571 #else
    572 	__asm__("xchgb %b0,%h0\n\t"	/* swap lower bytes	*/
    573 		"rorl $16,%0\n\t"	/* swap words		*/
    574 		"xchgb %b0,%h0"		/* swap higher bytes	*/
    575 		:"=q" (val)
    576 		: "0" (val));
    577 #endif
    578 	return val;
    579 }
    580 
    581 _INLINE_ __u16 blkid_swab16(__u16 val)
    582 {
    583 	__asm__("xchgb %b0,%h0"		/* swap bytes		*/ \
    584 		: "=q" (val) \
    585 		:  "0" (val)); \
    586 		return val;
    587 }
    588 
    589 _INLINE_ __u64 blkid_swab64(__u64 val)
    590 {
    591 	return (blkid_swab32(val >> 32) |
    592 		(((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
    593 }
    594 #endif
    595 
    596 #if !defined(_BLKID_HAVE_ASM_BITOPS_)
    597 
    598 _INLINE_  __u16 blkid_swab16(__u16 val)
    599 {
    600 	return (val >> 8) | (val << 8);
    601 }
    602 
    603 _INLINE_ __u32 blkid_swab32(__u32 val)
    604 {
    605 	return ((val>>24) | ((val>>8)&0xFF00) |
    606 		((val<<8)&0xFF0000) | (val<<24));
    607 }
    608 
    609 _INLINE_ __u64 blkid_swab64(__u64 val)
    610 {
    611 	return (blkid_swab32(val >> 32) |
    612 		(((__u64) blkid_swab32(val & 0xFFFFFFFFUL)) << 32));
    613 }
    614 #endif
    615 
    616 
    617 
    618 #ifdef WORDS_BIGENDIAN
    619 #define blkid_le16(x) blkid_swab16(x)
    620 #define blkid_le32(x) blkid_swab32(x)
    621 #define blkid_le64(x) blkid_swab64(x)
    622 #define blkid_be16(x) (x)
    623 #define blkid_be32(x) (x)
    624 #define blkid_be64(x) (x)
    625 #else
    626 #define blkid_le16(x) (x)
    627 #define blkid_le32(x) (x)
    628 #define blkid_le64(x) (x)
    629 #define blkid_be16(x) blkid_swab16(x)
    630 #define blkid_be32(x) blkid_swab32(x)
    631 #define blkid_be64(x) blkid_swab64(x)
    632 #endif
    633 
    634 #undef _INLINE_
    635 
    636 #endif /* _BLKID_PROBE_H */
    637