Fdisk:Disk partition management

更新时间:
2024-05-13
下载文档

Fdisk:Disk partition management

This module is used to obtain disk partition and mount information, and can re-partition and mount the specified disk. This module is available in EdgerOS 1.8.9 and later.

User can use the following code to import the fdisk module.

var fdisk = require('fdisk');

Support

The following shows fdisk module APIs available for each permissions.

 User ModePrivilege Mode
fdisk.list 
fdisk.info 
fdisk.partition 
fdisk.umount 
fdisk.remount 

Fdisk Object

fdisk.list()

  • Returns: {Array} Block device array.

Get the current system block device list.

The array members contain the following information:

  • blkdev {String} Block device name.
  • size {Integer} Block device size. The unit is MBytes.

Example

var array = fdisk.list();

for (var b of array) {
  console.log('Block device:', b.blkdev, 'Size:', b.size, 'MBytes');
}

fdisk.info(blkdev)

  • blkdev {String} Block device name.
  • Returns: {Object} Block device partition and mount information.

Get the partition and mount information of the specified block device.

The information contain the following members:

  • type {String} Type of disk partition, 'GPT' or 'MBR'.
  • partition {Array} Array of disk partition information.

Each partition information contains the following members:

  • active {Boolean} Is it an active partition.
  • fstype {String} Partition file system type.
  • size {Integer} Partition size. The unit is MBytes.
  • offset {Integer} Partition relative disk start offset. The unit is MBytes.
  • mount {String} The volume path where the partition is mounted. '' indicates that the mount failed.

The fstype may be the following: 'EMPTY', 'TPSFS', 'FAT', 'NTFS', 'LINUX', 'QNX', 'CDFS', 'EFI' or 'RESERVED'. Where 'TPSFS' is the SylixOS kernel power safe journaled file system type used by EdgerOS.

Example

var array = fdisk.list();

for (var b of array) {
  var info = fdisk.info(b.blkdev);
  console.log('Block device:', b.blkdev, 'Ptype:', info.type, 'info:');

  for (var p of info.partition) {
    console.log('Size:', p.size, 'Fs type:', p.fstype, 'mount:', p.mount);
  }
}

Also use sys.diskInfo to get disk details including manufacturer, serial number, transfer technology etc.

fdisk.partition(blkdev, partition, type)

  • blkdev {String} Block device name.
  • partition {Array} Partition parameter array.
  • type {String} Partition type, 'GPT' or 'MBR'.
  • Returns: {Boolean} Whether the partition is successful.

Format the disk. Default 4KBytes alignment.

Each partition item must contain the following information:

  • active {Boolean} Whether it is an active partition, only one active partition is allowed at most.
  • fstype {String} Partition file system type.
  • name {String} Partition name, Only valid in 'GPT' type partition table.
  • size {Integer} Partition size. The unit is MBytes. 0 indicates that the last partition.

Example

var partition = [
  { active: true,  fstype: 'EFI',   name: 'Boot',    size: 16 },
  { active: false, fstype: 'TPSFS', name: 'Recover', size: 1024 },
  { active: false, fstype: 'TPSFS', name: 'Main',    size: 0 }
];

fdisk.partition('hdd0', partition, 'GPT');

fdisk.umount(blkdev[, force])

  • blkdev {String} Block device name.
  • Returns: {Boolean} Whether the remount is successful.

Unmount all file systems related to the specified blkdev, this operation must be performed before invoke fdisk.partition. If it fails, you can get the error through sys.error, usually, the mounted file system is busy.

fdisk.remount(blkdev)

  • blkdev {String} Block device name.
  • Returns: {Boolean} Whether the remount is successful.

Remount the filesystem, which can be done after the disk partition is complete. After the remount is complete, you can view the partition mount status through fdisk.info.

文档内容是否对您有所帮助?
有帮助
没帮助