aboutsummaryrefslogtreecommitdiffstats
path: root/doc/ioctl.doc
blob: 77c9f9660d60bc8a8136bbefa29cd7d571902db6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
DMSDOS ioctl commands (outdated.... newers are missing here)

*****************************************************************************
WARNING: INFORMATION IN THIS FILE IS OUTDATED AND PARTIALLY WRONG. SEE THE
         DMSDOS UTILITIES SOURCE CODE FOR PROGRAMMING EXAMPLES.

         When I have enough time I write better documentation.....
*****************************************************************************

Example code:

  #include<stdio.h>
  #include<linux/dmsdos_fs.h>
  #include<sys/ioctl.h>
  #include<sys/types.h>
  #include<sys/stat.h>
  #include<fcntl.h>
  #include<string.h>
  #include<errno.h>

  Dblsb dblsb;
  int fd;
  int ret;
  unsigned long w[10];
  Mdfat_entry mde;

  /* open file descriptor fd */
  fd=open(CVF_name,O_RDONLY);
  if(fd<0)
  { printf("No such file or directory.\n");
    return;
  }

DMSDOS_GET_DBLSB:
read DMSDOS version number and read CVF parameters in dblsb structure.
This function also performs a version check, i.e. if the dmsdos driver in
the kernel thinks the version number you supply in s_dcluster is too old, 
it "or"s the returned value with 0x0f000000 and doesn't fill in the values
for the dblsb structure.

** Since not all DMSDOS versions support all commands, this ioctl should be
always issued first **

  dblsb.s_dcluster=DMSDOS_VERSION;  
  ret=ioctl(fd,DMSDOS_GET_DBLSB,&dblsb);
  if(ret<0)
  { printf("This is not a DMSDOS directory.\n");
    exit(1);
  }
  printf("You are running DMSDOS Version %d.%d.%d.\n\n",(ret&0xff0000)>>16,
         (ret&0x00ff00)>>8,ret&0xff);
  if(ret&0x0f000000)
  { printf("This program is too old for the DMSDOS version you are running.\n");
    exit(1);
  }

  dblsb structure see dmsdos.h.

DMSDOS_READ_BITFAT:
read bitfat entry
w[0]=sectornr; returns 0 in w[1] if sector free

  ret=ioctl(fd,DMSDOS_READ_BITFAT,w);
  if(ret<0)error.....;

DMSDOS_WRITE_BITFAT:
write bitfat entry
w[0]=sectornr, w[1]=new value (0=free, 1=allocated)

  ret=ioctl(fd,DMSDOS_WRITE_BITFAT,w);
  if(ret<0)error.....;

DMSDOS_READ_MDFAT:
read mdfat entry
w[0]=clusternr; returns result in mde structure.

  w[1]=&mde;
  ret=ioctl(fd,DMSDOS_READ_MDFAT,w);
  if(ret<0)error......;
  
DMSDOS_WRITE_MDFAT:
write mdfat entry
w[0]=clusternr; mde=new mdfat entry value.
  
  w[1]=&mde;
  ret=ioctl(fd,DMSDOS_WRITE_MDFAT,w);
  if(ret<0)error......;

raw MDFAT entry: 32/40 bit number (hidden to the user)

  dos 6.x, Win95 without drivespace 3:
  3322222222221111111111
  10987654321098765432109876543210 
  ucaaaammmm?sssssssssssssssssssss

  Win95 with drivespace 3:
  33333333322222222221111111111
  9876543210987654321098765432109876543210 
  ucaaaaaammmmmm??ssssssssssssssssssssssss

Mdfat_entry structure: (the dmsdos driver automatically converts it to the
                        appropriate 32 or 40 bit number)

  mde.sector_minus_1= ('ssss...' bits)
  mde.size_lo_minus_1= ('mmmmmm' bits)
  mde.size_hi_minus_1= ('aaaaaa' bits)
  mde.flags= ('uc' bits)
  mde.unknown= ('?' bit(s)), are NOT written, always set to zero
  
  u: 1=entry is used, 0=entry is free
  c: 1=cluster is uncompressed, 0=cluster is compressed
  a: uncompressed size minus 1 (number of sectors belonging to this cluster)
  m: compressed size minus 1 (      "      "        "          )
  ?: unknown, but seem(s) to be used sometimes
  s: sector number minus 1 (theoretical 2 GB limit)
     The sector number is counted from the beginning of the CVF file
     starting with sector number 0.

DMSDOS_SET_COMP:
set compression method for write access.
  
  ioctl(fd,DMSDOS_SET_COMP,READ_ONLY); or:
  ioctl(fd,DMSDOS_SET_COMP,UNCOMPRESSED); or:
  ioctl(fd,DMSDOS_SET_COMP,GUESS); or:
  ioctl(fd,DMSDOS_SET_COMP,DS_0_0); or:
  ioctl(fd,DMSDOS_SET_COMP,DS_0_1); or:
  ioctl(fd,DMSDOS_SET_COMP,DS_0_2); or:
  ioctl(fd,DMSDOS_SET_COMP,JM_0_0); or:
  ioctl(fd,DMSDOS_SET_COMP,JM_0_1); or:
  ioctl(fd,DMSDOS_SET_COMP,SQ_0_0);

DMSDOS_SET_CF:
set compression level:
  
  ioctl(fd,DMSDOS_SET_CF,level-1);

DMSDOS_EXTRA_STATFS:
special statfs command for dmsdos
reads special info in w.

  ioctl(fd,DMSDOS_EXTRA_STATFS,w);

w[0]= free sectors in CVF.
w[1]= used sectors.
w[2]= maximum free unfragmented sectors (contiguous sectors)
w[3]= free fat clusters
w[4]= used fat clusters
w[5]= clusters allocated in fat but free in MDFAT (filesystem error if > 0)
w[6]= sum of sectors used by compressed clusters
w[7]= sum of sectors used by uncompressed clusters
w[8]= number of compressed clusters
w[9]= number of uncompressed clusters

DMSDOS_READ_BLOCK:
read sector from CVF; returns sector contents in bstruct.data;

  struct bstruct
  { unsigned long sectornr;
    unsigned char data[512];
  };

  bstruct.sectornr= sector number;

  ioctl(fd,DMSDOS_READ_BLOCK,&bstruct);

DMSDOS_WRITE_BLOCK:

  analogue to read_block...

DMSDOS_READ_DIRENTRY:
DMSDOS_WRITE_DIRENTRY:

  removed and unsupported...

DMSDOS_READ_DFAT:
w[0]=clusternr; returns fat entry value in w[1]; (last=-1 or 0xFFFFFFFF)

  ret=ioctl(fd,DMSDOS_READ_DFAT,w);
  if(ret<0)error......;

DMSDOS_WRITE_DFAT:
w[0]=clusternr; w[1]=new value;

  ret=ioctl(fd,DMSDOS_WRITE_DFAT,w);
  if(ret<0)error......;

DMSDOS_SIMPLE_CHECK:
performs simple filesystem check (crosslinks & allocation errors)
w[0]=0; means do not try to repair errors

returns result in w[0] (0=ok, -1=FAT error, -2=MDFAT error, -3=BITFAT error,
                        1=out of memory, check aborted,
                        2=FAT ok, but out of memory for MDFAT check)

  ioctl(fd,DMSDOS_SIMPLE_CHECK,w);
  if(w[0]==....)printf(.....);


dmsdos daemon ioctls missing here....