release 3.4
https://sourceforge.net/projects/elilo/files/elilo/elilo-3.4/
This commit is contained in:
commit
fb6ce0d596
100 changed files with 20247 additions and 0 deletions
70
fs/Makefile
Normal file
70
fs/Makefile
Normal file
|
@ -0,0 +1,70 @@
|
|||
#
|
||||
# Copyright (C) 2001-2003 Hewlett-Packard Co.
|
||||
# Contributed by Stephane Eranian <eranian@hpl.hp.com>
|
||||
#
|
||||
# This file is part of the ELILO, the EFI Linux boot loader.
|
||||
#
|
||||
# ELILO 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.
|
||||
#
|
||||
# ELILO 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.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with ELILO; see the file COPYING. If not, write to the Free
|
||||
# Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
# 02111-1307, USA.
|
||||
#
|
||||
# Please check out the elilo.txt for complete documentation on how
|
||||
# to use this program.
|
||||
#
|
||||
|
||||
include ../Make.defaults
|
||||
include ../Make.rules
|
||||
|
||||
TOPDIR=$(CDIR)/..
|
||||
|
||||
FILES=
|
||||
ifeq ($(CONFIG_localfs),y)
|
||||
FILES += localfs.o
|
||||
endif
|
||||
|
||||
#
|
||||
# Ext2 is now disabled by default. See top level Makefile
|
||||
# for details
|
||||
#
|
||||
ifeq ($(CONFIG_ext2fs),y)
|
||||
FILES += ext2fs.o
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_netfs),y)
|
||||
FILES += netfs.o
|
||||
endif
|
||||
|
||||
|
||||
TARGET=fs.o
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
#
|
||||
# XXX: does not trigger recompile when changing filesystem selection
|
||||
# without doing make clean.
|
||||
#
|
||||
$(TARGET): check-filesystems $(TOPDIR)/Make.defaults $(FILES)
|
||||
$(LD) -r -o $@ $(FILES)
|
||||
|
||||
clean:
|
||||
$(RM) -f $(TARGET) $(FILES)
|
||||
|
||||
check-filesystems:
|
||||
@if [ -n "$(FILES)" ]; then \
|
||||
exit 0; \
|
||||
else \
|
||||
echo "You need to define at least one filesystem in Make.defaults"; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
626
fs/ext2_fs.h
Normal file
626
fs/ext2_fs.h
Normal file
|
@ -0,0 +1,626 @@
|
|||
/*
|
||||
* linux/include/linux/ext2_fs.h
|
||||
*
|
||||
* Copyright (C) 1992, 1993, 1994, 1995
|
||||
* Remy Card (card@masi.ibp.fr)
|
||||
* Laboratoire MASI - Institut Blaise Pascal
|
||||
* Universite Pierre et Marie Curie (Paris VI)
|
||||
*
|
||||
* from
|
||||
*
|
||||
* linux/include/linux/minix_fs.h
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_EXT2_FS_H
|
||||
#define _LINUX_EXT2_FS_H
|
||||
|
||||
/*
|
||||
* The second extended filesystem constants/structures
|
||||
*/
|
||||
|
||||
/*
|
||||
* Define EXT2FS_DEBUG to produce debug messages
|
||||
*/
|
||||
#undef EXT2FS_DEBUG
|
||||
|
||||
/*
|
||||
* Define EXT2_PREALLOCATE to preallocate data blocks for expanding files
|
||||
*/
|
||||
#define EXT2_PREALLOCATE
|
||||
#define EXT2_DEFAULT_PREALLOC_BLOCKS 8
|
||||
|
||||
/*
|
||||
* The second extended file system version
|
||||
*/
|
||||
#define EXT2FS_DATE "95/08/09"
|
||||
#define EXT2FS_VERSION "0.5b"
|
||||
|
||||
/*
|
||||
* Debug code
|
||||
*/
|
||||
#ifdef EXT2FS_DEBUG
|
||||
# define ext2_debug(f, a...) { \
|
||||
printk ("EXT2-fs DEBUG (%s, %d): %s:", \
|
||||
__FILE__, __LINE__, __FUNCTION__); \
|
||||
printk (f, ## a); \
|
||||
}
|
||||
#else
|
||||
# define ext2_debug(f, a...) /**/
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Special inodes numbers
|
||||
*/
|
||||
#define EXT2_BAD_INO 1 /* Bad blocks inode */
|
||||
#define EXT2_ROOT_INO 2 /* Root inode */
|
||||
#define EXT2_ACL_IDX_INO 3 /* ACL inode */
|
||||
#define EXT2_ACL_DATA_INO 4 /* ACL inode */
|
||||
#define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
|
||||
#define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
|
||||
|
||||
/* First non-reserved inode for old ext2 filesystems */
|
||||
#define EXT2_GOOD_OLD_FIRST_INO 11
|
||||
|
||||
/*
|
||||
* The second extended file system magic number
|
||||
*/
|
||||
#define EXT2_SUPER_MAGIC 0xEF53
|
||||
|
||||
/*
|
||||
* Maximal count of links to a file
|
||||
*/
|
||||
#define EXT2_LINK_MAX 32000
|
||||
|
||||
/*
|
||||
* Macro-instructions used to manage several block sizes
|
||||
*/
|
||||
#define EXT2_MIN_BLOCK_SIZE 1024
|
||||
#define EXT2_MAX_BLOCK_SIZE 4096
|
||||
#define EXT2_MIN_BLOCK_LOG_SIZE 10
|
||||
#ifdef __KERNEL__
|
||||
# define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
|
||||
#else
|
||||
# define EXT2_BLOCK_SIZE(s) (EXT2_MIN_BLOCK_SIZE << (s)->s_log_block_size)
|
||||
#endif
|
||||
#define EXT2_ACLE_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_acl_entry))
|
||||
#define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
|
||||
#ifdef __KERNEL__
|
||||
# define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
|
||||
#else
|
||||
# define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
|
||||
#endif
|
||||
#ifdef __KERNEL__
|
||||
#define EXT2_ADDR_PER_BLOCK_BITS(s) ((s)->u.ext2_sb.s_addr_per_block_bits)
|
||||
#define EXT2_INODE_SIZE(s) ((s)->u.ext2_sb.s_inode_size)
|
||||
#define EXT2_FIRST_INO(s) ((s)->u.ext2_sb.s_first_ino)
|
||||
#else
|
||||
#define EXT2_INODE_SIZE(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
|
||||
EXT2_GOOD_OLD_INODE_SIZE : \
|
||||
(s)->s_inode_size)
|
||||
#define EXT2_FIRST_INO(s) (((s)->s_rev_level == EXT2_GOOD_OLD_REV) ? \
|
||||
EXT2_GOOD_OLD_FIRST_INO : \
|
||||
(s)->s_first_ino)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Macro-instructions used to manage fragments
|
||||
*/
|
||||
#define EXT2_MIN_FRAG_SIZE 1024
|
||||
#define EXT2_MAX_FRAG_SIZE 4096
|
||||
#define EXT2_MIN_FRAG_LOG_SIZE 10
|
||||
#ifdef __KERNEL__
|
||||
# define EXT2_FRAG_SIZE(s) ((s)->u.ext2_sb.s_frag_size)
|
||||
# define EXT2_FRAGS_PER_BLOCK(s) ((s)->u.ext2_sb.s_frags_per_block)
|
||||
#else
|
||||
# define EXT2_FRAG_SIZE(s) (EXT2_MIN_FRAG_SIZE << (s)->s_log_frag_size)
|
||||
# define EXT2_FRAGS_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / EXT2_FRAG_SIZE(s))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ACL structures
|
||||
*/
|
||||
struct ext2_acl_header /* Header of Access Control Lists */
|
||||
{
|
||||
__u32 aclh_size;
|
||||
__u32 aclh_file_count;
|
||||
__u32 aclh_acle_count;
|
||||
__u32 aclh_first_acle;
|
||||
};
|
||||
|
||||
struct ext2_acl_entry /* Access Control List Entry */
|
||||
{
|
||||
__u32 acle_size;
|
||||
__u16 acle_perms; /* Access permissions */
|
||||
__u16 acle_type; /* Type of entry */
|
||||
__u16 acle_tag; /* User or group identity */
|
||||
__u16 acle_pad1;
|
||||
__u32 acle_next; /* Pointer on next entry for the */
|
||||
/* same inode or on next free entry */
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure of a blocks group descriptor
|
||||
*/
|
||||
struct ext2_group_desc
|
||||
{
|
||||
__u32 bg_block_bitmap; /* Blocks bitmap block */
|
||||
__u32 bg_inode_bitmap; /* Inodes bitmap block */
|
||||
__u32 bg_inode_table; /* Inodes table block */
|
||||
__u16 bg_free_blocks_count; /* Free blocks count */
|
||||
__u16 bg_free_inodes_count; /* Free inodes count */
|
||||
__u16 bg_used_dirs_count; /* Directories count */
|
||||
__u16 bg_pad;
|
||||
__u32 bg_reserved[3];
|
||||
};
|
||||
|
||||
/*
|
||||
* Macro-instructions used to manage group descriptors
|
||||
*/
|
||||
#ifdef __KERNEL__
|
||||
# define EXT2_BLOCKS_PER_GROUP(s) ((s)->u.ext2_sb.s_blocks_per_group)
|
||||
# define EXT2_DESC_PER_BLOCK(s) ((s)->u.ext2_sb.s_desc_per_block)
|
||||
# define EXT2_INODES_PER_GROUP(s) ((s)->u.ext2_sb.s_inodes_per_group)
|
||||
# define EXT2_DESC_PER_BLOCK_BITS(s) ((s)->u.ext2_sb.s_desc_per_block_bits)
|
||||
#else
|
||||
# define EXT2_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
|
||||
# define EXT2_DESC_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (struct ext2_group_desc))
|
||||
# define EXT2_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Constants relative to the data blocks
|
||||
*/
|
||||
#define EXT2_NDIR_BLOCKS 12
|
||||
#define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
|
||||
#define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
|
||||
#define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
|
||||
#define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
|
||||
|
||||
/*
|
||||
* Inode flags
|
||||
*/
|
||||
#define EXT2_SECRM_FL 0x00000001 /* Secure deletion */
|
||||
#define EXT2_UNRM_FL 0x00000002 /* Undelete */
|
||||
#define EXT2_COMPR_FL 0x00000004 /* Compress file */
|
||||
#define EXT2_SYNC_FL 0x00000008 /* Synchronous updates */
|
||||
#define EXT2_IMMUTABLE_FL 0x00000010 /* Immutable file */
|
||||
#define EXT2_APPEND_FL 0x00000020 /* writes to file may only append */
|
||||
#define EXT2_NODUMP_FL 0x00000040 /* do not dump file */
|
||||
#define EXT2_NOATIME_FL 0x00000080 /* do not update atime */
|
||||
/* Reserved for compression usage... */
|
||||
#define EXT2_DIRTY_FL 0x00000100
|
||||
#define EXT2_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
|
||||
#define EXT2_NOCOMP_FL 0x00000400 /* Don't compress */
|
||||
#define EXT2_ECOMPR_FL 0x00000800 /* Compression error */
|
||||
/* End compression flags --- maybe not all used */
|
||||
#define EXT2_BTREE_FL 0x00001000 /* btree format dir */
|
||||
#define EXT2_RESERVED_FL 0x80000000 /* reserved for ext2 lib */
|
||||
|
||||
#define EXT2_FL_USER_VISIBLE 0x00001FFF /* User visible flags */
|
||||
#define EXT2_FL_USER_MODIFIABLE 0x000000FF /* User modifiable flags */
|
||||
|
||||
/*
|
||||
* ioctl commands
|
||||
*/
|
||||
#define EXT2_IOC_GETFLAGS _IOR('f', 1, long)
|
||||
#define EXT2_IOC_SETFLAGS _IOW('f', 2, long)
|
||||
#define EXT2_IOC_GETVERSION _IOR('v', 1, long)
|
||||
#define EXT2_IOC_SETVERSION _IOW('v', 2, long)
|
||||
|
||||
/*
|
||||
* Structure of an inode on the disk
|
||||
*/
|
||||
struct ext2_inode {
|
||||
__u16 i_mode; /* File mode */
|
||||
__u16 i_uid; /* Low 16 bits of Owner Uid */
|
||||
__u32 i_size; /* Size in bytes */
|
||||
__u32 i_atime; /* Access time */
|
||||
__u32 i_ctime; /* Creation time */
|
||||
__u32 i_mtime; /* Modification time */
|
||||
__u32 i_dtime; /* Deletion Time */
|
||||
__u16 i_gid; /* Low 16 bits of Group Id */
|
||||
__u16 i_links_count; /* Links count */
|
||||
__u32 i_blocks; /* Blocks count */
|
||||
__u32 i_flags; /* File flags */
|
||||
union {
|
||||
struct {
|
||||
__u32 l_i_reserved1;
|
||||
} linux1;
|
||||
struct {
|
||||
__u32 h_i_translator;
|
||||
} hurd1;
|
||||
struct {
|
||||
__u32 m_i_reserved1;
|
||||
} masix1;
|
||||
} osd1; /* OS dependent 1 */
|
||||
__u32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
|
||||
__u32 i_generation; /* File version (for NFS) */
|
||||
__u32 i_file_acl; /* File ACL */
|
||||
__u32 i_dir_acl; /* Directory ACL */
|
||||
__u32 i_faddr; /* Fragment address */
|
||||
union {
|
||||
struct {
|
||||
__u8 l_i_frag; /* Fragment number */
|
||||
__u8 l_i_fsize; /* Fragment size */
|
||||
__u16 i_pad1;
|
||||
__u16 l_i_uid_high; /* these 2 fields */
|
||||
__u16 l_i_gid_high; /* were reserved2[0] */
|
||||
__u32 l_i_reserved2;
|
||||
} linux2;
|
||||
struct {
|
||||
__u8 h_i_frag; /* Fragment number */
|
||||
__u8 h_i_fsize; /* Fragment size */
|
||||
__u16 h_i_mode_high;
|
||||
__u16 h_i_uid_high;
|
||||
__u16 h_i_gid_high;
|
||||
__u32 h_i_author;
|
||||
} hurd2;
|
||||
struct {
|
||||
__u8 m_i_frag; /* Fragment number */
|
||||
__u8 m_i_fsize; /* Fragment size */
|
||||
__u16 m_pad1;
|
||||
__u32 m_i_reserved2[2];
|
||||
} masix2;
|
||||
} osd2; /* OS dependent 2 */
|
||||
};
|
||||
|
||||
#define i_size_high i_dir_acl
|
||||
|
||||
#if defined(__KERNEL__) || defined(__linux__)
|
||||
#define i_reserved1 osd1.linux1.l_i_reserved1
|
||||
#define i_frag osd2.linux2.l_i_frag
|
||||
#define i_fsize osd2.linux2.l_i_fsize
|
||||
#define i_uid_low i_uid
|
||||
#define i_gid_low i_gid
|
||||
#define i_uid_high osd2.linux2.l_i_uid_high
|
||||
#define i_gid_high osd2.linux2.l_i_gid_high
|
||||
#define i_reserved2 osd2.linux2.l_i_reserved2
|
||||
#endif
|
||||
|
||||
#ifdef __hurd__
|
||||
#define i_translator osd1.hurd1.h_i_translator
|
||||
#define i_frag osd2.hurd2.h_i_frag;
|
||||
#define i_fsize osd2.hurd2.h_i_fsize;
|
||||
#define i_uid_high osd2.hurd2.h_i_uid_high
|
||||
#define i_gid_high osd2.hurd2.h_i_gid_high
|
||||
#define i_author osd2.hurd2.h_i_author
|
||||
#endif
|
||||
|
||||
#ifdef __masix__
|
||||
#define i_reserved1 osd1.masix1.m_i_reserved1
|
||||
#define i_frag osd2.masix2.m_i_frag
|
||||
#define i_fsize osd2.masix2.m_i_fsize
|
||||
#define i_reserved2 osd2.masix2.m_i_reserved2
|
||||
#endif
|
||||
|
||||
/*
|
||||
* File system states
|
||||
*/
|
||||
#define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
|
||||
#define EXT2_ERROR_FS 0x0002 /* Errors detected */
|
||||
|
||||
/*
|
||||
* Mount flags
|
||||
*/
|
||||
#define EXT2_MOUNT_CHECK 0x0001 /* Do mount-time checks */
|
||||
#define EXT2_MOUNT_GRPID 0x0004 /* Create files with directory's group */
|
||||
#define EXT2_MOUNT_DEBUG 0x0008 /* Some debugging messages */
|
||||
#define EXT2_MOUNT_ERRORS_CONT 0x0010 /* Continue on errors */
|
||||
#define EXT2_MOUNT_ERRORS_RO 0x0020 /* Remount fs ro on errors */
|
||||
#define EXT2_MOUNT_ERRORS_PANIC 0x0040 /* Panic on errors */
|
||||
#define EXT2_MOUNT_MINIX_DF 0x0080 /* Mimics the Minix statfs */
|
||||
#define EXT2_MOUNT_NO_UID32 0x0200 /* Disable 32-bit UIDs */
|
||||
|
||||
#define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
|
||||
#define set_opt(o, opt) o |= EXT2_MOUNT_##opt
|
||||
#define test_opt(sb, opt) ((sb)->u.ext2_sb.s_mount_opt & \
|
||||
EXT2_MOUNT_##opt)
|
||||
/*
|
||||
* Maximal mount counts between two filesystem checks
|
||||
*/
|
||||
#define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
|
||||
#define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
|
||||
|
||||
/*
|
||||
* Behaviour when detecting errors
|
||||
*/
|
||||
#define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
|
||||
#define EXT2_ERRORS_RO 2 /* Remount fs read-only */
|
||||
#define EXT2_ERRORS_PANIC 3 /* Panic */
|
||||
#define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
|
||||
|
||||
/*
|
||||
* Structure of the super block
|
||||
*/
|
||||
struct ext2_super_block {
|
||||
__u32 s_inodes_count; /* Inodes count */
|
||||
__u32 s_blocks_count; /* Blocks count */
|
||||
__u32 s_r_blocks_count; /* Reserved blocks count */
|
||||
__u32 s_free_blocks_count; /* Free blocks count */
|
||||
__u32 s_free_inodes_count; /* Free inodes count */
|
||||
__u32 s_first_data_block; /* First Data Block */
|
||||
__u32 s_log_block_size; /* Block size */
|
||||
__s32 s_log_frag_size; /* Fragment size */
|
||||
__u32 s_blocks_per_group; /* # Blocks per group */
|
||||
__u32 s_frags_per_group; /* # Fragments per group */
|
||||
__u32 s_inodes_per_group; /* # Inodes per group */
|
||||
__u32 s_mtime; /* Mount time */
|
||||
__u32 s_wtime; /* Write time */
|
||||
__u16 s_mnt_count; /* Mount count */
|
||||
__s16 s_max_mnt_count; /* Maximal mount count */
|
||||
__u16 s_magic; /* Magic signature */
|
||||
__u16 s_state; /* File system state */
|
||||
__u16 s_errors; /* Behaviour when detecting errors */
|
||||
__u16 s_minor_rev_level; /* minor revision level */
|
||||
__u32 s_lastcheck; /* time of last check */
|
||||
__u32 s_checkinterval; /* max. time between checks */
|
||||
__u32 s_creator_os; /* OS */
|
||||
__u32 s_rev_level; /* Revision level */
|
||||
__u16 s_def_resuid; /* Default uid for reserved blocks */
|
||||
__u16 s_def_resgid; /* Default gid for reserved blocks */
|
||||
/*
|
||||
* These fields are for EXT2_DYNAMIC_REV superblocks only.
|
||||
*
|
||||
* Note: the difference between the compatible feature set and
|
||||
* the incompatible feature set is that if there is a bit set
|
||||
* in the incompatible feature set that the kernel doesn't
|
||||
* know about, it should refuse to mount the filesystem.
|
||||
*
|
||||
* e2fsck's requirements are more strict; if it doesn't know
|
||||
* about a feature in either the compatible or incompatible
|
||||
* feature set, it must abort and not try to meddle with
|
||||
* things it doesn't understand...
|
||||
*/
|
||||
__u32 s_first_ino; /* First non-reserved inode */
|
||||
__u16 s_inode_size; /* size of inode structure */
|
||||
__u16 s_block_group_nr; /* block group # of this superblock */
|
||||
__u32 s_feature_compat; /* compatible feature set */
|
||||
__u32 s_feature_incompat; /* incompatible feature set */
|
||||
__u32 s_feature_ro_compat; /* readonly-compatible feature set */
|
||||
__u8 s_uuid[16]; /* 128-bit uuid for volume */
|
||||
char s_volume_name[16]; /* volume name */
|
||||
char s_last_mounted[64]; /* directory where last mounted */
|
||||
__u32 s_algorithm_usage_bitmap; /* For compression */
|
||||
/*
|
||||
* Performance hints. Directory preallocation should only
|
||||
* happen if the EXT2_COMPAT_PREALLOC flag is on.
|
||||
*/
|
||||
__u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
|
||||
__u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
|
||||
__u16 s_padding1;
|
||||
__u32 s_reserved[204]; /* Padding to the end of the block */
|
||||
};
|
||||
|
||||
#ifdef __KERNEL__
|
||||
#define EXT2_SB(sb) (&((sb)->u.ext2_sb))
|
||||
#else
|
||||
/* Assume that user mode programs are passing in an ext2fs superblock, not
|
||||
* a kernel struct super_block. This will allow us to call the feature-test
|
||||
* macros from user land. */
|
||||
#define EXT2_SB(sb) (sb)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Codes for operating systems
|
||||
*/
|
||||
#define EXT2_OS_LINUX 0
|
||||
#define EXT2_OS_HURD 1
|
||||
#define EXT2_OS_MASIX 2
|
||||
#define EXT2_OS_FREEBSD 3
|
||||
#define EXT2_OS_LITES 4
|
||||
|
||||
/*
|
||||
* Revision levels
|
||||
*/
|
||||
#define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
|
||||
#define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
|
||||
|
||||
#define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
|
||||
#define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
|
||||
|
||||
#define EXT2_GOOD_OLD_INODE_SIZE 128
|
||||
|
||||
/*
|
||||
* Feature set definitions
|
||||
*/
|
||||
|
||||
#define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
|
||||
( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
|
||||
#define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
|
||||
( EXT2_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
|
||||
#define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
|
||||
( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
|
||||
#define EXT2_SET_COMPAT_FEATURE(sb,mask) \
|
||||
EXT2_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
|
||||
#define EXT2_SET_RO_COMPAT_FEATURE(sb,mask) \
|
||||
EXT2_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
|
||||
#define EXT2_SET_INCOMPAT_FEATURE(sb,mask) \
|
||||
EXT2_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
|
||||
#define EXT2_CLEAR_COMPAT_FEATURE(sb,mask) \
|
||||
EXT2_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
|
||||
#define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
|
||||
EXT2_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
|
||||
#define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
|
||||
EXT2_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
|
||||
|
||||
#define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
|
||||
|
||||
#define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
|
||||
#define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
|
||||
#define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
|
||||
|
||||
#define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
|
||||
#define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
|
||||
|
||||
#define EXT2_FEATURE_COMPAT_SUPP 0
|
||||
#define EXT2_FEATURE_INCOMPAT_SUPP EXT2_FEATURE_INCOMPAT_FILETYPE
|
||||
#define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
|
||||
EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
|
||||
EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
|
||||
|
||||
/*
|
||||
* Default values for user and/or group using reserved blocks
|
||||
*/
|
||||
#define EXT2_DEF_RESUID 0
|
||||
#define EXT2_DEF_RESGID 0
|
||||
|
||||
/*
|
||||
* Structure of a directory entry
|
||||
*/
|
||||
#define EXT2_NAME_LEN 255
|
||||
|
||||
struct ext2_dir_entry {
|
||||
__u32 inode; /* Inode number */
|
||||
__u16 rec_len; /* Directory entry length */
|
||||
__u16 name_len; /* Name length */
|
||||
char name[EXT2_NAME_LEN]; /* File name */
|
||||
};
|
||||
|
||||
/*
|
||||
* The new version of the directory entry. Since EXT2 structures are
|
||||
* stored in intel byte order, and the name_len field could never be
|
||||
* bigger than 255 chars, it's safe to reclaim the extra byte for the
|
||||
* file_type field.
|
||||
*/
|
||||
struct ext2_dir_entry_2 {
|
||||
__u32 inode; /* Inode number */
|
||||
__u16 rec_len; /* Directory entry length */
|
||||
__u8 name_len; /* Name length */
|
||||
__u8 file_type;
|
||||
char name[EXT2_NAME_LEN]; /* File name */
|
||||
};
|
||||
|
||||
/*
|
||||
* Ext2 directory file types. Only the low 3 bits are used. The
|
||||
* other bits are reserved for now.
|
||||
*/
|
||||
#define EXT2_FT_UNKNOWN 0
|
||||
#define EXT2_FT_REG_FILE 1
|
||||
#define EXT2_FT_DIR 2
|
||||
#define EXT2_FT_CHRDEV 3
|
||||
#define EXT2_FT_BLKDEV 4
|
||||
#define EXT2_FT_FIFO 5
|
||||
#define EXT2_FT_SOCK 6
|
||||
#define EXT2_FT_SYMLINK 7
|
||||
|
||||
#define EXT2_FT_MAX 8
|
||||
|
||||
/*
|
||||
* EXT2_DIR_PAD defines the directory entries boundaries
|
||||
*
|
||||
* NOTE: It must be a multiple of 4
|
||||
*/
|
||||
#define EXT2_DIR_PAD 4
|
||||
#define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
|
||||
#define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
|
||||
~EXT2_DIR_ROUND)
|
||||
|
||||
#ifdef __KERNEL__
|
||||
/*
|
||||
* Function prototypes
|
||||
*/
|
||||
|
||||
/*
|
||||
* Ok, these declarations are also in <linux/kernel.h> but none of the
|
||||
* ext2 source programs needs to include it so they are duplicated here.
|
||||
*/
|
||||
# define NORET_TYPE /**/
|
||||
# define ATTRIB_NORET __attribute__((noreturn))
|
||||
# define NORET_AND noreturn,
|
||||
|
||||
/* acl.c */
|
||||
extern int ext2_permission (struct inode *, int);
|
||||
|
||||
/* balloc.c */
|
||||
extern int ext2_bg_has_super(struct super_block *sb, int group);
|
||||
extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
|
||||
extern int ext2_new_block (const struct inode *, unsigned long,
|
||||
__u32 *, __u32 *, int *);
|
||||
extern void ext2_free_blocks (const struct inode *, unsigned long,
|
||||
unsigned long);
|
||||
extern unsigned long ext2_count_free_blocks (struct super_block *);
|
||||
extern void ext2_check_blocks_bitmap (struct super_block *);
|
||||
extern struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
|
||||
unsigned int block_group,
|
||||
struct buffer_head ** bh);
|
||||
|
||||
/* bitmap.c */
|
||||
extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
|
||||
|
||||
/* dir.c */
|
||||
extern int ext2_check_dir_entry (const char *, struct inode *,
|
||||
struct ext2_dir_entry_2 *, struct buffer_head *,
|
||||
unsigned long);
|
||||
|
||||
/* file.c */
|
||||
extern int ext2_read (struct inode *, struct file *, char *, int);
|
||||
extern int ext2_write (struct inode *, struct file *, char *, int);
|
||||
|
||||
/* fsync.c */
|
||||
extern int ext2_sync_file (struct file *, struct dentry *, int);
|
||||
extern int ext2_fsync_inode (struct inode *, int);
|
||||
|
||||
/* ialloc.c */
|
||||
extern struct inode * ext2_new_inode (const struct inode *, int);
|
||||
extern void ext2_free_inode (struct inode *);
|
||||
extern unsigned long ext2_count_free_inodes (struct super_block *);
|
||||
extern void ext2_check_inodes_bitmap (struct super_block *);
|
||||
|
||||
/* inode.c */
|
||||
|
||||
extern struct buffer_head * ext2_getblk (struct inode *, long, int, int *);
|
||||
extern struct buffer_head * ext2_bread (struct inode *, int, int, int *);
|
||||
|
||||
extern void ext2_read_inode (struct inode *);
|
||||
extern void ext2_write_inode (struct inode *, int);
|
||||
extern void ext2_put_inode (struct inode *);
|
||||
extern void ext2_delete_inode (struct inode *);
|
||||
extern int ext2_sync_inode (struct inode *);
|
||||
extern void ext2_discard_prealloc (struct inode *);
|
||||
|
||||
/* ioctl.c */
|
||||
extern int ext2_ioctl (struct inode *, struct file *, unsigned int,
|
||||
unsigned long);
|
||||
|
||||
/* namei.c */
|
||||
extern struct inode_operations ext2_dir_inode_operations;
|
||||
|
||||
/* super.c */
|
||||
extern void ext2_error (struct super_block *, const char *, const char *, ...)
|
||||
__attribute__ ((format (printf, 3, 4)));
|
||||
extern NORET_TYPE void ext2_panic (struct super_block *, const char *,
|
||||
const char *, ...)
|
||||
__attribute__ ((NORET_AND format (printf, 3, 4)));
|
||||
extern void ext2_warning (struct super_block *, const char *, const char *, ...)
|
||||
__attribute__ ((format (printf, 3, 4)));
|
||||
extern void ext2_update_dynamic_rev (struct super_block *sb);
|
||||
extern void ext2_put_super (struct super_block *);
|
||||
extern void ext2_write_super (struct super_block *);
|
||||
extern int ext2_remount (struct super_block *, int *, char *);
|
||||
extern struct super_block * ext2_read_super (struct super_block *,void *,int);
|
||||
extern int ext2_statfs (struct super_block *, struct statfs *);
|
||||
|
||||
/* truncate.c */
|
||||
extern void ext2_truncate (struct inode *);
|
||||
|
||||
/*
|
||||
* Inodes and files operations
|
||||
*/
|
||||
|
||||
/* dir.c */
|
||||
extern struct file_operations ext2_dir_operations;
|
||||
|
||||
/* file.c */
|
||||
extern struct inode_operations ext2_file_inode_operations;
|
||||
extern struct file_operations ext2_file_operations;
|
||||
|
||||
/* symlink.c */
|
||||
extern struct inode_operations ext2_fast_symlink_inode_operations;
|
||||
|
||||
extern struct address_space_operations ext2_aops;
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
#endif /* _LINUX_EXT2_FS_H */
|
42
fs/ext2_fs_i.h
Normal file
42
fs/ext2_fs_i.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* linux/include/linux/ext2_fs_i.h
|
||||
*
|
||||
* Copyright (C) 1992, 1993, 1994, 1995
|
||||
* Remy Card (card@masi.ibp.fr)
|
||||
* Laboratoire MASI - Institut Blaise Pascal
|
||||
* Universite Pierre et Marie Curie (Paris VI)
|
||||
*
|
||||
* from
|
||||
*
|
||||
* linux/include/linux/minix_fs_i.h
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_EXT2_FS_I
|
||||
#define _LINUX_EXT2_FS_I
|
||||
|
||||
/*
|
||||
* second extended file system inode data in memory
|
||||
*/
|
||||
struct ext2_inode_info {
|
||||
__u32 i_data[15];
|
||||
__u32 i_flags;
|
||||
__u32 i_faddr;
|
||||
__u8 i_frag_no;
|
||||
__u8 i_frag_size;
|
||||
__u16 i_osync;
|
||||
__u32 i_file_acl;
|
||||
__u32 i_dir_acl;
|
||||
__u32 i_dtime;
|
||||
__u32 not_used_1; /* FIX: not used/ 2.2 placeholder */
|
||||
__u32 i_block_group;
|
||||
__u32 i_next_alloc_block;
|
||||
__u32 i_next_alloc_goal;
|
||||
__u32 i_prealloc_block;
|
||||
__u32 i_prealloc_count;
|
||||
__u32 i_high_size;
|
||||
int i_new_inode:1; /* Is a freshly allocated inode */
|
||||
};
|
||||
|
||||
#endif /* _LINUX_EXT2_FS_I */
|
61
fs/ext2_fs_sb.h
Normal file
61
fs/ext2_fs_sb.h
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* linux/include/linux/ext2_fs_sb.h
|
||||
*
|
||||
* Copyright (C) 1992, 1993, 1994, 1995
|
||||
* Remy Card (card@masi.ibp.fr)
|
||||
* Laboratoire MASI - Institut Blaise Pascal
|
||||
* Universite Pierre et Marie Curie (Paris VI)
|
||||
*
|
||||
* from
|
||||
*
|
||||
* linux/include/linux/minix_fs_sb.h
|
||||
*
|
||||
* Copyright (C) 1991, 1992 Linus Torvalds
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_EXT2_FS_SB
|
||||
#define _LINUX_EXT2_FS_SB
|
||||
|
||||
/*
|
||||
* The following is not needed anymore since the descriptors buffer
|
||||
* heads are now dynamically allocated
|
||||
*/
|
||||
/* #define EXT2_MAX_GROUP_DESC 8 */
|
||||
|
||||
#define EXT2_MAX_GROUP_LOADED 8
|
||||
|
||||
/*
|
||||
* second extended-fs super-block data in memory
|
||||
*/
|
||||
struct ext2_sb_info {
|
||||
unsigned long s_frag_size; /* Size of a fragment in bytes */
|
||||
unsigned long s_frags_per_block;/* Number of fragments per block */
|
||||
unsigned long s_inodes_per_block;/* Number of inodes per block */
|
||||
unsigned long s_frags_per_group;/* Number of fragments in a group */
|
||||
unsigned long s_blocks_per_group;/* Number of blocks in a group */
|
||||
unsigned long s_inodes_per_group;/* Number of inodes in a group */
|
||||
unsigned long s_itb_per_group; /* Number of inode table blocks per group */
|
||||
unsigned long s_gdb_count; /* Number of group descriptor blocks */
|
||||
unsigned long s_desc_per_block; /* Number of group descriptors per block */
|
||||
unsigned long s_groups_count; /* Number of groups in the fs */
|
||||
struct buffer_head * s_sbh; /* Buffer containing the super block */
|
||||
struct ext2_super_block * s_es; /* Pointer to the super block in the buffer */
|
||||
struct buffer_head ** s_group_desc;
|
||||
unsigned short s_loaded_inode_bitmaps;
|
||||
unsigned short s_loaded_block_bitmaps;
|
||||
unsigned long s_inode_bitmap_number[EXT2_MAX_GROUP_LOADED];
|
||||
struct buffer_head * s_inode_bitmap[EXT2_MAX_GROUP_LOADED];
|
||||
unsigned long s_block_bitmap_number[EXT2_MAX_GROUP_LOADED];
|
||||
struct buffer_head * s_block_bitmap[EXT2_MAX_GROUP_LOADED];
|
||||
unsigned long s_mount_opt;
|
||||
uid_t s_resuid;
|
||||
gid_t s_resgid;
|
||||
unsigned short s_mount_state;
|
||||
unsigned short s_pad;
|
||||
int s_addr_per_block_bits;
|
||||
int s_desc_per_block_bits;
|
||||
int s_inode_size;
|
||||
int s_first_ino;
|
||||
};
|
||||
|
||||
#endif /* _LINUX_EXT2_FS_SB */
|
70
fs/ext2_private.h
Normal file
70
fs/ext2_private.h
Normal file
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2003 Hewlett-Packard Co.
|
||||
* Contributed by Stephane Eranian <eranian@hpl.hp.com>
|
||||
*
|
||||
* This file is part of the ELILO, the EFI Linux boot loader.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ELILO; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Please check out the elilo.txt for complete documentation on how
|
||||
* to use this program.
|
||||
*/
|
||||
|
||||
#ifndef __FS_EXT2FS_PRIVATE_H__
|
||||
#define __FS_EXT2FS_PRIVATE_H__
|
||||
|
||||
/*
|
||||
* Implement the Linux kernel internal data types
|
||||
* used by ext2
|
||||
*/
|
||||
typedef UINT32 __u32;
|
||||
typedef INT32 __s32;
|
||||
typedef UINT16 __u16;
|
||||
typedef INT16 __s16;
|
||||
typedef UINT8 __u8;
|
||||
typedef INT8 __s8;
|
||||
typedef UINT32 uid_t;
|
||||
typedef UINT32 gid_t;
|
||||
|
||||
/*
|
||||
* Get some constant from linux/stat.h
|
||||
*/
|
||||
#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)
|
||||
|
||||
|
||||
#include "fs/ext2_fs.h"
|
||||
#include "fs/ext2_fs_sb.h"
|
||||
#include "fs/ext2_fs_i.h"
|
||||
|
||||
#endif /* __FS_EXT2FS_PRIVATE_H__*/
|
1004
fs/ext2fs.c
Normal file
1004
fs/ext2fs.c
Normal file
File diff suppressed because it is too large
Load diff
63
fs/ext2fs.h
Normal file
63
fs/ext2fs.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2003 Hewlett-Packard Co.
|
||||
* Contributed by Stephane Eranian <eranian@hpl.hp.com>
|
||||
*
|
||||
* This file is part of the ELILO, the EFI Linux boot loader.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ELILO; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Please check out the elilo.txt for complete documentation on how
|
||||
* to use this program.
|
||||
*/
|
||||
#ifndef __EXT2FS_H__
|
||||
#define __EXT2FS_H__
|
||||
|
||||
INTERFACE_DECL(_ext2fs_interface_t);
|
||||
|
||||
/*
|
||||
* simplified stat structure
|
||||
* XXX: need to cleanup types !
|
||||
*/
|
||||
typedef struct {
|
||||
unsigned long st_ino;
|
||||
unsigned long st_nlink;
|
||||
unsigned int st_mode;
|
||||
unsigned int st_uid;
|
||||
unsigned int st_gid;
|
||||
unsigned long st_size;
|
||||
unsigned long st_atime;
|
||||
unsigned long st_mtime;
|
||||
unsigned long st_ctime;
|
||||
} ext2fs_stat_t;
|
||||
|
||||
|
||||
typedef struct _ext2fs_interface_t {
|
||||
EFI_STATUS (*ext2fs_name)(struct _ext2fs_interface_t *this, CHAR16 *name, UINTN maxlen);
|
||||
EFI_STATUS (*ext2fs_open)(struct _ext2fs_interface_t *this, CHAR16 *name, UINTN *fd);
|
||||
EFI_STATUS (*ext2fs_read)(struct _ext2fs_interface_t *this, UINTN fd, VOID *buf, UINTN *size);
|
||||
EFI_STATUS (*ext2fs_close)(struct _ext2fs_interface_t *this, UINTN fd);
|
||||
EFI_STATUS (*ext2fs_fstat)(struct _ext2fs_interface_t *this, UINTN fd, ext2fs_stat_t *st);
|
||||
EFI_STATUS (*ext2fs_seek)(struct _ext2fs_interface_t *this, UINTN fd, UINT64 newpos);
|
||||
} ext2fs_interface_t;
|
||||
|
||||
#define EXT2FS_PROTOCOL \
|
||||
{ 0x6ea924f6, 0xc9f2, 0x4331, {0x83, 0x54, 0x19, 0xd0, 0x17, 0x50, 0xd9, 0xc7} }
|
||||
|
||||
extern EFI_STATUS ext2fs_install(VOID);
|
||||
extern EFI_STATUS ext2fs_uninstall(VOID);
|
||||
|
||||
|
||||
#endif /* __EXT2FS_H__ */
|
297
fs/localfs.c
Normal file
297
fs/localfs.c
Normal file
|
@ -0,0 +1,297 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2003 Hewlett-Packard Co.
|
||||
* Contributed by Stephane Eranian <eranian@hpl.hp.com>
|
||||
*
|
||||
* This file is part of the ELILO, the EFI Linux boot loader.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ELILO; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Please check out the elilo.txt for complete documentation on how
|
||||
* to use this program.
|
||||
*/
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
#include "elilo.h"
|
||||
#include "fs/localfs.h"
|
||||
|
||||
/*
|
||||
* LocalFS is just a shim layer on top of the
|
||||
* FileSystem Protocol which gives access to FAT32,16,12
|
||||
*/
|
||||
#define FS_NAME L"vfat"
|
||||
|
||||
|
||||
typedef struct {
|
||||
EFI_HANDLE dev; /* device we're attached to */
|
||||
EFI_FILE_HANDLE volume; /* root of volume */
|
||||
} localfs_priv_state_t;
|
||||
|
||||
#define LOCALFS_F2FD(f) ((UINTN)(f))
|
||||
#define LOCALFS_FD2F(fd) ((EFI_FILE_HANDLE)(fd))
|
||||
|
||||
typedef union {
|
||||
localfs_interface_t pub_intf;
|
||||
struct {
|
||||
localfs_interface_t pub_intf;
|
||||
localfs_priv_state_t priv_data;
|
||||
} localfs_priv;
|
||||
} localfs_t;
|
||||
|
||||
#define FS_PRIVATE(n) (&(((localfs_t *)n)->localfs_priv.priv_data))
|
||||
|
||||
|
||||
static EFI_GUID LocalFsProtocol = LOCALFS_PROTOCOL;
|
||||
|
||||
/*
|
||||
* let's be clean here
|
||||
*/
|
||||
typedef union {
|
||||
EFI_HANDLE *dev;
|
||||
localfs_t *intf;
|
||||
} dev_tab_t;
|
||||
|
||||
static dev_tab_t *dev_tab; /* holds all devices we found */
|
||||
static UINTN ndev; /* how many entries in dev_tab */
|
||||
|
||||
static EFI_STATUS
|
||||
localfs_name(localfs_interface_t *this, CHAR16 *name, UINTN maxlen)
|
||||
{
|
||||
if (name == NULL || maxlen < 1) return EFI_INVALID_PARAMETER;
|
||||
|
||||
StrnCpy(name, FS_NAME, maxlen-1);
|
||||
|
||||
name[maxlen-1] = CHAR_NULL;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static EFI_STATUS
|
||||
localfs_open(localfs_interface_t *this, CHAR16 *name, UINTN *fd)
|
||||
{
|
||||
localfs_priv_state_t *lfs;
|
||||
EFI_STATUS status;
|
||||
EFI_FILE_HANDLE fh;
|
||||
|
||||
if (this == NULL || name == NULL || fd == NULL) return EFI_INVALID_PARAMETER;
|
||||
|
||||
lfs = FS_PRIVATE(this);
|
||||
|
||||
DBG_PRT((L"localfs_open on %s\n", name));
|
||||
|
||||
status = lfs->volume->Open(lfs->volume, &fh, name, EFI_FILE_MODE_READ, 0);
|
||||
if (status == EFI_SUCCESS) {
|
||||
*fd = LOCALFS_F2FD(fh);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
localfs_read(localfs_interface_t *this, UINTN fd, VOID *buf, UINTN *size)
|
||||
{
|
||||
localfs_priv_state_t *lfs;
|
||||
|
||||
if (this == NULL || fd == 0 || buf == NULL || size == NULL) return EFI_INVALID_PARAMETER;
|
||||
|
||||
lfs = FS_PRIVATE(this);
|
||||
|
||||
return lfs->volume->Read(LOCALFS_FD2F(fd), size, buf);
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
localfs_close(localfs_interface_t *this, UINTN fd)
|
||||
{
|
||||
localfs_priv_state_t *lfs;
|
||||
|
||||
if (this == NULL || fd == 0) return EFI_INVALID_PARAMETER;
|
||||
|
||||
lfs = FS_PRIVATE(this);
|
||||
|
||||
return lfs->volume->Close(LOCALFS_FD2F(fd));
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
localfs_infosize(localfs_interface_t *this, UINTN fd, UINT64 *sz)
|
||||
{
|
||||
localfs_priv_state_t *lfs;
|
||||
EFI_FILE_INFO *info;
|
||||
|
||||
if (this == NULL || fd == 0 || sz == NULL) return EFI_INVALID_PARAMETER;
|
||||
|
||||
lfs = FS_PRIVATE(this);
|
||||
|
||||
info = LibFileInfo(LOCALFS_FD2F(fd));
|
||||
if (info == NULL) return EFI_UNSUPPORTED;
|
||||
|
||||
*sz = info->FileSize;
|
||||
|
||||
FreePool(info);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
localfs_seek(localfs_interface_t *this, UINTN fd, UINT64 newpos)
|
||||
{
|
||||
localfs_priv_state_t *lfs;
|
||||
|
||||
if (this == NULL || fd == 0) return EFI_INVALID_PARAMETER;
|
||||
|
||||
lfs = FS_PRIVATE(this);
|
||||
|
||||
return lfs->volume->SetPosition(LOCALFS_FD2F(fd), newpos);
|
||||
}
|
||||
|
||||
static VOID
|
||||
localfs_init_state(localfs_t *localfs, EFI_HANDLE dev, EFI_FILE_HANDLE volume)
|
||||
{
|
||||
localfs_priv_state_t *lfs = FS_PRIVATE(localfs);
|
||||
|
||||
/* need to do some init here on localfs_intf */
|
||||
Memset(localfs, 0, sizeof(*localfs));
|
||||
|
||||
localfs->pub_intf.localfs_name = localfs_name;
|
||||
localfs->pub_intf.localfs_open = localfs_open;
|
||||
localfs->pub_intf.localfs_read = localfs_read;
|
||||
localfs->pub_intf.localfs_close = localfs_close;
|
||||
localfs->pub_intf.localfs_infosize = localfs_infosize;
|
||||
localfs->pub_intf.localfs_seek = localfs_seek;
|
||||
|
||||
lfs->dev = dev;
|
||||
lfs->volume = volume;
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
localfs_install_one(EFI_HANDLE dev, VOID **intf)
|
||||
{
|
||||
|
||||
EFI_STATUS status;
|
||||
localfs_t *localfs;
|
||||
EFI_FILE_IO_INTERFACE *volume;
|
||||
EFI_FILE_HANDLE volume_fh;
|
||||
|
||||
status = BS->HandleProtocol (dev, &LocalFsProtocol, (VOID **)&localfs);
|
||||
if (status == EFI_SUCCESS) {
|
||||
ERR_PRT((L"Warning: found existing %s protocol on device", FS_NAME));
|
||||
goto found;
|
||||
}
|
||||
|
||||
status = BS->HandleProtocol (dev, &FileSystemProtocol, (VOID **)&volume);
|
||||
if (EFI_ERROR(status)) return EFI_INVALID_PARAMETER;
|
||||
|
||||
status = volume->OpenVolume(volume, &volume_fh);
|
||||
if (EFI_ERROR(status)) {
|
||||
ERR_PRT((L"cannot open volume"));
|
||||
return status;
|
||||
}
|
||||
|
||||
localfs = (localfs_t *)alloc(sizeof(*localfs), EfiLoaderData);
|
||||
if (localfs == NULL) {
|
||||
ERR_PRT((L"failed to allocate %s", FS_NAME));
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
localfs_init_state(localfs, dev, volume_fh);
|
||||
|
||||
status = LibInstallProtocolInterfaces(&dev, &LocalFsProtocol, localfs, NULL);
|
||||
if (EFI_ERROR(status)) {
|
||||
ERR_PRT((L"Cannot install %s protocol: %r", FS_NAME, status));
|
||||
free(localfs);
|
||||
return status;
|
||||
}
|
||||
found:
|
||||
if (intf) *intf = (VOID *)localfs;
|
||||
|
||||
VERB_PRT(3,
|
||||
{ EFI_DEVICE_PATH *dp; CHAR16 *str;
|
||||
dp = DevicePathFromHandle(dev);
|
||||
str = DevicePathToStr(dp);
|
||||
Print(L"attached %s to %s\n", FS_NAME, str);
|
||||
FreePool(str);
|
||||
});
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
localfs_install(VOID)
|
||||
{
|
||||
UINTN size = 0;
|
||||
UINTN i;
|
||||
EFI_STATUS status;
|
||||
VOID *intf;
|
||||
|
||||
BS->LocateHandle(ByProtocol, &FileSystemProtocol, NULL, &size, NULL);
|
||||
if (size == 0) return EFI_UNSUPPORTED; /* no device found, oh well */
|
||||
|
||||
DBG_PRT((L"size=%d", size));
|
||||
|
||||
dev_tab = (dev_tab_t *)alloc(size, EfiLoaderData);
|
||||
if (dev_tab == NULL) {
|
||||
ERR_PRT((L"failed to allocate handle table"));
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
status = BS->LocateHandle(ByProtocol, &FileSystemProtocol, NULL, &size, (VOID **)dev_tab);
|
||||
if (status != EFI_SUCCESS) {
|
||||
ERR_PRT((L"failed to get handles: %r", status));
|
||||
free(dev_tab);
|
||||
return status;
|
||||
}
|
||||
ndev = size / sizeof(EFI_HANDLE);
|
||||
|
||||
for(i=0; i < ndev; i++) {
|
||||
intf = NULL;
|
||||
localfs_install_one(dev_tab[i].dev, &intf);
|
||||
/* override device handle with interface pointer */
|
||||
dev_tab[i].intf = intf;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
localfs_uninstall(VOID)
|
||||
{
|
||||
|
||||
localfs_priv_state_t *lfs;
|
||||
EFI_STATUS status;
|
||||
UINTN i;
|
||||
|
||||
for(i=0; i < ndev; i++) {
|
||||
if (dev_tab[i].intf == NULL) continue;
|
||||
lfs = FS_PRIVATE(dev_tab[i].intf);
|
||||
status = BS->UninstallProtocolInterface(lfs->dev, &LocalFsProtocol, dev_tab[i].intf);
|
||||
if (EFI_ERROR(status)) {
|
||||
ERR_PRT((L"Uninstall %s error: %r", FS_NAME, status));
|
||||
continue;
|
||||
}
|
||||
VERB_PRT(3,
|
||||
{ EFI_DEVICE_PATH *dp; CHAR16 *str;
|
||||
dp = DevicePathFromHandle(lfs->dev);
|
||||
str = DevicePathToStr(dp);
|
||||
Print(L"uninstalled %s on %s\n", FS_NAME, str);
|
||||
FreePool(str);
|
||||
});
|
||||
free(dev_tab[i].intf);
|
||||
}
|
||||
if (dev_tab) free(dev_tab);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
|
46
fs/localfs.h
Normal file
46
fs/localfs.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2003 Hewlett-Packard Co.
|
||||
* Contributed by Stephane Eranian <eranian@hpl.hp.com>
|
||||
*
|
||||
* This file is part of the ELILO, the EFI Linux boot loader.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ELILO; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Please check out the elilo.txt for complete documentation on how
|
||||
* to use this program.
|
||||
*/
|
||||
|
||||
#ifndef __LOCALFS_H__
|
||||
#define __LOCALFS_H__
|
||||
|
||||
INTERFACE_DECL(_localfs_interface_t);
|
||||
|
||||
typedef struct _localfs_interface_t {
|
||||
EFI_STATUS (*localfs_name)(struct _localfs_interface_t *this, CHAR16 *name, UINTN maxlen);
|
||||
EFI_STATUS (*localfs_open)(struct _localfs_interface_t *this, CHAR16 *name, UINTN *fd);
|
||||
EFI_STATUS (*localfs_read)(struct _localfs_interface_t *this, UINTN fd, VOID *buf, UINTN *size);
|
||||
EFI_STATUS (*localfs_close)(struct _localfs_interface_t *this, UINTN fd);
|
||||
EFI_STATUS (*localfs_infosize)(struct _localfs_interface_t *this, UINTN fd, UINT64 *size);
|
||||
EFI_STATUS (*localfs_seek)(struct _localfs_interface_t *this, UINTN fd, UINT64 newpos);
|
||||
} localfs_interface_t;
|
||||
|
||||
#define LOCALFS_PROTOCOL \
|
||||
{ 0x3a42ff5d, 0x43c9, 0x4db8, {0x82, 0x4e, 0xb8, 0x5b, 0xab, 0x97, 0x63, 0xcc} }
|
||||
|
||||
extern EFI_STATUS localfs_install(VOID);
|
||||
extern EFI_STATUS localfs_uninstall(VOID);
|
||||
|
||||
#endif /* __LOCALFS_H__ */
|
790
fs/netfs.c
Normal file
790
fs/netfs.c
Normal file
|
@ -0,0 +1,790 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2003 Hewlett-Packard Co.
|
||||
* Contributed by Stephane Eranian <eranian@hpl.hp.com>
|
||||
*
|
||||
* This file is part of the ELILO, the EFI Linux boot loader.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ELILO; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Please check out the elilo.txt for complete documentation on how
|
||||
* to use this program.
|
||||
*/
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
#include "fs/netfs.h"
|
||||
|
||||
#include "elilo.h"
|
||||
|
||||
#define FS_NAME L"netfs"
|
||||
|
||||
#define NETFS_DEFAULT_BUFSIZE 16*MB
|
||||
#define NETFS_DEFAULT_BUFSIZE_INC 8*MB
|
||||
|
||||
#define NETFS_DEFAULT_SERVER_TYPE EFI_PXE_BASE_CODE_BOOT_TYPE_BOOTSTRAP
|
||||
#define NETFS_FD_MAX 2
|
||||
|
||||
typedef struct _netfs_fd {
|
||||
struct _netfs_fd *next;
|
||||
|
||||
CHAR8 *netbuf;
|
||||
UINT64 netbuf_maxsize; /* currently allocated buffer */
|
||||
UINTN netbuf_size; /* number of bytes currently used in the buffer */
|
||||
UINT64 netbuf_pos; /* current position in the buffer */
|
||||
BOOLEAN is_valid; /* avoid conflicting opens */
|
||||
BOOLEAN netbuf_reuse;
|
||||
|
||||
CHAR16 last_file[FILENAME_MAXLEN];
|
||||
} netfs_fd_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
EFI_PXE_BASE_CODE *pxe;
|
||||
EFI_HANDLE dev; /* handle to device we're attached to */
|
||||
BOOLEAN using_pxe; /* true if downloaded using the PXE protocol vs. regular DHCP */
|
||||
|
||||
EFI_IP_ADDRESS srv_ip;
|
||||
EFI_IP_ADDRESS cln_ip;
|
||||
EFI_IP_ADDRESS gw_ip;
|
||||
EFI_IP_ADDRESS netmask;
|
||||
UINT8 hw_addr[16];
|
||||
|
||||
netfs_fd_t fd_tab[NETFS_FD_MAX];
|
||||
netfs_fd_t *free_fd;
|
||||
UINTN free_fd_count;
|
||||
|
||||
} netfs_priv_state_t;
|
||||
|
||||
#define NETFS_F2FD(l,f) (UINTN)((f)-(l)->fd_tab)
|
||||
#define NETFS_FD2F(l,fd) ((l)->fd_tab+fd)
|
||||
#define NETFS_F_INVALID(f) ((f)->is_valid == FALSE)
|
||||
|
||||
|
||||
typedef union {
|
||||
netfs_interface_t pub_intf;
|
||||
struct {
|
||||
netfs_interface_t pub_intf;
|
||||
netfs_priv_state_t priv_data;
|
||||
} netfs_priv;
|
||||
} netfs_t;
|
||||
|
||||
#define FS_PRIVATE(n) (&(((netfs_t *)n)->netfs_priv.priv_data))
|
||||
|
||||
typedef union {
|
||||
EFI_HANDLE *dev;
|
||||
netfs_t *intf;
|
||||
} dev_tab_t;
|
||||
|
||||
static dev_tab_t *dev_tab; /* holds all devices we found */
|
||||
static UINTN ndev; /* how many entries in dev_tab */
|
||||
|
||||
static EFI_GUID NetFsProtocol = NETFS_PROTOCOL;
|
||||
|
||||
|
||||
#if 0
|
||||
static EFI_PXE_BASE_CODE_CALLBACK_STATUS
|
||||
netfs_callback_func(
|
||||
IN EFI_PXE_BASE_CODE_CALLBACK *this,
|
||||
IN EFI_PXE_BASE_CODE_FUNCTION function,
|
||||
IN BOOLEAN received,
|
||||
IN UINT32 packet_len,
|
||||
IN EFI_PXE_BASE_CODE_PACKET *packet OPTIONAL
|
||||
)
|
||||
{
|
||||
Print(L"netfs_callback called received=%d packet_len=%d\n", received, packet_len);
|
||||
return EFI_ABORTED;
|
||||
}
|
||||
|
||||
static EFI_PXE_BASE_CODE_CALLBACK netfs_callback = {
|
||||
EFI_PXE_BASE_CODE_CALLBACK_INTERFACE_REVISION,
|
||||
&netfs_callback_func
|
||||
};
|
||||
#endif
|
||||
|
||||
static netfs_fd_t *
|
||||
netfs_fd_alloc(netfs_priv_state_t *nfs, CHAR16 *name)
|
||||
{
|
||||
netfs_fd_t *tmp = NULL, *prev = NULL, *match;
|
||||
UINT8 netbuf_reuse = 0;
|
||||
|
||||
if (nfs->free_fd == NULL) {
|
||||
ERR_PRT((L"out of file descriptor"));
|
||||
return NULL;
|
||||
}
|
||||
match = nfs->free_fd;
|
||||
for (tmp = nfs->free_fd; tmp; tmp = tmp->next) {
|
||||
if (!StrCmp(name, tmp->last_file)) {
|
||||
DBG_PRT((L"Using cached file %s netbuf_size=%d", tmp->last_file, tmp->netbuf_size));
|
||||
netbuf_reuse = 1;
|
||||
match = tmp;
|
||||
break;
|
||||
}
|
||||
prev = tmp;
|
||||
}
|
||||
/* indicate whether or not we got a match in caching */
|
||||
match->netbuf_reuse = netbuf_reuse;
|
||||
|
||||
if (match == nfs->free_fd)
|
||||
nfs->free_fd = match->next;
|
||||
else
|
||||
prev->next = match->next;
|
||||
|
||||
nfs->free_fd_count--;
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
static VOID
|
||||
netfs_fd_free(netfs_priv_state_t *nfs, netfs_fd_t *f)
|
||||
{
|
||||
if (f == NULL) {
|
||||
ERR_PRT((L"invalid fd"));
|
||||
return;
|
||||
}
|
||||
f->next = nfs->free_fd;
|
||||
|
||||
/* we keep the netbuf, in case we can reuse it */
|
||||
f->is_valid = FALSE;
|
||||
|
||||
nfs->free_fd = f;
|
||||
nfs->free_fd_count++;
|
||||
|
||||
if (nfs->free_fd_count > NETFS_FD_MAX) {
|
||||
ERR_PRT((L"too many free descriptors %d", nfs->free_fd_count));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static INTN
|
||||
netbuf_alloc(netfs_fd_t *f)
|
||||
{
|
||||
/* we will try to reuse the existing buffer first */
|
||||
if (f->netbuf != 0) return 0;
|
||||
|
||||
f->netbuf_pos = 0;
|
||||
|
||||
f->netbuf = (CHAR8 *)alloc_pages(EFI_SIZE_TO_PAGES(f->netbuf_maxsize), EfiLoaderData, AllocateAnyPages, 0);
|
||||
|
||||
return f->netbuf == 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
netfs_name(netfs_interface_t *this, CHAR16 *name, UINTN maxlen)
|
||||
{
|
||||
if (name == NULL || maxlen < 1) return EFI_INVALID_PARAMETER;
|
||||
|
||||
StrnCpy(name, FS_NAME, maxlen-1);
|
||||
|
||||
name[maxlen-1] = CHAR_NULL;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static VOID
|
||||
netfs_extract_ip(netfs_priv_state_t *nfs)
|
||||
{
|
||||
EFI_PXE_BASE_CODE *pxe = nfs->pxe;
|
||||
|
||||
if (pxe->Mode->PxeDiscoverValid) {
|
||||
nfs->using_pxe = TRUE;
|
||||
Memcpy(&nfs->srv_ip, pxe->Mode->PxeReply.Dhcpv4.BootpSiAddr, sizeof(EFI_IP_ADDRESS));
|
||||
Memcpy(&nfs->hw_addr, pxe->Mode->PxeReply.Dhcpv4.BootpHwAddr, 16*sizeof(UINT8));
|
||||
} else {
|
||||
Memcpy(&nfs->srv_ip, pxe->Mode->DhcpAck.Dhcpv4.BootpSiAddr, sizeof(EFI_IP_ADDRESS));
|
||||
Memcpy(&nfs->hw_addr, pxe->Mode->DhcpAck.Dhcpv4.BootpHwAddr, sizeof(nfs->hw_addr));
|
||||
}
|
||||
|
||||
Memcpy(&nfs->cln_ip, &pxe->Mode->StationIp, sizeof(EFI_IP_ADDRESS));
|
||||
Memcpy(&nfs->netmask, &pxe->Mode->SubnetMask, sizeof(EFI_IP_ADDRESS));
|
||||
|
||||
/*
|
||||
* the fact that we use index 0, is just a guess
|
||||
*/
|
||||
if (pxe->Mode->RouteTableEntries>0)
|
||||
Memcpy(&nfs->gw_ip, &pxe->Mode->RouteTable[0].GwAddr, sizeof(EFI_IP_ADDRESS));
|
||||
|
||||
VERB_PRT(1, Print(L"PXE PxeDiscoverValid: %s\n", pxe->Mode->PxeDiscoverValid? L"Yes (PXE-aware DHCPD)" : L"No (Regular DHCPD)"));
|
||||
#if 0
|
||||
status = BS->HandleProtocol(dev, &PxeCallbackProtocol, (VOID **)&netfs_callback);
|
||||
status = LibInstallProtocolInterfaces(&dev, &PxeCallbackProtocol, &netfs_callback, NULL);
|
||||
Print(L"PXE Callback support : %r\n", status);
|
||||
if (status == EFI_SUCCESS) {
|
||||
BOOLEAN doit = TRUE;
|
||||
status = pxe->SetParameters(pxe, NULL, NULL, NULL, NULL, &doit);
|
||||
Print(L"PXE Callback SetParameters: %r\n", status);
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
* XXX: TFTPD server not quite right when using PXE, need to extract bootservers...
|
||||
*/
|
||||
VERB_PRT(1, Print(L"Local IP: %d.%d.%d.%d\n",
|
||||
pxe->Mode->StationIp.v4.Addr[0] & 0xff,
|
||||
pxe->Mode->StationIp.v4.Addr[1] & 0xff,
|
||||
pxe->Mode->StationIp.v4.Addr[2] & 0xff,
|
||||
pxe->Mode->StationIp.v4.Addr[3] & 0xff));
|
||||
|
||||
VERB_PRT(1, Print(L"SM: %d.%d.%d.%d\n",
|
||||
pxe->Mode->SubnetMask.v4.Addr[0] & 0xff,
|
||||
pxe->Mode->SubnetMask.v4.Addr[1] & 0xff,
|
||||
pxe->Mode->SubnetMask.v4.Addr[2] & 0xff,
|
||||
pxe->Mode->SubnetMask.v4.Addr[3] & 0xff));
|
||||
|
||||
VERB_PRT(1, Print(L"TFTPD IP: %d.%d.%d.%d\n",
|
||||
nfs->srv_ip.v4.Addr[0] & 0xff,
|
||||
nfs->srv_ip.v4.Addr[1] & 0xff,
|
||||
nfs->srv_ip.v4.Addr[2] & 0xff,
|
||||
nfs->srv_ip.v4.Addr[3] & 0xff));
|
||||
|
||||
VERB_PRT(1, Print(L"Gateway IP: %d.%d.%d.%d\n",
|
||||
nfs->gw_ip.v4.Addr[0] & 0xff,
|
||||
nfs->gw_ip.v4.Addr[1] & 0xff,
|
||||
nfs->gw_ip.v4.Addr[2] & 0xff,
|
||||
nfs->gw_ip.v4.Addr[3] & 0xff));
|
||||
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
netfs_start(EFI_PXE_BASE_CODE *pxe)
|
||||
{
|
||||
EFI_STATUS status;
|
||||
|
||||
status = pxe->Start(pxe, FALSE);
|
||||
if (EFI_ERROR(status)) return status;
|
||||
|
||||
return pxe->Dhcp(pxe, FALSE);
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
netfs_open(netfs_interface_t *this, CHAR16 *name, UINTN *fd)
|
||||
{
|
||||
netfs_priv_state_t *nfs;
|
||||
netfs_fd_t *f;
|
||||
EFI_STATUS status;
|
||||
CHAR8 ascii_name[FILENAME_MAXLEN];
|
||||
UINTN blocksize = 0, prev_netbufsize;
|
||||
|
||||
if (this == NULL || name == NULL || fd == NULL) return EFI_INVALID_PARAMETER;
|
||||
|
||||
nfs = FS_PRIVATE(this);
|
||||
|
||||
if (nfs->pxe == NULL) return EFI_INVALID_PARAMETER;
|
||||
|
||||
/*
|
||||
* Try to start protocol if not already active
|
||||
*/
|
||||
if (nfs->pxe->Mode->Started == FALSE) {
|
||||
status = netfs_start(nfs->pxe);
|
||||
if (EFI_ERROR(status)) return status;
|
||||
netfs_extract_ip(nfs);
|
||||
}
|
||||
|
||||
if ((f=netfs_fd_alloc(nfs, name)) == NULL) return EFI_OUT_OF_RESOURCES;
|
||||
|
||||
if (f->netbuf_reuse) {
|
||||
f->netbuf_pos = 0;
|
||||
f->is_valid = TRUE;
|
||||
*fd = NETFS_F2FD(nfs, f);
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
f->netbuf_maxsize = NETFS_DEFAULT_BUFSIZE;
|
||||
|
||||
if (f->netbuf == NULL && netbuf_alloc(f) == -1) {
|
||||
netfs_fd_free(nfs, f);
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
/* well, we need to download ! */
|
||||
|
||||
U2ascii(name, ascii_name, FILENAME_MAXLEN);
|
||||
|
||||
VERB_PRT(2, Print(L"downloading %a from %d.%d.%d.%d...", ascii_name,
|
||||
nfs->srv_ip.v4.Addr[0],
|
||||
nfs->srv_ip.v4.Addr[1],
|
||||
nfs->srv_ip.v4.Addr[2],
|
||||
nfs->srv_ip.v4.Addr[3]));
|
||||
retry:
|
||||
f->netbuf_size = f->netbuf_maxsize;
|
||||
|
||||
DBG_PRT((L"\nbefore netbuf:0x%lx netbuf_size=%ld\n", f->netbuf, f->netbuf_size));
|
||||
|
||||
/*
|
||||
* For EFI versions older than 14.61:
|
||||
* it seems like there is an EFI bug (or undocumented behavior) when the buffer size
|
||||
* is too small AND the blocksize parameter is NULL, i.e., used the largest possible.
|
||||
* In this case, Mtftp() never returns EFI_BUFFER_TOO_SMALL but EFI_TIMEOUT instead.
|
||||
* This is true for 1.02 and also 1.10 it seems. Here we set it to the minimal value (512).
|
||||
*
|
||||
* Also it seems like on a READ_FILE which returns EFI_BUFFER_TOO_SMALL, the buffersize
|
||||
* is NOT updated to reflect the required size for the next attempt.
|
||||
*
|
||||
* For EFI versions 14.61 and higher:
|
||||
* In case the buffer is too small AND the TFTP server reports the file size (see RFC 2349),
|
||||
* the f->netbuf_size will report the exact size for the buffer.
|
||||
*/
|
||||
prev_netbufsize = f->netbuf_size;
|
||||
|
||||
status = nfs->pxe->Mtftp(nfs->pxe, EFI_PXE_BASE_CODE_TFTP_READ_FILE, f->netbuf, FALSE,
|
||||
&(f->netbuf_size),
|
||||
blocksize > 0 ? &blocksize : NULL,
|
||||
&nfs->srv_ip,
|
||||
ascii_name,
|
||||
NULL,
|
||||
FALSE);
|
||||
|
||||
DBG_PRT((L"after Mftp=%r netbuf:0x%lx netbuf_size=%ld blocksize=%ld\n",
|
||||
status,
|
||||
f->netbuf,
|
||||
f->netbuf_size,
|
||||
blocksize));
|
||||
|
||||
if (status == EFI_TIMEOUT && blocksize == 0) {
|
||||
/*
|
||||
* XXX: if blocksize is not adjusted we could loop forever here
|
||||
*/
|
||||
//blocksize = 512;
|
||||
status = EFI_BUFFER_TOO_SMALL;
|
||||
}
|
||||
/*
|
||||
* check if we need to increase our buffer size
|
||||
*/
|
||||
if (status == EFI_BUFFER_TOO_SMALL) {
|
||||
DBG_PRT((L"buffer too small, need netbuf_size=%d", f->netbuf_size));
|
||||
/*
|
||||
* if the TFTP server supports TFTP options, then we should
|
||||
* get the required size. So we test to see if the size
|
||||
* we set has changed. If so, we got the required size.
|
||||
* If not, we increase the buffer size and retry.
|
||||
*/
|
||||
if (f->netbuf_size == prev_netbufsize) {
|
||||
f->netbuf_maxsize += NETFS_DEFAULT_BUFSIZE_INC;
|
||||
} else {
|
||||
/* we got an answer from the TFTP server, let's try it */
|
||||
f->netbuf_maxsize = f->netbuf_size;
|
||||
}
|
||||
free(f->netbuf);
|
||||
|
||||
f->netbuf = NULL; /* will force reallocation */
|
||||
|
||||
if (netbuf_alloc(f) == 0) goto retry;
|
||||
|
||||
/* fall through in case of error */
|
||||
}
|
||||
|
||||
if (status == EFI_SUCCESS) {
|
||||
/* start at the beginning of the file */
|
||||
f->netbuf_pos = 0;
|
||||
|
||||
/* cache file name */
|
||||
StrCpy(f->last_file, name);
|
||||
|
||||
f->is_valid = 1;
|
||||
|
||||
*fd = NETFS_F2FD(nfs, f);
|
||||
VERB_PRT(2, Print(L"Done\n"));
|
||||
} else {
|
||||
netfs_fd_free(nfs, f);
|
||||
VERB_PRT(2, Print(L"Failed: %r\n", status));
|
||||
}
|
||||
DBG_PRT((L"File %s netbuf_size=%d: %r", name, f->netbuf_size, status));
|
||||
#if 0
|
||||
Print(L"\n---\n");
|
||||
{ INTN i;
|
||||
for(i=0; i < netbuf_size; i++) {
|
||||
Print(L"%c", (CHAR16)netbuf[i]);
|
||||
}
|
||||
}
|
||||
Print(L"\n---\n");
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
static EFI_STATUS
|
||||
netfs_read(netfs_interface_t *this, UINTN fd, VOID *buf, UINTN *size)
|
||||
{
|
||||
netfs_priv_state_t *nfs;
|
||||
netfs_fd_t *f;
|
||||
UINTN count;
|
||||
|
||||
if (this == NULL || fd >= NETFS_FD_MAX || buf == NULL || size == NULL) return EFI_INVALID_PARAMETER;
|
||||
|
||||
nfs = FS_PRIVATE(this);
|
||||
f = NETFS_FD2F(nfs, fd);
|
||||
|
||||
if (NETFS_F_INVALID(f)) return EFI_INVALID_PARAMETER;
|
||||
|
||||
count = MIN(*size, f->netbuf_size - f->netbuf_pos);
|
||||
|
||||
if (count) Memcpy(buf, f->netbuf+f->netbuf_pos, count);
|
||||
|
||||
*size = count;
|
||||
f->netbuf_pos += count;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
netfs_close(netfs_interface_t *this, UINTN fd)
|
||||
{
|
||||
netfs_priv_state_t *nfs;
|
||||
netfs_fd_t *f;
|
||||
|
||||
if (this == NULL || fd >= NETFS_FD_MAX) return EFI_INVALID_PARAMETER;
|
||||
|
||||
nfs = FS_PRIVATE(this);
|
||||
f = NETFS_FD2F(nfs, fd);
|
||||
|
||||
if (NETFS_F_INVALID(f)) return EFI_INVALID_PARAMETER;
|
||||
|
||||
netfs_fd_free(nfs, f);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
netfs_seek(netfs_interface_t *this, UINTN fd, UINT64 newpos)
|
||||
{
|
||||
netfs_priv_state_t *nfs;
|
||||
netfs_fd_t *f;
|
||||
|
||||
if (this == NULL || fd >= NETFS_FD_MAX) return EFI_INVALID_PARAMETER;
|
||||
|
||||
nfs = FS_PRIVATE(this);
|
||||
f = NETFS_FD2F(nfs, fd);
|
||||
|
||||
if (NETFS_F_INVALID(f)) return EFI_INVALID_PARAMETER;
|
||||
|
||||
if (newpos > f->netbuf_size) return EFI_INVALID_PARAMETER;
|
||||
|
||||
f->netbuf_pos = newpos;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
netfs_infosize(netfs_interface_t *this, UINTN fd, UINT64 *sz)
|
||||
{
|
||||
netfs_priv_state_t *nfs;
|
||||
netfs_fd_t *f;
|
||||
|
||||
if (this == NULL || fd >= NETFS_FD_MAX || sz == NULL) return EFI_INVALID_PARAMETER;
|
||||
|
||||
nfs = FS_PRIVATE(this);
|
||||
f = NETFS_FD2F(nfs, fd);
|
||||
|
||||
if (NETFS_F_INVALID(f)) return EFI_INVALID_PARAMETER;
|
||||
|
||||
*sz = f->netbuf_size;
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static INTN
|
||||
find_dhcp_option(EFI_PXE_BASE_CODE_PACKET *packet, UINT8 use_ipv6, UINT8 option, CHAR8 *str, INTN *len)
|
||||
{
|
||||
INTN i = 0;
|
||||
UINT8 tag, length;
|
||||
UINT8 *opts = packet->Dhcpv4.DhcpOptions;
|
||||
|
||||
*len = 0;
|
||||
|
||||
for(;;) {
|
||||
if (i >= 56) {
|
||||
DBG_PRT((L"reach end of options (no marker)\n"));
|
||||
break;
|
||||
}
|
||||
tag = opts[i++];
|
||||
|
||||
if (tag == 0) continue;
|
||||
if (tag == 255) break;
|
||||
|
||||
length = opts[i++];
|
||||
|
||||
#if 0
|
||||
{ UINT8 l = length, k = 0;
|
||||
Print(L"found option %d len=%d: ", tag, length);
|
||||
while (l--) { Print(L"%c(%d)\n", (CHAR16)opts[k], opts[k]); k++; }
|
||||
Print(L"\n");
|
||||
}
|
||||
#endif
|
||||
if (tag == option) {
|
||||
*len = length;
|
||||
while (length--) { *str++ = opts[i++]; }
|
||||
return 0;
|
||||
}
|
||||
i += length;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
netfs_getinfo(netfs_interface_t *this, netfs_info_t *info)
|
||||
{
|
||||
netfs_priv_state_t *nfs;
|
||||
CHAR8 str[256];
|
||||
INTN len, r;
|
||||
|
||||
if (this == NULL || info == NULL) return EFI_INVALID_PARAMETER;
|
||||
|
||||
nfs = FS_PRIVATE(this);
|
||||
|
||||
Memcpy(&info->cln_ipaddr, &nfs->cln_ip, sizeof(EFI_IP_ADDRESS));
|
||||
Memcpy(&info->srv_ipaddr, &nfs->srv_ip, sizeof(EFI_IP_ADDRESS));
|
||||
Memcpy(&info->netmask, &nfs->netmask, sizeof(EFI_IP_ADDRESS));
|
||||
Memcpy(&info->gw_ipaddr, &nfs->gw_ip, sizeof(EFI_IP_ADDRESS));
|
||||
Memcpy(&info->hw_addr, &nfs->hw_addr, sizeof(info->hw_addr));
|
||||
|
||||
info->using_pxe = nfs->using_pxe;
|
||||
info->started = nfs->pxe->Mode->Started;
|
||||
info->using_ipv6 = nfs->pxe->Mode->UsingIpv6;
|
||||
|
||||
if (nfs->pxe->Mode->UsingIpv6) goto skip_options;
|
||||
|
||||
r = find_dhcp_option(&nfs->pxe->Mode->DhcpAck,nfs->pxe->Mode->UsingIpv6, 15, str, &len);
|
||||
str[len] = '\0';
|
||||
ascii2U(str, info->domainame, 255);
|
||||
|
||||
VERB_PRT(3, Print(L"domain(15): %a\n", str));
|
||||
|
||||
r = find_dhcp_option(&nfs->pxe->Mode->DhcpAck,nfs->pxe->Mode->UsingIpv6, 12, str, &len);
|
||||
str[len] = '\0';
|
||||
ascii2U(str, info->hostname, 255);
|
||||
|
||||
VERB_PRT(3, Print(L"hostname(12): %a\n", str));
|
||||
|
||||
/*
|
||||
* extract bootfile name from DHCP exchanges
|
||||
*/
|
||||
if (nfs->using_pxe == 0) {
|
||||
ascii2U(nfs->pxe->Mode->DhcpAck.Dhcpv4.BootpBootFile, info->bootfile, NETFS_BOOTFILE_MAXLEN);
|
||||
VERB_PRT(3, Print(L"bootfile: %s\n", info->bootfile));
|
||||
}
|
||||
|
||||
skip_options:
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
static UINT16
|
||||
find_pxe_server_type(EFI_PXE_BASE_CODE *pxe)
|
||||
{
|
||||
INTN i = 0, max;
|
||||
UINT8 tag, length;
|
||||
UINT8 *opts = pxe->Mode->PxeReply.Dhcpv4.DhcpOptions;
|
||||
UINT16 server_type;
|
||||
|
||||
while(i < 55) {
|
||||
tag = opts[i];
|
||||
length = opts[i+1];
|
||||
|
||||
DBG_PRT((L"Tag #%d Length %d\n",tag, length));
|
||||
|
||||
if (tag == 43) goto found;
|
||||
|
||||
i += 2 + length;
|
||||
}
|
||||
return NETFS_DEFAULT_SERVER_TYPE;
|
||||
found:
|
||||
max = i+2+length;
|
||||
i += 2;
|
||||
while (i < max) {
|
||||
tag = opts[i];
|
||||
length = opts[i+1];
|
||||
if (tag == 71) {
|
||||
server_type =(opts[i+2]<<8) | opts[i+3];
|
||||
DBG_PRT((L"ServerType: %d\n", server_type));
|
||||
return server_type;
|
||||
}
|
||||
i+= 2 + length;
|
||||
}
|
||||
return NETFS_DEFAULT_SERVER_TYPE;
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
netfs_query_layer(netfs_interface_t *this, UINT16 server_type, UINT16 layer, UINTN maxlen, CHAR16 *str)
|
||||
{
|
||||
netfs_priv_state_t *nfs;
|
||||
EFI_STATUS status;
|
||||
|
||||
if (this == NULL || str == NULL) return EFI_INVALID_PARAMETER;
|
||||
|
||||
nfs = FS_PRIVATE(this);
|
||||
|
||||
if (nfs->using_pxe == FALSE) return EFI_UNSUPPORTED;
|
||||
|
||||
if (server_type == 0) server_type = find_pxe_server_type(nfs->pxe);
|
||||
|
||||
status = nfs->pxe->Discover(nfs->pxe, server_type, &layer, FALSE, 0);
|
||||
if(status == EFI_SUCCESS) {
|
||||
ascii2U(nfs->pxe->Mode->PxeReply.Dhcpv4.BootpBootFile, str, maxlen);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static VOID
|
||||
netfs_init_state(netfs_t *netfs, EFI_HANDLE dev, EFI_PXE_BASE_CODE *pxe)
|
||||
{
|
||||
netfs_priv_state_t *nfs = FS_PRIVATE(netfs);
|
||||
UINTN i;
|
||||
|
||||
/* need to do some init here on netfs_intf */
|
||||
Memset(netfs, 0, sizeof(*netfs));
|
||||
|
||||
|
||||
netfs->pub_intf.netfs_name = netfs_name;
|
||||
netfs->pub_intf.netfs_open = netfs_open;
|
||||
netfs->pub_intf.netfs_read = netfs_read;
|
||||
netfs->pub_intf.netfs_close = netfs_close;
|
||||
netfs->pub_intf.netfs_infosize = netfs_infosize;
|
||||
netfs->pub_intf.netfs_seek = netfs_seek;
|
||||
netfs->pub_intf.netfs_query_layer = netfs_query_layer;
|
||||
netfs->pub_intf.netfs_getinfo = netfs_getinfo;
|
||||
|
||||
nfs->dev = dev;
|
||||
nfs->pxe = pxe;
|
||||
|
||||
/*
|
||||
* we defer DHCP request until it is really necessary (netfs_open)
|
||||
*/
|
||||
if (pxe->Mode->Started == TRUE) netfs_extract_ip(nfs);
|
||||
|
||||
Memset(nfs->fd_tab, 0, sizeof(nfs->fd_tab));
|
||||
|
||||
for (i=0; i < NETFS_FD_MAX-1; i++) {
|
||||
nfs->fd_tab[i].next = &nfs->fd_tab[i+1];
|
||||
}
|
||||
/* null on last element is done by memset */
|
||||
|
||||
nfs->free_fd = nfs->fd_tab;
|
||||
nfs->free_fd_count = NETFS_FD_MAX;
|
||||
}
|
||||
|
||||
static EFI_STATUS
|
||||
netfs_install_one(EFI_HANDLE dev, VOID **intf)
|
||||
{
|
||||
|
||||
EFI_STATUS status;
|
||||
netfs_t *netfs;
|
||||
EFI_PXE_BASE_CODE *pxe;
|
||||
|
||||
status = BS->HandleProtocol (dev, &NetFsProtocol, (VOID **)&netfs);
|
||||
if (status == EFI_SUCCESS) {
|
||||
ERR_PRT((L"Warning: found existing %s protocol on device", FS_NAME));
|
||||
goto found;
|
||||
}
|
||||
|
||||
status = BS->HandleProtocol (dev, &PxeBaseCodeProtocol, (VOID **)&pxe);
|
||||
if (EFI_ERROR(status)) return EFI_INVALID_PARAMETER;
|
||||
|
||||
|
||||
netfs = (netfs_t *)alloc(sizeof(*netfs), EfiLoaderData);
|
||||
if (netfs == NULL) {
|
||||
ERR_PRT((L"failed to allocate %s", FS_NAME));
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
netfs_init_state(netfs, dev, pxe);
|
||||
|
||||
status = LibInstallProtocolInterfaces(&dev, &NetFsProtocol, netfs, NULL);
|
||||
if (EFI_ERROR(status)) {
|
||||
ERR_PRT((L"Cannot install %s protocol: %r", FS_NAME, status));
|
||||
free(netfs);
|
||||
return status;
|
||||
}
|
||||
|
||||
found:
|
||||
if (intf) *intf = (VOID *)netfs;
|
||||
|
||||
VERB_PRT(3,
|
||||
{ EFI_DEVICE_PATH *dp; CHAR16 *str;
|
||||
dp = DevicePathFromHandle(dev);
|
||||
str = DevicePathToStr(dp);
|
||||
Print(L"attached %s to %s\n", FS_NAME, str);
|
||||
FreePool(str);
|
||||
});
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
netfs_install(VOID)
|
||||
{
|
||||
UINTN size = 0;
|
||||
UINTN i;
|
||||
EFI_STATUS status;
|
||||
VOID *intf;
|
||||
|
||||
BS->LocateHandle(ByProtocol, &PxeBaseCodeProtocol, NULL, &size, NULL);
|
||||
if (size == 0) return EFI_UNSUPPORTED; /* no device found, oh well */
|
||||
|
||||
DBG_PRT((L"size=%d", size));
|
||||
|
||||
dev_tab = (dev_tab_t *)alloc(size, EfiLoaderData);
|
||||
if (dev_tab == NULL) {
|
||||
ERR_PRT((L"failed to allocate handle table"));
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
status = BS->LocateHandle(ByProtocol, &PxeBaseCodeProtocol, NULL, &size, (VOID **)dev_tab);
|
||||
if (status != EFI_SUCCESS) {
|
||||
ERR_PRT((L"failed to get handles: %r", status));
|
||||
free(dev_tab);
|
||||
return status;
|
||||
}
|
||||
ndev = size / sizeof(EFI_HANDLE);
|
||||
|
||||
for(i=0; i < ndev; i++) {
|
||||
intf = NULL;
|
||||
netfs_install_one(dev_tab[i].dev, &intf);
|
||||
/* override device handle with interface pointer */
|
||||
dev_tab[i].intf = intf;
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
netfs_uninstall(VOID)
|
||||
{
|
||||
|
||||
netfs_priv_state_t *nfs;
|
||||
EFI_STATUS status;
|
||||
UINTN i;
|
||||
|
||||
for(i=0; i < ndev; i++) {
|
||||
if (dev_tab[i].intf == NULL) continue;
|
||||
nfs = FS_PRIVATE(dev_tab[i].intf);
|
||||
status = BS->UninstallProtocolInterface(nfs->dev, &NetFsProtocol, dev_tab[i].intf);
|
||||
if (EFI_ERROR(status)) {
|
||||
ERR_PRT((L"Uninstall %s error: %r", FS_NAME, status));
|
||||
continue;
|
||||
}
|
||||
VERB_PRT(3,
|
||||
{ EFI_DEVICE_PATH *dp; CHAR16 *str;
|
||||
dp = DevicePathFromHandle(nfs->dev);
|
||||
str = DevicePathToStr(dp);
|
||||
Print(L"uninstalled %s on %s\n", FS_NAME, str);
|
||||
FreePool(str);
|
||||
});
|
||||
|
||||
if (nfs->pxe->Mode->Started == TRUE) nfs->pxe->Stop(nfs->pxe);
|
||||
|
||||
free(dev_tab[i].intf);
|
||||
}
|
||||
if (dev_tab) free(dev_tab);
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
68
fs/netfs.h
Normal file
68
fs/netfs.h
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* Copyright (C) 2001-2003 Hewlett-Packard Co.
|
||||
* Contributed by Stephane Eranian <eranian@hpl.hp.com>
|
||||
*
|
||||
* This file is part of the ELILO, the EFI Linux boot loader.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* ELILO 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.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with ELILO; see the file COPYING. If not, write to the Free
|
||||
* Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
||||
* 02111-1307, USA.
|
||||
*
|
||||
* Please check out the elilo.txt for complete documentation on how
|
||||
* to use this program.
|
||||
*/
|
||||
|
||||
#ifndef __NETLFS_H__
|
||||
#define __NETLFS_H__
|
||||
|
||||
#include <efi.h>
|
||||
#include <efilib.h>
|
||||
|
||||
#define NETFS_BOOTFILE_MAXLEN 256
|
||||
|
||||
typedef struct {
|
||||
EFI_IP_ADDRESS cln_ipaddr;
|
||||
EFI_IP_ADDRESS srv_ipaddr;
|
||||
EFI_IP_ADDRESS netmask;
|
||||
EFI_IP_ADDRESS gw_ipaddr;
|
||||
UINT8 hw_addr[16];
|
||||
CHAR16 hostname[255]; /* 255 limitation of DHCP protocol */
|
||||
CHAR16 domainame[255]; /* 255 limitation of DHCP protocol */
|
||||
CHAR16 bootfile[NETFS_BOOTFILE_MAXLEN]; /* name of file downloaded (BOOTP/DHCP) */
|
||||
BOOLEAN using_pxe;
|
||||
BOOLEAN started;
|
||||
BOOLEAN using_ipv6;
|
||||
} netfs_info_t;
|
||||
|
||||
|
||||
INTERFACE_DECL(_netfs_interface_t);
|
||||
|
||||
typedef struct _netfs_interface_t {
|
||||
EFI_STATUS (*netfs_name)(struct _netfs_interface_t *this, CHAR16 *name, UINTN maxlen);
|
||||
EFI_STATUS (*netfs_open)(struct _netfs_interface_t *this, CHAR16 *name, UINTN *fd);
|
||||
EFI_STATUS (*netfs_read)(struct _netfs_interface_t *this, UINTN fd, VOID *buf, UINTN *size);
|
||||
EFI_STATUS (*netfs_close)(struct _netfs_interface_t *this, UINTN fd);
|
||||
EFI_STATUS (*netfs_infosize)(struct _netfs_interface_t *this, UINTN fd, UINT64 *size);
|
||||
EFI_STATUS (*netfs_seek)(struct _netfs_interface_t *this, UINTN fd, UINT64 newpos);
|
||||
EFI_STATUS (*netfs_query_layer)(struct _netfs_interface_t *this, UINT16 server_type, UINT16 layer, UINTN maxlen, CHAR16 *str);
|
||||
EFI_STATUS (*netfs_getinfo)(struct _netfs_interface_t *this, netfs_info_t *info);
|
||||
} netfs_interface_t;
|
||||
|
||||
#define NETFS_PROTOCOL \
|
||||
{ 0x6746de4f, 0xcc1e, 0x4c5f, {0xb7, 0xfb, 0x85, 0x6a, 0x5d, 0x69, 0x0f, 0x06} }
|
||||
|
||||
extern EFI_STATUS netfs_install(VOID);
|
||||
extern EFI_STATUS netfs_uninstall(VOID);
|
||||
|
||||
#endif /* __NETFS_H__ */
|
Loading…
Add table
Add a link
Reference in a new issue