18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  fs/partitions/ultrix.c
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Code extracted from drivers/block/genhd.c
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  Re-organised Jul 1999 Russell King
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include "check.h"
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciint ultrix_partition(struct parsed_partitions *state)
138c2ecf20Sopenharmony_ci{
148c2ecf20Sopenharmony_ci	int i;
158c2ecf20Sopenharmony_ci	Sector sect;
168c2ecf20Sopenharmony_ci	unsigned char *data;
178c2ecf20Sopenharmony_ci	struct ultrix_disklabel {
188c2ecf20Sopenharmony_ci		s32	pt_magic;	/* magic no. indicating part. info exits */
198c2ecf20Sopenharmony_ci		s32	pt_valid;	/* set by driver if pt is current */
208c2ecf20Sopenharmony_ci		struct  pt_info {
218c2ecf20Sopenharmony_ci			s32		pi_nblocks; /* no. of sectors */
228c2ecf20Sopenharmony_ci			u32		pi_blkoff;  /* block offset for start */
238c2ecf20Sopenharmony_ci		} pt_part[8];
248c2ecf20Sopenharmony_ci	} *label;
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define PT_MAGIC	0x032957	/* Partition magic number */
278c2ecf20Sopenharmony_ci#define PT_VALID	1		/* Indicates if struct is valid */
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	data = read_part_sector(state, (16384 - sizeof(*label))/512, &sect);
308c2ecf20Sopenharmony_ci	if (!data)
318c2ecf20Sopenharmony_ci		return -1;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	label = (struct ultrix_disklabel *)(data + 512 - sizeof(*label));
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci	if (label->pt_magic == PT_MAGIC && label->pt_valid == PT_VALID) {
368c2ecf20Sopenharmony_ci		for (i=0; i<8; i++)
378c2ecf20Sopenharmony_ci			if (label->pt_part[i].pi_nblocks)
388c2ecf20Sopenharmony_ci				put_partition(state, i+1,
398c2ecf20Sopenharmony_ci					      label->pt_part[i].pi_blkoff,
408c2ecf20Sopenharmony_ci					      label->pt_part[i].pi_nblocks);
418c2ecf20Sopenharmony_ci		put_dev_sector(sect);
428c2ecf20Sopenharmony_ci		strlcat(state->pp_buf, "\n", PAGE_SIZE);
438c2ecf20Sopenharmony_ci		return 1;
448c2ecf20Sopenharmony_ci	} else {
458c2ecf20Sopenharmony_ci		put_dev_sector(sect);
468c2ecf20Sopenharmony_ci		return 0;
478c2ecf20Sopenharmony_ci	}
488c2ecf20Sopenharmony_ci}
49