root/fs/affs/amigaffs.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. affs_get_key_entry
  2. affs_find_next_hash_entry
  3. affs_get_fh_hash_link
  4. affs_get_file_name
  5. affs_get_extension
  6. affs_checksum_block
  7. init_affs_fs
  8. init_module
  9. cleanup_module

   1 /*
   2  *  linux/fs/affs/amigaffs.c
   3  *
   4  *  (C) 1996  Stefan Reinauer - Modified to compile as Module
   5  *
   6  *  (C) 1993  Ray Burr - Amiga FFS filesystem.
   7  *
   8  */
   9 
  10 
  11 #include <linux/module.h>
  12 
  13 #include <linux/fs.h>
  14 #include <linux/affs_fs.h>
  15 #include <linux/mm.h>
  16 
  17 #include "amigaffs.h"
  18 
  19 /*
  20  * Functions for accessing Amiga-FFS structures.
  21  *
  22  */
  23 
  24 /* Get key entry number ENTRY_POS from the header block pointed to
  25    by DATA.  If ENTRY_POS is invalid, -1 is returned.  This is
  26    used to get entries from file and directory headers as well
  27    as extension and root blocks.  In the current FFS specs, these
  28    tables are defined to be the same size in all of these. */
  29 
  30 int affs_get_key_entry (int bsize, void *data, int entry_pos)
     /* [previous][next][first][last][top][bottom][index][help] */
  31 {
  32         struct dir_front *dir_front = (struct dir_front *)data;
  33         int key, hash_table_size;
  34 
  35         hash_table_size = MIDBLOCK_LONGS (bsize);
  36         key = 0;
  37         if (entry_pos >= 0 && entry_pos < hash_table_size)
  38                 key = swap_long (dir_front->hash_table[entry_pos]);
  39 
  40         return key;
  41 }
  42 
  43 /* Find the next used hash entry at or after *HASH_POS in a directory's hash
  44    table.  *HASH_POS is assigned that entry's number.  DIR_DATA points to
  45    the directory header block in memory.  If there are no more entries,
  46    0 is returned.  Otherwise, the key number in the next used hash slot
  47    is returned. */
  48 
  49 int affs_find_next_hash_entry (int bsize, void *dir_data, int *hash_pos)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51         struct dir_front *dir_front = (struct dir_front *)dir_data;
  52         int i, hash_table_size;
  53 
  54         hash_table_size = MIDBLOCK_LONGS (bsize);
  55         if (*hash_pos < 0 || *hash_pos >= hash_table_size)
  56                 return -1;
  57         for (i = *hash_pos; i < hash_table_size; i++)
  58                 if (dir_front->hash_table[i] != 0)
  59                         break;
  60         if (i == hash_table_size)
  61                 return 0;
  62         *hash_pos = i;
  63         return swap_long (dir_front->hash_table[i]);
  64 }
  65 
  66 /* Get the hash_chain (next file header key in hash chain) entry from a
  67    file header block in memory pointed to by FH_DATA. */
  68 
  69 int affs_get_fh_hash_link (int bsize, void *fh_data)
     /* [previous][next][first][last][top][bottom][index][help] */
  70 {
  71         struct file_end *file_end;
  72         int key;
  73 
  74         file_end = GET_END_PTR (struct file_end, fh_data, bsize);
  75         key = swap_long (file_end->hash_chain);
  76         return key;
  77 }
  78 
  79 /* Set *NAME to point to the file name in a file header block in memory
  80    pointed to by FH_DATA.  The length of the name is returned. */
  81 
  82 int affs_get_file_name (int bsize, void *fh_data, char **name)
     /* [previous][next][first][last][top][bottom][index][help] */
  83 {
  84         struct file_end *file_end;
  85 
  86         file_end = GET_END_PTR (struct file_end, fh_data, bsize);
  87         if (file_end->file_name[0] == 0
  88             || file_end->file_name[0] > 30) {
  89                 printk ("affs_get_file_name: OOPS! bad filename\n");
  90                 printk ("  file_end->file_name[0] = %d\n",
  91                         file_end->file_name[0]);
  92                 *name = "***BAD_FILE***";
  93                 return 14;
  94         }
  95         *name = (char *) &file_end->file_name[1];
  96         return file_end->file_name[0];
  97 }
  98 
  99 /* Get the key number of the first extension block for the file
 100    header pointed to by FH_DATA. */
 101 
 102 int affs_get_extension (int bsize, void *fh_data)
     /* [previous][next][first][last][top][bottom][index][help] */
 103 {
 104         struct file_end *file_end;
 105         int key;
 106 
 107         file_end = GET_END_PTR (struct file_end, fh_data, bsize);
 108         key = swap_long (file_end->extension);
 109         return key;
 110 }
 111 
 112 /* Checksum a block, do various consistency checks and optionally return
 113    the blocks type number.  DATA points to the block.  If their pointers
 114    are non-null, *PTYPE and *STYPE are set to the primary and secondary
 115    block types respectively.  Returns non-zero if the block is not
 116    consistent. */
 117 
 118 int affs_checksum_block (int bsize, void *data, int *ptype, int *stype)
     /* [previous][next][first][last][top][bottom][index][help] */
 119 {
 120         if (ptype)
 121                 *ptype = swap_long (((long *) data)[0]);
 122         if (stype)
 123                 *stype = swap_long (((long *) data)[bsize / 4 - 1]);
 124         return 0;
 125 }
 126 
 127 static struct file_system_type affs_fs_type = {
 128         affs_read_super, "affs", 1, NULL
 129 };
 130 
 131 int init_affs_fs(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 132 {
 133         return register_filesystem(&affs_fs_type);
 134 }
 135 
 136 #ifdef MODULE
 137 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 138 {
 139         int status;
 140 
 141         if ((status = init_affs_fs()) == 0)
 142                 register_symtab(0);
 143         return status;
 144 }
 145 
 146 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 147 {
 148         unregister_filesystem(&affs_fs_type);
 149 }
 150 
 151 #endif
 152 

/* [previous][next][first][last][top][bottom][index][help] */