1 ------------------------------------------------------------------------------ 2 ------------------------------------------------------------------------------ 3 -- This file is part of 'Cryostat', an Ada library for persistent storage. -- 4 -- -- 5 -- (C) 2020 Stanislav Datskovskiy ( www.loper-os.org ) -- 6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html -- 7 -- -- 8 -- You do not have, nor can you ever acquire the right to use, copy or -- 9 -- distribute this software ; Should you use this software for any purpose, -- 10 -- or copy and distribute it to anyone or in any manner, you are breaking -- 11 -- the laws of whatever soi-disant jurisdiction, and you promise to -- 12 -- continue doing so for the indefinite future. In any case, please -- 13 -- always : read and understand any software ; verify any PGP signatures -- 14 -- that you use - for any purpose. -- 15 ------------------------------------------------------------------------------ 16 ------------------------------------------------------------------------------ 17 18 with System; 19 with Unix; use Unix; 20 with PMaps; use PMaps; 21 22 23 generic 24 25 -- The type of the item that will live in the Cryostat : 26 type Form is limited private; 27 28 -- The path of the backing file : 29 Path : in String; 30 31 -- Whether the contents of the Cryostat will be writable : 32 Writable : in Boolean; 33 34 -- Whether the backing file is to be created if it does not already exist : 35 Create : in Boolean; 36 37 package Cryostat is 38 39 pragma Preelaborate; 40 41 -- The concrete datum of type Form that will live in the Cryostat : 42 Item : Form; 43 44 -- Test if the Cryostat is usable 45 function IsReady return Boolean; 46 47 -- If the Cryostat is writable, sync it to disk immediately 48 procedure Sync; 49 50 -- Zero the entire mapped space of the Cryostat 51 procedure Zap; 52 53 -- Close the Cryostat and mark it unusable. 54 -- Normally, this is unnecessary (Finalize will do it) 55 procedure Stop; 56 57 private 58 59 -- The actual number of bytes occupied by an instance of the Form type : 60 Footprint : constant Word := Form'Size / System.Storage_Unit; 61 62 -- Instantiate a memory map using the given params : 63 Map : PMap(Handle => OpenMapFile(Path => Path, 64 Writable => Writable, 65 Create => Create), 66 Length => Footprint, 67 Offset => 0, -- Offsetted maps not supported yet! 68 Create => Create, 69 Writable => Writable); 70 71 -- Force Item to reside at the obtained address : 72 for Item'Address use GetAddress(Map); 73 74 end Cryostat;