static int is_vfat(int fd) { unsigned char buf[2]; /* No consistent 'magic' in FAT32, but some fields * have fixed values (always little-endian) in all but * very obscure cases */ /* Check signature */ if (seek_and_read(fd, 0x1FE, buf, 2)) return 0; if (buf[0] != 0x55 || buf[1] != 0xAA) return 0; /* Check number of FATs, should be 2 */ if (seek_and_read(fd, 0x10, buf, 1)) return 0; if (buf[0] != 2) return 0; /* Check bytes per sector, should be 512 */ if (seek_and_read(fd, 0x0B, buf, 2)) return 0; if (buf[0] != 0x00 || buf[1] != 0x02) return 0; return 1; }
static int is_iso9660(int fd) { unsigned char buf[5]; /* Check for ISO9660 magic value */ if (seek_and_read(fd, 16 * 2048 + 1, buf, 5)) return 0; if (!memcmp(buf, "CD001", 5)) return 1; return 0; }
/*-------------------------------------------------------------------------- * read_chunk * reads a chunk from the input files into a_chunk, the position of the * chunk is specified by chunk_no *-------------------------------------------------------------------------- */ static void read_chunk(int chunk_no[], int C[], char a_chunk[], int srcfd, int n, int baseSize, int PX[], int dist[]) { int i, j, cp, unit_transfer; int start_pos, pos[MAXDIM]; int indx[MAXDIM]; int fpOff; for ( i = start_pos = 0; i < n; i++) { pos[i] = chunk_no[i] * C[i]; start_pos += pos[i]*PX[i]; } start_pos *= baseSize; /* Read a block of dimesion C starting at co-ordinates pos */ unit_transfer = C[n-1] * baseSize; for (i = 0; i < n; indx[i++] = 0) ; fpOff = start_pos; seek_and_read(fpOff, unit_transfer, a_chunk, srcfd, SEEK_SET); fpOff += unit_transfer; cp = unit_transfer; while ((j = next_tuple(n-1, indx, C)) != -1) { fpOff += dist[j]; seek_and_read(fpOff, unit_transfer, &(a_chunk[cp]), srcfd, SEEK_SET); cp += unit_transfer; fpOff += unit_transfer; } }
static const char *is_extN(int fd) { struct ext2_super_block sb; if (seek_and_read(fd, 1024, &sb, sizeof(sb))) return 0; if (sb.s_magic != EXT2_SUPER_MAGIC) return 0; /* no journal? */ if (!(sb.s_feature_compat & EXT3_FEATURE_COMPAT_HAS_JOURNAL)) return "ext2"; /* small INCOMPAT? */ if (sb.s_feature_incompat < EXT3_FEATURE_INCOMPAT_EXTENTS && /* and small RO_COMPAT? */ sb.s_feature_ro_compat < EXT4_FEATURE_RO_COMPAT_HUGE_FILE) return "ext3"; return "ext4"; }
void in_place_stream::_calc_send () { // // refer to <<In-Place Rsync: File Synchronization for Mobile and Wireless Devices>> // to get the algorithm details. // typedef std::list<equal_node*>::iterator it_t; std::list<equal_node*> result; std::set<equal_node *> enode_set; std::copy (equal_nodes_.begin (), equal_nodes_.end () , std::inserter (enode_set, enode_set.end ())); for (it_t pos = equal_nodes_.begin (); pos != equal_nodes_.end (); ++pos) _handle_node (enode_set, *pos, result); for (it_t pos = result.begin (); pos != result.end (); ++pos) { equal_node * node = *pos; assert (node->tpos.t_offset == 0); // // 对于没有移动的块,不需要发送,可以节省一些传输成本,对于只更改不插入的文件 // 这会带来直接的优势。并且在重新构造文件时,因为移动更少的数据,因此会有直接的性能提升。 // if (node->tpos.index * node->blength != node->s_offset) output_.add_block (node->tpos, node->blength, node->s_offset); } reader_.open_file (); for (std::list<diff_node>::iterator pos = diff_nodes_.begin () ; pos != diff_nodes_.end (); ++pos) { const diff_node & node = *pos; seek_and_read (reader_, node.s_offset, node.blength, buff_.begin ()); output_.add_block (buff_.begin (), node.blength, node.s_offset); } reader_.close_file (); return; }