ms-sys  2.7.0
About: ms-sys writes Microsoft compatible boot records. Development version.
  Fossies Dox: ms-sys-2.7.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

partition_info.c
Go to the documentation of this file.
1 
18 #include <stdio.h>
19 
20 #include "file.h"
21 #include "fat16.h"
22 #include "fat32.h"
23 #include "exfat.h"
24 #include "ntfs.h"
25 #include "identify.h"
26 #include "partition_info.h"
27 
28 int write_partition_number_of_heads(FILE *fp, int iHeads)
29 {
30  unsigned char aucBuf[2];
31  unsigned short s = (iHeads < 0) ? partition_number_of_heads(fp) : (unsigned short)iHeads;
32 
33  if(!s)
34  return 0;
35  /* Converting a number like this is not necessary as long as we are on
36  i386 compatible CPUs, however, the following code might make the program
37  more portable... */
38  aucBuf[0] = (unsigned char)(s & 0xff);
39  aucBuf[1] = (unsigned char)((s & 0xff00) >> 8);
40  return write_data(fp, 0x1a, aucBuf, 2);
41 } /* write_partition_number_of_heads */
42 
43 #ifdef __OpenBSD__
44 int write_partition_start_sector_number(FILE *fp, const char *szPath)
45 #else
47 #endif
48 {
49 #ifdef __OpenBSD__
50  unsigned long l = partition_start_sector(fp, szPath);
51 #else
52  unsigned long l = partition_start_sector(fp);
53 #endif
54 
55  if(!l)
56  return 0;
57  /* Converting a number like this is not necessary as long as we are on
58  i386 compatible CPUs, however, the following code might make the program
59  more portable... */
60  if((is_fat_16_fs(fp)) || (is_fat_32_fs(fp)) || is_ntfs_fs(fp)) {
61  unsigned char aucBuf[4];
62  aucBuf[0] = (unsigned char)(l & 0xff);
63  aucBuf[1] = (unsigned char)((l & 0xff00) >> 8);
64  aucBuf[2] = (unsigned char)((l & 0xff0000) >> 16);
65  aucBuf[3] = (unsigned char)((l & 0xff000000) >> 24);
66  return write_data(fp, 0x1c, aucBuf, 4);
67  }
68  if(is_exfat_fs(fp)) {
69  unsigned char aucBuf[8];
70  aucBuf[0] = (unsigned char)(l & 0xff);
71  aucBuf[1] = (unsigned char)((l & 0xff00) >> 8);
72  aucBuf[2] = (unsigned char)((l & 0xff0000) >> 16);
73  aucBuf[3] = (unsigned char)((l & 0xff000000) >> 24);
74  aucBuf[4] = (unsigned char)((l & 0xff00000000) >> 32);
75  aucBuf[5] = (unsigned char)((l & 0xff0000000000) >> 40);
76  aucBuf[6] = (unsigned char)((l & 0xff000000000000) >> 48);
77  aucBuf[7] = (unsigned char)((l & 0xff00000000000000) >> 56);
78  return write_data(fp, 0x40, aucBuf, 8);
79  } else {
80  return 0;
81  }
82 } /* write_partition_start_sector_number */
83 
85 {
86  unsigned char ucId = 0x80; /* C: */
87 
88  return write_data(fp, 0x24, &ucId, 1);
89 } /* write_partition_physical_disk_drive_id_fat16 */
90 
92 {
93  unsigned char ucId = 0x80; /* C: */
94 
95  return write_data(fp, 0x40, &ucId, 1);
96 } /* write_partition_physical_disk_drive_id_fat32 */
97 
99 {
100  unsigned char ucId = 0x80; /* C: */
101 
102  return write_data(fp, 0x6f, &ucId, 1);
103 } /* write_partition_physical_disk_drive_id_exfat */
write_data
int write_data(FILE *fp, unsigned long ulPosition, const void *pData, unsigned int uiLen)
Definition: file.c:78
is_ntfs_fs
int is_ntfs_fs(FILE *fp)
Definition: ntfs.c:26
write_partition_physical_disk_drive_id_fat16
int write_partition_physical_disk_drive_id_fat16(FILE *fp)
Definition: partition_info.c:84
is_fat_32_fs
int is_fat_32_fs(FILE *fp)
Definition: fat32.c:24
write_partition_number_of_heads
int write_partition_number_of_heads(FILE *fp, int iHeads)
Definition: partition_info.c:28
partition_info.h
write_partition_start_sector_number
int write_partition_start_sector_number(FILE *fp)
Definition: partition_info.c:46
write_partition_physical_disk_drive_id_exfat
int write_partition_physical_disk_drive_id_exfat(FILE *fp)
Definition: partition_info.c:98
identify.h
is_exfat_fs
int is_exfat_fs(FILE *fp)
Definition: exfat.c:46
ntfs.h
fat16.h
partition_start_sector
unsigned long partition_start_sector(FILE *fp)
Definition: identify.c:226
partition_number_of_heads
unsigned short partition_number_of_heads(FILE *fp)
Definition: identify.c:315
fat32.h
file.h
is_fat_16_fs
int is_fat_16_fs(FILE *fp)
Definition: fat16.c:24
write_partition_physical_disk_drive_id_fat32
int write_partition_physical_disk_drive_id_fat32(FILE *fp)
Definition: partition_info.c:91
exfat.h