ReactOS 0.4.16-dev-297-gc569aee
io.h File Reference
#include <fcntl.h>
Include dependency graph for io.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void fs_open (char *path, int rw)
 
void fs_read (off_t pos, int size, void *data)
 
int fs_test (off_t pos, int size)
 
void fs_write (off_t pos, int size, void *data)
 
int fs_close (int write)
 
int fs_changed (void)
 

Function Documentation

◆ fs_changed()

int fs_changed ( void  )

Definition at line 475 of file io.c.

476{
477 return ! !changes || did_change;
478}
static CHANGE * changes
Definition: io.c:49
static int did_change
Definition: io.c:51

Referenced by VfatChkdsk().

◆ fs_close()

int fs_close ( int  write)

Definition at line 455 of file io.c.

456{
457 CHANGE *next;
458 int changed;
459
460 changed = ! !changes;
461 if (write)
462 fs_flush();
463 else
464 while (changes) {
465 next = changes->next;
466 free(changes->data);
467 free(changes);
468 changes = next;
469 }
470 if (close(fd) < 0)
471 pdie("closing filesystem");
472 return changed || did_change;
473}
#define close
Definition: acwin.h:98
#define write
Definition: acwin.h:97
#define free
Definition: debug_ros.c:5
static unsigned __int64 next
Definition: rand_nt.c:6
void pdie(const char *msg,...)
Definition: common.c:74
static int fd
Definition: io.c:51
static void fs_flush(void)
Definition: io.c:409
Definition: io.c:42
struct _change * next
Definition: io.c:46
void * data
Definition: io.c:43

◆ fs_open()

void fs_open ( char path,
int  rw 
)

Definition at line 163 of file io.c.

164{
165 if ((fd = open(path, rw ? O_RDWR : O_RDONLY)) < 0) {
166 perror("open");
167 exit(6);
168 }
169 changes = last = NULL;
170 did_change = 0;
171}
#define O_RDONLY
Definition: acwin.h:108
#define open
Definition: acwin.h:95
#define NULL
Definition: types.h:112
#define O_RDWR
Definition: fcntl.h:36
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
#define rw
Definition: rosglue.h:38
#define exit(n)
Definition: config.h:202
static CHANGE * last
Definition: io.c:49

◆ fs_read()

void fs_read ( off_t  pos,
int  size,
void data 
)

Read data from the partition, accounting for any pending updates that are queued for writing.

Parameters
[in]posByte offset, relative to the beginning of the partition, at which to read
[in]sizeNumber of bytes to read
[out]dataWhere to put the data read

Definition at line 282 of file io.c.

283{
284 CHANGE *walk;
285 int got;
286
287#ifdef __REACTOS__
288 const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size;
289 const off_t seekpos_aligned = pos - (pos % 512);
290 const size_t seek_delta = (size_t)(pos - seekpos_aligned);
291#if DBG
292 const size_t readsize = (size_t)(pos - seekpos_aligned) + readsize_aligned;
293#endif
294 char* tmpBuf = alloc(readsize_aligned);
295 if (lseek(fd, seekpos_aligned, 0) != seekpos_aligned) pdie("Seek to %lld",pos);
296 if ((got = read(fd, tmpBuf, readsize_aligned)) < 0) pdie("Read %d bytes at %lld",size,pos);
297 assert(got >= size);
298 got = size;
299 assert(seek_delta + size <= readsize);
300 memcpy(data, tmpBuf+seek_delta, size);
301 free(tmpBuf);
302#else
303 if (lseek(fd, pos, 0) != pos)
304 pdie("Seek to %lld", (long long)pos);
305 if ((got = read(fd, data, size)) < 0)
306 pdie("Read %d bytes at %lld", size, (long long)pos);
307#endif
308 if (got != size)
309 die("Got %d bytes instead of %d at %lld", got, size, (long long)pos);
310 for (walk = changes; walk; walk = walk->next) {
311 if (walk->pos < pos + size && walk->pos + walk->size > pos) {
312 if (walk->pos < pos)
313 memcpy(data, (char *)walk->data + pos - walk->pos,
314 min(size, walk->size - pos + walk->pos));
315 else
316 memcpy((char *)data + walk->pos - pos, walk->data,
317 min(walk->size, size + pos - walk->pos));
318 }
319 }
320}
#define read
Definition: acwin.h:96
#define assert(x)
Definition: debug.h:53
__kernel_size_t size_t
Definition: linux.h:237
__kernel_off_t off_t
Definition: linux.h:201
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
#define lseek
Definition: syshdrs.h:47
#define die(str)
Definition: mkdosfs.c:347
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define min(a, b)
Definition: monoChain.cc:55
#define alloc
Definition: rosglue.h:13
int size
Definition: io.c:45
off_t pos
Definition: io.c:44

Referenced by add_file(), alloc_rootdir_entry(), check_backup_boot(), find_volume_de(), read_boot(), read_fat(), read_fsinfo(), and write_boot_label().

◆ fs_test()

int fs_test ( off_t  pos,
int  size 
)

Definition at line 322 of file io.c.

323{
324 void *scratch;
325 int okay;
326
327#ifdef __REACTOS__
328 const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size; // TMN:
329 const off_t seekpos_aligned = pos - (pos % 512); // TMN:
330 scratch = alloc(readsize_aligned);
331 if (lseek(fd, seekpos_aligned, 0) != seekpos_aligned) pdie("Seek to %lld",pos);
332 okay = read(fd, scratch, readsize_aligned) == (int)readsize_aligned;
333 free(scratch);
334#else
335 if (lseek(fd, pos, 0) != pos)
336 pdie("Seek to %lld", (long long)pos);
337 scratch = alloc(size);
338 okay = read(fd, scratch, size) == size;
339 free(scratch);
340#endif
341 return okay;
342}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by fix_bad(), read_boot(), and test_file().

◆ fs_write()

void fs_write ( off_t  pos,
int  size,
void data 
)

Definition at line 344 of file io.c.

345{
346 CHANGE *new;
347 int did;
348
349#ifdef __REACTOS__
351
353 void *scratch;
354 const size_t readsize_aligned = (size % 512) ? (size + (512 - (size % 512))) : size;
355 const off_t seekpos_aligned = pos - (pos % 512);
356 const size_t seek_delta = (size_t)(pos - seekpos_aligned);
357 BOOLEAN use_read = (seek_delta != 0) || ((readsize_aligned-size) != 0);
358
359 /* Aloc temp buffer if write is not aligned */
360 if (use_read)
361 scratch = alloc(readsize_aligned);
362 else
363 scratch = data;
364
365 did_change = 1;
366 if (lseek(fd, seekpos_aligned, 0) != seekpos_aligned) pdie("Seek to %lld",seekpos_aligned);
367
368 if (use_read)
369 {
370 /* Read aligned data */
371 if (read(fd, scratch, readsize_aligned) < 0) pdie("Read %d bytes at %lld",size,pos);
372
373 /* Patch data in memory */
374 memcpy((char *)scratch + seek_delta, data, size);
375 }
376
377 /* Write it back */
378 if ((did = write(fd, scratch, readsize_aligned)) == (int)readsize_aligned)
379 {
380 if (use_read) free(scratch);
381 return;
382 }
383 if (did < 0) pdie("Write %d bytes at %lld", size, pos);
384 die("Wrote %d bytes instead of %d at %lld", did, size, pos);
385 }
386#else
387 if (write_immed) {
388 did_change = 1;
389 if (lseek(fd, pos, 0) != pos)
390 pdie("Seek to %lld", (long long)pos);
391 if ((did = write(fd, data, size)) == size)
392 return;
393 if (did < 0)
394 pdie("Write %d bytes at %lld", size, (long long)pos);
395 die("Wrote %d bytes instead of %d at %lld", did, size, (long long)pos);
396 }
397#endif
398 new = alloc(sizeof(CHANGE));
399 new->pos = pos;
400 memcpy(new->data = alloc(new->size = size), data, size);
401 new->next = NULL;
402 if (last)
403 last->next = new;
404 else
405 changes = new;
406 last = new;
407}
unsigned char BOOLEAN
ULONG FsCheckFlags
Definition: vfatlib.c:44
#define FSCHECK_IMMEDIATE_WRITE
Definition: rosglue.h:28
#define interactive
Definition: rosglue.h:34
#define write_immed
Definition: rosglue.h:39
#define new(TYPE, numElems)
Definition: treelist.c:54

Referenced by add_file(), alloc_rootdir_entry(), auto_rename(), check_backup_boot(), check_fat_state_bit(), clear_lfn_slots(), fs_flush(), lfn_add_slot(), lfn_fix_checksum(), lfn_get(), lfn_remove(), read_fat(), read_fsinfo(), reclaim_file(), rename_file(), set_fat(), update_free(), write_boot_label(), and write_volume_label().