mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
zipl/src: Introduce misc_open_simulate() and misc_open_device()
Introduce misc_open_simulate() to mark individual files as "opened for write simulation". Introduce misc_open_device() to open a file either in "usual", or in "simulation" mode, depending on the passed argument Tested-by: Mikhail Zaslonko <zaslonko@linux.ibm.com> Reviewed-by: Mikhail Zaslonko <zaslonko@linux.ibm.com> Signed-off-by: Eduard Shishkin <edward6@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
b94566048b
commit
72218c5bc3
@@ -34,6 +34,8 @@ int misc_asprintf(char **out, const char *fmt, ...);
|
||||
void* misc_calloc(size_t n, size_t size);
|
||||
char* misc_strdup(const char* s);
|
||||
int misc_open_exclusive(const char* filename);
|
||||
int misc_open_simulate(const char *filename, struct misc_fd *mfd);
|
||||
int misc_open_device(const char *filename, struct misc_fd *mfd, int simulate);
|
||||
int misc_read(int fd, void* buffer, size_t count);
|
||||
int misc_read_file(const char* filename, char** buffer, size_t* size,
|
||||
int nil_terminate);
|
||||
|
||||
@@ -101,6 +101,35 @@ misc_open_exclusive(const char* filename)
|
||||
return fd;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open file FILENAME for write simulation
|
||||
*/
|
||||
int misc_open_simulate(const char *filename, struct misc_fd *mfd)
|
||||
{
|
||||
/*
|
||||
* In write simulation mode actual data are not written to the file,
|
||||
* so open it as read-only
|
||||
*/
|
||||
mfd->fd = open(filename, O_RDONLY);
|
||||
mfd->simulate_write = 1;
|
||||
if (mfd->fd == -1)
|
||||
error_reason(strerror(errno));
|
||||
return mfd->fd;
|
||||
}
|
||||
|
||||
int misc_open_device(const char *filename, struct misc_fd *mfd, int simulate)
|
||||
{
|
||||
if (simulate) {
|
||||
/*
|
||||
* open the file for "write simulation", when actual
|
||||
* data are not written, and only current position in
|
||||
* the file is updated
|
||||
*/
|
||||
return misc_open_simulate(filename, mfd);
|
||||
}
|
||||
mfd->fd = misc_open_exclusive(filename);
|
||||
return mfd->fd;
|
||||
}
|
||||
|
||||
/* Read COUNT bytes of data from file identified by file descriptor FD to
|
||||
* memory at location BUFFER. Return 0 when all bytes were successfully read,
|
||||
|
||||
Reference in New Issue
Block a user