123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #ifndef SDRAMFILE_SOURCE
- #define SDRAMFILE_SOURCE
- #include <unistd.h>
- #include <memory.h>
- #include <fcntl.h>
- #include <errno.h>
- #include "../ram/sdram.h"
- #include "../tools/memory.h"
- #include "../tools/error.h"
- #include "../tools/flags.h"
- int sdramfile (int fd, char const * filename, flag_t flags)
- {
- uint32_t checksum;
- struct config_ram config_ram;
- memset (&config_ram, 0, sizeof (config_ram));
- if (lseek (fd, 0, SEEK_SET) == -1)
- {
- if (_allclr (flags, SDRAM_SILENCE))
- {
- error (0, errno, "Can't rewind file: %s", filename);
- }
- return (-1);
- }
- if (read (fd, &config_ram, sizeof (config_ram)) != sizeof (config_ram))
- {
- if (_allclr (flags, SDRAM_SILENCE))
- {
- error (0, errno, "Wrong file size: %s", filename);
- }
- return (-1);
- }
- if (read (fd, &checksum, sizeof (checksum)) != sizeof (checksum))
- {
- if (_allclr (flags, SDRAM_SILENCE))
- {
- error (0, errno, "Can't read checksum: %s", filename);
- }
- return (-1);
- }
- if (checksum32 (&config_ram, sizeof (config_ram), checksum))
- {
- if (_allclr (flags, SDRAM_SILENCE))
- {
- error (0, 0, "Bad checksum: %s", filename);
- }
- return (-1);
- }
- if (lseek (fd, 0, SEEK_SET) == -1)
- {
- if (_allclr (flags, SDRAM_SILENCE))
- {
- error (0, errno, "Can't rewind file: %s", filename);
- }
- return (-1);
- }
- return (0);
- }
- #endif
|