/*
* Copyright (c) 2007 Konopa-Jelen-Majer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** @addtogroup FSDemo
* @{
*/
/**
* @file cat.standard.c
* @brief A file system demonstration task - standard library version
*/
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <async.h>
#include "../console/console.h"
#include <io/file.h>
#include <io/stat.h>
/**
* This is a very basic linear demonstration script of the standard file library
*/
int main(int argc, char *argv[])
{
file_t * file;
unsigned int dir_items_length;
dir_item_t* dir_items;
char buffer[256];
int retval;
/* File list in working directory. */
dir_items = ls(&dir_items_length);
int entry;
for (entry = 0; entry < dir_items_length; entry++) {
printf("Inode number: %u\t\t", dir_items
[entry
].
inode_num);
printf("File name: %s\n", dir_items
[entry
].
name);
}
/* We want to change working directory */
retval = chdir("uspace/fs");
/* We want to work with specified file. */
file
= fopen("fs.c", F_MODE_READ
);
retval = fstat( file );
printf("Info about file: %s\n", file
->base_info.
name);
printf("Inode number: %d\n", file
->stat.
st_ino);
printf("Mode: %d\n", file
->stat.
st_mode);
printf("Links: %d\n", file
->stat.
st_nlink);
printf("Size: %d\n", file
->stat.
st_size);
retval
= fseek( file
, 100, 1);
retval
= fread( file
, buffer
, 100);
buffer[100]=0;
printf("%d bytes was read into buffer\n", retval
);
printf("\nContent of the buffer:\n");
retval
= fseek( file
, 0, 0);
retval
= fread( file
, buffer
, 50);
buffer[50]=0;
printf("%d bytes was read into buffer\n", retval
);
printf("\nContent of the buffer:\n");
/*close the file */
return 0;
}
/**
* }
*/