View | Details | Raw Unified | Return to bug 21809
Collapse All | Expand All

(-)./bootsect.h (-16 lines)
Lines 70-93 Link Here
70
#define	BOOTSIG1	0xaa
70
#define	BOOTSIG1	0xaa
71
#define	BOOTSIG2	0
71
#define	BOOTSIG2	0
72
#define	BOOTSIG3	0
72
#define	BOOTSIG3	0
73
};
73
};
74
#ifdef	atari
75
/*
76
 * The boot sector on a gemdos fs is a little bit different from the msdos fs
77
 * format. Currently there is no need to declare a seperate structure, the
78
 * bootsector33 struct will do.
79
 */
80
#if 0
81
struct bootsec_atari {
82
	u_int8_t	bsBranch[2];		/* branch inst if auto-boot	*/
83
	int8_t		bsFiller[6];		/* anything or nothing		*/
84
	int8_t		bsSerial[3];		/* serial no. for mediachange	*/
85
	int8_t		bsBPB[19];		/* BIOS parameter block		*/
86
	int8_t		bsBootCode[482];	/* pad so struct is 512b	*/
87
};
88
#endif
89
#endif /* atari */
90
74
91
union bootsector {
75
union bootsector {
92
	struct bootsector33 bs33;
76
	struct bootsector33 bs33;
93
	struct bootsector50 bs50;
77
	struct bootsector50 bs50;
(-)./bpb.h (-22 lines)
Lines 80-109 Link Here
80
	u_int16_t	bpbBackup;	/* backup boot sector */
80
	u_int16_t	bpbBackup;	/* backup boot sector */
81
	/* There is a 12 byte filler here, but we ignore it */
81
	/* There is a 12 byte filler here, but we ignore it */
82
};
82
};
83
83
84
#ifdef	atari
85
/*
86
 * BPB for gemdos filesystems. Atari leaves the obsolete stuff undefined.
87
 * Currently there is no need for a separate BPB structure.
88
 */
89
#if 0
90
struct bpb_a {
91
	u_int16_t	bpbBytesPerSec;	/* bytes per sector		*/
92
	u_int8_t	bpbSecPerClust;	/* sectors per cluster		*/
93
	u_int16_t	bpbResSectors;	/* number of reserved sectors	*/
94
	u_int8_t	bpbFATs;	/* number of FATs		*/
95
	u_int16_t	bpbRootDirEnts;	/* number of root directory entries */
96
	u_int16_t	bpbSectors;	/* total number of sectors	*/
97
	u_int8_t	bpbUseless1;	/* meaningless on gemdos fs	*/
98
	u_int16_t	bpbFATsecs;	/* number of sectors per FAT	*/
99
	u_int16_t	bpbUseless2;	/* meaningless for harddisk fs	*/
100
	u_int16_t	bpbUseless3;	/* meaningless for harddisk fs	*/
101
	u_int16_t	bpbHiddenSecs;	/* the TOS-BIOS ignores this	*/
102
};
103
#endif
104
#endif	/* atari */
105
106
/*
84
/*
107
 * The following structures represent how the bpb's look on disk.  shorts
85
 * The following structures represent how the bpb's look on disk.  shorts
108
 * and longs are just character arrays of the appropriate length.  This is
86
 * and longs are just character arrays of the appropriate length.  This is
109
 * because the compiler forces shorts and longs to align on word or
87
 * because the compiler forces shorts and longs to align on word or
(-)./fat.h (-5 lines)
Lines 70-82 Link Here
70
 * Reference says if the maximum cluster number in a filesystem is greater
70
 * Reference says if the maximum cluster number in a filesystem is greater
71
 * than 4078 ((CLUST_RSRVS - CLUST_FIRST) & FAT12_MASK) then we've got a
71
 * than 4078 ((CLUST_RSRVS - CLUST_FIRST) & FAT12_MASK) then we've got a
72
 * 16 bit fat filesystem. While mounting, the result of this test is stored
72
 * 16 bit fat filesystem. While mounting, the result of this test is stored
73
 * in pm_fatentrysize.
73
 * in pm_fatentrysize.
74
 * GEMDOS-flavour (atari):
75
 * If the filesystem is on floppy we've got a 12 bit fat filesystem, otherwise
76
 * 16 bit. We check the d_type field in the disklabel struct while mounting
77
 * and store the result in the pm_fatentrysize. Note that this kind of
78
 * detection gets flakey when mounting a vnd-device.
79
 */
74
 */
80
#define	FAT12(pmp)	(pmp->pm_fatmask == FAT12_MASK)
75
#define	FAT12(pmp)	(pmp->pm_fatmask == FAT12_MASK)
81
#define	FAT16(pmp)	(pmp->pm_fatmask == FAT16_MASK)
76
#define	FAT16(pmp)	(pmp->pm_fatmask == FAT16_MASK)
82
#define	FAT32(pmp)	(pmp->pm_fatmask == FAT32_MASK)
77
#define	FAT32(pmp)	(pmp->pm_fatmask == FAT32_MASK)
(-)./msdosfs_vfsops.c (-142 / +19 lines)
Lines 123-138 Link Here
123
		bcopy(argp->ul, pmp->pm_ul, sizeof(pmp->pm_ul));
123
		bcopy(argp->ul, pmp->pm_ul, sizeof(pmp->pm_ul));
124
		bcopy(argp->lu, pmp->pm_lu, sizeof(pmp->pm_lu));
124
		bcopy(argp->lu, pmp->pm_lu, sizeof(pmp->pm_lu));
125
	}
125
	}
126
126
127
#ifndef __FreeBSD__
128
	/*
129
	 * GEMDOS knows nothing (yet) about win95
130
	 */
131
	if (pmp->pm_flags & MSDOSFSMNT_GEMDOSFS)
132
		pmp->pm_flags |= MSDOSFSMNT_NOWIN95;
133
#endif
134
135
	if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
127
	if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
136
		pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
128
		pmp->pm_flags |= MSDOSFSMNT_SHORTNAME;
137
	else if (!(pmp->pm_flags &
129
	else if (!(pmp->pm_flags &
138
	    (MSDOSFSMNT_SHORTNAME | MSDOSFSMNT_LONGNAME))) {
130
	    (MSDOSFSMNT_SHORTNAME | MSDOSFSMNT_LONGNAME))) {
Lines 154-222 Link Here
154
	}
146
	}
155
	return 0;
147
	return 0;
156
}
148
}
157
149
158
#ifndef __FreeBSD__
159
int
160
msdosfs_mountroot()
161
{
162
	register struct mount *mp;
163
	struct proc *p = curproc;	/* XXX */
164
	size_t size;
165
	int error;
166
	struct msdosfs_args args;
167
168
	if (root_device->dv_class != DV_DISK)
169
		return (ENODEV);
170
171
	/*
172
	 * Get vnodes for swapdev and rootdev.
173
	 */
174
	if (bdevvp(rootdev, &rootvp))
175
		panic("msdosfs_mountroot: can't setup rootvp");
176
177
	mp = malloc((u_long)sizeof(struct mount), M_MOUNT, M_WAITOK);
178
	bzero((char *)mp, (u_long)sizeof(struct mount));
179
	mp->mnt_op = &msdosfs_vfsops;
180
	mp->mnt_flag = 0;
181
	LIST_INIT(&mp->mnt_vnodelist);
182
183
	args.flags = 0;
184
	args.uid = 0;
185
	args.gid = 0;
186
	args.mask = 0777;
187
188
	if ((error = mountmsdosfs(rootvp, mp, p, &args)) != 0) {
189
		free(mp, M_MOUNT);
190
		return (error);
191
	}
192
193
	if ((error = update_mp(mp, &args)) != 0) {
194
		(void)msdosfs_unmount(mp, 0, p);
195
		free(mp, M_MOUNT);
196
		return (error);
197
	}
198
199
	if ((error = vfs_lock(mp)) != 0) {
200
		(void)msdosfs_unmount(mp, 0, p);
201
		free(mp, M_MOUNT);
202
		return (error);
203
	}
204
205
	TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
206
	mp->mnt_vnodecovered = NULLVP;
207
	(void) copystr("/", mp->mnt_stat.f_mntonname, MNAMELEN - 1,
208
	    &size);
209
	bzero(mp->mnt_stat.f_mntonname + size, MNAMELEN - size);
210
	(void) copystr(ROOTNAME, mp->mnt_stat.f_mntfromname, MNAMELEN - 1,
211
	    &size);
212
	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
213
	(void)msdosfs_statfs(mp, &mp->mnt_stat, p);
214
	vfs_unlock(mp);
215
	return (0);
216
}
217
#endif
218
219
/*
150
/*
220
 * mp - path - addr in user space of mount point (ie /usr or whatever)
151
 * mp - path - addr in user space of mount point (ie /usr or whatever)
221
 * data - addr in user space of mount params including the name of the block
152
 * data - addr in user space of mount params including the name of the block
222
 * special file to treat as a filesystem.
153
 * special file to treat as a filesystem.
Lines 236-243 Link Here
236
	size_t size;
167
	size_t size;
237
	int error, flags;
168
	int error, flags;
238
	mode_t accessmode;
169
	mode_t accessmode;
239
170
171
	/* Check to see if we are mounting root */
172
	if (mp->mnt_flag & MNT_ROOTFS)
173
		panic("msdosfs_mount: root support yanked");
174
240
	error = copyin(data, (caddr_t)&args, sizeof(struct msdosfs_args));
175
	error = copyin(data, (caddr_t)&args, sizeof(struct msdosfs_args));
241
	if (error)
176
	if (error)
242
		return (error);
177
		return (error);
243
	if (args.magic != MSDOSFS_ARGSMAGIC)
178
	if (args.magic != MSDOSFS_ARGSMAGIC)
Lines 261-272 Link Here
261
		if (error)
196
		if (error)
262
			return (error);
197
			return (error);
263
		if ((pmp->pm_flags & MSDOSFSMNT_RONLY) && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
198
		if ((pmp->pm_flags & MSDOSFSMNT_RONLY) && (mp->mnt_kern_flag & MNTK_WANTRDWR)) {
264
			/*
199
			/*
265
			 * If upgrade to read-write by non-root, then verify
200
			 * If upgrade to read-write by regular user, then verify
266
			 * that user has necessary permissions on the device.
201
			 * that user has necessary permissions on the device.
267
			 */
202
			 */
268
			if (p->p_ucred->cr_uid != 0) {
203
			if (suser(p)) {
269
				devvp = pmp->pm_devvp;
204
				devvp = pmp->pm_devvp;
270
				vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
205
				vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
271
				error = VOP_ACCESS(devvp, VREAD | VWRITE,
206
				error = VOP_ACCESS(devvp, VREAD | VWRITE,
272
						   p->p_ucred, p);
207
						   p->p_ucred, p);
Lines 278-286 Link Here
278
			}
213
			}
279
			pmp->pm_flags &= ~MSDOSFSMNT_RONLY;
214
			pmp->pm_flags &= ~MSDOSFSMNT_RONLY;
280
		}
215
		}
281
		if (args.fspec == 0) {
216
		if (args.fspec == 0) {
282
#ifdef	__notyet__		/* doesn't work correctly with current mountd	XXX */
217
#ifdef	__notyet__	/* doesn't work correctly with current mountd	XXX */
283
			if (args.flags & MSDOSFSMNT_MNTOPT) {
218
			if (args.flags & MSDOSFSMNT_MNTOPT) {
284
				pmp->pm_flags &= ~MSDOSFSMNT_MNTOPT;
219
				pmp->pm_flags &= ~MSDOSFSMNT_MNTOPT;
285
				pmp->pm_flags |= args.flags & MSDOSFSMNT_MNTOPT;
220
				pmp->pm_flags |= args.flags & MSDOSFSMNT_MNTOPT;
286
				if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
221
				if (pmp->pm_flags & MSDOSFSMNT_NOWIN95)
Lines 311-319 Link Here
311
	/*
246
	/*
312
	 * If mount by non-root, then verify that user has necessary
247
	 * If mount by non-root, then verify that user has necessary
313
	 * permissions on the device.
248
	 * permissions on the device.
314
	 */
249
	 */
315
	if (p->p_ucred->cr_uid != 0) {
250
	if (suser(p)) {
316
		accessmode = VREAD;
251
		accessmode = VREAD;
317
		if ((mp->mnt_flag & MNT_RDONLY) == 0)
252
		if ((mp->mnt_flag & MNT_RDONLY) == 0)
318
			accessmode |= VWRITE;
253
			accessmode |= VWRITE;
319
		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
254
		vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY, p);
Lines 367-378 Link Here
367
{
302
{
368
	struct msdosfsmount *pmp;
303
	struct msdosfsmount *pmp;
369
	struct buf *bp;
304
	struct buf *bp;
370
	dev_t dev = devvp->v_rdev;
305
	dev_t dev = devvp->v_rdev;
371
#ifndef __FreeBSD__
372
	struct partinfo dpart;
373
	int bsize = 0, dtype = 0, tmp;
374
#endif
375
	union bootsector *bsp;
306
	union bootsector *bsp;
376
	struct byte_bpb33 *b33;
307
	struct byte_bpb33 *b33;
377
	struct byte_bpb50 *b50;
308
	struct byte_bpb50 *b50;
378
	struct byte_bpb710 *b710;
309
	struct byte_bpb710 *b710;
Lines 406-439 Link Here
406
337
407
	bp  = NULL; /* both used in error_exit */
338
	bp  = NULL; /* both used in error_exit */
408
	pmp = NULL;
339
	pmp = NULL;
409
340
410
#ifndef __FreeBSD__
411
	if (argp->flags & MSDOSFSMNT_GEMDOSFS) {
412
		/*
413
	 	 * We need the disklabel to calculate the size of a FAT entry
414
		 * later on. Also make sure the partition contains a filesystem
415
		 * of type FS_MSDOS. This doesn't work for floppies, so we have
416
		 * to check for them too.
417
	 	 *
418
	 	 * At least some parts of the msdos fs driver seem to assume
419
		 * that the size of a disk block will always be 512 bytes.
420
		 * Let's check it...
421
		 */
422
		error = VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart,
423
				  FREAD, NOCRED, p);
424
		if (error)
425
			goto error_exit;
426
		tmp   = dpart.part->p_fstype;
427
		dtype = dpart.disklab->d_type;
428
		bsize = dpart.disklab->d_secsize;
429
		if (bsize != 512 || (dtype!=DTYPE_FLOPPY && tmp!=FS_MSDOS)) {
430
			error = EINVAL;
431
			goto error_exit;
432
		}
433
	}
434
#endif
435
436
	/*
341
	/*
437
	 * Read the boot sector of the filesystem, and then check the
342
	 * Read the boot sector of the filesystem, and then check the
438
	 * boot signature.  If not a dos boot sector then error out.
343
	 * boot signature.  If not a dos boot sector then error out.
439
	 *
344
	 *
Lines 447-465 Link Here
447
	b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB;
352
	b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB;
448
	b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB;
353
	b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB;
449
	b710 = (struct byte_bpb710 *)bsp->bs710.bsPBP;
354
	b710 = (struct byte_bpb710 *)bsp->bs710.bsPBP;
450
355
451
#ifndef __FreeBSD__
452
	if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) {
453
#endif
454
#ifndef MSDOSFS_NOCHECKSIG
356
#ifndef MSDOSFS_NOCHECKSIG
455
		if (bsp->bs50.bsBootSectSig0 != BOOTSIG0
357
	if (bsp->bs50.bsBootSectSig0 != BOOTSIG0
456
		    || bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
358
	    || bsp->bs50.bsBootSectSig1 != BOOTSIG1) {
457
			error = EINVAL;
359
		error = EINVAL;
458
			goto error_exit;
360
		goto error_exit;
459
		}
460
#endif
461
#ifndef __FreeBSD__
462
	}
361
	}
463
#endif
362
#endif
464
363
465
	pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK);
364
	pmp = malloc(sizeof *pmp, M_MSDOSFSMNT, M_WAITOK);
Lines 484-508 Link Here
484
383
485
	/* calculate the ratio of sector size to DEV_BSIZE */
384
	/* calculate the ratio of sector size to DEV_BSIZE */
486
	pmp->pm_BlkPerSec = pmp->pm_BytesPerSec / DEV_BSIZE;
385
	pmp->pm_BlkPerSec = pmp->pm_BytesPerSec / DEV_BSIZE;
487
386
488
#ifndef __FreeBSD__
387
	/* XXX - We should probably check more values here */
489
	if (!(argp->flags & MSDOSFSMNT_GEMDOSFS)) {
388
	if (!pmp->pm_BytesPerSec || !SecPerClust
490
#endif
389
		|| !pmp->pm_Heads || pmp->pm_Heads > 255
491
		/* XXX - We should probably check more values here */
492
		if (!pmp->pm_BytesPerSec || !SecPerClust
493
			|| !pmp->pm_Heads || pmp->pm_Heads > 255
494
#ifdef PC98
390
#ifdef PC98
495
	    		|| !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 255) {
391
	    	|| !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 255) {
496
#else
392
#else
497
			|| !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 63) {
393
		|| !pmp->pm_SecPerTrack || pmp->pm_SecPerTrack > 63) {
498
#endif
394
#endif
499
			error = EINVAL;
395
		error = EINVAL;
500
			goto error_exit;
396
		goto error_exit;
501
		}
502
#ifndef __FreeBSD__
503
	}
397
	}
504
#endif
505
398
506
	if (pmp->pm_Sectors == 0) {
399
	if (pmp->pm_Sectors == 0) {
507
		pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs);
400
		pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs);
508
		pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors);
401
		pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors);
Lines 583-606 Link Here
583
	pmp->pm_maxcluster = (pmp->pm_HugeSectors - pmp->pm_firstcluster) /
476
	pmp->pm_maxcluster = (pmp->pm_HugeSectors - pmp->pm_firstcluster) /
584
	    SecPerClust + 1;
477
	    SecPerClust + 1;
585
	pmp->pm_fatsize = pmp->pm_FATsecs * DEV_BSIZE; /* XXX not used? */
478
	pmp->pm_fatsize = pmp->pm_FATsecs * DEV_BSIZE; /* XXX not used? */
586
479
587
#ifndef __FreeBSD__
588
	if (argp->flags & MSDOSFSMNT_GEMDOSFS) {
589
		if ((pmp->pm_maxcluster <= (0xff0 - 2))
590
		      && ((dtype == DTYPE_FLOPPY) || ((dtype == DTYPE_VNODE)
591
		      && ((pmp->pm_Heads == 1) || (pmp->pm_Heads == 2))))
592
		    ) {
593
			pmp->pm_fatmask = FAT12_MASK;
594
			pmp->pm_fatmult = 3;
595
			pmp->pm_fatdiv = 2;
596
		} else {
597
			pmp->pm_fatmask = FAT16_MASK;
598
			pmp->pm_fatmult = 2;
599
			pmp->pm_fatdiv = 1;
600
		}
601
	} else 
602
#endif
603
	if (pmp->pm_fatmask == 0) {
480
	if (pmp->pm_fatmask == 0) {
604
		if (pmp->pm_maxcluster
481
		if (pmp->pm_maxcluster
605
		    <= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) {
482
		    <= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) {
606
			/*
483
			/*
(-)./msdosfs_vnops.c (-1 / +1 lines)
Lines 415-423 Link Here
415
		 *
415
		 *
416
		 * An exception with regards to the SF_SETTABLE bits, is
416
		 * An exception with regards to the SF_SETTABLE bits, is
417
		 * SF_IMMUTABLE, which we map to ATTR_SYSTEM.
417
		 * SF_IMMUTABLE, which we map to ATTR_SYSTEM.
418
		 */
418
		 */
419
		if (cred->cr_uid != 0) {
419
		if (suser(ap->a_p)) {
420
			if (vap->va_flags & (SF_SETTABLE^SF_IMMUTABLE))
420
			if (vap->va_flags & (SF_SETTABLE^SF_IMMUTABLE))
421
				return EPERM;
421
				return EPERM;
422
			if (vap->va_flags & SF_IMMUTABLE)
422
			if (vap->va_flags & SF_IMMUTABLE)
423
				dep->de_Attributes |= ATTR_SYSTEM;
423
				dep->de_Attributes |= ATTR_SYSTEM;
(-)./msdosfsmount.h (-4 / +1 lines)
Lines 226-243 Link Here
226
 */
226
 */
227
#define	MSDOSFSMNT_SHORTNAME	1	/* Force old DOS short names only */
227
#define	MSDOSFSMNT_SHORTNAME	1	/* Force old DOS short names only */
228
#define	MSDOSFSMNT_LONGNAME	2	/* Force Win'95 long names */
228
#define	MSDOSFSMNT_LONGNAME	2	/* Force Win'95 long names */
229
#define	MSDOSFSMNT_NOWIN95	4	/* Completely ignore Win95 entries */
229
#define	MSDOSFSMNT_NOWIN95	4	/* Completely ignore Win95 entries */
230
#ifndef __FreeBSD__
231
#define	MSDOSFSMNT_GEMDOSFS	8	/* This is a gemdos-flavour */
232
#endif
233
#define MSDOSFSMNT_U2WTABLE     0x10    /* Local->Unicode and local<->DOS   */
230
#define MSDOSFSMNT_U2WTABLE     0x10    /* Local->Unicode and local<->DOS   */
234
					/* tables loaded                    */
231
					/* tables loaded                    */
235
#define MSDOSFSMNT_ULTABLE      0x20    /* Local upper<->lower table loaded */
232
#define MSDOSFSMNT_ULTABLE      0x20    /* Local upper<->lower table loaded */
236
/* All flags above: */
233
/* All flags above: */
237
#define	MSDOSFSMNT_MNTOPT \
234
#define	MSDOSFSMNT_MNTOPT \
238
	(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
235
	(MSDOSFSMNT_SHORTNAME|MSDOSFSMNT_LONGNAME|MSDOSFSMNT_NOWIN95 \
239
	 /*|MSDOSFSMNT_GEMDOSFS*/|MSDOSFSMNT_U2WTABLE|MSDOSFSMNT_ULTABLE)
236
	 |MSDOSFSMNT_U2WTABLE|MSDOSFSMNT_ULTABLE)
240
#define	MSDOSFSMNT_RONLY	0x80000000	/* mounted read-only	*/
237
#define	MSDOSFSMNT_RONLY	0x80000000	/* mounted read-only	*/
241
#define	MSDOSFSMNT_WAITONFAT	0x40000000	/* mounted synchronous	*/
238
#define	MSDOSFSMNT_WAITONFAT	0x40000000	/* mounted synchronous	*/
242
#define	MSDOSFS_FATMIRROR	0x20000000	/* FAT is mirrored */
239
#define	MSDOSFS_FATMIRROR	0x20000000	/* FAT is mirrored */

Return to bug 21809