aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-05-19 16:48:19 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-05-19 16:48:19 -0700
commit43b3ae31727836ef0e9c7348fa98c462a47b52aa (patch)
tree00ff02577f0e298c96bb523cbe755e0a99657aa2
parent0fa4369624b4637a7e36ed22e89a759031f08327 (diff)
downloadsyslinux-43b3ae31727836ef0e9c7348fa98c462a47b52aa.tar.gz
syslinux-43b3ae31727836ef0e9c7348fa98c462a47b52aa.tar.xz
syslinux-43b3ae31727836ef0e9c7348fa98c462a47b52aa.zip
Standardize the names SECTOR_SIZE and SECTOR_SHIFT
Use the names SECTOR_SIZE and SECTOR_SHIFT everywhere, instead of an odd mix of symbols and hard-coded constants. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--dos/syslinux.c14
-rw-r--r--extlinux/main.c8
-rw-r--r--libinstaller/syslinux.h4
-rw-r--r--libinstaller/syslxmod.c7
-rw-r--r--linux/syslinux.c12
-rw-r--r--mtools/syslinux.c16
-rw-r--r--win32/syslinux.c14
7 files changed, 38 insertions, 37 deletions
diff --git a/dos/syslinux.c b/dos/syslinux.c
index 047dc8f8..ecb7c07e 100644
--- a/dos/syslinux.c
+++ b/dos/syslinux.c
@@ -462,7 +462,7 @@ struct mbr_entry {
static void adjust_mbr(int device, int writembr, int set_active)
{
- static unsigned char sectbuf[512];
+ static unsigned char sectbuf[SECTOR_SIZE];
int i;
if ( !writembr && !set_active )
@@ -502,7 +502,7 @@ static void adjust_mbr(int device, int writembr, int set_active)
int main(int argc, char *argv[])
{
- static unsigned char sectbuf[512];
+ static unsigned char sectbuf[SECTOR_SIZE];
int dev_fd, fd;
static char ldlinux_name[] = "@:\\ldlinux.sys";
char **argp, *opt;
@@ -614,7 +614,7 @@ int main(int argc, char *argv[])
* this is supposed to be a simple, privileged version
* of the installer.
*/
- ldlinux_sectors = (syslinux_ldlinux_len+SECTOR_SIZE-1) >> SECTOR_BITS;
+ ldlinux_sectors = (syslinux_ldlinux_len+SECTOR_SIZE-1) >> SECTOR_SHIFT;
sectors = calloc(ldlinux_sectors, sizeof *sectors);
lock_device(2);
fs = libfat_open(libfat_xpread, dev_fd);
@@ -676,7 +676,7 @@ int main(int argc, char *argv[])
* Patch ldlinux.sys and the boot sector
*/
i = syslinux_patch(sectors, nsectors, stupid, raid_mode);
- patch_sectors = (i + 511) >> 9;
+ patch_sectors = (i+SECTOR_SIZE-1) >> SECTOR_SHIFT;
/*
* Overwrite the now-patched ldlinux.sys
@@ -686,10 +686,10 @@ int main(int argc, char *argv[])
uint16_t si, di, cx;
si = 0;
di = (size_t)sectbuf;
- cx = 512 >> 2;
+ cx = SECTOR_SIZE >> 2;
asm volatile("movw %3,%%fs ; fs ; rep ; movsl"
: "+S" (si), "+D" (di), "+c" (cx)
- : "abd" ((uint16_t)(ldlinux_seg + (i << (9-4)))));
+ : "abd" ((uint16_t)(ldlinux_seg + (i << (SECTOR_SHIFT-4)))));
write_device(dev_fd, sectbuf, 1, sectors[i]);
}
@@ -712,7 +712,7 @@ int main(int argc, char *argv[])
if ( bootsecfile ) {
unlock_device(0);
fd = creat(bootsecfile, 0x20); /* ARCHIVE */
- write_file(fd, sectbuf, 512);
+ write_file(fd, sectbuf, SECTOR_SIZE);
close(fd);
} else {
write_device(dev_fd, sectbuf, 1, 0);
diff --git a/extlinux/main.c b/extlinux/main.c
index 79123c9d..c4ccd538 100644
--- a/extlinux/main.c
+++ b/extlinux/main.c
@@ -233,7 +233,7 @@ sectmap(int fd, uint32_t *sectors, int nsectors)
return -1;
/* Number of sectors per block */
- blksize >>= SECTOR_BITS;
+ blksize >>= SECTOR_SHIFT;
nblk = 0;
while ( nsectors ) {
@@ -336,7 +336,7 @@ get_geometry(int devfd, uint64_t totalbytes, struct hd_geometry *geo)
geo->heads = opt.heads ?: 64;
geo->sectors = opt.sectors ?: 32;
- geo->cylinders = totalbytes/(geo->heads*geo->sectors << SECTOR_BITS);
+ geo->cylinders = totalbytes/(geo->heads*geo->sectors << SECTOR_SHIFT);
geo->start = 0;
if ( !opt.sectors && !opt.heads )
@@ -386,7 +386,7 @@ patch_file_and_bootblock(int fd, int dirfd, int devfd)
bs = (struct boot_sector *)boot_block;
- totalsectors = totalbytes >> SECTOR_BITS;
+ totalsectors = totalbytes >> SECTOR_SHIFT;
if ( totalsectors >= 65536 ) {
set_16(&bs->bsSectors, 0);
} else {
@@ -410,7 +410,7 @@ patch_file_and_bootblock(int fd, int dirfd, int devfd)
/* Construct the boot file */
dprintf("directory inode = %lu\n", (unsigned long) dirst.st_ino);
- nsect = (boot_image_len+SECTOR_SIZE-1) >> SECTOR_BITS;
+ nsect = (boot_image_len+SECTOR_SIZE-1) >> SECTOR_SHIFT;
nsect += 2; /* Two sectors for the ADV */
sectp = alloca(sizeof(uint32_t)*nsect);
if ( sectmap(fd, sectp, nsect) ) {
diff --git a/libinstaller/syslinux.h b/libinstaller/syslinux.h
index e0554255..902beaf9 100644
--- a/libinstaller/syslinux.h
+++ b/libinstaller/syslinux.h
@@ -30,8 +30,8 @@ extern const unsigned int syslinux_mbr_len;
extern const int syslinux_mbr_mtime;
/* Sector size assumptions... */
-#define SECTOR_BITS 9
-#define SECTOR_SIZE (1 << SECTOR_BITS)
+#define SECTOR_SHIFT 9
+#define SECTOR_SIZE (1 << SECTOR_SHIFT)
/* This takes a boot sector and merges in the syslinux fields */
void syslinux_make_bootsect(void *);
diff --git a/libinstaller/syslxmod.c b/libinstaller/syslxmod.c
index 78e226c4..969ce8b3 100644
--- a/libinstaller/syslxmod.c
+++ b/libinstaller/syslxmod.c
@@ -56,10 +56,11 @@ const char *syslinux_check_bootsect(const void *bs)
goto invalid;
sectorsize = get_16(&sectbuf->bsBytesPerSec);
- if ( sectorsize == 512 )
+ if ( sectorsize == SECTOR_SIZE )
; /* ok */
- else if ( sectorsize == 1024 || sectorsize == 2048 || sectorsize == 4096 )
- return "only 512-byte sectors are supported";
+ else if ( sectorsize >= 512 && sectorsize <= 4096 &&
+ (sectorsize & (sectorsize-1)) == 0 )
+ return "unsupported sectors size";
else
goto invalid;
diff --git a/linux/syslinux.c b/linux/syslinux.c
index e1b464ec..10c089c0 100644
--- a/linux/syslinux.c
+++ b/linux/syslinux.c
@@ -53,7 +53,7 @@
# define FAT_IOCTL_SET_ATTRIBUTES _IOW('r', 0x11, uint32_t)
#endif
#undef SECTOR_SIZE
-#undef SECTOR_BITS
+#undef SECTOR_SHIFT
#include <paths.h>
#ifndef _PATH_MOUNT
@@ -176,7 +176,7 @@ int make_block_map(uint32_t *sectors, int len, int dev_fd, int fd)
if (ioctl(fd, FIGETBSZ, &blocksize) < 0)
die("ioctl FIGETBSZ failed");
- blocksize >>= SECTOR_BITS; /* sectors/block */
+ blocksize >>= SECTOR_SHIFT; /* sectors/block */
nblock = 0;
while (len > 0) {
@@ -190,7 +190,7 @@ int make_block_map(uint32_t *sectors, int len, int dev_fd, int fd)
*sectors++ = (block*blocksize)+i;
nsectors++;
- len -= (1 << SECTOR_BITS);
+ len -= (1 << SECTOR_SHIFT);
}
}
@@ -519,7 +519,7 @@ int main(int argc, char *argv[])
/*
* Create a block map.
*/
- ldlinux_sectors = (syslinux_ldlinux_len+SECTOR_SIZE-1) >> SECTOR_BITS;
+ ldlinux_sectors = (syslinux_ldlinux_len+SECTOR_SIZE-1) >> SECTOR_SHIFT;
sectors = calloc(ldlinux_sectors, sizeof *sectors);
nsectors = make_block_map(sectors, syslinux_ldlinux_len, dev_fd, fd);
@@ -538,14 +538,14 @@ umount:
* Patch ldlinux.sys and the boot sector
*/
i = syslinux_patch(sectors, nsectors, stupid, raid_mode);
- patch_sectors = (i + SECTOR_SIZE - 1) >> SECTOR_BITS;
+ patch_sectors = (i + SECTOR_SIZE - 1) >> SECTOR_SHIFT;
/*
* Write the now-patched first sectors of ldlinux.sys
*/
for (i = 0; i < patch_sectors; i++) {
xpwrite(dev_fd, syslinux_ldlinux + i*SECTOR_SIZE, SECTOR_SIZE,
- filesystem_offset+((off_t)sectors[i] << SECTOR_BITS));
+ filesystem_offset+((off_t)sectors[i] << SECTOR_SHIFT));
}
/*
diff --git a/mtools/syslinux.c b/mtools/syslinux.c
index 8ddf42ec..b2a28bd3 100644
--- a/mtools/syslinux.c
+++ b/mtools/syslinux.c
@@ -124,7 +124,7 @@ int libfat_xpread(intptr_t pp, void *buf, size_t secsize, libfat_sector_t sector
int main(int argc, char *argv[])
{
- static unsigned char sectbuf[512];
+ static unsigned char sectbuf[SECTOR_SIZE];
int dev_fd;
struct stat st;
int status;
@@ -200,7 +200,7 @@ int main(int argc, char *argv[])
exit(1);
}
- xpread(dev_fd, sectbuf, 512, filesystem_offset);
+ xpread(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
/*
* Check to see that what we got was indeed an MS-DOS boot sector/superblock
@@ -250,7 +250,7 @@ int main(int argc, char *argv[])
/*
* Now, use libfat to create a block map
*/
- ldlinux_sectors = (syslinux_ldlinux_len+SECTOR_SIZE-1) >> SECTOR_BITS;
+ ldlinux_sectors = (syslinux_ldlinux_len+SECTOR_SIZE-1) >> SECTOR_SHIFT;
sectors = calloc(ldlinux_sectors, sizeof *sectors);
fs = libfat_open(libfat_xpread, dev_fd);
ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL);
@@ -266,12 +266,12 @@ int main(int argc, char *argv[])
/* Patch ldlinux.sys and the boot sector */
i = syslinux_patch(sectors, nsectors, stupid, raid_mode);
- patch_sectors = (i + 511) >> 9;
+ patch_sectors = (i+SECTOR_SIZE-1) >> SECTOR_SHIFT;
/* Write the now-patched first sectors of ldlinux.sys */
for (i = 0; i < patch_sectors; i++) {
- xpwrite(dev_fd, syslinux_ldlinux + i*512, 512,
- filesystem_offset + ((off_t)sectors[i] << 9));
+ xpwrite(dev_fd, syslinux_ldlinux + i*SECTOR_SIZE, SECTOR_SIZE,
+ filesystem_offset + ((off_t)sectors[i] << SECTOR_SHIFT));
}
/* Move ldlinux.sys to the desired location */
@@ -343,13 +343,13 @@ int main(int argc, char *argv[])
*/
/* Read the superblock again since it might have changed while mounted */
- xpread(dev_fd, sectbuf, 512, filesystem_offset);
+ xpread(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
/* Copy the syslinux code into the boot sector */
syslinux_make_bootsect(sectbuf);
/* Write new boot sector */
- xpwrite(dev_fd, sectbuf, 512, filesystem_offset);
+ xpwrite(dev_fd, sectbuf, SECTOR_SIZE, filesystem_offset);
close(dev_fd);
sync();
diff --git a/win32/syslinux.c b/win32/syslinux.c
index 7a0fafb2..9b74b8b5 100644
--- a/win32/syslinux.c
+++ b/win32/syslinux.c
@@ -244,7 +244,7 @@ int main(int argc, char *argv[])
DWORD drives;
UINT drive_type;
- static unsigned char sectbuf[512];
+ static unsigned char sectbuf[SECTOR_SIZE];
char **argp, *opt;
static char drive_name[] = "\\\\.\\?:";
static char drive_root[] = "?:\\";
@@ -361,11 +361,11 @@ int main(int argc, char *argv[])
/*
* Make sure we can read the boot sector
*/
- if ( !ReadFile(d_handle, sectbuf, 512, &bytes_read, NULL) ) {
+ if ( !ReadFile(d_handle, sectbuf, SECTOR_SIZE, &bytes_read, NULL) ) {
error("Reading boot sector");
exit(1);
}
- if (bytes_read != 512) {
+ if (bytes_read != SECTOR_SIZE) {
fprintf(stderr, "Could not read the whole boot sector\n");
exit(1);
}
@@ -415,7 +415,7 @@ int main(int argc, char *argv[])
}
/* Map the file (is there a better way to do this?) */
- ldlinux_sectors = (syslinux_ldlinux_len+SECTOR_SIZE-1) >> SECTOR_BITS;
+ ldlinux_sectors = (syslinux_ldlinux_len+SECTOR_SIZE-1) >> SECTOR_SHIFT;
sectors = calloc(ldlinux_sectors, sizeof *sectors);
fs = libfat_open(libfat_readfile, (intptr_t)d_handle);
ldlinux_cluster = libfat_searchdir(fs, 0, "LDLINUX SYS", NULL);
@@ -520,17 +520,17 @@ int main(int argc, char *argv[])
error("Unable to create bootsector file");
exit(1);
}
- if (!WriteFile(f_handle, sectbuf, 512, &bytes_written, NULL)) {
+ if (!WriteFile(f_handle, sectbuf, SECTOR_SIZE, &bytes_written, NULL)) {
error("Could not write boot sector file");
exit(1);
}
CloseHandle(f_handle);
} else {
SetFilePointer(d_handle, 0, NULL, FILE_BEGIN);
- WriteFile( d_handle, sectbuf, 512, &bytes_written, NULL ) ;
+ WriteFile( d_handle, sectbuf, SECTOR_SIZE, &bytes_written, NULL ) ;
}
- if(bytes_written != 512) {
+ if(bytes_written != SECTOR_SIZE) {
fprintf(stderr, "Could not write the whole boot sector\n");
exit(1);
}