Subversion Repositories HelenOS

Rev

Rev 2434 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2007 Konopa-Jelen-Majer
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup FSDemo
  30.  * @{
  31.  */
  32.  
  33. /**
  34.  * @file    cat.standard.c
  35.  * @brief   A file system demonstration task - standard library version
  36.  */
  37.  
  38.  
  39. #include <err.h>
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <string.h>
  43. #include <unistd.h>
  44. #include <async.h>
  45. #include "../console/console.h"
  46. #include <io/file.h>
  47. #include <io/stat.h>
  48.  
  49.  
  50. /**
  51.  * This is a very basic linear demonstration script of the standard file library
  52.  */
  53. int main(int argc, char *argv[])
  54. {
  55.    
  56.     file_t * file;
  57.     unsigned int dir_items_length;
  58.     dir_item_t* dir_items;
  59.     char buffer[256];
  60.     int retval;
  61.    
  62.     printf("Cat task\n");
  63.        
  64.     /* File list in working directory. */
  65.     printf("File list:\n");
  66.     dir_items = ls(&dir_items_length);
  67.     printf("Got a list\n");
  68.    
  69.     int entry;
  70.     for (entry = 0; entry < dir_items_length; entry++) {
  71.         printf("Inode number: %u\t\t", dir_items[entry].inode_num);
  72.         printf("File name: %s\n", dir_items[entry].name);
  73.        
  74.     }  
  75.    
  76.     /* We want to change working directory */
  77.     retval = chdir("uspace/fs");
  78.  
  79.     /* We want to work with specified file. */
  80.     file = fopen("fs.c", F_MODE_READ);
  81.     retval = fstat( file );
  82.    
  83.     printf("Info about file: %s\n", file->base_info.name);
  84.     printf("Inode number: %d\n", file->stat.st_ino);
  85.     printf("Mode: %d\n", file->stat.st_mode);
  86.     printf("Links: %d\n", file->stat.st_nlink);
  87.     printf("Size: %d\n", file->stat.st_size);
  88.    
  89.     retval = fseek( file, 100, 1);
  90.     retval = fread( file, buffer, 100);
  91.     buffer[100]=0;
  92.    
  93.     printf("%d bytes was read into buffer\n", retval);
  94.     printf("\nContent of the buffer:\n");
  95.     printf(buffer);
  96.     printf("\n\n");
  97.    
  98.     retval = fseek( file, 0, 0);
  99.     retval = fread( file, buffer, 50);
  100.     buffer[50]=0;
  101.    
  102.     printf("%d bytes was read into buffer\n", retval);
  103.     printf("\nContent of the buffer:\n");
  104.     printf(buffer);
  105.     printf("\n\n");
  106.   /*close the file */
  107.     retval = fclose( file );   
  108.    
  109.     return 0;
  110. }
  111.  
  112. /**
  113. * }
  114. */
  115.