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
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
use std::{default::Default, path::PathBuf};
use strum_macros::{AsRefStr, Display, EnumString};

use std::collections::HashMap;

macro_rules! impl_zfs_prop {
    ($type_:ty, $as_str:literal) => {
        impl ZfsProp for $type_ {
            fn nv_key() -> &'static str { $as_str }

            fn as_nv_value(&self) -> u64 { *self as u64 }
        }
    };
}
pub trait ZfsProp {
    /// String representation of ZFS Property
    fn nv_key() -> &'static str;
    fn as_nv_value(&self) -> u64;
}
/// Controls how ACL entries inherited when files and directories created. Default value is
/// `Restricted`.
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum AclInheritMode {
    /// For new objects, no ACL entries inherited when a file or directory created. The ACL on the
    /// new file or directory is equal to the permissions of the file or directory.
    #[strum(serialize = "discard")]
    Discard      = 0,

    /// For new objects, only inheritable ACL entries that have an access type of `deny` are
    /// inherited.
    #[strum(serialize = "noallow")]
    Noallow      = 1,

    /// For new objects, the `write_owner` and `write_acl` permissions removed when an ACL entry
    /// inherited.
    #[strum(serialize = "restricted")]
    Restricted   = 4,

    /// (Deprecated, might not work on all platforms) For new objects, the `write_owner` and
    /// `write_acl` permissions removed when an ACL entry inherited.
    #[strum(serialize = "secure")]
    Secure       = 2,

    /// When the property value set to passthrough, files created with permissions determined by
    /// the inheritable ACEs. If no inheritable ACEs exist that affect the permissions, then the
    /// permissions set in accordance to the requested permissions from the application.
    #[strum(serialize = "passthrough")]
    Passthrough  = 3,

    #[strum(serialize = "passthrough-x")]
    PassthroughX = 5,
}

impl Default for AclInheritMode {
    fn default() -> AclInheritMode { AclInheritMode::Restricted }
}

/// This property modifies ACL behavior when a file initially created or whenever a file or
/// directory's permissions modified by the chmod command.
///
/// NODE: Not available on ZOL
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum AclMode {
    /// All ACL entries removed except for the entries needed to define the mode of the file or
    /// directory.
    #[strum(serialize = "discard")]
    Discard     = 0,
    /// User or group ACL permissions reduced so that they are no greater than the group
    /// permissions, unless it is a user entry that has the same UID as the owner of the file or
    /// directory. Then, the ACL permissions reduced so that they are no greater than the owner
    /// permissions.
    #[strum(serialize = "groupmask")]
    GroupMask   = 2,

    /// During a `chmod` operation, ACEs other than `owner@`, `group@`, or `everyone@` are not
    /// modified in any way. ACEs with `owner@`, `group@`, or `everyone@` are disabled to set the
    /// file mode as requested by the `chmod` operation.
    #[strum(serialize = "passthrough")]
    Passthrough = 3,

    #[strum(serialize = "restricted")]
    Restricted  = 4,
}

impl Default for AclMode {
    fn default() -> AclMode { AclMode::Discard }
}

/// Controls the checksum used to verify data integrity. Default value is `on`.
///
/// NOTE: Some variants might not be supported by underlying zfs module. Consult proper manual pages
/// before using anything other than `on`.
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum Checksum {
    /// Use value from the parent
    #[strum(serialize = "inherit")]
    Inherit   = 0,
    /// Auto-select most appropriate algorithm. Currently, it is `fletcher4`.
    #[strum(serialize = "on")]
    On        = 1,
    /// Disable integrity check. Not recommended at all.
    #[strum(serialize = "off")]
    Off       = 2,
    /// Not only disables integrity but also disables maintaining parity for user data. This
    /// setting used internally by a dump device residing on a RAID-Z pool and should not be used
    /// by any other dataset.
    #[strum(serialize = "noparity")]
    NoParity  = 10,
    #[strum(serialize = "fletcher2")]
    Fletcher2 = 6,
    #[strum(serialize = "fletcher4")]
    Fletcher4 = 7,
    #[strum(serialize = "sha256")]
    SHA256    = 8,
    #[strum(serialize = "sha512")]
    SHA512    = 11,
    #[strum(serialize = "skein")]
    Skein     = 12,
}

impl Default for Checksum {
    fn default() -> Self { Checksum::On }
}

/// Enables or disables compression for a dataset.
///
/// NOTE: Some variants might not be supported by underlying zfs module. Consult proper manual pages
/// before using anything other than `off`.
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum Compression {
    /// Use value from the parent
    #[strum(serialize = "inherit")]
    Inherit = 0,
    /// Auto-select most appropriate algorithm. If possible uses LZ4, if not then LZJB.
    #[strum(serialize = "on")]
    On      = 1,
    /// Disables compression.
    #[strum(serialize = "off")]
    Off     = 2,
    #[strum(serialize = "lzjb")]
    LZJB    = 3,
    /// The lz4 compression algorithm is a high-performance replacement for the lzjb algorithm.
    #[strum(serialize = "lz4")]
    LZ4     = 15,
    /// The zle compression algorithm compresses runs of zeros.
    #[strum(serialize = "lze")]
    LZE     = 14,
    /// Fastest gzip level
    #[strum(serialize = "gzip-1")]
    Gzip1   = 5,
    #[strum(serialize = "gzip-2")]
    Gzip2   = 6,
    #[strum(serialize = "gzip-3")]
    Gzip3   = 7,
    #[strum(serialize = "gzip-4")]
    Gzip4   = 8,
    #[strum(serialize = "gzip-5")]
    Gzip5   = 9,
    #[strum(serialize = "gzip-6")]
    Gzip6   = 10,
    #[strum(serialize = "gzip-7")]
    Gzip7   = 11,
    #[strum(serialize = "gzip-8")]
    Gzip8   = 12,
    /// Slowest gzip level
    #[strum(serialize = "gzip-9")]
    Gzip9   = 13,
}

impl Default for Compression {
    fn default() -> Self { Compression::Off }
}
/// Sets the number of copies of user data per file system. These copies are in addition to any
/// pool-level redundancy.
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum Copies {
    #[strum(serialize = "1")]
    One = 1,
    #[strum(serialize = "2")]
    Two,
    #[strum(serialize = "3")]
    Three,
}

impl Default for Copies {
    fn default() -> Self { Copies::One }
}

/// What is cached in the primary cache (ARC).
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum CacheMode {
    /// Both user data and metadata.
    #[strum(serialize = "all")]
    All      = 2,
    /// Just the metadata.
    #[strum(serialize = "metadata")]
    Metadata = 1,
    /// Neither user data nor metadata is cached.
    #[strum(serialize = "none")]
    None     = 0,
}

impl ZfsProp for CacheMode {
    #[allow(clippy::unimplemented)]
    fn nv_key() -> &'static str { unimplemented!() }

    #[allow(clippy::as_conversion)]
    fn as_nv_value(&self) -> u64 { *self as u64 }
}

impl Default for CacheMode {
    fn default() -> Self { CacheMode::All }
}

/// Controls whether the .zfs directory is hidden or visible in the root of the file system
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum SnapDir {
    #[strum(serialize = "hidden")]
    Hidden  = 0,
    #[strum(serialize = "visible")]
    Visible = 1,
}

impl Default for SnapDir {
    fn default() -> Self { SnapDir::Hidden }
}

#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum CanMount {
    /// Allowed to be mounted
    #[strum(serialize = "on")]
    On     = 1,
    /// Can't be mounted
    #[strum(serialize = "off")]
    Off    = 0,
    /// Can be mounted, but only explicitly
    #[strum(serialize = "noauto")]
    NoAuto = 2,
}

impl Default for CanMount {
    fn default() -> Self { CanMount::On }
}

/// Controls the behavior of synchronous requests.
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum SyncMode {
    /// Posix specified behavior.
    #[strum(serialize = "standard")]
    Standard = 0,
    /// All transactions are written and flushed. Large performance penalty.
    #[strum(serialize = "always")]
    Always   = 1,
    /// DANGER. Disables synchronous requests.
    #[strum(serialize = "disabled")]
    Disabled = 2,
}

impl Default for SyncMode {
    fn default() -> Self { SyncMode::Standard }
}

/// This property specifies how volumes should be exposed to the OS.
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum VolumeMode {
    /// Controlled by system-wide sysctl/tunable.
    #[strum(serialize = "default")]
    Default = 0,
    /// Volumes with this property are exposed as [`geom(4)`](https://www.freebsd.org/cgi/man.cgi?geom(4)) device.
    #[strum(serialize = "geom")]
    GEOM    = 1,
    /// Volumes with this property are exposed as cdev in devfs.
    #[strum(serialize = "dev")]
    Dev     = 2,
    /// Volumes with this property are not exposed outside of zfs.
    #[strum(serialize = "none")]
    None    = 3,
}

impl Default for VolumeMode {
    fn default() -> Self { VolumeMode::Default }
}

/// Indicates whether the file name matching algorithm used by the file system should be
/// case-sensitive, case-insensitive, or allow a combination of both styles of matching.
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum CaseSensitivity {
    #[strum(serialize = "sensitive")]
    Sensitive,
    #[strum(serialize = "insensitive")]
    Insensitive,
    /// File system can support requests for both case-sensitive and case-insensitive matching
    /// behavior.
    #[strum(serialize = "mixed")]
    Mixed,
}

impl Default for CaseSensitivity {
    fn default() -> Self { CaseSensitivity::Sensitive }
}

/// Configures deduplication for a dataset. If set to verify, ZFS will do a byte-to-byte comparision
/// in case of two blocks having the same signature to make sure the block contents are identical.
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum Dedup {
    #[strum(serialize = "on")]
    On,
    #[strum(serialize = "off")]
    Off,
    #[strum(serialize = "verify")]
    Verify,
    #[strum(serialize = "sha256")]
    SHA256,
    #[strum(serialize = "sha256,verify")]
    VerifySHA256,
    #[strum(serialize = "sha512")]
    SHA512,
    #[strum(serialize = "sha512,verify")]
    VerifySHA512,
    #[strum(serialize = "skein")]
    Skein,
    #[strum(serialize = "skein,verify")]
    VerifySkein,
}

impl Default for Dedup {
    fn default() -> Self { Dedup::Off }
}
///  Indicates whether the file system should perform a unicode normalization of file names whenever
/// two filenames are compared, and which normalization algorithm should be used.
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum Normalization {
    #[strum(serialize = "none")]
    None,
    #[strum(serialize = "formc")]
    FormC,
    #[strum(serialize = "formd")]
    FormD,
    #[strum(serialize = "formkc")]
    FormKC,
    #[strum(serialize = "formkd")]
    FormKD,
}

impl Default for Normalization {
    fn default() -> Self { Normalization::None }
}

/// Provide a hint to ZFS about handling of synchronous requests in this dataset.
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum LogBias {
    /// ZFS will use pool log devices (if configured) to handle the requests at low latency.
    #[strum(serialize = "latency")]
    Latency,
    /// ZFS will not use configured pool log devices.  ZFS will instead optimize synchronous
    /// operations for global pool throughput and efficient use of resources.
    #[strum(serialize = "throughput")]
    Throughput,
}

impl Default for LogBias {
    fn default() -> Self { LogBias::Latency }
}

/// Controls what types of metadata are stored redundantly
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum RedundantMetadata {
    /// ZFS stores an extra copy of all metadata. If a single on-disk block is corrupt, at worst a
    /// single block of user data (which is recordsize bytes long can be lost.)
    #[strum(serialize = "all")]
    All,
    /// ZFS stores an extra copy of most types of metadata. This can improve performance of random
    /// writes, because less metadata must be written.  In practice, at worst about 100 blocks (of
    /// recordsize bytes each) of user data can be lost if a single on-disk block is corrupt.
    #[strum(serialize = "most")]
    Most,
}

impl Default for RedundantMetadata {
    fn default() -> Self { RedundantMetadata::All }
}

/// Specifies a compatibility mode or literal value for the size of dnodes in the file system.
#[derive(AsRefStr, EnumString, Display, Eq, PartialEq, Debug, Clone, Copy)]
#[repr(u64)]
pub enum DnodeSize {
    #[strum(serialize = "legacy")]
    Legacy,
    #[strum(serialize = "auto")]
    Auto,
    #[strum(serialize = "1k")]
    _1K,
    #[strum(serialize = "2k")]
    _2K,
    #[strum(serialize = "4k")]
    _4K,
    #[strum(serialize = "8k")]
    _8K,
    #[strum(serialize = "16k")]
    _16K,
}

impl Default for DnodeSize {
    fn default() -> Self { DnodeSize::Legacy }
}
/// Most of native properties of filesystem dataset - both immutable and mutable. Default values
/// taken from FreeBSD 12.
///
/// Notable missing properties:
///  - shareiscsi
///  - sharenfs
///  - sharesmb
///  - version
///  - zoned
#[derive(Debug, Clone, PartialEq, Getters, Builder)]
#[builder(derive(Debug))]
#[get = "pub"]
pub struct FilesystemProperties {
    name:                    PathBuf,
    /// Controls how ACL entries inherited when files and directories created.
    acl_inherit:             AclInheritMode,
    /// Controls how an ACL entry modified during a `chmod` operation.
    #[builder(default)]
    acl_mode:                Option<AclMode>,
    /// Controls whether the access time for files updated when they are read.
    atime:                   bool,
    /// Read-only property that identifies the amount of disk space available to a dataset and all
    /// its children, assuming no other activity in the pool. Because disk space shared within a
    /// pool, available space can be limited by various factors including physical pool size,
    /// quotas, reservations, and other datasets within the pool.
    available:               i64,
    /// Controls whether a file system can be mounted.
    can_mount:               CanMount,
    /// Indicates whether the file name matching algorithm used by the file system should be
    /// case-sensitive, case-insensitive, or allow a combination of both styles of matching.
    case_sensitivity:        CaseSensitivity,
    /// [Security label](https://docs.oracle.com/cd/E23824_01/html/821-1482/managezones-18.html)
    /// Controls the checksum used to verify data integrity.
    checksum:                Checksum,
    /// Enables or disables compression for a dataset.
    compression:             Compression,
    /// Read-only property that identifies the compression ratio achieved for a dataset, expressed
    /// as a multiplier.
    compression_ratio:       f64,
    /// Sets the number of copies of user data per file system. Available values are 1, 2, or 3.
    /// These copies are in addition to any pool-level redundancy. Disk space used by multiple
    /// copies of user data charged to the corresponding file and dataset, and counts against
    /// quotas and reservations. In addition, the used property updated when multiple copies
    /// enabled. Consider setting this property when the file system created because changing this
    /// property on an existing file system only affects newly written data.
    copies:                  Copies,
    /// The birth time transaction group (TXG) of the object.
    #[builder(default)]
    create_txg:              Option<u64>,
    /// Read-only property that identifies the date and time a dataset created.
    creation:                i64,
    /// Configures deduplication for a dataset.
    #[builder(default)]
    dedup:                   Dedup,
    /// Controls whether device files in a file system can be opened.
    devices:                 bool,
    /// Specifies a compatibility mode or literal value for the size of dnodes in the file system.
    #[builder(default)]
    dnode_size:              DnodeSize,
    /// Controls whether programs in a file system allowed to be executed. Also, when set to
    /// `false`, `mmap(2)` calls with `PROT_EXEC` disallowed.
    exec:                    bool,
    /// The total number of filesystems that exist under this location in the dataset tree.  This
    /// value is only available when a filesystem_limit has been set somewhere in the tree under
    /// which the dataset resides.
    filesystem_count:        u64,
    /// Limits the number of filesystems that can be created on a dataset and its descendents.
    filesystem_limit:        u64,
    /// GUID of the dataset
    #[builder(default)]
    guid:                    Option<u64>,
    /// Read-only property that indicates whether a file system, clone, or snapshot is currently
    /// mounted.
    mounted:                 bool,
    /// Controls the mount point used for this file system.
    mount_point:             Option<PathBuf>,
    /// [Cross-protocol locking](https://docs.oracle.com/cd/E19120-01/open.solaris/820-2429/configurecrossprotocollockingtask/index.html)
    #[builder(default)]
    nbmand:                  bool,
    ///  Indicates whether the file system should perform a unicode normalization of file names
    /// whenever two filenames are compared, and which normalization algorithm should be used.
    #[builder(default)]
    normalization:           Normalization,
    /// Controls what is cached in the primary cache (ARC).
    primary_cache:           CacheMode,
    // Read-only property for cloned file systems or volumes that identifies the snapshot from
    // which the clone was created.
    #[builder(default)]
    origin:                  Option<String>,
    /// Limits the amount of disk space a dataset and its descendants can consume.
    quota:                   u64,
    /// Controls whether a dataset can be modified.
    readonly:                bool,
    /// Specifies a suggested block size for files in a file system in bytes. The size specified
    /// must be a power of two greater than or equal to 512 and less than or equal to 128 KiB.
    /// If the large_blocks feature is enabled on the pool, the size may be up to 1 MiB.
    record_size:             u64,
    /// Controls what types of metadata are stored redundantly
    redundant_metadata:      RedundantMetadata,
    /// Compression ratio achieved for the referenced space of this snapshot.
    ref_compression_ratio:   f64,
    /// Read-only property that identifies the amount of data accessible by a dataset, which might
    /// or might not be shared with other datasets in the pool.
    referenced:              u64,
    /// Sets the amount of disk space a dataset can consume. This property enforces a hard limit on
    /// the amount of space used. This hard limit does not include disk space used by descendents,
    /// such as snapshots and clones.
    ref_quota:               u64,
    /// Sets the minimum amount of disk space is guaranteed to a dataset, not including
    /// descendants, such as snapshots and clones.
    ref_reservation:         u64,
    /// Sets the minimum amount of disk space guaranteed to a dataset and its descendants.
    reservation:             u64,
    /// Controls what is cached in the secondary cache (L2ARC).
    secondary_cache:         CacheMode,
    /// Controls whether the `setuid` bit is honored in a file system.
    setuid:                  bool,
    /// Controls whether the .zfs directory is hidden or visible in the root of the file system
    snap_dir:                SnapDir,
    /// The total number of snapshots that exist under this location in the dataset tree.  This
    /// value is only available when a snapshot_limit has been set somewhere in the tree under
    /// which the dataset resides.
    snapshot_count:          u64,
    /// Limits the number of snapshots that can be created on a dataset and its descendents.
    snapshot_limit:          u64,
    /// Controls the behavior of synchronous requests.
    sync:                    SyncMode,
    /// Read-only property that identifies the amount of disk space consumed by a dataset and all
    /// its descendants.
    used:                    u64,
    /// Read-only property that identifies the amount of disk space is used by children of this
    /// dataset, which would be freed if all the dataset's children were destroyed.
    used_by_children:        u64,
    /// Read-only property that identifies the amount of disk space is used by a dataset itself.
    used_by_dataset:         u64,
    /// Read-only property that identifies the amount of disk space is used by a refreservation set
    /// on a dataset.
    used_by_ref_reservation: u64,
    /// Read-only property that identifies the amount of disk space is consumed by snapshots of a
    /// dataset.
    used_by_snapshots:       u64,
    /// Indicates whether extended attributes are enabled or disabled.
    xattr:                   bool,
    /// Controls whether the dataset is managed from a jail.
    #[builder(default)]
    jailed:                  Option<bool>,
    /// Provide a hint to ZFS about handling of synchronous requests in this dataset.
    log_bias:                LogBias,
    /// The amount of space is "logically" accessible by this dataset.
    logical_referenced:      u64,
    ///  The amount of space is "logically" consumed by this dataset and all its descendents.
    logical_used:            u64,
    /// [Security label](https://docs.oracle.com/cd/E23824_01/html/821-1482/managezones-18.html)
    #[builder(default)]
    mls_label:               Option<String>,
    /// Indicates whether the file system should reject file names that include characters that are
    /// not present in the UTF-8 character code set. If this property is explicitly set to off, the
    /// normalization property must either not be explicitly set or be set to none.
    #[builder(default)]
    utf8_only:               Option<bool>,
    /// Version (should 5)
    version:                 u64,
    /// Written?
    written:                 u64,
    /// Controls how the volume is exposed to the OS
    volume_mode:             Option<VolumeMode>,
    /// Virus scan - not used outside solaris
    #[builder(default)]
    vscan:                   bool,
    /// User defined properties and properties this library failed to recognize.
    unknown_properties:      HashMap<String, String>,
}

impl FilesystemProperties {
    pub fn builder(name: PathBuf) -> FilesystemPropertiesBuilder {
        let mut ret = FilesystemPropertiesBuilder::default();
        ret.name(name);
        ret.unknown_properties(HashMap::new());
        ret
    }
}

impl FilesystemPropertiesBuilder {
    pub fn insert_unknown_property(&mut self, key: String, value: String) {
        if let Some(ref mut props) = self.unknown_properties {
            props.insert(key, value);
        } else {
            self.unknown_properties(HashMap::new());
            self.insert_unknown_property(key, value);
        }
    }
}

/// Most of native properties of volume dataset - both immutable and mutable. Default values taken
/// from FreeBSD 12.
///
/// Notable missing properties:
///  - shareiscsi
///  - sharenfs
///  - sharesmb
///  - version
///  - zoned
#[derive(Debug, Clone, PartialEq, Getters, Builder)]
#[get = "pub"]
pub struct VolumeProperties {
    name:                    PathBuf,
    /// Read-only property that identifies the amount of disk space available to a dataset and all
    /// its children, assuming no other activity in the pool. Because disk space shared within a
    /// pool, available space can be limited by various factors including physical pool size,
    /// quotas, reservations, and other datasets within the pool.
    available:               i64,
    /// Controls the checksum used to verify data integrity.
    checksum:                Checksum,
    /// Enables or disables compression for a dataset.
    compression:             Compression,
    /// Read-only property that identifies the compression ratio achieved for a dataset, expressed
    /// as a multiplier.
    compression_ratio:       f64,
    /// Sets the number of copies of user data per file system. Available values are 1, 2, or 3.
    /// These copies are in addition to any pool-level redundancy. Disk space used by multiple
    /// copies of user data charged to the corresponding file and dataset, and counts against
    /// quotas and reservations. In addition, the used property updated when multiple copies
    /// enabled. Consider setting this property when the file system created because changing this
    /// property on an existing file system only affects newly written data.
    copies:                  Copies,
    /// The birth time transaction group (TXG) of the object.
    #[builder(default)]
    create_txg:              Option<u64>,
    /// Read-only property that identifies the date and time a dataset created.
    creation:                i64,
    /// Configures deduplication for a dataset.
    #[builder(default)]
    dedup:                   Dedup,
    /// GUID of the dataset
    #[builder(default)]
    guid:                    Option<u64>,
    /// Provide a hint to ZFS about handling of synchronous requests in this dataset.
    log_bias:                LogBias,
    /// The amount of space is "logically" accessible by this dataset.
    logical_referenced:      u64,
    ///  The amount of space is "logically" consumed by this dataset and all its descendents.
    logical_used:            u64,
    /// [Security label](https://docs.oracle.com/cd/E23824_01/html/821-1482/managezones-18.html)
    #[builder(default)]
    mls_label:               Option<String>,
    /// Read-only property that indicates whether a file system, clone, or snapshot is currently
    /// Controls what is cached in the primary cache (ARC).
    primary_cache:           CacheMode,
    /// Controls whether a dataset can be modified.
    readonly:                bool,
    /// Controls what types of metadata are stored redundantly
    redundant_metadata:      RedundantMetadata,
    /// Compression ratio achieved for the referenced space of this snapshot.
    ref_compression_ratio:   f64,
    /// Read-only property that identifies the amount of data accessible by a dataset, which might
    /// or might not be shared with other datasets in the pool.
    referenced:              u64,
    /// Sets the minimum amount of disk space is guaranteed to a dataset, not including
    /// descendants, such as snapshots and clones.
    ref_reservation:         u64,
    /// Sets the minimum amount of disk space guaranteed to a dataset and its descendants.
    reservation:             u64,
    /// Controls what is cached in the secondary cache (L2ARC).
    secondary_cache:         CacheMode,
    /// The total number of snapshots that exist under this location in the dataset tree.  This
    /// value is only available when a snapshot_limit has been set somewhere in the tree under
    /// which the dataset resides.
    snapshot_count:          u64,
    /// Limits the number of snapshots that can be created on a dataset and its descendents.
    snapshot_limit:          u64,
    /// Controls the behavior of synchronous requests.
    sync:                    SyncMode,
    /// Read-only property that identifies the amount of disk space consumed by a dataset and all
    /// its descendants.
    used:                    u64,
    /// Read-only property that identifies the amount of disk space is used by children of this
    /// dataset, which would be freed if all the dataset's children were destroyed.
    used_by_children:        u64,
    /// Read-only property that identifies the amount of disk space is used by a dataset itself.
    used_by_dataset:         u64,
    /// Read-only property that identifies the amount of disk space is used by a refreservation set
    /// on a dataset.
    used_by_ref_reservation: u64,
    /// Read-only property that identifies the amount of disk space is consumed by snapshots of a
    /// dataset.
    used_by_snapshots:       u64,
    /// For volumes, specifies the block size of the volume in bytes. The block size cannot be
    /// changed after the volume has been written, so set the block size at volume creation time.
    /// The default block size for volumes is 8 KB. Any power of 2 from 512 bytes to 128 KB is
    /// valid.
    volume_block_size:       u64,
    /// Controls how the volume is exposed to the OS
    volume_mode:             Option<VolumeMode>,
    /// For volumes, specifies the logical size of the volume.
    volume_size:             u64,
    /// Written?
    written:                 u64,
    /// User defined properties and properties this library failed to recognize.
    unknown_properties:      HashMap<String, String>,
}

impl VolumeProperties {
    pub fn builder(name: PathBuf) -> VolumePropertiesBuilder {
        let mut ret = VolumePropertiesBuilder::default();
        ret.name(name);
        ret.unknown_properties(HashMap::new());
        ret
    }
}

impl VolumePropertiesBuilder {
    pub fn insert_unknown_property(&mut self, key: String, value: String) {
        if let Some(ref mut props) = self.unknown_properties {
            props.insert(key, value);
        } else {
            self.unknown_properties(HashMap::new());
            self.insert_unknown_property(key, value);
        }
    }
}

#[derive(Debug, Clone, PartialEq, Getters, Builder)]
#[builder(derive(Debug))]
#[get = "pub"]
pub struct SnapshotProperties {
    name:                  PathBuf,
    /// The birth time transaction group (TXG) of the object.
    #[builder(default)]
    create_txg:            Option<u64>,
    /// Read-only property that identifies the date and time a dataset created.
    creation:              i64,
    /// Read-only property that identifies the amount of disk space consumed by a dataset and all
    /// its descendants.
    used:                  u64,
    /// Read-only property that identifies the amount of data accessible by a dataset, which might
    /// or might not be shared with other datasets in the pool.
    referenced:            u64,
    /// Read-only property that identifies the compression ratio achieved for a dataset, expressed
    /// as a multiplier.
    compression_ratio:     f64,
    /// Controls whether device files in a file system can be opened.
    devices:               bool,
    /// Controls whether programs in a file system allowed to be executed. Also, when set to
    /// `false`, `mmap(2)` calls with `PROT_EXEC` disallowed.
    exec:                  bool,
    /// Controls whether the `setuid` bit is honored in a file system.
    setuid:                bool,
    /// Indicates whether extended attributes are enabled or disabled.
    xattr:                 bool,
    /// Version (should 5)
    version:               u64,
    /// Indicates whether the file system should reject file names that include characters that are
    /// not present in the UTF-8 character code set. If this property is explicitly set to off, the
    /// normalization property must either not be explicitly set or be set to none.
    #[builder(default)]
    utf8_only:             Option<bool>,
    /// GUID of the dataset
    #[builder(default)]
    guid:                  Option<u64>,
    /// Controls what is cached in the primary cache (ARC).
    primary_cache:         CacheMode,
    /// Controls what is cached in the secondary cache (L2ARC).
    secondary_cache:       CacheMode,
    /// Snapshot marked for deferred destroy.
    defer_destroy:         bool,
    /// Number of holds on this snapshot.
    user_refs:             u64,
    /// Compression ratio achieved for the referenced space of this snapshot.
    ref_compression_ratio: f64,
    /// The amount of referenced space written to this dataset since the previous snapshot.
    written:               u64,
    /// List of datasets which are clones of this snapshot.
    #[builder(default)]
    clones:                Option<Vec<PathBuf>>,
    /// The amount of space that is "logically" accessible by this dataset.
    logically_referenced:  u64,
    /// Controls how the volume is exposed to the OS
    #[builder(default)]
    volume_mode:           Option<VolumeMode>,
    /// Indicates whether the file name matching algorithm used by the file system should be
    /// case-sensitive, case-insensitive, or allow a combination of both styles of matching.
    case_sensitivity:      CaseSensitivity,
    /// [Security label](https://docs.oracle.com/cd/E23824_01/html/821-1482/managezones-18.html)
    #[builder(default)]
    mls_label:             Option<String>,
    /// [Cross-protocol locking](https://docs.oracle.com/cd/E19120-01/open.solaris/820-2429/configurecrossprotocollockingtask/index.html)
    #[builder(default)]
    nbmand:                bool,
    ///  Indicates whether the file system should perform a unicode normalization of file names
    /// whenever two filenames are compared, and which normalization algorithm should be used.
    #[builder(default)]
    normalization:         Normalization,
    /// User defined properties and properties this library failed to recognize.
    unknown_properties:    HashMap<String, String>,
}

impl SnapshotProperties {
    pub fn builder(name: PathBuf) -> SnapshotPropertiesBuilder {
        let mut ret = SnapshotPropertiesBuilder::default();
        ret.unknown_properties(HashMap::new());
        ret.name(name);
        ret
    }
}

impl SnapshotPropertiesBuilder {
    pub fn insert_unknown_property(&mut self, key: String, value: String) {
        if let Some(ref mut props) = self.unknown_properties {
            props.insert(key, value);
        } else {
            self.unknown_properties(HashMap::new());
            self.insert_unknown_property(key, value);
        }
    }
}

#[derive(Debug, Clone, PartialEq, Getters, Builder)]
#[builder(derive(Debug))]
#[get = "pub"]
pub struct BookmarkProperties {
    name:               PathBuf,
    /// The birth time transaction group (TXG) of the object.
    #[builder(default)]
    create_txg:         Option<u64>,
    /// Read-only property that identifies the date and time a dataset created.
    creation:           i64,
    /// GUID of the database
    #[builder(default)]
    guid:               Option<u64>,
    /// User defined properties and properties this library failed to recognize.
    unknown_properties: HashMap<String, String>,
}
impl BookmarkProperties {
    pub fn builder(name: PathBuf) -> BookmarkPropertiesBuilder {
        let mut ret = BookmarkPropertiesBuilder::default();
        ret.unknown_properties(HashMap::new());
        ret.name(name);
        ret
    }
}

impl BookmarkPropertiesBuilder {
    pub fn insert_unknown_property(&mut self, key: String, value: String) {
        if let Some(ref mut props) = self.unknown_properties {
            props.insert(key, value);
        } else {
            self.unknown_properties(HashMap::new());
            self.insert_unknown_property(key, value);
        }
    }
}

#[derive(Debug, Clone, PartialEq)]
pub enum Properties {
    Filesystem(FilesystemProperties),
    Volume(VolumeProperties),
    Snapshot(SnapshotProperties),
    Bookmark(BookmarkProperties),
    Unknown(HashMap<String, String>),
}

impl_zfs_prop!(AclInheritMode, "aclinherit");
impl_zfs_prop!(AclMode, "aclmode");
impl_zfs_prop!(CanMount, "canmount");
impl_zfs_prop!(Checksum, "checksum");
impl_zfs_prop!(Compression, "compression");
impl_zfs_prop!(Copies, "copies");
impl_zfs_prop!(SnapDir, "snapdir");
impl_zfs_prop!(VolumeMode, "volmod");