HP85 GPIB Disk Emulator  1.0
HP85GPIBDiskEmulator
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
lifutils.h
Go to the documentation of this file.
1 
16 #ifndef _LIFUTILS_H
17 #define _LIFUTILS_H
18 
19 #ifndef LIF_STAND_ALONE
20 #include "user_config.h"
21 #endif
22 
23 typedef struct stat stat_t;
24 
26 #define LIF_SECTOR_SIZE 256
27 
29 #define LIF_DIR_SIZE 32
30 #define LIF_DIR_RECORDS_PER_SECTOR (LIF_SECTOR_SIZE/LIF_DIR_SIZE)
31 
55 typedef struct
59 {
60  uint16_t LIFid; // 0
61  uint8_t Label[6+1]; // 2
62  uint32_t DirStartSector; // 8
63  uint16_t System3000LIFid; // 12
64  uint16_t zero1; // 14
65  uint32_t DirSectors; // 16
66  uint16_t LIFVersion; // 20
67  uint16_t zero2; // 22
68  uint32_t tracks_per_side; // 24
69  uint32_t sides; // 28
70  uint32_t sectors_per_track; // 32
71  uint8_t date[6]; // 36 BCD (YY MM DD HH MM SS)
72 } lifvol_t;
73 
96 typedef struct
98 {
99  uint8_t filename[10+1]; // 0
100  uint16_t FileType; // 10
101  uint32_t FileStartSector; // 12
102  uint32_t FileSectors; // 16
103  uint8_t date[6]; // 20 File date in BCD (YY MM DD HH MM SS)
104  uint16_t VolNumber; // 26
105  uint16_t FileBytes; // 28
106  uint16_t SectorSize; // 30
107 } lifdir_t;
108 
114 typedef struct
115 {
116  char *name; // LIF image file name
117  FILE *fp; // LIF file handel
118  uint32_t sectors; // LIF image size in sectors
119  uint32_t imagebytes; // LIF image size in bytes
120  uint32_t filestart; // LIF file area start in sectors
121  uint32_t filesectors; // LIF file area size in sectors
122  uint32_t usedsectors; // Used sector count
123  uint32_t freesectors; // Free sector count
124  int files; // File count
125  int purged; // Purged file count
126  int dirindex; // Directory index 0..N
127  int EOFindex; // Position of EOF directory record
128  lifvol_t VOL; // LIF Volume header
129  lifdir_t DIR; // LIF directory entry
130 } lif_t;
131 
132 // =============================================
133 
134 
135 /* lifutils.c */
136 MEMSPACE void lif_help ( int full );
137 MEMSPACE int lif_tests ( int argc , char *argv []);
138 MEMSPACE void *lif_calloc ( long size );
139 MEMSPACE void lif_free ( void *p );
140 MEMSPACE char *lif_stralloc ( char *str );
141 MEMSPACE FILE *lif_open ( char *name , char *mode );
142 MEMSPACE stat_t *lif_stat ( char *name , stat_t *p );
143 MEMSPACE int lif_seek_msg ( FILE *fp , long offset , char *msg );
144 MEMSPACE long lif_read ( lif_t *LIF , void *buf , long offset , int bytes );
145 MEMSPACE int lif_write ( lif_t *LIF , void *buf , long offset , int bytes );
146 MEMSPACE int lif_chars ( int c , int index __attribute__ ((unused )));
147 MEMSPACE int lif_B2S ( uint8_t *B , uint8_t *name , int size );
148 MEMSPACE int lif_checkname ( char *name );
149 MEMSPACE void lif_S2B ( uint8_t *B , uint8_t *name , int size );
150 MEMSPACE int lif_fixname ( uint8_t *B , char *name , int size );
151 MEMSPACE void lif_vol2str ( lif_t *LIF , uint8_t *B );
152 MEMSPACE void lif_str2vol ( uint8_t *B , lif_t *LIF );
153 MEMSPACE void lif_dir2str ( lif_t *LIF , uint8_t *B );
154 MEMSPACE void lif_str2dir ( uint8_t *B , lif_t *LIF );
155 MEMSPACE uint8_t lif_BIN2BCD ( uint8_t data );
156 MEMSPACE int lif_BCD2BIN ( uint8_t bin );
157 MEMSPACE void lif_time2lifbcd ( time_t t , uint8_t *bcd );
158 MEMSPACE time_t lif_lifbcd2time ( uint8_t *bcd );
159 MEMSPACE char *lif_ctime_gmt ( time_t *tp );
160 MEMSPACE char *lif_lifbcd2timestr ( uint8_t *bcd );
161 MEMSPACE void lif_image_clear ( lif_t *LIF );
162 MEMSPACE void lif_dir_clear ( lif_t *LIF );
163 MEMSPACE void lif_vol_clear ( lif_t *LIF );
164 MEMSPACE void lif_dump_vol ( lif_t *LIF , char *msg );
165 MEMSPACE int lif_check_volume ( lif_t *LIF );
166 MEMSPACE int lif_check_dir ( lif_t *LIF );
167 MEMSPACE lif_t *lif_create_volume ( char *imagename , char *liflabel , long dirstart , long dirsectors , long filesectors );
168 MEMSPACE void lif_close_volume ( lif_t *LIF );
169 MEMSPACE uint32_t lif_bytes2sectors ( uint32_t bytes );
170 MEMSPACE void lif_rewinddir ( lif_t *LIF );
171 MEMSPACE void lif_closedir ( lif_t *LIF );
172 MEMSPACE int lif_checkdirindex ( lif_t *LIF , int index );
173 MEMSPACE int lif_readdirindex ( lif_t *LIF , int index );
174 MEMSPACE int lif_writedirindex ( lif_t *LIF , int index );
175 MEMSPACE int lif_writedirEOF ( lif_t *LIF , int index );
178 MEMSPACE int lif_newdir ( lif_t *LIF , long sectors );
179 MEMSPACE lif_t *lif_open_volume ( char *name , char *mode );
180 MEMSPACE void lif_dir ( char *lifimagename );
181 MEMSPACE int lif_find_file ( lif_t *LIF , char *liflabel );
182 MEMSPACE int lif_e010_pad_sector ( long offset , uint8_t *wbuf );
183 MEMSPACE int lif_ascii_string_to_e010 ( char *str , long offset , uint8_t *wbuf );
184 MEMSPACE long lif_add_ascii_file_as_e010_wrapper ( lif_t *LIF , uint32_t offset , char *username );
185 MEMSPACE long lif_add_ascii_file_as_e010 ( char *lifimagename , char *lifname , char *userfile );
186 MEMSPACE int lif_extract_e010_as_ascii ( char *lifimagename , char *lifname , char *username );
187 MEMSPACE int lif_extract_lif_as_lif ( char *lifimagename , char *lifname , char *username );
188 MEMSPACE long lif_add_lif_file ( char *lifimagename , char *lifname , char *userfile );
189 MEMSPACE int lif_del_file ( char *lifimagename , char *lifname );
190 MEMSPACE int lif_rename_file ( char *lifimagename , char *oldlifname , char *newlifname );
191 MEMSPACE int lif_rename_volume ( char *lifimagename , char *volname );
192 MEMSPACE long lif_create_image ( char *lifimagename , char *liflabel , uint32_t dirsectors , uint32_t sectors );
193 #endif // #ifndef _LIFUTILS_H
lif_add_ascii_file_as_e010_wrapper
MEMSPACE long lif_add_ascii_file_as_e010_wrapper(lif_t *LIF, uint32_t offset, char *username)
Add ASCII file as E010 data to LIF image - or compute converted data size To find size of formatted r...
Definition: lifutils.c:2012
lif_BIN2BCD
MEMSPACE uint8_t lif_BIN2BCD(uint8_t data)
Convert number >= 0 and <= 99 to BCD.
Definition: lifutils.c:668
lif_del_file
MEMSPACE int lif_del_file(char *lifimagename, char *lifname)
Delete LIF file in LIF image.
Definition: lifutils.c:2609
stat
POSIX stat structure.
Definition: posix.h:105
lif_str2dir
MEMSPACE void lif_str2dir(uint8_t *B, lif_t *LIF)
Convert byte vector into byte vector.
Definition: lifutils.c:649
lif_vol2str
MEMSPACE void lif_vol2str(lif_t *LIF, uint8_t *B)
Convert LIF volume records into byte vector.
Definition: lifutils.c:586
lif_S2B
MEMSPACE void lif_S2B(uint8_t *B, uint8_t *name, int size)
Convert string to LIF directory record.
Definition: lifutils.c:526
lif_lifbcd2timestr
MEMSPACE char * lif_lifbcd2timestr(uint8_t *bcd)
Definition: lifutils.c:786
lif_t::filestart
uint32_t filestart
Definition: lifutils.h:120
lifvol_t::System3000LIFid
uint16_t System3000LIFid
Definition: lifutils.h:63
lifvol_t::LIFid
uint16_t LIFid
Definition: lifutils.h:60
lifdir_t::FileStartSector
uint32_t FileStartSector
Definition: lifutils.h:101
lif_check_volume
MEMSPACE int lif_check_volume(lif_t *LIF)
Check Volume Table for values in range.
Definition: lifutils.c:872
lif_t::DIR
lifdir_t DIR
Definition: lifutils.h:129
lif_t
Master LIF data structure Contains image file name Volume Structure Current Directory Entry read/writ...
Definition: lifutils.h:114
lif_ascii_string_to_e010
MEMSPACE int lif_ascii_string_to_e010(char *str, long offset, uint8_t *wbuf)
Convert an ASCII string into HP85 E010 format.
Definition: lifutils.c:1917
MEMSPACE
#define MEMSPACE
Definition: user_config.h:17
lifdir_t::FileSectors
uint32_t FileSectors
Definition: lifutils.h:102
lif_ctime_gmt
MEMSPACE char * lif_ctime_gmt(time_t *tp)
GMT version of POSIX ctime().
Definition: lifutils.c:766
lif_tests
MEMSPACE int lif_tests(int argc, char *argv[])
LIF user tests.
Definition: lifutils.c:139
user_config.h
lifvol_t::zero1
uint16_t zero1
Definition: lifutils.h:64
lif_stralloc
MEMSPACE char * lif_stralloc(char *str)
Allocate and copy a string Displays message on errors.
Definition: lifutils.c:322
lif_fixname
MEMSPACE int lif_fixname(uint8_t *B, char *name, int size)
Convert name into a valid LIF name Only use the basename() part of the string and remove any file nam...
Definition: lifutils.c:549
lif_writedirindex
MEMSPACE int lif_writedirindex(lif_t *LIF, int index)
Write LIF drectory record number N.
Definition: lifutils.c:1349
lif_checkdirindex
MEMSPACE int lif_checkdirindex(lif_t *LIF, int index)
Check directory index limits.
Definition: lifutils.c:1284
lif_add_lif_file
MEMSPACE long lif_add_lif_file(char *lifimagename, char *lifname, char *userfile)
Add LIF file from another LIF image.
Definition: lifutils.c:2491
lif_extract_e010_as_ascii
MEMSPACE int lif_extract_e010_as_ascii(char *lifimagename, char *lifname, char *username)
Extract E010 type file from LIF image and save as user ASCII file.
Definition: lifutils.c:2213
lifvol_t::sides
uint32_t sides
Definition: lifutils.h:69
lif_create_image
MEMSPACE long lif_create_image(char *lifimagename, char *liflabel, uint32_t dirsectors, uint32_t sectors)
Create/Format a LIF new disk image This can take a while to run, about 1 min for 10,...
Definition: lifutils.c:2798
lif_newdir
MEMSPACE int lif_newdir(lif_t *LIF, long sectors)
Allocate index of free directory record.
Definition: lifutils.c:1507
lif_str2vol
MEMSPACE void lif_str2vol(uint8_t *B, lif_t *LIF)
Convert byte vector into LIF volume records.
Definition: lifutils.c:608
lif_closedir
MEMSPACE void lif_closedir(lif_t *LIF)
Close LIF directory clear and free lif_t structure.
Definition: lifutils.c:1273
lif_t::filesectors
uint32_t filesectors
Definition: lifutils.h:121
lif_t::files
int files
Definition: lifutils.h:124
lif_close_volume
MEMSPACE void lif_close_volume(lif_t *LIF)
Free LIF structure and close any files.
Definition: lifutils.c:1220
lif_t::name
char * name
Definition: lifutils.h:116
lif_dir_clear
MEMSPACE void lif_dir_clear(lif_t *LIF)
Clear DIR part of LIF structure.
Definition: lifutils.c:816
lif_t::fp
FILE * fp
Definition: lifutils.h:117
lif_open
MEMSPACE FILE * lif_open(char *name, char *mode)
Open a file that must exist Displays message on errors.
Definition: lifutils.c:339
lif_free
MEMSPACE void lif_free(void *p)
Free allocated memory Displays message on errors.
Definition: lifutils.c:308
lif_t::freesectors
uint32_t freesectors
Definition: lifutils.h:123
lif_t::imagebytes
uint32_t imagebytes
Definition: lifutils.h:119
lif_time2lifbcd
MEMSPACE void lif_time2lifbcd(time_t t, uint8_t *bcd)
UNIX time to LIF BCD time format The BCD year is only the lower 2 digits of the year So We assume tha...
Definition: lifutils.c:694
__file
FILE type structure.
Definition: posix.h:158
lif_readdirindex
MEMSPACE int lif_readdirindex(lif_t *LIF, int index)
Read LIF directory record number N.
Definition: lifutils.c:1302
lifvol_t::DirStartSector
uint32_t DirStartSector
Definition: lifutils.h:62
lif_t::sectors
uint32_t sectors
Definition: lifutils.h:118
lif_find_file
MEMSPACE int lif_find_file(lif_t *LIF, char *liflabel)
Find a LIF image file by name.
Definition: lifutils.c:1815
lif_bytes2sectors
MEMSPACE uint32_t lif_bytes2sectors(uint32_t bytes)
Convert bytes into used sectors.
Definition: lifutils.c:1247
lifvol_t
Disk Layout.
Definition: lifutils.h:58
lif_dir2str
MEMSPACE void lif_dir2str(lif_t *LIF, uint8_t *B)
Convert LIF directory records into byte vector.
Definition: lifutils.c:631
lifdir_t::FileBytes
uint16_t FileBytes
Definition: lifutils.h:105
lif_t::purged
int purged
Definition: lifutils.h:125
lif_updatefree
MEMSPACE lif_t * lif_updatefree(lif_t *LIF)
Update free space @parameter[in] *LIF: LIF structure.
Definition: lifutils.c:1430
lif_open_volume
MEMSPACE lif_t * lif_open_volume(char *name, char *mode)
Open LIF directory for reading.
Definition: lifutils.c:1644
lif_chars
MEMSPACE int lif_chars(int c, int index __attribute__((unused)))
Check if characters in a LIF volume or LIF file name are valid.
Definition: lifutils.c:449
lif_seek_msg
MEMSPACE int lif_seek_msg(FILE *fp, long offset, char *msg)
Definition: lifutils.c:374
lif_t::VOL
lifvol_t VOL
Definition: lifutils.h:128
lif_t::EOFindex
int EOFindex
Definition: lifutils.h:127
lif_e010_pad_sector
MEMSPACE int lif_e010_pad_sector(long offset, uint8_t *wbuf)
HP85 E010 ASCII LIF records ef [ff]* = no more data in this sector df size [ASCII] = data must fit in...
Definition: lifutils.c:1877
lif_check_dir
MEMSPACE int lif_check_dir(lif_t *LIF)
Validate Directory record values We only do basic out of bounds tests for this record Purged or EOF d...
Definition: lifutils.c:946
lif_rename_volume
MEMSPACE int lif_rename_volume(char *lifimagename, char *volname)
Rename LIF VOLUME NAME.
Definition: lifutils.c:2730
lif_checkname
MEMSPACE int lif_checkname(char *name)
Check volume LIF name or directory name is valid.
Definition: lifutils.c:507
lifvol_t::tracks_per_side
uint32_t tracks_per_side
Definition: lifutils.h:68
lif_rewinddir
MEMSPACE void lif_rewinddir(lif_t *LIF)
Rewind LIF directory Note readdir pre-increments the directory pointer index so we start at -1.
Definition: lifutils.c:1261
lif_image_clear
MEMSPACE void lif_image_clear(lif_t *LIF)
File seek with error message.
Definition: lifutils.c:806
lif_BCD2BIN
MEMSPACE int lif_BCD2BIN(uint8_t bin)
Convert BCD in the range 0 and <= 99 to BIN BCD format: each hex nibble has a digit 0 ....
Definition: lifutils.c:678
lifdir_t::VolNumber
uint16_t VolNumber
Definition: lifutils.h:104
lifvol_t::DirSectors
uint32_t DirSectors
Definition: lifutils.h:65
lifvol_t::zero2
uint16_t zero2
Definition: lifutils.h:67
lifvol_t::sectors_per_track
uint32_t sectors_per_track
Definition: lifutils.h:70
lif_dir
MEMSPACE void lif_dir(char *lifimagename)
Display a LIF image file directory.
Definition: lifutils.c:1734
lifdir_t
Directory layout.
Definition: lifutils.h:97
lif_t::dirindex
int dirindex
Definition: lifutils.h:126
time_t
uint32_t time_t
type of EPOCH result.
Definition: time.h:34
lif_calloc
MEMSPACE void * lif_calloc(long size)
Allocate and clear memory Displays message on errors.
Definition: lifutils.c:293
lif_add_ascii_file_as_e010
MEMSPACE long lif_add_ascii_file_as_e010(char *lifimagename, char *lifname, char *userfile)
Convert and add ASCII file to the LIF image as type E010 format The basename of the lifname,...
Definition: lifutils.c:2109
lifdir_t::FileType
uint16_t FileType
Definition: lifutils.h:100
lif_readdir
MEMSPACE lifdir_t * lif_readdir(lif_t *LIF)
Read a directory records from LIF image advancind directory index.
Definition: lifutils.c:1403
lif_writedirEOF
MEMSPACE int lif_writedirEOF(lif_t *LIF, int index)
Write LIF drectory EOF.
Definition: lifutils.c:1387
lif_t::usedsectors
uint32_t usedsectors
Definition: lifutils.h:122
lifdir_t::SectorSize
uint16_t SectorSize
Definition: lifutils.h:106
lifvol_t::LIFVersion
uint16_t LIFVersion
Definition: lifutils.h:66
lif_write
MEMSPACE int lif_write(lif_t *LIF, void *buf, long offset, int bytes)
Write data to an LIF image Displays message on errors.
Definition: lifutils.c:424
lif_stat
MEMSPACE stat_t * lif_stat(char *name, stat_t *p)
Stat a file Displays message on errors.
Definition: lifutils.c:357
lif_extract_lif_as_lif
MEMSPACE int lif_extract_lif_as_lif(char *lifimagename, char *lifname, char *username)
Extract a file from LIF image entry as standalone LIF image.
Definition: lifutils.c:2390
lif_vol_clear
MEMSPACE void lif_vol_clear(lif_t *LIF)
Clear VOL part of LIF structure.
Definition: lifutils.c:826
lif_B2S
MEMSPACE int lif_B2S(uint8_t *B, uint8_t *name, int size)
Convert LIF space padded string name into normal string.
Definition: lifutils.c:485
lif_rename_file
MEMSPACE int lif_rename_file(char *lifimagename, char *oldlifname, char *newlifname)
Rename LIF file in LIF image.
Definition: lifutils.c:2669
lif_help
MEMSPACE void lif_help(int full)
Help Menu for User invoked GPIB functions and tasks See: int gpib_tests(char *str)
Definition: lifutils.c:111
lif_create_volume
MEMSPACE lif_t * lif_create_volume(char *imagename, char *liflabel, long dirstart, long dirsectors, long filesectors)
Create LIF image with Volume, Directory and optional empty filespace.
Definition: lifutils.c:1062
lif_dump_vol
MEMSPACE void lif_dump_vol(lif_t *LIF, char *msg)
Dump LIF struture data for debugging.
Definition: lifutils.c:836
lif_lifbcd2time
MEMSPACE time_t lif_lifbcd2time(uint8_t *bcd)
convert BCD date into time_t value The BCD year is only the lower 2 digits of the year So We assume t...
Definition: lifutils.c:724
lif_read
MEMSPACE long lif_read(lif_t *LIF, void *buf, long offset, int bytes)
Read data from a LIF image Displays message on errors.
Definition: lifutils.c:396