// SPDX-License-Identifier: GPL-2.0-only /* * linux/fs/adfs/map.c * * Copyright (C) 1997-2002 Russell King */ #include <linux/slab.h> #include <linux/statfs.h> #include <asm/unaligned.h> #include "adfs.h" /* * The ADFS map is basically a set of sectors. Each sector is called a * zone which contains a bitstream made up of variable sized fragments. * Each bit refers to a set of bytes in the filesystem, defined by * log2bpmb. This may be larger or smaller than the sector size, but * the overall size it describes will always be a round number of * sectors. A fragment id is always idlen bits long. * * < idlen > < n > <1> * +---------+-------//---------+---+ * | frag id | 0000....000000 | 1 | * +---------+-------//---------+---+ * * The physical disk space used by a fragment is taken from the start of * the fragment id up to and including the '1' bit - ie, idlen + n + 1 * bits. * * A fragment id can be repeated multiple times in the whole map for * large or fragmented files. The first map zone a fragment starts in * is given by fragment id / ids_per_zone - this allows objects to start * from any zone on the disk. * * Free space is described by a linked list of fragments. Each free * fragment describes free space in the same way as the other fragments, * however, the frag id specifies an offset (in map bits) from the end * of this fragment to the start of the next free fragment. * * Objects stored on the disk are allocated object ids (we use these as * our inode numbers.) Object ids contain a fragment id and an optional * offset. This allows a directory fragment to contain small files * associated with that directory. */ /* * For the future... */ static DEFINE_RWLOCK(adfs_map_lock); /* * This is fun. We need to load up to 19 bits from the map at an * arbitrary bit alignment. (We're limited to 19 bits by F+ version 2). */ #define GET_FRAG_ID(_map,_start,_idmask) … /* * return the map bit offset of the fragment frag_id in the zone dm. * Note that the loop is optimised for best asm code - look at the * output of: * gcc -D__KERNEL__ -O2 -I../../include -o - -S map.c */ static int lookup_zone(const struct adfs_discmap *dm, const unsigned int idlen, const u32 frag_id, unsigned int *offset) { … } /* * Scan the free space map, for this zone, calculating the total * number of map bits in each free space fragment. * * Note: idmask is limited to 15 bits [3.2] */ static unsigned int scan_free_map(struct adfs_sb_info *asb, struct adfs_discmap *dm) { … } static int scan_map(struct adfs_sb_info *asb, unsigned int zone, const u32 frag_id, unsigned int mapoff) { … } /* * calculate the amount of free blocks in the map. * * n=1 * total_free = E(free_in_zone_n) * nzones */ void adfs_map_statfs(struct super_block *sb, struct kstatfs *buf) { … } int adfs_map_lookup(struct super_block *sb, u32 frag_id, unsigned int offset) { … } static unsigned char adfs_calczonecheck(struct super_block *sb, unsigned char *map) { … } static int adfs_checkmap(struct super_block *sb, struct adfs_discmap *dm) { … } /* * Layout the map - the first zone contains a copy of the disc record, * and the last zone must be limited to the size of the filesystem. */ static void adfs_map_layout(struct adfs_discmap *dm, unsigned int nzones, struct adfs_discrecord *dr) { … } static int adfs_map_read(struct adfs_discmap *dm, struct super_block *sb, unsigned int map_addr, unsigned int nzones) { … } static void adfs_map_relse(struct adfs_discmap *dm, unsigned int nzones) { … } struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_discrecord *dr) { … } void adfs_free_map(struct super_block *sb) { … }