This file is indexed.

/usr/sbin/ocs-get-part-info is in clonezilla 3.27.16-2.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
#!/bin/bash
# Author: Steven Shiau <steven _at_ nchc org tw>
# License: GPL

#
export LC_ALL=C

# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"

. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
. /etc/drbl/drbl-ocs.conf
. $DRBL_SCRIPT_PATH/sbin/ocs-functions

#
prog="$(basename $0)"
USAGE() {
   echo "Usage: $prog [OPTION] PARTITION VALUE1 VALUE2..."
   echo "PARTITION is the partition device name. e.g. /dev/sda1"
   echo "VALUE is one of these value: start, end, size, type, filesystem or flags"
   echo "OPTION:"
   echo "-u, --unit UNIT     When the VALUE1, VALUE2... is about size, show the size with unit UNIT (s, kB, MB, GB... which parted accepts)."
   echo "Ex:" 
   echo "To list the /dev/sda1 size with unit sector"
   echo "  $prog -u s /dev/sda1 size"
}

#
check_col_idx() {
  # DEV is like /dev/hda
  # wanted is like "start", "end", "file" (since it's "file system" in SuSE 10.0, and filesystem in Redhat/FC)
  # Example in FC5 with parted-1.7.1-15.fc5
  #[root@fc5101 tmp]# LC_ALL=C parted -s /dev/hda p
  #
  #Disk /dev/hda: 4295MB
  #Sector size (logical/physical): 512B/512B
  #Partition Table: msdos
  #
  #Number  Start   End     Size    Type     File system  Flags
  # 1      32.3kB  4285MB  4285MB  primary  ntfs         boot
  #
  #For Mac OS GPT:
  #Model: ATA Hitachi HTS54168 (scsi)
  #Disk /dev/sda: 80.0GB
  #Sector size (logical/physical): 512B/512B
  #Partition Table: gpt
  #
  #Number  Start   End     Size    File system  Name                  Flags
  # 1      20.5kB  210MB   210MB   fat32        EFI System Partition  boot
  # 2      210MB   38.3GB  38.1GB  hfs+         Untitled
  # 3      38.4GB  41.6GB  3221MB  fat32        Untitled
  #
  # For multipath device (e.g. cciss):
  #root@cciss:~# parted -s /dev/cciss/c0d0 print
  #Model: Compaq Smart Array (cpqarray)
  #Disk /dev/cciss/c0d0: 440GB
  #Sector size (logical/physical): 512B/512B
  #Partition Table: msdos
  #
  #Number  Start   End    Size    Type      File system     Flags
  # 1      1049kB  107GB  107GB   primary   ext4
  # 2      107GB   440GB  333GB   extended
  # 5      107GB   161GB  53.7GB  logical   reiserfs
  # 6      161GB   172GB  10.7GB  logical   linux-swap(v1)
  # 7      172GB   440GB  269GB   logical   xfs
  #
  # Different versions of parted have different output formats, that's why it's so complicated here.
  local DEV=$1
  local wanted=$2
  local part_info_tmp
  part_info_tmp="$(mktemp /tmp/part_tmp.XXXXXX)"
  LC_ALL=C parted -s $DEV print | sed -r -e "s/File system/Filesystem/g" > $part_info_tmp 2>/dev/null
  # The seq is put in the order of possibility in clonezilla. Because filesystem is get by blkid, we put size then type.
  for i in 4 5 6 3 2 1 7; do
    col="$(grep -i flags $part_info_tmp | awk -F" " "{print \$$i}")"
    if [ -n "$(echo $col | grep -i $wanted)" ]; then
      col_idx=$i
      break
    fi
  done
  [ -f "$part_info_tmp" ] && rm -f $part_info_tmp
  echo $col_idx
} # end of check_col_idx

#
get_from_parted() {
  local part_info
  target_hd="/dev/$(get_diskname $part)"
  # For cciss partition, e.g. /dev/cciss/c0d0p2 will be "p2" which is got from $(get_part_number /dev/cciss/c0d0p2)", here the part_index we want is only number, hence we need to trip the leading characters.
  part_index="$(LC_ALL=C get_part_number $part | sed -r -e "s|^[^[:digit:]]*||g")"
  
  part_info="$(mktemp /tmp/part.XXXXXX)"
  [ -n "$unit" ] && unit_opt="unit $unit"
  LC_ALL=C parted -s $target_hd $unit_opt print > $part_info 2>/dev/null
  
  case "$wanted" in
    start)
       start_idx="$(check_col_idx $target_hd start)"
       if [ -z "$start_idx" ]; then
         [ -f "$part_info" ] && rm -f $part_info
	 return 1
       fi
       part_start=$(LC_ALL=C grep -E "^[[:space:]]*$part_index\>" $part_info | awk -F" " "{print \$$start_idx}")
       echo "$part_start"
       ;;
    end)
       end_idx="$(check_col_idx $target_hd end)"
       if [ -z "$end_idx" ]; then
         [ -f "$part_info" ] && rm -f $part_info
	 return 1
       fi
       part_end=$(LC_ALL=C grep -E "^[[:space:]]*$part_index\>" $part_info | awk -F" " "{print \$$end_idx}")
       echo "$part_end"
       ;;
    size)
       size_idx="$(check_col_idx $target_hd size)"
       if [ -z "$size_idx" ]; then
         [ -f "$part_info" ] && rm -f $part_info
	 return 1
       fi
       part_size=$(LC_ALL=C grep -E "^[[:space:]]*$part_index\>" $part_info | awk -F" " "{print \$$size_idx}")
       echo "$part_size"
       ;;
    type)
       type_idx="$(check_col_idx $target_hd type)"
       if [ -z "$type_idx" ]; then
         [ -f "$part_info" ] && rm -f $part_info
	 return 1
       fi
       part_type=$(LC_ALL=C grep -E "^[[:space:]]*$part_index\>" $part_info | awk -F" " "{print \$$type_idx}")
       echo "$part_type"
       ;;
    filesystem|fs)
       filesystem_idx="$(check_col_idx $target_hd file)"
       if [ -z "$filesystem_idx" ]; then
         [ -f "$part_info" ] && rm -f $part_info
	 return 1
       fi
       part_fs=$(LC_ALL=C grep -E "^[[:space:]]*$part_index\>" $part_info | awk -F" " "{print \$$filesystem_idx}")
       echo "$part_fs"
       ;;
    flags)
       flags_idx="$(check_col_idx $target_hd flags)"
       if [ -z "$flags_idx" ]; then
         [ -f "$part_info" ] && rm -f $part_info
	 return 1
       fi
       part_flags=$(LC_ALL=C grep -E "^[[:space:]]*$part_index\>" $part_info | awk -F" " "{print \$$flags_idx}")
       echo "$part_flags"
       ;;
  esac
  
  [ -f "$part_info" ] && rm -f $part_info
} # end of get_from_parted

#
get_fs_from_blkid() {
  local part_="$1"  # e.g. sda1, cciss/c0d0p1, dm-1
  local blkinfo TYPE hdtmp ptno pt_id p_type pt_info
  if type blkid &>/dev/null; then
    # blikd output example:
    # /dev/sda1: LABEL="/boot" UUID="a9cb47b6-e3ff-4a26-80e2-3fa8d30702e8" SEC_TYPE="ext2" TYPE="ext3" 
    # /dev/VolGroup00/LogVol00: UUID="110bc035-6920-4732-b117-5124843b93b9" SEC_TYPE="ext2" TYPE="ext3" 
    # /dev/VolGroup00/LogVol01: TYPE="swap" UUID="af85b756-39fa-48f0-80e7-b2128d5c87ab"
    # We want to filter to filter them as: TYPE="ext3" only
    # If $part_ is /dev/dm-1 in /proc/partitions, blkid still can get the correct type for /dev/dm-1 even the output of blkid is /dev/mapper/...:
    # ===============
    # root@fakeraid:~# cat /proc/partitions 
    # major minor  #blocks  name
    # 
    #   8        0  976762584 sda
    #   8        1  104857600 sda1
    #   8        2  314572800 sda2
    #   8        3  524288000 sda3
    #   8       16  976762584 sdb
    #  11        0    1048575 sr0
    #   7        0      90452 loop0
    # 254        0 1953519872 dm-0
    # 254        1  104857600 dm-1
    # 254        2  314572800 dm-2
    # 254        3  524288000 dm-3
    # ===============
    # The output of blkid:
    # root@fakeraid:~# blkid
    # /dev/sdb: TYPE="isw_raid_member" 
    # /dev/mapper/isw_deaeieebih_Volume01: UUID="d2350cad-2c66-4ac5-accb-bec596522958" TYPE="xfs" 
    # /dev/mapper/isw_deaeieebih_Volume02: UUID="300ed329-7dff-4b55-bb50-a3fab87d24b3" TYPE="xfs" 
    # /dev/mapper/isw_deaeieebih_Volume03: UUID="ab6cf10a-c74d-43e4-91d5-18817ff3d03f" TYPE="xfs" 
    # /dev/loop0: TYPE="squashfs" 
    # root@fakeraid:~# blkid -o export -c /dev/null /dev/sde30
    # DEVNAME=/dev/sde30
    # UUID_SUB=4e672e07-887dbdcf-4350-000c292c5b04
    # UUID=4e672e07-7dbf61e7-08e6-000c292c5b04
    # TYPE=VMFS_volume_member
    # PARTUUID=0004b3fb-1e
    # //NOTE// "TYPE" in the output of blkid is actually for file system.
    TYPE="$(LC_ALL=C blkid -o export -c /dev/null $part_ | grep -E "^TYPE=.*" | sed -r -e "s|^TYPE=||")"
    # If the result is vfat, it's too fuzzy, since there are fat12/fat16/fat32, and partimage does not support fat12.
    if [ -n "$(echo $TYPE | grep -iE "vfat")" ]; then
      if [ "$(file -Ls $part_ | grep -iw "fat" | grep -iw "12 bit")" ]; then
        # Ex. for FAT12:
	# /dev/sda1: x86 boot sector, mkdosfs boot message display, code offset 0x3c, OEM-ID " mkdosfs", sectors/cluster 16, root entries 512, sectors 63252 (volumes <=32 MB) , Media descriptor 0xf8, sectors/FAT 12, heads 255, serial number 0x487771fc, label: "           ", FAT (12 bit)
       TYPE="fat12"
      fi
    fi
    # UFS:
    # For ufs, it might be false one, since if the Id=a5, it's FreeBSD slice
    # E.g. The disk sdb has 3 slices (sdb1, sdb2, sdb3), and slice sdb1 contains partitions sdb5, sdb6, sdb7, slice sdb2 contains partitions sdb8, sdb9, sdb10, and sdb3 contains partitions sdb11, sdb12, sdb13. As shown in the following.
    # Then blkid will show /dev/sdb1 as ufs, but it's only slice, we only have to save the first 16 sectors by "dd if=/dev/sdb1 of=slice1-table.dd bs=512 count=16"
    # Therefore if blkid shows "ufs", we have to dig more.
    #
    # # sfdisk -l -uS /dev/sdb
    # Disk /dev/sdb: 2219 cylinders, 255 heads, 63 sectors/track
    # Units = sectors of 512 bytes, counting from 0
    #
    #    Device Boot    Start       End   #sectors  Id  System
    #    /dev/sdb1   *        63  20479094   20479032  a5  FreeBSD
    #    /dev/sdb2      20479095  24574724    4095630  a5  FreeBSD
    #    /dev/sdb3      24574725  33554114    8979390  a5  FreeBSD
    #    /dev/sdb4             0         -          0   0  Empty
    #    /dev/sdb5            63  10479094   10479032
    #    /dev/sdb6      10479095  20479094   10000000
    #    /dev/sdb7      21574725  22574724    1000000
    #    /dev/sdb8      20479095  21574724    1095630
    #    /dev/sdb9      22574725  24574724    2000000
    #    /dev/sdb10     24704115  25804114    1100000
    #    /dev/sdb11     24574725  24704114     129390
    #    /dev/sdb12     26304115  33554114    7250000
    #    /dev/sdb13     25804115  26304114     500000
    #
    # # disktype /dev/sdb
    # --- /dev/sdb
    # Block device, size 17 GiB (18253611008 bytes)
    # DOS/MBR partition map
    # Partition 1: 9.765 GiB (10485264384 bytes, 20479032 sectors from 63, bootable)
    #   Type 0xA5 (FreeBSD)
    #   FreeBSD boot loader (i386 boot1 at sector 0)
    #   FreeBSD boot loader (i386 boot2/BTX 1.02 at sector 2)
    #   BSD disklabel (at sector 1), 8 partitions
    #   Partition a: 4.997 GiB (5365264384 bytes, 10479032 sectors from 63)
    #     Type 7 (4.2BSD fast file system)
    #     Includes the disklabel and boot code
    #     UFS2 file system, 64 KiB offset, little-endian
    #       Last mounted at "/"
    #   Partition b: 4.768 GiB (5120000000 bytes, 10000000 sectors from 10479095)
    #     Type 1 (swap)
    #     Blank disk/medium
    #   Partition c: 9.765 GiB (10485264384 bytes, 20479032 sectors from 63)
    #     Type 0 (Unused)
    # Partition 2: 1.953 GiB (2096962560 bytes, 4095630 sectors from 20479095)
    #   Type 0xA5 (FreeBSD)
    #   FreeBSD boot loader (i386 boot1 at sector 0)
    #   FreeBSD boot loader (i386 boot2/BTX 1.02 at sector 2)
    #   BSD disklabel (at sector 1), 8 partitions
    #   Partition b: 488.3 MiB (512000000 bytes, 1000000 sectors from 21574725)
    #     Type 1 (swap)
    #     Blank disk/medium
    #   Partition c: 1.953 GiB (2096962560 bytes, 4095630 sectors from 20479095)
    #     Type 0 (Unused)
    #   Partition d: 535.0 MiB (560962560 bytes, 1095630 sectors from 20479095)
    #     Type 7 (4.2BSD fast file system)
    #     Includes the disklabel and boot code
    #     UFS2 file system, 64 KiB offset, little-endian
    #       Last mounted at "/home"
    #   Partition e: 976.6 MiB (1024000000 bytes, 2000000 sectors from 22574725)
    #     Type 1 (swap)
    #     Blank disk/medium
    # Partition 3: 4.282 GiB (4597447680 bytes, 8979390 sectors from 24574725)
    #   Type 0xA5 (FreeBSD)
    #   FreeBSD boot loader (i386 boot1 at sector 0)
    #   FreeBSD boot loader (i386 boot2/BTX 1.02 at sector 2)
    #   BSD disklabel (at sector 1), 8 partitions
    #   Partition b: 537.1 MiB (563200000 bytes, 1100000 sectors from 24704115)
    #     Type 1 (swap)
    #     Blank disk/medium
    #   Partition c: 4.282 GiB (4597447680 bytes, 8979390 sectors from 24574725)
    #     Type 0 (Unused)
    #   Partition d: 63.18 MiB (66247680 bytes, 129390 sectors from 24574725)
    #     Type 7 (4.2BSD fast file system)
    #     Includes the disklabel and boot code
    #     UFS2 file system, 64 KiB offset, little-endian
    #       Last mounted at "/opt"
    #   Partition e: 3.457 GiB (3712000000 bytes, 7250000 sectors from 26304115)
    #     Type 7 (4.2BSD fast file system)
    #     UFS2 file system, 64 KiB offset, little-endian
    #       Last mounted at "/home2"
    #   Partition h: 244.1 MiB (256000000 bytes, 500000 sectors from 25804115)
    #     Type 1 (swap)
    #     Blank disk/medium
    #
    # # blkid
    # /dev/sdb1: TYPE="ufs"
    # /dev/sdb2: TYPE="ufs"
    # /dev/sdb3: TYPE="ufs"
    # /dev/sdb5: TYPE="ufs"
    # /dev/sdb8: TYPE="ufs"
    # /dev/sdb11: TYPE="ufs"
    # /dev/sdb12: TYPE="ufs"
    #
    if [ -n "$(echo $TYPE | grep -iE "ufs")" ]; then
      # (1) MBR
      # The example for sfdisk command to get partition id:
      # sfdisk --print-id /dev/sdb 1
      # a5
      # (2) GPT
      # root@debian:~#  blkid
      # /dev/sda2: TYPE="ufs"
      # /dev/sda3: TYPE="ufs"
      # /dev/sda4: TYPE="ufs"
      # /dev/sda5: TYPE="ufs"
      # /dev/loop0: TYPE="squashfs"
      # 
      # root@debian:~#  sgdisk -p /dev/sda
      # Disk /dev/sda: 41943040 sectors, 20.0 GiB
      # Logical sector size: 512 bytes
      # Disk identifier (GUID): 0D3CC1B2-3DF6-11E1-AF1F-000C2976A9B0
      # Partition table holds up to 128 entries
      # First usable sector is 34, last usable sector is 41943006
      # Partitions will be aligned on 2-sector boundaries
      # Total free space is 1 sectors (512 bytes)
      # 
      # Number  Start (sector)    End (sector)  Size       Code  Name
      #    1              34             161   64.0 KiB    A501
      #    2             162         2097313   1024.0 MiB  A502
      #    3         2097314        12583073   5.0 GiB     A503
      #    4        12583074        16777377   2.0 GiB     A503
      #    5        16777378        41943005   12.0 GiB    A503
      # 
      # root@debian:~#  sgdisk -i 1 /dev/sda
      # Partition GUID code: 83BD6B9D-7F41-11DC-BE0B-001560B84F0F (FreeBSD boot)
      # Partition unique GUID: 0D3D0C89-3DF6-11E1-AF1F-000C2976A9B0
      # First sector: 34 (at 17.0 KiB)
      # Last sector: 161 (at 80.5 KiB)
      # Partition size: 128 sectors (64.0 KiB)
      # Attribute flags: 0000000000000000
      # Partition name: ''
      # 
      # root@debian:~#  sgdisk -i 2 /dev/sda
      # Partition GUID code: 516E7CB5-6ECF-11D6-8FF8-00022D09712B (FreeBSD swap)
      # Partition unique GUID: 39B6CECD-3DF6-11E1-AF1F-000C2976A9B0
      # First sector: 162 (at 81.0 KiB)
      # Last sector: 2097313 (at 1.0 GiB)
      # Partition size: 2097152 sectors (1024.0 MiB)
      # Attribute flags: 0000000000000000
      # Partition name: ''
      # 
      # root@debian:~#  sgdisk -i 3 /dev/sda
      # Partition GUID code: 516E7CB6-6ECF-11D6-8FF8-00022D09712B (FreeBSD UFS)
      # Partition unique GUID: 436931F9-3DF6-11E1-AF1F-000C2976A9B0
      # First sector: 2097314 (at 1.0 GiB)
      # Last sector: 12583073 (at 6.0 GiB)
      # Partition size: 10485760 sectors (5.0 GiB)
      # Attribute flags: 0000000000000000
      # Partition name: ''
      # ===
      # /dev/sda5 -> /dev/sda 5
      hdtmp="/dev/$(get_diskname ${part_})"
      ptno="$(get_part_number ${part_})"
      p_type="$(get_partition_table_type_from_disk $hdtmp)"
      case "$p_type" in
      mbr)
        # sfdisk >= 2.26 "--print-id" is deprecated in favour of "--part-type"
	if [ -n "$(LC_ALL=C sfdisk --help 2>&1 | grep -- "--part-type")" ]; then
	  print_id_opt="--part-type"
        else
          # old option "--print-id"
	  print_id_opt="--print-id"
	fi
        pt_id="$(LC_ALL=C sfdisk $print_id_opt $hdtmp $ptno 2>/dev/null)"
        # Partition ID a5 (FreeBSD), a6 (OpenBSD), a9 (NetBSD) are slices
        if [ "$(echo "$pt_id" | grep -Ewi "(a5|a6|a9)")" ]; then
          TYPE="BSD_slice"
        fi
	;;
      gpt)
	pt_info="$(LC_ALL=C sgdisk -i $ptno $hdtmp 2>/dev/null | grep -Ei "^Partition GUID code:")"
	if [ -n "$(echo $pt_info | grep -i "FreeBSD boot")" ]; then
          TYPE="BSD_boot"
	elif [ -n "$(echo $pt_info | grep -i "FreeBSD swap")" ]; then
          # Do not use any word with "swap" in TYPE, otherwise it won't be saved by dd, since we do not good mechanism for BSD swap imaging/cloning.
          TYPE="BSD_part"
	fi
	;;
      esac
    fi
    # For Ext, especially on ChromiumOS/ChromeOS, the root filesystem (/dev/sda3) is like:
    # /dev/sda1: LABEL="STATE" UUID="0b2b024a-2226-44d6-b482-5304c0ba1ad3" TYPE="ext4" PARTLABEL="STATE" PARTUUID="aff6ee6c-1f3d-e640-ac20-662a4e4321ac"
    # /dev/sda3: LABEL="ROOT-A" SEC_TYPE="ext2" TYPE="ext4" PARTLABEL="ROOT-A" PARTUUID="d84d1434-e366-994a-9b63-07230c2ba241"
    # /dev/sda8: LABEL="OEM" UUID="9c727706-030f-4fc8-9860-9cd49f301c99" TYPE="ext4" PARTLABEL="OEM" PARTUUID="a2db8f6d-6171-f14a-8c9e-409655a1dfdf"
    # /dev/sda12: SEC_TYPE="msdos" LABEL="EFI-SYSTEM" UUID="C9BF-10DC" TYPE="vfat" PARTLABEL="EFI-SYSTEM" PARTUUID="de94c6c7-2d57-9c44-8ecd-d1271d66afc2"
    # /dev/sda2: PARTLABEL="KERN-A" PARTUUID="290e0120-49f1-5246-aff4-95790db5419e"
    # /dev/sda4: PARTLABEL="KERN-B" PARTUUID="98361589-6471-6c46-8ebf-28225baec874"
    # /dev/sda5: PARTLABEL="ROOT-B" PARTUUID="75f18b32-d4fe-4d43-be2c-f44edb73c463"
    # /dev/sda11: PARTLABEL="RWFW" PARTUUID="d1d19fae-1141-554d-915b-e1534ef4333d"
    # It implements some special features (not compatible with Linux Extfs) which could not be saved correctly by Partclone:
    # e2fsck -n /dev/sda3
    # e2fsck 1.42.12 (29-Aug-2014)
    # /dev/sda3 has unsupported feature(s): FEATURE_R24 FEATURE_R25 FEATURE_R26 FEATURE_R27 FEATURE_R28 FEATURE_R29 FEATURE_R30 FEATURE_R31
    # e2fsck: Get a newer version of e2fsck!
    # ROOT-A: ********** WARNING: Filesystem still has errors **********
    if [ -n "$(LC_ALl=C echo $TYPE | grep -iE "ext")" ]; then
      if [ -n "$(LC_ALL=C blkid -c /dev/null $part_ | grep -iw 'LABEL="ROOT-A"' )" ]; then
         # /dev/sda3: LABEL="ROOT-A" SEC_TYPE="ext2" TYPE="ext4" PARTLABEL="ROOT-A" PARTUUID="d84d1434-e366-994a-9b63-07230c2ba241"
	 if [ -n "$(LC_ALL=C e2fsck -n $part_ 2>&1 | grep -iw "has unsupported feature(s): FEATURE_.*")" ]; then
	   TYPE="chromium_ext4"
	 fi
      fi
    fi
    echo "$TYPE"
  fi
} # end of get_fs_from_blkid
#
get_fs_from_partclone_fstype() {
  local part_="$1"  # e.g. sda1, cciss/c0d0p1, dm-1
  local fstypeinfo TYPE
  if type partclone.fstype &>/dev/null; then
    fstypeinfo="$(mktemp /tmp/fstypeinfo.XXXXXX)"
    # partclone.fstype output example:
    # partclone.fstype /dev/hda3 2>/dev/null
    # TYPE="vmfs"
    # We want to filter to filter them as: TYPE="vmfs" only
    LC_ALL=C partclone.fstype $part_ 2>/dev/null| grep -o -E '\<TYPE="[^[:space:]]*"($|[[:space:]]+)' > $fstypeinfo
    TYPE=""
    . $fstypeinfo
    echo "$TYPE"
    [ -f "$fstypeinfo" ] && rm -f $fstypeinfo
  fi
} # end of get_fs_from_partclone_fstype
#
get_size_from_lsblk() {
  local part_="$1"  # e.g. /dev/sda1, /dev/cciss/c0d0p1
  if type lsblk &>/dev/null; then
    part_size="$(LC_ALL=C lsblk -n -d -o size ${part_} | sed -r -e "s/^[[:space:]]*//g")"
    echo "$part_size"
  fi
} # end of get_size_from_lsblk
#
get_type_from_lsblk() {
  # This function is intended to get if a parition is swap or extended. 
  # Because the mechanism got from parted is too slow, we use lsblk to simulate it.
  local part_="$1"  # e.g. /dev/sda1, /dev/cciss/c0d0p1
  if type lsblk &>/dev/null; then
    # For swap, e.g.
    # lsblk -n -o FSTYPE /dev/sda6
    part_type="$(LC_ALL=C lsblk -n -d -o FSTYPE ${part_} | sed -r -e "s/^[[:space:]]*//g")"
    if [ "$part_type" != "swap" ]; then
      # We only care if it's swap or extended. For other file system, just ignore it.
      part_type=""
    fi
    if [ -z "$part_type" ]; then
      # For extended, e.g.
      # lsblk -n -o PARTTYPE /dev/sda2
      part_type="$(LC_ALL=C lsblk -n -d -o PARTTYPE ${part_} | sed -r -e "s/^[[:space:]]*//g")"
      if [ "$part_type" = "0x5" -o \
           "$part_type" = "0xf" ]; then
        # Convert to human readable
        part_type="extended"
      fi
    fi
    echo "$part_type"
  fi
} # end of get_type_from_lsblk
#
check_if_bitlocker_fs() {
  local rc_n rc_f
  if type dislocker-find &>/dev/null; then
    dislocker-find $part &>/dev/null
    # //NOTE// Here the return code for dislocker-find is the number of bitlocker partition. Not the true/false.
    rc_n=$?
    if [ "$rc_n" -eq 1 ]; then
      rc_f="bitlocker"
    else
      rc_f=""
    fi
    echo "$rc_f"
  fi
} # end of check_if_bitlocker_fs
#
check_if_MSR_part() {
  local rc_n rc_f
  # Microsoft Reserved Partition
  # The GPT label for this partition type is E3C9E316-0B5C-4DB8-817D-F92DF00215AE.
  # Only exists on GPT partition table. It's not UUID of file system, nor the PARTUUID for the GPT partition. Actually there is no any file system for this. Here we just want to identify it.
  #
  rc_n="$(LC_ALL=C sfdisk -d "/dev/$(get_diskname $part)" 2>/dev/null | grep -Ew "$part" | grep -Eo type=[[:alnum:]-]+)"
  rc_f=""
  if [ "$(echo $rc_n | grep -Ewi "E3C9E316-0B5C-4DB8-817D-F92DF00215AE")" ]; then
   rc_f="MS_Reserved_Partition"
  fi
  echo "$rc_f"
} # end of check_if_MSR_part

# Some notes:
# First priority is to use blkid to get filesystem, 2 reasons:
# (1) Since parted seems to have problem with ntfs in some case:
# LC_ALL=C parted -s /dev/hdb p
# Model: VMware Virtual IDE Hard Drive (ide)
# Disk /dev/hdb: 8590MB
# Sector size (logical/physical): 512B/512B
# Partition Table: msdos
# 
# Number  Start   End     Size    Type     File system  Flags
#  1      32.3kB  8579MB  8579MB  primary  ntfs         boot
# 
# [root@drblrhvmnet101 ~]# LC_ALL=C parted -s /dev/hdb1 p
# Error: Can't have a partition outside the disk!
#
# (2) Moreover, the method in get_from_parted does NOT work for LV in LVM... blkid can solve the problem. The weakness is blkid does not provide size info, but it's not so used very often in clonezilla, and normally size is not important when cloning.

#
##############
#### MAIN ####
##############
#
while [ $# -gt 0 ]; do
  case "$1" in
    -u|--unit)
            shift
            if [ -z "$(echo $1 |grep ^-.)" ]; then
              # skip the -xx option, in case 
	      unit="$1"
              shift
            fi
            [ -z "$unit" ] && USAGE >&2 && exit 1
	    ;;
    -*)     echo "${0}: ${1}: invalid option" >&2
            USAGE >& 2
            exit 2 ;;
    *)      break ;;
  esac
done
# part is like /dev/hda1
# request is one of start, end, size, type, filesystem or flags.
part="$1"
shift
request="$*"

[ -z "$part" -o -z "$request" ] && exit 1

#
for wanted in $request; do
  case "$wanted" in
    filesystem|fs)
       # We use partclone.fstype to tell vmfs3 and vmfs5 first, otherwise blkid will show them as VMFS_volume_member, which we can not tell it's vmfs3 or vmfs5.
       fs="$(get_fs_from_partclone_fstype $part)"
       if [ -z "$fs" ]; then
         fs="$(get_fs_from_blkid $part)"
       fi
       if [ -z "$fs" ]; then
	 fs="$(check_if_bitlocker_fs $part)"
       fi
       if [ -z "$fs" ]; then
	 fs="$(check_if_MSR_part $part)"
       fi
       if [ -z "$fs" ]; then
         get_from_parted
       else
         echo "$fs"
       fi
       ;;
    size)
       psize="$(get_size_from_lsblk $part)"
       if [ -z "$psize" ]; then
         get_from_parted
       else
         echo "$psize"
       fi
       ;;
    type)
       ptype="$(get_type_from_lsblk $part)"
       if [ -z "$ptype" ]; then
         get_from_parted
       else
         echo "$ptype"
       fi
       ;;
    *)
       get_from_parted
       ;;
  esac
done