FreeBSD/lib/libstand/dosfs.c
/*
 * Get next cluster in cluster chain. Use in core fat cache unless another
 * device replaced it.
 */
Get next cluster in cluster chain. Use in core fat cache unless another
device replaced it.
Get next cluster in cluster chain . Use in core fat cache unless another device replaced it .
static int
fatget(DOS_FS *fs, u_int *c)
{
    u_char buf[4];
    u_char *s;
    u_int x, offset, off, n, nbyte, lsec;
    struct devdesc *dd = fs->fd->f_devdata;
    int err = 0;
    if (fat.unit != dd->d_unit) {
	err = ioread(fs, secbyt(fs->lsnfat) + fatoff(fs->fatsz, *c), buf,
	    fs->fatsz != 32 ? 2 : 4);
	if (err)
	    return err;
    } else {
	offset = fatoff(fs->fatsz, *c);
	nbyte = fs->fatsz != 32 ? 2 : 4;
	s = buf;
	if ((off = offset & (SECSIZ - 1))) {
	    offset -= off;
	    lsec = bytsec(offset);
	    offset += SECSIZ;
	    if ((n = SECSIZ - off) > nbyte)
		n = nbyte;
	    memcpy(s, fat.buf + secbyt(lsec) + off, n);
	    s += n;
	    nbyte -= n;
	}
	n = nbyte & (SECSIZ - 1);
	if (nbyte -= n) {
	    memcpy(s, fat.buf + secbyt(bytsec(offset)), nbyte);
	    offset += nbyte;
	    s += nbyte;
	}
	if (n)
	    memcpy(s, fat.buf + secbyt(bytsec(offset)), n);
    }
    x = fs->fatsz != 32 ? cv2(buf) : cv4(buf);
    *c = fs->fatsz == 12 ? *c & 1 ? x >> 4 : x & 0xfff : x;
    return (0);
}
static int fatget ( DOS_FS * fs , u_int * c ) { u_char buf [ 4 ] ; u_char * s ; u_int x , offset , off , n , nbyte , lsec ; struct devdesc * dd = fs -> fd -> f_devdata ; int err = 0 ; if ( fat . unit != dd -> d_unit ) { err = ioread ( fs , secbyt ( fs -> lsnfat ) + fatoff ( fs -> fatsz , * c ) , buf , fs -> fatsz != 32 ? 2 : 4 ) ; if ( err ) return err ; } else { offset = fatoff ( fs -> fatsz , * c ) ; nbyte = fs -> fatsz != 32 ? 2 : 4 ; s = buf ; if ( ( off = offset & ( SECSIZ - 1 ) ) ) { offset -= off ; lsec = bytsec ( offset ) ; offset += SECSIZ ; if ( ( n = SECSIZ - off ) > nbyte ) n = nbyte ; memcpy ( s , fat . buf + secbyt ( lsec ) + off , n ) ; s += n ; nbyte -= n ; } n = nbyte & ( SECSIZ - 1 ) ; if ( nbyte -= n ) { memcpy ( s , fat . buf + secbyt ( bytsec ( offset ) ) , nbyte ) ; offset += nbyte ; s += nbyte ; } if ( n ) memcpy ( s , fat . buf + secbyt ( bytsec ( offset ) ) , n ) ; } x = fs -> fatsz != 32 ? cv2 ( buf ) : cv4 ( buf ) ; * c = fs -> fatsz == 12 ? * c & 1 ? x >> 4 : x & 0xfff : x ; return ( 0 ) ; }
Get next cluster in cluster chain.
Get next cluster in cluster chain .
/* fat cache was changed to another device, dont use it */