/*
 * Copyright (C) 1993, 1994 by Ralf Baechle (linux@uni-koblenz.de)
 *
 * This file is part of Minix-Handler, an AmigaDOS Filehandler to access
 * Minix filesystems via AmigaDOS.
 *
 * Minix-Handler is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * Minix-Handler is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifndef _MINIX_FS_H
#define _MINIX_FS_H

#include <exec/types.h>

#define BLOCK_SIZE_BITS 10
#define BLOCK_SIZE      (1<<BLOCK_SIZE_BITS)
#define BLOCK_SIZE_MASK (BLOCK_SIZE-1)

/*
 * The minix filesystem constants/structures
 */

#define MINIX_NAME_LEN 14
#define MINIX_ROOT_INO 1

#define MINIX_I_MAP_SLOTS	8
#define MINIX_Z_MAP_SLOTS	8
#define MINIX_SUPER_MAGIC	0x137F
#define MINIX_SUPER_MAGIC2	0x138F		/* minix fs, 30 char names    */
#define NEW_MINIX_SUPER_MAGIC	0x2468		/* minix V2 - not implemented */

#define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode)))
#define MINIX_DIR_ENTRIES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_dir_entry)))

typedef UWORD ino_t;

struct minix_inode {
	unsigned short i_mode;
	unsigned short i_uid;
	unsigned long i_size;
	unsigned long i_time;
	unsigned char i_gid;
	unsigned char i_nlinks;
	unsigned short i_zone[9];
};

/*
 * minix super-block data on disk
 */
struct minix_super_block {
	unsigned short s_ninodes;
	unsigned short s_nzones;
	unsigned short s_imap_blocks;
	unsigned short s_zmap_blocks;
	unsigned short s_firstdatazone;
	unsigned short s_log_zone_size;
	unsigned long s_max_size;
	unsigned short s_magic;
};

#define LOG_DIR_ENTRY_SIZE 4

struct minix_dir_entry {
	unsigned short inode;
	char name[MINIX_NAME_LEN];
};

#define S_IFMT   00170000
#define S_IFSOCK 0140000
#define S_IFLNK	 0120000
#define S_IFREG  0100000
#define S_IFBLK  0060000
#define S_IFDIR  0040000
#define S_IFCHR  0020000
#define S_IFIFO  0010000
#define S_ISUID  0004000
#define S_ISGID  0002000
#define S_ISVTX  0001000

#define S_ISLNK(m)	(((m) & S_IFMT) == S_IFLNK)
#define S_ISREG(m)	(((m) & S_IFMT) == S_IFREG)
#define S_ISDIR(m)	(((m) & S_IFMT) == S_IFDIR)
#define S_ISCHR(m)	(((m) & S_IFMT) == S_IFCHR)
#define S_ISBLK(m)	(((m) & S_IFMT) == S_IFBLK)
#define S_ISFIFO(m)	(((m) & S_IFMT) == S_IFIFO)
#define S_ISSOCK(m)	(((m) & S_IFMT) == S_IFSOCK)

#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100

#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010

#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001

//#define test_bit(nr,addr)  (((unsigned long *)(addr))[nr >> 5] & (1 << (0x1f - (nr & 0x1f))))
//#define set_bit(nr,addr)   (((unsigned long *)(addr))[nr >> 5] |= (1 << (0x1f - (nr & 0x1f))))
//#define clear_bit(nr,addr) (((unsigned long *)(addr))[nr >> 5] &= ~(1 << (0x1f - (nr & 0x1f))))

//#define ID_MINIX_DISK		(0x4d4e5800)	/* 'MNX\0' */
#define ID_MINIX_DISK		ID_DOS_DISK	/* 'DOS\0' */

#ifndef FOREVER
#  define FOREVER for(;;)
#endif /* FOREVER */

#endif /* _MINIX_FS_H */
