2013-05-03 20:52:33 +02:00
|
|
|
/****************************************************************************
|
2021-06-16 10:31:09 +02:00
|
|
|
* apps/testing/smart/smart_main.c
|
2013-05-03 20:52:33 +02:00
|
|
|
*
|
2020-04-11 20:13:56 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2013-05-03 20:52:33 +02:00
|
|
|
*
|
2020-04-11 20:13:56 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-05-03 20:52:33 +02:00
|
|
|
*
|
2020-04-11 20:13:56 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2013-05-03 20:52:33 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2020-06-15 08:02:49 +02:00
|
|
|
#include <malloc.h>
|
2013-05-03 20:52:33 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <crc32.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2013-11-15 18:22:23 +01:00
|
|
|
#include <nuttx/mtd/mtd.h>
|
2013-12-10 16:38:48 +01:00
|
|
|
#include <nuttx/fs/smart.h>
|
2013-05-03 20:52:33 +02:00
|
|
|
#include <nuttx/fs/ioctl.h>
|
2017-06-20 15:08:27 +02:00
|
|
|
|
|
|
|
#include "fsutils/mksmartfs.h"
|
2013-05-03 20:52:33 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-02 22:06:11 +02:00
|
|
|
* Pre-processor Definitions
|
2013-05-03 20:52:33 +02:00
|
|
|
****************************************************************************/
|
2020-04-11 20:56:24 +02:00
|
|
|
|
2013-05-03 20:52:33 +02:00
|
|
|
/* Configuration ************************************************************/
|
2020-04-11 20:56:24 +02:00
|
|
|
|
2013-05-03 20:52:33 +02:00
|
|
|
/* The default is to use the RAM MTD device at drivers/mtd/rammtd.c. But
|
|
|
|
* an architecture-specific MTD driver can be used instead by defining
|
2019-01-24 21:44:54 +01:00
|
|
|
* CONFIG_TESTING_SMART_ARCHINIT. In this case, the initialization logic
|
2013-05-03 20:52:33 +02:00
|
|
|
* will call smart_archinitialize() to obtain the MTD driver instance.
|
|
|
|
*/
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#ifndef CONFIG_TESTING_SMART_ARCHINIT
|
2013-05-03 20:52:33 +02:00
|
|
|
|
2020-04-11 20:56:24 +02:00
|
|
|
/* This must exactly match the default configuration in
|
|
|
|
* drivers/mtd/rammtd.c
|
|
|
|
*/
|
2013-05-03 20:52:33 +02:00
|
|
|
|
|
|
|
# ifndef CONFIG_RAMMTD_ERASESIZE
|
|
|
|
# define CONFIG_RAMMTD_ERASESIZE 4096
|
|
|
|
# endif
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
# ifndef CONFIG_TESTING_SMART_NEBLOCKS
|
|
|
|
# define CONFIG_TESTING_SMART_NEBLOCKS (256)
|
2013-05-03 20:52:33 +02:00
|
|
|
# endif
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
# define TESTING_SMART_BUFSIZE \
|
|
|
|
(CONFIG_RAMMTD_ERASESIZE * CONFIG_TESTING_SMART_NEBLOCKS)
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#ifndef CONFIG_TESTING_SMART_MAXNAME
|
|
|
|
# define CONFIG_TESTING_SMART_MAXNAME 128
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_MAXNAME > 255
|
|
|
|
# undef CONFIG_TESTING_SMART_MAXNAME
|
|
|
|
# define CONFIG_TESTING_SMART_MAXNAME 255
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#ifndef CONFIG_TESTING_SMART_MAXFILE
|
|
|
|
# define CONFIG_TESTING_SMART_MAXFILE 8192
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#ifndef CONFIG_TESTING_SMART_MAXIO
|
|
|
|
# define CONFIG_TESTING_SMART_MAXIO 347
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#ifndef CONFIG_TESTING_SMART_MAXOPEN
|
|
|
|
# define CONFIG_TESTING_SMART_MAXOPEN 512
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#ifndef CONFIG_TESTING_SMART_MOUNTPT
|
|
|
|
# define CONFIG_TESTING_SMART_MOUNTPT "/mnt/smart"
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#ifndef CONFIG_TESTING_SMART_NLOOPS
|
|
|
|
# define CONFIG_TESTING_SMART_NLOOPS 100
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#ifndef CONFIG_TESTING_SMART_VERBOSE
|
|
|
|
# define CONFIG_TESTING_SMART_VERBOSE 0
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct smart_filedesc_s
|
|
|
|
{
|
|
|
|
FAR char *name;
|
|
|
|
bool deleted;
|
|
|
|
size_t len;
|
|
|
|
uint32_t crc;
|
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
2020-04-11 20:56:24 +02:00
|
|
|
|
2013-05-03 20:52:33 +02:00
|
|
|
/* Pre-allocated simulated flash */
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#ifndef CONFIG_TESTING_SMART_ARCHINIT
|
|
|
|
static uint8_t g_simflash[TESTING_SMART_BUFSIZE];
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
static uint8_t g_fileimage[CONFIG_TESTING_SMART_MAXFILE];
|
|
|
|
static struct smart_filedesc_s g_files[CONFIG_TESTING_SMART_MAXOPEN];
|
|
|
|
static const char g_mountdir[] = CONFIG_TESTING_SMART_MOUNTPT "/";
|
2013-05-03 20:52:33 +02:00
|
|
|
static int g_nfiles;
|
|
|
|
static int g_ndeleted;
|
|
|
|
|
|
|
|
static struct mallinfo g_mmbefore;
|
|
|
|
static struct mallinfo g_mmprevious;
|
|
|
|
static struct mallinfo g_mmafter;
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* External Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#ifdef CONFIG_TESTING_SMART_ARCHINIT
|
2013-05-03 20:52:33 +02:00
|
|
|
extern FAR struct mtd_dev_s *smart_archinitialize(void);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_memusage
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void smart_showmemusage(struct mallinfo *mmbefore,
|
|
|
|
struct mallinfo *mmafter)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("VARIABLE BEFORE AFTER\n");
|
|
|
|
printf("======== ======== ========\n");
|
|
|
|
printf("arena %8x %8x\n", mmbefore->arena, mmafter->arena);
|
|
|
|
printf("ordblks %8d %8d\n", mmbefore->ordblks, mmafter->ordblks);
|
|
|
|
printf("mxordblk %8x %8x\n", mmbefore->mxordblk, mmafter->mxordblk);
|
|
|
|
printf("uordblks %8x %8x\n", mmbefore->uordblks, mmafter->uordblks);
|
|
|
|
printf("fordblks %8x %8x\n", mmbefore->fordblks, mmafter->fordblks);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_loopmemusage
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void smart_loopmemusage(void)
|
|
|
|
{
|
|
|
|
/* Get the current memory usage */
|
|
|
|
|
|
|
|
g_mmafter = mallinfo();
|
|
|
|
|
|
|
|
/* Show the change from the previous loop */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("\nEnd of loop memory usage:\n");
|
2013-05-03 20:52:33 +02:00
|
|
|
smart_showmemusage(&g_mmprevious, &g_mmafter);
|
|
|
|
|
|
|
|
/* Set up for the next test */
|
|
|
|
|
|
|
|
g_mmprevious = g_mmafter;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_endmemusage
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void smart_endmemusage(void)
|
|
|
|
{
|
|
|
|
g_mmafter = mallinfo();
|
2020-04-11 20:13:56 +02:00
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("\nFinal memory usage:\n");
|
2013-05-03 20:52:33 +02:00
|
|
|
smart_showmemusage(&g_mmbefore, &g_mmafter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_randchar
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline char smart_randchar(void)
|
|
|
|
{
|
|
|
|
int value = rand() % 63;
|
|
|
|
if (value == 0)
|
|
|
|
{
|
|
|
|
return '0';
|
|
|
|
}
|
|
|
|
else if (value <= 10)
|
|
|
|
{
|
|
|
|
return value + '0' - 1;
|
|
|
|
}
|
|
|
|
else if (value <= 36)
|
|
|
|
{
|
|
|
|
return value + 'a' - 11;
|
|
|
|
}
|
|
|
|
else /* if (value <= 62) */
|
|
|
|
{
|
|
|
|
return value + 'A' - 37;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_randname
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void smart_randname(FAR struct smart_filedesc_s *file)
|
|
|
|
{
|
|
|
|
int dirlen;
|
|
|
|
int maxname;
|
|
|
|
int namelen;
|
|
|
|
int alloclen;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dirlen = strlen(g_mountdir);
|
2019-01-24 21:44:54 +01:00
|
|
|
maxname = CONFIG_TESTING_SMART_MAXNAME - dirlen;
|
2013-05-03 20:52:33 +02:00
|
|
|
namelen = (rand() % maxname) + 1;
|
|
|
|
alloclen = namelen + dirlen;
|
|
|
|
|
2020-04-11 20:56:24 +02:00
|
|
|
file->name = (FAR char *)malloc(alloclen + 1);
|
2013-05-03 20:52:33 +02:00
|
|
|
if (!file->name)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to allocate name, length=%d\n", namelen);
|
|
|
|
fflush(stdout);
|
2013-05-03 20:52:33 +02:00
|
|
|
exit(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(file->name, g_mountdir, dirlen);
|
|
|
|
for (i = dirlen; i < alloclen; i++)
|
|
|
|
{
|
|
|
|
file->name[i] = smart_randchar();
|
|
|
|
}
|
2014-04-14 00:24:28 +02:00
|
|
|
|
2013-05-03 20:52:33 +02:00
|
|
|
file->name[alloclen] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_randfile
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void smart_randfile(FAR struct smart_filedesc_s *file)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
file->len = (rand() % CONFIG_TESTING_SMART_MAXFILE) + 1;
|
2013-05-03 20:52:33 +02:00
|
|
|
for (i = 0; i < file->len; i++)
|
|
|
|
{
|
|
|
|
g_fileimage[i] = smart_randchar();
|
|
|
|
}
|
|
|
|
|
|
|
|
file->crc = crc32(g_fileimage, file->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_freefile
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void smart_freefile(FAR struct smart_filedesc_s *file)
|
|
|
|
{
|
|
|
|
if (file->name)
|
|
|
|
{
|
|
|
|
free(file->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(file, 0, sizeof(struct smart_filedesc_s));
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_wrfile
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline int smart_wrfile(FAR struct smart_filedesc_s *file)
|
|
|
|
{
|
|
|
|
size_t offset;
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Create a random file */
|
|
|
|
|
|
|
|
smart_randname(file);
|
|
|
|
smart_randfile(file);
|
|
|
|
fd = open(file->name, O_WRONLY | O_CREAT | O_EXCL, 0666);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
/* If it failed because there is no space on the device, then don't
|
|
|
|
* complain.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (errno != ENOSPC)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to open file for writing: %d\n", errno);
|
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
smart_freefile(file);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write a random amount of data to the file */
|
|
|
|
|
|
|
|
for (offset = 0; offset < file->len; )
|
|
|
|
{
|
2019-01-24 21:44:54 +01:00
|
|
|
size_t maxio = (rand() % CONFIG_TESTING_SMART_MAXIO) + 1;
|
2013-05-03 20:52:33 +02:00
|
|
|
size_t nbytestowrite = file->len - offset;
|
|
|
|
ssize_t nbyteswritten;
|
|
|
|
|
|
|
|
if (nbytestowrite > maxio)
|
|
|
|
{
|
|
|
|
nbytestowrite = maxio;
|
|
|
|
}
|
|
|
|
|
|
|
|
nbyteswritten = write(fd, &g_fileimage[offset], nbytestowrite);
|
|
|
|
if (nbyteswritten < 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
int errcode = errno;
|
2013-05-03 20:52:33 +02:00
|
|
|
|
|
|
|
/* If the write failed because there is no space on the device,
|
|
|
|
* then don't complain.
|
|
|
|
*/
|
|
|
|
|
2016-06-11 22:49:55 +02:00
|
|
|
if (errcode != ENOSPC)
|
2013-05-03 20:52:33 +02:00
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
printf("ERROR: Failed to write file: %d\n", errcode);
|
2014-10-08 16:33:00 +02:00
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
|
|
|
printf(" Write offset: %ld\n", (long)offset);
|
|
|
|
printf(" Write size: %ld\n", (long)nbytestowrite);
|
2013-05-03 20:52:33 +02:00
|
|
|
ret = ERROR;
|
|
|
|
}
|
2016-06-11 22:49:55 +02:00
|
|
|
|
2013-05-03 20:52:33 +02:00
|
|
|
close(fd);
|
|
|
|
|
|
|
|
/* Remove any garbage file that might have been left behind */
|
|
|
|
|
|
|
|
ret = unlink(file->name);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf(" Failed to remove partial file\n");
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_VERBOSE != 0
|
2014-10-08 16:33:00 +02:00
|
|
|
printf(" Successfully removed partial file\n");
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
smart_freefile(file);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
else if (nbyteswritten != nbytestowrite)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Partial write:\n");
|
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
|
|
|
printf(" Write offset: %ld\n", (long)offset);
|
|
|
|
printf(" Write size: %ld\n", (long)nbytestowrite);
|
|
|
|
printf(" Written: %ld\n", (long)nbyteswritten);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
offset += nbyteswritten;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_fillfs
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int smart_fillfs(void)
|
|
|
|
{
|
|
|
|
FAR struct smart_filedesc_s *file;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Create a file for each unused file structure */
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
for (i = 0; i < CONFIG_TESTING_SMART_MAXOPEN; i++)
|
2013-05-03 20:52:33 +02:00
|
|
|
{
|
|
|
|
file = &g_files[i];
|
|
|
|
if (file->name == NULL)
|
|
|
|
{
|
|
|
|
ret = smart_wrfile(file);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_VERBOSE != 0
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to write file %d\n", i);
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_VERBOSE != 0
|
2014-10-08 16:33:00 +02:00
|
|
|
printf(" Created file %s\n", file->name);
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
g_nfiles++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_rdblock
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static ssize_t smart_rdblock(int fd, FAR struct smart_filedesc_s *file,
|
|
|
|
size_t offset, size_t len)
|
|
|
|
{
|
2019-01-24 21:44:54 +01:00
|
|
|
size_t maxio = (rand() % CONFIG_TESTING_SMART_MAXIO) + 1;
|
2013-05-03 20:52:33 +02:00
|
|
|
ssize_t nbytesread;
|
|
|
|
|
|
|
|
if (len > maxio)
|
|
|
|
{
|
|
|
|
len = maxio;
|
|
|
|
}
|
|
|
|
|
|
|
|
nbytesread = read(fd, &g_fileimage[offset], len);
|
|
|
|
if (nbytesread < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to read file: %d\n", errno);
|
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
|
|
|
printf(" Read offset: %ld\n", (long)offset);
|
|
|
|
printf(" Read size: %ld\n", (long)len);
|
2013-05-03 20:52:33 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
else if (nbytesread == 0)
|
|
|
|
{
|
|
|
|
#if 0 /* No... we do this on purpose sometimes */
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Unexpected end-of-file:\n");
|
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
|
|
|
printf(" Read offset: %ld\n", (long)offset);
|
|
|
|
printf(" Read size: %ld\n", (long)len);
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
else if (nbytesread != len)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Partial read:\n");
|
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
|
|
|
printf(" Read offset: %ld\n", (long)offset);
|
|
|
|
printf(" Read size: %ld\n", (long)len);
|
|
|
|
printf(" Bytes read: %ld\n", (long)nbytesread);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nbytesread;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_rdfile
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline int smart_rdfile(FAR struct smart_filedesc_s *file)
|
|
|
|
{
|
|
|
|
size_t ntotalread;
|
|
|
|
ssize_t nbytesread;
|
|
|
|
uint32_t crc;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* Open the file for reading */
|
|
|
|
|
|
|
|
fd = open(file->name, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
if (!file->deleted)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to open file for reading: %d\n", errno);
|
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read all of the data info the fileimage buffer using random read sizes */
|
|
|
|
|
|
|
|
for (ntotalread = 0; ntotalread < file->len; )
|
|
|
|
{
|
2020-04-11 20:56:24 +02:00
|
|
|
nbytesread = smart_rdblock(fd, file, ntotalread,
|
|
|
|
file->len - ntotalread);
|
2013-05-03 20:52:33 +02:00
|
|
|
if (nbytesread < 0)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ntotalread += nbytesread;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify the file image CRC */
|
|
|
|
|
|
|
|
crc = crc32(g_fileimage, file->len);
|
|
|
|
if (crc != file->crc)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Bad CRC: %d vs %d\n", crc, file->crc);
|
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
2013-05-03 20:52:33 +02:00
|
|
|
close(fd);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Try reading past the end of the file */
|
|
|
|
|
|
|
|
nbytesread = smart_rdblock(fd, file, ntotalread, 1024) ;
|
|
|
|
if (nbytesread > 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Read past the end of file\n");
|
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
2014-11-25 21:51:10 +01:00
|
|
|
printf(" Bytes read: %ld\n", (long)nbytesread);
|
2013-05-03 20:52:33 +02:00
|
|
|
close(fd);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_verifyfs
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int smart_verifyfs(void)
|
|
|
|
{
|
|
|
|
FAR struct smart_filedesc_s *file;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Create a file for each unused file structure */
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
for (i = 0; i < CONFIG_TESTING_SMART_MAXOPEN; i++)
|
2013-05-03 20:52:33 +02:00
|
|
|
{
|
|
|
|
file = &g_files[i];
|
|
|
|
if (file->name != NULL)
|
|
|
|
{
|
|
|
|
ret = smart_rdfile(file);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
if (file->deleted)
|
|
|
|
{
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_VERBOSE != 0
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("Deleted file %d OK\n", i);
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
smart_freefile(file);
|
|
|
|
g_ndeleted--;
|
|
|
|
g_nfiles--;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to read a file: %d\n", i);
|
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
2013-05-03 20:52:33 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (file->deleted)
|
|
|
|
{
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_VERBOSE != 0
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("Succesffully read a deleted file\n");
|
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
smart_freefile(file);
|
|
|
|
g_ndeleted--;
|
|
|
|
g_nfiles--;
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_VERBOSE != 0
|
2014-10-08 16:33:00 +02:00
|
|
|
printf(" Verifed file %s\n", file->name);
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_delfiles
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int smart_delfiles(void)
|
|
|
|
{
|
|
|
|
FAR struct smart_filedesc_s *file;
|
|
|
|
int ndel;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
/* Are there any files to be deleted? */
|
|
|
|
|
|
|
|
int nfiles = g_nfiles - g_ndeleted;
|
|
|
|
if (nfiles < 1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Yes... How many files should we delete? */
|
|
|
|
|
|
|
|
ndel = (rand() % nfiles) + 1;
|
|
|
|
|
|
|
|
/* Now pick which files to delete */
|
|
|
|
|
|
|
|
for (i = 0; i < ndel; i++)
|
|
|
|
{
|
|
|
|
/* Guess a file index */
|
|
|
|
|
|
|
|
int ndx = (rand() % (g_nfiles - g_ndeleted));
|
|
|
|
|
2015-10-11 01:15:15 +02:00
|
|
|
/* And delete the next undeleted file after that random index. NOTE
|
|
|
|
* that the entry at ndx is not checked.
|
|
|
|
*/
|
2013-05-03 20:52:33 +02:00
|
|
|
|
2015-10-11 01:15:15 +02:00
|
|
|
for (j = ndx + 1; j != ndx; j++)
|
2013-05-03 20:52:33 +02:00
|
|
|
{
|
2015-10-11 01:15:15 +02:00
|
|
|
/* Test for wrap-around */
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
if (j >= CONFIG_TESTING_FSTEST_MAXOPEN)
|
2015-10-11 01:15:15 +02:00
|
|
|
{
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
|
2013-05-03 20:52:33 +02:00
|
|
|
file = &g_files[j];
|
|
|
|
if (file->name && !file->deleted)
|
|
|
|
{
|
|
|
|
ret = unlink(file->name);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2020-04-11 20:56:24 +02:00
|
|
|
printf("ERROR: Unlink %d failed: %d\n", i + 1, errno);
|
2014-10-08 16:33:00 +02:00
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
|
|
|
printf(" File index: %d\n", j);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_VERBOSE != 0
|
2014-10-08 16:33:00 +02:00
|
|
|
printf(" Deleted file %s\n", file->name);
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
file->deleted = true;
|
|
|
|
g_ndeleted++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_delallfiles
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int smart_delallfiles(void)
|
|
|
|
{
|
|
|
|
FAR struct smart_filedesc_s *file;
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
for (i = 0; i < CONFIG_TESTING_SMART_MAXOPEN; i++)
|
2013-05-03 20:52:33 +02:00
|
|
|
{
|
|
|
|
file = &g_files[i];
|
|
|
|
if (file->name)
|
|
|
|
{
|
|
|
|
ret = unlink(file->name);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2020-04-11 20:56:24 +02:00
|
|
|
printf("ERROR: Unlink %d failed: %d\n", i + 1, errno);
|
2014-10-08 16:33:00 +02:00
|
|
|
printf(" File name: %s\n", file->name);
|
|
|
|
printf(" File size: %d\n", file->len);
|
|
|
|
printf(" File index: %d\n", i);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_VERBOSE != 0
|
2014-10-08 16:33:00 +02:00
|
|
|
printf(" Deleted file %s\n", file->name);
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
smart_freefile(file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_nfiles = 0;
|
|
|
|
g_ndeleted = 0;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_directory
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int smart_directory(void)
|
|
|
|
{
|
|
|
|
DIR *dirp;
|
|
|
|
FAR struct dirent *entryp;
|
|
|
|
int number;
|
|
|
|
|
|
|
|
/* Open the directory */
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
dirp = opendir(CONFIG_TESTING_SMART_MOUNTPT);
|
2013-05-03 20:52:33 +02:00
|
|
|
|
|
|
|
if (!dirp)
|
|
|
|
{
|
|
|
|
/* Failed to open the directory */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to open directory '%s': %d\n",
|
2019-01-24 21:44:54 +01:00
|
|
|
CONFIG_TESTING_SMART_MOUNTPT, errno);
|
2013-05-03 20:52:33 +02:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read each directory entry */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("Directory:\n");
|
2013-05-03 20:52:33 +02:00
|
|
|
number = 1;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
entryp = readdir(dirp);
|
|
|
|
if (entryp)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("%2d. Type[%d]: %s Name: %s\n",
|
|
|
|
number, entryp->d_type,
|
|
|
|
entryp->d_type == DTYPE_FILE ? "File " : "Error",
|
|
|
|
entryp->d_name);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
number++;
|
|
|
|
}
|
|
|
|
while (entryp != NULL);
|
|
|
|
|
|
|
|
closedir(dirp);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: smart_main
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-06 17:23:23 +02:00
|
|
|
int main(int argc, FAR char *argv[])
|
2013-05-03 20:52:33 +02:00
|
|
|
{
|
|
|
|
FAR struct mtd_dev_s *mtd;
|
|
|
|
unsigned int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Seed the random number generated */
|
|
|
|
|
|
|
|
srand(0x93846);
|
|
|
|
|
|
|
|
/* Create and initialize a RAM MTD device instance */
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#ifdef CONFIG_TESTING_SMART_ARCHINIT
|
2013-05-03 20:52:33 +02:00
|
|
|
mtd = smart_archinitialize();
|
|
|
|
#else
|
2019-01-24 21:44:54 +01:00
|
|
|
mtd = rammtd_initialize(g_simflash, TESTING_SMART_BUFSIZE);
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
if (!mtd)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to create RAM MTD instance\n");
|
|
|
|
fflush(stdout);
|
2013-05-03 20:52:33 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize to provide SMART on an MTD interface */
|
|
|
|
|
|
|
|
MTD_IOCTL(mtd, MTDIOC_BULKERASE, 0);
|
2017-06-20 15:08:27 +02:00
|
|
|
ret = smart_initialize(1, mtd, "SmartTest");
|
2013-05-03 20:52:33 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: SMART initialization failed: %d\n", -ret);
|
|
|
|
fflush(stdout);
|
2013-05-03 20:52:33 +02:00
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
2014-02-11 02:11:56 +01:00
|
|
|
/* Create a SMARTFS filesystem */
|
2013-05-03 20:52:33 +02:00
|
|
|
|
2017-06-20 15:08:27 +02:00
|
|
|
#ifdef CONFIG_SMARTFS_MULTI_ROOT_DIRS
|
2020-01-02 13:09:50 +01:00
|
|
|
mksmartfs("/dev/smart1", 1024, 1);
|
2017-06-20 15:08:27 +02:00
|
|
|
#else
|
2020-01-02 13:09:50 +01:00
|
|
|
mksmartfs("/dev/smart1", 1024);
|
2017-06-20 15:08:27 +02:00
|
|
|
#endif
|
2013-05-03 20:52:33 +02:00
|
|
|
|
|
|
|
/* Mount the file system */
|
|
|
|
|
2020-04-11 20:56:24 +02:00
|
|
|
ret = mount("/dev/smart1", CONFIG_TESTING_SMART_MOUNTPT, "smartfs",
|
|
|
|
0, NULL);
|
2013-05-03 20:52:33 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to mount the SMART volume: %d\n", errno);
|
|
|
|
fflush(stdout);
|
2013-05-03 20:52:33 +02:00
|
|
|
exit(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up memory monitoring */
|
|
|
|
|
|
|
|
g_mmbefore = mallinfo();
|
|
|
|
g_mmprevious = g_mmbefore;
|
|
|
|
|
|
|
|
/* Loop a few times ... file the file system with some random, files,
|
|
|
|
* delete some files randomly, fill the file system with more random file,
|
|
|
|
* delete, etc. This beats the FLASH very hard!
|
|
|
|
*/
|
|
|
|
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_NLOOPS == 0
|
2013-05-03 20:52:33 +02:00
|
|
|
for (i = 0; ; i++)
|
|
|
|
#else
|
2019-01-24 21:44:54 +01:00
|
|
|
for (i = 1; i <= CONFIG_TESTING_SMART_NLOOPS; i++)
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* Write a files to the SMART file system until either (1) all of the
|
2020-04-11 20:56:24 +02:00
|
|
|
* open file structures are utilized or until (2) SMART reports an
|
|
|
|
* error (hopefully that the file system is full)
|
2013-05-03 20:52:33 +02:00
|
|
|
*/
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("\n=== FILLING %u =============================\n", i);
|
2020-01-02 13:09:50 +01:00
|
|
|
smart_fillfs();
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("Filled file system\n");
|
|
|
|
printf(" Number of files: %d\n", g_nfiles);
|
|
|
|
printf(" Number deleted: %d\n", g_ndeleted);
|
2013-05-03 20:52:33 +02:00
|
|
|
|
|
|
|
/* Directory listing */
|
|
|
|
|
|
|
|
smart_directory();
|
|
|
|
|
|
|
|
/* Verify all files written to FLASH */
|
|
|
|
|
|
|
|
ret = smart_verifyfs();
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to verify files\n");
|
|
|
|
printf(" Number of files: %d\n", g_nfiles);
|
|
|
|
printf(" Number deleted: %d\n", g_ndeleted);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_VERBOSE != 0
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("Verified!\n");
|
|
|
|
printf(" Number of files: %d\n", g_nfiles);
|
|
|
|
printf(" Number deleted: %d\n", g_ndeleted);
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete some files */
|
|
|
|
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("\n=== DELETING %u ============================\n", i);
|
2013-05-03 20:52:33 +02:00
|
|
|
ret = smart_delfiles();
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to delete files\n");
|
|
|
|
printf(" Number of files: %d\n", g_nfiles);
|
|
|
|
printf(" Number deleted: %d\n", g_ndeleted);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("Deleted some files\n");
|
|
|
|
printf(" Number of files: %d\n", g_nfiles);
|
|
|
|
printf(" Number deleted: %d\n", g_ndeleted);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Directory listing */
|
|
|
|
|
|
|
|
smart_directory();
|
|
|
|
|
|
|
|
/* Verify all files written to FLASH */
|
|
|
|
|
|
|
|
ret = smart_verifyfs();
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("ERROR: Failed to verify files\n");
|
|
|
|
printf(" Number of files: %d\n", g_nfiles);
|
|
|
|
printf(" Number deleted: %d\n", g_ndeleted);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-24 21:44:54 +01:00
|
|
|
#if CONFIG_TESTING_SMART_VERBOSE != 0
|
2014-10-08 16:33:00 +02:00
|
|
|
printf("Verified!\n");
|
|
|
|
printf(" Number of files: %d\n", g_nfiles);
|
|
|
|
printf(" Number deleted: %d\n", g_ndeleted);
|
2013-05-03 20:52:33 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show memory usage */
|
|
|
|
|
|
|
|
smart_loopmemusage();
|
2014-10-08 16:33:00 +02:00
|
|
|
fflush(stdout);
|
2013-05-03 20:52:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete all files then show memory usage again */
|
|
|
|
|
|
|
|
smart_delallfiles();
|
|
|
|
smart_endmemusage();
|
2014-10-08 16:33:00 +02:00
|
|
|
fflush(stdout);
|
2013-05-03 20:52:33 +02:00
|
|
|
return 0;
|
|
|
|
}
|