From d3c37c08b36dbbf4c0996a56dbdfe856d0ec9b2b Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 28 May 2002 17:27:12 +0000 Subject: 2002-05-28 Ralf Corsepius * libblock, libfs moved to src/exec for multilib'ing. --- c/src/libblock/.cvsignore | 14 - c/src/libblock/ChangeLog | 58 - c/src/libblock/Makefile.am | 12 - c/src/libblock/README | 14 - c/src/libblock/configure.ac | 32 - c/src/libblock/include/.cvsignore | 2 - c/src/libblock/include/Makefile.am | 22 - c/src/libblock/include/rtems/.cvsignore | 2 - c/src/libblock/include/rtems/bdbuf.h | 275 ---- c/src/libblock/include/rtems/blkdev.h | 147 --- c/src/libblock/include/rtems/diskdevs.h | 206 --- c/src/libblock/include/rtems/ramdisk.h | 52 - c/src/libblock/src/.cvsignore | 2 - c/src/libblock/src/Makefile.am | 32 - c/src/libblock/src/bdbuf.c | 1648 ------------------------ c/src/libblock/src/blkdev.c | 245 ---- c/src/libblock/src/diskdevs.c | 631 --------- c/src/libblock/src/ramdisk.c | 225 ---- c/src/libfs/.cvsignore | 16 - c/src/libfs/ChangeLog | 323 ----- c/src/libfs/Makefile.am | 12 - c/src/libfs/README | 13 - c/src/libfs/configure.ac | 39 - c/src/libfs/src/.cvsignore | 2 - c/src/libfs/src/Makefile.am | 9 - c/src/libfs/src/dosfs/.cvsignore | 6 - c/src/libfs/src/dosfs/Makefile.am | 55 - c/src/libfs/src/dosfs/dosfs.h | 31 - c/src/libfs/src/dosfs/fat.c | 695 ---------- c/src/libfs/src/dosfs/fat.h | 488 ------- c/src/libfs/src/dosfs/fat_fat_operations.c | 445 ------- c/src/libfs/src/dosfs/fat_fat_operations.h | 58 - c/src/libfs/src/dosfs/fat_file.c | 978 -------------- c/src/libfs/src/dosfs/fat_file.h | 195 --- c/src/libfs/src/dosfs/msdos.h | 408 ------ c/src/libfs/src/dosfs/msdos_create.c | 208 --- c/src/libfs/src/dosfs/msdos_dir.c | 483 ------- c/src/libfs/src/dosfs/msdos_eval.c | 435 ------- c/src/libfs/src/dosfs/msdos_file.c | 485 ------- c/src/libfs/src/dosfs/msdos_free.c | 56 - c/src/libfs/src/dosfs/msdos_fsunmount.c | 71 - c/src/libfs/src/dosfs/msdos_handlers_dir.c | 36 - c/src/libfs/src/dosfs/msdos_handlers_file.c | 36 - c/src/libfs/src/dosfs/msdos_init.c | 60 - c/src/libfs/src/dosfs/msdos_initsupp.c | 149 --- c/src/libfs/src/dosfs/msdos_misc.c | 1087 ---------------- c/src/libfs/src/dosfs/msdos_mknod.c | 90 -- c/src/libfs/src/dosfs/msdos_node_type.c | 58 - c/src/libfs/src/imfs/.cvsignore | 7 - c/src/libfs/src/imfs/Makefile.am | 66 - c/src/libfs/src/imfs/deviceio.c | 260 ---- c/src/libfs/src/imfs/imfs.h | 546 -------- c/src/libfs/src/imfs/imfs_chown.c | 56 - c/src/libfs/src/imfs/imfs_config.c | 37 - c/src/libfs/src/imfs/imfs_creat.c | 137 -- c/src/libfs/src/imfs/imfs_debug.c | 176 --- c/src/libfs/src/imfs/imfs_directory.c | 353 ----- c/src/libfs/src/imfs/imfs_eval.c | 660 ---------- c/src/libfs/src/imfs/imfs_fchmod.c | 78 -- c/src/libfs/src/imfs/imfs_fcntl.c | 28 - c/src/libfs/src/imfs/imfs_fdatasync.c | 29 - c/src/libfs/src/imfs/imfs_free.c | 40 - c/src/libfs/src/imfs/imfs_fsunmount.c | 100 -- c/src/libfs/src/imfs/imfs_getchild.c | 73 -- c/src/libfs/src/imfs/imfs_gtkn.c | 90 -- c/src/libfs/src/imfs/imfs_handlers_device.c | 41 - c/src/libfs/src/imfs/imfs_handlers_directory.c | 42 - c/src/libfs/src/imfs/imfs_handlers_link.c | 41 - c/src/libfs/src/imfs/imfs_handlers_memfile.c | 58 - c/src/libfs/src/imfs/imfs_init.c | 71 - c/src/libfs/src/imfs/imfs_initsupp.c | 88 -- c/src/libfs/src/imfs/imfs_link.c | 76 -- c/src/libfs/src/imfs/imfs_load_tar.c | 260 ---- c/src/libfs/src/imfs/imfs_mknod.c | 78 -- c/src/libfs/src/imfs/imfs_mount.c | 53 - c/src/libfs/src/imfs/imfs_ntype.c | 32 - c/src/libfs/src/imfs/imfs_readlink.c | 44 - c/src/libfs/src/imfs/imfs_rmnod.c | 82 -- c/src/libfs/src/imfs/imfs_stat.c | 68 - c/src/libfs/src/imfs/imfs_symlink.c | 64 - c/src/libfs/src/imfs/imfs_unixstub.c | 74 -- c/src/libfs/src/imfs/imfs_unlink.c | 78 -- c/src/libfs/src/imfs/imfs_unmount.c | 62 - c/src/libfs/src/imfs/imfs_utime.c | 41 - c/src/libfs/src/imfs/ioman.c | 110 -- c/src/libfs/src/imfs/linearfile.c | 116 -- c/src/libfs/src/imfs/memfile.c | 1137 ---------------- c/src/libfs/src/imfs/miniimfs_init.c | 74 -- c/src/libfs/wrapup/.cvsignore | 13 - c/src/libfs/wrapup/Makefile.am | 42 - 90 files changed, 16227 deletions(-) delete mode 100644 c/src/libblock/.cvsignore delete mode 100644 c/src/libblock/ChangeLog delete mode 100644 c/src/libblock/Makefile.am delete mode 100644 c/src/libblock/README delete mode 100644 c/src/libblock/configure.ac delete mode 100644 c/src/libblock/include/.cvsignore delete mode 100644 c/src/libblock/include/Makefile.am delete mode 100644 c/src/libblock/include/rtems/.cvsignore delete mode 100644 c/src/libblock/include/rtems/bdbuf.h delete mode 100644 c/src/libblock/include/rtems/blkdev.h delete mode 100644 c/src/libblock/include/rtems/diskdevs.h delete mode 100644 c/src/libblock/include/rtems/ramdisk.h delete mode 100644 c/src/libblock/src/.cvsignore delete mode 100644 c/src/libblock/src/Makefile.am delete mode 100644 c/src/libblock/src/bdbuf.c delete mode 100644 c/src/libblock/src/blkdev.c delete mode 100644 c/src/libblock/src/diskdevs.c delete mode 100644 c/src/libblock/src/ramdisk.c delete mode 100644 c/src/libfs/.cvsignore delete mode 100644 c/src/libfs/ChangeLog delete mode 100644 c/src/libfs/Makefile.am delete mode 100644 c/src/libfs/README delete mode 100644 c/src/libfs/configure.ac delete mode 100644 c/src/libfs/src/.cvsignore delete mode 100644 c/src/libfs/src/Makefile.am delete mode 100644 c/src/libfs/src/dosfs/.cvsignore delete mode 100644 c/src/libfs/src/dosfs/Makefile.am delete mode 100644 c/src/libfs/src/dosfs/dosfs.h delete mode 100644 c/src/libfs/src/dosfs/fat.c delete mode 100644 c/src/libfs/src/dosfs/fat.h delete mode 100644 c/src/libfs/src/dosfs/fat_fat_operations.c delete mode 100644 c/src/libfs/src/dosfs/fat_fat_operations.h delete mode 100644 c/src/libfs/src/dosfs/fat_file.c delete mode 100644 c/src/libfs/src/dosfs/fat_file.h delete mode 100644 c/src/libfs/src/dosfs/msdos.h delete mode 100644 c/src/libfs/src/dosfs/msdos_create.c delete mode 100644 c/src/libfs/src/dosfs/msdos_dir.c delete mode 100644 c/src/libfs/src/dosfs/msdos_eval.c delete mode 100644 c/src/libfs/src/dosfs/msdos_file.c delete mode 100644 c/src/libfs/src/dosfs/msdos_free.c delete mode 100644 c/src/libfs/src/dosfs/msdos_fsunmount.c delete mode 100644 c/src/libfs/src/dosfs/msdos_handlers_dir.c delete mode 100644 c/src/libfs/src/dosfs/msdos_handlers_file.c delete mode 100644 c/src/libfs/src/dosfs/msdos_init.c delete mode 100644 c/src/libfs/src/dosfs/msdos_initsupp.c delete mode 100644 c/src/libfs/src/dosfs/msdos_misc.c delete mode 100644 c/src/libfs/src/dosfs/msdos_mknod.c delete mode 100644 c/src/libfs/src/dosfs/msdos_node_type.c delete mode 100644 c/src/libfs/src/imfs/.cvsignore delete mode 100644 c/src/libfs/src/imfs/Makefile.am delete mode 100644 c/src/libfs/src/imfs/deviceio.c delete mode 100644 c/src/libfs/src/imfs/imfs.h delete mode 100644 c/src/libfs/src/imfs/imfs_chown.c delete mode 100644 c/src/libfs/src/imfs/imfs_config.c delete mode 100644 c/src/libfs/src/imfs/imfs_creat.c delete mode 100644 c/src/libfs/src/imfs/imfs_debug.c delete mode 100644 c/src/libfs/src/imfs/imfs_directory.c delete mode 100644 c/src/libfs/src/imfs/imfs_eval.c delete mode 100644 c/src/libfs/src/imfs/imfs_fchmod.c delete mode 100644 c/src/libfs/src/imfs/imfs_fcntl.c delete mode 100644 c/src/libfs/src/imfs/imfs_fdatasync.c delete mode 100644 c/src/libfs/src/imfs/imfs_free.c delete mode 100644 c/src/libfs/src/imfs/imfs_fsunmount.c delete mode 100644 c/src/libfs/src/imfs/imfs_getchild.c delete mode 100644 c/src/libfs/src/imfs/imfs_gtkn.c delete mode 100644 c/src/libfs/src/imfs/imfs_handlers_device.c delete mode 100644 c/src/libfs/src/imfs/imfs_handlers_directory.c delete mode 100644 c/src/libfs/src/imfs/imfs_handlers_link.c delete mode 100644 c/src/libfs/src/imfs/imfs_handlers_memfile.c delete mode 100644 c/src/libfs/src/imfs/imfs_init.c delete mode 100644 c/src/libfs/src/imfs/imfs_initsupp.c delete mode 100644 c/src/libfs/src/imfs/imfs_link.c delete mode 100644 c/src/libfs/src/imfs/imfs_load_tar.c delete mode 100644 c/src/libfs/src/imfs/imfs_mknod.c delete mode 100644 c/src/libfs/src/imfs/imfs_mount.c delete mode 100644 c/src/libfs/src/imfs/imfs_ntype.c delete mode 100644 c/src/libfs/src/imfs/imfs_readlink.c delete mode 100644 c/src/libfs/src/imfs/imfs_rmnod.c delete mode 100644 c/src/libfs/src/imfs/imfs_stat.c delete mode 100644 c/src/libfs/src/imfs/imfs_symlink.c delete mode 100644 c/src/libfs/src/imfs/imfs_unixstub.c delete mode 100644 c/src/libfs/src/imfs/imfs_unlink.c delete mode 100644 c/src/libfs/src/imfs/imfs_unmount.c delete mode 100644 c/src/libfs/src/imfs/imfs_utime.c delete mode 100644 c/src/libfs/src/imfs/ioman.c delete mode 100644 c/src/libfs/src/imfs/linearfile.c delete mode 100644 c/src/libfs/src/imfs/memfile.c delete mode 100644 c/src/libfs/src/imfs/miniimfs_init.c delete mode 100644 c/src/libfs/wrapup/.cvsignore delete mode 100644 c/src/libfs/wrapup/Makefile.am (limited to 'c') diff --git a/c/src/libblock/.cvsignore b/c/src/libblock/.cvsignore deleted file mode 100644 index d29e5050f5..0000000000 --- a/c/src/libblock/.cvsignore +++ /dev/null @@ -1,14 +0,0 @@ -Makefile -Makefile.in -aclocal.m4 -autom4te.cache -config.cache -config.guess -config.log -config.status -config.sub -configure -depcomp -install-sh -missing -mkinstalldirs diff --git a/c/src/libblock/ChangeLog b/c/src/libblock/ChangeLog deleted file mode 100644 index 0f3f896f65..0000000000 --- a/c/src/libblock/ChangeLog +++ /dev/null @@ -1,58 +0,0 @@ -2002-04-06 Ralf Corsepius - - * src/ramdisk.c: include . - * src/blkdev.c: include . - -2002-04-03 Alexander Kukuta - - * include/rtems/bdbuf.h: Address PR168 by changing bdbuf_buffer.avl.bal - and bdbuf_buffer.avl.cache to signed char instead of char. - -2002-03-27 Ralf Corsepius - - * configure.ac: - AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS). - AM_INIT_AUTOMAKE([no-define foreign 1.6]). - * include/Makefile.am: Remove AUTOMAKE_OPTIONS. - * Makefile.am: Remove AUTOMAKE_OPTIONS. - * src/Makefile.am: Remove AUTOMAKE_OPTIONS. - -2002-03-21 Alexander Kukuta - - * src/bdbuf.c (avl_insert, avl_remove): Reimplemented from scratch - to avoid using GPLed sources in RTEMS core. - * src/bdbuf.c, include/rtems/bdbuf.h: Remove "binary tree" - implementation which was used for debugging only. - -2002-03-13 Victor V. Vengerov - - * src/bdbuf.c (find_or_assign_buffer, rtems_bdbuf_read, - rtems_bdbuf_sync, rtems_bdbuf_syncdev, bdbuf_swapout_task): - Fix bug: disable interrupts and set level properly before - _CORE_mutex_Seize invocation). - -2002-02-28 Joel Sherrill - - * Submitted by Victor V. Vengerov and merged - into the RTEMS source. - * ChangeLog, Makefile.am, README, configure.ac, include/Makefile.am, - include/rtems/bdbuf.h, include/rtems/blkdev.h, include/rtems/diskdevs.h, - include/rtems/ramdisk.h, include/rtems/.cvsignore, include/.cvsignore, - src/Makefile.am, src/bdbuf.c, src/blkdev.c, src/diskdevs.c, - src/ramdisk.c, src/.cvsignore, .cvsignore: New files. - -2001-11-29 Victor V. Vengerov - * AVL trees implementation added. - -2001-11-16 Victor V. Vengerov - * include/rtems/bdbuf.h, src/bdbuf.c(rtems_bdbuf_syncdev): New. - -2001-11-07 Victor V. Vengerov - - * ChangeLog: New file. - * src/, include/, include/rtems/: New directories. - * README, configure.ac, Makefile.am, src/Makefile.am, - include/Makefile.am: New files. - * include/rtems/bdbuf.h include/rtems/blkdev.h - include/rtems/diskdevs.h include/rtems/ramdisk.h - src/bdbuf.c src/blkdev.c src/diskdevs.c src/ramdisk.c: New files. diff --git a/c/src/libblock/Makefile.am b/c/src/libblock/Makefile.am deleted file mode 100644 index 740f764d6a..0000000000 --- a/c/src/libblock/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -## -## $Id$ -## - -ACLOCAL_AMFLAGS = -I ../../../aclocal - -SUBDIRS = include src - -EXTRA_DIST = README - -include $(top_srcdir)/../../../automake/subdirs.am -include $(top_srcdir)/../../../automake/local.am diff --git a/c/src/libblock/README b/c/src/libblock/README deleted file mode 100644 index 671cc7f645..0000000000 --- a/c/src/libblock/README +++ /dev/null @@ -1,14 +0,0 @@ -# -# $Id$ -# - -This directory contains the block device (HDD, CDROMs, etc) support code. -It includes: - - block device driver interface - - generic open/close/read/write/ioctl primitives for block device drivers - - disk I/O buffering - - logical disk support - - RAM disk block device driver - -Victor V. Vengerov, -November, 7 2001 diff --git a/c/src/libblock/configure.ac b/c/src/libblock/configure.ac deleted file mode 100644 index f5bf09fa2e..0000000000 --- a/c/src/libblock/configure.ac +++ /dev/null @@ -1,32 +0,0 @@ -## Process this file with autoconf to produce a configure script. -## -## $Id$ - -AC_PREREQ(2.52) -AC_INIT([rtems-c-src-libblock],[_RTEMS_VERSION],[rtems-bugs@OARcorp.com]) -AC_CONFIG_SRCDIR([src/bdbuf.c]) -RTEMS_TOP(../../..) -AC_CONFIG_AUX_DIR(../../..) - -RTEMS_CANONICAL_TARGET_CPU -RTEMS_CANONICAL_HOST - -AM_INIT_AUTOMAKE([no-define foreign 1.6]) -AM_MAINTAINER_MODE - -RTEMS_ENV_RTEMSBSP -RTEMS_CHECK_CPU -RTEMS_CHECK_CUSTOM_BSP(RTEMS_BSP) -RTEMS_PROG_CC_FOR_TARGET -RTEMS_ENABLE_BARE - -RTEMS_CANONICALIZE_TOOLS - -RTEMS_PROJECT_ROOT - -# Explicitly list all Makefiles here -AC_CONFIG_FILES([Makefile -include/Makefile -src/Makefile -]) -AC_OUTPUT diff --git a/c/src/libblock/include/.cvsignore b/c/src/libblock/include/.cvsignore deleted file mode 100644 index 282522db03..0000000000 --- a/c/src/libblock/include/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/c/src/libblock/include/Makefile.am b/c/src/libblock/include/Makefile.am deleted file mode 100644 index 7f8f8dc48f..0000000000 --- a/c/src/libblock/include/Makefile.am +++ /dev/null @@ -1,22 +0,0 @@ -## -## $Id$ -## - - -include_rtemsdir = $(includedir)/rtems - -$(PROJECT_INCLUDE)/%.h: %.h - $(INSTALL_DATA) $< $@ - -$(PROJECT_INCLUDE)/rtems: - @$(mkinstalldirs) $@ - -include_rtems_HEADERS = \ - rtems/bdbuf.h rtems/blkdev.h rtems/diskdevs.h rtems/ramdisk.h - -PREINSTALL_FILES = $(PROJECT_INCLUDE)/rtems \ - $(include_rtems_HEADERS:%=$(PROJECT_INCLUDE)/%) - -all-local: $(PREINSTALL_FILES) - -include $(top_srcdir)/../../../automake/local.am diff --git a/c/src/libblock/include/rtems/.cvsignore b/c/src/libblock/include/rtems/.cvsignore deleted file mode 100644 index 282522db03..0000000000 --- a/c/src/libblock/include/rtems/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/c/src/libblock/include/rtems/bdbuf.h b/c/src/libblock/include/rtems/bdbuf.h deleted file mode 100644 index 4405e17e34..0000000000 --- a/c/src/libblock/include/rtems/bdbuf.h +++ /dev/null @@ -1,275 +0,0 @@ -/* bdbuf.h -- block device buffer management - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Victor V. Vengerov - * - * @(#) $Id$ - */ - -#ifndef __RTEMS_LIBBLOCK_BDBUF_H__ -#define __RTEMS_LIBBLOCK_BDBUF_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -#include "rtems/blkdev.h" -#include "rtems/diskdevs.h" - - -/* - * To manage buffers we using Buffer Descriptors. - * To speed-up buffer lookup descriptors are organized in AVL-Tree. - * The fields 'dev' and 'block' are search key. - */ - -/* Buffer descriptors - * Descriptors organized in AVL-tree to speedup buffer lookup. - * dev and block fields are search key in AVL-tree. - * Modified buffers, free buffers and used buffers linked in 'mod', 'free' and - * 'lru' chains appropriately. - */ - -typedef struct bdbuf_buffer { - Chain_Node link; /* Link in the lru, mod or free chains */ - - struct bdbuf_avl_node { - signed char cache; /* Cache */ - - struct bdbuf_buffer* left; /* Left Child */ - struct bdbuf_buffer* right; /* Right Child */ - - signed char bal; /* The balance of the sub-tree */ - } avl; - - dev_t dev; /* device number */ - blkdev_bnum block; /* block number on the device */ - - char *buffer; /* Pointer to the buffer memory area */ - rtems_status_code status; /* Last I/O operation completion status */ - int error; /* If status != RTEMS_SUCCESSFUL, this field contains - errno value which can be used by user later */ - boolean modified:1; /* =1 if buffer was modified */ - boolean in_progress:1; /* =1 if exchange with disk is in progress; - need to wait on semaphore */ - boolean actual:1; /* Buffer contains actual data */ - int use_count; /* Usage counter; incremented when somebody use - this buffer; decremented when buffer released - without modification or when buffer is flushed - by swapout task */ - - rtems_bdpool_id pool; /* Identifier of buffer pool to which this buffer - belongs */ - CORE_mutex_Control transfer_sema; - /* Transfer operation semaphore */ -} bdbuf_buffer; - - - -/* bdbuf_config structure describes block configuration (size, - * amount, memory location) for buffering layer - */ -typedef struct rtems_bdbuf_config { - int size; /* Size of block */ - int num; /* Number of blocks of appropriate size */ - char *mem_area; /* Pointer to the blocks location or NULL, in this - case memory for blocks will be allocated by - Buffering Layer with the help of RTEMS partition - manager */ -} rtems_bdbuf_config; - -extern rtems_bdbuf_config rtems_bdbuf_configuration[]; -extern int rtems_bdbuf_configuration_size; - -/* rtems_bdbuf_init -- - * Prepare buffering layer to work - initialize buffer descritors - * and (if it is neccessary) buffers. Buffers will be allocated accoriding - * to the configuration table, each entry describes kind of block and - * amount requested. After initialization all blocks is placed into - * free elements lists. - * - * PARAMETERS: - * conf_table - pointer to the buffers configuration table - * size - number of entries in configuration table - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - */ -rtems_status_code -rtems_bdbuf_init(rtems_bdbuf_config *conf_table, int size); - - -/* rtems_bdbuf_get -- - * Obtain block buffer. If specified block already cached (i.e. there's - * block in the _modified_, or _recently_used_), return address - * of appropriate buffer descriptor and increment reference counter to 1. - * If block is not cached, allocate new buffer and return it. Data - * shouldn't be read to the buffer from media; buffer may contains - * arbitrary data. This primitive may be blocked if there are no free - * buffer descriptors available and there are no unused non-modified - * (or synchronized with media) buffers available. - * - * PARAMETERS: - * device - device number (constructed of major and minor device number) - * block - linear media block number - * bd - address of variable to store pointer to the buffer descriptor - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - * - * SIDE EFFECTS: - * bufget_sema semaphore obtained by this primitive. - */ -rtems_status_code -rtems_bdbuf_get(dev_t device, blkdev_bnum block, bdbuf_buffer **bdb_ptr); - -/* rtems_bdbuf_read -- - * (Similar to the rtems_bdbuf_get, except reading data from media) - * Obtain block buffer. If specified block already cached, return address - * of appropriate buffer and increment reference counter to 1. If block is - * not cached, allocate new buffer and read data to it from the media. - * This primitive may be blocked on waiting until data to be read from - * media, if there are no free buffer descriptors available and there are - * no unused non-modified (or synchronized with media) buffers available. - * - * PARAMETERS: - * device - device number (consists of major and minor device number) - * block - linear media block number - * bd - address of variable to store pointer to the buffer descriptor - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - * - * SIDE EFFECTS: - * bufget_sema and transfer_sema semaphores obtained by this primitive. - */ -rtems_status_code -rtems_bdbuf_read(dev_t device, blkdev_bnum block, bdbuf_buffer **bdb_ptr); - -/* rtems_bdbuf_release -- - * Release buffer allocated before. This primitive decrease the - * usage counter. If it is zero, further destiny of buffer depends on - * 'modified' status. If buffer was modified, it is placed to the end of - * mod list and flush task waken up. If buffer was not modified, - * it is placed to the end of lru list, and bufget_sema released, allowing - * to reuse this buffer. - * - * PARAMETERS: - * bd_buf - pointer to the bdbuf_buffer structure previously obtained using - * get/read primitive. - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - * - * SIDE EFFECTS: - * flush_sema and bufget_sema semaphores may be released by this primitive. - */ -rtems_status_code -rtems_bdbuf_release(bdbuf_buffer *bd_buf); - -/* rtems_bdbuf_release_modified -- - * Release buffer allocated before, assuming that it is _modified_ by - * it's owner. This primitive decrease usage counter for buffer, mark - * buffer descriptor as modified. If usage counter is 0, insert it at - * end of mod chain and release flush_sema semaphore to activate the - * flush task. - * - * PARAMETERS: - * bd_buf - pointer to the bdbuf_buffer structure previously obtained using - * get/read primitive. - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - * - * SIDE EFFECTS: - * flush_sema semaphore may be released by this primitive. - */ -rtems_status_code -rtems_bdbuf_release_modified(bdbuf_buffer *bd_buf); - -/* rtems_bdbuf_sync -- - * Wait until specified buffer synchronized with disk. Invoked on exchanges - * critical for data consistency on the media. This primitive mark owned - * block as modified, decrease usage counter. If usage counter is 0, - * block inserted to the mod chain and flush_sema semaphore released. - * Finally, primitives blocked on transfer_sema semaphore. - * - * PARAMETERS: - * bd_buf - pointer to the bdbuf_buffer structure previously obtained using - * get/read primitive. - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - * - * SIDE EFFECTS: - * Primitive may be blocked on transfer_sema semaphore. - */ -rtems_status_code -rtems_bdbuf_sync(bdbuf_buffer *bd_buf); - -/* rtems_bdbuf_syncdev -- - * Synchronize with disk all buffers containing the blocks belonging to - * specified device. - * - * PARAMETERS: - * dev - block device number - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - */ -rtems_status_code -rtems_bdbuf_syncdev(dev_t dev); - -/* rtems_bdbuf_find_pool -- - * Find first appropriate buffer pool. This primitive returns the index - * of first buffer pool which block size is greater than or equal to - * specified size. - * - * PARAMETERS: - * block_size - requested block size - * pool - placeholder for result - * - * RETURNS: - * RTEMS status code: RTEMS_SUCCESSFUL if operation completed successfully, - * RTEMS_INVALID_SIZE if specified block size is invalid (not a power - * of 2), RTEMS_NOT_DEFINED if buffer pool for this or greater block size - * is not configured. - */ -rtems_status_code -rtems_bdbuf_find_pool(int block_size, rtems_bdpool_id *pool); - -/* rtems_bdbuf_get_pool_info -- - * Obtain characteristics of buffer pool with specified number. - * - * PARAMETERS: - * pool - buffer pool number - * block_size - block size for which buffer pool is configured returned - * there - * blocks - number of buffers in buffer pool returned there - * - * RETURNS: - * RTEMS status code: RTEMS_SUCCESSFUL if operation completed successfully, - * RTEMS_INVALID_NUMBER if appropriate buffer pool is not configured. - * - * NOTE: - * Buffer pools enumerated contiguously starting from 0. - */ -rtems_status_code -rtems_bdbuf_get_pool_info(rtems_bdpool_id pool, int *block_size, int *blocks); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/c/src/libblock/include/rtems/blkdev.h b/c/src/libblock/include/rtems/blkdev.h deleted file mode 100644 index ca3b5ba5e2..0000000000 --- a/c/src/libblock/include/rtems/blkdev.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - * blkdev.h - block device driver interface definitions - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Victor V. Vengerov - * - * @(#) $Id$ - */ - -#ifndef __RTEMS_LIBBLOCK_BLKDEV_H__ -#define __RTEMS_LIBBLOCK_BLKDEV_H__ - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Interface with device drivers - * Block device looks, initialized and behaves like traditional RTEMS device - * driver. Heart of the block device driver is in BIOREQUEST ioctl. This call - * puts I/O request to the block device queue, in priority order, for - * asynchronous processing. When driver executes request, req_done - * function invoked, so callee knows about it. Look for details below. - */ - - -/* Block device block number datatype */ -typedef rtems_unsigned32 blkdev_bnum; - -/* Block device request type */ -typedef enum blkdev_request_op { - BLKDEV_REQ_READ, /* Read operation */ - BLKDEV_REQ_WRITE /* Write operation */ -} blkdev_request_op; - -/* Type for block device request done callback function. - * - * PARAMETERS: - * arg - argument supplied in blkdev_request - * status - rtems status code for this operation - * errno - errno value to be passed to the user when - * status != RTEMS_SUCCESSFUL - */ -typedef void (* blkdev_request_cb)(void *arg, - rtems_status_code status, - int error); - -/* blkdev_sg_buffer - * Block device scatter/gather buffer structure - */ -typedef struct blkdev_sg_buffer { - rtems_unsigned32 length; /* Buffer length */ - void *buffer; /* Buffer pointer */ -} blkdev_sg_buffer; - -/* blkdev_request (Block Device Request) structure is - * used to read/write a number of blocks from/to device. - */ -typedef struct blkdev_request { - blkdev_request_op req; /* Block device operation (read or write) */ - blkdev_request_cb req_done; /* Callback function */ - void *done_arg; /* Argument to be passed to callback function*/ - blkdev_bnum start; /* Start block number */ - rtems_unsigned32 count; /* Number of blocks to be exchanged */ - rtems_unsigned32 bufnum; /* Number of buffers provided */ - - blkdev_sg_buffer bufs[0];/* List of scatter/gather buffers */ -} blkdev_request; - -/* Block device IOCTL request codes */ -#define BLKIO_REQUEST _IOWR('B', 1, blkdev_request) -#define BLKIO_GETBLKSIZE _IO('B', 2) -#define BLKIO_GETSIZE _IO('B', 3) -#define BLKIO_SYNCDEV _IO('B', 4) - -/* Device driver interface conventions suppose that driver may - * contain initialize/open/close/read/write/ioctl entry points. These - * primitives (except initialize) can be implemented in generic fashion, - * based upon supplied block device driver ioctl handler. Every block - * device driver should provide initialize entry point, which is register - * all block devices and appropriate ioctl handlers. - */ - -#define GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES \ - rtems_blkdev_generic_open, rtems_blkdev_generic_close, \ - rtems_blkdev_generic_read, rtems_blkdev_generic_write, \ - rtems_blkdev_generic_ioctl - -/* blkdev_generic_read -- - * Generic block device read primitive. Implemented using block device - * buffer management primitives. - */ -rtems_device_driver -rtems_blkdev_generic_read( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -); - -/* blkdev_generic_write -- - * Generic block device driver write primitive. Implemented using block - * device buffer management primitives. - */ -rtems_device_driver -rtems_blkdev_generic_write( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -); - -/* blkdev_generic_open -- - * Generic block device open primitive. - */ -rtems_device_driver -rtems_blkdev_generic_open( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -); - -/* blkdev_generic_close -- - * Generic block device close primitive. - */ -rtems_device_driver -rtems_blkdev_generic_close( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -); - -/* blkdev_generic_ioctl -- - * Generic block device ioctl primitive. - */ -rtems_device_driver -rtems_blkdev_generic_ioctl( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg -); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/c/src/libblock/include/rtems/diskdevs.h b/c/src/libblock/include/rtems/diskdevs.h deleted file mode 100644 index fab3231e62..0000000000 --- a/c/src/libblock/include/rtems/diskdevs.h +++ /dev/null @@ -1,206 +0,0 @@ -/* - * logdisk.h - Physical and logical block devices (disks) support - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Victor V. Vengerov - * - * @(#) $Id$ - */ - -#ifndef __RTEMS_LIBBLOCK_LOGDISK_H__ -#define __RTEMS_LIBBLOCK_LOGDISK_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -#include "rtems/blkdev.h" - -/* Buffer pool identifier */ -typedef int rtems_bdpool_id; - -/* Block device ioctl handler */ -typedef int (* block_device_ioctl) (dev_t dev, int req, void *argp); - -/* disk_device: Entry of this type created for every disk device (both for - * logical and physical disks). - * Array of arrays of pointers to disk_device structures maintained. First - * table indexed by major number and second table indexed by minor number. - * Such data organization allow quick lookup using data structure of - * moderated size. - */ -typedef struct disk_device { - dev_t dev; /* Device ID (major + minor) */ - struct disk_device *phys_dev; /* Physical device ID (the same - as dev if this entry specifies - the physical device) */ - char *name; /* Disk device name */ - int uses; /* Use counter. Device couldn't be - removed if it is in use. */ - int start; /* Starting block number (0 for - physical devices, block offset - on the related physical device - for logical device) */ - int size; /* Size of physical or logical disk - in disk blocks */ - int block_size; /* Size of device block (minimum - transfer unit) in bytes - (must be power of 2) */ - int block_size_log2; /* log2 of block_size */ - rtems_bdpool_id pool; /* Buffer pool assigned to this - device */ - block_device_ioctl ioctl; /* ioctl handler for this block - device */ -} disk_device; - -/* rtems_disk_create_phys -- - * Create physical disk entry. This function usually invoked from - * block device driver initialization code when physical device - * detected in the system. Device driver should provide ioctl handler - * to allow block device access operations. This primitive will register - * device in rtems (invoke rtems_io_register_name). - * - * PARAMETERS: - * dev - device identifier (major, minor numbers) - * block_size - size of disk block (minimum data transfer unit); must be - * power of 2 - * disk_size - number of blocks on device - * handler - IOCTL handler (function providing basic block input/output - * request handling BIOREQUEST and other device management - * operations) - * name - character name of device (e.g. /dev/hda) - * - * RETURNS: - * RTEMS_SUCCESSFUL if information about new physical disk added, or - * error code if error occured (device already registered, wrong block - * size value, no memory available). - */ -rtems_status_code -rtems_disk_create_phys(dev_t dev, int block_size, int disk_size, - block_device_ioctl handler, - char *name); - -/* rtems_disk_create_log -- - * Create logical disk entry. Logical disk is contiguous area on physical - * disk. Disk may be splitted to several logical disks in several ways: - * manually or using information stored in blocks on physical disk - * (DOS-like partition table, BSD disk label, etc). This function usually - * invoked from application when application-specific splitting are in use, - * or from generic code which handle different logical disk organizations. - * This primitive will register device in rtems (invoke - * rtems_io_register_name). - * - * PARAMETERS: - * dev - logical device identifier (major, minor numbers) - * phys - physical device (block device which holds this logical disk) - * identifier - * start - starting block number on the physical device - * size - logical disk size in blocks - * name - logical disk name - * - * RETURNS: - * RTEMS_SUCCESSFUL if logical device successfully added, or error code - * if error occured (device already registered, no physical device - * exists, logical disk is out of physical disk boundaries, no memory - * available). - */ -rtems_status_code -rtems_disk_create_log(dev_t dev, dev_t phys, int start, int size, char *name); - -/* rtems_disk_delete -- - * Delete physical or logical disk device. Device may be deleted if its - * use counter (and use counters of all logical devices - if it is - * physical device) equal to 0. When physical device deleted, - * all logical devices deleted inherently. Appropriate devices removed - * from "/dev" filesystem. - * - * PARAMETERS: - * dev - device identifier (major, minor numbers) - * - * RETURNS: - * RTEMS_SUCCESSFUL if block device successfully deleted, or error code - * if error occured (device is not defined, device is in use). - */ -rtems_status_code -rtems_disk_delete(dev_t dev); - -/* rtems_disk_lookup -- - * Find block device descriptor by its device identifier. This function - * increment usage counter to 1. User should release disk_device structure - * by invoking rtems_disk_release primitive. - * - * PARAMETERS: - * dev - device identifier (major, minor numbers) - * - * RETURNS: - * pointer to the block device descriptor, or NULL if no such device - * exists. - */ -disk_device * -rtems_disk_lookup(dev_t dev); - -/* rtems_disk_release -- - * Release disk_device structure (decrement usage counter to 1). - * - * PARAMETERS: - * dd - pointer to disk device structure - * - * RETURNS: - * RTEMS_SUCCESSFUL - * - * NOTE: - * It should be implemented as inline function. - */ -rtems_status_code -rtems_disk_release(disk_device *dd); - -/* rtems_disk_next -- - * Disk device enumerator. Looking for device having device number larger - * than dev and return disk device descriptor for it. If there are no - * such device, NULL value returned. - * - * PARAMETERS: - * dev - device number (use -1 to start search) - * - * RETURNS: - * Pointer to the disk descriptor for next disk device, or NULL if all - * devices enumerated. */ -disk_device * -rtems_disk_next(dev_t dev); - -/* rtems_diskio_initialize -- - * Initialization of disk device library (initialize all data structures, - * etc.) - * - * PARAMETERS: - * none - * - * RETURNS: - * RTEMS_SUCCESSFUL if library initialized, or error code if error - * occured. - */ -rtems_status_code -rtems_disk_io_initialize(void); - -/* rtems_diskio_done -- - * Release all resources allocated for disk device interface. - * - * PARAMETERS: - * none - * - * RETURNS: - * RTEMS_SUCCESSFUL if all resources released, or error code if error - * occured. - */ -rtems_status_code -rtems_disk_io_done(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/c/src/libblock/include/rtems/ramdisk.h b/c/src/libblock/include/rtems/ramdisk.h deleted file mode 100644 index b9e8c238b8..0000000000 --- a/c/src/libblock/include/rtems/ramdisk.h +++ /dev/null @@ -1,52 +0,0 @@ -/* ramdisk.c -- RAM disk block device implementation - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Victor V. Vengerov - * - * @(#) $Id$ - */ - -#ifndef __RTEMS_LIBBLOCK_RAMDISK_H__ -#define __RTEMS_LIBBLOCK_RAMDISK_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include "rtems/blkdev.h" - -/* RAM disk configuration table entry */ -typedef struct rtems_ramdisk_config { - int block_size; /* RAM disk block size */ - int block_num; /* Number of blocks on this RAM disk */ - void *location; /* RAM disk permanent location (out of RTEMS controlled - memory), or NULL if RAM disk memory should be - allocated dynamically */ -} rtems_ramdisk_config; - -/* If application want to use RAM disk, it should specify configuration of - * available RAM disks. - * The following is definitions for RAM disk configuration table - */ -extern rtems_ramdisk_config rtems_ramdisk_configuration[]; -extern int rtems_ramdisk_configuration_size; - -/* ramdisk_initialize -- - * RAM disk driver initialization entry point. - */ -rtems_device_driver -ramdisk_initialize( - rtems_device_major_number major, - rtems_device_minor_number minor, - void *arg); - -#define RAMDISK_DRIVER_TABLE_ENTRY \ - { ramdisk_initialize, GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES } - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/c/src/libblock/src/.cvsignore b/c/src/libblock/src/.cvsignore deleted file mode 100644 index 282522db03..0000000000 --- a/c/src/libblock/src/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/c/src/libblock/src/Makefile.am b/c/src/libblock/src/Makefile.am deleted file mode 100644 index ead52c2ab3..0000000000 --- a/c/src/libblock/src/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -## -## $Id$ -## - - -LIBNAME = libblock -LIB = ${ARCH}/${LIBNAME}.a - -C_FILES = bdbuf.c blkdev.c diskdevs.c ramdisk.c - -C_O_FILES = $(C_FILES:%.c=${ARCH}/%.o) - -SRCS = $(C_FILES) -OBJS = $(C_O_FILES) - -include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg -include $(top_srcdir)/../../../automake/compile.am -include $(top_srcdir)/../../../automake/lib.am - -AM_CFLAGS += $(LIBC_DEFINES) - -TMPINSTALL_FILES += $(PROJECT_RELEASE)/lib/$(LIBNAME)$(LIB_VARIANT).a - -$(LIB): ${OBJS} - $(make-library) - -$(PROJECT_RELEASE)/lib/$(LIBNAME)$(LIB_VARIANT).a: $(LIB) - $(INSTALL_DATA) $< $@ - -all-local: ${ARCH} $(PREINSTALL_FILES) $(TMPINSTALL_FILES) - -include $(top_srcdir)/../../../automake/local.am diff --git a/c/src/libblock/src/bdbuf.c b/c/src/libblock/src/bdbuf.c deleted file mode 100644 index 877e3c561c..0000000000 --- a/c/src/libblock/src/bdbuf.c +++ /dev/null @@ -1,1648 +0,0 @@ -/* - * Disk I/O buffering - * Buffer managment - * - * Copyright (C) 2001 OKTET Ltd., St.-Peterburg, Russia - * Author: Andrey G. Ivanov - * Victor V. Vengerov - * Alexander Kukuta - * - * @(#) $Id$ - */ - -#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__ -#include -#include -#include -#include - -#include "rtems/bdbuf.h" - -/* Fatal errors: */ -#define BLKDEV_FATAL_ERROR(n) (('B' << 24) | ((n) & 0x00FFFFFF)) -#define BLKDEV_FATAL_BDBUF_CONSISTENCY BLKDEV_FATAL_ERROR(1) -#define BLKDEV_FATAL_BDBUF_SWAPOUT BLKDEV_FATAL_ERROR(2) - - -#define SWAPOUT_PRIORITY 15 -#define SWAPOUT_STACK_SIZE (RTEMS_MINIMUM_STACK_SIZE * 2) - -static rtems_task bdbuf_swapout_task(rtems_task_argument unused); - -/* - * The groups of the blocks with the same size are collected in the - * bd_pool. Note that a several of the buffer's groups with the - * same size can exists. - */ -typedef struct bdbuf_pool -{ - bdbuf_buffer *tree; /* Buffer descriptor lookup AVL tree root */ - - Chain_Control free; /* Free buffers list */ - Chain_Control lru; /* Last recently used list */ - - int blksize; /* The size of the blocks (in bytes) */ - int nblks; /* Number of blocks in this pool */ - rtems_id bufget_sema; /* Buffer obtain counting semaphore */ - void *mallocd_bufs; /* Pointer to the malloc'd buffer memory, - or NULL, if buffer memory provided in - buffer configuration */ - bdbuf_buffer *bdbufs; /* Pointer to table of buffer descriptors - allocated for this buffer pool. */ -} bdbuf_pool; - -/* Buffering layer context definition */ -struct bdbuf_context { - bdbuf_pool *pool; /* Table of buffer pools */ - int npools; /* Number of entries in pool table */ - - Chain_Control mod; /* Modified buffers list */ - rtems_id flush_sema; /* Buffer flush semaphore; counting - semaphore; incremented when buffer - flushed to the disk; decremented when - buffer modified */ - rtems_id swapout_task; /* Swapout task ID */ -}; - -/* Block device request with a single buffer provided */ -typedef struct blkdev_request1 { - blkdev_request req; - blkdev_sg_buffer sg[1]; -} blkdev_request1; - -/* The static context of buffering layer */ -static struct bdbuf_context bd_ctx; - -#define SAFE -#ifdef SAFE -typedef rtems_mode preemption_key; - -#define DISABLE_PREEMPTION(key) \ - do { \ - rtems_task_mode(RTEMS_PREEMPT_MASK, RTEMS_NO_PREEMPT, &(key)); \ - } while (0) - -#define ENABLE_PREEMPTION(key) \ - do { \ - rtems_mode temp; \ - rtems_task_mode(RTEMS_PREEMPT_MASK, (key), &temp); \ - } while (0) - -#else - -typedef boolean preemption_key; - -#define DISABLE_PREEMPTION(key) \ - do { \ - (key) = _Thread_Executing->is_preemptible; \ - _Thread_Executing->is_preemptible = 0; \ - } while (0) - -#define ENABLE_PREEMPTION(key) \ - do { \ - _Thread_Executing->is_preemptible = (key); \ - if (_Thread_Evaluate_mode()) \ - _Thread_Dispatch(); \ - } while (0) - -#endif - - -/* The default maximum height of 32 allows for AVL trees having - between 5,704,880 and 4,294,967,295 nodes, depending on order of - insertion. You may change this compile-time constant as you - wish. */ -#ifndef AVL_MAX_HEIGHT -#define AVL_MAX_HEIGHT 32 -#endif - -/* - * avl_search -- - * Searches for the node with specified dev/block. - * - * PARAMETERS: - * root - pointer to the root node of the AVL-Tree. - * dev, block - search key - * - * RETURNS: - * NULL if node with specified dev/block not found - * non-NULL - pointer to the node with specified dev/block - */ -static bdbuf_buffer * -avl_search(bdbuf_buffer **root, dev_t dev, blkdev_bnum block) -{ - bdbuf_buffer *p = *root; - - while ((p != NULL) && ((p->dev != dev) || (p->block != block))) - { - if ((p->dev < dev) || ((p->dev == dev) && (p->block < block))) - { - p = p->avl.right; - } - else - { - p = p->avl.left; - } - } - - return p; -} - - -/* avl_search_for_sync -- - * Search in AVL tree for first modified buffer belongs to specified - * disk device. - * - * PARAMETERS: - * root - pointer to tree root - * dd - disk device descriptor - * - * RETURNS: - * Block buffer, or NULL if no modified blocks on specified device - * exists. - */ -static bdbuf_buffer * -avl_search_for_sync(bdbuf_buffer **root, disk_device *dd) -{ - dev_t dev = dd->phys_dev->dev; - blkdev_bnum block_start = dd->start; - blkdev_bnum block_end = dd->start + dd->size - 1; - - bdbuf_buffer *buf_stack[AVL_MAX_HEIGHT]; - bdbuf_buffer **buf_prev = buf_stack; - bdbuf_buffer *p = *root; - - while (p != NULL) - { - if ((p->dev < dev) || ((p->dev == dev) && (p->block < block_start))) - { - p = p->avl.right; - } - else if ((p->dev > dev) || ((p->dev == dev) && (p->block > block_end))) - { - p = p->avl.left; - } - else if (p->modified) - { - return p; - } - else - { - if (p->avl.right != NULL) - { - *buf_prev++ = p->avl.right; - } - p = p->avl.left; - } - - if ((p == NULL) && (buf_prev > buf_stack)) - { - p = *--buf_prev; - } - } - - return p; -} - - -/* - * avl_insert -- - * Inserts the specified node to the AVl-Tree. - * - * PARAMETERS: - * root - Pointer to pointer to the root node - * node - Pointer to the node to add. - * - * RETURNS: - * 0 - The node added successfully - * -1 - An error occured - */ -static int -avl_insert(bdbuf_buffer **root, bdbuf_buffer *node) -{ - dev_t dev = node->dev; - blkdev_bnum block = node->block; - - bdbuf_buffer *p = *root; - bdbuf_buffer *q, *p1, *p2; - bdbuf_buffer *buf_stack[AVL_MAX_HEIGHT]; - bdbuf_buffer **buf_prev = buf_stack; - - boolean modified = FALSE; - - if (p == NULL) - { - *root = node; - node->avl.left = NULL; - node->avl.right = NULL; - node->avl.bal = 0; - return 0; - } - - while (p != NULL) - { - *buf_prev++ = p; - - if ((p->dev < dev) || ((p->dev == dev) && (p->block < block))) - { - p->avl.cache = 1; - q = p->avl.right; - if (q == NULL) - { - q = node; - p->avl.right = q = node; - break; - } - } - else if ((p->dev != dev) || (p->block != block)) - { - p->avl.cache = -1; - q = p->avl.left; - if (q == NULL) - { - q = node; - p->avl.left = q; - break; - } - } - else - { - return -1; - } - - p = q; - } - - q->avl.left = q->avl.right = NULL; - q->avl.bal = 0; - modified = TRUE; - buf_prev--; - - while (modified) - { - if (p->avl.cache == -1) - { - switch (p->avl.bal) - { - case 1: - p->avl.bal = 0; - modified = FALSE; - break; - - case 0: - p->avl.bal = -1; - break; - - case -1: - p1 = p->avl.left; - if (p1->avl.bal == -1) /* simple LL-turn */ - { - p->avl.left = p1->avl.right; - p1->avl.right = p; - p->avl.bal = 0; - p = p1; - } - else /* double LR-turn */ - { - p2 = p1->avl.right; - p1->avl.right = p2->avl.left; - p2->avl.left = p1; - p->avl.left = p2->avl.right; - p2->avl.right = p; - if (p2->avl.bal == -1) p->avl.bal = +1; else p->avl.bal = 0; - if (p2->avl.bal == +1) p1->avl.bal = -1; else p1->avl.bal = 0; - p = p2; - } - p->avl.bal = 0; - modified = FALSE; - break; - - default: - break; - } - } - else - { - switch (p->avl.bal) - { - case -1: - p->avl.bal = 0; - modified = FALSE; - break; - - case 0: - p->avl.bal = 1; - break; - - case 1: - p1 = p->avl.right; - if (p1->avl.bal == 1) /* simple RR-turn */ - { - p->avl.right = p1->avl.left; - p1->avl.left = p; - p->avl.bal = 0; - p = p1; - } - else /* double RL-turn */ - { - p2 = p1->avl.left; - p1->avl.left = p2->avl.right; - p2->avl.right = p1; - p->avl.right = p2->avl.left; - p2->avl.left = p; - if (p2->avl.bal == +1) p->avl.bal = -1; else p->avl.bal = 0; - if (p2->avl.bal == -1) p1->avl.bal = +1; else p1->avl.bal = 0; - p = p2; - } - p->avl.bal = 0; - modified = FALSE; - break; - - default: - break; - } - } - q = p; - if (buf_prev > buf_stack) - { - p = *--buf_prev; - - if (p->avl.cache == -1) - { - p->avl.left = q; - } - else - { - p->avl.right = q; - } - } - else - { - *root = p; - break; - } - }; - - return 0; -} - - -/* avl_remove -- - * removes the node from the tree. - * - * PARAMETERS: - * root_addr - Pointer to pointer to the root node - * node - Pointer to the node to remove - * - * RETURNS: - * 0 - Item removed - * -1 - No such item found - */ -static int -avl_remove(bdbuf_buffer **root, const bdbuf_buffer *node) -{ - dev_t dev = node->dev; - blkdev_bnum block = node->block; - - bdbuf_buffer *p = *root; - bdbuf_buffer *q, *r, *s, *p1, *p2; - bdbuf_buffer *buf_stack[AVL_MAX_HEIGHT]; - bdbuf_buffer **buf_prev = buf_stack; - - boolean modified = FALSE; - - memset(buf_stack, 0, sizeof(buf_stack)); - - while (p != NULL) - { - *buf_prev++ = p; - - if ((p->dev < dev) || ((p->dev == dev) && (p->block < block))) - { - p->avl.cache = 1; - p = p->avl.right; - } - else if ((p->dev != dev) || (p->block != block)) - { - p->avl.cache = -1; - p = p->avl.left; - } - else - { - /* node found */ - break; - } - } - - if (p == NULL) - { - /* there is no such node */ - return -1; - } - - q = p; - - buf_prev--; - if (buf_prev > buf_stack) - { - p = *(buf_prev - 1); - } - else - { - p = NULL; - } - - /* at this moment q - is a node to delete, p is q's parent */ - if (q->avl.right == NULL) - { - r = q->avl.left; - if (r != NULL) - { - r->avl.bal = 0; - } - q = r; - } - else - { - bdbuf_buffer **t; - - r = q->avl.right; - - if (r->avl.left == NULL) - { - r->avl.left = q->avl.left; - r->avl.bal = q->avl.bal; - r->avl.cache = 1; - *buf_prev++ = q = r; - } - else - { - t = buf_prev++; - s = r; - - while (s->avl.left != NULL) - { - *buf_prev++ = r = s; - s = r->avl.left; - r->avl.cache = -1; - } - - s->avl.left = q->avl.left; - r->avl.left = s->avl.right; - s->avl.right = q->avl.right; - s->avl.bal = q->avl.bal; - s->avl.cache = 1; - - *t = q = s; - } - } - - if (p != NULL) - { - if (p->avl.cache == -1) - { - p->avl.left = q; - } - else - { - p->avl.right = q; - } - } - else - { - *root = q; - } - - modified = TRUE; - - while (modified) - { - if (buf_prev > buf_stack) - { - p = *--buf_prev; - } - else - { - break; - } - - if (p->avl.cache == -1) - { - /* rebalance left branch */ - switch (p->avl.bal) - { - case -1: - p->avl.bal = 0; - break; - case 0: - p->avl.bal = 1; - modified = FALSE; - break; - - case +1: - p1 = p->avl.right; - - if (p1->avl.bal >= 0) /* simple RR-turn */ - { - p->avl.right = p1->avl.left; - p1->avl.left = p; - - if (p1->avl.bal == 0) - { - p1->avl.bal = -1; - modified = FALSE; - } - else - { - p->avl.bal = 0; - p1->avl.bal = 0; - } - p = p1; - } - else /* double RL-turn */ - { - p2 = p1->avl.left; - - p1->avl.left = p2->avl.right; - p2->avl.right = p1; - p->avl.right = p2->avl.left; - p2->avl.left = p; - - if (p2->avl.bal == +1) p->avl.bal = -1; else p->avl.bal = 0; - if (p2->avl.bal == -1) p1->avl.bal = 1; else p1->avl.bal = 0; - - p = p2; - p2->avl.bal = 0; - } - break; - - default: - break; - } - } - else - { - /* rebalance right branch */ - switch (p->avl.bal) - { - case +1: - p->avl.bal = 0; - break; - - case 0: - p->avl.bal = -1; - modified = FALSE; - break; - - case -1: - p1 = p->avl.left; - - if (p1->avl.bal <= 0) /* simple LL-turn */ - { - p->avl.left = p1->avl.right; - p1->avl.right = p; - if (p1->avl.bal == 0) - { - p1->avl.bal = 1; - modified = FALSE; - } - else - { - p->avl.bal = 0; - p1->avl.bal = 0; - } - p = p1; - } - else /* double LR-turn */ - { - p2 = p1->avl.right; - - p1->avl.right = p2->avl.left; - p2->avl.left = p1; - p->avl.left = p2->avl.right; - p2->avl.right = p; - - if (p2->avl.bal == -1) p->avl.bal = 1; else p->avl.bal = 0; - if (p2->avl.bal == +1) p1->avl.bal = -1; else p1->avl.bal = 0; - - p = p2; - p2->avl.bal = 0; - } - break; - - default: - break; - } - } - - if (buf_prev > buf_stack) - { - q = *(buf_prev - 1); - - if (q->avl.cache == -1) - { - q->avl.left = p; - } - else - { - q->avl.right = p; - } - } - else - { - *root = p; - break; - } - - } - - return 0; -} - -/* bdbuf_initialize_pool -- - * Initialize single buffer pool. - * - * PARAMETERS: - * config - buffer pool configuration - * pool - pool number - * - * RETURNS: - * RTEMS_SUCCESSFUL, if buffer pool initialized successfully, or error - * code if error occured. - */ -static rtems_status_code -bdbuf_initialize_pool(rtems_bdbuf_config *config, int pool) -{ - bdbuf_pool *p = bd_ctx.pool + pool; - unsigned char *bufs; - bdbuf_buffer *b; - rtems_status_code rc; - int i; - - p->blksize = config->size; - p->nblks = config->num; - p->tree = NULL; - - Chain_Initialize_empty(&p->free); - Chain_Initialize_empty(&p->lru); - - /* Allocate memory for buffer descriptors */ - p->bdbufs = calloc(config->num, sizeof(bdbuf_buffer)); - if (p->bdbufs == NULL) - { - return RTEMS_NO_MEMORY; - } - - /* Allocate memory for buffers if required */ - if (config->mem_area == NULL) - { - bufs = p->mallocd_bufs = malloc(config->num * config->size); - if (bufs == NULL) - { - free(p->bdbufs); - return RTEMS_NO_MEMORY; - } - } - else - { - bufs = config->mem_area; - p->mallocd_bufs = NULL; - } - - for (i = 0, b = p->bdbufs; i < p->nblks; i++, b++, bufs += p->blksize) - { - b->dev = -1; b->block = 0; - b->buffer = bufs; - b->actual = b->modified = b->in_progress = FALSE; - b->use_count = 0; - b->pool = pool; - _Chain_Append(&p->free, &b->link); - } - - rc = rtems_semaphore_create( - rtems_build_name('B', 'U', 'F', 'G'), - p->nblks, - RTEMS_FIFO | RTEMS_COUNTING_SEMAPHORE | RTEMS_NO_INHERIT_PRIORITY | - RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL, - 0, - &p->bufget_sema); - - if (rc != RTEMS_SUCCESSFUL) - { - free(p->bdbufs); - free(p->mallocd_bufs); - return rc; - } - - return RTEMS_SUCCESSFUL; -} - -/* bdbuf_release_pool -- - * Free resources allocated for buffer pool with specified number. - * - * PARAMETERS: - * pool - buffer pool number - * - * RETURNS: - * RTEMS_SUCCESSFUL - */ -static rtems_status_code -bdbuf_release_pool(rtems_bdpool_id pool) -{ - bdbuf_pool *p = bd_ctx.pool + pool; - rtems_semaphore_delete(p->bufget_sema); - free(p->bdbufs); - free(p->mallocd_bufs); - return RTEMS_SUCCESSFUL; -} - -/* rtems_bdbuf_init -- - * Prepare buffering layer to work - initialize buffer descritors - * and (if it is neccessary)buffers. Buffers will be allocated accoriding - * to the configuration table, each entry describes kind of block and - * amount requested. After initialization all blocks is placed into - * free elements lists. - * - * PARAMETERS: - * conf_table - pointer to the buffers configuration table - * size - number of entries in configuration table - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - */ -rtems_status_code -rtems_bdbuf_init(rtems_bdbuf_config *conf_table, int size) -{ - rtems_bdpool_id i; - rtems_status_code rc; - - if (size <= 0) - return RTEMS_INVALID_SIZE; - - bd_ctx.npools = size; - - /* - * Allocate memory for buffer pool descriptors - */ - bd_ctx.pool = calloc(size, sizeof(bdbuf_pool)); - if (bd_ctx.pool == NULL) - { - return RTEMS_NO_MEMORY; - } - - Chain_Initialize_empty(&bd_ctx.mod); - - /* Initialize buffer pools and roll out if something failed */ - for (i = 0; i < size; i++) - { - rc = bdbuf_initialize_pool(conf_table + i, i); - if (rc != RTEMS_SUCCESSFUL) - { - rtems_bdpool_id j; - for (j = 0; j < i - 1; j++) - { - bdbuf_release_pool(j); - } - return rc; - } - } - - /* Create buffer flush semaphore */ - rc = rtems_semaphore_create( - rtems_build_name('B', 'F', 'L', 'U'), 0, - RTEMS_FIFO | RTEMS_COUNTING_SEMAPHORE | RTEMS_NO_INHERIT_PRIORITY | - RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL, 0, - &bd_ctx.flush_sema); - if (rc != RTEMS_SUCCESSFUL) - { - for (i = 0; i < size; i++) - bdbuf_release_pool(i); - free(bd_ctx.pool); - return rc; - } - - /* Create and start swapout task */ - rc = rtems_task_create( - rtems_build_name('B', 'S', 'W', 'P'), - SWAPOUT_PRIORITY, - SWAPOUT_STACK_SIZE, - RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, - RTEMS_DEFAULT_ATTRIBUTES, - &bd_ctx.swapout_task); - if (rc != RTEMS_SUCCESSFUL) - { - rtems_semaphore_delete(bd_ctx.flush_sema); - for (i = 0; i < size; i++) - bdbuf_release_pool(i); - free(bd_ctx.pool); - return rc; - } - - rc = rtems_task_start(bd_ctx.swapout_task, bdbuf_swapout_task, 0); - if (rc != RTEMS_SUCCESSFUL) - { - rtems_task_delete(bd_ctx.swapout_task); - rtems_semaphore_delete(bd_ctx.flush_sema); - for (i = 0; i < size; i++) - bdbuf_release_pool(i); - free(bd_ctx.pool); - return rc; - } - - return RTEMS_SUCCESSFUL; -} - -/* find_or_assign_buffer -- - * Looks for buffer already assigned for this dev/block. If one is found - * obtain block buffer. If specified block already cached (i.e. there's - * block in the _modified_, or _recently_used_), return address - * of appropriate buffer descriptor and increment reference counter to 1. - * If block is not cached, allocate new buffer and return it. Data - * shouldn't be read to the buffer from media; buffer contains arbitrary - * data. This primitive may be blocked if there are no free buffer - * descriptors available and there are no unused non-modified (or - * synchronized with media) buffers available. - * - * PARAMETERS: - * device - device number (constructed of major and minor device number - * block - linear media block number - * ret_buf - address of the variable to store address of found descriptor - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - * - * SIDE EFFEECTS: - * bufget_sema may be obtained by this primitive - * - * NOTE: - * It is assumed that primitive invoked when thread preemption is disabled. - */ -static rtems_status_code -find_or_assign_buffer(disk_device *dd, - blkdev_bnum block, - bdbuf_buffer **ret_buf) -{ - bdbuf_buffer *bd_buf; - bdbuf_pool *bd_pool; - rtems_status_code rc; - dev_t device; - ISR_Level level; - - int blksize; - - device = dd->dev; - bd_pool = bd_ctx.pool + dd->pool; - blksize = dd->block_size; - -again: - /* Looking for buffer descriptor used for this dev/block. */ - bd_buf = avl_search(&bd_pool->tree, device, block); - - if (bd_buf == NULL) - { - /* Try to obtain semaphore without waiting first. It is the most - frequent case when reasonable number of buffers configured. If - it is failed, obtain semaphore blocking on it. In this case - it should be checked that appropriate buffer hasn't been loaded - by another thread, because this thread is preempted */ - rc = rtems_semaphore_obtain(bd_pool->bufget_sema, RTEMS_NO_WAIT, 0); - if (rc == RTEMS_UNSATISFIED) - { - rc = rtems_semaphore_obtain(bd_pool->bufget_sema, - RTEMS_WAIT, RTEMS_NO_TIMEOUT); - bd_buf = avl_search(&bd_pool->tree, device, block); - if (bd_buf != NULL) - rtems_semaphore_release(bd_pool->bufget_sema); - } - } - - if (bd_buf == NULL) - { - /* Assign new buffer descriptor */ - if (_Chain_Is_empty(&bd_pool->free)) - { - bd_buf = (bdbuf_buffer *)Chain_Get(&bd_pool->lru); - if (bd_buf != NULL) - { - int avl_result; - avl_result = avl_remove(&bd_pool->tree, bd_buf); - if (avl_result != 0) - { - rtems_fatal_error_occurred(BLKDEV_FATAL_BDBUF_CONSISTENCY); - return RTEMS_INTERNAL_ERROR; - } - } - } - else - { - bd_buf = (bdbuf_buffer *)Chain_Get(&(bd_pool->free)); - } - - if (bd_buf == NULL) - { - goto again; - } - else - { - bd_buf->dev = device; - bd_buf->block = block; -#ifdef AVL_GPL - bd_buf->avl.link[0] = NULL; - bd_buf->avl.link[1] = NULL; -#else - bd_buf->avl.left = NULL; - bd_buf->avl.right = NULL; -#endif - bd_buf->use_count = 1; - bd_buf->modified = bd_buf->actual = bd_buf->in_progress = FALSE; - bd_buf->status = RTEMS_SUCCESSFUL; - - if (avl_insert(&bd_pool->tree, bd_buf) != 0) - { - rtems_fatal_error_occurred(BLKDEV_FATAL_BDBUF_CONSISTENCY); - return RTEMS_INTERNAL_ERROR; - } - - *ret_buf = bd_buf; - - return RTEMS_SUCCESSFUL; - } - } - else - { - /* Buffer descriptor already assigned for this dev/block */ - if (bd_buf->use_count == 0) - { - /* If we are removing from lru list, obtain the bufget_sema - * first. If we are removing from mod list, obtain flush sema. - * It should be obtained without blocking because we know - * that our buffer descriptor is in the list. */ - if (bd_buf->modified) - { - rc = rtems_semaphore_obtain(bd_ctx.flush_sema, - RTEMS_NO_WAIT, 0); - } - else - { - rc = rtems_semaphore_obtain(bd_pool->bufget_sema, - RTEMS_NO_WAIT, 0); - } - /* It is possible that we couldn't obtain flush or bufget sema - * although buffer in the appropriate chain is available: - * semaphore may be released to swapout task, but this task - * actually did not start to process it. */ - if (rc == RTEMS_UNSATISFIED) - rc = RTEMS_SUCCESSFUL; - if (rc != RTEMS_SUCCESSFUL) - { - rtems_fatal_error_occurred(BLKDEV_FATAL_BDBUF_CONSISTENCY); - return RTEMS_INTERNAL_ERROR; - } - - /* Buffer descriptor is linked to the lru or mod chain. Remove - it from there. */ - Chain_Extract(&bd_buf->link); - } - bd_buf->use_count++; - while (bd_buf->in_progress != 0) - { - rtems_interrupt_disable(level); - _CORE_mutex_Seize(&bd_buf->transfer_sema, 0, TRUE, - WATCHDOG_NO_TIMEOUT, level); - } - - *ret_buf = bd_buf; - return RTEMS_SUCCESSFUL; - } -} - -/* rtems_bdbuf_get -- - * Obtain block buffer. If specified block already cached (i.e. there's - * block in the _modified_, or _recently_used_), return address - * of appropriate buffer descriptor and increment reference counter to 1. - * If block is not cached, allocate new buffer and return it. Data - * shouldn't be read to the buffer from media; buffer may contains - * arbitrary data. This primitive may be blocked if there are no free - * buffer descriptors available and there are no unused non-modified - * (or synchronized with media) buffers available. - * - * PARAMETERS: - * device - device number (constructed of major and minor device number) - * block - linear media block number - * bd - address of variable to store pointer to the buffer descriptor - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - * - * SIDE EFFECTS: - * bufget_sema semaphore obtained by this primitive. - */ -rtems_status_code -rtems_bdbuf_get(dev_t device, blkdev_bnum block, bdbuf_buffer **bd) -{ - rtems_status_code rc; - disk_device *dd; - disk_device *pdd; - preemption_key key; - - /* - * Convert logical dev/block to physical one - */ - dd = rtems_disk_lookup(device); - if (dd == NULL) - return RTEMS_INVALID_ID; - - if (block >= dd->size) - { - rtems_disk_release(dd); - return RTEMS_INVALID_NUMBER; - } - - pdd = dd->phys_dev; - block += dd->start; - rtems_disk_release(dd); - - DISABLE_PREEMPTION(key); - rc = find_or_assign_buffer(pdd, block, bd); - ENABLE_PREEMPTION(key); - - if (rc != RTEMS_SUCCESSFUL) - return rc; - - return RTEMS_SUCCESSFUL; -} - -/* bdbuf_initialize_transfer_sema -- - * Initialize transfer_sema mutex semaphore associated with buffer - * descriptor. - */ -static inline void -bdbuf_initialize_transfer_sema(bdbuf_buffer *bd_buf) -{ - CORE_mutex_Attributes mutex_attr; - mutex_attr.lock_nesting_behavior = CORE_MUTEX_NESTING_BLOCKS; - mutex_attr.only_owner_release = FALSE; - mutex_attr.discipline = CORE_MUTEX_DISCIPLINES_FIFO; - mutex_attr.priority_ceiling = 0; - - _CORE_mutex_Initialize(&bd_buf->transfer_sema, OBJECTS_NO_CLASS, - &mutex_attr, CORE_MUTEX_LOCKED, NULL); -} - -/* bdbuf_write_transfer_done -- - * Callout function. Invoked by block device driver when data transfer - * to device (write) is completed. This function may be invoked from - * interrupt handler. - * - * PARAMETERS: - * arg - arbitrary argument specified in block device request - * structure (in this case - pointer to the appropriate - * bdbuf_buffer buffer descriptor structure). - * status - I/O completion status - * error - errno error code if status != RTEMS_SUCCESSFUL - * - * RETURNS: - * none - */ -static void -bdbuf_write_transfer_done(void *arg, rtems_status_code status, int error) -{ - bdbuf_buffer *bd_buf = arg; - bd_buf->status = status; - bd_buf->error = error; - bd_buf->in_progress = bd_buf->modified = FALSE; - _CORE_mutex_Surrender(&bd_buf->transfer_sema, 0, NULL); - _CORE_mutex_Flush(&bd_buf->transfer_sema, NULL, - CORE_MUTEX_STATUS_SUCCESSFUL); -} - -/* bdbuf_read_transfer_done -- - * Callout function. Invoked by block device driver when data transfer - * from device (read) is completed. This function may be invoked from - * interrupt handler. - * - * PARAMETERS: - * arg - arbitrary argument specified in block device request - * structure (in this case - pointer to the appropriate - * bdbuf_buffer buffer descriptor structure). - * status - I/O completion status - * error - errno error code if status != RTEMS_SUCCESSFUL - * - * RETURNS: - * none - */ -static void -bdbuf_read_transfer_done(void *arg, rtems_status_code status, int error) -{ - bdbuf_buffer *bd_buf = arg; - bd_buf->status = status; - bd_buf->error = error; - _CORE_mutex_Surrender(&bd_buf->transfer_sema, 0, NULL); - _CORE_mutex_Flush(&bd_buf->transfer_sema, NULL, - CORE_MUTEX_STATUS_SUCCESSFUL); -} - -/* rtems_bdbuf_read -- - * (Similar to the rtems_bdbuf_get, except reading data from media) - * Obtain block buffer. If specified block already cached, return address - * of appropriate buffer and increment reference counter to 1. If block is - * not cached, allocate new buffer and read data to it from the media. - * This primitive may be blocked on waiting until data to be read from - * media, if there are no free buffer descriptors available and there are - * no unused non-modified (or synchronized with media) buffers available. - * - * PARAMETERS: - * device - device number (consists of major and minor device number) - * block - linear media block number - * bd - address of variable to store pointer to the buffer descriptor - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - * - * SIDE EFFECTS: - * bufget_sema and transfer_sema semaphores obtained by this primitive. - */ -rtems_status_code -rtems_bdbuf_read(dev_t device, - blkdev_bnum block, - bdbuf_buffer **bd) -{ - preemption_key key; - ISR_Level level; - - bdbuf_buffer *bd_buf; - rtems_status_code rc; - int result; - disk_device *dd; - disk_device *pdd; - blkdev_request1 req; - - dd = rtems_disk_lookup(device); - if (dd == NULL) - return RTEMS_INVALID_ID; - - if (block >= dd->size) - { - rtems_disk_release(dd); - return RTEMS_INVALID_NUMBER; - } - - pdd = dd->phys_dev; - block += dd->start; - - DISABLE_PREEMPTION(key); - rc = find_or_assign_buffer(pdd, block, &bd_buf); - - if (rc != RTEMS_SUCCESSFUL) - { - ENABLE_PREEMPTION(key); - rtems_disk_release(dd); - return rc; - } - - if (!bd_buf->actual) - { - bd_buf->in_progress = 1; - - req.req.req = BLKDEV_REQ_READ; - req.req.req_done = bdbuf_read_transfer_done; - req.req.done_arg = bd_buf; - req.req.start = block; - req.req.count = 1; - req.req.bufnum = 1; - req.req.bufs[0].length = dd->block_size; - req.req.bufs[0].buffer = bd_buf->buffer; - - bdbuf_initialize_transfer_sema(bd_buf); - result = dd->ioctl(device, BLKIO_REQUEST, &req); - if (result == -1) - { - bd_buf->status = RTEMS_IO_ERROR; - bd_buf->error = errno; - bd_buf->actual = FALSE; - } - else - { - rtems_interrupt_disable(level); - _CORE_mutex_Seize(&bd_buf->transfer_sema, 0, TRUE, - WATCHDOG_NO_TIMEOUT, level); - bd_buf->actual = TRUE; - } - bd_buf->in_progress = FALSE; - } - rtems_disk_release(dd); - - ENABLE_PREEMPTION(key); - - *bd = bd_buf; - - return RTEMS_SUCCESSFUL; -} - - -/* bdbuf_release -- - * Release buffer. Decrease buffer usage counter. If it is zero, further - * processing depends on modified attribute. If buffer was modified, it - * is inserted into mod chain and swapout task waken up. If buffer was - * not modified, it is returned to the end of lru chain making it available - * for further use. - * - * PARAMETERS: - * bd_buf - pointer to the released buffer descriptor. - * - * RETURNS: - * RTEMS_SUCCESSFUL if buffer released successfully, or error code if - * error occured. - * - * NOTE: - * This is internal function. It is assumed that task made non-preemptive - * before its invocation. - */ -static rtems_status_code -bdbuf_release(bdbuf_buffer *bd_buf) -{ - bdbuf_pool *bd_pool; - rtems_status_code rc = RTEMS_SUCCESSFUL; - - if (bd_buf->use_count <= 0) - return RTEMS_INTERNAL_ERROR; - - bd_pool = bd_ctx.pool + bd_buf->pool; - - bd_buf->use_count--; - - if (bd_buf->use_count == 0) - { - if (bd_buf->modified) - { - - /* Buffer was modified. Insert buffer to the modified buffers - * list and initiate flushing. */ - Chain_Append(&bd_ctx.mod, &bd_buf->link); - - /* Release the flush_sema */ - rc = rtems_semaphore_release(bd_ctx.flush_sema); - } - else - { - /* Buffer was not modified. Add this descriptor to the - * end of lru chain and make it available for reuse. */ - Chain_Append(&bd_pool->lru, &bd_buf->link); - rc = rtems_semaphore_release(bd_pool->bufget_sema); - } - } - return rc; -} - - -/* rtems_bdbuf_release -- - * Release buffer allocated before. This primitive decrease the - * usage counter. If it is zero, further destiny of buffer depends on - * 'modified' status. If buffer was modified, it is placed to the end of - * mod list and flush task waken up. If buffer was not modified, - * it is placed to the end of lru list, and bufget_sema released, allowing - * to reuse this buffer. - * - * PARAMETERS: - * bd_buf - pointer to the bdbuf_buffer structure previously obtained using - * get/read primitive. - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - * - * SIDE EFFECTS: - * flush_sema and bufget_sema semaphores may be released by this primitive. - */ -rtems_status_code -rtems_bdbuf_release(bdbuf_buffer *bd_buf) -{ - preemption_key key; - rtems_status_code rc = RTEMS_SUCCESSFUL; - - if (bd_buf == NULL) - return RTEMS_INVALID_ADDRESS; - - DISABLE_PREEMPTION(key); - - rc = bdbuf_release(bd_buf); - - ENABLE_PREEMPTION(key); - - return rc; -} - -/* rtems_bdbuf_release_modified -- - * Release buffer allocated before, assuming that it is _modified_ by - * it's owner. This primitive decrease usage counter for buffer, mark - * buffer descriptor as modified. If usage counter is 0, insert it at - * end of mod chain and release flush_sema semaphore to activate the - * flush task. - * - * PARAMETERS: - * bd_buf - pointer to the bdbuf_buffer structure previously obtained using - * get/read primitive. - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - * - * SIDE EFFECTS: - * flush_sema semaphore may be released by this primitive. - */ -rtems_status_code -rtems_bdbuf_release_modified(bdbuf_buffer *bd_buf) -{ - preemption_key key; - rtems_status_code rc = RTEMS_SUCCESSFUL; - - if (bd_buf == NULL) - return RTEMS_INVALID_ADDRESS; - - DISABLE_PREEMPTION(key); - - if (!bd_buf->modified) - { - bdbuf_initialize_transfer_sema(bd_buf); - } - bd_buf->modified = TRUE; - bd_buf->actual = TRUE; - rc = bdbuf_release(bd_buf); - - ENABLE_PREEMPTION(key); - - return rc; -} - -/* rtems_bdbuf_sync -- - * Wait until specified buffer synchronized with disk. Invoked on exchanges - * critical for data consistency on the media. This primitive mark owned - * block as modified, decrease usage counter. If usage counter is 0, - * block inserted to the mod chain and flush_sema semaphore released. - * Finally, primitives blocked on transfer_sema semaphore. - * - * PARAMETERS: - * bd_buf - pointer to the bdbuf_buffer structure previously obtained using - * get/read primitive. - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - * - * SIDE EFFECTS: - * Primitive may be blocked on transfer_sema semaphore. - */ -rtems_status_code -rtems_bdbuf_sync(bdbuf_buffer *bd_buf) -{ - preemption_key key; - ISR_Level level; - rtems_status_code rc = RTEMS_SUCCESSFUL; - - if (bd_buf == NULL) - return RTEMS_INVALID_ADDRESS; - - DISABLE_PREEMPTION(key); - - if (!bd_buf->modified) - { - bdbuf_initialize_transfer_sema(bd_buf); - } - bd_buf->modified = TRUE; - bd_buf->actual = TRUE; - - rc = bdbuf_release(bd_buf); - - if (rc == RTEMS_SUCCESSFUL) - { - rtems_interrupt_disable(level); - _CORE_mutex_Seize(&bd_buf->transfer_sema, 0, TRUE, - WATCHDOG_NO_TIMEOUT, level); - } - - ENABLE_PREEMPTION(key); - - return rc; -} - -/* rtems_bdbuf_syncdev -- - * Synchronize with disk all buffers containing the blocks belonging to - * specified device. - * - * PARAMETERS: - * dev - block device number - * - * RETURNS: - * RTEMS status code (RTEMS_SUCCESSFUL if operation completed successfully - * or error code if error is occured) - */ -rtems_status_code -rtems_bdbuf_syncdev(dev_t dev) -{ - preemption_key key; - ISR_Level level; - - bdbuf_buffer *bd_buf; - disk_device *dd; - bdbuf_pool *pool; - - dd = rtems_disk_lookup(dev); - if (dd == NULL) - return RTEMS_INVALID_ID; - - pool = bd_ctx.pool + dd->pool; - - DISABLE_PREEMPTION(key); - do { - bd_buf = avl_search_for_sync(&pool->tree, dd); - if (bd_buf != NULL /* && bd_buf->modified */) - { - rtems_interrupt_disable(level); - _CORE_mutex_Seize(&bd_buf->transfer_sema, 0, TRUE, - WATCHDOG_NO_TIMEOUT, level); - } - } while (bd_buf != NULL); - ENABLE_PREEMPTION(key); - return rtems_disk_release(dd); -} - -/* bdbuf_swapout_task -- - * Body of task which take care on flushing modified buffers to the - * disk. - */ -static rtems_task -bdbuf_swapout_task(rtems_task_argument unused) -{ - rtems_status_code rc; - int result; - ISR_Level level; - bdbuf_buffer *bd_buf; - bdbuf_pool *bd_pool; - disk_device *dd; - blkdev_request1 req; - - while (1) - { - rc = rtems_semaphore_obtain(bd_ctx.flush_sema, RTEMS_WAIT, 0); - if (rc != RTEMS_SUCCESSFUL) - { - rtems_fatal_error_occurred(BLKDEV_FATAL_BDBUF_SWAPOUT); - } - - bd_buf = (bdbuf_buffer *)Chain_Get(&bd_ctx.mod); - if (bd_buf == NULL) - { - /* It is possible that flush_sema semaphore will be released, but - * buffer to be removed from mod chain before swapout task start - * its processing. */ - continue; - } - - bd_buf->in_progress = TRUE; - bd_buf->use_count++; - bd_pool = bd_ctx.pool + bd_buf->pool; - dd = rtems_disk_lookup(bd_buf->dev); - - req.req.req = BLKDEV_REQ_WRITE; - req.req.req_done = bdbuf_write_transfer_done; - req.req.done_arg = bd_buf; - req.req.start = bd_buf->block + dd->start; - req.req.count = 1; - req.req.bufnum = 1; - req.req.bufs[0].length = dd->block_size; - req.req.bufs[0].buffer = bd_buf->buffer; - - /* transfer_sema initialized when bd_buf inserted in the mod chain - first time */ - result = dd->ioctl(dd->phys_dev->dev, BLKIO_REQUEST, &req); - - rtems_disk_release(dd); - - if (result == -1) - { - bd_buf->status = RTEMS_IO_ERROR; - bd_buf->error = errno; - /* Release tasks waiting on syncing this buffer */ - _CORE_mutex_Flush(&bd_buf->transfer_sema, NULL, - CORE_MUTEX_STATUS_SUCCESSFUL); - } - else - { - if (bd_buf->in_progress) - { - rtems_interrupt_disable(level); - _CORE_mutex_Seize(&bd_buf->transfer_sema, 0, TRUE, 0, level); - } - } - bd_buf->use_count--; - - /* Another task have chance to use this buffer, or even - * modify it. If buffer is not in use, insert it in appropriate chain - * and release semaphore */ - if (bd_buf->use_count == 0) - { - if (bd_buf->modified) - { - Chain_Append(&bd_ctx.mod, &bd_buf->link); - rc = rtems_semaphore_release(bd_ctx.flush_sema); - } - else - { - Chain_Append(&bd_pool->lru, &bd_buf->link); - rc = rtems_semaphore_release(bd_pool->bufget_sema); - } - } - } -} - -/* rtems_bdbuf_find_pool -- - * Find first appropriate buffer pool. This primitive returns the index - * of first buffer pool which block size is greater than or equal to - * specified size. - * - * PARAMETERS: - * block_size - requested block size - * pool - placeholder for result - * - * RETURNS: - * RTEMS status code: RTEMS_SUCCESSFUL if operation completed successfully, - * RTEMS_INVALID_SIZE if specified block size is invalid (not a power - * of 2), RTEMS_NOT_DEFINED if buffer pool for this or greater block size - * is not configured. - */ -rtems_status_code -rtems_bdbuf_find_pool(int block_size, rtems_bdpool_id *pool) -{ - rtems_bdpool_id i; - bdbuf_pool *p; - int cursize = INT_MAX; - rtems_bdpool_id curid = -1; - rtems_boolean found = FALSE; - int j; - - for (j = block_size; (j != 0) && ((j & 1) == 0); j >>= 1); - if (j != 1) - return RTEMS_INVALID_SIZE; - - for (i = 0, p = bd_ctx.pool; i < bd_ctx.npools; i++, p++) - { - if ((p->blksize >= block_size) && - (p->blksize < cursize)) - { - curid = i; - cursize = p->blksize; - found = TRUE; - } - } - - if (found) - { - if (pool != NULL) - *pool = curid; - return RTEMS_SUCCESSFUL; - } - else - { - return RTEMS_NOT_DEFINED; - } -} - -/* rtems_bdbuf_get_pool_info -- - * Obtain characteristics of buffer pool with specified number. - * - * PARAMETERS: - * pool - buffer pool number - * block_size - block size for which buffer pool is configured returned - * there - * blocks - number of buffers in buffer pool returned there - * - * RETURNS: - * RTEMS status code: RTEMS_SUCCESSFUL if operation completed successfully, - * RTEMS_INVALID_NUMBER if appropriate buffer pool is not configured. - * - * NOTE: - * Buffer pools enumerated contiguously starting from 0. - */ -rtems_status_code -rtems_bdbuf_get_pool_info(rtems_bdpool_id pool, int *block_size, - int *blocks) -{ - if (pool >= bd_ctx.npools) - return RTEMS_INVALID_NUMBER; - - if (block_size != NULL) - { - *block_size = bd_ctx.pool[pool].blksize; - } - - if (blocks != NULL) - { - *blocks = bd_ctx.pool[pool].nblks; - } - - return RTEMS_SUCCESSFUL; -} diff --git a/c/src/libblock/src/blkdev.c b/c/src/libblock/src/blkdev.c deleted file mode 100644 index d769dc45ca..0000000000 --- a/c/src/libblock/src/blkdev.c +++ /dev/null @@ -1,245 +0,0 @@ -/* - * blkdev.h - block device driver generic support - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Victor V. Vengerov - * - * @(#) $Id$ - */ - -#include - -#include -#include -#include - -#include "rtems/diskdevs.h" -#include "rtems/bdbuf.h" - -/* rtems_blkdev_generic_read -- - * Generic block device read primitive. Implemented using block device - * buffer management primitives. - */ -rtems_device_driver -rtems_blkdev_generic_read( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg) -{ - rtems_libio_rw_args_t *args = arg; - int block_size_log2; - int block_size; - char *buf; - unsigned int count; - unsigned int block; - unsigned int blkofs; - dev_t dev; - disk_device *dd; - - dev = rtems_filesystem_make_dev_t(major, minor); - dd = rtems_disk_lookup(dev); - if (dd == NULL) - return RTEMS_INVALID_NUMBER; - - block_size_log2 = dd->block_size_log2; - block_size = dd->block_size; - - buf = args->buffer; - count = args->count; - args->bytes_moved = 0; - - block = args->offset >> block_size_log2; - blkofs = args->offset & (block_size - 1); - - while (count > 0) - { - bdbuf_buffer *diskbuf; - int copy; - rtems_status_code rc; - - rc = rtems_bdbuf_read(dev, block, &diskbuf); - if (rc != RTEMS_SUCCESSFUL) - return rc; - copy = block_size - blkofs; - if (copy > count) - copy = count; - memcpy(buf, (char *)diskbuf->buffer + blkofs, copy); - rc = rtems_bdbuf_release(diskbuf); - args->bytes_moved += copy; - if (rc != RTEMS_SUCCESSFUL) - return rc; - count -= copy; - buf += copy; - blkofs = 0; - block++; - } - return RTEMS_SUCCESSFUL; -} - -/* rtems_blkdev_generic_write -- - * Generic block device write primitive. Implemented using block device - * buffer management primitives. - */ -rtems_device_driver -rtems_blkdev_generic_write( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg) -{ - rtems_libio_rw_args_t *args = arg; - int block_size_log2; - int block_size; - char *buf; - unsigned int count; - unsigned int block; - unsigned int blkofs; - dev_t dev; - rtems_status_code rc; - disk_device *dd; - - dev = rtems_filesystem_make_dev_t(major, minor); - dd = rtems_disk_lookup(dev); - if (dd == NULL) - return RTEMS_INVALID_NUMBER; - - block_size_log2 = dd->block_size_log2; - block_size = dd->block_size; - - buf = args->buffer; - count = args->count; - args->bytes_moved = 0; - - block = args->offset >> block_size_log2; - blkofs = args->offset & (block_size - 1); - - while (count > 0) - { - bdbuf_buffer *diskbuf; - int copy; - - if ((blkofs == 0) && (count > block_size)) - rc = rtems_bdbuf_get(dev, block, &diskbuf); - else - rc = rtems_bdbuf_read(dev, block, &diskbuf); - if (rc != RTEMS_SUCCESSFUL) - return rc; - - copy = block_size - blkofs; - if (copy > count) - copy = count; - memcpy((char *)diskbuf->buffer + blkofs, buf, copy); - args->bytes_moved += copy; - - rc = rtems_bdbuf_release_modified(diskbuf); - if (rc != RTEMS_SUCCESSFUL) - return rc; - - count -= copy; - buf += copy; - blkofs = 0; - block++; - } - return RTEMS_SUCCESSFUL; -} - -/* blkdev_generic_open -- - * Generic block device open primitive. - */ -rtems_device_driver -rtems_blkdev_generic_open( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg) -{ - dev_t dev; - disk_device *dd; - - dev = rtems_filesystem_make_dev_t(major, minor); - dd = rtems_disk_lookup(dev); - if (dd == NULL) - return RTEMS_INVALID_NUMBER; - - dd->uses++; - - rtems_disk_release(dd); - - return RTEMS_SUCCESSFUL; -} - - -/* blkdev_generic_close -- - * Generic block device close primitive. - */ -rtems_device_driver -rtems_blkdev_generic_close( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg) -{ - dev_t dev; - disk_device *dd; - - dev = rtems_filesystem_make_dev_t(major, minor); - dd = rtems_disk_lookup(dev); - if (dd == NULL) - return RTEMS_INVALID_NUMBER; - - dd->uses--; - - rtems_disk_release(dd); - - return RTEMS_SUCCESSFUL; -} - -/* blkdev_generic_ioctl -- - * Generic block device ioctl primitive. - */ -rtems_device_driver -rtems_blkdev_generic_ioctl( - rtems_device_major_number major, - rtems_device_minor_number minor, - void * arg) -{ - rtems_libio_ioctl_args_t *args = arg; - dev_t dev; - disk_device *dd; - int rc; - - dev = rtems_filesystem_make_dev_t(major, minor); - dd = rtems_disk_lookup(dev); - if (dd == NULL) - return RTEMS_INVALID_NUMBER; - - switch (args->command) - { - case BLKIO_GETBLKSIZE: - args->ioctl_return = dd->block_size; - break; - - case BLKIO_GETSIZE: - args->ioctl_return = dd->size; - break; - - case BLKIO_SYNCDEV: - rc = rtems_bdbuf_syncdev(dd->dev); - args->ioctl_return = (rc == RTEMS_SUCCESSFUL ? 0 : -1); - break; - - case BLKIO_REQUEST: - { - blkdev_request *req = args->buffer; - req->start += dd->start; - args->ioctl_return = dd->ioctl(dd->phys_dev->dev, args->command, - req); - break; - } - - default: - args->ioctl_return = dd->ioctl(dd->phys_dev->dev, args->command, - args->buffer); - break; - } - rtems_disk_release(dd); - - return RTEMS_SUCCESSFUL; -} diff --git a/c/src/libblock/src/diskdevs.c b/c/src/libblock/src/diskdevs.c deleted file mode 100644 index a9d6035e8b..0000000000 --- a/c/src/libblock/src/diskdevs.c +++ /dev/null @@ -1,631 +0,0 @@ -/* - * diskdevs.c - Physical and logical block devices (disks) support - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Victor V. Vengerov - * - * @(#) $Id$ - */ - - -#include -#include -#include -#include - -#include "rtems/diskdevs.h" -#include "rtems/bdbuf.h" - -#define DISKTAB_INITIAL_SIZE 32 - -/* Table of disk devices having the same major number */ -struct disk_device_table { - disk_device **minor; /* minor-indexed disk device table */ - int size; /* Number of entries in the table */ -}; - -/* Pointer to [major].minor[minor] indexed array of disk devices */ -static struct disk_device_table *disktab; - -/* Number of allocated entries in disktab table */ -static int disktab_size; - -/* Mutual exclusion semaphore for disk devices table */ -static rtems_id diskdevs_mutex; - -/* Flag meaning that disk I/O, buffering etc. already has been initialized. */ -static boolean disk_io_initialized = FALSE; - -/* diskdevs data structures protection flag. - * Normally, only table lookup operations performed. It is quite fast, so - * it is possible to done lookups when interrupts are disabled, avoiding - * obtaining the semaphore. This flags sets immediately after entering in - * mutex-protected section and cleared before leaving this section in - * "big" primitives like add/delete new device etc. Lookup function first - * disable interrupts and check this flag. If it is set, lookup function - * will be blocked on semaphore and lookup operation will be performed in - * semaphore-protected code. If it is not set (very-very frequent case), - * we can do lookup safely, enable interrupts and return result. - */ -static volatile rtems_boolean diskdevs_protected; - -/* create_disk_entry -- - * Return pointer to the disk_entry structure for the specified device, or - * create one if it is not exists. - * - * PARAMETERS: - * dev - device id (major, minor) - * - * RETURNS: - * pointer to the disk device descirptor entry, or NULL if no memory - * available for its creation. - */ -static disk_device * -create_disk_entry(dev_t dev) -{ - rtems_device_major_number major; - rtems_device_minor_number minor; - struct disk_device **d; - - rtems_filesystem_split_dev_t (dev, major, minor); - - if (major >= disktab_size) - { - struct disk_device_table *p; - int newsize; - int i; - newsize = disktab_size * 2; - if (major >= newsize) - newsize = major + 1; - p = realloc(disktab, sizeof(struct disk_device_table) * newsize); - if (p == NULL) - return NULL; - p += disktab_size; - for (i = disktab_size; i < newsize; i++, p++) - { - p->minor = NULL; - p->size = 0; - } - disktab_size = newsize; - } - - if ((disktab[major].minor == NULL) || - (minor >= disktab[major].size)) - { - int newsize; - disk_device **p; - int i; - int s = disktab[major].size; - - if (s == 0) - newsize = DISKTAB_INITIAL_SIZE; - else - newsize = s * 2; - if (minor >= newsize) - newsize = minor + 1; - - p = realloc(disktab[major].minor, sizeof(disk_device *) * newsize); - if (p == NULL) - return NULL; - disktab[major].minor = p; - p += s; - for (i = s; i < newsize; i++, p++) - *p = NULL; - disktab[major].size = newsize; - } - - d = disktab[major].minor + minor; - if (*d == NULL) - { - *d = calloc(1, sizeof(disk_device)); - } - return *d; -} - -/* get_disk_entry -- - * Get disk device descriptor by device number. - * - * PARAMETERS: - * dev - block device number - * - * RETURNS: - * Pointer to the disk device descriptor corresponding to the specified - * device number, or NULL if disk device with such number not exists. - */ -static inline disk_device * -get_disk_entry(dev_t dev) -{ - rtems_device_major_number major; - rtems_device_minor_number minor; - struct disk_device_table *dtab; - - rtems_filesystem_split_dev_t (dev, major, minor); - - if ((major >= disktab_size) || (disktab == NULL)) - return NULL; - - dtab = disktab + major; - - if ((minor >= dtab->size) || (dtab->minor == NULL)) - return NULL; - - return dtab->minor[minor]; -} - -/* create_disk -- - * Check that disk entry for specified device number is not defined - * and create it. - * - * PARAMETERS: - * dev - device identifier (major, minor numbers) - * name - character name of device (e.g. /dev/hda) - * disdev - placeholder for pointer to created disk descriptor - * - * RETURNS: - * RTEMS_SUCCESSFUL if disk entry successfully created, or - * error code if error occured (device already registered, - * no memory available). - */ -static rtems_status_code -create_disk(dev_t dev, char *name, disk_device **diskdev) -{ - disk_device *dd; - char *n; - - dd = get_disk_entry(dev); - if (dd != NULL) - { - return RTEMS_RESOURCE_IN_USE; - } - - if (name == NULL) - { - n = NULL; - } - else - { - int nlen = strlen(name) + 1; - n = malloc(nlen); - if (n == NULL) - return RTEMS_NO_MEMORY; - strncpy(n, name, nlen); - } - - dd = create_disk_entry(dev); - if (dd == NULL) - { - free(n); - return RTEMS_NO_MEMORY; - } - - dd->dev = dev; - dd->name = n; - - *diskdev = dd; - - return RTEMS_SUCCESSFUL; -} - -/* rtems_disk_create_phys -- - * Create physical disk entry. This function usually invoked from - * block device driver initialization code when physical device - * detected in the system. Device driver should provide ioctl handler - * to allow block device access operations. This primitive will register - * device in rtems (invoke rtems_io_register_name). - * - * PARAMETERS: - * dev - device identifier (major, minor numbers) - * block_size - size of disk block (minimum data transfer unit); must be - * power of 2 - * disk_size - number of blocks on device - * handler - IOCTL handler (function providing basic block input/output - * request handling BIOREQUEST and other device management - * operations) - * name - character name of device (e.g. /dev/hda) - * - * RETURNS: - * RTEMS_SUCCESSFUL if information about new physical disk added, or - * error code if error occured (device already registered, wrong block - * size value, no memory available). - */ -rtems_status_code -rtems_disk_create_phys(dev_t dev, int block_size, int disk_size, - block_device_ioctl handler, - char *name) -{ - int bs_log2; - int i; - disk_device *dd; - rtems_status_code rc; - rtems_bdpool_id pool; - rtems_device_major_number major; - rtems_device_minor_number minor; - - rtems_filesystem_split_dev_t (dev, major, minor); - - - for (bs_log2 = 0, i = block_size; (i & 1) == 0; i >>= 1, bs_log2++); - if ((bs_log2 < 9) || (i != 1)) /* block size < 512 or not power of 2 */ - return RTEMS_INVALID_NUMBER; - - rc = rtems_semaphore_obtain(diskdevs_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - if (rc != RTEMS_SUCCESSFUL) - return rc; - diskdevs_protected = TRUE; - - rc = rtems_bdbuf_find_pool(block_size, &pool); - if (rc != RTEMS_SUCCESSFUL) - { - diskdevs_protected = FALSE; - rtems_semaphore_release(diskdevs_mutex); - return rc; - } - - rc = create_disk(dev, name, &dd); - if (rc != RTEMS_SUCCESSFUL) - { - diskdevs_protected = FALSE; - rtems_semaphore_release(diskdevs_mutex); - return rc; - } - - dd->phys_dev = dd; - dd->uses = 0; - dd->start = 0; - dd->size = disk_size; - dd->block_size = block_size; - dd->block_size_log2 = bs_log2; - dd->ioctl = handler; - dd->pool = pool; - - rc = rtems_io_register_name(name, major, minor); - - diskdevs_protected = FALSE; - rtems_semaphore_release(diskdevs_mutex); - - return rc; -} - -/* rtems_disk_create_log -- - * Create logical disk entry. Logical disk is contiguous area on physical - * disk. Disk may be splitted to several logical disks in several ways: - * manually or using information stored in blocks on physical disk - * (DOS-like partition table, BSD disk label, etc). This function usually - * invoked from application when application-specific splitting are in use, - * or from generic code which handle different logical disk organizations. - * This primitive will register device in rtems (invoke - * rtems_io_register_name). - * - * PARAMETERS: - * dev - logical device identifier (major, minor numbers) - * phys - physical device (block device which holds this logical disk) - * identifier - * start - starting block number on the physical device - * size - logical disk size in blocks - * name - logical disk name - * - * RETURNS: - * RTEMS_SUCCESSFUL if logical device successfully added, or error code - * if error occured (device already registered, no physical device - * exists, logical disk is out of physical disk boundaries, no memory - * available). - */ -rtems_status_code -rtems_disk_create_log(dev_t dev, dev_t phys, int start, int size, char *name) -{ - disk_device *dd; - disk_device *pdd; - rtems_status_code rc; - rtems_device_major_number major; - rtems_device_minor_number minor; - - rtems_filesystem_split_dev_t (dev, major, minor); - - rc = rtems_semaphore_obtain(diskdevs_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - if (rc != RTEMS_SUCCESSFUL) - return rc; - diskdevs_protected = TRUE; - - pdd = get_disk_entry(phys); - if (pdd == NULL) - { - diskdevs_protected = FALSE; - rtems_semaphore_release(diskdevs_mutex); - return RTEMS_INVALID_NUMBER; - } - - rc = create_disk(dev, name, &dd); - if (rc != RTEMS_SUCCESSFUL) - { - diskdevs_protected = FALSE; - rtems_semaphore_release(diskdevs_mutex); - return rc; - } - - dd->phys_dev = pdd; - dd->uses = 0; - dd->start = start; - dd->size = size; - dd->block_size = pdd->block_size; - dd->block_size_log2 = pdd->block_size_log2; - dd->ioctl = pdd->ioctl; - - rc = rtems_io_register_name(name, major, minor); - - diskdevs_protected = FALSE; - rc = rtems_semaphore_release(diskdevs_mutex); - - return rc; -} - -/* rtems_disk_delete -- - * Delete physical or logical disk device. Device may be deleted if its - * use counter (and use counters of all logical devices - if it is - * physical device) equal to 0. When physical device deleted, - * all logical devices deleted inherently. Appropriate devices removed - * from "/dev" filesystem. - * - * PARAMETERS: - * dev - device identifier (major, minor numbers) - * - * RETURNS: - * RTEMS_SUCCESSFUL if block device successfully deleted, or error code - * if error occured (device is not defined, device is in use). - */ -rtems_status_code -rtems_disk_delete(dev_t dev) -{ - rtems_status_code rc; - int used; - rtems_device_major_number maj; - rtems_device_minor_number min; - - rc = rtems_semaphore_obtain(diskdevs_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - if (rc != RTEMS_SUCCESSFUL) - return rc; - diskdevs_protected = TRUE; - - /* Check if this device is in use -- calculate usage counter */ - used = 0; - for (maj = 0; maj < disktab_size; maj++) - { - struct disk_device_table *dtab = disktab + maj; - if (dtab != NULL) - { - for (min = 0; min < dtab->size; min++) - { - disk_device *dd = dtab->minor[min]; - if ((dd != NULL) && (dd->phys_dev->dev == dev)) - used += dd->uses; - } - } - } - - if (used != 0) - { - diskdevs_protected = FALSE; - rtems_semaphore_release(diskdevs_mutex); - return RTEMS_RESOURCE_IN_USE; - } - - /* Delete this device and all of its logical devices */ - for (maj = 0; maj < disktab_size; maj++) - { - struct disk_device_table *dtab = disktab +maj; - if (dtab != NULL) - { - for (min = 0; min < dtab->size; min++) - { - disk_device *dd = dtab->minor[min]; - if ((dd != NULL) && (dd->phys_dev->dev == dev)) - { - unlink(dd->name); - free(dd->name); - free(dd); - dtab->minor[min] = NULL; - } - } - } - } - - diskdevs_protected = FALSE; - rc = rtems_semaphore_release(diskdevs_mutex); - return rc; -} - -/* rtems_disk_lookup -- - * Find block device descriptor by its device identifier. - * - * PARAMETERS: - * dev - device identifier (major, minor numbers) - * - * RETURNS: - * pointer to the block device descriptor, or NULL if no such device - * exists. - */ -disk_device * -rtems_disk_lookup(dev_t dev) -{ - rtems_interrupt_level level; - disk_device *dd; - rtems_status_code rc; - - rtems_interrupt_disable(level); - if (diskdevs_protected) - { - rtems_interrupt_enable(level); - rc = rtems_semaphore_obtain(diskdevs_mutex, RTEMS_WAIT, - RTEMS_NO_TIMEOUT); - if (rc != RTEMS_SUCCESSFUL) - return NULL; - diskdevs_protected = TRUE; - dd = get_disk_entry(dev); - dd->uses++; - diskdevs_protected = FALSE; - rtems_semaphore_release(diskdevs_mutex); - return dd; - } - else - { - /* Frequent and quickest case */ - dd = get_disk_entry(dev); - dd->uses++; - rtems_interrupt_enable(level); - return dd; - } -} - -/* rtems_disk_release -- - * Release disk_device structure (decrement usage counter to 1). - * - * PARAMETERS: - * dd - pointer to disk device structure - * - * RETURNS: - * RTEMS_SUCCESSFUL - */ -rtems_status_code -rtems_disk_release(disk_device *dd) -{ - rtems_interrupt_level level; - rtems_interrupt_disable(level); - dd->uses--; - rtems_interrupt_enable(level); - return RTEMS_SUCCESSFUL; -} - -/* rtems_disk_next -- - * Disk device enumerator. Looking for device having device number larger - * than dev and return disk device descriptor for it. If there are no - * such device, NULL value returned. - * - * PARAMETERS: - * dev - device number (use -1 to start search) - * - * RETURNS: - * Pointer to the disk descriptor for next disk device, or NULL if all - * devices enumerated. - */ -disk_device * -rtems_disk_next(dev_t dev) -{ - rtems_device_major_number major; - rtems_device_minor_number minor; - struct disk_device_table *dtab; - - dev++; - rtems_filesystem_split_dev_t (dev, major, minor); - - if (major >= disktab_size) - return NULL; - - dtab = disktab + major; - while (TRUE) - { - if ((dtab == NULL) || (minor > dtab->size)) - { - major++; minor = 0; - if (major >= disktab_size) - return NULL; - dtab = disktab + major; - } - else if (dtab->minor[minor] == NULL) - { - minor++; - } - else - return dtab->minor[minor]; - } -} - -/* rtems_disk_initialize -- - * Initialization of disk device library (initialize all data structures, - * etc.) - * - * PARAMETERS: - * none - * - * RETURNS: - * RTEMS_SUCCESSFUL if library initialized, or error code if error - * occured. - */ -rtems_status_code -rtems_disk_io_initialize(void) -{ - rtems_status_code rc; - - if (disk_io_initialized) - return RTEMS_SUCCESSFUL; - - disktab_size = DISKTAB_INITIAL_SIZE; - disktab = calloc(disktab_size, sizeof(struct disk_device_table)); - if (disktab == NULL) - return RTEMS_NO_MEMORY; - - diskdevs_protected = FALSE; - rc = rtems_semaphore_create( - rtems_build_name('D', 'D', 'E', 'V'), 1, - RTEMS_FIFO | RTEMS_BINARY_SEMAPHORE | RTEMS_NO_INHERIT_PRIORITY | - RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL, 0, &diskdevs_mutex); - - if (rc != RTEMS_SUCCESSFUL) - { - free(disktab); - return rc; - } - - rc = rtems_bdbuf_init(rtems_bdbuf_configuration, - rtems_bdbuf_configuration_size); - - if (rc != RTEMS_SUCCESSFUL) - { - rtems_semaphore_delete(diskdevs_mutex); - free(disktab); - return rc; - } - - disk_io_initialized = 1; - return RTEMS_SUCCESSFUL; -} - -/* rtems_disk_io_done -- - * Release all resources allocated for disk device interface. - * - * PARAMETERS: - * none - * - * RETURNS: - * RTEMS_SUCCESSFUL if all resources released, or error code if error - * occured. - */ -rtems_status_code -rtems_disk_io_done(void) -{ - rtems_device_major_number maj; - rtems_device_minor_number min; - rtems_status_code rc; - - /* Free data structures */ - for (maj = 0; maj < disktab_size; maj++) - { - struct disk_device_table *dtab = disktab + maj; - if (dtab != NULL) - { - for (min = 0; min < dtab->size; min++) - { - disk_device *dd = dtab->minor[min]; - unlink(dd->name); - free(dd->name); - free(dd); - } - free(dtab); - } - } - free(disktab); - - rc = rtems_semaphore_release(diskdevs_mutex); - - /* XXX bdbuf should be released too! */ - disk_io_initialized = 0; - return rc; -} diff --git a/c/src/libblock/src/ramdisk.c b/c/src/libblock/src/ramdisk.c deleted file mode 100644 index 7be2eabcc8..0000000000 --- a/c/src/libblock/src/ramdisk.c +++ /dev/null @@ -1,225 +0,0 @@ -/* ramdisk.c -- RAM disk block device implementation - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Victor V. Vengerov - * - * @(#) $Id$ - */ - -#include -#include -#include -#include -#include -#include - -#include "rtems/blkdev.h" -#include "rtems/diskdevs.h" -#include "rtems/ramdisk.h" - -#define RAMDISK_DEVICE_BASE_NAME "/dev/ramdisk" - -/* Internal RAM disk descriptor */ -struct ramdisk { - int block_size; /* RAM disk block size */ - int block_num; /* Number of blocks on this RAM disk */ - void *area; /* RAM disk memory area */ - rtems_boolean initialized;/* RAM disk is initialized */ - rtems_boolean malloced; /* != 0, if memory allocated by malloc for this - RAM disk */ -}; - -static struct ramdisk *ramdisk; -static int nramdisks; - -/* ramdisk_read -- - * RAM disk READ request handler. This primitive copies data from RAM - * disk to supplied buffer and invoke the callout function to inform - * upper layer that reading is completed. - * - * PARAMETERS: - * req - pointer to the READ block device request info - * - * RETURNS: - * ioctl return value - */ -static int -ramdisk_read(struct ramdisk *rd, blkdev_request *req) -{ - char *from; - rtems_unsigned32 i; - blkdev_sg_buffer *sg; - rtems_unsigned32 remains; - - from = (char *)rd->area + (req->start * rd->block_size); - remains = rd->block_size * req->count; - sg = req->bufs; - for (i = 0; (remains > 0) && (i < req->bufnum); i++, sg++) - { - int count = sg->length; - if (count > remains) - count = remains; - memcpy(sg->buffer, from, count); - remains -= count; - } - req->req_done(req->done_arg, RTEMS_SUCCESSFUL, 0); - return 0; -} - -/* ramdisk_write -- - * RAM disk WRITE request handler. This primitive copies data from - * supplied buffer to RAM disk and invoke the callout function to inform - * upper layer that writing is completed. - * - * PARAMETERS: - * req - pointer to the WRITE block device request info - * - * RETURNS: - * ioctl return value - */ -static int -ramdisk_write(struct ramdisk *rd, blkdev_request *req) -{ - char *to; - rtems_unsigned32 i; - blkdev_sg_buffer *sg; - rtems_unsigned32 remains; - - to = (char *)rd->area + (req->start * rd->block_size); - remains = rd->block_size * req->count; - sg = req->bufs; - for (i = 0; (remains > 0) && (i < req->bufnum); i++, sg++) - { - int count = sg->length; - if (count > remains) - count = remains; - memcpy(to, sg->buffer, count); - remains -= count; - } - req->req_done(req->done_arg, RTEMS_SUCCESSFUL, 0); - return 0; -} - -/* ramdisk_ioctl -- - * IOCTL handler for RAM disk device. - * - * PARAMETERS: - * dev - device number (major, minor number) - * req - IOCTL request code - * argp - IOCTL argument - * - * RETURNS: - * IOCTL return value - */ -static int -ramdisk_ioctl(dev_t dev, int req, void *argp) -{ - switch (req) - { - case BLKIO_REQUEST: - { - rtems_device_minor_number minor; - blkdev_request *r = argp; - struct ramdisk *rd; - - minor = rtems_filesystem_dev_minor_t(dev); - if ((minor >= nramdisks) || !ramdisk[minor].initialized) - { - errno = ENODEV; - return -1; - } - - rd = ramdisk + minor; - - switch (r->req) - { - case BLKDEV_REQ_READ: - return ramdisk_read(rd, r); - - case BLKDEV_REQ_WRITE: - return ramdisk_write(rd, r); - - default: - errno = EBADRQC; - return -1; - } - break; - } - - default: - errno = EBADRQC; - return -1; - } -} - -/* ramdisk_initialize -- - * RAM disk device driver initialization. Run through RAM disk - * configuration information and configure appropriate RAM disks. - * - * PARAMETERS: - * major - RAM disk major device number - * minor - minor device number, not applicable - * arg - initialization argument, not applicable - * - * RETURNS: - * none - */ -rtems_device_driver -ramdisk_initialize( - rtems_device_major_number major, - rtems_device_minor_number minor, - void *arg) -{ - rtems_device_minor_number i; - rtems_ramdisk_config *c = rtems_ramdisk_configuration; - struct ramdisk *r; - rtems_status_code rc; - - rc = rtems_disk_io_initialize(); - if (rc != RTEMS_SUCCESSFUL) - return rc; - - r = ramdisk = calloc(rtems_ramdisk_configuration_size, - sizeof(struct ramdisk)); - - for (i = 0; i < rtems_ramdisk_configuration_size; i++, c++, r++) - { - dev_t dev = rtems_filesystem_make_dev_t(major, i); - char name[sizeof(RAMDISK_DEVICE_BASE_NAME "0123456789")]; - snprintf(name, sizeof(name), RAMDISK_DEVICE_BASE_NAME "%d", i); - r->block_size = c->block_size; - r->block_num = c->block_num; - if (c->location == NULL) - { - r->malloced = TRUE; - r->area = malloc(r->block_size * r->block_num); - if (r->area == NULL) /* No enough memory for this disk */ - { - r->initialized = FALSE; - continue; - } - else - { - r->initialized = TRUE; - } - } - else - { - r->malloced = FALSE; - r->initialized = TRUE; - r->area = c->location; - } - rc = rtems_disk_create_phys(dev, c->block_size, c->block_num, - ramdisk_ioctl, name); - if (rc != RTEMS_SUCCESSFUL) - { - if (r->malloced) - { - free(r->area); - } - r->initialized = FALSE; - } - } - nramdisks = rtems_ramdisk_configuration_size; - return RTEMS_SUCCESSFUL; -} diff --git a/c/src/libfs/.cvsignore b/c/src/libfs/.cvsignore deleted file mode 100644 index ea6e093b99..0000000000 --- a/c/src/libfs/.cvsignore +++ /dev/null @@ -1,16 +0,0 @@ -Makefile -Makefile.in -aclocal.m4 -autom4te.cache -config.cache -config.guess -config.log -config.status -config.sub -configure -depcomp -install-sh -missing -mkinstalldirs -config.h* -stamp-h* diff --git a/c/src/libfs/ChangeLog b/c/src/libfs/ChangeLog deleted file mode 100644 index 2fd4267714..0000000000 --- a/c/src/libfs/ChangeLog +++ /dev/null @@ -1,323 +0,0 @@ -2002-04-06 Ralf Corsepius - - * src/imfs/imfs_getchild.c: include . - * src/imfs/imfs_gtkn.c: Include . - * src/imfs/ioman.c: Include . - * src/imfs/linearfile.c: Include . - * src/imfs/memfile.c: Include . - -2001-04-04 Joel Sherrill - - * src/dosfs/Makefile.am: Per PR129 do not install as many files - to the $(includedir). - -2002-04-04 Ralf Corsepius - - * src/dosfs/fat.h: Include . - Remove DBG1 and DBG2 (unused). - -2002-04-04 Ralf Corsepius - - * Per PR169. - * src/dosfs/config.h.in, src/dosfs/stamp-h2.in: Removed from CVS. - - -2002-03-27 Ralf Corsepius - - * src/dosfs/fat_file.c: Remove bsp.h. - fat_file_write(.. const char*buf ..). - * src/dosfs/fat_file.h: fat_file_write(.. const char*buf ..). - -2002-03-27 Ralf Corsepius - - * configure.ac: - AC_INIT(package,_RTEMS_VERSION,_RTEMS_BUGS). - AM_INIT_AUTOMAKE([no-define foreign 1.6]). - * src/dosfs/Makefile.am: Remove AUTOMAKE_OPTIONS. - * src/Makefile.am: Remove AUTOMAKE_OPTIONS. - * src/imfs/Makefile.am: Remove AUTOMAKE_OPTIONS. - * Makefile.am: Remove AUTOMAKE_OPTIONS. - * wrapup/Makefile.am: Remove AUTOMAKE_OPTIONS. - -2002-03-16 Ralf Corsepius - - Addressing PR 140. - * src/dosfs/config.h.in: Removed. - * src/dosfs/stamp-h2.in: Removed. - * .cvsignore: Add config.h*, stamp-h*. - * configure.ac: Remove AC_SRC_DIR(.../dosfs.h). - Remove AM_CONFIG_HEADER(src/dosfs/config.h). - Remove AM_CONFIG_HEADER(src/imfs/config.h). - Add AM_CONFIG_HEADER(config.h). - * src/dosfs/Makefile.am: INCLUDES = -I../.. . - * src/imfs/Makefile.am: INCLUDES = -I../.. . - -2002-03-14 Ralf Corsepius - - Reported and tracked as PR130. - * src/dosfs/Makefile.am: Reworked, Disable dosfs for UNIX. - * wrapup/Makefile.am: Disable dosfs for UNIX. - -2001-03-01 Joel Sherrill - - * src/imfs/.cvsignore: Added stamp-h1.in - -2002-02-28 Victor V. Vengerov - - * DOS filesystem including FAT12, FAT16, and FAT32 support submitted. - * src/dosfs, src/dosfs/Makefile.am, src/dosfs/stamp-h2.in, - src/dosfs/config.h.in, src/dosfs/dosfs.h, src/dosfs/fat.c, - src/dosfs/fat.h, src/dosfs/fat_fat_operations.c, - src/dosfs/fat_fat_operations.h, src/dosfs/fat_file.c, - src/dosfs/fat_file.h, src/dosfs/msdos.h, src/dosfs/msdos_create.c, - src/dosfs/msdos_dir.c, src/dosfs/msdos_eval.c, src/dosfs/msdos_file.c, - src/dosfs/msdos_free.c, src/dosfs/msdos_fsunmount.c, - src/dosfs/msdos_handlers_dir.c, src/dosfs/msdos_handlers_file.c, - src/dosfs/msdos_init.c, src/dosfs/msdos_initsupp.c, - src/dosfs/msdos_misc.c, src/dosfs/msdos_mknod.c, - src/dosfs/msdos_node_type.c, src/dosfs/.cvsignore: New files. - * configure.ac, src/Makefile.am, wrapup/Makefile.am: Modified to - reflect addition. - -2002-01-07 Ralf Corsepius - - * src/imfs/imfs_load_tar.c: Add include . - Add include . Add include . - * src/imfs/imfs_rmnod.c: Add include . - -2002-01-04 Ralf Corsepius - - * src/imfs/imfs_eval.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/memfile.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs_readlink.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs_unlink.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs_link.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs_chown.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/ioman.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs_mount.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs_directory.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs_stat.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs_fchmod.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs_symlink.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs_mknod.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/linearfile.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs_unmount.c: Include . - Apply rtems_set_errno_and_return_minus_one. - * src/imfs/imfs.h: Apply rtems_set_errno_and_return_minus_one. - Comment out increment_and_check_linkcounts. - -2001-11-27 Ralf Corsepius - - * wrapup/Makefile.am: Remove HAS_IMFS. - -2001-11-26 Ralf Corsepius - - * src/imfs/Makefile.am: Cleanup. - -2001-11-07 Jennifer Averett - - Reported by Ibragimov Ilya and tracked as PR49. - * src/imfs/imfs_directory.c: Do not calculate the offset twice. - -2001-10-26 Victor V. Vengerov - - * src/imfs/imfs_load_tar.c: Minor modification so this will - compile with gcc-2.95.3 with the arguments "-m5200 -O4". - -2001-10-16 Chris Johns - - * imfs/imfs_load_tar.c: Changed the code around to remove an - internal compiler error on the Coldfire target. - -2001-10-11 Ralf Corsepius - - * .cvsignore: Add autom4te.cache for autoconf > 2.52. - * configure.in: Remove. - * configure.ac: New file, generated from configure.in by autoupdate. - -2001-10-10 Joel Sherrill - - * src/imfs/imfs_getchild.c: Correct length of static string - as reported by Ibragimov Ilya . - -2001-09-28 Ralf Corsepius - - * src/imfs/Makefile.am: Use 'PREINSTALL_FILES ='. - -2001-09-22 Ralf Corsepius - - * src/imfs/Makefile.am: Revamp INCLUDES handling to make automake-1.5 - happy. - -2001-08-09 Fernando-Ruiz Casas - - * src/imfs/imfs_eval.c: The CD_UP problem in imfs_eval has been - touched. The order of the questions is the key. - -2001-07-06 Thomas Doerfler - - * src/imfs/deviceio.c: Make sure errno gets set to reflect - the status from the driver. - -2001-05-25 Joel Sherrill - - * src/imfs/imfs_initsupp.c: Create the root node with the - desired permissions. Nodes should be created with the right - permissions because chmod() is not supported by the miniIMFS - so changing after creation is not possible. - -2001-04-27 Ralf Corsepius - - * configure.in: Add [-ansi -fasm] to RTEMS_PROG_CC_FOR_TARGET. - -2001-04-24 Joel Sherrill - - * src/imfs/memfile.c (memfile_open): Did not set iop->size - and thus the value was incorrect. Before this field was cleared, - this resulted in the value from the last time that IOP was used - being still in place. Discovered by Andrew Bythell - . - -2001-04-20 Joel Sherrill - - * src/imfs/imfs_debug.c (IMFS_print_jnode): Modified to print - only information that does not vary based on target or memory - configuration. The old prints are still there in case they - are needed in the future to debug. Printing target dependent - addresses makes the test output vary by target unnecessarily. - -2001-03-23 Joel Sherrill - - * src/imfs/memfile.c: Reapply fix from bug report from - Jose Sturniolo where NULL pointer - was dereferenced when freeing a triply indirect file. - The fix was applied to the 4.5 release branch and not - the development branch. - -2001-02-03 Ralf Corsepius - - * src/imfs/Makefile.am: Apply include_*HEADERS instead of H_FILES. - -2001-01-16 Ralf Corsepius - - * configure.in: Add src/imfs/config.h - * src/imfs/Makefile.am: Add INCLUDES += -I. to pickup config.h - * src/imfs/.cvsignore: Add config.h and stamp-h - * src/imfs/*.c: Add config.h support. - -2001-01-12 Jake Janovetz - - * src/imfs/imfs.h, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c, - src/imfs/imfs_eval.c, src/imfs/imfs_fchmod.c, - src/imfs/imfs_handlers_memfile.c, src/imfs/imfs_init.c, - src/imfs/imfs_initsupp.c, src/imfs/imfs_stat.c, src/imfs/memfile.c, - src/imfs/miniimfs_init.c: Final developmental update to "tarfs". - When rtems_tarfs_load() is called, it checks the permissions - on each file. If there is write permission, it just creates a - standard file using "creat()" and therefore, uses the IMFS MEMORY_FILE. - If there is no write permission, it creates a LINEAR_FILE node - with the appropriate properties. If the permission is ever changed - to writeable, IMFS_fchmod converts it to a regular memory file. - -2000-12-12 Jake Janovetz - - * src/imfs/linearfile.c, src/imfs/imfs_load_tar.c: New files. - * src/imfs/Makefile.am, src/imfs/imfs.h, - src/imfs/imfs_creat.c, src/imfs/imfs_debug.c, - src/imfs/imfs_eval.c, src/imfs/imfs_handlers_memfile.c, - src/imfs/imfs_init.c, src/imfs/imfs_initsupp.c, - src/imfs/imfs_stat.c, src/imfs/miniimfs_init.c: Added "tarfs". - This is not really a tar filesystem. It is a way to load a tar - image into the IMFS but actually leave bulky file contents in the - original tar image. It essentially adds the linear file type and - associated support and a loader routine. - -2000-11-28 Joel Sherrill - - * src/imfs/memfile.c: Bug report from Sturniolo Jose - where NULL pointer was dereferenced. - -2000-11-17 Jennifer Averret - - * src/imfs/imfs_eval.c: Always return imaginary node at mount points. - -2000-11-09 Ralf Corsepius - - * Makefile.am: Use ... instead of RTEMS_TOPdir in ACLOCAL_AMFLAGS. - -2000-11-02 Ralf Corsepius - - * Makefile.am: Switch to ACLOCAL_AMFLAGS = -I $(RTEMS_TOPdir)/aclocal. - -2000-11-01 Joel Sherrill - - * src/imfs/Makefile.am, src/imfs/deviceio.c, src/imfs/imfs_chown.c, - src/imfs/imfs_config.c, src/imfs/imfs_creat.c, src/imfs/imfs_debug.c, - src/imfs/imfs_directory.c, src/imfs/imfs_eval.c, src/imfs/imfs_fchmod.c, - src/imfs/imfs_free.c, src/imfs/imfs_fsunmount.c, src/imfs/imfs_gtkn.c, - src/imfs/imfs_init.c, src/imfs/imfs_initsupp.c, src/imfs/imfs_link.c, - src/imfs/imfs_mknod.c, src/imfs/imfs_mount.c, src/imfs/imfs_readlink.c, - src/imfs/imfs_rmnod.c, src/imfs/imfs_stat.c, src/imfs/imfs_symlink.c, - src/imfs/imfs_unixstub.c, src/imfs/imfs_unlink.c, - src/imfs/imfs_unmount.c, src/imfs/imfs_utime.c, src/imfs/ioman.c, - src/imfs/memfile.c, src/imfs/miniimfs_init.c: - assoc.h, error.h, libio_.h, libio.h, and libcsupport.h moved - from libc to lib/include/rtems and now must be referenced as - . Now we do not have to reach up and over to - libc to pick them up. - -2000-10-24 Joel Sherrill - - * src/imfs/imfs_config.c: New file containing IMFS configuration - information split from libc/base_fs.c. - * src/imfs/ioman.c: New file. Moved from lib/libc. Missed previously. - * src/imfs/Makefile.am: Added imfs_config.c and ioman.c. - -2000-10-24 Ralf Corsepius - - * Makefile.am, configure.in: Introduce GNU canonicalization to libfs/. - The approach is currently a bit of a hack as GNU canonicalization - does not support the per-BSP build some of the other directories - require. As more of the tree is converted, this will become less - of an issue. - -2000-10-19 Joel Sherrill - - * .cvsignore, src/.cvsignore, src/imfs/.cvsignore, wrapup/.cvsignore: - New files. - -2000-10-18 Chris Johns - - * libfs created. - * src, src/imfs, wrapup: New directories. - * ChangeLog, Makefile.am, README, configure.in, src/Makefile.am, - wrapup/Makefile.am: New files. - * src/imfs/deviceio.c, src/imfs/imfs_getchild.c, - src/imfs/imfs_readlink.c, src/imfs/imfs.h, src/imfs/imfs_gtkn.c, - src/imfs/imfs_rmnod.c, src/imfs/imfs_chown.c, - src/imfs/imfs_handlers_device.c, src/imfs/imfs_stat.c, - src/imfs/imfs_creat.c, src/imfs/imfs_handlers_directory.c, - src/imfs/imfs_symlink.c, src/imfs/imfs_debug.c, - src/imfs/imfs_handlers_link.c, src/imfs/imfs_unixstub.c, - src/imfs/imfs_directory.c, src/imfs/imfs_handlers_memfile.c, - src/imfs/imfs_unlink.c, src/imfs/imfs_eval.c, src/imfs/imfs_init.c, - src/imfs/imfs_unmount.c, src/imfs/imfs_fchmod.c, - src/imfs/imfs_initsupp.c, src/imfs/imfs_utime.c, src/imfs/imfs_fcntl.c, - src/imfs/imfs_link.c, src/imfs/memfile.c, src/imfs/imfs_fdatasync.c, - src/imfs/imfs_mknod.c, src/imfs/miniimfs_init.c, src/imfs/imfs_free.c, - src/imfs/imfs_mount.c, src/imfs/imfs_fsunmount.c, src/imfs/imfs_ntype.c: - New files. Moved from libc. diff --git a/c/src/libfs/Makefile.am b/c/src/libfs/Makefile.am deleted file mode 100644 index da1442fcfc..0000000000 --- a/c/src/libfs/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -## -## $Id$ -## - -ACLOCAL_AMFLAGS = -I ../../../aclocal - -SUBDIRS = src wrapup - -EXTRA_DIST = README - -include $(top_srcdir)/../../../automake/subdirs.am -include $(top_srcdir)/../../../automake/local.am diff --git a/c/src/libfs/README b/c/src/libfs/README deleted file mode 100644 index 7409b93dca..0000000000 --- a/c/src/libfs/README +++ /dev/null @@ -1,13 +0,0 @@ -# -# $Id$ -# - -This directory contains for the "file system" library. All supported -file systems live under this tree. - -Currently the only supported file systems in this library are the IMFS -and miniIMFS. The TFTP client filesystem is part of the libnetworking -library. - ---Chris Johns and Joel Sherrill -18 October 2000 diff --git a/c/src/libfs/configure.ac b/c/src/libfs/configure.ac deleted file mode 100644 index 5451ca5e3a..0000000000 --- a/c/src/libfs/configure.ac +++ /dev/null @@ -1,39 +0,0 @@ -## Process this file with autoconf to produce a configure script. -## -## $Id$ - -AC_PREREQ(2.52) -AC_INIT([rtems-c-src-libfs],[_RTEMS_VERSION],[rtems-bugs@OARcorp.com]) -AC_CONFIG_SRCDIR([src/imfs/imfs.h]) - -RTEMS_TOP(../../..) -AC_CONFIG_AUX_DIR(../../..) - -RTEMS_CANONICAL_TARGET_CPU - -AM_INIT_AUTOMAKE([no-define foreign 1.6]) -AM_MAINTAINER_MODE - -RTEMS_ENABLE_BARE - -RTEMS_ENV_RTEMSBSP - -RTEMS_CHECK_CPU -RTEMS_CANONICAL_HOST - -RTEMS_PROJECT_ROOT - -RTEMS_PROG_CC_FOR_TARGET([-ansi -fasm]) -RTEMS_CANONICALIZE_TOOLS - -AM_CONDITIONAL(UNIX,test x"$RTEMS_CPU" = x"unix") -AM_CONFIG_HEADER(config.h) - -# Explicitly list all Makefiles here -AC_CONFIG_FILES([Makefile -src/Makefile -src/imfs/Makefile -src/dosfs/Makefile -wrapup/Makefile -]) -AC_OUTPUT diff --git a/c/src/libfs/src/.cvsignore b/c/src/libfs/src/.cvsignore deleted file mode 100644 index 282522db03..0000000000 --- a/c/src/libfs/src/.cvsignore +++ /dev/null @@ -1,2 +0,0 @@ -Makefile -Makefile.in diff --git a/c/src/libfs/src/Makefile.am b/c/src/libfs/src/Makefile.am deleted file mode 100644 index 10582f188c..0000000000 --- a/c/src/libfs/src/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -## -## $Id$ -## - - -SUBDIRS = imfs dosfs - -include $(top_srcdir)/../../../automake/subdirs.am -include $(top_srcdir)/../../../automake/local.am diff --git a/c/src/libfs/src/dosfs/.cvsignore b/c/src/libfs/src/dosfs/.cvsignore deleted file mode 100644 index 7bb609bf24..0000000000 --- a/c/src/libfs/src/dosfs/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -Makefile -Makefile.in -config.h -config.h.in -stamp-h -stamp-h.in diff --git a/c/src/libfs/src/dosfs/Makefile.am b/c/src/libfs/src/dosfs/Makefile.am deleted file mode 100644 index ad5e898689..0000000000 --- a/c/src/libfs/src/dosfs/Makefile.am +++ /dev/null @@ -1,55 +0,0 @@ -## -## $Id$ -## - - -include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg -include $(top_srcdir)/../../../automake/compile.am -include $(top_srcdir)/../../../automake/lib.am - -INCLUDES = -I../.. - -AM_CFLAGS += $(LIBC_DEFINES) - -FATFS_C_FILES = fat.c fat_fat_operations.c fat_file.c - -DOSFS_C_FILES = msdos_create.c msdos_dir.c msdos_eval.c msdos_file.c \ - msdos_free.c msdos_fsunmount.c msdos_handlers_dir.c \ - msdos_handlers_file.c msdos_init.c msdos_initsupp.c \ - msdos_misc.c msdos_mknod.c msdos_node_type.c - -if !UNIX -LIBNAME = libdosfs -LIB = ${ARCH}/${LIBNAME}.a - -C_FILES = $(FATFS_C_FILES) $(DOSFS_C_FILES) - -C_O_FILES = $(C_FILES:%.c=${ARCH}/%.o) - -include_HEADERS = dosfs.h - -H_FILES = $(PROJECT_INCLUDE) \ - $(include_HEADERS:%=$(PROJECT_INCLUDE)/%) - -$(PROJECT_INCLUDE): - @$(mkinstalldirs) $@ - -$(PROJECT_INCLUDE)/%.h: %.h - $(INSTALL_DATA) $< $@ - -OBJS = $(C_O_FILES) - -# -# Add local stuff here using += -# -all-local: ${ARCH} $(LIB) - -$(LIB): ${OBJS} - $(make-library) -endif - -TMPINSTALL_FILES += $(H_FILES) - -EXTRA_DIST = $(DOSFS_C_FILES) $(FATFS_C_FILES) - -include $(top_srcdir)/../../../automake/local.am diff --git a/c/src/libfs/src/dosfs/dosfs.h b/c/src/libfs/src/dosfs/dosfs.h deleted file mode 100644 index 4cea929d4c..0000000000 --- a/c/src/libfs/src/dosfs/dosfs.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * dosfs.h - * - * Application interface to MSDOS filesystem. - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ -#ifndef __DOSFS_DOSFS_H__ -#define __DOSFS_DOSFS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -extern rtems_filesystem_operations_table msdos_ops; - -#ifdef __cplusplus -} -#endif - -#endif /* __DOSFS_DOSFS_H__ */ diff --git a/c/src/libfs/src/dosfs/fat.c b/c/src/libfs/src/dosfs/fat.c deleted file mode 100644 index 852c104781..0000000000 --- a/c/src/libfs/src/dosfs/fat.c +++ /dev/null @@ -1,695 +0,0 @@ -/* - * fat.c - * - * Low-level operations on a volume with FAT filesystem - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * @(#) $Id$ - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fat.h" - -/* _fat_block_read -- - * This function reads 'count' bytes from device filesystem is mounted on, - * starts at 'start+offset' position where 'start' computed in sectors - * and 'offset' is offset inside sector (reading may cross sectors - * boundary; in this case assumed we want to read sequential sector(s)) - * - * PARAMETERS: - * mt_entry - mount table entry - * start - sector num to start read from - * offset - offset inside sector 'start' - * count - count of bytes to read - * buff - buffer provided by user - * - * RETURNS: - * bytes read on success, or -1 if error occured - * and errno set appropriately - */ -ssize_t -_fat_block_read( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 start, - unsigned32 offset, - unsigned32 count, - void *buff - ) -{ - int rc = RC_OK; - register fat_fs_info_t *fs_info = mt_entry->fs_info; - ssize_t cmpltd = 0; - unsigned32 blk = start; - unsigned32 ofs = offset; - bdbuf_buffer *block = NULL; - unsigned32 c = 0; - - while (count > 0) - { - rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_READ, &block); - if (rc != RC_OK) - return rc; - - c = MIN(count, (fs_info->vol.bps - ofs)); - memcpy((buff + cmpltd), (block->buffer + ofs), c); - - count -= c; - cmpltd += c; - blk++; - ofs = 0; - } - return cmpltd; -} - -/* _fat_block_write -- - * This function write 'count' bytes to device filesystem is mounted on, - * starts at 'start+offset' position where 'start' computed in sectors - * and 'offset' is offset inside sector (writing may cross sectors - * boundary; in this case assumed we want to write sequential sector(s)) - * - * PARAMETERS: - * mt_entry - mount table entry - * start - sector num to start read from - * offset - offset inside sector 'start' - * count - count of bytes to write - * buff - buffer provided by user - * - * RETURNS: - * bytes written on success, or -1 if error occured - * and errno set appropriately - */ -ssize_t -_fat_block_write( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 start, - unsigned32 offset, - unsigned32 count, - const void *buff) -{ - int rc = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - ssize_t cmpltd = 0; - unsigned32 blk = start; - unsigned32 ofs = offset; - bdbuf_buffer *block = NULL; - unsigned32 c = 0; - - while(count > 0) - { - c = MIN(count, (fs_info->vol.bps - ofs)); - - if (c == fs_info->vol.bps) - rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_GET, &block); - else - rc = fat_buf_access(fs_info, blk, FAT_OP_TYPE_READ, &block); - if (rc != RC_OK) - return rc; - - memcpy((block->buffer + ofs), (buff + cmpltd), c); - - fat_buf_mark_modified(fs_info); - - count -= c; - cmpltd +=c; - blk++; - ofs = 0; - } - return cmpltd; -} - - - - -/* fat_cluster_read -- - * wrapper for reading a whole cluster at once - * - * PARAMETERS: - * mt_entry - mount table entry - * cln - number of cluster to read - * buff - buffer provided by user - * - * RETURNS: - * bytes read on success, or -1 if error occured - * and errno set appropriately - */ -ssize_t -fat_cluster_read( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - void *buff - ) -{ - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 fsec = 0; - - fsec = fat_cluster_num_to_sector_num(mt_entry, cln); - - return _fat_block_read(mt_entry, fsec, 0, - fs_info->vol.spc << fs_info->vol.sec_log2, buff); -} - -/* fat_cluster_write -- - * wrapper for writting a whole cluster at once - * - * PARAMETERS: - * mt_entry - mount table entry - * cln - number of cluster to write - * buff - buffer provided by user - * - * RETURNS: - * bytes written on success, or -1 if error occured - * and errno set appropriately - */ -ssize_t -fat_cluster_write( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - const void *buff - ) -{ - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 fsec = 0; - - fsec = fat_cluster_num_to_sector_num(mt_entry, cln); - - return _fat_block_write(mt_entry, fsec, 0, - fs_info->vol.spc << fs_info->vol.sec_log2, buff); -} - -/* fat_init_volume_info -- - * Get inforamtion about volume on which filesystem is mounted on - * - * PARAMETERS: - * mt_entry - mount table entry - * - * RETURNS: - * RC_OK on success, or -1 if error occured - * and errno set appropriately - */ -int -fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry) -{ - int rc = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - register fat_vol_t *vol = &fs_info->vol; - unsigned32 data_secs = 0; - char boot_rec[FAT_MAX_BPB_SIZE]; - char fs_info_sector[FAT_USEFUL_INFO_SIZE]; - ssize_t ret = 0; - int fd; - struct stat stat_buf; - int i = 0; - - rc = stat(mt_entry->dev, &stat_buf); - if (rc == -1) - return rc; - - /* rtmes feature: no block devices, all are character devices */ - if (!S_ISCHR(stat_buf.st_mode)) - set_errno_and_return_minus_one(ENOTBLK); - - /* check that device is registred as block device and lock it */ - vol->dd = rtems_disk_lookup(stat_buf.st_dev); - if (vol->dd == NULL) - set_errno_and_return_minus_one(ENOTBLK); - - vol->dev = stat_buf.st_dev; - - fd = open(mt_entry->dev, O_RDONLY); - if (fd == -1) - { - rtems_disk_release(vol->dd); - return -1; - } - - ret = read(fd, (void *)boot_rec, FAT_MAX_BPB_SIZE); - if ( ret != FAT_MAX_BPB_SIZE ) - { - close(fd); - rtems_disk_release(vol->dd); - set_errno_and_return_minus_one( EIO ); - } - close(fd); - - vol->bps = FAT_BR_BYTES_PER_SECTOR(boot_rec); - - if ( (vol->bps != 512) && - (vol->bps != 1024) && - (vol->bps != 2048) && - (vol->bps != 4096)) - { - rtems_disk_release(vol->dd); - set_errno_and_return_minus_one( EINVAL ); - } - - for (vol->sec_mul = 0, i = (vol->bps >> FAT_SECTOR512_BITS); (i & 1) == 0; - i >>= 1, vol->sec_mul++); - for (vol->sec_log2 = 0, i = vol->bps; (i & 1) == 0; - i >>= 1, vol->sec_log2++); - - vol->spc = FAT_BR_SECTORS_PER_CLUSTER(boot_rec); - for (vol->spc_log2 = 0, i = vol->spc; (i & 1) == 0; - i >>= 1, vol->spc_log2++); - - /* - * According to M$ White Paper "bytes per cluster" value - * greater than 32K is invalid - */ - if ((vol->bpc = vol->bps << vol->spc_log2) > MS_BYTES_PER_CLUSTER_LIMIT) - { - rtems_disk_release(vol->dd); - set_errno_and_return_minus_one(EINVAL); - } - - for (vol->bpc_log2 = 0, i = vol->bpc; (i & 1) == 0; - i >>= 1, vol->bpc_log2++); - - vol->fats = FAT_BR_FAT_NUM(boot_rec); - vol->fat_loc = FAT_BR_RESERVED_SECTORS_NUM(boot_rec); - - vol->rdir_entrs = FAT_BR_FILES_PER_ROOT_DIR(boot_rec); - - /* calculate the count of sectors occupied by the root directory */ - vol->rdir_secs = ((vol->rdir_entrs * FAT_DIRENTRY_SIZE) + (vol->bps - 1)) / - vol->bps; - - vol->rdir_size = vol->rdir_secs << vol->sec_log2; - - if ( (FAT_BR_SECTORS_PER_FAT(boot_rec)) != 0) - vol->fat_length = FAT_BR_SECTORS_PER_FAT(boot_rec); - else - vol->fat_length = FAT_BR_SECTORS_PER_FAT32(boot_rec); - - vol->data_fsec = vol->fat_loc + vol->fats * vol->fat_length + - vol->rdir_secs; - - /* for FAT12/16 root dir starts at(sector) */ - vol->rdir_loc = vol->fat_loc + vol->fats * vol->fat_length; - - if ( (FAT_BR_TOTAL_SECTORS_NUM16(boot_rec)) != 0) - vol->tot_secs = FAT_BR_TOTAL_SECTORS_NUM16(boot_rec); - else - vol->tot_secs = FAT_BR_TOTAL_SECTORS_NUM32(boot_rec); - - data_secs = vol->tot_secs - vol->data_fsec; - - vol->data_cls = data_secs / vol->spc; - - /* determine FAT type at least */ - if ( vol->data_cls < FAT_FAT12_MAX_CLN) - { - vol->type = FAT_FAT12; - vol->mask = FAT_FAT12_MASK; - vol->eoc_val = FAT_FAT12_EOC; - } - else - { - if ( vol->data_cls < FAT_FAT16_MAX_CLN) - { - vol->type = FAT_FAT16; - vol->mask = FAT_FAT16_MASK; - vol->eoc_val = FAT_FAT16_EOC; - } - else - { - vol->type = FAT_FAT32; - vol->mask = FAT_FAT32_MASK; - vol->eoc_val = FAT_FAT32_EOC; - } - } - - if (vol->type == FAT_FAT32) - { - vol->rdir_cl = FAT_BR_FAT32_ROOT_CLUSTER(boot_rec); - - vol->mirror = FAT_BR_EXT_FLAGS(boot_rec) & FAT_BR_EXT_FLAGS_MIRROR; - if (vol->mirror) - vol->afat = FAT_BR_EXT_FLAGS(boot_rec) & FAT_BR_EXT_FLAGS_FAT_NUM; - else - vol->afat = 0; - - vol->info_sec = FAT_BR_FAT32_FS_INFO_SECTOR(boot_rec); - if( vol->info_sec == 0 ) - { - rtems_disk_release(vol->dd); - set_errno_and_return_minus_one( EINVAL ); - } - else - { - ret = _fat_block_read(mt_entry, vol->info_sec , 0, - FAT_FSI_LEADSIG_SIZE, fs_info_sector); - if ( ret < 0 ) - { - rtems_disk_release(vol->dd); - return -1; - } - - if (FAT_FSINFO_LEAD_SIGNATURE(fs_info_sector) != - FAT_FSINFO_LEAD_SIGNATURE_VALUE) - { - rtems_disk_release(vol->dd); - set_errno_and_return_minus_one( EINVAL ); - } - else - { - ret = _fat_block_read(mt_entry, vol->info_sec , FAT_FSI_INFO, - FAT_USEFUL_INFO_SIZE, fs_info_sector); - if ( ret < 0 ) - { - rtems_disk_release(vol->dd); - return -1; - } - - vol->free_cls = FAT_FSINFO_FREE_CLUSTER_COUNT(fs_info_sector); - vol->next_cl = FAT_FSINFO_NEXT_FREE_CLUSTER(fs_info_sector); - rc = fat_fat32_update_fsinfo_sector(mt_entry, 0xFFFFFFFF, - 0xFFFFFFFF); - if ( rc != RC_OK ) - { - rtems_disk_release(vol->dd); - return rc; - } - } - } - } - else - { - vol->rdir_cl = 0; - vol->mirror = 0; - vol->afat = 0; - vol->free_cls = 0xFFFFFFFF; - vol->next_cl = 0xFFFFFFFF; - } - vol->afat_loc = vol->fat_loc + vol->fat_length * vol->afat; - - /* set up collection of fat-files fd */ - fs_info->vhash = calloc(FAT_HASH_SIZE, sizeof(Chain_Control)); - if ( fs_info->vhash == NULL ) - { - rtems_disk_release(vol->dd); - set_errno_and_return_minus_one( ENOMEM ); - } - - for (i = 0; i < FAT_HASH_SIZE; i++) - _Chain_Initialize_empty(fs_info->vhash + i); - - fs_info->rhash = calloc(FAT_HASH_SIZE, sizeof(Chain_Control)); - if ( fs_info->rhash == NULL ) - { - rtems_disk_release(vol->dd); - free(fs_info->vhash); - set_errno_and_return_minus_one( ENOMEM ); - } - for (i = 0; i < FAT_HASH_SIZE; i++) - _Chain_Initialize_empty(fs_info->rhash + i); - - fs_info->uino_pool_size = FAT_UINO_POOL_INIT_SIZE; - fs_info->uino_base = (vol->tot_secs << vol->sec_mul) << 4; - fs_info->index = 0; - fs_info->uino = (char *)calloc(fs_info->uino_pool_size, sizeof(char)); - if ( fs_info->uino == NULL ) - { - rtems_disk_release(vol->dd); - free(fs_info->vhash); - free(fs_info->rhash); - set_errno_and_return_minus_one( ENOMEM ); - } - fs_info->sec_buf = (char *)calloc(vol->bps, sizeof(char)); - if (fs_info->sec_buf == NULL) - { - rtems_disk_release(vol->dd); - free(fs_info->vhash); - free(fs_info->rhash); - free(fs_info->uino); - set_errno_and_return_minus_one( ENOMEM ); - } - - return RC_OK; -} - -/* fat_shutdown_drive -- - * Free all allocated resources and synchronize all necessary data - * - * PARAMETERS: - * mt_entry - mount table entry - * - * RETURNS: - * RC_OK on success, or -1 if error occured - * and errno set appropriately - */ -int -fat_shutdown_drive(rtems_filesystem_mount_table_entry_t *mt_entry) -{ - int rc = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - int i = 0; - - if (fs_info->vol.type & FAT_FAT32) - { - rc = fat_fat32_update_fsinfo_sector(mt_entry, fs_info->vol.free_cls, - fs_info->vol.next_cl); - if ( rc != RC_OK ) - rc = -1; - } - - fat_buf_release(fs_info); - - if (rtems_bdbuf_syncdev(fs_info->vol.dev) != RTEMS_SUCCESSFUL) - rc = -1; - - for (i = 0; i < FAT_HASH_SIZE; i++) - { - Chain_Node *node = NULL; - Chain_Control *the_chain = fs_info->vhash + i; - - while ( (node = _Chain_Get(the_chain)) != NULL ) - free(node); - } - - for (i = 0; i < FAT_HASH_SIZE; i++) - { - Chain_Node *node = NULL; - Chain_Control *the_chain = fs_info->rhash + i; - - while ( (node = _Chain_Get(the_chain)) != NULL ) - free(node); - } - - free(fs_info->vhash); - free(fs_info->rhash); - - free(fs_info->uino); - free(fs_info->sec_buf); - rtems_disk_release(fs_info->vol.dd); - - if (rc) - errno = EIO; - return rc; -} - -/* fat_init_clusters_chain -- - * Zeroing contents of all clusters in the chain - * - * PARAMETERS: - * mt_entry - mount table entry - * start_cluster_num - num of first cluster in the chain - * - * RETURNS: - * RC_OK on success, or -1 if error occured - * and errno set appropriately - */ -int -fat_init_clusters_chain( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 start_cln - ) -{ - int rc = RC_OK; - ssize_t ret = 0; - register fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 cur_cln = start_cln; - char *buf; - - buf = calloc(fs_info->vol.bpc, sizeof(char)); - if ( buf == NULL ) - set_errno_and_return_minus_one( EIO ); - - while ((cur_cln & fs_info->vol.mask) != fs_info->vol.eoc_val) - { - ret = fat_cluster_write(mt_entry, cur_cln, buf); - if ( ret == -1 ) - { - free(buf); - return -1; - } - - rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln); - if ( rc != RC_OK ) - { - free(buf); - return rc; - } - - } - free(buf); - return rc; -} - -#define FAT_UNIQ_INO_BASE 0x0FFFFF00 - -#define FAT_UNIQ_INO_IS_BUSY(index, arr) \ - (((arr)[((index)>>3)]>>((index) & (8-1))) & 0x01) - -#define FAT_SET_UNIQ_INO_BUSY(index, arr) \ - ((arr)[((index)>>3)] |= (0x01<<((index) & (8-1)))) - -#define FAT_SET_UNIQ_INO_FREE(index, arr) \ - ((arr)[((index)>>3)] &= (~(0x01<<((index) & (8-1))))) - -/* fat_get_unique_ino -- - * Allocate unique ino from unique ino pool - * - * PARAMETERS: - * mt_entry - mount table entry - * - * RETURNS: - * unique inode number on success, or 0 if there is no free unique inode - * number in the pool - * - * ATTENTION: - * 0 means FAILED !!! - * - */ -unsigned32 -fat_get_unique_ino(rtems_filesystem_mount_table_entry_t *mt_entry) -{ - register fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 j = 0; - rtems_boolean resrc_unsuff = FALSE; - - while (!resrc_unsuff) - { - for (j = 0; j < fs_info->uino_pool_size; j++) - { - if (!FAT_UNIQ_INO_IS_BUSY(fs_info->index, fs_info->uino)) - { - FAT_SET_UNIQ_INO_BUSY(fs_info->index, fs_info->uino); - return (fs_info->uino_base + fs_info->index); - } - fs_info->index++; - if (fs_info->index >= fs_info->uino_pool_size) - fs_info->index = 0; - } - - if ((fs_info->uino_pool_size << 1) < (0x0FFFFFFF - fs_info->uino_base)) - { - fs_info->uino_pool_size <<= 1; - fs_info->uino = realloc(fs_info->uino, fs_info->uino_pool_size); - if (fs_info->uino != NULL) - fs_info->index = fs_info->uino_pool_size; - else - resrc_unsuff = TRUE; - } - else - resrc_unsuff = TRUE; - } - return 0; -} - -/* fat_free_unique_ino -- - * Return unique ino to unique ino pool - * - * PARAMETERS: - * mt_entry - mount table entry - * ino - inode number to free - * - * RETURNS: - * None - */ -void -fat_free_unique_ino( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 ino - ) -{ - fat_fs_info_t *fs_info = mt_entry->fs_info; - - FAT_SET_UNIQ_INO_FREE((ino - fs_info->uino_base), fs_info->uino); -} - -/* fat_ino_is_unique -- - * Test whether ino is from unique ino pool - * - * PARAMETERS: - * mt_entry - mount table entry - * ino - ino to be tested - * - * RETURNS: - * TRUE if ino is allocated from unique ino pool, FALSE otherwise - */ -inline rtems_boolean -fat_ino_is_unique( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 ino - ) -{ - fat_fs_info_t *fs_info = mt_entry->fs_info; - - return (ino >= fs_info->uino_base); -} - -/* fat_fat32_update_fsinfo_sector -- - * Synchronize fsinfo sector for FAT32 volumes - * - * PARAMETERS: - * mt_entry - mount table entry - * free_count - count of free clusters - * next_free - the next free cluster num - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set appropriately) - */ -int -fat_fat32_update_fsinfo_sector( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 free_count, - unsigned32 next_free - ) -{ - ssize_t ret1 = 0, ret2 = 0; - register fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 le_free_count = 0; - unsigned32 le_next_free = 0; - - le_free_count = CT_LE_L(free_count); - le_next_free = CT_LE_L(next_free); - - ret1 = _fat_block_write(mt_entry, - fs_info->vol.info_sec, - FAT_FSINFO_FREE_CLUSTER_COUNT_OFFSET, - 4, - (char *)(&le_free_count)); - - ret2 = _fat_block_write(mt_entry, - fs_info->vol.info_sec, - FAT_FSINFO_NEXT_FREE_CLUSTER_OFFSET, - 4, - (char *)(&le_next_free)); - - if ( (ret1 < 0) || (ret2 < 0) ) - return -1; - - return RC_OK; -} - \ No newline at end of file diff --git a/c/src/libfs/src/dosfs/fat.h b/c/src/libfs/src/dosfs/fat.h deleted file mode 100644 index f0aaf21c98..0000000000 --- a/c/src/libfs/src/dosfs/fat.h +++ /dev/null @@ -1,488 +0,0 @@ -/* - * fat.h - * - * Constants/data structures/prototypes for low-level operations on a volume - * with FAT filesystem - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ - -#ifndef __DOSFS_FAT_H__ -#define __DOSFS_FAT_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include - -/* XXX: temporary hack :(( */ -#ifndef set_errno_and_return_minus_one -#define set_errno_and_return_minus_one rtems_set_errno_and_return_minus_one -#endif /* set_errno_and_return_minus_one */ - -#include -#include -#include - -#ifndef RC_OK -#define RC_OK 0x00000000 -#endif - -/* - * Remember that all FAT file system on disk data structure is - * "little endian"! - * (derived from linux) - */ -/* - * Conversion from and to little-endian byte order. (no-op on i386/i486) - * - * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian, - * BE = big-endian, c: W = word (16 bits), L = longword (32 bits) - */ - -#if (CPU_BIG_ENDIAN == TRUE) -# define CF_LE_W(v) CPU_swap_u16(v) -# define CF_LE_L(v) CPU_swap_u32(v) -# define CT_LE_W(v) CPU_swap_u16(v) -# define CT_LE_L(v) CPU_swap_u32(v) -#else -# define CF_LE_W(v) (v) -# define CF_LE_L(v) (v) -# define CT_LE_W(v) (v) -# define CT_LE_L(v) (v) -#endif - -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) - -#define FAT_HASH_SIZE 2 -#define FAT_HASH_MODULE FAT_HASH_SIZE - - -#define FAT_SECTOR512_SIZE 512 /* sector size (bytes) */ -#define FAT_SECTOR512_BITS 9 /* log2(SECTOR_SIZE) */ - -/* maximum + 1 number of clusters for FAT12 */ -#define FAT_FAT12_MAX_CLN 4085 - -/* maximum + 1 number of clusters for FAT16 */ -#define FAT_FAT16_MAX_CLN 65525 - -#define FAT_FAT12 0x01 -#define FAT_FAT16 0x02 -#define FAT_FAT32 0x04 - -#define FAT_UNDEFINED_VALUE 0xFFFFFFFF - -#define FAT_FAT12_EOC 0x0FFF -#define FAT_FAT16_EOC 0xFFFF -#define FAT_FAT32_EOC 0x0FFFFFFF - -#define FAT_FAT12_FREE 0x0000 -#define FAT_FAT16_FREE 0x0000 -#define FAT_FAT32_FREE 0x00000000 - -#define FAT_GENFAT_EOC 0xFFFFFFFF -#define FAT_GENFAT_FREE 0x00000000 - -#define FAT_FAT12_SHIFT 0x04 - -#define FAT_FAT12_MASK 0x00000FFF -#define FAT_FAT16_MASK 0x0000FFFF -#define FAT_FAT32_MASK 0x0FFFFFFF - -#define FAT_MAX_BPB_SIZE 90 - -/* size of useful information in FSInfo sector */ -#define FAT_USEFUL_INFO_SIZE 12 - -#define FAT_VAL8(x, ofs) (unsigned8)(*((unsigned8 *)(x) + (ofs))) - -#define FAT_VAL16(x, ofs) \ - (unsigned16)( (*((unsigned8 *)(x) + (ofs))) | \ - ((*((unsigned8 *)(x) + (ofs) + 1)) << 8) ) - -#define FAT_VAL32(x, ofs) \ - (unsigned32)( (*((unsigned8 *)(x) + (ofs))) | \ - ((*((unsigned8 *)(x) + (ofs) + 1)) << 8) | \ - ((*((unsigned8 *)(x) + (ofs) + 2)) << 16) | \ - ((*((unsigned8 *)(x) + (ofs) + 3)) << 24) ) - -/* macros to access boot sector fields */ -#define FAT_BR_BYTES_PER_SECTOR(x) FAT_VAL16(x, 11) -#define FAT_BR_SECTORS_PER_CLUSTER(x) FAT_VAL8(x, 13) -#define FAT_BR_RESERVED_SECTORS_NUM(x) FAT_VAL16(x, 14) -#define FAT_BR_FAT_NUM(x) FAT_VAL8(x, 16) -#define FAT_BR_FILES_PER_ROOT_DIR(x) FAT_VAL16(x, 17) -#define FAT_BR_TOTAL_SECTORS_NUM16(x) FAT_VAL16(x, 19) -#define FAT_BR_MEDIA(x) FAT_VAL8(x, 21) -#define FAT_BR_SECTORS_PER_FAT(x) FAT_VAL16(x, 22) -#define FAT_BR_TOTAL_SECTORS_NUM32(x) FAT_VAL32(x, 32) -#define FAT_BR_SECTORS_PER_FAT32(x) FAT_VAL32(x, 36) -#define FAT_BR_EXT_FLAGS(x) FAT_VAL16(x, 40) -#define FAT_BR_FAT32_ROOT_CLUSTER(x) FAT_VAL32(x, 44) -#define FAT_BR_FAT32_FS_INFO_SECTOR(x) FAT_VAL16(x, 48) -#define FAT_FSINFO_LEAD_SIGNATURE(x) FAT_VAL32(x, 0) -/* - * I read FSInfo sector from offset 484 to access the information, so offsets - * of these fields a relative - */ -#define FAT_FSINFO_FREE_CLUSTER_COUNT(x) FAT_VAL32(x, 4) -#define FAT_FSINFO_NEXT_FREE_CLUSTER(x) FAT_VAL32(x, 8) - -#define FAT_FSINFO_FREE_CLUSTER_COUNT_OFFSET 488 - -#define FAT_FSINFO_NEXT_FREE_CLUSTER_OFFSET 492 - -#define FAT_RSRVD_CLN 0x02 - -#define FAT_FSINFO_LEAD_SIGNATURE_VALUE 0x41615252 - -#define FAT_FSI_LEADSIG_SIZE 0x04 - -#define FAT_FSI_INFO 484 - -#define MS_BYTES_PER_CLUSTER_LIMIT 0x8000 /* 32K */ - -#define FAT_BR_EXT_FLAGS_MIRROR 0x0080 - -#define FAT_BR_EXT_FLAGS_FAT_NUM 0x000F - - -#define FAT_DIRENTRY_SIZE 32 - -#define FAT_DIRENTRIES_PER_SEC512 16 - -/* - * Volume descriptor - * Description of the volume the FAT filesystem is located on - generally - * the fields of the structure corresponde to Boot Sector and BPB Srtucture - * (see M$ White Paper) fields - */ -typedef struct fat_vol_s -{ - unsigned16 bps; /* bytes per sector */ - unsigned8 sec_log2; /* log2 of bps */ - unsigned8 sec_mul; /* log2 of 512bts sectors number per sector */ - unsigned8 spc; /* sectors per cluster */ - unsigned8 spc_log2; /* log2 of spc */ - unsigned16 bpc; /* bytes per cluster */ - unsigned8 bpc_log2; /* log2 of bytes per cluster */ - unsigned8 fats; /* number of FATs */ - unsigned8 type; /* FAT type */ - unsigned32 mask; - unsigned32 eoc_val; - unsigned16 fat_loc; /* FAT start */ - unsigned32 fat_length; /* sectors per FAT */ - unsigned32 rdir_loc; /* root directory start */ - unsigned16 rdir_entrs; /* files per root directory */ - unsigned32 rdir_secs; /* sectors per root directory */ - unsigned32 rdir_size; /* root directory size in bytes */ - unsigned32 tot_secs; /* total count of sectors */ - unsigned32 data_fsec; /* first data sector */ - unsigned32 data_cls; /* count of data clusters */ - unsigned32 rdir_cl; /* first cluster of the root directory */ - unsigned16 info_sec; /* FSInfo Sector Structure location */ - unsigned32 free_cls; /* last known free clusters count */ - unsigned32 next_cl; /* next free cluster number */ - unsigned8 mirror; /* mirroring enabla/disable */ - unsigned32 afat_loc; /* active FAT location */ - unsigned8 afat; /* the number of active FAT */ - dev_t dev; /* device ID */ - disk_device *dd; /* disk device (see libblock) */ - void *private_data; /* reserved */ -} fat_vol_t; - - -typedef struct fat_cache_s -{ - unsigned32 blk_num; - rtems_boolean modified; - unsigned8 state; - bdbuf_buffer *buf; -} fat_cache_t; - -/* - * This structure identifies the instance of the filesystem on the FAT - * ("fat-file") level. - */ -typedef struct fat_fs_info_s -{ - fat_vol_t vol; /* volume descriptor */ - Chain_Control *vhash; /* "vhash" of fat-file descriptors */ - Chain_Control *rhash; /* "rhash" of fat-file descriptors */ - char *uino; /* array of unique ino numbers */ - unsigned32 index; - unsigned32 uino_pool_size; /* size */ - unsigned32 uino_base; - fat_cache_t c; /* cache */ - unsigned8 *sec_buf; /* just placeholder for anything */ -} fat_fs_info_t; - -/* - * if the name we looking for is file we store not only first data cluster - * number, but and cluster number and offset for directory entry for this - * name - */ -typedef struct fat_auxiliary_s -{ - unsigned32 cln; - unsigned32 ofs; -} fat_auxiliary_t; - -#define FAT_FAT_OFFSET(fat_type, cln) \ - ((fat_type) & FAT_FAT12 ? ((cln) + ((cln) >> 1)) : \ - (fat_type) & FAT_FAT16 ? ((cln) << 1) : \ - ((cln) << 2)) - -#define FAT_CLUSTER_IS_ODD(n) ((n) & 0x0001) - -#define FAT12_SHIFT 0x4 /* half of a byte */ - -/* initial size of array of unique ino */ -#define FAT_UINO_POOL_INIT_SIZE 0x100 - -/* cache support */ -#define FAT_CACHE_EMPTY 0x0 -#define FAT_CACHE_ACTUAL 0x1 - -#define FAT_OP_TYPE_READ 0x1 -#define FAT_OP_TYPE_GET 0x2 - -static inline unsigned32 -fat_cluster_num_to_sector_num( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln - ) -{ - register fat_fs_info_t *fs_info = mt_entry->fs_info; - - if ( (cln == 0) && (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16)) ) - return fs_info->vol.rdir_loc; - - return (((cln - FAT_RSRVD_CLN) << fs_info->vol.spc_log2) + - fs_info->vol.data_fsec); -} - -static inline unsigned32 -fat_cluster_num_to_sector512_num( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln - ) -{ - fat_fs_info_t *fs_info = mt_entry->fs_info; - - if (cln == 1) - return 1; - - return (fat_cluster_num_to_sector_num(mt_entry, cln) << - fs_info->vol.sec_mul); -} - -static inline int -fat_buf_access(fat_fs_info_t *fs_info, unsigned32 blk, int op_type, - bdbuf_buffer **buf) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - unsigned8 i; - rtems_boolean sec_of_fat; - - - if (fs_info->c.state == FAT_CACHE_EMPTY) - { - if (op_type == FAT_OP_TYPE_READ) - sc = rtems_bdbuf_read(fs_info->vol.dev, blk, &fs_info->c.buf); - else - sc = rtems_bdbuf_get(fs_info->vol.dev, blk, &fs_info->c.buf); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - fs_info->c.blk_num = blk; - fs_info->c.state = FAT_CACHE_ACTUAL; - } - - sec_of_fat = ((fs_info->c.blk_num >= fs_info->vol.fat_loc) && - (fs_info->c.blk_num < fs_info->vol.rdir_loc)); - - if (fs_info->c.blk_num != blk) - { - if (fs_info->c.modified) - { - if (sec_of_fat && !fs_info->vol.mirror) - memcpy(fs_info->sec_buf, fs_info->c.buf->buffer, - fs_info->vol.bps); - - sc = rtems_bdbuf_release_modified(fs_info->c.buf); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - fs_info->c.modified = 0; - - if (sec_of_fat && !fs_info->vol.mirror) - { - bdbuf_buffer *b; - - for (i = 1; i < fs_info->vol.fats; i++) - { - sc = rtems_bdbuf_get(fs_info->vol.dev, - fs_info->c.blk_num + - fs_info->vol.fat_length * i, - &b); - if ( sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(ENOMEM); - memcpy(b->buffer, fs_info->sec_buf, fs_info->vol.bps); - sc = rtems_bdbuf_release_modified(b); - if ( sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(ENOMEM); - } - } - } - else - { - sc = rtems_bdbuf_release(fs_info->c.buf); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - } - if (op_type == FAT_OP_TYPE_READ) - sc = rtems_bdbuf_read(fs_info->vol.dev, blk, &fs_info->c.buf); - else - sc = rtems_bdbuf_get(fs_info->vol.dev, blk, &fs_info->c.buf); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - fs_info->c.blk_num = blk; - } - *buf = fs_info->c.buf; - return RC_OK; -} - - -static inline int -fat_buf_release(fat_fs_info_t *fs_info) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - unsigned8 i; - rtems_boolean sec_of_fat; - - if (fs_info->c.state == FAT_CACHE_EMPTY) - return RC_OK; - - sec_of_fat = ((fs_info->c.blk_num >= fs_info->vol.fat_loc) && - (fs_info->c.blk_num < fs_info->vol.rdir_loc)); - - if (fs_info->c.modified) - { - if (sec_of_fat && !fs_info->vol.mirror) - memcpy(fs_info->sec_buf, fs_info->c.buf->buffer, fs_info->vol.bps); - - sc = rtems_bdbuf_release_modified(fs_info->c.buf); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - fs_info->c.modified = 0; - - if (sec_of_fat && !fs_info->vol.mirror) - { - bdbuf_buffer *b; - - for (i = 1; i < fs_info->vol.fats; i++) - { - sc = rtems_bdbuf_get(fs_info->vol.dev, - fs_info->c.blk_num + - fs_info->vol.fat_length * i, - &b); - if ( sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(ENOMEM); - memcpy(b->buffer, fs_info->sec_buf, fs_info->vol.bps); - sc = rtems_bdbuf_release_modified(b); - if ( sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(ENOMEM); - } - } - } - else - { - sc = rtems_bdbuf_release(fs_info->c.buf); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - } - fs_info->c.state = FAT_CACHE_EMPTY; - return RC_OK; -} - -static inline void -fat_buf_mark_modified(fat_fs_info_t *fs_info) -{ - fs_info->c.modified = TRUE; -} - - - -ssize_t -_fat_block_read(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 start, - unsigned32 offset, - unsigned32 count, - void *buff); - -ssize_t -_fat_block_write(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 start, - unsigned32 offset, - unsigned32 count, - const void *buff); - -ssize_t -fat_cluster_read(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - void *buff); - -ssize_t -fat_cluster_write(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - const void *buff); - -int -fat_init_volume_info(rtems_filesystem_mount_table_entry_t *mt_entry); - -int -fat_init_clusters_chain(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 start_cln); - -unsigned32 -fat_cluster_num_to_sector_num(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln); - -int -fat_shutdown_drive(rtems_filesystem_mount_table_entry_t *mt_entry); - - -unsigned32 -fat_get_unique_ino(rtems_filesystem_mount_table_entry_t *mt_entry); - -rtems_boolean -fat_ino_is_unique(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 ino); - -void -fat_free_unique_ino(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 ino); - -int -fat_fat32_update_fsinfo_sector( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 free_count, - unsigned32 next_free - ); - -#ifdef __cplusplus -} -#endif - -#endif /* __DOSFS_FAT_H__ */ diff --git a/c/src/libfs/src/dosfs/fat_fat_operations.c b/c/src/libfs/src/dosfs/fat_fat_operations.c deleted file mode 100644 index 49b2ab70d3..0000000000 --- a/c/src/libfs/src/dosfs/fat_fat_operations.c +++ /dev/null @@ -1,445 +0,0 @@ -/* - * fat_fat_operations.c - * - * General operations on File Allocation Table - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * @(#) $Id$ - */ - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fat.h" -#include "fat_fat_operations.h" - -/* fat_scan_fat_for_free_clusters -- - * Allocate chain of free clusters from Files Allocation Table - * - * PARAMETERS: - * mt_entry - mount table entry - * chain - the number of the first allocated cluster (first cluster - * in the chain) - * count - count of clusters to allocate (chain length) - * - * RETURNS: - * RC_OK on success, or error code if error occured (errno set - * appropriately) - * - * - */ -int -fat_scan_fat_for_free_clusters( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 *chain, - unsigned32 count, - unsigned32 *cls_added, - unsigned32 *last_cl - ) -{ - int rc = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 cl4find = 2; - unsigned32 next_cln = 0; - unsigned32 save_cln = 0; - unsigned32 data_cls_val = fs_info->vol.data_cls + 2; - unsigned32 i = 2; - - *cls_added = 0; - - if (count == 0) - return rc; - - if ((fs_info->vol.type & FAT_FAT32) && - (fs_info->vol.next_cl != FAT_UNDEFINED_VALUE)) - cl4find = fs_info->vol.next_cl; - - /* - * fs_info->vol.data_cls is exactly the count of data clusters - * starting at cluster 2, so the maximum valid cluster number is - * (fs_info->vol.data_cls + 1) - */ - while (i < data_cls_val) - { - rc = fat_get_fat_cluster(mt_entry, cl4find, &next_cln); - if ( rc != RC_OK ) - { - if (*cls_added != 0) - fat_free_fat_clusters_chain(mt_entry, (*chain)); - return rc; - } - - if ((next_cln & fs_info->vol.mask) == FAT_GENFAT_FREE) - { - /* - * We are enforced to process allocation of the first free cluster - * by separate 'if' statement because otherwise undo function - * wouldn't work properly - */ - if (*cls_added == 0) - { - *chain = cl4find; - rc = fat_set_fat_cluster(mt_entry, cl4find, FAT_GENFAT_EOC); - if ( rc != RC_OK ) - { - /* - * this is the first cluster we tried to allocate so no - * cleanup activity needed - */ - return rc; - } - } - else - { - /* set EOC value to new allocated cluster */ - rc = fat_set_fat_cluster(mt_entry, cl4find, FAT_GENFAT_EOC); - if ( rc != RC_OK ) - { - /* cleanup activity */ - fat_free_fat_clusters_chain(mt_entry, (*chain)); - return rc; - } - - rc = fat_set_fat_cluster(mt_entry, save_cln, cl4find); - if ( rc != RC_OK ) - { - /* cleanup activity */ - fat_free_fat_clusters_chain(mt_entry, (*chain)); - /* trying to save last allocated cluster for future use */ - fat_set_fat_cluster(mt_entry, cl4find, FAT_GENFAT_FREE); - fat_buf_release(fs_info); - return rc; - } - } - - save_cln = cl4find; - (*cls_added)++; - - /* have we satisfied request ? */ - if (*cls_added == count) - { - if (fs_info->vol.type & FAT_FAT32) - { - fs_info->vol.next_cl = save_cln; - if (fs_info->vol.free_cls != 0xFFFFFFFF) - fs_info->vol.free_cls -= (*cls_added); - } - *last_cl = save_cln; - fat_buf_release(fs_info); - return rc; - } - } - i++; - cl4find++; - if (cl4find >= data_cls_val) - cl4find = 2; - } - - if (fs_info->vol.type & FAT_FAT32) - { - fs_info->vol.next_cl = save_cln; - if (fs_info->vol.free_cls != 0xFFFFFFFF) - fs_info->vol.free_cls -= (*cls_added); - } - *last_cl = save_cln; - fat_buf_release(fs_info); - return RC_OK; -} - -/* fat_free_fat_clusters_chain -- - * Free chain of clusters in Files Allocation Table. - * - * PARAMETERS: - * mt_entry - mount table entry - * chain - number of the first cluster in the chain - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set appropriately) - */ -int -fat_free_fat_clusters_chain( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 chain - ) -{ - int rc = RC_OK, rc1 = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 cur_cln = chain; - unsigned32 next_cln = 0; - unsigned32 freed_cls_cnt = 0; - - while ((cur_cln & fs_info->vol.mask) != fs_info->vol.eoc_val) - { - rc = fat_get_fat_cluster(mt_entry, cur_cln, &next_cln); - if ( rc != RC_OK ) - { - if ((fs_info->vol.type & FAT_FAT32) && - (fs_info->vol.free_cls != FAT_UNDEFINED_VALUE)) - fs_info->vol.free_cls += freed_cls_cnt; - fat_buf_release(fs_info); - return rc; - } - - rc = fat_set_fat_cluster(mt_entry, cur_cln, FAT_GENFAT_FREE); - if ( rc != RC_OK ) - rc1 = rc; - - freed_cls_cnt++; - cur_cln = next_cln; - } - - if (fs_info->vol.type & FAT_FAT32) - { - fs_info->vol.next_cl = chain; - if (fs_info->vol.free_cls != FAT_UNDEFINED_VALUE) - fs_info->vol.free_cls += freed_cls_cnt; - } - - fat_buf_release(fs_info); - if (rc1 != RC_OK) - return rc1; - - return RC_OK; -} - -/* fat_get_fat_cluster -- - * Fetches the contents of the cluster (link to next cluster in the chain) - * from Files Allocation Table. - * - * PARAMETERS: - * mt_entry - mount table entry - * cln - number of cluster to fetch the contents from - * ret_val - contents of the cluster 'cln' (link to next cluster in - * the chain) - * - * RETURNS: - * RC_OK on success, or -1 if error occured - * and errno set appropriately - */ -int -fat_get_fat_cluster( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - unsigned32 *ret_val - ) -{ - int rc = RC_OK; - register fat_fs_info_t *fs_info = mt_entry->fs_info; - bdbuf_buffer *block0 = NULL; - unsigned32 sec = 0; - unsigned32 ofs = 0; - - /* sanity check */ - if ( (cln < 2) || (cln > (fs_info->vol.data_cls + 1)) ) - set_errno_and_return_minus_one(EIO); - - sec = (FAT_FAT_OFFSET(fs_info->vol.type, cln) >> fs_info->vol.sec_log2) + - fs_info->vol.afat_loc; - ofs = FAT_FAT_OFFSET(fs_info->vol.type, cln) & (fs_info->vol.bps - 1); - - rc = fat_buf_access(fs_info, sec, FAT_OP_TYPE_READ, &block0); - if (rc != RC_OK) - return rc; - - switch ( fs_info->vol.type ) - { - case FAT_FAT12: - /* - * we are enforced in complex computations for FAT12 to escape CPU - * align problems for some architectures - */ - *ret_val = (*((unsigned8 *)(block0->buffer + ofs))); - if ( ofs == (fs_info->vol.bps - 1) ) - { - rc = fat_buf_access(fs_info, sec + 1, FAT_OP_TYPE_READ, - &block0); - if (rc != RC_OK) - return rc; - - *ret_val |= (*((unsigned8 *)(block0->buffer)))<<8; - } - else - { - *ret_val |= (*((unsigned8 *)(block0->buffer + ofs + 1)))<<8; - } - - if ( FAT_CLUSTER_IS_ODD(cln) ) - *ret_val = (*ret_val) >> FAT12_SHIFT; - else - *ret_val = (*ret_val) & FAT_FAT12_MASK; - - break; - - case FAT_FAT16: - *ret_val = *((unsigned16 *)(block0->buffer + ofs)); - *ret_val = CF_LE_W(*ret_val); - break; - - case FAT_FAT32: - *ret_val = *((unsigned32 *)(block0->buffer + ofs)); - *ret_val = CF_LE_L(*ret_val); - break; - - default: - set_errno_and_return_minus_one(EIO); - break; - } - - return RC_OK; -} - -/* fat_set_fat_cluster -- - * Set the contents of the cluster (link to next cluster in the chain) - * from Files Allocation Table. - * - * PARAMETERS: - * mt_entry - mount table entry - * cln - number of cluster to set contents to - * in_val - value to set - * - * RETURNS: - * RC_OK on success, or -1 if error occured - * and errno set appropriately - */ -int -fat_set_fat_cluster( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - unsigned32 in_val - ) -{ - int rc = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 sec = 0; - unsigned32 ofs = 0; - unsigned16 fat16_clv = 0; - unsigned32 fat32_clv = 0; - bdbuf_buffer *block0 = NULL; - - /* sanity check */ - if ( (cln < 2) || (cln > (fs_info->vol.data_cls + 1)) ) - set_errno_and_return_minus_one(EIO); - - sec = (FAT_FAT_OFFSET(fs_info->vol.type, cln) >> fs_info->vol.sec_log2) + - fs_info->vol.afat_loc; - ofs = FAT_FAT_OFFSET(fs_info->vol.type, cln) & (fs_info->vol.bps - 1); - - rc = fat_buf_access(fs_info, sec, FAT_OP_TYPE_READ, &block0); - if (rc != RC_OK) - return rc; - - switch ( fs_info->vol.type ) - { - case FAT_FAT12: - if ( FAT_CLUSTER_IS_ODD(cln) ) - { - fat16_clv = CT_LE_W((((unsigned16)in_val) << FAT_FAT12_SHIFT)); - - *((unsigned8 *)(block0->buffer + ofs)) = - (*((unsigned8 *)(block0->buffer + ofs))) & 0x0F; - - *((unsigned8 *)(block0->buffer + ofs)) = - (*((unsigned8 *)(block0->buffer + ofs))) | - (unsigned8)(fat16_clv & 0x00FF); - - fat_buf_mark_modified(fs_info); - - if ( ofs == (fs_info->vol.bps - 1) ) - { - rc = fat_buf_access(fs_info, sec + 1, FAT_OP_TYPE_READ, - &block0); - if (rc != RC_OK) - return rc; - - *((unsigned8 *)(block0->buffer)) &= 0x00; - - *((unsigned8 *)(block0->buffer)) = - (*((unsigned8 *)(block0->buffer))) | - (unsigned8)((fat16_clv & 0xFF00)>>8); - - fat_buf_mark_modified(fs_info); - } - else - { - *((unsigned8 *)(block0->buffer + ofs + 1)) &= 0x00; - - *((unsigned8 *)(block0->buffer + ofs + 1)) = - (*((unsigned8 *)(block0->buffer + ofs + 1))) | - (unsigned8)((fat16_clv & 0xFF00)>>8); - } - } - else - { - fat16_clv = CT_LE_W((((unsigned16)in_val) & FAT_FAT12_MASK)); - - *((unsigned8 *)(block0->buffer + ofs)) &= 0x00; - - *((unsigned8 *)(block0->buffer + ofs)) = - (*((unsigned8 *)(block0->buffer + ofs))) | - (unsigned8)(fat16_clv & 0x00FF); - - fat_buf_mark_modified(fs_info); - - if ( ofs == (fs_info->vol.bps - 1) ) - { - rc = fat_buf_access(fs_info, sec + 1, FAT_OP_TYPE_READ, - &block0); - if (rc != RC_OK) - return rc; - - *((unsigned8 *)(block0->buffer)) = - (*((unsigned8 *)(block0->buffer))) & 0xF0; - - *((unsigned8 *)(block0->buffer)) = - (*((unsigned8 *)(block0->buffer))) | - (unsigned8)((fat16_clv & 0xFF00)>>8); - - fat_buf_mark_modified(fs_info); - } - else - { - *((unsigned8 *)(block0->buffer + ofs + 1)) = - (*((unsigned8 *)(block0->buffer + ofs + 1))) & 0xF0; - - *((unsigned8 *)(block0->buffer + ofs+1)) = - (*((unsigned8 *)(block0->buffer + ofs+1))) | - (unsigned8)((fat16_clv & 0xFF00)>>8); - } - } - break; - - case FAT_FAT16: - *((unsigned16 *)(block0->buffer + ofs)) = - (unsigned16)(CT_LE_W(in_val)); - fat_buf_mark_modified(fs_info); - break; - - case FAT_FAT32: - fat32_clv = CT_LE_L((in_val & FAT_FAT32_MASK)); - - *((unsigned32 *)(block0->buffer + ofs)) = - (*((unsigned32 *)(block0->buffer + ofs))) & (CT_LE_L(0xF0000000)); - - *((unsigned32 *)(block0->buffer + ofs)) = - fat32_clv | (*((unsigned32 *)(block0->buffer + ofs))); - - fat_buf_mark_modified(fs_info); - break; - - default: - set_errno_and_return_minus_one(EIO); - break; - - } - - return RC_OK; -} diff --git a/c/src/libfs/src/dosfs/fat_fat_operations.h b/c/src/libfs/src/dosfs/fat_fat_operations.h deleted file mode 100644 index 59b6a84018..0000000000 --- a/c/src/libfs/src/dosfs/fat_fat_operations.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * fat_fat_operations.h - * - * Constants/data structures/prototypes for operations on Files Allocation - * Table - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ -#ifndef __DOSFS_FAT_FAT_OPERATIONS_H__ -#define __DOSFS_FAT_FAT_OPERATIONS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#include -#include "fat.h" - -int -fat_get_fat_cluster(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - unsigned32 *ret_val); - -int -fat_set_fat_cluster(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - unsigned32 in_val); - -int -fat_scan_fat_for_free_clusters( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 *chain, - unsigned32 count, - unsigned32 *cls_added, - unsigned32 *last_cl -); - -int -fat_free_fat_clusters_chain( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 chain -); - -#ifdef __cplusplus -} -#endif - -#endif /* __DOSFS_FAT_FAT_OPERATIONS_H__ */ diff --git a/c/src/libfs/src/dosfs/fat_file.c b/c/src/libfs/src/dosfs/fat_file.c deleted file mode 100644 index 8046f47720..0000000000 --- a/c/src/libfs/src/dosfs/fat_file.c +++ /dev/null @@ -1,978 +0,0 @@ -/* - * fat_file.c - * - * General operations on "fat-file" - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * @(#) $Id$ - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fat.h" -#include "fat_fat_operations.h" -#include "fat_file.h" - -static inline void -_hash_insert(Chain_Control *hash, unsigned32 key1, unsigned32 key2, - fat_file_fd_t *el); - -static inline void -_hash_delete(Chain_Control *hash, unsigned32 key1, unsigned32 key2, - fat_file_fd_t *el); - -static inline int -_hash_search( - rtems_filesystem_mount_table_entry_t *mt_entry, - Chain_Control *hash, - unsigned32 key1, - unsigned32 key2, - void **ret -); - -static int -fat_file_lseek( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 file_cln, - unsigned32 *disk_cln -); - -/* fat_file_open -- - * Open fat-file. Two hash tables are accessed by key - * constructed from cluster num and offset of the node (i.e. - * files/directories are distinguished by location on the disk). - * First, hash table("vhash") consists of fat-file descriptors corresponded - * to "valid" files is accessed. Search is made by 2 fields equal to key - * constructed. If descriptor is found in the "vhash" - return it. - * Otherwise search is made in hash table("rhash") consits of fat-file - * descriptors corresponded to "removed-but-still-open" files with the - * same keys. - * If search failed, new fat-file descriptor is added to "vhash" - * with both key fields equal to constructed key. Otherwise new fat-file - * descriptor is added to "vhash" with first key field equal to key - * constructed and the second equal to an unique (unique among all values - * of second key fields) value. - * - * PARAMETERS: - * mt_entry - mount table entry - * cln - cluster num of the node - * ofs - offset of the node - * fat_fd - placeholder for returned fat-file descriptor - * - * RETURNS: - * RC_OK and pointer to opened descriptor on success, or -1 if error - * occured (errno set appropriately) - */ -int -fat_file_open( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - unsigned32 ofs, - fat_file_fd_t **fat_fd - ) -{ - int rc = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - fat_file_fd_t *lfat_fd = NULL; - unsigned32 key = 0; - - /* construct key */ - key = fat_construct_key(mt_entry, cln, ofs); - - /* access "valid" hash table */ - rc = _hash_search(mt_entry, fs_info->vhash, key, 0, (void **)&lfat_fd); - if ( rc == RC_OK ) - { - /* return pointer to fat_file_descriptor allocated before */ - (*fat_fd) = lfat_fd; - lfat_fd->links_num++; - return rc; - } - - /* access "removed-but-still-open" hash table */ - rc = _hash_search(mt_entry, fs_info->rhash, key, key, (void **)&lfat_fd); - - lfat_fd = (*fat_fd) = (fat_file_fd_t*)malloc(sizeof(fat_file_fd_t)); - if ( lfat_fd == NULL ) - set_errno_and_return_minus_one( ENOMEM ); - - lfat_fd->links_num = 1; - lfat_fd->flags &= ~FAT_FILE_REMOVED; - lfat_fd->map.last_cln = FAT_UNDEFINED_VALUE; - - if ( rc != RC_OK ) - lfat_fd->ino = key; - else - { - lfat_fd->ino = fat_get_unique_ino(mt_entry); - - if ( lfat_fd->ino == 0 ) - { - free((*fat_fd)); - /* - * XXX: kernel resource is unsufficient, but not the memory, - * but there is no suitable errno :( - */ - set_errno_and_return_minus_one( ENOMEM ); - } - } - _hash_insert(fs_info->vhash, key, lfat_fd->ino, lfat_fd); - - - /* - * other fields of fat-file descriptor will be initialized on upper - * level - */ - - return RC_OK; -} - - -/* fat_file_reopen -- - * Increment by 1 number of links - * - * PARAMETERS: - * fat_fd - fat-file descriptor - * - * RETURNS: - * RC_OK - */ -int -fat_file_reopen(fat_file_fd_t *fat_fd) -{ - fat_fd->links_num++; - return RC_OK; -} - -/* fat_file_close -- - * Close fat-file. If count of links to fat-file - * descriptor is greater than 1 (i.e. somebody esle holds pointer - * to this descriptor) just decrement it. Otherwise - * do the following. If this descriptor corresponded to removed fat-file - * then free clusters contained fat-file data, delete descriptor from - * "rhash" table and free memory allocated by descriptor. If descriptor - * correspondes to non-removed fat-file and 'ino' field has value from - * unique inode numbers pool then set count of links to descriptor to zero - * and leave it in hash, otherwise delete descriptor from "vhash" and free - * memory allocated by the descriptor - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * - * RETURNS: - * RC_OK, or -1 if error occured (errno set appropriately) - */ -int -fat_file_close( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd - ) -{ - int rc = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 key = 0; - - /* - * if links_num field of fat-file descriptor is greater than 1 - * decrement the count of links and return - */ - if (fat_fd->links_num > 1) - { - fat_fd->links_num--; - return rc; - } - - key = fat_construct_key(mt_entry, fat_fd->info_cln, fat_fd->info_ofs); - - if (fat_fd->flags & FAT_FILE_REMOVED) - { - rc = fat_file_truncate(mt_entry, fat_fd, 0); - if ( rc != RC_OK ) - return rc; - - _hash_delete(fs_info->rhash, key, fat_fd->ino, fat_fd); - - if ( fat_ino_is_unique(mt_entry, fat_fd->ino) ) - fat_free_unique_ino(mt_entry, fat_fd->ino); - - free(fat_fd); - } - else - { - if (fat_ino_is_unique(mt_entry, fat_fd->ino)) - { - fat_fd->links_num = 0; - } - else - { - _hash_delete(fs_info->vhash, key, fat_fd->ino, fat_fd); - free(fat_fd); - } - } - return rc; -} - -/* fat_file_read -- - * Read 'count' bytes from 'start' position from fat-file. This - * interface hides the architecture of fat-file, represents it as - * linear file - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * start - offset in fat-file (in bytes) to read from - * count - count of bytes to read - * buf - buffer provided by user - * - * RETURNS: - * the number of bytes read on success, or -1 if error occured (errno - * set appropriately) - */ -ssize_t -fat_file_read( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 start, - unsigned32 count, - char *buf - ) -{ - int rc = RC_OK; - ssize_t ret = 0; - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 cmpltd = 0; - unsigned32 cur_cln = 0; - unsigned32 cl_start = 0; - unsigned32 save_cln = 0; - unsigned32 ofs = 0; - unsigned32 save_ofs; - unsigned32 sec = 0; - unsigned32 byte = 0; - unsigned32 c = 0; - - /* it couldn't be removed - otherwise cache update will be broken */ - if (count == 0) - return cmpltd; - - /* - * >= because start is offset and computed from 0 and file_size - * computed from 1 - */ - if ( start >= fat_fd->fat_file_size ) - return FAT_EOF; - - if ((count > fat_fd->fat_file_size) || - (start > fat_fd->fat_file_size - count)) - count = fat_fd->fat_file_size - start; - - if ((FAT_FD_OF_ROOT_DIR(fat_fd)) && - (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16))) - { - sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->cln); - sec += (start >> fs_info->vol.sec_log2); - byte = start & (fs_info->vol.bps - 1); - - ret = _fat_block_read(mt_entry, sec, byte, count, buf); - if ( ret < 0 ) - return -1; - - return ret; - } - - cl_start = start >> fs_info->vol.bpc_log2; - save_ofs = ofs = start & (fs_info->vol.bpc - 1); - - rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln); - if (rc != RC_OK) - return rc; - - while (count > 0) - { - c = MIN(count, (fs_info->vol.bpc - ofs)); - - sec = fat_cluster_num_to_sector_num(mt_entry, cur_cln); - sec += (ofs >> fs_info->vol.sec_log2); - byte = ofs & (fs_info->vol.bps - 1); - - ret = _fat_block_read(mt_entry, sec, byte, c, buf + cmpltd); - if ( ret < 0 ) - return -1; - - count -= c; - cmpltd += c; - save_cln = cur_cln; - rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln); - if ( rc != RC_OK ) - return rc; - - ofs = 0; - } - - /* update cache */ - /* XXX: check this - I'm not sure :( */ - fat_fd->map.file_cln = cl_start + - ((save_ofs + cmpltd - 1) >> fs_info->vol.bpc_log2); - fat_fd->map.disk_cln = save_cln; - - return cmpltd; -} - -/* fat_file_write -- - * Write 'count' bytes of data from user supplied buffer to fat-file - * starting at offset 'start'. This interface hides the architecture - * of fat-file, represents it as linear file - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * start - offset(in bytes) to write from - * count - count - * buf - buffer provided by user - * - * RETURNS: - * number of bytes actually written to the file on success, or -1 if - * error occured (errno set appropriately) - */ -ssize_t -fat_file_write( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 start, - unsigned32 count, - const char *buf - ) -{ - int rc = 0; - ssize_t ret = 0; - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 cmpltd = 0; - unsigned32 cur_cln = 0; - unsigned32 save_cln = 0; /* FIXME: This might be incorrect, cf. below */ - unsigned32 cl_start = 0; - unsigned32 ofs = 0; - unsigned32 save_ofs; - unsigned32 sec = 0; - unsigned32 byte = 0; - unsigned32 c = 0; - - if ( count == 0 ) - return cmpltd; - - if ( start > fat_fd->fat_file_size ) - set_errno_and_return_minus_one( EIO ); - - if ((count > fat_fd->size_limit) || - (start > fat_fd->size_limit - count)) - set_errno_and_return_minus_one( EIO ); - - rc = fat_file_extend(mt_entry, fat_fd, start + count, &c); - if (rc != RC_OK) - return rc; - - /* - * check whether there was enough room on device to locate - * file of 'start + count' bytes - */ - if (c != (start + count)) - count = c - start; - - if ((FAT_FD_OF_ROOT_DIR(fat_fd)) && - (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16))) - { - sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->cln); - sec += (start >> fs_info->vol.sec_log2); - byte = start & (fs_info->vol.bps - 1); - - ret = _fat_block_write(mt_entry, sec, byte, count, buf); - if ( ret < 0 ) - return -1; - - return ret; - } - - cl_start = start >> fs_info->vol.bpc_log2; - save_ofs = ofs = start & (fs_info->vol.bpc - 1); - - rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln); - if (rc != RC_OK) - return rc; - - while (count > 0) - { - c = MIN(count, (fs_info->vol.bpc - ofs)); - - sec = fat_cluster_num_to_sector_num(mt_entry, cur_cln); - sec += (ofs >> fs_info->vol.sec_log2); - byte = ofs & (fs_info->vol.bps - 1); - - ret = _fat_block_write(mt_entry, sec, byte, c, buf + cmpltd); - if ( ret < 0 ) - return -1; - - count -= c; - cmpltd += c; - save_cln = cur_cln; - rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln); - if ( rc != RC_OK ) - return rc; - - ofs = 0; - } - - /* update cache */ - /* XXX: check this - I'm not sure :( */ - fat_fd->map.file_cln = cl_start + - ((save_ofs + cmpltd - 1) >> fs_info->vol.bpc_log2); - fat_fd->map.disk_cln = save_cln; - - return cmpltd; -} - -/* fat_file_extend -- - * Extend fat-file. If new length less than current fat-file size - - * do nothing. Otherwise calculate necessary count of clusters to add, - * allocate it and add new clusters chain to the end of - * existing clusters chain. - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * new_length - new length - * a_length - placeholder for result - actual new length of file - * - * RETURNS: - * RC_OK and new length of file on success, or -1 if error occured (errno - * set appropriately) - */ -int -fat_file_extend( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 new_length, - unsigned32 *a_length - ) -{ - int rc = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 chain = 0; - unsigned32 bytes2add = 0; - unsigned32 cls2add = 0; - unsigned32 old_last_cl; - unsigned32 last_cl = 0; - unsigned32 bytes_remain = 0; - unsigned32 cls_added; - - *a_length = new_length; - - if (new_length <= fat_fd->fat_file_size) - return RC_OK; - - if ((FAT_FD_OF_ROOT_DIR(fat_fd)) && - (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16))) - set_errno_and_return_minus_one( ENOSPC ); - - bytes_remain = (fs_info->vol.bpc - - (fat_fd->fat_file_size & (fs_info->vol.bpc - 1))) & - (fs_info->vol.bpc - 1); - - bytes2add = new_length - fat_fd->fat_file_size; - - if (bytes2add > bytes_remain) - bytes2add -= bytes_remain; - else - bytes2add = 0; - - /* - * if in last cluster allocated for the file there is enough room to - * handle extention (hence we don't need to add even one cluster to the - * file ) - return - */ - if (bytes2add == 0) - return RC_OK; - - cls2add = ((bytes2add - 1) >> fs_info->vol.bpc_log2) + 1; - - rc = fat_scan_fat_for_free_clusters(mt_entry, &chain, cls2add, - &cls_added, &last_cl); - - /* this means that low level I/O error occured */ - if (rc != RC_OK) - return rc; - - /* this means that no space left on device */ - if ((cls_added == 0) && (bytes_remain == 0)) - set_errno_and_return_minus_one(ENOSPC); - - /* check wether we satisfied request for 'cls2add' clusters */ - if (cls2add != cls_added) - *a_length = new_length - - ((cls2add - cls_added - 1) << fs_info->vol.bpc_log2) - - (bytes2add & (fs_info->vol.bpc - 1)); - - /* add new chain to the end of existed */ - if ( fat_fd->fat_file_size == 0 ) - { - fat_fd->map.disk_cln = fat_fd->cln = chain; - fat_fd->map.file_cln = 0; - } - else - { - if (fat_fd->map.last_cln != FAT_UNDEFINED_VALUE) - { - old_last_cl = fat_fd->map.last_cln; - } - else - { - rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM, - (fat_fd->fat_file_size - 1), &old_last_cl); - if ( rc != RC_OK ) - { - fat_free_fat_clusters_chain(mt_entry, chain); - return rc; - } - } - - rc = fat_set_fat_cluster(mt_entry, old_last_cl, chain); - if ( rc != RC_OK ) - { - fat_free_fat_clusters_chain(mt_entry, chain); - return rc; - } - fat_buf_release(fs_info); - } - - /* update number of the last cluster of the file if it changed */ - if (cls_added != 0) - { - fat_fd->map.last_cln = last_cl; - if (fat_fd->fat_file_type == FAT_DIRECTORY) - { - rc = fat_init_clusters_chain(mt_entry, chain); - if ( rc != RC_OK ) - { - fat_free_fat_clusters_chain(mt_entry, chain); - return rc; - } - } - } - - return RC_OK; -} - -/* fat_file_truncate -- - * Truncate fat-file. If new length greater than current fat-file size - - * do nothing. Otherwise find first cluster to free and free all clusters - * in the chain starting from this cluster. - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * new_length - new length - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set appropriately) - */ -int -fat_file_truncate( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 new_length - ) -{ - int rc = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 cur_cln = 0; - unsigned32 cl_start = 0; - unsigned32 new_last_cln = FAT_UNDEFINED_VALUE; - - - if ( new_length >= fat_fd->fat_file_size ) - return rc; - - assert(fat_fd->fat_file_size); - - cl_start = (new_length + fs_info->vol.bpc - 1) >> fs_info->vol.bpc_log2; - - if ((cl_start << fs_info->vol.bpc_log2) >= fat_fd->fat_file_size) - return RC_OK; - - if (cl_start != 0) - { - rc = fat_file_lseek(mt_entry, fat_fd, cl_start - 1, &new_last_cln); - if (rc != RC_OK) - return rc; - - } - - rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln); - if (rc != RC_OK) - return rc; - - rc = fat_free_fat_clusters_chain(mt_entry, cur_cln); - if (rc != RC_OK) - return rc; - - if (cl_start != 0) - { - rc = fat_set_fat_cluster(mt_entry, new_last_cln, FAT_GENFAT_EOC); - if ( rc != RC_OK ) - return rc; - fat_fd->map.file_cln = cl_start - 1; - fat_fd->map.disk_cln = new_last_cln; - fat_fd->map.last_cln = new_last_cln; - } - return RC_OK; -} - -/* fat_file_ioctl -- - * F_CLU_NUM: - * make mapping between serial number of the cluster in fat-file and - * its real number on the volume - * - * PARAMETERS: - * fat_fd - fat-file descriptor - * mt_entry - mount table entry - * cmd - command - * ... - * - * RETURNS: - * RC_OK on success, or -1 if error occured and errno set appropriately - */ -int -fat_file_ioctl( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - int cmd, - ...) -{ - int rc = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 cur_cln = 0; - unsigned32 cl_start = 0; - unsigned32 pos = 0; - unsigned32 *ret; - va_list ap; - - va_start(ap, cmd); - - switch (cmd) - { - case F_CLU_NUM: - pos = va_arg(ap, int); - ret = va_arg(ap, int *); - - /* sanity check */ - if ( pos >= fat_fd->fat_file_size ) - set_errno_and_return_minus_one( EIO ); - - if ((FAT_FD_OF_ROOT_DIR(fat_fd)) && - (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16))) - { - /* cluster 0 (zero) reserved for root dir */ - *ret = 0; - return RC_OK; - } - - cl_start = pos >> fs_info->vol.bpc_log2; - - rc = fat_file_lseek(mt_entry, fat_fd, cl_start, &cur_cln); - if ( rc != RC_OK ) - return rc; - - *ret = cur_cln; - break; - - default: - errno = EINVAL; - rc = -1; - break; - } - return rc; -} - -/* fat_file_mark_removed -- - * Remove the fat-file descriptor from "valid" hash table, insert it - * into "removed-but-still-open" hash table and set up "removed" bit. - * - * PARAMETERS: - * fat_fd - fat-file descriptor - * mt_entry - mount table entry - * - * RETURNS: - * None - */ -void -fat_file_mark_removed( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd - ) -{ - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 key = 0; - - key = fat_construct_key(mt_entry, fat_fd->info_cln, fat_fd->info_ofs); - - _hash_delete(fs_info->vhash, key, fat_fd->ino, fat_fd); - - _hash_insert(fs_info->rhash, key, fat_fd->ino, fat_fd); - - fat_fd->flags |= FAT_FILE_REMOVED; -} - -/* fat_file_datasync -- - * Synchronize fat-file - flush all buffered data to the media. - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * - * RETURNS: - * RC_OK on success, or -1 if error occured and errno set appropriately - */ -int -fat_file_datasync( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd - ) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 cur_cln = fat_fd->cln; - bdbuf_buffer *block = NULL; - unsigned32 sec = 0; - unsigned32 i = 0; - - if (fat_fd->fat_file_size == 0) - return RC_OK; - - /* - * we can use only one bdbuf :( and we also know that cache is useless - * for sync operation, so don't use it - */ - rc = fat_buf_release(fs_info); - if (rc != RC_OK) - return rc; - - /* for each cluster of the file ... */ - while ((cur_cln & fs_info->vol.mask) != fs_info->vol.eoc_val) - { - sec = fat_cluster_num_to_sector_num(mt_entry, cur_cln); - /* for each sector in cluster ... */ - for ( i = 0; i < fs_info->vol.spc; i++ ) - { - /* ... sync it */ - sc = rtems_bdbuf_read(fs_info->vol.dev, (sec + i), &block); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one( EIO ); - - sc = rtems_bdbuf_sync(block); - if ( sc != RTEMS_SUCCESSFUL ) - set_errno_and_return_minus_one( EIO ); - } - - rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln); - if ( rc != RC_OK ) - return rc; - } - return rc; -} - -/* fat_file_size -- - * Calculate fat-file size - fat-file is nothing that clusters chain, so - * go through all clusters in the chain and count it. Only - * special case is root directory for FAT12/16 volumes. - * This function is used only for directories which are fat-files with - * non-zero length, hence 'fat_fd->cln' always contains valid data. - * Calculated size is stored in 'fat_file_size' field of fat-file - * descriptor. - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set appropriately) - */ -int -fat_file_size( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd - ) -{ - int rc = RC_OK; - fat_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 cur_cln = fat_fd->cln; - unsigned32 save_cln = 0; - - /* Have we requested root dir size for FAT12/16? */ - if ((FAT_FD_OF_ROOT_DIR(fat_fd)) && - (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16))) - { - fat_fd->fat_file_size = fs_info->vol.rdir_size; - return rc; - } - - fat_fd->fat_file_size = 0; - - while ((cur_cln & fs_info->vol.mask) != fs_info->vol.eoc_val) - { - save_cln = cur_cln; - rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln); - if ( rc != RC_OK ) - return rc; - - fat_fd->fat_file_size += fs_info->vol.bpc; - } - fat_fd->map.last_cln = save_cln; - return rc; -} - -/* hash support routines */ - -/* _hash_insert -- - * Insert elemnt into hash based on key 'key1' - * - * PARAMETERS: - * hash - hash element will be inserted into - * key1 - key on which insertion is based on - * key2 - not used during insertion - * el - element to insert - * - * RETURNS: - * None - */ -static inline void -_hash_insert(Chain_Control *hash, unsigned32 key1, unsigned32 key2, - fat_file_fd_t *el) -{ - _Chain_Append((hash) + ((key1) % FAT_HASH_MODULE), &(el)->link); -} - - -/* _hash_delete -- - * Remove element from hash - * - * PARAMETERS: - * hash - hash element will be removed from - * key1 - not used - * key2 - not used - * el - element to delete - * - * RETURNS: - * None - */ -static inline void -_hash_delete(Chain_Control *hash, unsigned32 key1, unsigned32 key2, - fat_file_fd_t *el) -{ - _Chain_Extract(&(el)->link); -} - -/* _hash_search -- - * Search element in hash. If both keys match pointer to found element - * is returned - * - * PARAMETERS: - * mt_entry - mount table entry - * hash - hash element will be removed from - * key1 - search key - * key2 - search key - * ret - placeholder for result - * - * RETURNS: - * 0 and pointer to found element on success, -1 otherwise - */ -static inline int -_hash_search( - rtems_filesystem_mount_table_entry_t *mt_entry, - Chain_Control *hash, - unsigned32 key1, - unsigned32 key2, - void **ret - ) -{ - unsigned32 mod = (key1) % FAT_HASH_MODULE; - Chain_Node *the_node = ((Chain_Control *)((hash) + mod))->first; - - for ( ; !_Chain_Is_tail((hash) + mod, the_node) ; ) - { - fat_file_fd_t *ffd = (fat_file_fd_t *)the_node; - unsigned32 ck = - fat_construct_key(mt_entry, ffd->info_cln, ffd->info_ofs); - - if ( (key1) == ck) - { - if ( ((key2) == 0) || ((key2) == ffd->ino) ) - { - *ret = (void *)the_node; - return 0; - } - } - the_node = the_node->next; - } - return -1; -} - -static int -fat_file_lseek( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 file_cln, - unsigned32 *disk_cln - ) -{ - int rc = RC_OK; -/* - assert(fat_fd->fat_file_size); - */ - if (file_cln == fat_fd->map.file_cln) - *disk_cln = fat_fd->map.disk_cln; - else - { - unsigned32 cur_cln; - unsigned32 count; - unsigned32 i; - - if (file_cln > fat_fd->map.file_cln) - { - cur_cln = fat_fd->map.disk_cln; - count = file_cln - fat_fd->map.file_cln; - } - else - { - cur_cln = fat_fd->cln; - count = file_cln; - } - - /* skip over the clusters */ - for (i = 0; i < count; i++) - { - rc = fat_get_fat_cluster(mt_entry, cur_cln, &cur_cln); - if ( rc != RC_OK ) - return rc; - } - - /* update cache */ - fat_fd->map.file_cln = file_cln; - fat_fd->map.disk_cln = cur_cln; - - *disk_cln = cur_cln; - } - return RC_OK; -} diff --git a/c/src/libfs/src/dosfs/fat_file.h b/c/src/libfs/src/dosfs/fat_file.h deleted file mode 100644 index 02baf3f1ef..0000000000 --- a/c/src/libfs/src/dosfs/fat_file.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - * fat_file.h - * - * Constants/data structures/prototypes for operations on "fat-file" - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ -#ifndef __DOSFS_FAT_FILE_H__ -#define __DOSFS_FAT_FILE_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#include - -/* "fat-file" representation - * - * the idea is: fat-file is nothing but a cluster chain, any open fat-file is - * represented in system by fat-file descriptor and has well-known - * file interface: - * - * fat_file_open() - * fat_file_close() - * fat_file_read() - * fat_file_write() - * - * Such interface hides the architecture of fat-file and represents it like - * linear file - */ - -typedef rtems_filesystem_node_types_t fat_file_type_t; - -#define FAT_DIRECTORY RTEMS_FILESYSTEM_DIRECTORY -#define FAT_FILE RTEMS_FILESYSTEM_MEMORY_FILE - -typedef struct fat_file_map_s -{ - unsigned32 file_cln; - unsigned32 disk_cln; - unsigned32 last_cln; -} fat_file_map_t; -/* - * descriptor of a fat-file - * - * To each particular clusters chain - */ -typedef struct fat_file_fd_s -{ - Chain_Node link; /* - * fat-file descriptors organized into hash; - * collision lists are handled via link - * field - */ - unsigned32 links_num; /* - * the number of fat_file_open call on - * this fat-file - */ - unsigned32 ino; /* inode, file serial number :)))) */ - fat_file_type_t fat_file_type; - unsigned32 size_limit; - unsigned32 fat_file_size; /* length */ - unsigned32 info_cln; - unsigned32 cln; - unsigned16 info_ofs; - unsigned char first_char; - unsigned8 flags; - fat_file_map_t map; - time_t mtime; - -} fat_file_fd_t; - - -#define FAT_FILE_REMOVED 0x01 - -#define FAT_FILE_IS_REMOVED(p)\ - (((p)->flags & FAT_FILE_REMOVED) ? 1 : 0) - -/* ioctl macros */ -#define F_CLU_NUM 0x01 - -/* - * Each file and directory on a MSDOS volume is unique identified by it - * location, i.e. location of it 32 Bytes Directory Entry Structure. We can - * distinguish them by cluster number it locates on and offset inside this - * cluster. But root directory on any volumes (FAT12/16/32) has no 32 Bytes - * Directory Entry Structure corresponded to it. So we assume 32 Bytes - * Directory Entry Structure of root directory locates at cluster 1 (invalid - * cluaster number) and offset 0 - */ -#define FAT_ROOTDIR_CLUSTER_NUM 0x01 - -#define FAT_FD_OF_ROOT_DIR(fat_fd) \ - ((fat_fd->info_cln == FAT_ROOTDIR_CLUSTER_NUM ) && \ - (fat_fd->info_ofs == 0)) - -#define FAT_EOF 0x00 - -/* fat_construct_key -- - * Construct key for hash access: convert (cluster num, offset) to - * (sector512 num, new offset) and than construct key as - * key = (sector512 num) << 4 | (new offset) - * - * PARAMETERS: - * cl - cluster number - * ofs - offset inside cluster 'cl' - * mt_entry - mount table entry - * - * RETURNS: - * constructed key - */ -static inline unsigned32 -fat_construct_key( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cl, - unsigned32 ofs) -{ - return ( ((fat_cluster_num_to_sector512_num(mt_entry, cl) + - (ofs >> FAT_SECTOR512_BITS)) << 4) + - ((ofs >> 5) & (FAT_DIRENTRIES_PER_SEC512 - 1)) ); -} - -/* Prototypes for "fat-file" operations */ -int -fat_file_open(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - unsigned32 ofs, - fat_file_fd_t **fat_fd); - -int -fat_file_reopen(fat_file_fd_t *fat_fd); - -int -fat_file_close(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd); - -ssize_t -fat_file_read(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 start, - unsigned32 count, - char *buf); - -ssize_t -fat_file_write(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 start, - unsigned32 count, - const char *buf); - -int -fat_file_extend(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 new_length, - unsigned32 *a_length); - -int -fat_file_truncate(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 new_length); - -int -fat_file_datasync(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd); - - -int -fat_file_ioctl(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - int cmd, - ...); - -int -fat_file_size(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd); - -void -fat_file_mark_removed(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd); - -#ifdef __cplusplus -} -#endif - -#endif /* __DOSFS_FAT_FILE_H__ */ diff --git a/c/src/libfs/src/dosfs/msdos.h b/c/src/libfs/src/dosfs/msdos.h deleted file mode 100644 index a9216b1ed3..0000000000 --- a/c/src/libfs/src/dosfs/msdos.h +++ /dev/null @@ -1,408 +0,0 @@ -/* - * msdos.h - * - * The MSDOS filesystem constants/data structures/prototypes - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ -#ifndef __DOSFS_MSDOS_H__ -#define __DOSFS_MSDOS_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#include "fat.h" -#include "fat_file.h" - -#ifndef RC_OK -#define RC_OK 0x00000000 -#endif - -#define MSDOS_NAME_NOT_FOUND_ERR 0xDD000001 - -/* - * This structure identifies the instance of the filesystem on the MSDOS - * level. - */ -typedef struct msdos_fs_info_s -{ - fat_fs_info_t fat; /* - * volume - * description - */ - rtems_filesystem_file_handlers_r *directory_handlers; /* - * a set of routines - * that handles the - * nodes of directory - * type - */ - rtems_filesystem_file_handlers_r *file_handlers; /* - * a set of routines - * that handles the - * nodes of file - * type - */ - rtems_id vol_sema; /* - * semaphore - * associated with - * the volume - */ - unsigned8 *cl_buf; /* - * just placeholder - * for anything - */ -} msdos_fs_info_t; - -/* a set of routines that handle the nodes which are directories */ -extern rtems_filesystem_file_handlers_r msdos_dir_handlers; - -/* a set of routines that handle the nodes which are files */ -extern rtems_filesystem_file_handlers_r msdos_file_handlers; - -/* Volume semaphore timeout value */ -#define MSDOS_VOLUME_SEMAPHORE_TIMEOUT 100 - -/* Node types */ -#define MSDOS_DIRECTORY RTEMS_FILESYSTEM_DIRECTORY -#define MSDOS_REGULAR_FILE RTEMS_FILESYSTEM_MEMORY_FILE - -typedef rtems_filesystem_node_types_t msdos_node_type_t; - -/* - * Macros for fetching fields from 32 bytes long FAT Directory Entry - * Structure (see M$ White Paper) - */ -#define MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE 32 /* 32 bytes */ - -#define MSDOS_DIR_NAME(x) (unsigned8 *)((x) + 0) -#define MSDOS_DIR_ATTR(x) (unsigned8 *)((x) + 11) -#define MSDOS_DIR_NT_RES(x) (unsigned8 *)((x) + 12) -#define MSDOS_DIR_CRT_TIME_TENTH(x) (unsigned8 *)((x) + 13) -#define MSDOS_DIR_CRT_TIME(x) (unsigned16 *)((x) + 14) -#define MSDOS_DIR_CRT_DATE(x) (unsigned16 *)((x) + 16) -#define MSDOS_DIR_LAST_ACCESS_DATE(x) (unsigned16 *)((x) + 18) -#define MSDOS_DIR_FIRST_CLUSTER_HI(x) (unsigned16 *)((x) + 20) -#define MSDOS_DIR_WRITE_TIME(x) (unsigned16 *)((x) + 22) -#define MSDOS_DIR_WRITE_DATE(x) (unsigned16 *)((x) + 24) -#define MSDOS_DIR_FIRST_CLUSTER_LOW(x) (unsigned16 *)((x) + 26) -#define MSDOS_DIR_FILE_SIZE(x) (unsigned32 *)((x) + 28) - -#define MSDOS_EXTRACT_CLUSTER_NUM(p) \ - (unsigned32)( (CF_LE_W(*MSDOS_DIR_FIRST_CLUSTER_LOW(p))) | \ - ((CF_LE_W((*MSDOS_DIR_FIRST_CLUSTER_HI(p))))<<16) ) - -/* - * Fields offset in 32 bytes long FAT Directory Entry - * Structure (see M$ White Paper) - */ -#define MSDOS_FILE_SIZE_OFFSET 28 -#define MSDOS_FILE_NAME_OFFSET 0 -#define MSDOS_FIRST_CLUSTER_HI_OFFSET 20 -#define MSDOS_FIRST_CLUSTER_LOW_OFFSET 26 -#define MSDOS_FILE_WDATE_OFFSET 24 -#define MSDOS_FILE_WTIME_OFFSET 22 - -/* - * Possible values of DIR_Attr field of 32 bytes long FAT Directory Entry - * Structure (see M$ White Paper) - */ -#define MSDOS_ATTR_READ_ONLY 0x01 -#define MSDOS_ATTR_HIDDEN 0x02 -#define MSDOS_ATTR_SYSTEM 0x04 -#define MSDOS_ATTR_VOLUME_ID 0x08 -#define MSDOS_ATTR_DIRECTORY 0x10 -#define MSDOS_ATTR_ARCHIVE 0x20 - -/* - * Possible values of DIR_Name[0] field of 32 bytes long FAT Directory Entry - * Structure (see M$ White Paper) - */ -#define MSDOS_THIS_DIR_ENTRY_EMPTY 0xE5 -#define MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY 0x00 - - -/* - * Macros for names parsing and formatting - */ -#define msdos_is_valid_name_char(_ch) (1) -#define msdos_is_separator(_ch) rtems_filesystem_is_separator(_ch) - -#define MSDOS_SHORT_NAME_LEN 11 /* 11 characters */ -#define MSDOS_NAME_MAX MSDOS_SHORT_NAME_LEN -#define MSDOS_NAME_MAX_WITH_DOT (MSDOS_NAME_MAX + 1) - -#define MSDOS_DOT_NAME ". " /* ".", padded to MSDOS_NAME chars */ -#define MSDOS_DOTDOT_NAME ".. " /* "..", padded to MSDOS_NAME chars */ - -typedef enum msdos_token_types_e -{ - MSDOS_NO_MORE_PATH, - MSDOS_CURRENT_DIR, - MSDOS_UP_DIR, - MSDOS_NAME, - MSDOS_INVALID_TOKEN -} msdos_token_types_t; - -/* Others macros */ -#define MSDOS_RES_NT_VALUE 0x00 -#define MSDOS_INIT_DIR_SIZE 0x00 - -/* "dot" entry offset in a directory */ -#define MSDOS_DOT_DIR_ENTRY_OFFSET 0x00 /* first entry in directory */ - -/* "dotdot" entry offset in a directory */ -#define MSDOS_DOTDOT_DIR_ENTRY_OFFSET 0x20 /* second entry in directory */ - -/* 'p' should be char* */ -#define DOT_NODE_P(p) ((char *)(p)) -#define DOTDOT_NODE_P(p) ((char *)((p) + MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE)) - -/* Size limits for files and directories (see M$ White Paper) */ -#define MSDOS_MAX_DIR_LENGHT 0x200000 /* 2,097,152 bytes */ -#define MSDOS_MAX_FILE_SIZE 0xFFFFFFFF /* 4 Gb */ - -/* - * The number of 32 bytes long FAT Directory Entry - * Structures per 512 bytes sector - */ -#define MSDOS_DPS512_NUM 16 - -/* Prototypes */ -int -msdos_initialize(rtems_filesystem_mount_table_entry_t *temp_mt_entry); - -int -msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry); - -int -msdos_eval_path(const char *pathname, /* IN */ - int flags, /* IN */ - rtems_filesystem_location_info_t *pathloc /* IN/OUT */); - -int -msdos_eval4make(const char *path, /* IN */ - rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ - const char **name /* OUT */); - -int -msdos_unlink(rtems_filesystem_location_info_t *pathloc /* IN */); - -int -msdos_free_node_info(rtems_filesystem_location_info_t *pathloc /* IN */); - -rtems_filesystem_node_types_t -msdos_node_type(rtems_filesystem_location_info_t *pathloc); - -int -msdos_mknod(const char *path, /* IN */ - mode_t mode, /* IN */ - dev_t dev, /* IN */ - rtems_filesystem_location_info_t *pathloc /* IN/OUT */); - -int -msdos_utime(rtems_filesystem_location_info_t *pathloc, /* IN */ - time_t actime, /* IN */ - time_t modtime /* IN */); - -int -msdos_initialize_support( - rtems_filesystem_mount_table_entry_t *temp_mt_entry, - rtems_filesystem_operations_table *op_table, - rtems_filesystem_file_handlers_r *file_handlers, - rtems_filesystem_file_handlers_r *directory_handlers -); - -int -msdos_file_open( - rtems_libio_t *iop, /* IN */ - const char *pathname, /* IN */ - unsigned32 flag, /* IN */ - unsigned32 mode /* IN */ -); - -int -msdos_file_close(rtems_libio_t *iop /* IN */); - -ssize_t -msdos_file_read( - rtems_libio_t *iop, /* IN */ - void *buffer, /* IN */ - unsigned32 count /* IN */ -); - -ssize_t -msdos_file_write( - rtems_libio_t *iop, /* IN */ - const void *buffer, /* IN */ - unsigned32 count /* IN */ -); - -int -msdos_file_lseek( - rtems_libio_t *iop, /* IN */ - off_t offset, /* IN */ - int whence /* IN */ -); - -int -msdos_file_stat(rtems_filesystem_location_info_t *loc, /* IN */ - struct stat *buf /* OUT */); - -int -msdos_file_ftruncate( - rtems_libio_t *iop, /* IN */ - off_t length /* IN */ -); - -int -msdos_file_sync(rtems_libio_t *iop); - -int -msdos_file_datasync(rtems_libio_t *iop); - -int -msdos_file_ioctl( - rtems_libio_t *iop, /* IN */ - unsigned32 command, /* IN */ - void *buffer /* IN */ -); - -int -msdos_file_rmnod(rtems_filesystem_location_info_t *pathloc /* IN */); - -int -msdos_dir_open( - rtems_libio_t *iop, /* IN */ - const char *pathname, /* IN */ - unsigned32 flag, /* IN */ - unsigned32 mode /* IN */ -); - -int -msdos_dir_close(rtems_libio_t *iop /* IN */); - -ssize_t -msdos_dir_read( - rtems_libio_t *iop, /* IN */ - void *buffer, /* IN */ - unsigned32 count /* IN */ -); - -int -msdos_dir_lseek( - rtems_libio_t *iop, /* IN */ - off_t offset, /* IN */ - int whence /* IN */ -); - -int -msdos_dir_rmnod(rtems_filesystem_location_info_t *pathloc /* IN */); - -int -msdos_dir_sync(rtems_libio_t *iop); - -int -msdos_dir_stat( - rtems_filesystem_location_info_t *loc, /* IN */ - struct stat *buf /* OUT */ -); - -int -msdos_creat_node(rtems_filesystem_location_info_t *parent_loc, - msdos_node_type_t type, - char *name, - mode_t mode); - -/* Misc prototypes */ -msdos_token_types_t msdos_get_token(const char *path, - char *token, - int *token_len); - -int -msdos_find_name(rtems_filesystem_location_info_t *parent_loc, - char *name); - -int -msdos_get_name_node(rtems_filesystem_location_info_t *parent_loc, - char *name, - fat_auxiliary_t *paux, - char *name_dir_entry); - -int -msdos_dir_info_remove(rtems_filesystem_location_info_t *pathloc); - -void -msdos_date_unix2dos(int unix_date, - unsigned short *time_val, - unsigned short *date); - -unsigned int -msdos_date_dos2unix(unsigned short time_val, unsigned short date); - -int -msdos_set_first_cluster_num(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd); - -int -msdos_set_file_size(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd); - -int -msdos_set_first_char4file_name(rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cl, - unsigned32 ofs, - unsigned char first_char); - -int -msdos_set_dir_wrt_time_and_date( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd -); - - -int -msdos_dir_is_empty(rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - rtems_boolean *ret_val); - -int -msdos_find_name_in_fat_file( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - char *name, - fat_auxiliary_t *paux, - char *name_dir_entry); - -int -msdos_find_node_by_cluster_num_in_fat_file( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 cl4find, - fat_auxiliary_t *paux, - char *dir_entry -); - -int -msdos_get_dotdot_dir_info_cluster_num_and_offset( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - fat_auxiliary_t *paux, - char *dir_entry -); - -#ifdef __cplusplus -} -#endif - -#endif /* __DOSFS_MSDOS_H__ */ diff --git a/c/src/libfs/src/dosfs/msdos_create.c b/c/src/libfs/src/dosfs/msdos_create.c deleted file mode 100644 index 4b4c7001ca..0000000000 --- a/c/src/libfs/src/dosfs/msdos_create.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Routine to create a new MSDOS filesystem node - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - * - */ -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include - -#include "fat.h" -#include "fat_fat_operations.h" -#include "fat_file.h" - -#include "msdos.h" - -/* msdos_creat_node -- - * Create a new node. If a new node is file, FAT 32 Bytes Directory - * Entry Structure (see M$ White Paper) is initialized, free space is - * found in parent directory and structure is written to the disk. - * In case of directory, all above steps present and also new cluster - * is allocated for a new directory and dot and dotdot nodes are created - * in alloceted cluster. - * - * PARAMETERS: - * parent_loc - parent (directory we are going to create node in) - * type - new node type (file or directory) - * name - new node name - * mode - mode - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set appropriately). - * - */ -int -msdos_creat_node( - rtems_filesystem_location_info_t *parent_loc, - msdos_node_type_t type, - char *name, - mode_t mode - ) -{ - int rc = RC_OK; - ssize_t ret = 0; - msdos_fs_info_t *fs_info = parent_loc->mt_entry->fs_info; - fat_file_fd_t *parent_fat_fd = parent_loc->node_access; - fat_file_fd_t *fat_fd = NULL; - time_t time_ret = 0; - unsigned16 time_val = 0; - unsigned16 date = 0; - fat_auxiliary_t aux; - unsigned char new_node[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE]; - unsigned char dot_dotdot[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE * 2]; - - memset(new_node, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE); - memset(dot_dotdot, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE * 2); - - /* set up name */ - strncpy(MSDOS_DIR_NAME(new_node), name, MSDOS_NAME_MAX); - - /* fill reserved field */ - *MSDOS_DIR_NT_RES(new_node) = MSDOS_RES_NT_VALUE; - - /* set up last write date and time */ - time_ret = time(NULL); - if ( time_ret == -1 ) - return -1; - - msdos_date_unix2dos(time_ret, &time_val, &date); - *MSDOS_DIR_WRITE_TIME(new_node) = CT_LE_W(time_val); - *MSDOS_DIR_WRITE_DATE(new_node) = CT_LE_W(date); - - /* initialize directory/file size */ - *MSDOS_DIR_FILE_SIZE(new_node) = MSDOS_INIT_DIR_SIZE; - - if (type == MSDOS_DIRECTORY) - *MSDOS_DIR_ATTR(new_node) |= MSDOS_ATTR_DIRECTORY; - else - *MSDOS_DIR_ATTR(new_node) |= MSDOS_ATTR_ARCHIVE; - - /* - * find free space in the parent directory and write new initialized - * FAT 32 Bytes Directory Entry Structure (see M$ White Paper) - * to the disk - */ - rc = msdos_get_name_node(parent_loc, NULL, &aux, new_node); - if ( rc != RC_OK ) - return rc; - - /* - * if we create a new file we are done, if directory there are more steps - * to do - */ - if (type == MSDOS_DIRECTORY) - { - /* open new directory as fat-file */ - rc = fat_file_open(parent_loc->mt_entry, aux.cln, aux.ofs, &fat_fd); - if (rc != RC_OK) - goto err; - - /* - * we opened fat-file for node we just created, so initialize fat-file - * descritor - */ - fat_fd->info_cln = aux.cln; - fat_fd->info_ofs = aux.ofs; - fat_fd->fat_file_size = 0; - fat_fd->fat_file_type = FAT_DIRECTORY; - fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT; - - /* - * dot and dotdot entries are identical to new node except the - * names - */ - memcpy(DOT_NODE_P(dot_dotdot), new_node, - MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE); - memcpy(DOTDOT_NODE_P(dot_dotdot), new_node, - MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE); - memcpy(MSDOS_DIR_NAME(DOT_NODE_P(dot_dotdot)), MSDOS_DOT_NAME, - MSDOS_NAME_MAX); - memcpy(MSDOS_DIR_NAME(DOTDOT_NODE_P(dot_dotdot)), MSDOS_DOTDOT_NAME, - MSDOS_NAME_MAX); - - /* set up cluster num for dotdot entry */ - /* - * here we can ommit FAT32 condition because for all FAT types dirs - * right under root dir should contain 0 in dotdot entry but for - * FAT12/16 parent_fat_fd->cluster_num always contains such value - */ - if ((FAT_FD_OF_ROOT_DIR(parent_fat_fd)) && - (fs_info->fat.vol.type & FAT_FAT32)) - { - *MSDOS_DIR_FIRST_CLUSTER_LOW(DOTDOT_NODE_P(dot_dotdot)) = 0x0000; - *MSDOS_DIR_FIRST_CLUSTER_HI(DOTDOT_NODE_P(dot_dotdot)) = 0x0000; - } - else - { - *MSDOS_DIR_FIRST_CLUSTER_LOW(DOTDOT_NODE_P(dot_dotdot)) = - CT_LE_W((unsigned16)((parent_fat_fd->cln) & 0x0000FFFF)); - *MSDOS_DIR_FIRST_CLUSTER_HI(DOTDOT_NODE_P(dot_dotdot)) = - CT_LE_W((unsigned16)(((parent_fat_fd->cln) & 0xFFFF0000)>>16)); - } - - /* - * write dot and dotdot entries to new fat-file: currently fat-file - * correspondes to a new node is zero length, so it will be extended - * by one cluster and entries will be written - */ - ret = fat_file_write(parent_loc->mt_entry, fat_fd, 0, - MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE * 2, - dot_dotdot); - if (ret < 0) - { - rc = -1; - goto error; - } - - /* increment fat-file size by cluster size */ - fat_fd->fat_file_size += fs_info->fat.vol.bpc; - - /* set up cluster num for dot entry */ - *MSDOS_DIR_FIRST_CLUSTER_LOW(DOT_NODE_P(dot_dotdot)) = - CT_LE_W((unsigned16)((fat_fd->cln) & 0x0000FFFF)); - *MSDOS_DIR_FIRST_CLUSTER_HI(DOT_NODE_P(dot_dotdot)) = - CT_LE_W((unsigned16)(((fat_fd->cln) & 0xFFFF0000) >> 16)); - - /* rewrite dot entry */ - ret = fat_file_write(parent_loc->mt_entry, fat_fd, 0, - MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE, - DOT_NODE_P(dot_dotdot)); - if (ret < 0) - { - rc = -1; - goto error; - } - - /* write first cluster num of a new directory to disk */ - rc = msdos_set_first_cluster_num(parent_loc->mt_entry, fat_fd); - if (rc != RC_OK) - goto error; - - fat_file_close(parent_loc->mt_entry, fat_fd); - } - return RC_OK; - -error: - fat_file_close(parent_loc->mt_entry, fat_fd); - -err: - /* mark 32bytes structure on the disk as free */ - msdos_set_first_char4file_name(parent_loc->mt_entry, aux.cln, aux.ofs, - 0xE5); - return rc; -} diff --git a/c/src/libfs/src/dosfs/msdos_dir.c b/c/src/libfs/src/dosfs/msdos_dir.c deleted file mode 100644 index 93449cd2fb..0000000000 --- a/c/src/libfs/src/dosfs/msdos_dir.c +++ /dev/null @@ -1,483 +0,0 @@ -/* - * MSDOS directory handlers implementation - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fat.h" -#include "fat_fat_operations.h" -#include "fat_file.h" - -#include "msdos.h" - -/* msdos_dir_open -- - * Open fat-file which correspondes to the directory being opened and - * set offset field of file control block to zero. - * - * PARAMETERS: - * iop - file control block - * pathname - name - * flag - flags - * mode - mode - * - * RETURNS: - * RC_OK, if directory opened successfully, or -1 if error occured (errno - * set apropriately) - */ -int -msdos_dir_open(rtems_libio_t *iop, const char *pathname, unsigned32 flag, - unsigned32 mode) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - fat_file_fd_t *fat_fd = iop->file_info; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one( EIO ); - - rc = fat_file_reopen(fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - iop->offset = 0; - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; -} - -/* msdos_dir_close -- - * Close fat-file which correspondes to the directory being closed - * - * PARAMETERS: - * iop - file control block - * - * RETURNS: - * RC_OK, if directory closed successfully, or -1 if error occured (errno - * set apropriately. - */ -int -msdos_dir_close(rtems_libio_t *iop) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - fat_file_fd_t *fat_fd = iop->file_info; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one( EIO ); - - rc = fat_file_close(iop->pathinfo.mt_entry, fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; -} - -/* msdos_dir_read -- - * This routine will read the next directory entry based on the directory - * offset. The offset should be equal to -n- time the size of an - * individual dirent structure. If n is not an integer multiple of the - * sizeof a dirent structure, an integer division will be performed to - * determine directory entry that will be returned in the buffer. Count - * should reflect -m- times the sizeof dirent bytes to be placed in the - * buffer. - * If there are not -m- dirent elements from the current directory - * position to the end of the exisiting file, the remaining entries will - * be placed in the buffer and the returned value will be equal to - * -m actual- times the size of a directory entry. - * - * PARAMETERS: - * iop - file control block - * buffer - buffer provided by user - * count - count of bytes to read - * - * RETURNS: - * the number of bytes read on success, or -1 if error occured (errno - * set apropriately). - */ -ssize_t -msdos_dir_read(rtems_libio_t *iop, void *buffer, unsigned32 count) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - fat_file_fd_t *fat_fd = iop->file_info; - fat_file_fd_t *tmp_fat_fd = NULL; - struct dirent tmp_dirent; - unsigned32 start = 0; - ssize_t ret = 0; - unsigned32 cmpltd = 0; - unsigned32 j = 0, i = 0; - unsigned32 bts2rd = 0; - unsigned32 cur_cln = 0; - - /* - * cast start and count - protect against using sizes that are not exact - * multiples of the -dirent- size. These could result in unexpected - * results - */ - start = iop->offset / sizeof(struct dirent); - count = (count / sizeof(struct dirent)) * sizeof(struct dirent); - - /* - * optimization: we know that root directory for FAT12/16 volumes is - * sequential set of sectors and any cluster is sequential set of sectors - * too, so read such set of sectors is quick operation for low-level IO - * layer. - */ - bts2rd = (FAT_FD_OF_ROOT_DIR(fat_fd) && - (fs_info->fat.vol.type & (FAT_FAT12 | FAT_FAT16))) ? - fat_fd->fat_file_size : - fs_info->fat.vol.bpc; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - while (count > 0) - { - /* - * fat-file is already opened by open call, so read it - * Always read directory fat-file from the beggining because of MSDOS - * directories feature :( - we should count elements currently - * present in the directory because there may be holes :) - */ - ret = fat_file_read(iop->pathinfo.mt_entry, fat_fd, (j * bts2rd), - bts2rd, fs_info->cl_buf); - if (ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE) - { - rtems_semaphore_release(fs_info->vol_sema); - set_errno_and_return_minus_one(EIO); - } - - for (i = 0; i < ret; i += MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE) - { - if ((*MSDOS_DIR_NAME(fs_info->cl_buf + i)) == - MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY) - { - rtems_semaphore_release(fs_info->vol_sema); - return cmpltd; - } - - if ((*MSDOS_DIR_NAME(fs_info->cl_buf + i)) == - MSDOS_THIS_DIR_ENTRY_EMPTY) - continue; - - /* - * skip active entries until get the entry to start from - */ - if (start) - { - start--; - continue; - } - - /* - * Move the entry to the return buffer - * - * unfortunately there is no method to extract ino except to - * open fat-file descriptor :( ... so, open it - */ - - /* get number of cluster we are working with */ - rc = fat_file_ioctl(iop->pathinfo.mt_entry, fat_fd, F_CLU_NUM, - j * bts2rd, &cur_cln); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - rc = fat_file_open(iop->pathinfo.mt_entry, cur_cln, i, - &tmp_fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - tmp_fat_fd->info_cln = cur_cln; - tmp_fat_fd->info_ofs = i; - - /* fill in dirent structure */ - /* XXX: from what and in what d_off should be computed ?! */ - tmp_dirent.d_off = start + cmpltd; - tmp_dirent.d_reclen = sizeof(struct dirent); - tmp_dirent.d_ino = tmp_fat_fd->ino; - tmp_dirent.d_namlen = MSDOS_SHORT_NAME_LEN; - memcpy(tmp_dirent.d_name, MSDOS_DIR_NAME((fs_info->cl_buf + i)), - MSDOS_SHORT_NAME_LEN); - - /* d_name is null-terminated */ - tmp_dirent.d_name[MSDOS_SHORT_NAME_LEN] = 0; - memcpy(buffer + cmpltd, &tmp_dirent, sizeof(struct dirent)); - - iop->offset = iop->offset + sizeof(struct dirent); - cmpltd += (sizeof(struct dirent)); - count -= (sizeof(struct dirent)); - - /* inode number extracted, close fat-file */ - rc = fat_file_close(iop->pathinfo.mt_entry, tmp_fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - if (count <= 0) - break; - } - j++; - } - - rtems_semaphore_release(fs_info->vol_sema); - return cmpltd; -} - -/* msdos_dir_write -- - * no write for directory - */ - -/* msdos_dir_lseek -- - * - * This routine will behave in one of three ways based on the state of - * argument whence. Based on the state of its value the offset argument will - * be interpreted using one of the following methods: - * - * SEEK_SET - offset is the absolute byte offset from the start of the - * logical start of the dirent sequence that represents the - * directory - * SEEK_CUR - offset is used as the relative byte offset from the current - * directory position index held in the iop structure - * SEEK_END - N/A --> This will cause an assert. - * - * PARAMETERS: - * iop - file control block - * offset - offset - * whence - predefine directive - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno - * set apropriately). - */ -int -msdos_dir_lseek(rtems_libio_t *iop, off_t offset, int whence) -{ - switch (whence) - { - case SEEK_SET: - case SEEK_CUR: - break; - /* - * Movement past the end of the directory via lseek is not a - * permitted operation - */ - case SEEK_END: - default: - set_errno_and_return_minus_one( EINVAL ); - break; - } - return RC_OK; -} - -/* msdos_dir_stat -- - * - * This routine will obtain the following information concerning the current - * directory: - * st_dev device id - * st_ino node serial number :) - * st_mode mode extracted from the node - * st_size total size in bytes - * st_blksize blocksize for filesystem I/O - * st_blocks number of blocks allocated - * stat_mtime time of last modification - * - * PARAMETERS: - * loc - this directory - * buf - stat buffer provided by user - * - * RETURNS: - * RC_OK and filled stat buffer on success, or -1 if error occured (errno - * set apropriately). - */ -int -msdos_dir_stat( - rtems_filesystem_location_info_t *loc, - struct stat *buf - ) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = loc->mt_entry->fs_info; - fat_file_fd_t *fat_fd = loc->node_access; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - buf->st_dev = fs_info->fat.vol.dev; - buf->st_ino = fat_fd->ino; - buf->st_mode = S_IFDIR; - buf->st_rdev = 0ll; - buf->st_size = fat_fd->fat_file_size; - buf->st_blocks = fat_fd->fat_file_size >> FAT_SECTOR512_BITS; - buf->st_blksize = fs_info->fat.vol.bps; - buf->st_mtime = fat_fd->mtime; - - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; -} - -/* msdos_dir_truncate -- - * No truncate for directory. - * - * PARAMETERS: - * - * RETURNS: - * - */ - -/* msdos_dir_sync -- - * The following routine does a syncronization on a MSDOS directory node. - * DIR_WrtTime, DIR_WrtDate and DIR_fileSize fields of 32 Bytes Directory - * Entry Structure(see M$ White Paper) should not be updated for - * directories, so only call to corresponding fat-file routine. - * - * PARAMETERS: - * iop - file control block - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set apropriately). - */ -int -msdos_dir_sync(rtems_libio_t *iop) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - fat_file_fd_t *fat_fd = iop->file_info; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - rc = fat_file_datasync(iop->pathinfo.mt_entry, fat_fd); - - rtems_semaphore_release(fs_info->vol_sema); - return rc; -} - -/* msdos_dir_rmnod -- - * Remove directory node. - * - * Check that this directory node is not opened as fat-file, is empty and - * not filesystem root node. If all this conditions met then delete. - * - * PARAMETERS: - * pathloc - node description - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set apropriately). - */ -int -msdos_dir_rmnod(rtems_filesystem_location_info_t *pathloc) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info; - fat_file_fd_t *fat_fd = pathloc->node_access; - rtems_boolean is_empty = FALSE; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - /* - * We deny attemp to delete open directory (if directory is current - * directory we assume it is open one) - */ - if (fat_fd->links_num > 1) - { - rtems_semaphore_release(fs_info->vol_sema); - set_errno_and_return_minus_one(EBUSY); - } - - /* - * You cannot remove a node that still has children - */ - rc = msdos_dir_is_empty(pathloc->mt_entry, fat_fd, &is_empty); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - if (!is_empty) - { - rtems_semaphore_release(fs_info->vol_sema); - set_errno_and_return_minus_one(ENOTEMPTY); - } - - /* - * You cannot remove the file system root node. - */ - if (pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access) - { - rtems_semaphore_release(fs_info->vol_sema); - set_errno_and_return_minus_one(EBUSY); - } - - /* - * You cannot remove a mountpoint. - * not used - mount() not implemenetd yet. - */ - - /* mark file removed */ - rc = msdos_set_first_char4file_name(pathloc->mt_entry, fat_fd->info_cln, - fat_fd->info_ofs, - MSDOS_THIS_DIR_ENTRY_EMPTY); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - fat_file_mark_removed(pathloc->mt_entry, fat_fd); - - rtems_semaphore_release(fs_info->vol_sema); - return rc; -} diff --git a/c/src/libfs/src/dosfs/msdos_eval.c b/c/src/libfs/src/dosfs/msdos_eval.c deleted file mode 100644 index 3eba0e63e8..0000000000 --- a/c/src/libfs/src/dosfs/msdos_eval.c +++ /dev/null @@ -1,435 +0,0 @@ -/* - * MSDOS evaluation routines - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fat.h" -#include "fat_fat_operations.h" -#include "fat_file.h" - -#include "msdos.h" - -/* msdos_set_handlers -- - * Set handlers for the node with specified type(i.e. handlers for file - * or directory). - * - * PARAMETERS: - * loc - node description - * - * RETURNS: - * None - */ -static void -msdos_set_handlers(rtems_filesystem_location_info_t *loc) -{ - msdos_fs_info_t *fs_info = loc->mt_entry->fs_info; - fat_file_fd_t *fat_fd = loc->node_access; - - if (fat_fd->fat_file_type == FAT_DIRECTORY) - loc->handlers = fs_info->directory_handlers; - else - loc->handlers = fs_info->file_handlers; -} - -/* msdos_eval_path -- - * - * The following routine evaluate path for a node that wishes to be - * accessed. Structure 'pathloc' is returned with a pointer to the - * node to be accessed. - * - * PARAMETERS: - * pathname - path for evaluation - * flags - flags - * pathloc - node description (IN/OUT) - * - * RETURNS: - * RC_OK and filled pathloc on success, or -1 if error occured - * (errno set appropriately) - * - */ -int -msdos_eval_path( - const char *pathname, - int flags, - rtems_filesystem_location_info_t *pathloc - ) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info; - fat_file_fd_t *fat_fd = NULL; - rtems_filesystem_location_info_t newloc; - int i = 0; - int len = 0; - msdos_token_types_t type = MSDOS_CURRENT_DIR; - char token[MSDOS_NAME_MAX + 1]; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - if (!pathloc->node_access) - { - errno = ENOENT; - rc = -1; - goto err; - } - - fat_fd = pathloc->node_access; - - rc = fat_file_reopen(fat_fd); - if (rc != RC_OK) - goto err; - - while ((type != MSDOS_NO_MORE_PATH) && (type != MSDOS_INVALID_TOKEN)) - { - type = msdos_get_token(&pathname[i], token, &len); - i += len; - - fat_fd = pathloc->node_access; - - switch (type) - { - case MSDOS_UP_DIR: - /* - * Only a directory can be decended into. - */ - if (fat_fd->fat_file_type != FAT_DIRECTORY) - { - errno = ENOTDIR; - rc = -1; - goto error; - } - - /* - * Am I at the root of this mounted filesystem? - */ - if (pathloc->node_access == - pathloc->mt_entry->mt_fs_root.node_access) - { - /* - * Am I at the root of all filesystems? - * XXX: MSDOS is not supposed to be base fs. - */ - if (pathloc->node_access == - rtems_filesystem_root.node_access) - { - break; /* Throw out the .. in this case */ - } - else - { - newloc = pathloc->mt_entry->mt_point_node; - *pathloc = newloc; - - rc = fat_file_close(pathloc->mt_entry, fat_fd); - if (rc != RC_OK) - goto err; - - rtems_semaphore_release(fs_info->vol_sema); - return (*pathloc->ops->evalpath_h)(&(pathname[i-len]), - flags, pathloc); - } - } - else - { - rc = msdos_find_name(pathloc, token); - if (rc != RC_OK) - { - if (rc == MSDOS_NAME_NOT_FOUND_ERR) - { - errno = ENOENT; - rc = -1; - } - goto error; - } - } - break; - - case MSDOS_NAME: - /* - * Only a directory can be decended into. - */ - if (fat_fd->fat_file_type != FAT_DIRECTORY) - { - errno = ENOTDIR; - rc = -1; - goto error; - } - - /* - * Otherwise find the token name in the present location and - * set the node access to the point we have found. - */ - rc = msdos_find_name(pathloc, token); - if (rc != RC_OK) - { - if (rc == MSDOS_NAME_NOT_FOUND_ERR) - { - errno = ENOENT; - rc = -1; - } - goto error; - } - break; - - case MSDOS_NO_MORE_PATH: - case MSDOS_CURRENT_DIR: - break; - - case MSDOS_INVALID_TOKEN: - errno = ENAMETOOLONG; - rc = -1; - goto error; - break; - - } - } - - /* - * Always return the root node. - * - * If we are at a node that is a mount point. Set loc to the - * new fs root node and let let the mounted filesystem set the handlers. - * - * NOTE: The behavior of stat() on a mount point appears to be - * questionable. - * NOTE: MSDOS filesystem currently doesn't support mount functionality -> - * action not implemented - */ - fat_fd = pathloc->node_access; - - msdos_set_handlers(pathloc); - - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; - -error: - fat_file_close(pathloc->mt_entry, fat_fd); - -err: - rtems_semaphore_release(fs_info->vol_sema); - return rc; -} - -/* msdos_eval4make -- - * The following routine evaluate path for a new node to be created. - * 'pathloc' is returned with a pointer to the parent of the new node. - * 'name' is returned with a pointer to the first character in the - * new node name. The parent node is verified to be a directory. - * - * PARAMETERS: - * path - path for evaluation - * pathloc - IN/OUT (start point for evaluation/parent directory for - * creation) - * name - new node name - * - * RETURNS: - * RC_OK, filled pathloc for parent directory and name of new node on - * success, or -1 if error occured (errno set appropriately) - */ -int -msdos_eval4make( - const char *path, - rtems_filesystem_location_info_t *pathloc, - const char **name - ) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info; - fat_file_fd_t *fat_fd = NULL; - rtems_filesystem_location_info_t newloc; - msdos_token_types_t type; - int i = 0; - int len; - char token[ MSDOS_NAME_MAX + 1 ]; - rtems_boolean done = 0; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - if (!pathloc->node_access) - { - errno = ENOENT; - rc = -1; - goto err; - } - - fat_fd = pathloc->node_access; - - rc = fat_file_reopen(fat_fd); - if (rc != RC_OK) - goto err; - - while (!done) - { - type = msdos_get_token(&path[i], token, &len); - i += len; - fat_fd = pathloc->node_access; - - switch (type) - { - case MSDOS_UP_DIR: - /* - * Only a directory can be decended into. - */ - if (fat_fd->fat_file_type != FAT_DIRECTORY) - { - errno = ENOTDIR; - rc = -1; - goto error; - } - - /* - * Am I at the root of this mounted filesystem? - */ - if (pathloc->node_access == - pathloc->mt_entry->mt_fs_root.node_access) - { - /* - * Am I at the root of all filesystems? - * XXX: MSDOS is not supposed to be base fs. - */ - if (pathloc->node_access == - rtems_filesystem_root.node_access) - { - break; /* Throw out the .. in this case */ - } - else - { - newloc = pathloc->mt_entry->mt_point_node; - *pathloc = newloc; - - rc = fat_file_close(pathloc->mt_entry, fat_fd); - if (rc != RC_OK) - goto err; - - rtems_semaphore_release(fs_info->vol_sema); - return (*pathloc->ops->evalformake_h)(&path[i-len], - pathloc, name); - } - } - else - { - rc = msdos_find_name(pathloc, token); - if (rc != RC_OK) - { - if (rc == MSDOS_NAME_NOT_FOUND_ERR) - { - errno = ENOENT; - rc = -1; - } - goto error; - } - } - break; - - case MSDOS_NAME: - /* - * Only a directory can be decended into. - */ - if (fat_fd->fat_file_type != FAT_DIRECTORY) - { - errno = ENOTDIR; - rc = -1; - goto error; - } - - /* - * Otherwise find the token name in the present location and - * set the node access to the point we have found. - */ - rc = msdos_find_name(pathloc, token); - if (rc) - { - if (rc != MSDOS_NAME_NOT_FOUND_ERR) - { - errno = ENOENT; - rc = -1; - goto error; - } - else - done = TRUE; - } - break; - - case MSDOS_NO_MORE_PATH: - errno = EEXIST; - rc = -1; - goto error; - break; - - case MSDOS_CURRENT_DIR: - break; - - case MSDOS_INVALID_TOKEN: - errno = ENAMETOOLONG; - rc = -1; - goto error; - break; - - } - } - - *name = &path[i - len]; - - /* - * We have evaluated the path as far as we can. - * Verify there is not any invalid stuff at the end of the name. - */ - for( ; path[i] != '\0'; i++) - { - if (!msdos_is_separator(path[i])) - { - errno = ENOENT; - rc = -1; - goto error; - } - } - - fat_fd = pathloc->node_access; - - if (fat_fd->fat_file_type != FAT_DIRECTORY) - { - errno = ENOTDIR; - rc = -1; - goto error; - } - - msdos_set_handlers(pathloc); - - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; - -error: - fat_file_close(pathloc->mt_entry, fat_fd); - -err: - rtems_semaphore_release(fs_info->vol_sema); - return rc; -} diff --git a/c/src/libfs/src/dosfs/msdos_file.c b/c/src/libfs/src/dosfs/msdos_file.c deleted file mode 100644 index da36827338..0000000000 --- a/c/src/libfs/src/dosfs/msdos_file.c +++ /dev/null @@ -1,485 +0,0 @@ -/* - * MSDOS file handlers implementation - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include -#include -#include - -#include "fat.h" -#include "fat_fat_operations.h" -#include "fat_file.h" - -#include "msdos.h" - -/* msdos_file_open -- - * Open fat-file which correspondes to the file - * - * PARAMETERS: - * iop - file control block - * pathname - name - * flag - flags - * mode - mode - * - * RETURNS: - * RC_OK, if file opened successfully, or -1 if error occured - * and errno set appropriately - */ -int -msdos_file_open(rtems_libio_t *iop, const char *pathname, unsigned32 flag, - unsigned32 mode) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - fat_file_fd_t *fat_fd = iop->file_info; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - rc = fat_file_reopen(fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - if (iop->flags & LIBIO_FLAGS_APPEND) - iop->offset = fat_fd->fat_file_size; - - iop->size = fat_fd->fat_file_size; - - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; -} - -/* msdos_file_close -- - * Close fat-file which correspondes to the file. If fat-file descriptor - * which correspondes to the file is not marked "removed", synchronize - * size, first cluster number, write time and date fields of the file. - * - * PARAMETERS: - * iop - file control block - * - * RETURNS: - * RC_OK, if file closed successfully, or -1 if error occured (errno set - * appropriately) - */ -int -msdos_file_close(rtems_libio_t *iop) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - fat_file_fd_t *fat_fd = iop->file_info; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - /* - * if fat-file descriptor is not marked as "removed", synchronize - * size, first cluster number, write time and date fields of the file - */ - if (!FAT_FILE_IS_REMOVED(fat_fd)) - { - rc = msdos_set_first_cluster_num(iop->pathinfo.mt_entry, fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - rc = msdos_set_file_size(iop->pathinfo.mt_entry, fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - rc = msdos_set_dir_wrt_time_and_date(iop->pathinfo.mt_entry, fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - } - - rc = fat_file_close(iop->pathinfo.mt_entry, fat_fd); - - rtems_semaphore_release(fs_info->vol_sema); - return rc; -} - -/* msdos_file_read -- - * This routine read from file pointed to by file control block into - * the specified data buffer provided by user - * - * PARAMETERS: - * iop - file control block - * buffer - buffer provided by user - * count - the number of bytes to read - * - * RETURNS: - * the number of bytes read on success, or -1 if error occured (errno set - * appropriately) - */ -ssize_t -msdos_file_read(rtems_libio_t *iop, void *buffer, unsigned32 count) -{ - ssize_t ret = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - fat_file_fd_t *fat_fd = iop->file_info; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - ret = fat_file_read(iop->pathinfo.mt_entry, fat_fd, iop->offset, count, - buffer); - - rtems_semaphore_release(fs_info->vol_sema); - return ret; -} - -/* msdos_file_write -- - * This routine writes the specified data buffer into the file pointed to - * by file control block. - * - * PARAMETERS: - * iop - file control block - * buffer - data to write - * count - count of bytes to write - * - * RETURNS: - * the number of bytes written on success, or -1 if error occured - * and errno set appropriately - */ -ssize_t -msdos_file_write(rtems_libio_t *iop,const void *buffer, unsigned32 count) -{ - ssize_t ret = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - fat_file_fd_t *fat_fd = iop->file_info; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - ret = fat_file_write(iop->pathinfo.mt_entry, fat_fd, iop->offset, count, - buffer); - if (ret < 0) - { - rtems_semaphore_release(fs_info->vol_sema); - return -1; - } - - /* - * update file size in both fat-file descriptor and file control block if - * file was extended - */ - if (iop->offset + ret > fat_fd->fat_file_size) - fat_fd->fat_file_size = iop->offset + ret; - - iop->size = fat_fd->fat_file_size; - - rtems_semaphore_release(fs_info->vol_sema); - return ret; -} - -/* msdos_file_lseek -- - * Process lseek call to the file: extend file if lseek is up to the end - * of the file. - * - * PARAMETERS: - * iop - file control block - * offset - new offset - * whence - predefine directive - * - * RETURNS: - * new offset on success, or -1 if error occured (errno set - * appropriately). - */ -int -msdos_file_lseek(rtems_libio_t *iop, off_t offset, int whence) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - fat_file_fd_t *fat_fd = iop->file_info; - unsigned32 real_size = 0; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - rc = fat_file_extend(iop->pathinfo.mt_entry, fat_fd, iop->offset, - &real_size); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - if (real_size > fat_fd->fat_file_size) - fat_fd->fat_file_size = iop->offset = real_size; - - iop->size = fat_fd->fat_file_size; - - rtems_semaphore_release(fs_info->vol_sema); - return iop->offset; -} - -/* msdos_file_stat -- - * - * PARAMETERS: - * loc - node description - * buf - stat buffer provided by user - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set appropriately) - */ -int -msdos_file_stat( - rtems_filesystem_location_info_t *loc, - struct stat *buf - ) -{ - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = loc->mt_entry->fs_info; - fat_file_fd_t *fat_fd = loc->node_access; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - buf->st_dev = fs_info->fat.vol.dev; - buf->st_ino = fat_fd->ino; - buf->st_mode = S_IFREG; - buf->st_rdev = 0ll; - buf->st_size = fat_fd->fat_file_size; - buf->st_blocks = fat_fd->fat_file_size >> FAT_SECTOR512_BITS; - buf->st_blksize = fs_info->fat.vol.bps; - buf->st_mtime = fat_fd->mtime; - - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; -} - -/* msdos_file_ftruncate -- - * Truncate the file (if new length is greater then current do nothing). - * - * PARAMETERS: - * iop - file control block - * length - new length - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set appropriately). - */ -int -msdos_file_ftruncate(rtems_libio_t *iop, off_t length) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - fat_file_fd_t *fat_fd = iop->file_info; - - if (length >= fat_fd->fat_file_size) - return RC_OK; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - rc = fat_file_truncate(iop->pathinfo.mt_entry, fat_fd, length); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - /* - * fat_file_truncate do nothing if new length >= fat-file size, so update - * file size only if length < fat-file size - */ - if (length < fat_fd->fat_file_size) - iop->size = fat_fd->fat_file_size = length; - - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; -} - -/* msdos_file_sync -- - * Synchronize file - synchronize file data and if file is not removed - * synchronize file metadata. - * - * PARAMETERS: - * iop - file control block - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set appropriately) - */ -int -msdos_file_sync(rtems_libio_t *iop) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - fat_file_fd_t *fat_fd = iop->file_info; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - /* synchronize file data */ - rc = fat_file_datasync(iop->pathinfo.mt_entry, fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - /* - * if fat-file descriptor is not marked "removed" - synchronize file - * metadata - */ - if (!FAT_FILE_IS_REMOVED(fat_fd)) - { - rc = msdos_set_first_cluster_num(iop->pathinfo.mt_entry, fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - rc = msdos_set_file_size(iop->pathinfo.mt_entry, fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - rc = msdos_set_dir_wrt_time_and_date(iop->pathinfo.mt_entry, fat_fd); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - } - - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; -} - -/* msdos_file_datasync -- - * Synchronize file - synchronize only file data (metadata is letf intact). - * - * PARAMETERS: - * iop - file control block - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set appropriately) - */ -int -msdos_file_datasync(rtems_libio_t *iop) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - fat_file_fd_t *fat_fd = iop->file_info; - msdos_fs_info_t *fs_info = iop->pathinfo.mt_entry->fs_info; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - /* synchronize file data */ - rc = fat_file_datasync(iop->pathinfo.mt_entry, fat_fd); - - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; -} - - -/* msdos_file_ioctl -- - * - * - * PARAMETERS: - * iop - file control block - * ... - * - * RETURNS: - * - */ -int -msdos_file_ioctl(rtems_libio_t *iop,unsigned32 command, void *buffer) -{ - int rc = RC_OK; - - return rc; -} - -/* msdos_file_rmnod -- - * Remove node associated with a file - set up first name character to - * predefined value(and write it to the disk), and mark fat-file which - * correspondes to the file as "removed" - * - * PARAMETERS: - * pathloc - node description - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set appropriately) - */ -int -msdos_file_rmnod(rtems_filesystem_location_info_t *pathloc) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info; - fat_file_fd_t *fat_fd = pathloc->node_access; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - /* mark file removed */ - rc = msdos_set_first_char4file_name(pathloc->mt_entry, fat_fd->info_cln, - fat_fd->info_ofs, - MSDOS_THIS_DIR_ENTRY_EMPTY); - if (rc != RC_OK) - { - rtems_semaphore_release(fs_info->vol_sema); - return rc; - } - - fat_file_mark_removed(pathloc->mt_entry, fat_fd); - - rtems_semaphore_release(fs_info->vol_sema); - return RC_OK; -} diff --git a/c/src/libfs/src/dosfs/msdos_free.c b/c/src/libfs/src/dosfs/msdos_free.c deleted file mode 100644 index c0d5938dbb..0000000000 --- a/c/src/libfs/src/dosfs/msdos_free.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Free node handler implementation for the filesystem - * operations table. - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include - -#include "fat.h" -#include "fat_fat_operations.h" -#include "fat_file.h" - -#include "msdos.h" - -/* msdos_free_node_info -- - * Call fat-file close routine. - * - * PARAMETERS: - * pathloc - node description - * - * RETURNS: - * RC_OK on success, or -1 code if error occured - * - */ -int -msdos_free_node_info(rtems_filesystem_location_info_t *pathloc) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info; - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - rc = fat_file_close(pathloc->mt_entry, pathloc->node_access); - - rtems_semaphore_release(fs_info->vol_sema); - return rc; -} diff --git a/c/src/libfs/src/dosfs/msdos_fsunmount.c b/c/src/libfs/src/dosfs/msdos_fsunmount.c deleted file mode 100644 index 9072a2fad5..0000000000 --- a/c/src/libfs/src/dosfs/msdos_fsunmount.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * MSDOS shut down handler implementation - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "fat.h" -#include "fat_fat_operations.h" -#include "fat_file.h" - -#include "msdos.h" - -/* msdos_shut_down -- - * Shut down MSDOS filesystem - free all allocated resources (don't - * return if deallocation of some resource failed - free as much as - * possible). - * - * PARAMETERS: - * temp_mt_entry - mount table entry - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set apropriately). - * - */ -int -msdos_shut_down(rtems_filesystem_mount_table_entry_t *temp_mt_entry) -{ - int rc = RC_OK; - msdos_fs_info_t *fs_info = temp_mt_entry->fs_info; - fat_file_fd_t *fat_fd = temp_mt_entry->mt_fs_root.node_access; - - /* close fat-file which correspondes to root directory */ - if (fat_file_close(temp_mt_entry, fat_fd) != RC_OK) - { - /* no return - try to free as much as possible */ - rc = -1; - } - - if (fat_shutdown_drive(temp_mt_entry) != RC_OK) - { - /* no return - try to free as much as possible */ - rc = -1; - } - - rtems_semaphore_delete(fs_info->vol_sema); - free(fs_info->cl_buf); - free(temp_mt_entry->fs_info); - - return rc; -} diff --git a/c/src/libfs/src/dosfs/msdos_handlers_dir.c b/c/src/libfs/src/dosfs/msdos_handlers_dir.c deleted file mode 100644 index e14d892add..0000000000 --- a/c/src/libfs/src/dosfs/msdos_handlers_dir.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Directory Handlers Table for MSDOS filesystem - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "msdos.h" - -rtems_filesystem_file_handlers_r msdos_dir_handlers = { - msdos_dir_open, - msdos_dir_close, - msdos_dir_read, - NULL, /* msdos_dir_write */ - NULL, /* msdos_dir_ioctl */ - msdos_dir_lseek, - msdos_dir_stat, - NULL, - NULL, /* msdos_dir_ftruncate */ - NULL, - msdos_dir_sync, - msdos_dir_sync, - NULL, /* msdos_dir_fcntl */ - msdos_dir_rmnod -}; diff --git a/c/src/libfs/src/dosfs/msdos_handlers_file.c b/c/src/libfs/src/dosfs/msdos_handlers_file.c deleted file mode 100644 index ae627066de..0000000000 --- a/c/src/libfs/src/dosfs/msdos_handlers_file.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * File Operations Table for MSDOS filesystem - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "msdos.h" - -rtems_filesystem_file_handlers_r msdos_file_handlers = { - msdos_file_open, - msdos_file_close, - msdos_file_read, - msdos_file_write, - msdos_file_ioctl, - msdos_file_lseek, - msdos_file_stat, - NULL, - msdos_file_ftruncate, - NULL, - msdos_file_sync, - msdos_file_datasync, - NULL, /* msdos_file_fcntl */ - msdos_file_rmnod -}; diff --git a/c/src/libfs/src/dosfs/msdos_init.c b/c/src/libfs/src/dosfs/msdos_init.c deleted file mode 100644 index 2d5bf6c9e0..0000000000 --- a/c/src/libfs/src/dosfs/msdos_init.c +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Init routine for MSDOS - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "msdos.h" - -rtems_filesystem_operations_table msdos_ops = { - msdos_eval_path, - msdos_eval4make, - NULL, /* msdos_link */ - msdos_file_rmnod, - msdos_node_type, - msdos_mknod, - NULL, /* msdos_chown */ - msdos_free_node_info, - NULL, - msdos_initialize, - NULL, - msdos_shut_down, /* msdos_shut_down */ - NULL, /* msdos_utime */ - NULL, - NULL, - NULL -}; - -/* msdos_initialize -- - * MSDOS filesystem initialization - * - * PARAMETERS: - * temp_mt_entry - mount table entry - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set apropriately). - * - */ -int -msdos_initialize(rtems_filesystem_mount_table_entry_t *temp_mt_entry) -{ - int rc = RC_OK; - - rc = msdos_initialize_support(temp_mt_entry, - &msdos_ops, - &msdos_file_handlers, - &msdos_dir_handlers); - return rc; -} diff --git a/c/src/libfs/src/dosfs/msdos_initsupp.c b/c/src/libfs/src/dosfs/msdos_initsupp.c deleted file mode 100644 index eee8a6f9b2..0000000000 --- a/c/src/libfs/src/dosfs/msdos_initsupp.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - * MSDOS Initialization support routine implementation - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "fat.h" -#include "fat_fat_operations.h" -#include "fat_file.h" - -#include "msdos.h" - -/* msdos_initialize_support -- - * MSDOS filesystem initialization - * - * PARAMETERS: - * temp_mt_entry - mount table entry - * op_table - filesystem operations table - * file_handlers - file operations table - * directory_handlers - directory operations table - * - * RETURNS: - * RC_OK and filled temp_mt_entry on success, or -1 if error occured - * (errno set apropriately) - * - */ -int -msdos_initialize_support( - rtems_filesystem_mount_table_entry_t *temp_mt_entry, - rtems_filesystem_operations_table *op_table, - rtems_filesystem_file_handlers_r *file_handlers, - rtems_filesystem_file_handlers_r *directory_handlers - ) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = NULL; - fat_file_fd_t *fat_fd = NULL; - unsigned32 cl_buf_size; - - fs_info = (msdos_fs_info_t *)calloc(1, sizeof(msdos_fs_info_t)); - if (!fs_info) - set_errno_and_return_minus_one(ENOMEM); - - temp_mt_entry->fs_info = fs_info; - - rc = fat_init_volume_info(temp_mt_entry); - if (rc != RC_OK) - { - free(fs_info); - return rc; - } - - fs_info->file_handlers = file_handlers; - fs_info->directory_handlers = directory_handlers; - - /* - * open fat-file which correspondes to root directory - * (so inode number 0x00000010 is always used for root directory) - */ - rc = fat_file_open(temp_mt_entry, FAT_ROOTDIR_CLUSTER_NUM, 0, &fat_fd); - if (rc != RC_OK) - { - fat_shutdown_drive(temp_mt_entry); - free(fs_info); - return rc; - } - - /* again: unfortunately "fat-file" is just almost fat file :( */ - fat_fd->fat_file_type = FAT_DIRECTORY; - fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT; - fat_fd->info_cln = FAT_ROOTDIR_CLUSTER_NUM; - fat_fd->info_ofs = 0; - fat_fd->cln = fs_info->fat.vol.rdir_cl; - - fat_fd->map.file_cln = 0; - fat_fd->map.disk_cln = fat_fd->cln; - - /* if we have FAT12/16 */ - if ( fat_fd->cln == 0 ) - { - fat_fd->fat_file_size = fs_info->fat.vol.rdir_size; - cl_buf_size = (fs_info->fat.vol.bpc > fs_info->fat.vol.rdir_size) ? - fs_info->fat.vol.bpc : - fs_info->fat.vol.rdir_size; - } - else - { - rc = fat_file_size(temp_mt_entry, fat_fd); - if ( rc != RC_OK ) - { - fat_file_close(temp_mt_entry, fat_fd); - fat_shutdown_drive(temp_mt_entry); - free(fs_info); - return rc; - } - cl_buf_size = fs_info->fat.vol.bpc; - } - - fs_info->cl_buf = (char *)calloc(cl_buf_size, sizeof(char)); - if (fs_info->cl_buf == NULL) - { - fat_file_close(temp_mt_entry, fat_fd); - fat_shutdown_drive(temp_mt_entry); - free(fs_info); - set_errno_and_return_minus_one(ENOMEM); - } - - sc = rtems_semaphore_create(3, - 1, - RTEMS_BINARY_SEMAPHORE | RTEMS_FIFO, - RTEMS_INHERIT_PRIORITY, - &fs_info->vol_sema); - if (sc != RTEMS_SUCCESSFUL) - { - fat_file_close(temp_mt_entry, fat_fd); - fat_shutdown_drive(temp_mt_entry); - free(fs_info->cl_buf); - free(fs_info); - set_errno_and_return_minus_one( EIO ); - } - - temp_mt_entry->mt_fs_root.node_access = fat_fd; - temp_mt_entry->mt_fs_root.handlers = directory_handlers; - temp_mt_entry->mt_fs_root.ops = op_table; - - return rc; -} diff --git a/c/src/libfs/src/dosfs/msdos_misc.c b/c/src/libfs/src/dosfs/msdos_misc.c deleted file mode 100644 index fe2779f7a8..0000000000 --- a/c/src/libfs/src/dosfs/msdos_misc.c +++ /dev/null @@ -1,1087 +0,0 @@ -/* - * Miscellaneous routines implementation for MSDOS filesystem - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include - -#include "fat.h" -#include "fat_fat_operations.h" -#include "fat_file.h" - -#include "msdos.h" - -/* This copied from Linux */ -static int day_n[] = { 0,31,59,90,120,151,181,212,243,273,304,334,0,0,0,0 }; - /* JanFebMarApr May Jun Jul Aug Sep Oct Nov Dec */ - -#undef CONFIG_ATARI - -/* MS-DOS "device special files" */ -static const char *reserved_names[] = { -#ifndef CONFIG_ATARI /* GEMDOS is less stupid */ - "CON ","PRN ","NUL ","AUX ", - "LPT1 ","LPT2 ","LPT3 ","LPT4 ", - "COM1 ","COM2 ","COM3 ","COM4 ", -#endif - NULL }; - -static char bad_chars[] = "*?<>|\""; -#ifdef CONFIG_ATARI -/* GEMDOS is less restrictive */ -static char bad_if_strict[] = " "; -#else -static char bad_if_strict[] = "+=,; "; -#endif - -/* The following three functions copied from Linux */ -/* - * Formats an MS-DOS file name. Rejects invalid names - * - * conv is relaxed/normal/strict, name is proposed name, - * len is the length of the proposed name, res is the result name, - * dotsOK is if hidden files get dots. - */ -int -msdos_format_name(char conv, const char *name, int len, char *res, - char dotsOK) -{ - char *walk; - const char **reserved; - unsigned char c; - int space; - if (name[0] == '.') { /* dotfile because . and .. already done */ - if (!dotsOK) return -EINVAL; - /* Get rid of dot - test for it elsewhere */ - name++; len--; - } -#ifndef CONFIG_ATARI - space = 1; /* disallow names that _really_ start with a dot */ -#else - space = 0; /* GEMDOS does not care */ -#endif - c = 0; - for (walk = res; len && walk-res < 8; walk++) { - c = *name++; - len--; - if (conv != 'r' && strchr(bad_chars,c)) return -EINVAL; - if (conv == 's' && strchr(bad_if_strict,c)) return -EINVAL; - if (c >= 'A' && c <= 'Z' && conv == 's') return -EINVAL; - if (c < ' ' || c == ':' || c == '\\') return -EINVAL; -/* 0xE5 is legal as a first character, but we must substitute 0x05 */ -/* because 0xE5 marks deleted files. Yes, DOS really does this. */ -/* It seems that Microsoft hacked DOS to support non-US characters */ -/* after the 0xE5 character was already in use to mark deleted files. */ - if((res==walk) && (c==0xE5)) c=0x05; - if (c == '.') break; - space = (c == ' '); - *walk = (c >= 'a' && c <= 'z') ? c-32 : c; - } - if (space) return -EINVAL; - if (conv == 's' && len && c != '.') { - c = *name++; - len--; - if (c != '.') return -EINVAL; - } - while (c != '.' && len--) c = *name++; - if (c == '.') { - while (walk-res < 8) *walk++ = ' '; - while (len > 0 && walk-res < MSDOS_NAME_MAX) { - c = *name++; - len--; - if (conv != 'r' && strchr(bad_chars,c)) return -EINVAL; - if (conv == 's' && strchr(bad_if_strict,c)) - return -EINVAL; - if (c < ' ' || c == ':' || c == '\\') - return -EINVAL; - if (c == '.') { - if (conv == 's') - return -EINVAL; - break; - } - if (c >= 'A' && c <= 'Z' && conv == 's') return -EINVAL; - space = c == ' '; - *walk++ = c >= 'a' && c <= 'z' ? c-32 : c; - } - if (space) return -EINVAL; - if (conv == 's' && len) return -EINVAL; - } - while (walk-res < MSDOS_NAME_MAX) *walk++ = ' '; - for (reserved = reserved_names; *reserved; reserved++) - if (!strncmp(res,*reserved,8)) return -EINVAL; - return 0; -} - -/* Convert a MS-DOS time/date pair to a UNIX date (seconds since 1 1 70) */ -unsigned int -msdos_date_dos2unix(unsigned short time_val,unsigned short date) -{ - int month,year,secs; - - month = ((date >> 5) & 15)-1; - year = date >> 9; - secs = (time_val & 31)*2+60*((time_val >> 5) & 63)+ - (time_val >> 11)*3600+86400* - ((date & 31)-1+day_n[month]+(year/4)+year*365-((year & 3) == 0 && - month < 2 ? 1 : 0)+3653); - /* days since 1.1.70 plus 80's leap day */ - - return secs; -} - - -/* Convert linear UNIX date to a MS-DOS time/date pair */ -void msdos_date_unix2dos(int unix_date, - unsigned short *time_val, - unsigned short *date) -{ - int day,year,nl_day,month; - - *time_val = (unix_date % 60)/2+(((unix_date/60) % 60) << 5)+ - (((unix_date/3600) % 24) << 11); - day = unix_date/86400-3652; - year = day/365; - if ((year+3)/4+365*year > day) year--; - day -= (year+3)/4+365*year; - if (day == 59 && !(year & 3)) { - nl_day = day; - month = 2; - } - else { - nl_day = (year & 3) || day <= 59 ? day : day-1; - for (month = 0; month < 12; month++) - if (day_n[month] > nl_day) break; - } - *date = nl_day-day_n[month-1]+1+(month << 5)+(year << 9); -} - - -/* msdos_get_token -- - * Routine to get a token (name or separator) from the path. - * - * PARAMETERS: - * path - path to get token from - * ret_token - returned token - * token_len - length of returned token - * - * RETURNS: - * token type, token and token length - * - */ -msdos_token_types_t -msdos_get_token(const char *path, char *ret_token, int *token_len) -{ - int rc = RC_OK; - register int i = 0; - msdos_token_types_t type = MSDOS_NAME; - char token[MSDOS_NAME_MAX_WITH_DOT+1]; - register char c; - - /* - * Copy a name into token. (Remember NULL is a token.) - */ - c = path[i]; - while ( (!msdos_is_separator(c)) && (i <= MSDOS_NAME_MAX_WITH_DOT) ) - { - token[i] = c; - if ( i == MSDOS_NAME_MAX_WITH_DOT ) - return MSDOS_INVALID_TOKEN; - if ( !msdos_is_valid_name_char(c) ) - return MSDOS_INVALID_TOKEN; - c = path [++i]; - } - - /* - * Copy a seperator into token. - */ - if ( i == 0 ) - { - token[i] = c; - if ( token[i] != '\0' ) - { - i++; - type = MSDOS_CURRENT_DIR; - } - else - type = MSDOS_NO_MORE_PATH; - } - else if (token[ i-1 ] != '\0') - token[i] = '\0'; - - /* - * Set token_len to the number of characters copied. - */ - *token_len = i; - - /* - * If we copied something that was not a seperator see if - * it was a special name. - */ - if ( type == MSDOS_NAME ) - { - if ( strcmp( token, "..") == 0 ) - { - strcpy(ret_token, MSDOS_DOTDOT_NAME); - type = MSDOS_UP_DIR; - return type; - } - - if ( strcmp( token, "." ) == 0 ) - { - strcpy(ret_token, MSDOS_DOT_NAME); - type = MSDOS_CURRENT_DIR; - return type; - } - - rc = msdos_format_name('r', token, *token_len, ret_token, 0); - if ( rc != RC_OK ) - return MSDOS_INVALID_TOKEN; - } - ret_token[MSDOS_NAME_MAX] = '\0'; - return type; -} - - -/* msdos_find_name -- - * Find the node which correspondes to the name, open fat-file which - * correspondes to the found node and close fat-file which correspondes - * to the node we searched in. - * - * PARAMETERS: - * parent_loc - parent node description - * name - name to find - * - * RETURNS: - * RC_OK and updated 'parent_loc' on success, or -1 if error - * occured (errno set apropriately) - * - */ -int -msdos_find_name( - rtems_filesystem_location_info_t *parent_loc, - char *name - ) -{ - int rc = RC_OK; - msdos_fs_info_t *fs_info = parent_loc->mt_entry->fs_info; - fat_file_fd_t *fat_fd = NULL; - fat_auxiliary_t aux; - unsigned short time_val = 0; - unsigned short date = 0; - unsigned char node_entry[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE]; - - memset(node_entry, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE); - - /* - * find the node which correspondes to the name in the directory pointed by - * 'parent_loc' - */ - rc = msdos_get_name_node(parent_loc, name, &aux, node_entry); - if (rc != RC_OK) - return rc; - - /* open fat-file corresponded to the found node */ - rc = fat_file_open(parent_loc->mt_entry, aux.cln, aux.ofs, &fat_fd); - if (rc != RC_OK) - return rc; - - /* - * I don't like this if, but: we should do it , or should write new file - * size and first cluster num to the disk after each write operation - * (even if one byte is written - that is TOO non-optimize) because - * otherwise real values of these fields stored in fat-file descriptor - * may be accidentely rewritten with wrong values stored on the disk - */ - if (fat_fd->links_num == 1) - { - fat_fd->info_cln = aux.cln; - fat_fd->info_ofs = aux.ofs; - fat_fd->cln = MSDOS_EXTRACT_CLUSTER_NUM(node_entry); - fat_fd->first_char = *MSDOS_DIR_NAME(node_entry); - - time_val = *MSDOS_DIR_WRITE_TIME(node_entry); - date = *MSDOS_DIR_WRITE_DATE(node_entry); - - fat_fd->mtime = msdos_date_dos2unix(CF_LE_W(time_val), CF_LE_W(date)); - - if ((*MSDOS_DIR_ATTR(node_entry)) & MSDOS_ATTR_DIRECTORY) - { - fat_fd->fat_file_type = FAT_DIRECTORY; - fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT; - - rc = fat_file_size(parent_loc->mt_entry, fat_fd); - if (rc != RC_OK) - { - fat_file_close(parent_loc->mt_entry, fat_fd); - return rc; - } - } - else - { - fat_fd->fat_file_size = CF_LE_L(*MSDOS_DIR_FILE_SIZE(node_entry)); - fat_fd->fat_file_type = FAT_FILE; - fat_fd->size_limit = MSDOS_MAX_FILE_SIZE; - } - - /* these data is not actual for zero-length fat-file */ - fat_fd->map.file_cln = 0; - fat_fd->map.disk_cln = fat_fd->cln; - - if ((fat_fd->fat_file_size != 0) && - (fat_fd->fat_file_size <= fs_info->fat.vol.bpc)) - { - fat_fd->map.last_cln = fat_fd->cln; - } - else - { - fat_fd->map.last_cln = FAT_UNDEFINED_VALUE; - } - } - - /* close fat-file corresponded to the node we searched in */ - rc = fat_file_close(parent_loc->mt_entry, parent_loc->node_access); - if (rc != RC_OK) - { - fat_file_close(parent_loc->mt_entry, fat_fd); - return rc; - } - - /* update node_info_ptr field */ - parent_loc->node_access = fat_fd; - - return rc; -} - -/* msdos_get_name_node -- - * This routine is used in two ways: for a new mode creation (a) or for - * search the node which correspondes to the name parameter (b). - * In case (a) 'name' should be set up to NULL and 'name_dir_entry' should - * point to initialized 32 bytes structure described a new node. - * In case (b) 'name' should contain a valid string. - * - * (a): reading fat-file which correspondes to directory we are going to - * create node in. If free slot is found write contents of - * 'name_dir_entry' into it. If reach end of fat-file and no free - * slot found, write 32 bytes to the end of fat-file. - * - * (b): reading fat-file which correspondes to directory and trying to - * find slot with the name field == 'name' parameter - * - * - * PARAMETERS: - * parent_loc - node description to create node in or to find name in - * name - NULL or name to find - * paux - identify a node location on the disk - - * cluster num and offset inside the cluster - * name_dir_entry - node to create/placeholder for found node (IN/OUT) - * - * RETURNS: - * RC_OK, filled aux_struct_ptr and name_dir_entry on success, or -1 if - * error occured (errno set apropriately) - * - */ -int -msdos_get_name_node( - rtems_filesystem_location_info_t *parent_loc, - char *name, - fat_auxiliary_t *paux, - char *name_dir_entry - ) -{ - int rc = RC_OK; - ssize_t ret = 0; - msdos_fs_info_t *fs_info = parent_loc->mt_entry->fs_info; - fat_file_fd_t *fat_fd = parent_loc->node_access; - unsigned32 dotdot_cln = 0; - - /* find name in fat-file which correspondes to the directory */ - rc = msdos_find_name_in_fat_file(parent_loc->mt_entry, fat_fd, name, paux, - name_dir_entry); - if ((rc != RC_OK) && (rc != MSDOS_NAME_NOT_FOUND_ERR)) - return rc; - - /* if we search for valid name and name not found -> return */ - if ((rc == MSDOS_NAME_NOT_FOUND_ERR) && (name != NULL)) - return rc; - - /* - * if we try to create new entry and the directory is not big enough - * currently - try to enlarge directory - */ - if ((rc == MSDOS_NAME_NOT_FOUND_ERR) && (name == NULL)) - { - ret = fat_file_write(parent_loc->mt_entry, fat_fd, - fat_fd->fat_file_size, - MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE, - name_dir_entry); - if (ret == -1) - return -1; - - /* on success directory is enlarged by a new cluster */ - fat_fd->fat_file_size += fs_info->fat.vol.bpc; - - /* get cluster num where a new node located */ - rc = fat_file_ioctl(parent_loc->mt_entry, fat_fd, F_CLU_NUM, - fat_fd->fat_file_size - 1, &paux->cln); - - if (rc != RC_OK) - return rc; - - /* - * if new cluster allocated succesfully then new node is at very - * beginning of the cluster (offset is computed in bytes) - */ - paux->ofs = 0; - return RC_OK; - } - - /* - * if we have deal with ".." - it is a special case :((( - * - * Really, we should return cluster num and offset not of ".." slot, but - * slot which correspondes to real directory name. - */ - if ((rc == RC_OK) && (name != NULL)) - { - if (strncmp(name, MSDOS_DOTDOT_NAME, MSDOS_SHORT_NAME_LEN) == 0) - { - dotdot_cln = MSDOS_EXTRACT_CLUSTER_NUM((name_dir_entry)); - - /* are we right under root dir ? */ - if (dotdot_cln == 0) - { - /* - * we can relax about first_char field - it never should be - * used for root dir - */ - paux->cln = FAT_ROOTDIR_CLUSTER_NUM; - paux->ofs = 0; - } - else - { - rc = msdos_get_dotdot_dir_info_cluster_num_and_offset( - parent_loc->mt_entry, - dotdot_cln, - paux, - name_dir_entry - ); - if (rc != RC_OK) - return rc; - } - } - } - return rc; -} - -/* - * msdos_get_dotdot_dir_info_cluster_num_and_offset - * - * Unfortunately, in general, we cann't work here in fat-file ideologic - * (open fat_file "..", get ".." and ".", open "..", find an entry ...) - * because if we open - * fat-file ".." it may happend that we have two different fat-file - * descriptors ( for real name of directory and ".." name ) for a single - * file ( cluster num of both pointers to the same cluster ) - * But...we do it because we protected by semaphore - * - */ - -/* msdos_get_dotdot_dir_info_cluster_num_and_offset -- - * Get cluster num and offset not of ".." slot, but slot which correspondes - * to real directory name. - * - * PARAMETERS: - * mt_entry - mount table entry - * cln - data cluster num extracted drom ".." slot - * paux - identify a node location on the disk - - * number of cluster and offset inside the cluster - * dir_entry - placeholder for found node - * - * RETURNS: - * RC_OK, filled 'paux' and 'dir_entry' on success, or -1 if error occured - * (errno set apropriately) - * - */ -int -msdos_get_dotdot_dir_info_cluster_num_and_offset( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cln, - fat_auxiliary_t *paux, - char *dir_entry - ) -{ - int rc = RC_OK; - msdos_fs_info_t *fs_info = mt_entry->fs_info; - fat_file_fd_t *fat_fd = NULL; - unsigned char dot_node[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE]; - unsigned char dotdot_node[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE]; - unsigned char cur_node[MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE]; - unsigned32 cl4find = 0; - - memset(dot_node, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE); - memset(dotdot_node, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE); - memset(cur_node, 0, MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE); - - /* - * open fat-file corresponded to ".." - */ - rc = fat_file_open(mt_entry, paux->cln, paux->ofs, &fat_fd); - if (rc != RC_OK) - return rc; - - fat_fd->info_cln = paux->cln; - fat_fd->info_ofs = paux->ofs; - fat_fd->cln = cln; - fat_fd->fat_file_type = FAT_DIRECTORY; - fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT; - - fat_fd->map.file_cln = 0; - fat_fd->map.disk_cln = fat_fd->cln; - - rc = fat_file_size(mt_entry, fat_fd); - if (rc != RC_OK) - { - fat_file_close(mt_entry, fat_fd); - return rc; - } - - /* find "." node in opened directory */ - rc = msdos_find_name_in_fat_file(mt_entry, fat_fd, MSDOS_DOT_NAME, paux, - dot_node); - - if (rc != RC_OK) - { - fat_file_close(mt_entry, fat_fd); - return rc; - } - - /* find ".." node in opened directory */ - rc = msdos_find_name_in_fat_file(mt_entry, fat_fd, MSDOS_DOTDOT_NAME, paux, - dotdot_node); - - if (rc != RC_OK) - { - fat_file_close(mt_entry, fat_fd); - return rc; - } - - cl4find = MSDOS_EXTRACT_CLUSTER_NUM(dot_node); - - /* close fat-file corresponded to ".." directory */ - rc = fat_file_close(mt_entry, fat_fd); - if ( rc != RC_OK ) - return rc; - - if ( (MSDOS_EXTRACT_CLUSTER_NUM(dotdot_node)) == 0) - { - /* - * we handle root dir for all FAT types in the same way with the - * ordinary directories ( through fat_file_* calls ) - */ - paux->cln = FAT_ROOTDIR_CLUSTER_NUM; - paux->ofs = 0; - } - - /* open fat-file corresponded to second ".." */ - rc = fat_file_open(mt_entry, paux->cln, paux->ofs, &fat_fd); - if (rc != RC_OK) - return rc; - - fat_fd->info_cln = paux->cln; - fat_fd->info_ofs = paux->ofs; - - if ((MSDOS_EXTRACT_CLUSTER_NUM(dotdot_node)) == 0) - fat_fd->cln = fs_info->fat.vol.rdir_cl; - else - fat_fd->cln = MSDOS_EXTRACT_CLUSTER_NUM(dotdot_node); - - fat_fd->fat_file_type = FAT_DIRECTORY; - fat_fd->size_limit = MSDOS_MAX_DIR_LENGHT; - - fat_fd->map.file_cln = 0; - fat_fd->map.disk_cln = fat_fd->cln; - - rc = fat_file_size(mt_entry, fat_fd); - if (rc != RC_OK) - { - fat_file_close(mt_entry, fat_fd); - return rc; - } - - /* in this directory find slot with specified cluster num */ - rc = msdos_find_node_by_cluster_num_in_fat_file(mt_entry, fat_fd, cl4find, - paux, dir_entry); - if (rc != RC_OK) - { - fat_file_close(mt_entry, fat_fd); - return rc; - } - rc = fat_file_close(mt_entry, fat_fd); - return rc; -} - - -/* msdos_set_dir_wrt_time_and_date -- - * Write last write date and time for a file to the disk (to corresponded - * 32bytes node) - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set apropriately). - * - */ -int -msdos_set_dir_wrt_time_and_date( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd - ) -{ - ssize_t ret1 = 0, ret2 = 0; - msdos_fs_info_t *fs_info = mt_entry->fs_info; - unsigned short time_val; - unsigned short date; - unsigned32 sec = 0; - unsigned32 byte = 0; - - msdos_date_unix2dos(fat_fd->mtime, &time_val, &date); - - /* - * calculate input for _fat_block_write: convert (cluster num, offset) to - * (sector num, new offset) - */ - sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->info_cln); - sec += (fat_fd->info_ofs >> fs_info->fat.vol.sec_log2); - /* byte points to start of 32bytes structure */ - byte = fat_fd->info_ofs & (fs_info->fat.vol.bps - 1); - - time_val = CT_LE_W(time_val); - ret1 = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_WTIME_OFFSET, - 2, (char *)(&time_val)); - date = CT_LE_W(date); - ret2 = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_WDATE_OFFSET, - 2, (char *)(&date)); - - if ( (ret1 < 0) || (ret2 < 0) ) - return -1; - - return RC_OK; -} - -/* msdos_set_first_cluster_num -- - * Write number of first cluster of the file to the disk (to corresponded - * 32bytes slot) - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * - * RETURNS: - * RC_OK on success, or -1 if error occured - * - */ -int -msdos_set_first_cluster_num( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd - ) -{ - ssize_t ret1 = 0, ret2 = 0; - msdos_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 new_cln = fat_fd->cln; - unsigned16 le_cl_low = 0; - unsigned16 le_cl_hi = 0; - unsigned32 sec = 0; - unsigned32 byte = 0; - - /* - * calculate input for _fat_block_write: convert (cluster num, offset) to - * (sector num, new offset) - */ - sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->info_cln); - sec += (fat_fd->info_ofs >> fs_info->fat.vol.sec_log2); - /* byte from points to start of 32bytes structure */ - byte = fat_fd->info_ofs & (fs_info->fat.vol.bps - 1); - - le_cl_low = CT_LE_W((unsigned16)(new_cln & 0x0000FFFF)); - ret1 = _fat_block_write(mt_entry, sec, - byte + MSDOS_FIRST_CLUSTER_LOW_OFFSET, 2, - (char *)(&le_cl_low)); - le_cl_hi = CT_LE_W((unsigned16)((new_cln & 0xFFFF0000) >> 16)); - ret2 = _fat_block_write(mt_entry, sec, - byte + MSDOS_FIRST_CLUSTER_HI_OFFSET, 2, - (char *)(&le_cl_hi)); - if ( (ret1 < 0) || (ret2 < 0) ) - return -1; - - return RC_OK; -} - - -/* msdos_set_file size -- - * Write file size of the file to the disk (to corresponded 32bytes slot) - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set apropriately). - * - */ -int -msdos_set_file_size( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd - ) -{ - ssize_t ret = 0; - msdos_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 le_new_length = 0; - unsigned32 sec = 0; - unsigned32 byte = 0; - - sec = fat_cluster_num_to_sector_num(mt_entry, fat_fd->info_cln); - sec += (fat_fd->info_ofs >> fs_info->fat.vol.sec_log2); - byte = (fat_fd->info_ofs & (fs_info->fat.vol.bps - 1)); - - le_new_length = CT_LE_L((fat_fd->fat_file_size)); - ret = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_SIZE_OFFSET, 4, - (char *)(&le_new_length)); - if ( ret < 0 ) - return -1; - - return RC_OK; -} - -/* - * We should not check whether this routine is called for root dir - it - * never can happend - */ - -/* msdos_set_first_char4file_name -- - * Write first character of the name of the file to the disk (to - * corresponded 32bytes slot) - * - * PARAMETERS: - * mt_entry - mount table entry - * cl - number of cluster - * ofs - offset inside cluster - * fchar - character to set up - * - * RETURNS: - * RC_OK on success, or -1 if error occured (errno set apropriately) - * - */ -int -msdos_set_first_char4file_name( - rtems_filesystem_mount_table_entry_t *mt_entry, - unsigned32 cl, - unsigned32 ofs, - unsigned char fchar - ) -{ - ssize_t ret = 0; - msdos_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 sec = 0; - unsigned32 byte = 0; - - sec = fat_cluster_num_to_sector_num(mt_entry, cl); - sec += (ofs >> fs_info->fat.vol.sec_log2); - byte = (ofs & (fs_info->fat.vol.bps - 1)); - - ret = _fat_block_write(mt_entry, sec, byte + MSDOS_FILE_NAME_OFFSET, 1, - &fchar); - if ( ret < 0) - return -1; - - return RC_OK; -} - -/* msdos_dir_is_empty -- - * Check whether directory which correspondes to the fat-file descriptor is - * empty. - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * ret_val - placeholder for result - * - * RETURNS: - * RC_OK on success, or -1 if error occured - * - */ -int -msdos_dir_is_empty( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - rtems_boolean *ret_val - ) -{ - ssize_t ret = 0; - msdos_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 j = 0, i = 0; - - /* dir is not empty */ - *ret_val = FALSE; - - while ((ret = fat_file_read(mt_entry, fat_fd, j * fs_info->fat.vol.bps, - fs_info->fat.vol.bps, - fs_info->cl_buf)) != FAT_EOF) - { - if (ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE) - return -1; - - assert(ret == fs_info->fat.vol.bps); - - for (i = 0; - i < fs_info->fat.vol.bps; - i += MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE) - { - if (((*MSDOS_DIR_NAME(fs_info->cl_buf + i)) == - MSDOS_THIS_DIR_ENTRY_EMPTY) || - (strncmp(MSDOS_DIR_NAME((fs_info->cl_buf + i)), MSDOS_DOT_NAME, - MSDOS_SHORT_NAME_LEN) == 0) || - (strncmp(MSDOS_DIR_NAME((fs_info->cl_buf + i)), - MSDOS_DOTDOT_NAME, - MSDOS_SHORT_NAME_LEN) == 0)) - continue; - - if ((*MSDOS_DIR_NAME(fs_info->cl_buf + i)) == - MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY) - { - *ret_val = TRUE; - return RC_OK; - } - return RC_OK; - } - j++; - } - *ret_val = TRUE; - return RC_OK; -} - - -/* msdos_find_name_in_fat_file -- - * This routine is used in two ways: for a new mode creation (a) or for - * search the node which correspondes to the 'name' parameter (b). - * In case (a) name should be set up to NULL and 'name_dir_entry' should - * point to initialized 32 bytes structure described a new node. - * In case (b) 'name' should contain a valid string. - * - * (a): reading fat-file corresponded to directory we are going to create - * node in. If found free slot write contents of name_dir_entry into - * it. - * - * (b): reading fat-file corresponded to directory and trying to find slot - * with the name field == name parameter - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * name - NULL or name to find - * paux - identify a node location on the disk - - * number of cluster and offset inside the cluster - * name_dir_entry - node to create/placeholder for found node - * - * RETURNS: - * RC_OK on success, or error code if error occured (errno set - * appropriately) - * - */ -int -msdos_find_name_in_fat_file( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - char *name, - fat_auxiliary_t *paux, - char *name_dir_entry - ) -{ - int rc = RC_OK; - ssize_t ret = 0; - msdos_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 i = 0, j = 0; - unsigned32 bts2rd = 0; - - if (FAT_FD_OF_ROOT_DIR(fat_fd) && - (fs_info->fat.vol.type & (FAT_FAT12 | FAT_FAT16))) - bts2rd = fat_fd->fat_file_size; - else - bts2rd = fs_info->fat.vol.bpc; - - while ((ret = fat_file_read(mt_entry, fat_fd, (j * bts2rd), bts2rd, - fs_info->cl_buf)) != FAT_EOF) - { - if (ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE) - set_errno_and_return_minus_one(EIO); - - assert(ret == bts2rd); - - for (i = 0; i < bts2rd; i += MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE) - { - /* is the entry empty ? */ - if (((*MSDOS_DIR_NAME(fs_info->cl_buf + i)) == - MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY) || - ((*MSDOS_DIR_NAME(fs_info->cl_buf + i)) == - MSDOS_THIS_DIR_ENTRY_EMPTY)) - { - /* whether we are looking for an empty entry */ - if (name == NULL) - { - /* get current cluster number */ - rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM, - j * bts2rd, &paux->cln); - if (rc != RC_OK) - return rc; - - /* offset is computed in bytes */ - paux->ofs = i; - - /* write new node entry */ - ret = fat_file_write(mt_entry, fat_fd, j * bts2rd + i, - MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE, - name_dir_entry); - if (ret != MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE) - return -1; - - /* - * we don't update fat_file_size here - it should not - * increase - */ - return RC_OK; - } - - /* - * if name != NULL and there is no more entries in the - * directory - return name-not-found - */ - if (((*MSDOS_DIR_NAME(fs_info->cl_buf + i)) == - MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY)) - return MSDOS_NAME_NOT_FOUND_ERR; - } - else - { - /* entry not empty and name != NULL -> compare names */ - if (name != NULL) - { - if (strncmp(MSDOS_DIR_NAME((fs_info->cl_buf + i)), name, - MSDOS_SHORT_NAME_LEN) == 0) - { - /* - * we get the entry we looked for - fill auxiliary - * structure and copy all 32 bytes of the entry - */ - rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM, - j * bts2rd, &paux->cln); - if (rc != RC_OK) - return rc; - - /* offset is computed in bytes */ - paux->ofs = i; - memcpy(name_dir_entry,(fs_info->cl_buf + i), - MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE); - return RC_OK; - } - } - } - } - j++; - } - return MSDOS_NAME_NOT_FOUND_ERR; -} - -/* msdos_find_node_by_cluster_num_in_fat_file -- - * Find node with specified number of cluster in fat-file. - * - * PARAMETERS: - * mt_entry - mount table entry - * fat_fd - fat-file descriptor - * cl4find - number of cluster to find - * paux - identify a node location on the disk - - * cluster num and offset inside the cluster - * dir_entry - placeholder for found node - * - * RETURNS: - * RC_OK on success, or error code if error occured - * - */ -int -msdos_find_node_by_cluster_num_in_fat_file( - rtems_filesystem_mount_table_entry_t *mt_entry, - fat_file_fd_t *fat_fd, - unsigned32 cl4find, - fat_auxiliary_t *paux, - char *dir_entry - ) -{ - int rc = RC_OK; - ssize_t ret = 0; - msdos_fs_info_t *fs_info = mt_entry->fs_info; - unsigned32 bts2rd = 0; - unsigned32 i = 0, j = 0; - - if (FAT_FD_OF_ROOT_DIR(fat_fd) && - (fs_info->fat.vol.type & (FAT_FAT12 | FAT_FAT16))) - bts2rd = fat_fd->fat_file_size; - else - bts2rd = fs_info->fat.vol.bpc; - - while ((ret = fat_file_read(mt_entry, fat_fd, j * bts2rd, bts2rd, - fs_info->cl_buf)) != FAT_EOF) - { - if ( ret < MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE ) - set_errno_and_return_minus_one( EIO ); - - assert(ret == bts2rd); - - for (i = 0; i < bts2rd; i += MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE) - { - /* if this and all rest entries are empty - return not-found */ - if ((*MSDOS_DIR_NAME(fs_info->cl_buf + i)) == - MSDOS_THIS_DIR_ENTRY_AND_REST_EMPTY) - return MSDOS_NAME_NOT_FOUND_ERR; - - /* if this entry is empty - skip it */ - if ((*MSDOS_DIR_NAME(fs_info->cl_buf + i)) == - MSDOS_THIS_DIR_ENTRY_EMPTY) - continue; - - /* if get a non-empty entry - compare clusters num */ - if (MSDOS_EXTRACT_CLUSTER_NUM((fs_info->cl_buf + i)) == cl4find) - { - /* on success fill aux structure and copy all 32 bytes */ - rc = fat_file_ioctl(mt_entry, fat_fd, F_CLU_NUM, j * bts2rd, - &paux->cln); - if (rc != RC_OK) - return rc; - - paux->ofs = i; - memcpy(dir_entry, fs_info->cl_buf + i, - MSDOS_DIRECTORY_ENTRY_STRUCT_SIZE); - return RC_OK; - } - } - j++; - } - return MSDOS_NAME_NOT_FOUND_ERR; -} diff --git a/c/src/libfs/src/dosfs/msdos_mknod.c b/c/src/libfs/src/dosfs/msdos_mknod.c deleted file mode 100644 index 5e32dbf3bf..0000000000 --- a/c/src/libfs/src/dosfs/msdos_mknod.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Routine for node creation in MSDOS filesystem. - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fat.h" -#include "fat_fat_operations.h" -#include "fat_file.h" - -#include "msdos.h" - -/* msdos_mknod -- - * The following function checks spelling and formats name for a new node, - * determines type of the node to be created and creates it. - * - * PARAMETERS: - * token - non-formatted name of a new node - * mode - node type - * dev - dev - * pathloc - parent directory description - * - * RETURNS: - * RC_OK on succes, or -1 if error occured and set errno - * - */ -int -msdos_mknod( - const char *token, - mode_t mode, - dev_t dev, - rtems_filesystem_location_info_t *pathloc - ) -{ - int rc = RC_OK; - rtems_status_code sc = RTEMS_SUCCESSFUL; - msdos_fs_info_t *fs_info = pathloc->mt_entry->fs_info; - msdos_token_types_t type = 0; - char new_name[ MSDOS_NAME_MAX + 1 ]; - int len; - - /* check spelling and format new node name */ - msdos_get_token(token, new_name, &len); - - /* - * Figure out what type of msdos node this is. - */ - if (S_ISDIR(mode)) - { - type = MSDOS_DIRECTORY; - } - else if (S_ISREG(mode)) - { - type = MSDOS_REGULAR_FILE; - } - else - set_errno_and_return_minus_one(EINVAL); - - sc = rtems_semaphore_obtain(fs_info->vol_sema, RTEMS_WAIT, - MSDOS_VOLUME_SEMAPHORE_TIMEOUT); - if (sc != RTEMS_SUCCESSFUL) - set_errno_and_return_minus_one(EIO); - - /* Create an MSDOS node */ - rc = msdos_creat_node(pathloc, type, new_name, mode); - - rtems_semaphore_release(fs_info->vol_sema); - return rc; -} diff --git a/c/src/libfs/src/dosfs/msdos_node_type.c b/c/src/libfs/src/dosfs/msdos_node_type.c deleted file mode 100644 index 517dabda3f..0000000000 --- a/c/src/libfs/src/dosfs/msdos_node_type.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * The following returns the type of node that the loc refers to. - * - * Copyright (C) 2001 OKTET Ltd., St.-Petersburg, Russia - * Author: Eugeny S. Mints - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * @(#) $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "fat.h" -#include "fat_fat_operations.h" -#include "fat_file.h" - -#include "msdos.h" - -/* msdos_node_type -- - * Determine type of the node that the pathloc refers to. - * - * PARAMETERS: - * pathloc - node description - * - * RETURNS: - * node type - * - */ -rtems_filesystem_node_types_t -msdos_node_type(rtems_filesystem_location_info_t *pathloc) -{ - fat_file_fd_t *fat_fd; - - /* - * we don't need to obtain the volume semaphore here because node_type_h - * call always follows evalpath_h call(hence link increment occured) and - * hence node_access memory can't be freed during processing node_type_h - * call - */ - fat_fd = pathloc->node_access; - - return fat_fd->fat_file_type; -} diff --git a/c/src/libfs/src/imfs/.cvsignore b/c/src/libfs/src/imfs/.cvsignore deleted file mode 100644 index acbf393fde..0000000000 --- a/c/src/libfs/src/imfs/.cvsignore +++ /dev/null @@ -1,7 +0,0 @@ -Makefile -Makefile.in -config.h -config.h.in -stamp-h -stamp-h.in -stamp-h1.in diff --git a/c/src/libfs/src/imfs/Makefile.am b/c/src/libfs/src/imfs/Makefile.am deleted file mode 100644 index 855fa9f84f..0000000000 --- a/c/src/libfs/src/imfs/Makefile.am +++ /dev/null @@ -1,66 +0,0 @@ -## -## $Id$ -## - - -INCLUDES = -I../.. - -LIBNAME = libimfs -LIB = ${ARCH}/${LIBNAME}.a - -IMFS_C_FILES = imfs_chown.c imfs_config.c imfs_creat.c imfs_directory.c \ - imfs_eval.c imfs_free.c imfs_fsunmount.c imfs_gtkn.c imfs_init.c \ - imfs_initsupp.c imfs_link.c imfs_mknod.c imfs_mount.c imfs_fchmod.c \ - imfs_unlink.c imfs_unmount.c imfs_utime.c imfs_ntype.c imfs_stat.c \ - imfs_getchild.c memfile.c linearfile.c deviceio.c imfs_handlers_device.c \ - imfs_handlers_directory.c imfs_handlers_link.c imfs_handlers_memfile.c \ - imfs_debug.c imfs_rmnod.c imfs_symlink.c imfs_readlink.c imfs_fdatasync.c \ - imfs_fcntl.c ioman.c miniimfs_init.c imfs_load_tar.c - -UNIX_C_FILES = imfs_unixstub.c - -EMBEDDED_C_FILES = $(IMFS_C_FILES) - -COMMON_C_FILES = - -if UNIX -C_FILES = $(COMMON_C_FILES) $(UNIX_C_FILES) -else -C_FILES = $(COMMON_C_FILES) $(EMBEDDED_C_FILES) -endif -C_O_FILES = $(C_FILES:%.c=${ARCH}/%.o) - -include_HEADERS = imfs.h - -include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg -include $(top_srcdir)/../../../automake/compile.am -include $(top_srcdir)/../../../automake/lib.am - -PREINSTALL_FILES = $(PROJECT_INCLUDE) \ - $(include_HEADERS:%=$(PROJECT_INCLUDE)/%) - -$(PROJECT_INCLUDE): - @$(mkinstalldirs) $@ - -$(PROJECT_INCLUDE)/%.h: %.h - $(INSTALL_DATA) $< $@ - -OBJS = $(C_O_FILES) - -# -# Add local stuff here using += -# - -AM_CFLAGS += $(LIBC_DEFINES) - -all-local: ${ARCH} $(LIB) - -$(LIB): ${OBJS} - $(make-library) - -DOC_FILES = TODO CASES - -EXTRA_DIST = $(DOC_FILES) $(COMMON_C_FILES) $(EMBEDDED_C_FILES) \ - $(UNIX_C_FILES) - -include $(top_srcdir)/../../../automake/local.am diff --git a/c/src/libfs/src/imfs/deviceio.c b/c/src/libfs/src/imfs/deviceio.c deleted file mode 100644 index eafc48ec4e..0000000000 --- a/c/src/libfs/src/imfs/deviceio.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * IMFS Device Node Handlers - * - * This file contains the set of handlers used to map operations on - * IMFS device nodes onto calls to the RTEMS Classic API IO Manager. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include /* assoc.h not included by rtems.h */ -#include - -#include "imfs.h" - -/* - * Convert RTEMS status to a UNIX errno - */ - -rtems_assoc_t errno_assoc[] = { - { "OK", RTEMS_SUCCESSFUL, 0 }, - { "BUSY", RTEMS_RESOURCE_IN_USE, EBUSY }, - { "INVALID NAME", RTEMS_INVALID_NAME, EINVAL }, - { "NOT IMPLEMENTED", RTEMS_NOT_IMPLEMENTED, ENOSYS }, - { "TIMEOUT", RTEMS_TIMEOUT, ETIMEDOUT }, - { "NO MEMORY", RTEMS_NO_MEMORY, ENOMEM }, - { "NO DEVICE", RTEMS_UNSATISFIED, ENODEV }, - { "INVALID NUMBER", RTEMS_INVALID_NUMBER, EBADF}, - { "NOT RESOURCE OWNER", RTEMS_NOT_OWNER_OF_RESOURCE, EPERM}, - { "IO ERROR", RTEMS_IO_ERROR, EIO}, - { 0, 0, 0 }, -}; - -static unsigned32 -rtems_deviceio_errno(rtems_status_code code) -{ - int rc; - - if ((rc = rtems_assoc_remote_by_local(errno_assoc, (unsigned32) code))) - { - errno = rc; - return -1; - } - return -1; -} - -/* - * device_open - * - * This handler maps an open() operation onto rtems_io_open(). - */ - -int device_open( - rtems_libio_t *iop, - const char *pathname, - unsigned32 flag, - unsigned32 mode -) -{ - rtems_libio_open_close_args_t args; - rtems_status_code status; - IMFS_jnode_t *the_jnode; - - the_jnode = iop->file_info; - - args.iop = iop; - args.flags = iop->flags; - args.mode = mode; - - status = rtems_io_open( - the_jnode->info.device.major, - the_jnode->info.device.minor, - (void *) &args - ); - if ( status ) { - rtems_deviceio_errno(status); - return RTEMS_UNSATISFIED; - } - - return 0; -} - -/* - * device_close - * - * This handler maps a close() operation onto rtems_io_close(). - */ - -int device_close( - rtems_libio_t *iop -) -{ - rtems_libio_open_close_args_t args; - rtems_status_code status; - IMFS_jnode_t *the_jnode; - - the_jnode = iop->file_info; - - args.iop = iop; - args.flags = 0; - args.mode = 0; - - status = rtems_io_close( - the_jnode->info.device.major, - the_jnode->info.device.minor, - (void *) &args - ); - if ( status ) { - rtems_deviceio_errno(status); - return RTEMS_UNSATISFIED; - } - return 0; -} - -/* - * device_read - * - * This handler maps a read() operation onto rtems_io_read(). - */ - -int device_read( - rtems_libio_t *iop, - void *buffer, - unsigned32 count -) -{ - rtems_libio_rw_args_t args; - rtems_status_code status; - IMFS_jnode_t *the_jnode; - - the_jnode = iop->file_info; - - args.iop = iop; - args.offset = iop->offset; - args.buffer = buffer; - args.count = count; - args.flags = iop->flags; - args.bytes_moved = 0; - - status = rtems_io_read( - the_jnode->info.device.major, - the_jnode->info.device.minor, - (void *) &args - ); - - if ( status ) - return rtems_deviceio_errno(status); - - return args.bytes_moved; -} - -/* - * device_write - * - * This handler maps a write() operation onto rtems_io_write(). - */ - -int device_write( - rtems_libio_t *iop, - const void *buffer, - unsigned32 count -) -{ - rtems_libio_rw_args_t args; - rtems_status_code status; - IMFS_jnode_t *the_jnode; - - the_jnode = iop->file_info; - - args.iop = iop; - args.offset = iop->offset; - args.buffer = (void *) buffer; - args.count = count; - args.flags = iop->flags; - args.bytes_moved = 0; - - status = rtems_io_write( - the_jnode->info.device.major, - the_jnode->info.device.minor, - (void *) &args - ); - - if ( status ) - return rtems_deviceio_errno(status); - - return args.bytes_moved; -} - -/* - * device_ioctl - * - * This handler maps an ioctl() operation onto rtems_io_ioctl(). - */ - -int device_ioctl( - rtems_libio_t *iop, - unsigned32 command, - void *buffer -) -{ - rtems_libio_ioctl_args_t args; - rtems_status_code status; - IMFS_jnode_t *the_jnode; - - args.iop = iop; - args.command = command; - args.buffer = buffer; - - the_jnode = iop->file_info; - - status = rtems_io_control( - the_jnode->info.device.major, - the_jnode->info.device.minor, - (void *) &args - ); - - if ( status ) - return rtems_deviceio_errno(status); - - return args.ioctl_return; -} - -/* - * device_lseek - * - * This handler eats all lseek() operations. - */ - -int device_lseek( - rtems_libio_t *iop, - off_t offset, - int whence -) -{ - return 0; -} - -/* - * device_stat - * - * The IMFS_stat() is used. - */ - -/* - * device_rmnod - * - * The IMFS_rmnod() is used. - */ diff --git a/c/src/libfs/src/imfs/imfs.h b/c/src/libfs/src/imfs/imfs.h deleted file mode 100644 index 4113553768..0000000000 --- a/c/src/libfs/src/imfs/imfs.h +++ /dev/null @@ -1,546 +0,0 @@ -/* - * Header file for the In-Memory File System - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#ifndef __IMFS_h -#define __IMFS_h - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#include -#include -#include - -/* - * File name macros - */ - -#define IMFS_is_valid_name_char( _ch ) ( 1 ) - -#define IMFS_is_separator( _ch ) \ - rtems_filesystem_is_separator( _ch ) - -/* - * Data types - */ - -struct IMFS_jnode_tt; -typedef struct IMFS_jnode_tt IMFS_jnode_t; - -typedef struct { - Chain_Control Entries; - rtems_filesystem_mount_table_entry_t *mt_fs; -} IMFS_directory_t; - -typedef struct { - rtems_device_major_number major; - rtems_device_minor_number minor; -} IMFS_device_t; - -typedef struct { - IMFS_jnode_t *link_node; -} IMFS_link_t; - -typedef struct { - const char *name; -} IMFS_sym_link_t; - -/* - * IMFS "memfile" information - * - * The data structure for the in-memory "memfiles" is based on classic UNIX. - * - * block_ptr is a pointer to a block of IMFS_MEMFILE_BYTES_PER_BLOCK in - * length which could be data or a table of pointers to blocks. - * - * Setting IMFS_MEMFILE_BYTES_PER_BLOCK to different values has a significant - * impact on the maximum file size supported as well as the amount of - * memory wasted due to internal file fragmentation. The following - * is a list of maximum file sizes based on various settings - * - * max_filesize with blocks of 16 is 1,328 - * max_filesize with blocks of 32 is 18,656 - * max_filesize with blocks of 64 is 279,488 - * max_filesize with blocks of 128 is 4,329,344 - * max_filesize with blocks of 256 is 68,173,568 - * max_filesize with blocks of 512 is 1,082,195,456 - */ - -#define IMFS_MEMFILE_BYTES_PER_BLOCK 128 -#define IMFS_MEMFILE_BLOCK_SLOTS \ - (IMFS_MEMFILE_BYTES_PER_BLOCK / sizeof(void *)) - -typedef unsigned char * block_p; -typedef block_p *block_ptr; - -typedef struct { - off_t size; /* size of file in bytes */ - block_ptr indirect; /* array of 128 data blocks pointers */ - block_ptr doubly_indirect; /* 128 indirect blocks */ - block_ptr triply_indirect; /* 128 doubly indirect blocks */ -} IMFS_memfile_t; - -typedef struct { - off_t size; /* size of file in bytes */ - block_p direct; /* pointer to file image */ -} IMFS_linearfile_t; - -/* - * Important block numbers for "memfiles" - */ - -#define FIRST_INDIRECT (0) -#define LAST_INDIRECT (IMFS_MEMFILE_BLOCK_SLOTS - 1) - -#define FIRST_DOUBLY_INDIRECT (LAST_INDIRECT + 1) -#define LAST_DOUBLY_INDIRECT \ - (LAST_INDIRECT + \ - (IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS)) - -#define FIRST_TRIPLY_INDIRECT (LAST_DOUBLY_INDIRECT + 1) -#define LAST_TRIPLY_INDIRECT \ - (LAST_DOUBLY_INDIRECT +\ - (IMFS_MEMFILE_BLOCK_SLOTS * \ - IMFS_MEMFILE_BLOCK_SLOTS * IMFS_MEMFILE_BLOCK_SLOTS)) - -#define IMFS_MEMFILE_MAXIMUM_SIZE \ - (LAST_TRIPLY_INDIRECT * IMFS_MEMFILE_BYTES_PER_BLOCK) - -/* - * What types of IMFS file systems entities there can be. - */ - -#define IMFS_jnode_types_t rtems_filesystem_node_types_t -#define IMFS_DIRECTORY RTEMS_FILESYSTEM_DIRECTORY -#define IMFS_DEVICE RTEMS_FILESYSTEM_DEVICE -#define IMFS_HARD_LINK RTEMS_FILESYSTEM_HARD_LINK -#define IMFS_SYM_LINK RTEMS_FILESYSTEM_SYM_LINK -#define IMFS_MEMORY_FILE RTEMS_FILESYSTEM_MEMORY_FILE -#define IMFS_LINEAR_FILE (IMFS_MEMORY_FILE + 1) - -#define IMFS_NUMBER_OF_TYPES (IMFS_LINEAR_FILE + 1) - -typedef union { - IMFS_directory_t directory; - IMFS_device_t device; - IMFS_link_t hard_link; - IMFS_sym_link_t sym_link; - IMFS_memfile_t file; - IMFS_linearfile_t linearfile; -} IMFS_types_union; - -/* - * Maximum length of a "basename" of an IMFS file/node. - */ - -#define IMFS_NAME_MAX 32 - -/* - * The control structure for an IMFS jnode. - */ - -struct IMFS_jnode_tt { - Chain_Node Node; /* for chaining them together */ - IMFS_jnode_t *Parent; /* Parent node */ - char name[IMFS_NAME_MAX+1]; /* "basename" */ - mode_t st_mode; /* File mode */ - nlink_t st_nlink; /* Link count */ - ino_t st_ino; /* inode */ - - uid_t st_uid; /* User ID of owner */ - gid_t st_gid; /* Group ID of owner */ - - time_t stat_atime; /* Time of last access */ - time_t stat_mtime; /* Time of last modification */ - time_t stat_ctime; /* Time of last status change */ - IMFS_jnode_types_t type; /* Type of this entry */ - IMFS_types_union info; -}; - -#define IMFS_update_atime( _jnode ) \ - do { \ - struct timeval tv; \ - gettimeofday( &tv, 0 ); \ - _jnode->stat_atime = (time_t) tv.tv_sec; \ - } while (0) - -#define IMFS_update_mtime( _jnode ) \ - do { \ - struct timeval tv; \ - gettimeofday( &tv, 0 ); \ - _jnode->stat_mtime = (time_t) tv.tv_sec; \ - } while (0) - -#define IMFS_update_ctime( _jnode ) \ - do { \ - struct timeval tv; \ - gettimeofday( &tv, 0 ); \ - _jnode->stat_ctime = (time_t) tv.tv_sec; \ - } while (0) - -#define IMFS_atime_mtime_update( _jnode ) \ - do { \ - struct timeval tv; \ - gettimeofday( &tv, 0 ); \ - _jnode->stat_mtime = (time_t) tv.tv_sec; \ - _jnode->stat_atime = (time_t) tv.tv_sec; \ - } while (0) - -typedef struct { - ino_t ino_count; - rtems_filesystem_file_handlers_r *linearfile_handlers; - rtems_filesystem_file_handlers_r *memfile_handlers; - rtems_filesystem_file_handlers_r *directory_handlers; -} IMFS_fs_info_t; - -#if UNUSED -/* FIXME: Unused, we might want to remove it */ -#define increment_and_check_linkcounts( _fs_info ) \ - ((IMFS_fs_info_t * )_fs_info)->link_counts++; \ - if ( ((IMFS_fs_info_t * )_fs_info)->link_counts > MAXSYMLINKS ) \ - rtems_set_errno_and_return_minus_one( ELOOP ) -#endif - -#define decrement_linkcounts( _fs_info ) \ - ((IMFS_fs_info_t * )_fs_info)->link_counts--; - -/* - * Type defination for tokens returned from IMFS_get_token - */ - -typedef enum { - IMFS_NO_MORE_PATH, - IMFS_CURRENT_DIR, - IMFS_UP_DIR, - IMFS_NAME, - IMFS_INVALID_TOKEN -} IMFS_token_types; - -/* - * Shared Data - */ - -extern rtems_filesystem_file_handlers_r IMFS_directory_handlers; -extern rtems_filesystem_file_handlers_r IMFS_device_handlers; -extern rtems_filesystem_file_handlers_r IMFS_link_handlers; -extern rtems_filesystem_file_handlers_r IMFS_linearfile_handlers; -extern rtems_filesystem_file_handlers_r IMFS_memfile_handlers; -extern rtems_filesystem_operations_table IMFS_ops; -extern rtems_filesystem_operations_table miniIMFS_ops; -extern rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS; - -/* - * Routines - */ - -int IMFS_initialize( - rtems_filesystem_mount_table_entry_t *mt_entry -); - -int miniIMFS_initialize( - rtems_filesystem_mount_table_entry_t *mt_entry -); - -int IMFS_initialize_support( - rtems_filesystem_mount_table_entry_t *mt_entry, - rtems_filesystem_operations_table *op_table, - rtems_filesystem_file_handlers_r *linearfile_handlers, - rtems_filesystem_file_handlers_r *memfile_handlers, - rtems_filesystem_file_handlers_r *directory_handlers -); - -int IMFS_fsunmount( - rtems_filesystem_mount_table_entry_t *mt_entry -); - -int rtems_tarfs_load( - char *mountpoint, - unsigned char *addr, - unsigned long length -); - -/* - * Returns the number of characters copied from path to token. - */ -IMFS_token_types IMFS_get_token( - const char *path, - char *token, - int *token_len -); - -void IMFS_dump( void ); - -void IMFS_initialize_jnode( - IMFS_jnode_t *the_jnode, - IMFS_jnode_types_t type, - IMFS_jnode_t *the_parent, - char *name, - mode_t mode -); - -IMFS_jnode_t *IMFS_find_match_in_dir( - IMFS_jnode_t *directory, /* IN */ - char *name /* IN */ -); - -rtems_filesystem_node_types_t IMFS_node_type( - rtems_filesystem_location_info_t *pathloc /* IN */ -); - -int IMFS_stat( - rtems_filesystem_location_info_t *loc, /* IN */ - struct stat *buf /* OUT */ -); - -int IMFS_Set_handlers( - rtems_filesystem_location_info_t *loc -); - -int IMFS_evaluate_link( - rtems_filesystem_location_info_t *node, /* IN/OUT */ - int flags /* IN */ -); - -int IMFS_eval_path( - const char *pathname, /* IN */ - int flags, /* IN */ - rtems_filesystem_location_info_t *pathloc /* IN/OUT */ -); - - -int IMFS_link( - rtems_filesystem_location_info_t *to_loc, /* IN */ - rtems_filesystem_location_info_t *parent_loc, /* IN */ - const char *token /* IN */ -); - -int IMFS_unlink( - rtems_filesystem_location_info_t *pathloc /* IN */ -); - -int IMFS_chown( - rtems_filesystem_location_info_t *pathloc, /* IN */ - uid_t owner, /* IN */ - gid_t group /* IN */ -); - -int IMFS_freenodinfo( - rtems_filesystem_location_info_t *pathloc /* IN */ -); - -int IMFS_mknod( - const char *path, /* IN */ - mode_t mode, /* IN */ - dev_t dev, /* IN */ - rtems_filesystem_location_info_t *pathloc /* IN/OUT */ -); - -IMFS_jnode_t *IMFS_create_node( - rtems_filesystem_location_info_t *parent_loc, /* IN */ - IMFS_jnode_types_t type, /* IN */ - char *name, /* IN */ - mode_t mode, /* IN */ - IMFS_types_union *info /* IN */ -); - -int IMFS_evaluate_for_make( - const char *path, /* IN */ - rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ - const char **name /* OUT */ -); - -int IMFS_mount( - rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ -); - -int IMFS_unmount( - rtems_filesystem_mount_table_entry_t *mt_entry /* IN */ -); - -int IMFS_freenod( - rtems_filesystem_location_info_t *node /* IN/OUT */ -); - -int IMFS_memfile_remove( - IMFS_jnode_t *the_jnode /* IN/OUT */ -); - -int memfile_ftruncate( - rtems_libio_t *iop, /* IN */ - off_t length /* IN */ -); - -int imfs_dir_open( - rtems_libio_t *iop, /* IN */ - const char *pathname, /* IN */ - unsigned32 flag, /* IN */ - unsigned32 mode /* IN */ -); - -int imfs_dir_close( - rtems_libio_t *iop /* IN */ -); - -int imfs_dir_read( - rtems_libio_t *iop, /* IN */ - void *buffer, /* IN */ - unsigned32 count /* IN */ -); - -int imfs_dir_lseek( - rtems_libio_t *iop, /* IN */ - off_t offset, /* IN */ - int whence /* IN */ -); - -int imfs_dir_fstat( - rtems_filesystem_location_info_t *loc, /* IN */ - struct stat *buf /* OUT */ -); - -int imfs_dir_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -); - -int linearfile_read( - rtems_libio_t *iop, /* IN */ - void *buffer, /* IN */ - unsigned32 count /* IN */ -); - -int linearfile_lseek( - rtems_libio_t *iop, /* IN */ - off_t offset, /* IN */ - int whence /* IN */ -); - -int memfile_open( - rtems_libio_t *iop, /* IN */ - const char *pathname, /* IN */ - unsigned32 flag, /* IN */ - unsigned32 mode /* IN */ -); - -int memfile_close( - rtems_libio_t *iop /* IN */ -); - -int memfile_read( - rtems_libio_t *iop, /* IN */ - void *buffer, /* IN */ - unsigned32 count /* IN */ -); - -int memfile_write( - rtems_libio_t *iop, /* IN */ - const void *buffer, /* IN */ - unsigned32 count /* IN */ -); - -int memfile_ioctl( - rtems_libio_t *iop, /* IN */ - unsigned32 command, /* IN */ - void *buffer /* IN */ -); - -int memfile_lseek( - rtems_libio_t *iop, /* IN */ - off_t offset, /* IN */ - int whence /* IN */ -); - -int memfile_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -); - -int device_open( - rtems_libio_t *iop, /* IN */ - const char *pathname, /* IN */ - unsigned32 flag, /* IN */ - unsigned32 mode /* IN */ -); - -int device_close( - rtems_libio_t *iop /* IN */ -); - -int device_read( - rtems_libio_t *iop, /* IN */ - void *buffer, /* IN */ - unsigned32 count /* IN */ -); - -int device_write( - rtems_libio_t *iop, /* IN */ - const void *buffer, /* IN */ - unsigned32 count /* IN */ -); - -int device_ioctl( - rtems_libio_t *iop, /* IN */ - unsigned32 command, /* IN */ - void *buffer /* IN */ -); - -int device_lseek( - rtems_libio_t *iop, /* IN */ - off_t offset, /* IN */ - int whence /* IN */ -); - -int IMFS_utime( - rtems_filesystem_location_info_t *pathloc, /* IN */ - time_t actime, /* IN */ - time_t modtime /* IN */ -); - -int IMFS_fchmod( - rtems_filesystem_location_info_t *loc, - mode_t mode -); - -int IMFS_symlink( - rtems_filesystem_location_info_t *parent_loc, /* IN */ - const char *link_name, - const char *node_name -); - -int IMFS_readlink( - rtems_filesystem_location_info_t *loc, /* IN */ - char *buf, /* OUT */ - size_t bufsize -); - -int IMFS_fdatasync( - rtems_libio_t *iop -); - -int IMFS_fcntl( - int cmd, - rtems_libio_t *iop -); - -int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -); - -#ifdef __cplusplus -} -#endif - -#endif -/* end of include file */ diff --git a/c/src/libfs/src/imfs/imfs_chown.c b/c/src/libfs/src/imfs/imfs_chown.c deleted file mode 100644 index 2db58052ee..0000000000 --- a/c/src/libfs/src/imfs/imfs_chown.c +++ /dev/null @@ -1,56 +0,0 @@ -/* - * IMFS_chown - * - * This routine is the implementation of the chown() system - * call for the IMFS. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include "imfs.h" - -int IMFS_chown( - rtems_filesystem_location_info_t *pathloc, /* IN */ - uid_t owner, /* IN */ - gid_t group /* IN */ -) -{ - IMFS_jnode_t *jnode; -#if defined(RTEMS_POSIX_API) - uid_t st_uid; -#endif - - jnode = (IMFS_jnode_t *) pathloc->node_access; - - /* - * Verify I am the owner of the node or the super user. - */ - -#if defined(RTEMS_POSIX_API) - st_uid = geteuid(); - - if ( ( st_uid != jnode->st_uid ) && ( st_uid != 0 ) ) - rtems_set_errno_and_return_minus_one( EPERM ); -#endif - - jnode->st_uid = owner; - jnode->st_gid = group; - - IMFS_update_ctime( jnode ); - - return 0; -} diff --git a/c/src/libfs/src/imfs/imfs_config.c b/c/src/libfs/src/imfs/imfs_config.c deleted file mode 100644 index af9d1d1f16..0000000000 --- a/c/src/libfs/src/imfs/imfs_config.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include "imfs.h" - -/* XXX this structure should use real constants */ - -rtems_filesystem_limits_and_options_t IMFS_LIMITS_AND_OPTIONS = { - 5, /* link_max */ - 6, /* max_canon */ - 7, /* max_input */ - IMFS_NAME_MAX, /* name_max */ - 255, /* path_max */ - 2, /* pipe_buf */ - 1, /* posix_async_io */ - 2, /* posix_chown_restrictions */ - 3, /* posix_no_trunc */ - 4, /* posix_prio_io */ - 5, /* posix_sync_io */ - 6 /* posix_vdisable */ -}; - - diff --git a/c/src/libfs/src/imfs/imfs_creat.c b/c/src/libfs/src/imfs/imfs_creat.c deleted file mode 100644 index cc7449b12d..0000000000 --- a/c/src/libfs/src/imfs/imfs_creat.c +++ /dev/null @@ -1,137 +0,0 @@ -/* - * IMFS_create_node() - * - * Routine to create a new in memory file system node. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include "imfs.h" -#include - -IMFS_jnode_t *IMFS_create_node( - rtems_filesystem_location_info_t *parent_loc, - IMFS_jnode_types_t type, - char *name, - mode_t mode, - IMFS_types_union *info -) -{ - IMFS_jnode_t *node; - struct timeval tv; - IMFS_jnode_t *parent = NULL; - IMFS_fs_info_t *fs_info; - char *sym_name; - - if ( parent_loc != NULL ) - parent = parent_loc->node_access; - - /* - * Allocate an IMFS jnode - */ - - node = calloc( 1, sizeof( IMFS_jnode_t ) ); - if ( !node ) - return NULL; - - /* - * Fill in the basic information - */ - - node->st_nlink = 1; - node->type = type; - strncpy( node->name, name, IMFS_NAME_MAX ); - - /* - * Fill in the mode and permission information for the jnode structure. - */ - - node->st_mode = mode & ~rtems_filesystem_umask; - -#if defined(RTEMS_POSIX_API) - node->st_uid = geteuid(); - node->st_gid = getegid(); -#else - node->st_uid = 0; - node->st_gid = 0; -#endif - - /* - * Now set all the times. - */ - - gettimeofday( &tv, 0 ); - - node->stat_atime = (time_t) tv.tv_sec; - node->stat_mtime = (time_t) tv.tv_sec; - node->stat_ctime = (time_t) tv.tv_sec; - - /* - * Set the type specific information - */ - - switch (type) { - case IMFS_DIRECTORY: - Chain_Initialize_empty(&node->info.directory.Entries); - break; - - case IMFS_HARD_LINK: - node->info.hard_link.link_node = info->hard_link.link_node; - break; - - case IMFS_SYM_LINK: - sym_name = calloc( 1, strlen( info->sym_link.name ) + 1 ); - strcpy( sym_name, info->sym_link.name ); - node->info.sym_link.name = sym_name; - break; - - case IMFS_DEVICE: - node->info.device.major = info->device.major; - node->info.device.minor = info->device.minor; - break; - - case IMFS_LINEAR_FILE: - node->info.linearfile.size = 0; - node->info.linearfile.direct = 0; - - case IMFS_MEMORY_FILE: - node->info.file.size = 0; - node->info.file.indirect = 0; - node->info.file.doubly_indirect = 0; - node->info.file.triply_indirect = 0; - break; - - default: - assert(0); - break; - } - - /* - * If this node has a parent, then put it in that directory list. - */ - - if ( parent ) { - Chain_Append( &parent->info.directory.Entries, &node->Node ); - node->Parent = parent; - - fs_info = parent_loc->mt_entry->fs_info; - node->st_ino = ++fs_info->ino_count; - } - - - return node; -} diff --git a/c/src/libfs/src/imfs/imfs_debug.c b/c/src/libfs/src/imfs/imfs_debug.c deleted file mode 100644 index f852c81d8b..0000000000 --- a/c/src/libfs/src/imfs/imfs_debug.c +++ /dev/null @@ -1,176 +0,0 @@ -/* - * IMFS debug support routines - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include /* for close */ - -#include -#include - -#include "imfs.h" -#include - -/* - * IMFS_types - * - * Printable names for each of the IMFS file system types. - */ - -char *IMFS_types[ IMFS_NUMBER_OF_TYPES ] = { - "directory", - "device", - "link", - "memory file", - "linear file" -}; - -/* - * IMFS_print_jnode - * - * This routine prints the contents of the specified jnode. - */ - -void IMFS_print_jnode( - IMFS_jnode_t *the_jnode -) -{ - assert( the_jnode ); - - printf( "%s", the_jnode->name ); - switch( the_jnode->type ) { - case IMFS_DIRECTORY: - printf( "/" ); - break; - - case IMFS_DEVICE: - printf( " (device %d, %d)", - the_jnode->info.device.major, the_jnode->info.device.minor ); - break; - - case IMFS_LINEAR_FILE: - printf( " (file %d %p)", - (int)the_jnode->info.linearfile.size, - the_jnode->info.linearfile.direct - ); - break; - - case IMFS_MEMORY_FILE: - /* Useful when debugging .. varies between targets */ -#if 0 - printf( " (file %d %p %p %p)", - (int)the_jnode->info.file.size, - the_jnode->info.file.indirect, - the_jnode->info.file.doubly_indirect, - the_jnode->info.file.triply_indirect - ); -#else - printf( " (file %d)", (int)the_jnode->info.file.size ); -#endif - break; - - case IMFS_HARD_LINK: - printf( " links not printed\n" ); - assert(0); - break; - - case IMFS_SYM_LINK: - printf( " links not printed\n" ); - assert(0); - break; - - default: - printf( " bad type %d\n", the_jnode->type ); - assert(0); - break; - } - puts(""); -} - -/* - * IMFS_dump_directory - * - * This routine prints the contents of a directory in the IMFS. If a - * directory is encountered, then this routine will recurse to process - * the subdirectory. - */ - -void IMFS_dump_directory( - IMFS_jnode_t *the_directory, - int level -) -{ - Chain_Node *the_node; - Chain_Control *the_chain; - IMFS_jnode_t *the_jnode; - int i; - - assert( the_directory ); - - assert( level >= 0 ); - - assert( the_directory->type == IMFS_DIRECTORY ); - - the_chain = &the_directory->info.directory.Entries; - - for ( the_node = the_chain->first; - !_Chain_Is_tail( the_chain, the_node ); - the_node = the_node->next ) { - - the_jnode = (IMFS_jnode_t *) the_node; - - for ( i=0 ; i<=level ; i++ ) - printf( "...." ); - IMFS_print_jnode( the_jnode ); - if ( the_jnode->type == IMFS_DIRECTORY ) - IMFS_dump_directory( the_jnode, level + 1 ); - } -} - -/* - * IMFS_dump - * - * This routine dumps the entire IMFS that is mounted at the root - * directory. - * - * NOTE: Assuming the "/" directory is bad. - * Not checking that the starting directory is in an IMFS is bad. - */ - -void IMFS_dump( void ) -{ - printf( "*************** Dump of Entire IMFS ***************\n" ); - printf( "/\n" ); - IMFS_dump_directory( rtems_filesystem_root.node_access, 0 ); - printf( "*************** End of Dump ***************\n" ); -} - -/* - * IMFS_memfile_maximum_size() - * - * This routine returns the size of the largest file which can be created - * using the IMFS memory file type. - * - */ - -int IMFS_memfile_maximum_size( void ) -{ - return IMFS_MEMFILE_MAXIMUM_SIZE; -} diff --git a/c/src/libfs/src/imfs/imfs_directory.c b/c/src/libfs/src/imfs/imfs_directory.c deleted file mode 100644 index dec1e0ec2d..0000000000 --- a/c/src/libfs/src/imfs/imfs_directory.c +++ /dev/null @@ -1,353 +0,0 @@ -/* - * IMFS Directory Access Routines - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "imfs.h" -#include -#include - -/* - * imfs_dir_open - * - * This rountine will verify that the node being opened as a directory is - * in fact a directory node. If it is then the offset into the directory - * will be set to 0 to position to the first directory entry. - */ - -int imfs_dir_open( - rtems_libio_t *iop, - const char *pathname, - unsigned32 flag, - unsigned32 mode -) -{ - IMFS_jnode_t *the_jnode; - - /* Is the node a directory ? */ - the_jnode = (IMFS_jnode_t *) iop->file_info; - - if ( the_jnode->type != IMFS_DIRECTORY ) - return -1; /* It wasn't a directory --> return error */ - - iop->offset = 0; - return 0; -} - -/* - * imfs_dir_read - * - * This routine will read the next directory entry based on the directory - * offset. The offset should be equal to -n- time the size of an individual - * dirent structure. If n is not an integer multiple of the sizeof a - * dirent structure, an integer division will be performed to determine - * directory entry that will be returned in the buffer. Count should reflect - * -m- times the sizeof dirent bytes to be placed in the buffer. - * If there are not -m- dirent elements from the current directory position - * to the end of the exisiting file, the remaining entries will be placed in - * the buffer and the returned value will be equal to -m actual- times the - * size of a directory entry. - */ - -int imfs_dir_read( - rtems_libio_t *iop, - void *buffer, - unsigned32 count -) -{ - /* - * Read up to element iop->offset in the directory chain of the - * imfs_jnode_t struct for this file descriptor. - */ - Chain_Node *the_node; - Chain_Control *the_chain; - IMFS_jnode_t *the_jnode; - int bytes_transferred; - int current_entry; - int first_entry; - int last_entry; - struct dirent tmp_dirent; - - the_jnode = (IMFS_jnode_t *)iop->file_info; - the_chain = &the_jnode->info.directory.Entries; - - if ( Chain_Is_empty( the_chain ) ) - return 0; - - /* Move to the first of the desired directory entries */ - the_node = the_chain->first; - - bytes_transferred = 0; - first_entry = iop->offset; - /* protect against using sizes that are not exact multiples of the */ - /* -dirent- size. These could result in unexpected results */ - last_entry = first_entry + (count/sizeof(struct dirent)) * sizeof(struct dirent); - - /* The directory was not empty so try to move to the desired entry in chain*/ - for ( - current_entry = 0; - current_entry < last_entry; - current_entry = current_entry + sizeof(struct dirent) ){ - - if ( Chain_Is_tail( the_chain, the_node ) ){ - /* We hit the tail of the chain while trying to move to the first */ - /* entry in the read */ - return bytes_transferred; /* Indicate that there are no more */ - /* entries to return */ - } - - if( current_entry >= first_entry ) { - /* Move the entry to the return buffer */ - tmp_dirent.d_off = current_entry; - tmp_dirent.d_reclen = sizeof( struct dirent ); - the_jnode = (IMFS_jnode_t *) the_node; - tmp_dirent.d_ino = the_jnode->st_ino; - tmp_dirent.d_namlen = strlen( the_jnode->name ); - strcpy( tmp_dirent.d_name, the_jnode->name ); - memcpy( - buffer + bytes_transferred, - (void *)&tmp_dirent, - sizeof( struct dirent ) - ); - iop->offset = iop->offset + sizeof(struct dirent); - bytes_transferred = bytes_transferred + sizeof( struct dirent ); - } - - the_node = the_node->next; - } - - /* Success */ - return bytes_transferred; -} - - - -/* - * imfs_dir_close - * - * This routine will be called by the generic close routine to cleanup any - * resources that have been allocated for the management of the file - */ - -int imfs_dir_close( - rtems_libio_t *iop -) -{ - /* - * The generic close routine handles the deallocation of the file control - * and associated memory. At present the imfs_dir_close simply - * returns a successful completion status. - */ - - return 0; -} - - - -/* - * imfs_dir_lseek - * - * This routine will behave in one of three ways based on the state of - * argument whence. Based on the state of its value the offset argument will - * be interpreted using one of the following methods: - * - * SEEK_SET - offset is the absolute byte offset from the start of the - * logical start of the dirent sequence that represents the - * directory - * SEEK_CUR - offset is used as the relative byte offset from the current - * directory position index held in the iop structure - * SEEK_END - N/A --> This will cause an assert. - */ - -int imfs_dir_lseek( - rtems_libio_t *iop, - off_t offset, - int whence -) -{ - switch( whence ) { - case SEEK_SET: /* absolute move from the start of the file */ - case SEEK_CUR: /* relative move */ - iop->offset = (iop->offset/sizeof(struct dirent)) * - sizeof(struct dirent); - break; - - case SEEK_END: /* Movement past the end of the directory via lseek */ - /* is not a permitted operation */ - default: - rtems_set_errno_and_return_minus_one( EINVAL ); - break; - } - - return 0; -} - - - -/* - * imfs_dir_fstat - * - * This routine will obtain the following information concerning the current - * directory: - * st_dev 0ll - * st_ino 1 - * st_mode mode extracted from the jnode - * st_nlink number of links to this node - * st_uid uid extracted from the jnode - * st_gid gid extracted from the jnode - * st_rdev 0ll - * st_size the number of bytes in the directory - * This is calculated by taking the number of entries - * in the directory and multiplying by the size of a - * dirent structure - * st_blksize 0 - * st_blocks 0 - * stat_atime time of last access - * stat_mtime time of last modification - * stat_ctime time of the last change - * - * This information will be returned to the calling function in a -stat- struct - * - */ - -int imfs_dir_fstat( - rtems_filesystem_location_info_t *loc, - struct stat *buf -) -{ - Chain_Node *the_node; - Chain_Control *the_chain; - IMFS_jnode_t *the_jnode; - - - the_jnode = (IMFS_jnode_t *) loc->node_access; - - buf->st_dev = 0ll; - buf->st_ino = the_jnode->st_ino; - buf->st_mode = the_jnode->st_mode; - buf->st_nlink = the_jnode->st_nlink; - buf->st_uid = the_jnode->st_uid; - buf->st_gid = the_jnode->st_gid; - buf->st_rdev = 0ll; - buf->st_blksize = 0; - buf->st_blocks = 0; - buf->st_atime = the_jnode->stat_atime; - buf->st_mtime = the_jnode->stat_mtime; - buf->st_ctime = the_jnode->stat_ctime; - - buf->st_size = 0; - - the_chain = &the_jnode->info.directory.Entries; - - /* Run through the chain and count the number of directory entries */ - /* that are subordinate to this directory node */ - for ( the_node = the_chain->first ; - !_Chain_Is_tail( the_chain, the_node ) ; - the_node = the_node->next ) { - - buf->st_size = buf->st_size + sizeof( struct dirent ); - } - - return 0; -} - -/* - * IMFS_dir_rmnod - * - * This routine is available from the optable to remove a node - * from the IMFS file system. - */ - -int imfs_dir_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = (IMFS_jnode_t *) pathloc->node_access; - - /* - * You cannot remove a node that still has children - */ - - if ( ! Chain_Is_empty( &the_jnode->info.directory.Entries ) ) - rtems_set_errno_and_return_minus_one( ENOTEMPTY ); - - /* - * You cannot remove the file system root node. - */ - - if ( pathloc->mt_entry->mt_fs_root.node_access == pathloc->node_access ) - rtems_set_errno_and_return_minus_one( EBUSY ); - - /* - * You cannot remove a mountpoint. - */ - - if ( the_jnode->info.directory.mt_fs != NULL ) - rtems_set_errno_and_return_minus_one( EBUSY ); - - /* - * Take the node out of the parent's chain that contains this node - */ - - if ( the_jnode->Parent != NULL ) { - Chain_Extract( (Chain_Node *) the_jnode ); - the_jnode->Parent = NULL; - } - - /* - * Decrement the link counter and see if we can free the space. - */ - - the_jnode->st_nlink--; - IMFS_update_ctime( the_jnode ); - - /* - * The file cannot be open and the link must be less than 1 to free. - */ - - if ( !rtems_libio_is_file_open( the_jnode ) && (the_jnode->st_nlink < 1) ) { - - /* - * Is the rtems_filesystem_current is this node? - */ - - if ( rtems_filesystem_current.node_access == pathloc->node_access ) - rtems_filesystem_current.node_access = NULL; - - /* - * Free memory associated with a memory file. - */ - - free( the_jnode ); - } - - return 0; - -} - - diff --git a/c/src/libfs/src/imfs/imfs_eval.c b/c/src/libfs/src/imfs/imfs_eval.c deleted file mode 100644 index 09838230cb..0000000000 --- a/c/src/libfs/src/imfs/imfs_eval.c +++ /dev/null @@ -1,660 +0,0 @@ -/* - * Evaluation IMFS Node Support Routines - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include - -#include "imfs.h" -#include -#include - -#define RTEMS_LIBIO_PERMS_RX (RTEMS_LIBIO_PERMS_SEARCH | RTEMS_LIBIO_PERMS_READ) -#define RTEMS_LIBIO_PERMS_WX (RTEMS_LIBIO_PERMS_SEARCH | RTEMS_LIBIO_PERMS_WRITE) - -#define MAXSYMLINK 5 - -int IMFS_Set_handlers( - rtems_filesystem_location_info_t *loc -) -{ - IMFS_jnode_t *node = loc->node_access; - IMFS_fs_info_t *fs_info; - - fs_info = loc->mt_entry->fs_info; - switch( node->type ) { - case IMFS_DIRECTORY: - loc->handlers = fs_info->directory_handlers; - break; - case IMFS_DEVICE: - loc->handlers = &IMFS_device_handlers; - break; - case IMFS_SYM_LINK: - case IMFS_HARD_LINK: - loc->handlers = &IMFS_link_handlers; - break; - case IMFS_LINEAR_FILE: - loc->handlers = fs_info->linearfile_handlers; - break; - case IMFS_MEMORY_FILE: - loc->handlers = fs_info->memfile_handlers; - break; - } - - return 0; -} - -/* - * IMFS_evaluate_permission - * - * The following routine evaluates that we have permission - * to do flags on the node. - */ - -int IMFS_evaluate_permission( - rtems_filesystem_location_info_t *node, - int flags -) -{ - uid_t st_uid; - gid_t st_gid; - IMFS_jnode_t *jnode; - int flags_to_test; - - if ( !rtems_libio_is_valid_perms( flags ) ) { - assert( 0 ); - rtems_set_errno_and_return_minus_one( EIO ); - } - - jnode = node->node_access; - -#if defined(RTEMS_POSIX_API) - st_uid = geteuid(); - st_gid = getegid(); -#else - st_uid = jnode->st_uid; - st_gid = jnode->st_gid; -#endif - - /* - * Check if I am owner or a group member or someone else. - */ - - flags_to_test = flags; - - if ( st_uid == jnode->st_uid ) - flags_to_test <<= 6; - else if ( st_gid == jnode->st_gid ) - flags_to_test <<= 3; - else - /* must be other - do nothing */; - - /* - * If all of the flags are set we have permission - * to do this. - */ - if ( ( flags_to_test & jnode->st_mode) == flags_to_test ) - return 1; - - return 0; -} - -/* - * IMFS_evaluate_hard_link - * - * The following routine evaluates a hardlink to the actual node. - */ - -int IMFS_evaluate_hard_link( - rtems_filesystem_location_info_t *node, /* IN/OUT */ - int flags /* IN */ -) -{ - IMFS_jnode_t *jnode = node->node_access; - int result = 0; - - /* - * Check for things that should never happen. - */ - - if ( jnode->type != IMFS_HARD_LINK ) - rtems_fatal_error_occurred (0xABCD0000); - - /* - * Set the hard link value and the handlers. - */ - - node->node_access = jnode->info.hard_link.link_node; - - IMFS_Set_handlers( node ); - - /* - * Verify we have the correct permissions for this node. - */ - - if ( !IMFS_evaluate_permission( node, flags ) ) - rtems_set_errno_and_return_minus_one( EACCES ); - - return result; -} - - -/* - * IMFS_evaluate_sym_link - * - * The following routine evaluates a symbolic link to the actual node. - */ - -int IMFS_evaluate_sym_link( - rtems_filesystem_location_info_t *node, /* IN/OUT */ - int flags /* IN */ -) -{ - IMFS_jnode_t *jnode = node->node_access; - int result = 0; - int i; - - /* - * Check for things that should never happen. - */ - - if ( jnode->type != IMFS_SYM_LINK ) - rtems_fatal_error_occurred (0xABCD0000); - - if ( !jnode->Parent ) - rtems_fatal_error_occurred( 0xBAD00000 ); - - - /* - * Move the node_access to either the symbolic links parent or - * root depending on the symbolic links path. - */ - - node->node_access = jnode->Parent; - - rtems_filesystem_get_sym_start_loc( - jnode->info.sym_link.name, - &i, - node - ); - - /* - * Use eval path to evaluate the path of the symbolic link. - */ - - result = IMFS_eval_path( - &jnode->info.sym_link.name[i], - flags, - node - ); - - IMFS_Set_handlers( node ); - - /* - * Verify we have the correct permissions for this node. - */ - - if ( !IMFS_evaluate_permission( node, flags ) ) - rtems_set_errno_and_return_minus_one( EACCES ); - - return result; -} - -/* - * IMFS_evaluate_link - * - * The following routine returns the real node pointed to by a link. - */ - -int IMFS_evaluate_link( - rtems_filesystem_location_info_t *node, /* IN/OUT */ - int flags /* IN */ -) -{ - IMFS_jnode_t *jnode; - int result = 0; - - do { - jnode = node->node_access; - - /* - * Increment and check the link counter. - */ - - rtems_filesystem_link_counts ++; - if ( rtems_filesystem_link_counts > MAXSYMLINK ) { - rtems_filesystem_link_counts = 0; - rtems_set_errno_and_return_minus_one( ELOOP ); - } - - /* - * Follow the Link node. - */ - - if ( jnode->type == IMFS_HARD_LINK ) - result = IMFS_evaluate_hard_link( node, flags ); - - else if (jnode->type == IMFS_SYM_LINK ) - result = IMFS_evaluate_sym_link( node, flags ); - - } while ( ( result == 0 ) && ( ( jnode->type == IMFS_SYM_LINK ) || - ( jnode->type == IMFS_HARD_LINK ) ) ); - - /* - * Clear link counter. - */ - - rtems_filesystem_link_counts = 0; - - return result; -} - - -/* - * IMFS_evaluate_for_make - * - * The following routine evaluate path for a new node to be created. - * pathloc is returned with a pointer to the parent of the new node. - * name is returned with a pointer to the first character in the - * new node name. The parent node is verified to be a directory. - */ - -int IMFS_evaluate_for_make( - const char *path, /* IN */ - rtems_filesystem_location_info_t *pathloc, /* IN/OUT */ - const char **name /* OUT */ -) -{ - int i = 0; - int len; - IMFS_token_types type; - char token[ IMFS_NAME_MAX + 1 ]; - rtems_filesystem_location_info_t newloc; - IMFS_jnode_t *node; - int done = 0; - int result; - - /* - * This was filled in by the caller and is valid in the - * mount table. - */ - node = pathloc->node_access; - - /* - * Evaluate all tokens until we are done or an error occurs. - */ - - while( !done ) { - - type = IMFS_get_token( &path[i], token, &len ); - i += len; - - if ( !pathloc->node_access ) - rtems_set_errno_and_return_minus_one( ENOENT ); - - /* - * I cannot move out of this directory without execute permission. - */ - - if ( type != IMFS_NO_MORE_PATH ) - if ( node->type == IMFS_DIRECTORY ) - if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_SEARCH ) ) - rtems_set_errno_and_return_minus_one( EACCES ); - - node = pathloc->node_access; - - switch( type ) { - - case IMFS_UP_DIR: - /* - * Am I at the root of all filesystems? (chroot'ed?) - */ - - if ( pathloc->node_access == rtems_filesystem_root.node_access ) - break; /* Throw out the .. in this case */ - - - /* - * Am I at the root of this mounted filesystem? - */ - - if (pathloc->node_access == pathloc->mt_entry->mt_fs_root.node_access){ - - /* - * Am I at the root of all filesystems? - */ - - if ( pathloc->node_access == rtems_filesystem_root.node_access ) { - break; - - } else { - newloc = pathloc->mt_entry->mt_point_node; - *pathloc = newloc; - return (*pathloc->ops->evalformake_h)( &path[i-len], pathloc, name ); - } - } else { - - if ( !node->Parent ) - rtems_set_errno_and_return_minus_one( ENOENT ); - - node = node->Parent; - } - - pathloc->node_access = node; - break; - - case IMFS_NAME: - - if ( node->type == IMFS_HARD_LINK ) { - - result = IMFS_evaluate_link( pathloc, 0 ); - if ( result == -1 ) - return -1; - - } else if ( node->type == IMFS_SYM_LINK ) { - - result = IMFS_evaluate_link( pathloc, 0 ); - - if ( result == -1 ) - return -1; - } - - node = pathloc->node_access; - if ( !node ) - rtems_set_errno_and_return_minus_one( ENOTDIR ); - - /* - * Only a directory can be decended into. - */ - - if ( node->type != IMFS_DIRECTORY ) - rtems_set_errno_and_return_minus_one( ENOTDIR ); - - /* - * If we are at a node that is a mount point. Set loc to the - * new fs root node and let them finish evaluating the path. - */ - - if ( node->info.directory.mt_fs != NULL ) { - newloc = node->info.directory.mt_fs->mt_fs_root; - *pathloc = newloc; - return (*pathloc->ops->evalformake_h)( &path[i-len], pathloc, name ); - } - - /* - * Otherwise find the token name in the present location. - */ - - node = IMFS_find_match_in_dir( node, token ); - - /* - * If there is no node we have found the name of the node we - * wish to create. - */ - - if ( ! node ) - done = TRUE; - else - pathloc->node_access = node; - - break; - - case IMFS_NO_MORE_PATH: - rtems_set_errno_and_return_minus_one( EEXIST ); - break; - - case IMFS_INVALID_TOKEN: - rtems_set_errno_and_return_minus_one( ENAMETOOLONG ); - break; - - case IMFS_CURRENT_DIR: - break; - } - } - - *name = &path[ i - len ]; - - /* - * We have evaluated the path as far as we can. - * Verify there is not any invalid stuff at the end of the name. - */ - - for( ; path[i] != '\0'; i++) { - if ( !IMFS_is_separator( path[ i ] ) ) - rtems_set_errno_and_return_minus_one( ENOENT ); - } - - /* - * Verify we can execute and write to this directory. - */ - - result = IMFS_Set_handlers( pathloc ); - - /* - * The returned node must be a directory - */ - node = pathloc->node_access; - if ( node->type != IMFS_DIRECTORY ) - rtems_set_errno_and_return_minus_one( ENOTDIR ); - - /* - * We must have Write and execute permission on the returned node. - */ - - if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_WX ) ) - rtems_set_errno_and_return_minus_one( EACCES ); - - return result; -} - - -/* - * IMFS_eval_path - * - * The following routine evaluate path for a node that wishes to be - * accessed with mode. pathloc is returned with a pointer to the - * node to be accessed. - */ - -int IMFS_eval_path( - const char *pathname, /* IN */ - int flags, /* IN */ - rtems_filesystem_location_info_t *pathloc /* IN/OUT */ -) -{ - int i = 0; - int len; - IMFS_token_types type = IMFS_CURRENT_DIR; - char token[ IMFS_NAME_MAX + 1 ]; - rtems_filesystem_location_info_t newloc; - IMFS_jnode_t *node; - int result; - - if ( !rtems_libio_is_valid_perms( flags ) ) { - assert( 0 ); - rtems_set_errno_and_return_minus_one( EIO ); - } - - /* - * This was filled in by the caller and is valid in the - * mount table. - */ - - node = pathloc->node_access; - - /* - * Evaluate all tokens until we are done or an error occurs. - */ - - while( (type != IMFS_NO_MORE_PATH) && (type != IMFS_INVALID_TOKEN) ) { - - type = IMFS_get_token( &pathname[i], token, &len ); - i += len; - - if ( !pathloc->node_access ) - rtems_set_errno_and_return_minus_one( ENOENT ); - - /* - * I cannot move out of this directory without execute permission. - */ - if ( type != IMFS_NO_MORE_PATH ) - if ( node->type == IMFS_DIRECTORY ) - if ( !IMFS_evaluate_permission( pathloc, RTEMS_LIBIO_PERMS_SEARCH ) ) - rtems_set_errno_and_return_minus_one( EACCES ); - - node = pathloc->node_access; - - switch( type ) { - case IMFS_UP_DIR: - /* - * Am I at the root of all filesystems? (chroot'ed?) - */ - - if ( pathloc->node_access == rtems_filesystem_root.node_access ) - break; /* Throw out the .. in this case */ - - /* - * Am I at the root of this mounted filesystem? - */ - - if (pathloc->node_access == - pathloc->mt_entry->mt_fs_root.node_access) { - - /* - * Am I at the root of all filesystems? - */ - - if ( pathloc->node_access == rtems_filesystem_root.node_access ) { - break; /* Throw out the .. in this case */ - } else { - newloc = pathloc->mt_entry->mt_point_node; - *pathloc = newloc; - return (*pathloc->ops->evalpath_h)(&(pathname[i-len]),flags,pathloc); - } - } else { - - if ( !node->Parent ) - rtems_set_errno_and_return_minus_one( ENOENT ); - - node = node->Parent; - pathloc->node_access = node; - - } - - pathloc->node_access = node; - break; - - case IMFS_NAME: - /* - * If we are at a link follow it. - */ - - if ( node->type == IMFS_HARD_LINK ) { - - IMFS_evaluate_hard_link( pathloc, 0 ); - - node = pathloc->node_access; - if ( !node ) - rtems_set_errno_and_return_minus_one( ENOTDIR ); - - } else if ( node->type == IMFS_SYM_LINK ) { - - result = IMFS_evaluate_sym_link( pathloc, 0 ); - - node = pathloc->node_access; - if ( result == -1 ) - return -1; - } - - /* - * Only a directory can be decended into. - */ - - if ( node->type != IMFS_DIRECTORY ) - rtems_set_errno_and_return_minus_one( ENOTDIR ); - - /* - * If we are at a node that is a mount point. Set loc to the - * new fs root node and let them finish evaluating the path. - */ - - if ( node->info.directory.mt_fs != NULL ) { - newloc = node->info.directory.mt_fs->mt_fs_root; - *pathloc = newloc; - return (*pathloc->ops->evalpath_h)( &pathname[i-len], flags, pathloc ); - } - - /* - * Otherwise find the token name in the present location. - */ - - node = IMFS_find_match_in_dir( node, token ); - if ( !node ) - rtems_set_errno_and_return_minus_one( ENOENT ); - - /* - * Set the node access to the point we have found. - */ - - pathloc->node_access = node; - break; - - case IMFS_NO_MORE_PATH: - case IMFS_CURRENT_DIR: - break; - - case IMFS_INVALID_TOKEN: - rtems_set_errno_and_return_minus_one( ENAMETOOLONG ); - break; - - } - } - - /* - * Always return the root node. - * - * If we are at a node that is a mount point. Set loc to the - * new fs root node and let let the mounted filesystem set the handlers. - * - * NOTE: The behavior of stat() on a mount point appears to be questionable. - */ - - if ( node->type == IMFS_DIRECTORY ) { - if ( node->info.directory.mt_fs != NULL ) { - newloc = node->info.directory.mt_fs->mt_fs_root; - *pathloc = newloc; - return (*pathloc->ops->evalpath_h)( &pathname[i-len], flags, pathloc ); - } else { - result = IMFS_Set_handlers( pathloc ); - } - } else { - result = IMFS_Set_handlers( pathloc ); - } - - /* - * Verify we have the correct permissions for this node. - */ - - if ( !IMFS_evaluate_permission( pathloc, flags ) ) - rtems_set_errno_and_return_minus_one( EACCES ); - - return result; -} diff --git a/c/src/libfs/src/imfs/imfs_fchmod.c b/c/src/libfs/src/imfs/imfs_fchmod.c deleted file mode 100644 index cf7c644793..0000000000 --- a/c/src/libfs/src/imfs/imfs_fchmod.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * IMFS file change mode routine. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include -#include "imfs.h" - -int IMFS_fchmod( - rtems_filesystem_location_info_t *loc, - mode_t mode -) -{ - IMFS_jnode_t *jnode; -#if defined(RTEMS_POSIX_API) - uid_t st_uid; -#endif - - jnode = loc->node_access; - - /* - * Verify I am the owner of the node or the super user. - */ -#if defined(RTEMS_POSIX_API) - st_uid = geteuid(); - - if ( ( st_uid != jnode->st_uid ) && ( st_uid != 0 ) ) - rtems_set_errno_and_return_minus_one( EPERM ); -#endif - - /* - * Change only the RWX permissions on the jnode to mode. - */ - if ( mode & (~ (S_IRWXU | S_IRWXG | S_IRWXO ) ) ) - rtems_set_errno_and_return_minus_one( EPERM ); - - /* - * If we make a linear-file writeable, construct a block file - * from it first. - */ - if ( (jnode->type == IMFS_LINEAR_FILE) && - (mode & (S_IWUSR | S_IWGRP | S_IWOTH)) ) - { - unsigned32 count = jnode->info.linearfile.size; - const unsigned char *buffer = jnode->info.linearfile.direct; - - jnode->type = IMFS_MEMORY_FILE; - jnode->info.file.size = 0; - jnode->info.file.indirect = 0; - jnode->info.file.doubly_indirect = 0; - jnode->info.file.triply_indirect = 0; - if (IMFS_memfile_write(jnode, 0, buffer, count) == -1) - return(-1); - } - - jnode->st_mode &= ~(S_IRWXU | S_IRWXG | S_IRWXO); - jnode->st_mode |= mode; - - IMFS_update_ctime( jnode ); - - return 0; -} - diff --git a/c/src/libfs/src/imfs/imfs_fcntl.c b/c/src/libfs/src/imfs/imfs_fcntl.c deleted file mode 100644 index a21d5a5720..0000000000 --- a/c/src/libfs/src/imfs/imfs_fcntl.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * IMFS_fcntl - * - * The following routine does a fcntl on an IMFS node. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include "imfs.h" - -int IMFS_fcntl( - int cmd, - rtems_libio_t *iop -) -{ - return 0; -} diff --git a/c/src/libfs/src/imfs/imfs_fdatasync.c b/c/src/libfs/src/imfs/imfs_fdatasync.c deleted file mode 100644 index 1a5b9fdcd1..0000000000 --- a/c/src/libfs/src/imfs/imfs_fdatasync.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * IMFS_fdatasync - * - * The following routine does a sync on an IMFS node. The In Memory - * File System is always in sync, therefore this routine always returns - * pass. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include "imfs.h" - -int IMFS_fdatasync( - rtems_libio_t *iop -) -{ - return 0; -} diff --git a/c/src/libfs/src/imfs/imfs_free.c b/c/src/libfs/src/imfs/imfs_free.c deleted file mode 100644 index 01e07d9bf2..0000000000 --- a/c/src/libfs/src/imfs/imfs_free.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Free IMFS Node Support Routines - * - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include "imfs.h" - -/* - * IMFS_freenodinfo - * - * This routine is the IMFS free node handler for the file system - * operations table. - * - * The In Memory File System keeps its nodes in memory. This routine - * is for file sytems that do not. - */ - -int IMFS_freenodinfo( - rtems_filesystem_location_info_t *pathloc /* IN */ -) -{ - return 0; -} - diff --git a/c/src/libfs/src/imfs/imfs_fsunmount.c b/c/src/libfs/src/imfs/imfs_fsunmount.c deleted file mode 100644 index 3425d6cfa2..0000000000 --- a/c/src/libfs/src/imfs/imfs_fsunmount.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * IMFS Initialization - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for mkdir */ -#include -#include -#include - -#include - -#include "imfs.h" -#include - -#if defined(IMFS_DEBUG) -#include -#endif - -/* - * IMFS_fsunmount - */ - -#define jnode_get_control( jnode ) \ - (&jnode->info.directory.Entries) - -#define jnode_has_no_children( jnode ) \ - Chain_Is_empty( jnode_get_control( jnode ) ) - -#define jnode_has_children( jnode ) \ - ( ! jnode_has_no_children( jnode ) ) - -#define jnode_get_first_child( jnode ) \ - ((IMFS_jnode_t *)( Chain_Head( jnode_get_control( jnode ) )->next)) - -int IMFS_fsunmount( - rtems_filesystem_mount_table_entry_t *temp_mt_entry -) -{ - IMFS_jnode_t *jnode; - IMFS_jnode_t *next; - rtems_filesystem_location_info_t loc; - int result = 0; - - /* - * Traverse tree that starts at the mt_fs_root and deallocate memory - * associated memory space - */ - - jnode = (IMFS_jnode_t *)temp_mt_entry->mt_fs_root.node_access; - loc = temp_mt_entry->mt_fs_root; - - /* - * Set this to null to indicate that it is being unmounted. - */ - - temp_mt_entry->mt_fs_root.node_access = NULL; - - do { - next = jnode->Parent; - loc.node_access = (void *)jnode; - IMFS_Set_handlers( &loc ); - - if ( jnode->type != IMFS_DIRECTORY ) { - result = IMFS_unlink( &loc ); - if (result != 0) - return -1; - jnode = next; - } else if ( jnode_has_no_children( jnode ) ) { - result = IMFS_unlink( &loc ); - if (result != 0) - return -1; - jnode = next; - } - if ( jnode != NULL ) { - if ( jnode->type == IMFS_DIRECTORY ) { - if ( jnode_has_children( jnode ) ) - jnode = jnode_get_first_child( jnode ); - } - } - } while (jnode != NULL); - - return 0; -} - - - - diff --git a/c/src/libfs/src/imfs/imfs_getchild.c b/c/src/libfs/src/imfs/imfs_getchild.c deleted file mode 100644 index 8b173afc91..0000000000 --- a/c/src/libfs/src/imfs/imfs_getchild.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * IMFS_find_match_in_dir() - * - * This routine returns the child name in the given directory. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include "imfs.h" - -static char dotname[2] = "."; -static char dotdotname[3] = ".."; - -IMFS_jnode_t *IMFS_find_match_in_dir( - IMFS_jnode_t *directory, - char *name -) -{ - Chain_Node *the_node; - Chain_Control *the_chain; - IMFS_jnode_t *the_jnode; - - /* - * Check for fatal errors. A NULL directory show a problem in the - * the IMFS code. - */ - - assert( directory ); - if ( !name ) - return 0; - - assert( name ); - if ( !directory ) - return 0; - - /* - * Check for "." and ".." - */ - - if ( !strcmp( name, dotname ) ) - return directory; - - if ( !strcmp( name, dotdotname ) ) - return directory->Parent; - - the_chain = &directory->info.directory.Entries; - - for ( the_node = the_chain->first; - !_Chain_Is_tail( the_chain, the_node ); - the_node = the_node->next ) { - - the_jnode = (IMFS_jnode_t *) the_node; - - if ( !strcmp( name, the_jnode->name ) ) - return the_jnode; - } - - return 0; -} diff --git a/c/src/libfs/src/imfs/imfs_gtkn.c b/c/src/libfs/src/imfs/imfs_gtkn.c deleted file mode 100644 index c5e51c182b..0000000000 --- a/c/src/libfs/src/imfs/imfs_gtkn.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * IMFS_get_token - * - * Routine to get a token (name or separator) from the path - * the length of the token is returned in token_len. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include "imfs.h" -#include - -IMFS_token_types IMFS_get_token( - const char *path, - char *token, - int *token_len -) -{ - register int i = 0; - IMFS_token_types type = IMFS_NAME; - register char c; - - /* - * Copy a name into token. (Remember NULL is a token.) - */ - c = path[i]; - while ( (!IMFS_is_separator(c)) && (i <= IMFS_NAME_MAX) ) { - - token[i] = c; - - if ( i == IMFS_NAME_MAX ) - return IMFS_INVALID_TOKEN; - - if ( !IMFS_is_valid_name_char(c) ) - type = IMFS_INVALID_TOKEN; - - c = path [++i]; - } - - /* - * Copy a seperator into token. - */ - - if ( i == 0 ) { - token[i] = c; - - if ( token[i] != '\0' ) { - i++; - type = IMFS_CURRENT_DIR; - } else { - type = IMFS_NO_MORE_PATH; - } - } else if (token[ i-1 ] != '\0') { - token[i] = '\0'; - } - - /* - * Set token_len to the number of characters copied. - */ - - *token_len = i; - - /* - * If we copied something that was not a seperator see if - * it was a special name. - */ - - if ( type == IMFS_NAME ) { - if ( strcmp( token, "..") == 0 ) - type = IMFS_UP_DIR; - else if ( strcmp( token, "." ) == 0 ) - type = IMFS_CURRENT_DIR; - } - - return type; -} diff --git a/c/src/libfs/src/imfs/imfs_handlers_device.c b/c/src/libfs/src/imfs/imfs_handlers_device.c deleted file mode 100644 index 753c7f50c4..0000000000 --- a/c/src/libfs/src/imfs/imfs_handlers_device.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Device Operations Table for the IMFS - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "imfs.h" - -/* - * Handler table for IMFS device nodes - */ - -rtems_filesystem_file_handlers_r IMFS_device_handlers = { - device_open, - device_close, - device_read, - device_write, - device_ioctl, - device_lseek, - IMFS_stat, - IMFS_fchmod, - NULL, /* ftruncate */ - NULL, /* fpathconf */ - NULL, /* fsync */ - NULL, /* fdatasync */ - NULL, /* fcntl */ - IMFS_rmnod -}; diff --git a/c/src/libfs/src/imfs/imfs_handlers_directory.c b/c/src/libfs/src/imfs/imfs_handlers_directory.c deleted file mode 100644 index 21528711a4..0000000000 --- a/c/src/libfs/src/imfs/imfs_handlers_directory.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Operations Table for Directories for the IMFS - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "imfs.h" - -/* - * Set of operations handlers for operations on directories. - */ - -rtems_filesystem_file_handlers_r IMFS_directory_handlers = { - imfs_dir_open, - imfs_dir_close, - imfs_dir_read, - NULL, /* write */ - NULL, /* ioctl */ - imfs_dir_lseek, - imfs_dir_fstat, - IMFS_fchmod, - NULL, /* ftruncate */ - NULL, /* fpathconf */ - NULL, /* fsync */ - IMFS_fdatasync, - IMFS_fcntl, - imfs_dir_rmnod -}; - diff --git a/c/src/libfs/src/imfs/imfs_handlers_link.c b/c/src/libfs/src/imfs/imfs_handlers_link.c deleted file mode 100644 index a8383db605..0000000000 --- a/c/src/libfs/src/imfs/imfs_handlers_link.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Link Operations Table for the IMFS - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "imfs.h" - -/* - * Handler table for IMFS device nodes - */ - -rtems_filesystem_file_handlers_r IMFS_link_handlers = { - NULL, /* open */ - NULL, /* close */ - NULL, /* read */ - NULL, /* write */ - NULL, /* ioctl */ - NULL, /* lseek */ - IMFS_stat, /* stat */ - NULL, /* fchmod */ - NULL, /* ftruncate */ - NULL, /* fpathconf */ - NULL, /* fsync */ - NULL, /* fdatasync */ - NULL, /* fcntl */ - IMFS_rmnod -}; diff --git a/c/src/libfs/src/imfs/imfs_handlers_memfile.c b/c/src/libfs/src/imfs/imfs_handlers_memfile.c deleted file mode 100644 index 4458d09dc9..0000000000 --- a/c/src/libfs/src/imfs/imfs_handlers_memfile.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Memfile Operations Tables for the IMFS - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "imfs.h" - -/* - * Set of operations handlers for operations on memfile entities. - */ - -rtems_filesystem_file_handlers_r IMFS_linearfile_handlers = { - memfile_open, - memfile_close, - memfile_read, - NULL, /* write */ - memfile_ioctl, - memfile_lseek, - IMFS_stat, - IMFS_fchmod, - NULL, /* ftruncate */ - NULL, /* fpathconf */ - IMFS_fdatasync, /* fsync */ - IMFS_fdatasync, - IMFS_fcntl, - memfile_rmnod -}; - -rtems_filesystem_file_handlers_r IMFS_memfile_handlers = { - memfile_open, - memfile_close, - memfile_read, - memfile_write, - memfile_ioctl, - memfile_lseek, - IMFS_stat, - IMFS_fchmod, - memfile_ftruncate, - NULL, /* fpathconf */ - IMFS_fdatasync, /* fsync */ - IMFS_fdatasync, - IMFS_fcntl, - memfile_rmnod -}; diff --git a/c/src/libfs/src/imfs/imfs_init.c b/c/src/libfs/src/imfs/imfs_init.c deleted file mode 100644 index 01f02ae406..0000000000 --- a/c/src/libfs/src/imfs/imfs_init.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * IMFS Initialization - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for mkdir */ -#include -#include -#include - -#include - -#include "imfs.h" -#include - -#if defined(IMFS_DEBUG) -#include -#endif - -/* - * IMFS file system operations table - */ - -rtems_filesystem_operations_table IMFS_ops = { - IMFS_eval_path, - IMFS_evaluate_for_make, - IMFS_link, - IMFS_unlink, - IMFS_node_type, - IMFS_mknod, - IMFS_chown, - IMFS_freenodinfo, - IMFS_mount, - IMFS_initialize, - IMFS_unmount, - IMFS_fsunmount, - IMFS_utime, - IMFS_evaluate_link, - IMFS_symlink, - IMFS_readlink -}; - -/* - * IMFS_initialize - */ - -int IMFS_initialize( - rtems_filesystem_mount_table_entry_t *temp_mt_entry -) -{ - IMFS_initialize_support( - temp_mt_entry, - &IMFS_ops, - &IMFS_linearfile_handlers, - &IMFS_memfile_handlers, - &IMFS_directory_handlers - ); - return 0; -} diff --git a/c/src/libfs/src/imfs/imfs_initsupp.c b/c/src/libfs/src/imfs/imfs_initsupp.c deleted file mode 100644 index bf0cb8ccdc..0000000000 --- a/c/src/libfs/src/imfs/imfs_initsupp.c +++ /dev/null @@ -1,88 +0,0 @@ -/* - * IMFS Initialization - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for mkdir */ -#include -#include -#include - -#include - -#include "imfs.h" -#include - -#if defined(IMFS_DEBUG) -#include -#endif - -/* - * IMFS_initialize - */ - -int IMFS_initialize_support( - rtems_filesystem_mount_table_entry_t *temp_mt_entry, - rtems_filesystem_operations_table *op_table, - rtems_filesystem_file_handlers_r *linearfile_handlers, - rtems_filesystem_file_handlers_r *memfile_handlers, - rtems_filesystem_file_handlers_r *directory_handlers -) -{ - IMFS_fs_info_t *fs_info; - IMFS_jnode_t *jnode; - - /* - * Create the root node - * - * NOTE: UNIX root is 755 and owned by root/root (0/0). - */ - - temp_mt_entry->mt_fs_root.node_access = IMFS_create_node( - NULL, - IMFS_DIRECTORY, - "", - ( S_IFDIR | 0755 ), - NULL - ); - - temp_mt_entry->mt_fs_root.handlers = directory_handlers; - temp_mt_entry->mt_fs_root.ops = op_table; - temp_mt_entry->pathconf_limits_and_options = IMFS_LIMITS_AND_OPTIONS; - - /* - * Create custom file system data. - */ - fs_info = calloc( 1, sizeof( IMFS_fs_info_t ) ); - if ( !fs_info ){ - free(temp_mt_entry->mt_fs_root.node_access); - return 1; - } - temp_mt_entry->fs_info = fs_info; - - /* - * Set st_ino for the root to 1. - */ - - fs_info->ino_count = 1; - fs_info->linearfile_handlers = linearfile_handlers; - fs_info->memfile_handlers = memfile_handlers; - fs_info->directory_handlers = directory_handlers; - - jnode = temp_mt_entry->mt_fs_root.node_access; - jnode->st_ino = fs_info->ino_count; - - return 0; -} diff --git a/c/src/libfs/src/imfs/imfs_link.c b/c/src/libfs/src/imfs/imfs_link.c deleted file mode 100644 index 610c3cb831..0000000000 --- a/c/src/libfs/src/imfs/imfs_link.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * IMFS_link - * - * The following rouine creates a new link node under parent with the - * name given in name. The link node is set to point to the node at - * to_loc. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "imfs.h" -#include -#include - -int IMFS_link( - rtems_filesystem_location_info_t *to_loc, /* IN */ - rtems_filesystem_location_info_t *parent_loc, /* IN */ - const char *token /* IN */ -) -{ - IMFS_types_union info; - IMFS_jnode_t *new_node; - char new_name[ IMFS_NAME_MAX + 1 ]; - int i; - - /* - * Verify this node can be linked to. - */ - - info.hard_link.link_node = to_loc->node_access; - if ( info.hard_link.link_node->st_nlink >= LINK_MAX ) - rtems_set_errno_and_return_minus_one( EMLINK ); - - /* - * Remove any separators at the end of the string. - */ - - IMFS_get_token( token, new_name, &i ); - - /* - * Create a new link node. - */ - - new_node = IMFS_create_node( - parent_loc, - IMFS_HARD_LINK, - new_name, - ( S_IFLNK | ( S_IRWXU | S_IRWXG | S_IRWXO )), - &info - ); - - if ( !new_node ) - rtems_set_errno_and_return_minus_one( ENOMEM ); - - /* - * Increment the link count of the node being pointed to. - */ - - info.hard_link.link_node->st_nlink++; - IMFS_update_ctime( info.hard_link.link_node ); - - return 0; -} - diff --git a/c/src/libfs/src/imfs/imfs_load_tar.c b/c/src/libfs/src/imfs/imfs_load_tar.c deleted file mode 100644 index afbf2b0291..0000000000 --- a/c/src/libfs/src/imfs/imfs_load_tar.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -/************************************************************************** - * This file implements the "mount" procedure for tar-based IMFS - * extensions. The TAR is not actually mounted under the IMFS. - * Directories from the TAR file are created as usual in the IMFS. - * File entries are created as IMFS_LINEAR_FILE nodes with their nods - * pointing to addresses in the TAR image. - *************************************************************************/ - -#include -#include -#include - -#include - -#include -#include -#include -#include - - -/************************************************************************** - * TAR file format: - * - * Offset Length Contents - * 0 100 bytes File name ('\0' terminated, 99 maxmum length) - * 100 8 bytes File mode (in octal ascii) - * 108 8 bytes User ID (in octal ascii) - * 116 8 bytes Group ID (in octal ascii) - * 124 12 bytes File size (s) (in octal ascii) - * 136 12 bytes Modify time (in octal ascii) - * 148 8 bytes Header checksum (in octal ascii) - * 156 1 bytes Link flag - * 157 100 bytes Linkname ('\0' terminated, 99 maxmum length) - * 257 8 bytes Magic ("ustar \0") - * 265 32 bytes User name ('\0' terminated, 31 maxmum length) - * 297 32 bytes Group name ('\0' terminated, 31 maxmum length) - * 329 8 bytes Major device ID (in octal ascii) - * 337 8 bytes Minor device ID (in octal ascii) - * 345 167 bytes Padding - * 512 (s+p)bytes File contents (s+p) := (((s) + 511) & ~511), - * round up to 512 bytes - * - * Checksum: - * int i, sum; - * char* header = tar_header_pointer; - * sum = 0; - * for(i = 0; i < 512; i++) - * sum += 0xFF & header[i]; - *************************************************************************/ - -#define LF_OLDNORMAL '\0' /* Normal disk file, Unix compatible */ -#define LF_NORMAL '0' /* Normal disk file */ -#define LF_LINK '1' /* Link to previously dumped file */ -#define LF_SYMLINK '2' /* Symbolic link */ -#define LF_CHR '3' /* Character special file */ -#define LF_BLK '4' /* Block special file */ -#define LF_DIR '5' /* Directory */ -#define LF_FIFO '6' /* FIFO special file */ -#define LF_CONFIG '7' /* Contiguous file */ - -#define MAX_NAME_FIELD_SIZE 99 - -#define MIN(a,b) ((a)>(b)?(b):(a)) - -static unsigned long octal2ulong(char *octascii, int len); -static int compute_tar_header_checksum(char *bufr); - -/************************************************************************** - * rtems_tarfs_load - * - * Here we create the mountpoint directory and load the tarfs at - * that node. Once the IMFS has been mounted, we work through the - * tar image and perform as follows: - * - For directories, simply call mkdir(). The IMFS creates nodes as - * needed. - * - For files, we make our own calls to IMFS eval_for_make and - * create_node. - *************************************************************************/ -int -rtems_tarfs_load(char *mountpoint, - unsigned char *tar_image, - unsigned long tar_size) -{ - rtems_filesystem_location_info_t root_loc; - rtems_filesystem_location_info_t loc; - char *hdr_ptr; - char filename[100]; - char full_filename[256]; - int hdr_chksum; - unsigned char linkflag; - unsigned long file_size; - unsigned long file_mode; - int offset; - unsigned long nblocks; - IMFS_jnode_t *node; - int status; - - - status = rtems_filesystem_evaluate_path(mountpoint, 0, &root_loc, 0); - if (status != 0) - return(-1); - - if (root_loc.ops != &IMFS_ops) - return(-1); - - /*********************************************************************** - * Create an IMFS node structure pointing to tar image memory. - **********************************************************************/ - offset = 0; - while (1) - { - if (offset + 512 > tar_size) - break; - - /****************************************************************** - * Read a header. - ******************************************************************/ - hdr_ptr = &tar_image[offset]; - offset += 512; - if (strncmp(&hdr_ptr[257], "ustar ", 7)) - break; - - strncpy(filename, hdr_ptr, MAX_NAME_FIELD_SIZE); - filename[MAX_NAME_FIELD_SIZE] = '\0'; - - linkflag = hdr_ptr[156]; - file_mode = octal2ulong(&hdr_ptr[100], 8); - file_size = octal2ulong(&hdr_ptr[124], 12); - hdr_chksum = (int)octal2ulong(&hdr_ptr[148], 8); - - if (compute_tar_header_checksum(hdr_ptr) != hdr_chksum) - break; - - /****************************************************************** - * Generate an IMFS node depending on the file type. - * - For directories, just create directories as usual. IMFS - * will take care of the rest. - * - For files, create a file node with special tarfs properties. - *****************************************************************/ - if (linkflag == LF_DIR) - { - strcpy(full_filename, mountpoint); - if (full_filename[strlen(full_filename)-1] != '/') - strcat(full_filename, "/"); - strcat(full_filename, filename); - mkdir(full_filename, S_IRWXU | S_IRWXG | S_IRWXO); - } - /****************************************************************** - * Create a LINEAR_FILE node if no user write permission. - *****************************************************************/ - else if ((linkflag == LF_NORMAL) && - ((file_mode & 0200) == 0000)) - { - const char *name; - - loc = root_loc; - if (IMFS_evaluate_for_make(filename, &loc, &name) == 0) - { - node = IMFS_create_node(&loc, - IMFS_LINEAR_FILE, (char *)name, - (S_IRUSR | S_IRGRP | S_IROTH) | S_IFREG, - NULL); - node->info.linearfile.size = file_size; - node->info.linearfile.direct = &tar_image[offset]; - } - - nblocks = (((file_size) + 511) & ~511) / 512; - offset += 512 * nblocks; - } - /****************************************************************** - * Create a regular MEMORY_FILE if write permission exists. - *****************************************************************/ - else if ((linkflag == LF_NORMAL) && - ((file_mode & 0200) == 0200)) - { - int fd; - int n, left, ptr; - - strcpy(full_filename, mountpoint); - if (full_filename[strlen(full_filename)-1] != '/') - strcat(full_filename, "/"); - strcat(full_filename, filename); - - fd = creat(full_filename, S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP); - if (fd != -1) - { - left = file_size; - ptr = offset; - while ((n = write(fd, &tar_image[ptr], left)) > 0) - { - left -= n; - ptr += n; - } - close(fd); - } - - nblocks = (((file_size) + 511) & ~511) / 512; - offset += 512 * nblocks; - } - } - - return(status); -} - -/************************************************************************** - * This converts octal ASCII number representations into an - * unsigned long. Only support 32-bit numbers for now. - *************************************************************************/ -static unsigned long -octal2ulong(char *octascii, int len) -{ - int i; - unsigned long num; - unsigned long mult; - - num = 0; - mult = 1; - for (i=len-1; i>=0; i--) - { - if (octascii[i] < '0') - continue; - if (octascii[i] > '9') - continue; - - num += mult*((unsigned long)(octascii[i] - '0')); - mult *= 8; - } - return(num); -} - - -/************************************************************************ - * Compute the TAR checksum and check with the value in - * the archive. The checksum is computed over the entire - * header, but the checksum field is substituted with blanks. - ************************************************************************/ -static int -compute_tar_header_checksum(char *bufr) -{ - int i, sum; - - - sum = 0; - for (i=0; i<512; i++) - { - if ((i >= 148) && (i < 156)) - sum += 0xff & ' '; - else - sum += 0xff & bufr[i]; - } - return(sum); -} diff --git a/c/src/libfs/src/imfs/imfs_mknod.c b/c/src/libfs/src/imfs/imfs_mknod.c deleted file mode 100644 index 670f71fe7d..0000000000 --- a/c/src/libfs/src/imfs/imfs_mknod.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * IMFS_mknod - * - * Routine to create a node in the IMFS file system. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include - -#include "imfs.h" -#include -#include - -int IMFS_mknod( - const char *token, /* IN */ - mode_t mode, /* IN */ - dev_t dev, /* IN */ - rtems_filesystem_location_info_t *pathloc /* IN/OUT */ -) -{ - IMFS_token_types type = 0; - IMFS_jnode_t *new_node; - int result; - char new_name[ IMFS_NAME_MAX + 1 ]; - IMFS_types_union info; - - IMFS_get_token( token, new_name, &result ); - - /* - * Figure out what type of IMFS node this is. - */ - - if ( S_ISDIR(mode) ) - type = IMFS_DIRECTORY; - else if ( S_ISREG(mode) ) - type = IMFS_MEMORY_FILE; - else if ( S_ISBLK(mode) || S_ISCHR(mode) ) { - type = IMFS_DEVICE; - rtems_filesystem_split_dev_t( dev, info.device.major, info.device.minor ); - } else { - rtems_set_errno_and_return_minus_one( EINVAL ); - } - - /* - * Allocate and fill in an IMFS jnode - */ - - new_node = IMFS_create_node( - pathloc, - type, - new_name, - mode, - &info - ); - - if ( !new_node ) - rtems_set_errno_and_return_minus_one( ENOMEM ); - - return 0; -} - diff --git a/c/src/libfs/src/imfs/imfs_mount.c b/c/src/libfs/src/imfs/imfs_mount.c deleted file mode 100644 index 1674d9a60d..0000000000 --- a/c/src/libfs/src/imfs/imfs_mount.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * IMFS_mount - * - * This routine will look at a mount table entry that we are going to - * add to the mount table. If the mount point rtems_filesystem - * location_info_t struct refers to a node that is a directory, - * the node will be marked as a mount point by setting its directory.mt_fs - * pointer to point to the mount table entry that we are about to add - * to the mount table chain. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "imfs.h" -#include -#include - -int IMFS_mount( - rtems_filesystem_mount_table_entry_t *mt_entry -) -{ - IMFS_jnode_t *node; - - node = mt_entry->mt_point_node.node_access; - - /* - * Is the node that we are mounting onto a directory node ? - */ - - if ( node->type != IMFS_DIRECTORY ) - rtems_set_errno_and_return_minus_one( ENOTDIR ); - - /* - * Set mt_fs pointer to point to the mount table entry for - * the mounted file system. - */ - - node->info.directory.mt_fs = mt_entry; - return 0; -} diff --git a/c/src/libfs/src/imfs/imfs_ntype.c b/c/src/libfs/src/imfs/imfs_ntype.c deleted file mode 100644 index baa69f15e4..0000000000 --- a/c/src/libfs/src/imfs/imfs_ntype.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * IMFS_node_type - * - * The following verifies that returns the type of node that the - * loc refers to. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "imfs.h" - -rtems_filesystem_node_types_t IMFS_node_type( - rtems_filesystem_location_info_t *pathloc /* IN */ -) -{ - IMFS_jnode_t *node; - - node = pathloc->node_access; - return node->type; -} diff --git a/c/src/libfs/src/imfs/imfs_readlink.c b/c/src/libfs/src/imfs/imfs_readlink.c deleted file mode 100644 index 89ef715086..0000000000 --- a/c/src/libfs/src/imfs/imfs_readlink.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * IMFS_readlink - * - * The following rouine puts the symblic links destination name into - * buff. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "imfs.h" -#include -#include - -int IMFS_readlink( - rtems_filesystem_location_info_t *loc, - char *buf, /* OUT */ - size_t bufsize -) -{ - IMFS_jnode_t *node; - int i; - - node = loc->node_access; - - if ( node->type != IMFS_SYM_LINK ) - rtems_set_errno_and_return_minus_one( EINVAL ); - - for( i=0; ((iinfo.sym_link.name[i] != '\0')); i++ ) - buf[i] = node->info.sym_link.name[i]; - - return i; -} diff --git a/c/src/libfs/src/imfs/imfs_rmnod.c b/c/src/libfs/src/imfs/imfs_rmnod.c deleted file mode 100644 index 8257ace5ca..0000000000 --- a/c/src/libfs/src/imfs/imfs_rmnod.c +++ /dev/null @@ -1,82 +0,0 @@ -/* - * IMFS Node Removal Handler - * - * This file contains the handler used to remove a node when a file type - * does not require special actions. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include -#include - -#include "imfs.h" - -/* - * IMFS_rmnod - */ - -int IMFS_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = (IMFS_jnode_t *) pathloc->node_access; - - /* - * Take the node out of the parent's chain that contains this node - */ - - if ( the_jnode->Parent != NULL ) { - Chain_Extract( (Chain_Node *) the_jnode ); - the_jnode->Parent = NULL; - } - - /* - * Decrement the link counter and see if we can free the space. - */ - - the_jnode->st_nlink--; - IMFS_update_ctime( the_jnode ); - - /* - * The file cannot be open and the link must be less than 1 to free. - */ - - if ( !rtems_libio_is_file_open( the_jnode ) && (the_jnode->st_nlink < 1) ) { - - /* - * Is rtems_filesystem_current this node? - */ - - if ( rtems_filesystem_current.node_access == pathloc->node_access ) - rtems_filesystem_current.node_access = NULL; - - /* - * Free memory associated with a memory file. - */ - - free( the_jnode ); - } - - return 0; - -} - - - diff --git a/c/src/libfs/src/imfs/imfs_stat.c b/c/src/libfs/src/imfs/imfs_stat.c deleted file mode 100644 index bd1e319d0b..0000000000 --- a/c/src/libfs/src/imfs/imfs_stat.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - * IMFS_stat - * - * This routine provides a stat for the IMFS file system. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "imfs.h" -#include -#include - -int IMFS_stat( - rtems_filesystem_location_info_t *loc, - struct stat *buf -) -{ - IMFS_jnode_t *the_jnode; - IMFS_device_t *io; - - the_jnode = loc->node_access; - - - switch ( the_jnode->type ) { - - case IMFS_DEVICE: - io = &the_jnode->info.device; - buf->st_dev = rtems_filesystem_make_dev_t( io->major, io->minor ); - break; - - case IMFS_LINEAR_FILE: - case IMFS_MEMORY_FILE: - buf->st_size = the_jnode->info.file.size; - break; - - case IMFS_SYM_LINK: - buf->st_size = 0; - break; - - default: - rtems_set_errno_and_return_minus_one( ENOTSUP ); - break; - } - - buf->st_mode = the_jnode->st_mode; - buf->st_nlink = the_jnode->st_nlink; - buf->st_ino = the_jnode->st_ino; - buf->st_uid = the_jnode->st_uid; - buf->st_gid = the_jnode->st_gid; - - buf->st_atime = the_jnode->stat_atime; - buf->st_mtime = the_jnode->stat_mtime; - buf->st_ctime = the_jnode->stat_ctime; - - return 0; -} diff --git a/c/src/libfs/src/imfs/imfs_symlink.c b/c/src/libfs/src/imfs/imfs_symlink.c deleted file mode 100644 index 5a062f3439..0000000000 --- a/c/src/libfs/src/imfs/imfs_symlink.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * IMFS_symlink - * - * The following rouine creates a new symbolic link node under parent - * with the name given in name. The node is set to point to the node at - * to_loc. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include "imfs.h" -#include -#include - -int IMFS_symlink( - rtems_filesystem_location_info_t *parent_loc, - const char *link_name, - const char *node_name -) -{ - IMFS_types_union info; - IMFS_jnode_t *new_node; - char new_name[ IMFS_NAME_MAX + 1 ]; - int i; - - /* - * Remove any separators at the end of the string. - */ - - IMFS_get_token( node_name, new_name, &i ); - - info.sym_link.name = link_name; - - /* - * Create a new link node. - */ - - new_node = IMFS_create_node( - parent_loc, - IMFS_SYM_LINK, - new_name, - ( S_IFLNK | ( S_IRWXU | S_IRWXG | S_IRWXO )), - &info - ); - - if ( !new_node ) - rtems_set_errno_and_return_minus_one( ENOMEM ); - - return 0; -} - - diff --git a/c/src/libfs/src/imfs/imfs_unixstub.c b/c/src/libfs/src/imfs/imfs_unixstub.c deleted file mode 100644 index 3af9cee647..0000000000 --- a/c/src/libfs/src/imfs/imfs_unixstub.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * IMFS Stub for UNIX configuration - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for mkdir */ -#include -#include -#include - -#include - -#include "imfs.h" -#include - -#include - -/* - * IMFS file system operations table - */ - -rtems_filesystem_operations_table IMFS_ops = { - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL -}; - -/* - * IMFS file system operations table - */ - -rtems_filesystem_operations_table miniIMFS_ops = { - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL, - NULL -}; diff --git a/c/src/libfs/src/imfs/imfs_unlink.c b/c/src/libfs/src/imfs/imfs_unlink.c deleted file mode 100644 index 9e0861b53a..0000000000 --- a/c/src/libfs/src/imfs/imfs_unlink.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * IMFS_unlink - * - * Routine to remove a link node from the tree. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include "imfs.h" -#include -#include - -int IMFS_unlink( - rtems_filesystem_location_info_t *loc /* IN */ -) -{ - IMFS_jnode_t *node; - rtems_filesystem_location_info_t the_link; - int result = 0; - - node = loc->node_access; - - /* - * Decrement the link counter of node pointed to and free the - * space. - */ - - /* - * If this is the last last pointer to the node - * free the node. - */ - - if ( node->type == IMFS_HARD_LINK ) { - - if ( !node->info.hard_link.link_node ) - rtems_set_errno_and_return_minus_one( EINVAL ); - - the_link = *loc; - the_link.node_access = node->info.hard_link.link_node; - IMFS_Set_handlers( &the_link ); - - /* - * If removing the last hard link to a node, then we need - * to remove the node that is a link and the node itself. - */ - - node->info.hard_link.link_node->st_nlink --; - IMFS_update_ctime( node->info.hard_link.link_node ); - if ( node->info.hard_link.link_node->st_nlink < 1) { - result = (*the_link.handlers->rmnod_h)( &the_link ); - if ( result != 0 ) - return -1; - } - } - - /* - * Now actually free the node we were asked to free. - */ - - result = (*loc->handlers->rmnod_h)( loc ); - - return result; -} - diff --git a/c/src/libfs/src/imfs/imfs_unmount.c b/c/src/libfs/src/imfs/imfs_unmount.c deleted file mode 100644 index ea40def946..0000000000 --- a/c/src/libfs/src/imfs/imfs_unmount.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * IMFS_unmount - * - * This routine will look at a mount table entry that we are going to - * add to the mount table. If the mount point - * rtems_filesystem_location_info_t struct refers to a node that is a - * directory that has a file system mounted on it, the node will be - * marked as a mount point by * setting its directory.mt_fs pointer - * to NULL. This indicates that a directory is no longer mounted on - * this node. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include "imfs.h" -#include -#include - -int IMFS_unmount( - rtems_filesystem_mount_table_entry_t *mt_entry -) -{ - IMFS_jnode_t *node; - - node = mt_entry->mt_point_node.node_access; - - /* - * Is the node that we are mounting onto a directory node ? - */ - - if ( node->type != IMFS_DIRECTORY ) - rtems_set_errno_and_return_minus_one( ENOTDIR ); - - /* - * Did the node indicate that there was a directory mounted here? - */ - - if ( node->info.directory.mt_fs == NULL ) - rtems_set_errno_and_return_minus_one( EINVAL ); /* XXX */ - - /* - * Set the mt_fs pointer to indicate that there is no longer - * a file system mounted to this point. - */ - - node->info.directory.mt_fs = NULL; - - return 0; -} diff --git a/c/src/libfs/src/imfs/imfs_utime.c b/c/src/libfs/src/imfs/imfs_utime.c deleted file mode 100644 index 2000d8791e..0000000000 --- a/c/src/libfs/src/imfs/imfs_utime.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * IMFS_utime - * - * This routine is the implementation of the utime() system - * call for the IMFS. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include -#include "imfs.h" - -int IMFS_utime( - rtems_filesystem_location_info_t *pathloc, /* IN */ - time_t actime, /* IN */ - time_t modtime /* IN */ -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = (IMFS_jnode_t *) pathloc->node_access; - - the_jnode->stat_atime = actime; - the_jnode->stat_mtime = modtime; - - return 0; -} diff --git a/c/src/libfs/src/imfs/ioman.c b/c/src/libfs/src/imfs/ioman.c deleted file mode 100644 index ffddc89928..0000000000 --- a/c/src/libfs/src/imfs/ioman.c +++ /dev/null @@ -1,110 +0,0 @@ -/* - * This file emulates the old Classic RTEMS IO manager directives - * which register and lookup names using the in-memory filesystem. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include "imfs.h" - -#if defined(__linux__) -#define S_IFCHR __S_IFCHR -#endif - -/* - * rtems_io_register_name - * - * This assumes that all registered devices are character devices. - */ - -rtems_status_code rtems_io_register_name( - char *device_name, - rtems_device_major_number major, - rtems_device_minor_number minor -) -{ -#if !defined(RTEMS_UNIX) - int status; - dev_t dev; - - dev = rtems_filesystem_make_dev_t( major, minor ); - status = mknod( device_name, 0777 | S_IFCHR, dev ); - - /* this is the only error returned by the old version */ - if ( status ) - return RTEMS_TOO_MANY; - -#endif - return RTEMS_SUCCESSFUL; -} - -/* - * rtems_io_lookup_name - * - * This version is not reentrant. - * - * XXX - This is dependent upon IMFS and should not be. - * Suggest adding a filesystem routine to fill in the device_info. - */ - -rtems_status_code rtems_io_lookup_name( - const char *name, - rtems_driver_name_t **device_info -) -{ -#if !defined(RTEMS_UNIX) - IMFS_jnode_t *the_jnode; - rtems_filesystem_location_info_t loc; - static rtems_driver_name_t device; - int result; - rtems_filesystem_node_types_t node_type; - - result = rtems_filesystem_evaluate_path( name, 0x00, &loc, TRUE ); - the_jnode = loc.node_access; - - if ( !loc.ops->node_type_h ) { - rtems_filesystem_freenode( &loc ); - rtems_set_errno_and_return_minus_one( ENOTSUP ); - } - - node_type = (*loc.ops->node_type_h)( &loc ); - - if ( (result != 0) || node_type != RTEMS_FILESYSTEM_DEVICE ) { - *device_info = 0; - rtems_filesystem_freenode( &loc ); - return RTEMS_UNSATISFIED; - } - - device.device_name = (char *) name; - device.device_name_length = strlen( name ); - device.major = the_jnode->info.device.major; - device.minor = the_jnode->info.device.minor; - *device_info = &device; - - rtems_filesystem_freenode( &loc ); - -#endif - return RTEMS_SUCCESSFUL; -} diff --git a/c/src/libfs/src/imfs/linearfile.c b/c/src/libfs/src/imfs/linearfile.c deleted file mode 100644 index 3d6593dfce..0000000000 --- a/c/src/libfs/src/imfs/linearfile.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * IMFS Linear File Handlers - * - * This file contains the set of handlers used to process operations on - * IMFS linear memory file nodes. Linear memory files are contiguous - * blocks of memory created from a TAR or other filesystem image. - * The blocks are nonwriteable and nonresizeable. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -#include -#include -#include "imfs.h" -#include -#include - -/* - * linearfile_read - * - * This routine processes the read() system call. - */ - -int linearfile_read( - rtems_libio_t *iop, - void *buffer, - unsigned32 count -) -{ - IMFS_jnode_t *the_jnode; - unsigned char *dest; - unsigned char *file_ptr; - int file_offset; - - - the_jnode = iop->file_info; - - /* - * Perform internal consistency checks - */ - - assert( the_jnode ); - if ( !the_jnode ) - rtems_set_errno_and_return_minus_one( EIO ); - - assert( the_jnode->type == IMFS_LINEAR_FILE ); - if ( the_jnode->type != IMFS_LINEAR_FILE ) - rtems_set_errno_and_return_minus_one( EIO ); - - /* - * Error checks on arguments - */ - - dest = (unsigned char *)buffer; - assert( dest ); - if ( !dest ) - rtems_set_errno_and_return_minus_one( EINVAL ); - - /* - * Perform a simple memory copy. - */ - - if (count == 0) - return(0); - - the_jnode = iop->file_info; - file_ptr = (unsigned char *)the_jnode->info.linearfile.direct; - file_offset = (unsigned long)iop->offset; - - if (count > (the_jnode->info.linearfile.size - file_offset)) - count = the_jnode->info.linearfile.size - file_offset; - - memcpy(dest, &file_ptr[file_offset], count); - - return(count); -} - - -/* - * linearfile_lseek - * - * This routine processes the lseek() system call. - */ - -int linearfile_lseek( - rtems_libio_t *iop, - off_t offset, - int whence -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = iop->file_info; - - if (iop->offset > the_jnode->info.linearfile.size) - iop->offset = the_jnode->info.linearfile.size; - - return iop->offset; -} - diff --git a/c/src/libfs/src/imfs/memfile.c b/c/src/libfs/src/imfs/memfile.c deleted file mode 100644 index cfa37c20c6..0000000000 --- a/c/src/libfs/src/imfs/memfile.c +++ /dev/null @@ -1,1137 +0,0 @@ -/* - * IMFS Device Node Handlers - * - * This file contains the set of handlers used to process operations on - * IMFS memory file nodes. The memory files are created in memory using - * malloc'ed memory. Thus any data stored in one of these files is lost - * at system shutdown unless special arrangements to copy the data to - * some type of non-volailte storage are made by the application. - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -#include -#include -#include "imfs.h" -#include -#include - -#define MEMFILE_STATIC - -/* - * Prototypes of private routines - */ - -MEMFILE_STATIC int IMFS_memfile_extend( - IMFS_jnode_t *the_jnode, - off_t new_length -); - -MEMFILE_STATIC int IMFS_memfile_addblock( - IMFS_jnode_t *the_jnode, - unsigned int block -); - -MEMFILE_STATIC int IMFS_memfile_remove_block( - IMFS_jnode_t *the_jnode, - unsigned int block -); - -MEMFILE_STATIC block_p *IMFS_memfile_get_block_pointer( - IMFS_jnode_t *the_jnode, - unsigned int block, - int malloc_it -); - -MEMFILE_STATIC int IMFS_memfile_read( - IMFS_jnode_t *the_jnode, - off_t start, - unsigned char *destination, - unsigned int length -); - -MEMFILE_STATIC int IMFS_memfile_write( - IMFS_jnode_t *the_jnode, - off_t start, - const unsigned char *source, - unsigned int length -); - -void *memfile_alloc_block(void); - -void memfile_free_block( - void *memory -); - -/* - * memfile_open - * - * This routine processes the open() system call. Note that there is - * nothing special to be done at open() time. - */ - -int memfile_open( - rtems_libio_t *iop, - const char *pathname, - unsigned32 flag, - unsigned32 mode -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = iop->file_info; - - if (iop->flags & LIBIO_FLAGS_APPEND) - iop->offset = the_jnode->info.file.size; - - iop->size = the_jnode->info.file.size; - return 0; -} - -/* - * memfile_close - * - * This routine processes the close() system call. Note that there is - * nothing to flush or memory to free at this point. - */ - -int memfile_close( - rtems_libio_t *iop -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = iop->file_info; - - if (iop->flags & LIBIO_FLAGS_APPEND) - iop->offset = the_jnode->info.file.size; - - return 0; -} - -/* - * memfile_read - * - * This routine processes the read() system call. - */ - -int memfile_read( - rtems_libio_t *iop, - void *buffer, - unsigned32 count -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = iop->file_info; - - return IMFS_memfile_read( the_jnode, iop->offset, buffer, count ); -} - -/* - * memfile_write - * - * This routine processes the write() system call. - */ - -int memfile_write( - rtems_libio_t *iop, - const void *buffer, - unsigned32 count -) -{ - IMFS_jnode_t *the_jnode; - int status; - - the_jnode = iop->file_info; - - status = IMFS_memfile_write( the_jnode, iop->offset, buffer, count ); - iop->size = the_jnode->info.file.size; - - return status; -} - -/* - * memfile_ioctl - * - * This routine processes the ioctl() system call. - * - * NOTE: No ioctl()'s are supported for in-memory files. - */ - -int memfile_ioctl( - rtems_libio_t *iop, - unsigned32 command, - void *buffer -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = iop->file_info; - - return 0; -} - -/* - * memfile_lseek - * - * This routine processes the lseek() system call. - */ - -int memfile_lseek( - rtems_libio_t *iop, - off_t offset, - int whence -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = iop->file_info; - - if (the_jnode->type == IMFS_LINEAR_FILE) { - if (iop->offset > the_jnode->info.linearfile.size) - iop->offset = the_jnode->info.linearfile.size; - } - else { /* Must be a block file (IMFS_MEMORY_FILE). */ - if (IMFS_memfile_extend( the_jnode, iop->offset )) - rtems_set_errno_and_return_minus_one( ENOSPC ); - - iop->size = the_jnode->info.file.size; - } - return iop->offset; -} - -/* - * memfile_stat - * - * This IMFS_stat() can be used. - */ - -/* - * memfile_ftruncate - * - * This routine processes the ftruncate() system call. - */ - -int memfile_ftruncate( - rtems_libio_t *iop, - off_t length -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = iop->file_info; - - /* - * POSIX 1003.1b does not specify what happens if you truncate a file - * and the new length is greater than the current size. We treat this - * as an extend operation. - */ - - if ( length > the_jnode->info.file.size ) - return IMFS_memfile_extend( the_jnode, length ); - - /* - * The in-memory files do not currently reclaim memory until the file is - * deleted. So we leave the previously allocated blocks in place for - * future use and just set the length. - */ - - the_jnode->info.file.size = length; - iop->size = the_jnode->info.file.size; - - IMFS_update_atime( the_jnode ); - - return 0; -} - -/* - * IMFS_memfile_extend - * - * This routine insures that the in-memory file is of the length - * specified. If necessary, it will allocate memory blocks to - * extend the file. - */ - -MEMFILE_STATIC int IMFS_memfile_extend( - IMFS_jnode_t *the_jnode, - off_t new_length -) -{ - unsigned int block; - unsigned int new_blocks; - unsigned int old_blocks; - - /* - * Perform internal consistency checks - */ - - assert( the_jnode ); - if ( !the_jnode ) - rtems_set_errno_and_return_minus_one( EIO ); - - assert( the_jnode->type == IMFS_MEMORY_FILE ); - if ( the_jnode->type != IMFS_MEMORY_FILE ) - rtems_set_errno_and_return_minus_one( EIO ); - - if ( new_length >= IMFS_MEMFILE_MAXIMUM_SIZE ) - rtems_set_errno_and_return_minus_one( EINVAL ); - - if ( new_length <= the_jnode->info.file.size ) - return 0; - - /* - * Calculate the number of range of blocks to allocate - */ - - new_blocks = new_length / IMFS_MEMFILE_BYTES_PER_BLOCK; - old_blocks = the_jnode->info.file.size / IMFS_MEMFILE_BYTES_PER_BLOCK; - - /* - * Now allocate each of those blocks. - */ - - for ( block=old_blocks ; block<=new_blocks ; block++ ) { - if ( IMFS_memfile_addblock( the_jnode, block ) ) { - for ( ; block>=old_blocks ; block-- ) { - IMFS_memfile_remove_block( the_jnode, block ); - } - rtems_set_errno_and_return_minus_one( ENOSPC ); - } - } - - /* - * Set the new length of the file. - */ - - the_jnode->info.file.size = new_length; - return 0; -} - -/* - * IMFS_memfile_addblock - * - * This routine adds a single block to the specified in-memory file. - */ - -MEMFILE_STATIC int IMFS_memfile_addblock( - IMFS_jnode_t *the_jnode, - unsigned int block -) -{ - block_p memory; - block_p *block_entry_ptr; - - assert( the_jnode ); - if ( !the_jnode ) - rtems_set_errno_and_return_minus_one( EIO ); - - assert( the_jnode->type == IMFS_MEMORY_FILE ); - if ( the_jnode->type != IMFS_MEMORY_FILE ) - rtems_set_errno_and_return_minus_one( EIO ); - - block_entry_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 1 ); - if ( *block_entry_ptr ) - return 0; - -#if 0 - printf( "%d %p", block, block_entry_ptr ); - fflush(stdout); -#endif - - memory = memfile_alloc_block(); - if ( !memory ) - return 1; - *block_entry_ptr = memory; - - return 0; -} - -/* - * IMFS_memfile_remove_block - * - * This routine removes the specified block from the in-memory file. - * - * NOTE: This is a support routine and is called only to remove - * the last block or set of blocks in a file. Removing a - * block from the middle of a file would be exceptionally - * dangerous and the results unpredictable. - */ - -MEMFILE_STATIC int IMFS_memfile_remove_block( - IMFS_jnode_t *the_jnode, - unsigned int block -) -{ - block_p *block_entry_ptr; - block_p ptr; - - block_entry_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); - ptr = *block_entry_ptr; - *block_entry_ptr = 0; - - memfile_free_block( ptr ); - - return 1; -} - -/* - * memfile_free_blocks_in_table - * - * This is a support routine for IMFS_memfile_remove. It frees all the - * blocks in one of the indirection tables. - */ - -void memfile_free_blocks_in_table( - block_p **block_table, - int entries -) -{ - int i; - block_p *b; - - /* - * Perform internal consistency checks - */ - - assert( block_table ); - if ( !block_table ) - return; - - /* - * Now go through all the slots in the table and free the memory. - */ - - b = *block_table; - - for ( i=0 ; itype == IMFS_MEMORY_FILE ); - if ( the_jnode->type != IMFS_MEMORY_FILE ) - rtems_set_errno_and_return_minus_one( EIO ); - - /* - * Eventually this could be set smarter at each call to - * memfile_free_blocks_in_table to greatly speed this up. - */ - - to_free = IMFS_MEMFILE_BLOCK_SLOTS; - - /* - * Now start freeing blocks in this order: - * + indirect - * + doubly indirect - * + triply indirect - */ - - info = &the_jnode->info.file; - - if ( info->indirect ) { - memfile_free_blocks_in_table( &info->indirect, to_free ); - } - - if ( info->doubly_indirect ) { - - for ( i=0 ; idoubly_indirect[i] ) { - memfile_free_blocks_in_table( - (block_p **)&info->doubly_indirect[i], to_free ); - } - } - memfile_free_blocks_in_table( &info->doubly_indirect, to_free ); - - } - - if ( info->triply_indirect ) { - for ( i=0 ; itriply_indirect[i]; - if ( !p ) /* ensure we have a valid pointer */ - break; - for ( j=0 ; jtriply_indirect[i], to_free ); - } - memfile_free_blocks_in_table( - (block_p **)&info->triply_indirect, to_free ); - } - - return 0; -} - -/* - * IMFS_memfile_read - * - * This routine read from memory file pointed to by the_jnode into - * the specified data buffer specified by destination. The file - * is NOT extended. An offset greater than the length of the file - * is considered an error. Read from an offset for more bytes than - * are between the offset and the end of the file will result in - * reading the data between offset and the end of the file (truncated - * read). - */ - -MEMFILE_STATIC int IMFS_memfile_read( - IMFS_jnode_t *the_jnode, - off_t start, - unsigned char *destination, - unsigned int length -) -{ - block_p *block_ptr; - unsigned int block; - unsigned int my_length; - unsigned int to_copy = 0; - unsigned int last_byte; - unsigned int copied; - unsigned int start_offset; - unsigned char *dest; - - dest = destination; - - /* - * Perform internal consistency checks - */ - - assert( the_jnode ); - if ( !the_jnode ) - rtems_set_errno_and_return_minus_one( EIO ); - - assert( the_jnode->type == IMFS_MEMORY_FILE || - the_jnode->type == IMFS_LINEAR_FILE ); - if ( the_jnode->type != IMFS_MEMORY_FILE && - the_jnode->type != IMFS_LINEAR_FILE ) - rtems_set_errno_and_return_minus_one( EIO ); - - /* - * Error checks on arguments - */ - - assert( dest ); - if ( !dest ) - rtems_set_errno_and_return_minus_one( EINVAL ); - - /* - * If there is nothing to read, then quick exit. - */ - - my_length = length; - if ( !my_length ) - rtems_set_errno_and_return_minus_one( EINVAL ); - - /* - * Linear files (as created from a tar file are easier to handle - * than block files). - */ - if (the_jnode->type == IMFS_LINEAR_FILE) { - unsigned char *file_ptr; - - file_ptr = (unsigned char *)the_jnode->info.linearfile.direct; - - if (my_length > (the_jnode->info.linearfile.size - start)) - my_length = the_jnode->info.linearfile.size - start; - - memcpy(dest, &file_ptr[start], my_length); - - IMFS_update_atime( the_jnode ); - - return my_length; - } - - /* - * If the last byte we are supposed to read is past the end of this - * in memory file, then shorten the length to read. - */ - - last_byte = start + length; - if ( last_byte > the_jnode->info.file.size ) - my_length = the_jnode->info.file.size - start; - - copied = 0; - - /* - * Three phases to the read: - * + possibly the last part of one block - * + all of zero of more blocks - * + possibly the first part of one block - */ - - /* - * Phase 1: possibly the last part of one block - */ - - start_offset = start % IMFS_MEMFILE_BYTES_PER_BLOCK; - block = start / IMFS_MEMFILE_BYTES_PER_BLOCK; - if ( start_offset ) { - to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK - start_offset; - if ( to_copy > my_length ) - to_copy = my_length; - block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); - assert( block_ptr ); - if ( !block_ptr ) - return copied; - memcpy( dest, &(*block_ptr)[ start_offset ], to_copy ); - dest += to_copy; - block++; - my_length -= to_copy; - copied += to_copy; - } - - /* - * Phase 2: all of zero of more blocks - */ - - to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK; - while ( my_length >= IMFS_MEMFILE_BYTES_PER_BLOCK ) { - block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); - assert( block_ptr ); - if ( !block_ptr ) - return copied; - memcpy( dest, &(*block_ptr)[ 0 ], to_copy ); - dest += to_copy; - block++; - my_length -= to_copy; - copied += to_copy; - } - - /* - * Phase 3: possibly the first part of one block - */ - - assert( my_length < IMFS_MEMFILE_BYTES_PER_BLOCK ); - - if ( my_length ) { - block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); - assert( block_ptr ); - if ( !block_ptr ) - return copied; - memcpy( dest, &(*block_ptr)[ 0 ], my_length ); - copied += my_length; - } - - IMFS_update_atime( the_jnode ); - - return copied; -} - -/* - * IMFS_memfile_write - * - * This routine writes the specified data buffer into the in memory - * file pointed to by the_jnode. The file is extended as needed. - */ - -MEMFILE_STATIC int IMFS_memfile_write( - IMFS_jnode_t *the_jnode, - off_t start, - const unsigned char *source, - unsigned int length -) -{ - block_p *block_ptr; - unsigned int block; - int status; - unsigned int my_length; - unsigned int to_copy = 0; - unsigned int last_byte; - unsigned int start_offset; - int copied; - const unsigned char *src; - - src = source; - - /* - * Perform internal consistency checks - */ - - assert( the_jnode ); - if ( !the_jnode ) - rtems_set_errno_and_return_minus_one( EIO ); - - assert( the_jnode->type == IMFS_MEMORY_FILE ); - if ( the_jnode->type != IMFS_MEMORY_FILE ) - rtems_set_errno_and_return_minus_one( EIO ); - - /* - * Error check arguments - */ - - assert( source ); - if ( !source ) - rtems_set_errno_and_return_minus_one( EINVAL ); - - - /* - * If there is nothing to write, then quick exit. - */ - - my_length = length; - if ( !my_length ) - rtems_set_errno_and_return_minus_one( EINVAL ); - - /* - * If the last byte we are supposed to write is past the end of this - * in memory file, then extend the length. - */ - - last_byte = start + length; - if ( last_byte > the_jnode->info.file.size ) { - status = IMFS_memfile_extend( the_jnode, last_byte ); - if ( status ) - rtems_set_errno_and_return_minus_one( ENOSPC ); - } - - copied = 0; - - /* - * Three phases to the write: - * + possibly the last part of one block - * + all of zero of more blocks - * + possibly the first part of one block - */ - - /* - * Phase 1: possibly the last part of one block - */ - - start_offset = start % IMFS_MEMFILE_BYTES_PER_BLOCK; - block = start / IMFS_MEMFILE_BYTES_PER_BLOCK; - if ( start_offset ) { - to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK - start_offset; - if ( to_copy > my_length ) - to_copy = my_length; - block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); - assert( block_ptr ); - if ( !block_ptr ) - return copied; -#if 0 -printf( "write %d at %d in %d: %*s\n", to_copy, start_offset, block, to_copy, src ); -#endif - memcpy( &(*block_ptr)[ start_offset ], src, to_copy ); - src += to_copy; - block++; - my_length -= to_copy; - copied += to_copy; - } - - /* - * Phase 2: all of zero of more blocks - */ - - to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK; - while ( my_length >= IMFS_MEMFILE_BYTES_PER_BLOCK ) { - block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); - assert( block_ptr ); - if ( !block_ptr ) - return copied; -#if 0 -printf( "write %d in %d: %*s\n", to_copy, block, to_copy, src ); -#endif - memcpy( &(*block_ptr)[ 0 ], src, to_copy ); - src += to_copy; - block++; - my_length -= to_copy; - copied += to_copy; - } - - /* - * Phase 3: possibly the first part of one block - */ - - assert( my_length < IMFS_MEMFILE_BYTES_PER_BLOCK ); - - to_copy = my_length; - if ( my_length ) { - block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 ); - assert( block_ptr ); - if ( !block_ptr ) - return copied; -#if 0 -printf( "write %d in %d: %*s\n", to_copy, block, to_copy, src ); -#endif - memcpy( &(*block_ptr)[ 0 ], src, my_length ); - my_length = 0; - copied += to_copy; - } - - IMFS_atime_mtime_update( the_jnode ); - - return copied; -} - -/* - * IMFS_memfile_get_block_pointer - * - * This routine looks up the block pointer associated with the given block - * number. If that block has not been allocated and "malloc_it" is - * TRUE, then the block is allocated. Otherwise, it is an error. - */ - -#if 0 -block_p *IMFS_memfile_get_block_pointer_DEBUG( - IMFS_jnode_t *the_jnode, - unsigned int block, - int malloc_it -); - -block_p *IMFS_memfile_get_block_pointer( - IMFS_jnode_t *the_jnode, - unsigned int block, - int malloc_it -) -{ - block_p *p; - - p = IMFS_memfile_get_block_pointer_DEBUG( the_jnode, block, malloc_it ); - printf( "(%d -> %p) ", block, p ); - return p; -} - -block_p *IMFS_memfile_get_block_pointer_DEBUG( -#else -block_p *IMFS_memfile_get_block_pointer( -#endif - IMFS_jnode_t *the_jnode, - unsigned int block, - int malloc_it -) -{ - unsigned int my_block; - IMFS_memfile_t *info; - unsigned int singly; - unsigned int doubly; - unsigned int triply; - block_p *p; - block_p *p1; - block_p *p2; - - /* - * Perform internal consistency checks - */ - - assert( the_jnode ); - if ( !the_jnode ) - return NULL; - - assert( the_jnode->type == IMFS_MEMORY_FILE ); - if ( the_jnode->type != IMFS_MEMORY_FILE ) - return NULL; - - info = &the_jnode->info.file; - - my_block = block; - - /* - * Is the block number in the simple indirect portion? - */ - - if ( my_block <= LAST_INDIRECT ) { -#if 0 -printf( "(s %d) ", block ); -fflush(stdout); -#endif - p = info->indirect; - - if ( malloc_it ) { - - if ( !p ) { - p = memfile_alloc_block(); - if ( !p ) - return 0; - info->indirect = p; - } - return &info->indirect[ my_block ]; - } - - if ( !p ) - return 0; - - return &info->indirect[ my_block ]; - } - - /* - * Is the block number in the doubly indirect portion? - */ - - if ( my_block <= LAST_DOUBLY_INDIRECT ) { -#if 0 -printf( "(d %d) ", block ); -fflush(stdout); -#endif - - my_block -= FIRST_DOUBLY_INDIRECT; - - singly = my_block % IMFS_MEMFILE_BLOCK_SLOTS; - doubly = my_block / IMFS_MEMFILE_BLOCK_SLOTS; - - p = info->doubly_indirect; - if ( malloc_it ) { - - if ( !p ) { - p = memfile_alloc_block(); - if ( !p ) - return 0; - info->doubly_indirect = p; - } - - p1 = (block_p *)p[ doubly ]; - if ( !p1 ) { - p1 = memfile_alloc_block(); - if ( !p1 ) - return 0; - p[ doubly ] = (block_p) p1; - } - - return (block_p *)&p1[ singly ]; - } - - if ( !p ) - return 0; - - p = (block_p *)p[ doubly ]; - if ( !p ) - return 0; - -#if 0 -printf( "(d %d %d %d %d %p %p) ", block, my_block, doubly, - singly, p, &p[singly] ); -fflush(stdout); -#endif - return (block_p *)&p[ singly ]; - } - -#if 0 -printf( "(t %d) ", block ); -fflush(stdout); -#endif - /* - * Is the block number in the triply indirect portion? - */ - - if ( my_block <= LAST_TRIPLY_INDIRECT ) { - my_block -= FIRST_TRIPLY_INDIRECT; - - singly = my_block % IMFS_MEMFILE_BLOCK_SLOTS; - doubly = my_block / IMFS_MEMFILE_BLOCK_SLOTS; - triply = doubly / IMFS_MEMFILE_BLOCK_SLOTS; - doubly %= IMFS_MEMFILE_BLOCK_SLOTS; - - p = info->triply_indirect; - - if ( malloc_it ) { - if ( !p ) { - p = memfile_alloc_block(); - if ( !p ) - return 0; - info->triply_indirect = p; - } - - p1 = (block_p *) p[ triply ]; - if ( !p1 ) { - p1 = memfile_alloc_block(); - if ( !p1 ) - return 0; - p[ triply ] = (block_p) p1; - } - - p2 = (block_p *)p1[ doubly ]; - if ( !p2 ) { - p2 = memfile_alloc_block(); - if ( !p2 ) - return 0; - p1[ doubly ] = (block_p) p2; - } - return (block_p *)&p2[ singly ]; - } - - if ( !p ) - return 0; - -#if 0 -printf( "(t %d %d %d %d %d) ", block, my_block, triply, doubly, singly ); -fflush(stdout); -#endif - p1 = (block_p *) p[ triply ]; - if ( !p1 ) - return 0; - - p2 = (block_p *)p1[ doubly ]; - if ( !p ) - return 0; - - return (block_p *)&p2[ singly ]; - } - - /* - * This means the requested block number is out of range. - */ - - return 0; -} - -/* - * memfile_alloc_block - * - * Allocate a block for an in-memory file. - */ - -int memfile_blocks_allocated = 0; - -void *memfile_alloc_block(void) -{ - void *memory; - - memory = (void *)calloc(1, IMFS_MEMFILE_BYTES_PER_BLOCK); - if ( memory ) - memfile_blocks_allocated++; - - return memory; -} - -/* - * memfile_free_block - * - * Free a block from an in-memory file. - */ - -void memfile_free_block( - void *memory -) -{ -#if 0 -printf( "(d %p) ", memory ); -fflush(stdout); -#endif - free(memory); - memfile_blocks_allocated--; -} - - -/* - * memfile_rmnod - * - * This routine is available from the optable to remove a node - * from the IMFS file system. - */ - -int memfile_rmnod( - rtems_filesystem_location_info_t *pathloc /* IN */ -) -{ - IMFS_jnode_t *the_jnode; - - the_jnode = (IMFS_jnode_t *) pathloc->node_access; - - /* - * Take the node out of the parent's chain that contains this node - */ - - if ( the_jnode->Parent != NULL ) { - Chain_Extract( (Chain_Node *) the_jnode ); - the_jnode->Parent = NULL; - } - - /* - * Decrement the link counter and see if we can free the space. - */ - - the_jnode->st_nlink--; - IMFS_update_ctime( the_jnode ); - - /* - * The file cannot be open and the link must be less than 1 to free. - */ - - if ( !rtems_libio_is_file_open( the_jnode ) && (the_jnode->st_nlink < 1) ) { - - /* - * Is the rtems_filesystem_current is this node? - */ - - if ( rtems_filesystem_current.node_access == pathloc->node_access ) - rtems_filesystem_current.node_access = NULL; - - /* - * Free memory associated with a memory file. - */ - if (the_jnode->type != IMFS_LINEAR_FILE) - IMFS_memfile_remove( the_jnode ); - - free( the_jnode ); - } - - return 0; - -} - - diff --git a/c/src/libfs/src/imfs/miniimfs_init.c b/c/src/libfs/src/imfs/miniimfs_init.c deleted file mode 100644 index 8ead84524e..0000000000 --- a/c/src/libfs/src/imfs/miniimfs_init.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Mini-IMFS Initialization - * - * COPYRIGHT (c) 1989-1999. - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.OARcorp.com/rtems/license.html. - * - * $Id$ - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include /* for mkdir */ -#include -#include -#include - -#include - -#include "imfs.h" -#include - -#if defined(IMFS_DEBUG) -#include -#endif - -/* - * miniIMFS file system operations table - */ - -rtems_filesystem_operations_table miniIMFS_ops = { - IMFS_eval_path, - IMFS_evaluate_for_make, - NULL, /* XXX IMFS_link, */ - NULL, /* XXX IMFS_unlink, */ - IMFS_node_type, - IMFS_mknod, - NULL, /* XXX IMFS_chown, */ - NULL, /* XXX IMFS_freenodinfo, */ - NULL, /* XXX IMFS_mount, */ - miniIMFS_initialize, - NULL, /* XXX IMFS_unmount, */ - NULL, /* XXX IMFS_fsunmount, */ - NULL, /* XXX IMFS_utime, */ - NULL, /* XXX IMFS_evaluate_link, */ - NULL, /* XXX IMFS_symlink, */ - NULL /* XXX IMFS_readlink */ -}; - -/* - * miniIMFS_initialize - */ - -int miniIMFS_initialize( - rtems_filesystem_mount_table_entry_t *temp_mt_entry -) -{ - IMFS_initialize_support( - temp_mt_entry, - &miniIMFS_ops, - &rtems_filesystem_null_handlers, /* for linearfiles */ - &rtems_filesystem_null_handlers, /* for memfiles */ - &rtems_filesystem_null_handlers /* for directories */ - ); - return 0; -} - - - diff --git a/c/src/libfs/wrapup/.cvsignore b/c/src/libfs/wrapup/.cvsignore deleted file mode 100644 index 525275c115..0000000000 --- a/c/src/libfs/wrapup/.cvsignore +++ /dev/null @@ -1,13 +0,0 @@ -Makefile -Makefile.in -aclocal.m4 -config.cache -config.guess -config.log -config.status -config.sub -configure -depcomp -install-sh -missing -mkinstalldirs diff --git a/c/src/libfs/wrapup/Makefile.am b/c/src/libfs/wrapup/Makefile.am deleted file mode 100644 index 0ce22c6cb8..0000000000 --- a/c/src/libfs/wrapup/Makefile.am +++ /dev/null @@ -1,42 +0,0 @@ -## -## $Id$ -## - - -LIBNAME = libfs -LIB = $(ARCH)/$(LIBNAME).a - -include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg -include $(top_srcdir)/../../../automake/compile.am -include $(top_srcdir)/../../../automake/lib.am - -IMFSLIB = ../src/imfs/$(ARCH)/libimfs.a - -if !UNIX -DOSFSLIB = ../src/dosfs/$(ARCH)/libdosfs.a -endif - -TMP_LIBS = $(IMFSLIB) $(DOSFSLIB) - -$(PROJECT_RELEASE)/lib/$(LIBNAME)$(LIB_VARIANT).a: $(LIB) - $(INSTALL_DATA) $< $@ - -# -# (OPTIONAL) Add local stuff here using += -# - -$(LIB): $(TMP_LIBS) - $(RM) $@ - $(RM) -r $(ARCH) - mkdir $(ARCH) - cd $(ARCH); for lib in $^; do $(AR) -xv ../$$lib; done - $(AR) ruv $@ $(ARCH)/* - $(RANLIB) $@ - -TMPINSTALL_FILES += $(PROJECT_RELEASE)/lib/$(LIBNAME)$(LIB_VARIANT).a - -all-local: $(ARCH) $(LIB) $(TMPINSTALL_FILES) - -.PRECIOUS: $(LIB) - -include $(top_srcdir)/../../../automake/local.am -- cgit v1.2.3