Rev 3535 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3535 | Rev 3561 | ||
---|---|---|---|
Line 34... | Line 34... | ||
34 | import os |
34 | import os |
35 | import random |
35 | import random |
36 | import xstruct |
36 | import xstruct |
37 | import array |
37 | import array |
38 | 38 | ||
- | 39 | exclude_names = set(['.svn']) |
|
- | 40 | ||
39 | def align_up(size, alignment): |
41 | def align_up(size, alignment): |
40 | "Return size aligned up to alignment" |
42 | "Return size aligned up to alignment" |
41 | 43 | ||
42 | if (size % alignment == 0): |
44 | if (size % alignment == 0): |
43 | return size |
45 | return size |
Line 51... | Line 53... | ||
51 | files = 2 |
53 | files = 2 |
52 | 54 | ||
53 | for name in os.listdir(root): |
55 | for name in os.listdir(root): |
54 | canon = os.path.join(root, name) |
56 | canon = os.path.join(root, name) |
55 | 57 | ||
56 | if (os.path.isfile(canon)): |
58 | if (os.path.isfile(canon) and (not name in exclude_names)): |
57 | size += align_up(os.path.getsize(canon), cluster_size) |
59 | size += align_up(os.path.getsize(canon), cluster_size) |
58 | files += 1 |
60 | files += 1 |
59 | 61 | ||
60 | if (os.path.isdir(canon)): |
62 | if (os.path.isdir(canon) and (not name in exclude_names)): |
61 | size += subtree_size(canon, cluster_size, dirent_size) |
63 | size += subtree_size(canon, cluster_size, dirent_size) |
62 | files += 1 |
64 | files += 1 |
63 | 65 | ||
64 | return size + align_up(files * dirent_size, cluster_size) |
66 | return size + align_up(files * dirent_size, cluster_size) |
65 | 67 | ||
Line 284... | Line 286... | ||
284 | empty_cluster = 0 |
286 | empty_cluster = 0 |
285 | 287 | ||
286 | for name in os.listdir(root): |
288 | for name in os.listdir(root): |
287 | canon = os.path.join(root, name) |
289 | canon = os.path.join(root, name) |
288 | 290 | ||
289 | if (os.path.isfile(canon)): |
291 | if (os.path.isfile(canon) and (not name in exclude_names)): |
290 | rv = write_file(canon, outf, cluster_size, data_start, fat, reserved_clusters) |
292 | rv = write_file(canon, outf, cluster_size, data_start, fat, reserved_clusters) |
291 | directory.append(create_dirent(name, False, rv[0], rv[1])) |
293 | directory.append(create_dirent(name, False, rv[0], rv[1])) |
292 | 294 | ||
293 | if (os.path.isdir(canon)): |
295 | if (os.path.isdir(canon) and (not name in exclude_names)): |
294 | rv = recursion(False, canon, outf, cluster_size, root_start, data_start, fat, reserved_clusters, dirent_size, empty_cluster) |
296 | rv = recursion(False, canon, outf, cluster_size, root_start, data_start, fat, reserved_clusters, dirent_size, empty_cluster) |
295 | directory.append(create_dirent(name, True, rv[0], rv[1])) |
297 | directory.append(create_dirent(name, True, rv[0], rv[1])) |
296 | 298 | ||
297 | if (head): |
299 | if (head): |
298 | outf.seek(root_start) |
300 | outf.seek(root_start) |
Line 349... | Line 351... | ||
349 | if (not os.path.isdir(path)): |
351 | if (not os.path.isdir(path)): |
350 | print "<PATH> must be a directory" |
352 | print "<PATH> must be a directory" |
351 | return |
353 | return |
352 | 354 | ||
353 | fat16_clusters = 4096 |
355 | fat16_clusters = 4096 |
354 | min_cluster_size = 1024 |
- | |
355 | 356 | ||
356 | sector_size = 512 |
357 | sector_size = 512 |
357 | cluster_size = 4096 |
358 | cluster_size = 4096 |
358 | dirent_size = 32 |
359 | dirent_size = 32 |
359 | fatent_size = 2 |
360 | fatent_size = 2 |
Line 361... | Line 362... | ||
361 | reserved_clusters = 2 |
362 | reserved_clusters = 2 |
362 | 363 | ||
363 | # Make sure the filesystem is large enought for FAT16 |
364 | # Make sure the filesystem is large enought for FAT16 |
364 | size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size |
365 | size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size |
365 | while (size / cluster_size < fat16_clusters): |
366 | while (size / cluster_size < fat16_clusters): |
366 | if (cluster_size > min_cluster_size): |
367 | if (cluster_size > sector_size): |
367 | cluster_size /= 2 |
368 | cluster_size /= 2 |
368 | size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size |
369 | size = subtree_size(path, cluster_size, dirent_size) + reserved_clusters * cluster_size |
369 | else: |
370 | else: |
370 | size = fat16_clusters * cluster_size + reserved_clusters * cluster_size |
371 | size = fat16_clusters * cluster_size + reserved_clusters * cluster_size |
371 | 372 |