pub async fn init_empty(&self, filesystem: Arc<dyn Filesystem>) -> Result<(), Error> {
        // The following constants are only used at format time. When mounting, the recorded values
        // in the superblock should be used.  The root parent store does not have a parent, but
        // needs an object ID to be registered with ObjectManager, so it cannot collide (i.e. have
        // the same object ID) with any objects in the root store that use the journal to track
        // mutations.
        const INIT_ROOT_PARENT_STORE_OBJECT_ID: u64 = 3;
        const INIT_ROOT_STORE_OBJECT_ID: u64 = 4;
        const INIT_ALLOCATOR_OBJECT_ID: u64 = 5;

        log::info!("Formatting fxfs device-size: {})", filesystem.device().size());

        let checkpoint = self.inner.lock().unwrap().writer.journal_file_checkpoint();

        let root_parent =
            ObjectStore::new_empty(None, INIT_ROOT_PARENT_STORE_OBJECT_ID, filesystem.clone());
        self.objects.set_root_parent_store(root_parent.clone());

        let allocator =
            Arc::new(SimpleAllocator::new(filesystem.clone(), INIT_ALLOCATOR_OBJECT_ID));
        self.objects.set_allocator(allocator.clone());

        let journal_handle;
        let super_block_a_handle;
        let super_block_b_handle;
        let root_store;
        let mut transaction = filesystem
            .new_transaction(&[], Options { skip_journal_checks: true, ..Default::default() })
            .await?;
        root_store = root_parent
            .create_child_store_with_id(&mut transaction, INIT_ROOT_STORE_OBJECT_ID)
            .await
            .context("create root store")?;
        self.objects.set_root_store(root_store.clone());

        allocator.create().await?;

        // Create the super-block objects...
        super_block_a_handle = ObjectStore::create_object_with_id(
            &root_store,
            &mut transaction,
            SUPER_BLOCK_A_OBJECT_ID,
            HandleOptions::default(),
            None,
        )
        .await
        .context("create super block")?;
        super_block_a_handle
            .extend(&mut transaction, SuperBlockCopy::A.first_extent())
            .await
            .context("extend super block")?;
        super_block_b_handle = ObjectStore::create_object_with_id(
            &root_store,
            &mut transaction,
            SUPER_BLOCK_B_OBJECT_ID,
            HandleOptions::default(),
            None,
        )
        .await
        .context("create super block")?;
        super_block_b_handle
            .extend(&mut transaction, SuperBlockCopy::B.first_extent())
            .await
            .context("extend super block")?;

        // the journal object...
        journal_handle = ObjectStore::create_object(
            &root_parent,
            &mut transaction,
            journal_handle_options(),
            None,
        )
        .await
        .context("create journal")?;
        journal_handle
            .preallocate_range(&mut transaction, 0..self.chunk_size())
            .await
            .context("preallocate journal")?;

        // the root store's graveyard and root directory...
        let graveyard = Graveyard::create(&mut transaction, &root_store).await?;
        root_store.set_graveyard_directory_object_id(&mut transaction, graveyard.object_id());
        self.objects.register_graveyard(graveyard);

        let root_directory = Directory::create(&mut transaction, &root_store)
            .await
            .context("create root directory")?;
        root_store.set_root_directory_object_id(&mut transaction, root_directory.object_id());

        transaction.commit().await?;

        // Cache the super-block.
        {
            let mut inner = self.inner.lock().unwrap();
            inner.super_block = SuperBlock::new(
                root_parent.store_object_id(),
                root_store.store_object_id(),
                allocator.object_id(),
                journal_handle.object_id(),
                checkpoint,
            );
            inner.super_block_to_write = SuperBlockCopy::A;
        }

        // Initialize the journal writer.
        let _ = self.handle.set(journal_handle);

        self.write_super_block().await
    }
/// Creates an empty filesystem with the minimum viable objects (including a root parent and
/// root store but no further child stores).
Creates an empty filesystem with the minimum viable objects (including a root parent and
root store but no further child stores).
Creates an empty filesystem with the minimum viable objects ( including a root parent and root store but no further child stores ) .
pub async fn init_empty(&self, filesystem: Arc<dyn Filesystem>) -> Result<(), Error> {
        // The following constants are only used at format time. When mounting, the recorded values
        // in the superblock should be used.  The root parent store does not have a parent, but
        // needs an object ID to be registered with ObjectManager, so it cannot collide (i.e. have
        // the same object ID) with any objects in the root store that use the journal to track
        // mutations.
        const INIT_ROOT_PARENT_STORE_OBJECT_ID: u64 = 3;
        const INIT_ROOT_STORE_OBJECT_ID: u64 = 4;
        const INIT_ALLOCATOR_OBJECT_ID: u64 = 5;
        log::info!("Formatting fxfs device-size: {})", filesystem.device().size());
        let checkpoint = self.inner.lock().unwrap().writer.journal_file_checkpoint();
        let root_parent =
            ObjectStore::new_empty(None, INIT_ROOT_PARENT_STORE_OBJECT_ID, filesystem.clone());
        self.objects.set_root_parent_store(root_parent.clone());
        let allocator =
            Arc::new(SimpleAllocator::new(filesystem.clone(), INIT_ALLOCATOR_OBJECT_ID));
        self.objects.set_allocator(allocator.clone());
        let journal_handle;
        let super_block_a_handle;
        let super_block_b_handle;
        let root_store;
        let mut transaction = filesystem
            .new_transaction(&[], Options { skip_journal_checks: true, ..Default::default() })
            .await?;
        root_store = root_parent
            .create_child_store_with_id(&mut transaction, INIT_ROOT_STORE_OBJECT_ID)
            .await
            .context("create root store")?;
        self.objects.set_root_store(root_store.clone());
        allocator.create().await?;
        // Create the super-block objects...
        super_block_a_handle = ObjectStore::create_object_with_id(
            &root_store,
            &mut transaction,
            SUPER_BLOCK_A_OBJECT_ID,
            HandleOptions::default(),
            None,
        )
        .await
        .context("create super block")?;
        super_block_a_handle
            .extend(&mut transaction, SuperBlockCopy::A.first_extent())
            .await
            .context("extend super block")?;
        super_block_b_handle = ObjectStore::create_object_with_id(
            &root_store,
            &mut transaction,
            SUPER_BLOCK_B_OBJECT_ID,
            HandleOptions::default(),
            None,
        )
        .await
        .context("create super block")?;
        super_block_b_handle
            .extend(&mut transaction, SuperBlockCopy::B.first_extent())
            .await
            .context("extend super block")?;
        // the journal object...
        journal_handle = ObjectStore::create_object(
            &root_parent,
            &mut transaction,
            journal_handle_options(),
            None,
        )
        .await
        .context("create journal")?;
        journal_handle
            .preallocate_range(&mut transaction, 0..self.chunk_size())
            .await
            .context("preallocate journal")?;
        // the root store's graveyard and root directory...
        let graveyard = Graveyard::create(&mut transaction, &root_store).await?;
        root_store.set_graveyard_directory_object_id(&mut transaction, graveyard.object_id());
        self.objects.register_graveyard(graveyard);
        let root_directory = Directory::create(&mut transaction, &root_store)
            .await
            .context("create root directory")?;
        root_store.set_root_directory_object_id(&mut transaction, root_directory.object_id());
        transaction.commit().await?;
        // Cache the super-block.
        {
            let mut inner = self.inner.lock().unwrap();
            inner.super_block = SuperBlock::new(
                root_parent.store_object_id(),
                root_store.store_object_id(),
                allocator.object_id(),
                journal_handle.object_id(),
                checkpoint,
            );
            inner.super_block_to_write = SuperBlockCopy::A;
        }
        // Initialize the journal writer.
        let _ = self.handle.set(journal_handle);
        self.write_super_block().await
    }
pub async fn init_empty ( & self , filesystem : Arc < dyn Filesystem > ) -> Result < ( ) , Error > { // The following constants are only used at format time. When mounting, the recorded values // in the superblock should be used.  The root parent store does not have a parent, but // needs an object ID to be registered with ObjectManager, so it cannot collide (i.e. have // the same object ID) with any objects in the root store that use the journal to track // mutations. const INIT_ROOT_PARENT_STORE_OBJECT_ID : u64 = 3 ; const INIT_ROOT_STORE_OBJECT_ID : u64 = 4 ; const INIT_ALLOCATOR_OBJECT_ID : u64 = 5 ; log :: info ! ( " " filesystem device ( ) size ( ) ) ; let checkpoint = self . inner . lock ( ) . unwrap ( ) . writer . journal_file_checkpoint ( ) ; let root_parent = ObjectStore :: new_empty ( None , INIT_ROOT_PARENT_STORE_OBJECT_ID , filesystem . clone ( ) ) ; self . objects . set_root_parent_store ( root_parent . clone ( ) ) ; let allocator = Arc :: new ( SimpleAllocator :: new ( filesystem . clone ( ) , INIT_ALLOCATOR_OBJECT_ID ) ) ; self . objects . set_allocator ( allocator . clone ( ) ) ; let journal_handle ; let super_block_a_handle ; let super_block_b_handle ; let root_store ; let mut transaction = filesystem . new_transaction ( & [ ] , Options { skip_journal_checks : true , .. Default :: default ( ) } ) . await ? ; root_store = root_parent . create_child_store_with_id ( & mut transaction , INIT_ROOT_STORE_OBJECT_ID ) . await . context ( " " ) ? ; self . objects . set_root_store ( root_store . clone ( ) ) ; allocator . create ( ) . await ? ; // Create the super-block objects... super_block_a_handle = ObjectStore :: create_object_with_id ( & root_store , & mut transaction , SUPER_BLOCK_A_OBJECT_ID , HandleOptions :: default ( ) , None , ) . await . context ( " " ) ? ; super_block_a_handle . extend ( & mut transaction , SuperBlockCopy :: A . first_extent ( ) ) . await . context ( " " ) ? ; super_block_b_handle = ObjectStore :: create_object_with_id ( & root_store , & mut transaction , SUPER_BLOCK_B_OBJECT_ID , HandleOptions :: default ( ) , None , ) . await . context ( " " ) ? ; super_block_b_handle . extend ( & mut transaction , SuperBlockCopy :: B . first_extent ( ) ) . await . context ( " " ) ? ; // the journal object... journal_handle = ObjectStore :: create_object ( & root_parent , & mut transaction , journal_handle_options ( ) , None , ) . await . context ( " " ) ? ; journal_handle . preallocate_range ( & mut transaction , 0 .. self . chunk_size ( ) ) . await . context ( " " ) ? ; // the root store's graveyard and root directory... let graveyard = Graveyard :: create ( & mut transaction , & root_store ) . await ? ; root_store . set_graveyard_directory_object_id ( & mut transaction , graveyard . object_id ( ) ) ; self . objects . register_graveyard ( graveyard ) ; let root_directory = Directory :: create ( & mut transaction , & root_store ) . await . context ( " " ) ? ; root_store . set_root_directory_object_id ( & mut transaction , root_directory . object_id ( ) ) ; transaction . commit ( ) . await ? ; // Cache the super-block. { let mut inner = self . inner . lock ( ) . unwrap ( ) ; inner . super_block = SuperBlock :: new ( root_parent . store_object_id ( ) , root_store . store_object_id ( ) , allocator . object_id ( ) , journal_handle . object_id ( ) , checkpoint , ) ; inner . super_block_to_write = SuperBlockCopy :: A ; } // Initialize the journal writer. let _ = self . handle . set ( journal_handle ) ; self . write_super_block ( ) . await }
Creates an empty filesystem with the minimum viable objects (including a root parent and
root store but no further child stores).
Creates an empty filesystem with the minimum viable objects ( including a root parent and root store but no further child stores ) .
&self
filesystem
Arc<dyn Filesystem>
&self
filesystem
Arc<dyn Filesystem>