Ejemplo n.º 1
0
static errcode_t orphan_dir_check(ocfs2_filesys *fs,
				  uint16_t new_slots)
{
	errcode_t ret = 0;
	uint64_t blkno;
	int i, has_orphan = 0;
	uint16_t max_slots = OCFS2_RAW_SB(fs->fs_super)->s_max_slots;

	for (i = new_slots ; i < max_slots; ++i) {
		ret = ocfs2_lookup_system_inode(fs, ORPHAN_DIR_SYSTEM_INODE,
						i, &blkno);
		if (ret) {
			verbosef(VL_APP,
				 "%s while looking up orphan dir for "
				 "slot %u during orphan dir check\n",
				 error_message(ret), i);
			break;
		}

		ret = ocfs2_dir_iterate(fs, blkno,
					OCFS2_DIRENT_FLAG_EXCLUDE_DOTS, NULL,
					orphan_iterate, &has_orphan);

		if (has_orphan) {
			ret = TUNEFS_ET_ORPHAN_DIR_NOT_EMPTY;
			verbosef(VL_APP,
				 "Entries found in orphan dir for slot %u\n",
				 i);
			break;
		}
	}

	return ret;
}
Ejemplo n.º 2
0
/* very similar to decode_ether ... */
static int decode_linux_sll(DECODER_ARGS) {
   const struct sll_header {
      uint16_t packet_type;
      uint16_t device_type;
      uint16_t addr_length;
#define SLL_MAX_ADDRLEN 8
      uint8_t addr[SLL_MAX_ADDRLEN];
      uint16_t ether_type;
   } *hdr = (const struct sll_header *)pdata;
   u_short type;

   if (pheader->caplen < SLL_HDR_LEN) {
      verbosef("linux_sll: packet too short (%u bytes)", pheader->caplen);
      return 0;
   }
   type = ntohs(hdr->ether_type);
   switch (type) {
   case ETHERTYPE_IP:
   case ETHERTYPE_IPV6:
      return helper_ip(pdata + SLL_HDR_LEN,
                       pheader->caplen - SLL_HDR_LEN,
                       sm);
   case ETHERTYPE_ARP:
      /* known protocol, don't complain about it. */
      return 0;
   default:
      verbosef("linux_sll: unknown protocol (0x%04x)", type);
      return 0;
   }
}
Ejemplo n.º 3
0
static errcode_t truncate_orphan_dir(ocfs2_filesys *fs,
				     uint16_t removed_slot)
{
	errcode_t ret;
	uint64_t blkno;
	char fname[OCFS2_MAX_FILENAME_LEN];

	ocfs2_sprintf_system_inode_name(fname, OCFS2_MAX_FILENAME_LEN,
					ORPHAN_DIR_SYSTEM_INODE,
					removed_slot);
	verbosef(VL_APP, "Truncating orphan dir \"%s\"\n", fname);

	ret = ocfs2_lookup_system_inode(fs, ORPHAN_DIR_SYSTEM_INODE,
					removed_slot, &blkno);
	if (!ret) {
		ret = ocfs2_truncate(fs, blkno, 0);
		if (!ret)
			verbosef(VL_APP, "Orphan dir \"%s\" truncated\n",
				 fname);
		else
			verbosef(VL_APP,
				 "%s while truncating orphan dir \"%s\"\n",
				 error_message(ret), fname);
	} else
		verbosef(VL_APP,
			 "%s while looking up orphan dir \"%s\"\n",
			 error_message(ret), fname);

	return ret;
}
Ejemplo n.º 4
0
static int helper_ipv6(HELPER_ARGS) {
   const struct ip6_hdr *hdr = (const struct ip6_hdr *)pdata;

   if (len < IPV6_HDR_LEN) {
      verbosef("ipv6: packet too short (%u bytes)", len);
      return 0;
   }
   if ((hdr->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) {
      verbosef("ipv6: bad version (%02x, expecting %02x)",
               hdr->ip6_vfc & IPV6_VERSION_MASK, IPV6_VERSION);
      return 0;
   }

   /* IPv4 has "total length," but IPv6 has "payload length" which doesn't
    * count the header bytes.
    */
   sm->len = ntohs(hdr->ip6_plen) + IPV6_HDR_LEN;
   sm->proto = hdr->ip6_nxt;
   sm->src.family = IPv6;
   memcpy(&sm->src.ip.v6, &hdr->ip6_src, sizeof(sm->src.ip.v6));
   sm->dst.family = IPv6;
   memcpy(&sm->dst.ip.v6, &hdr->ip6_dst, sizeof(sm->dst.ip.v6));

   helper_ip_deeper(pdata + IPV6_HDR_LEN, len - IPV6_HDR_LEN, sm);
   return 1;
}
Ejemplo n.º 5
0
static int helper_ip(HELPER_ARGS) {
   const struct ip *hdr = (const struct ip *)pdata;

   if (len < IP_HDR_LEN) {
      verbosef("ip: packet too short (%u bytes)", len);
      return 0;
   }
   if (hdr->ip_v == 6) {
      return helper_ipv6(pdata, len, sm);
   }
   if (hdr->ip_v != 4) {
      verbosef("ip: version %d (expecting 4 or 6)", hdr->ip_v);
      return 0;
   }

   sm->len = ntohs(hdr->ip_len);
   sm->proto = hdr->ip_p;

   sm->src.family = IPv4;
   sm->src.ip.v4 = hdr->ip_src.s_addr;

   sm->dst.family = IPv4;
   sm->dst.ip.v4 = hdr->ip_dst.s_addr;

   helper_ip_deeper(pdata + IP_HDR_LEN, len - IP_HDR_LEN, sm);
   return 1;
}
Ejemplo n.º 6
0
static errcode_t truncate_log_check(ocfs2_filesys *fs,
				    uint16_t new_slots)
{
	errcode_t ret = 0;
	uint16_t i;
	uint64_t blkno;
	char *buf = NULL;
	struct ocfs2_dinode *di = NULL;

	uint16_t max_slots = OCFS2_RAW_SB(fs->fs_super)->s_max_slots;

	ret = ocfs2_malloc_block(fs->fs_io, &buf);
	if (ret) {
		verbosef(VL_APP,
			 "%s while allocating inode buffer for "
			 "truncate log check\n",
			 error_message(ret));
		goto bail;
	}

	for (i = new_slots; i < max_slots; ++i) {
		ret = ocfs2_lookup_system_inode(fs, TRUNCATE_LOG_SYSTEM_INODE,
						i, &blkno);
		if (ret) {
			verbosef(VL_APP,
				 "%s while looking up truncate log for "
				 "slot %u during truncate log check\n",
				 error_message(ret), i);
			goto bail;
		}

		ret = ocfs2_read_inode(fs, blkno, buf);
		if (ret) {
			verbosef(VL_APP,
				 "%s while reading inode %"PRIu64" "
				 "during truncate log check\n",
				 error_message(ret), blkno);
			goto bail;
		}

		di = (struct ocfs2_dinode *)buf;

		if (di->id2.i_dealloc.tl_used > 0) {
			ret = TUNEFS_ET_TRUNCATE_LOG_NOT_EMPTY;
			verbosef(VL_APP,
				 "Truncate log for slot %u is not empty\n",
				 i);
			goto bail;
		}
	}

bail:
	if (buf)
		ocfs2_free(&buf);
	return ret;
}
Ejemplo n.º 7
0
static void convert_shp_to_bmp() {
  PG_Shp *shp;
  verbosef(1, "Reading from %s\n", input_file);
  shp = shp_load(input_file);
  if (!shp) abortf("Input file '%s' could not be loaded\n", input_file);
  
  verbosef(1, "Writing to %s\n", output_file);
  if (SDL_SaveBMP(shp->surf, output_file) < 0)
    abortf("Could not write to '%s'\n", output_file);
}
Ejemplo n.º 8
0
static void init_sdl() {
  verbosef(2, "Initialising SDL...\n");
  verbosef(3, "SDL_Init\n");
  /* SDL required for graphical conversion */
  SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER );
  verbosef(3, "SDL_SetVideoMode\n");
  SDL_SetVideoMode( 20, 20, 16, SDL_SWSURFACE );
  verbosef(3, "Registering exit-handler\n");
  atexit( SDL_Quit );
}
Ejemplo n.º 9
0
static errcode_t local_alloc_check(ocfs2_filesys *fs,
				   uint16_t new_slots)
{
	errcode_t ret = 0;
	uint16_t i;
	uint64_t blkno;
	char *buf = NULL;
	struct ocfs2_dinode *di = NULL;

	uint16_t max_slots = OCFS2_RAW_SB(fs->fs_super)->s_max_slots;

	ret = ocfs2_malloc_block(fs->fs_io, &buf);
	if (ret) {
		verbosef(VL_APP,
			 "%s while allocating inode buffer for local "
			 "alloc check\n",
			 error_message(ret));
		goto bail;
	}

	for (i = new_slots ; i < max_slots; ++i) {
		ret = ocfs2_lookup_system_inode(fs, LOCAL_ALLOC_SYSTEM_INODE,
						i, &blkno);
		if (ret) {
			verbosef(VL_APP,
				 "%s while looking up local alloc for "
				 "slot %u during local alloc check\n",
				 error_message(ret), i);
			break;
		}

		ret = ocfs2_read_inode(fs, blkno, buf);
		if (ret) {
			verbosef(VL_APP,
				 "%s while reading inode %"PRIu64" "
				 "during local alloc check\n",
				 error_message(ret), blkno);
			break;
		}

		di = (struct ocfs2_dinode *)buf;
		if (di->id1.bitmap1.i_total > 0) {
			ret = TUNEFS_ET_LOCAL_ALLOC_NOT_EMPTY;
			verbosef(VL_APP,
				 "Local alloc for slot %u is not empty\n",
				 i);
			break;
		}
	}

bail:
	if (buf)
		ocfs2_free(&buf);
	return ret;
}
Ejemplo n.º 10
0
void cap_start(const int promisc) {
   struct str *ifs = str_make();

   assert(STAILQ_EMPTY(&cap_ifs));
   if (STAILQ_EMPTY(&cli_ifnames))
      errx(1, "no interfaces specified");

   /* For each ifname */
   while (!STAILQ_EMPTY(&cli_ifnames)) {
      struct strnode *ifname, *filter = NULL;
      struct cap_iface *iface = xmalloc(sizeof(*iface));

      ifname = STAILQ_FIRST(&cli_ifnames);
      STAILQ_REMOVE_HEAD(&cli_ifnames, entries);

      if (!STAILQ_EMPTY(&cli_filters)) {
         filter = STAILQ_FIRST(&cli_filters);
         STAILQ_REMOVE_HEAD(&cli_filters, entries);
      }

      iface->name = ifname->str;
      iface->filter = (filter == NULL) ? NULL : filter->str;
      iface->pcap = NULL;
      iface->fd = -1;
      iface->linkhdr = NULL;
      localip_init(&iface->local_ips);
      STAILQ_INSERT_TAIL(&cap_ifs, iface, entries);
      cap_start_one(iface, promisc);

      free(ifname);
      if (filter) free(filter);

      if (str_len(ifs) == 0)
         str_append(ifs, iface->name);
      else
         str_appendf(ifs, ", %s", iface->name);
   }
   verbosef("all capture interfaces prepared");

   /* Deallocate extra filters, if any. */
   while (!STAILQ_EMPTY(&cli_filters)) {
      struct strnode *filter = STAILQ_FIRST(&cli_filters);

      verbosef("ignoring extraneous filter '%s'", filter->str);
      STAILQ_REMOVE_HEAD(&cli_filters, entries);
      free(filter);
   }

   str_appendn(ifs, "", 1); /* NUL terminate */
   {
      size_t _;
      str_extract(ifs, &_, &title_interfaces);
   }
}
Ejemplo n.º 11
0
static int decode_ppp(DECODER_ARGS) {
   if (pheader->caplen < PPPOE_HDR_LEN) {
      verbosef("ppp: packet too short (%u bytes)", pheader->caplen);
      return 0;
   }
   if (pdata[2] == 0x00 && pdata[3] == 0x21)
      return helper_ip(pdata + PPP_HDR_LEN,
                       pheader->caplen - PPP_HDR_LEN,
                       sm);
   verbosef("ppp: non-IP PPP packet; ignoring.");
   return 0;
}
Ejemplo n.º 12
0
static void update_volume_label(ocfs2_filesys *fs,
				const char *new_label)
{
	int len;
	char label_buf[OCFS2_MAX_VOL_LABEL_LEN];
	struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);

	memset(label_buf, 0, OCFS2_MAX_VOL_LABEL_LEN);

	if (new_label) {
		len = strlen(new_label);
		if (len > OCFS2_MAX_VOL_LABEL_LEN)
			len = OCFS2_MAX_VOL_LABEL_LEN;
		if (!memcmp(sb->s_label, new_label, len)) {
			verbosef(VL_APP,
				 "Device \"%s\" already has the label "
				 "\"%.*s\"; label not updated\n",
				 fs->fs_devname, OCFS2_MAX_VOL_LABEL_LEN,
				 new_label);
			return;
		}
		strncpy(label_buf, new_label, OCFS2_MAX_VOL_LABEL_LEN);
	} else {
		strncpy(label_buf, (char *)sb->s_label,
			OCFS2_MAX_VOL_LABEL_LEN);
		len = strnlen(label_buf, OCFS2_MAX_VOL_LABEL_LEN);

		/*
		 * If we don't have CLONED_LABEL at the end of the label,
		 * add it.  Truncate the existing label if necessary to
		 * fit CLONED_LABEL.
		 */
		if (strncmp(label_buf + len - CLONED_LABEL_LEN,
			    CLONED_LABEL, CLONED_LABEL_LEN)) {
			if ((len + CLONED_LABEL_LEN) > OCFS2_MAX_VOL_LABEL_LEN)
				len = OCFS2_MAX_VOL_LABEL_LEN -
					CLONED_LABEL_LEN;
			strncpy(label_buf + len, CLONED_LABEL,
				CLONED_LABEL_LEN);
		}
	}

	verbosef(VL_APP,
		 "Setting the label \"%.*s\" on device \"%s\"\n",
		 OCFS2_MAX_VOL_LABEL_LEN, label_buf, fs->fs_devname);
	memset(OCFS2_RAW_SB(fs->fs_super)->s_label, 0,
	       OCFS2_MAX_VOL_LABEL_LEN);
	strncpy((char *)sb->s_label, label_buf,
		OCFS2_MAX_VOL_LABEL_LEN);
}
Ejemplo n.º 13
0
static int revoke_this_block(struct rb_root *root, uint64_t block, 
		 	     uint32_t seq)
{
	struct rb_node *node = root->rb_node;
	struct revoke_entry *re;

	while (node) {
		re = rb_entry(node, struct revoke_entry, r_node);

		if (block < re->r_block)
			node = node->rb_left;
		else if (block > re->r_block)
			node = node->rb_right;
		else {
			/* only revoke if we've recorded a revoke entry for
			 * this block that is <= the seq that we're interested
			 * in */
			if (re && !seq_gt(seq, re->r_seq)) {
				verbosef("%"PRIu64" is revoked\n", block);
				return 1;
			}
		}
	}

	return 0;
}
Ejemplo n.º 14
0
static errcode_t create_system_file(ocfs2_filesys *fs, int type, int node)
{
	char fname[OCFS2_MAX_FILENAME_LEN];
	uint64_t blkno;
	errcode_t ret;

	ocfs2_sprintf_system_inode_name(fname, sizeof(fname),
		type, node);
	ret = ocfs2_lookup(fs, fs->fs_sysdir_blkno, fname, strlen(fname), NULL,
			   &blkno);
	if (!ret) {
		verbosef(VL_APP, "System file \"%s\" already exists!\n",
			 fname);
		return 0;
	}
	ret = ocfs2_new_system_inode(fs, &blkno,
				ocfs2_system_inodes[type].si_mode,
				ocfs2_system_inodes[type].si_iflags);
	if (ret) {
		tcom_err(ret, "while creating system file \"%s\"", fname);
		return ret;
	}

	ret = ocfs2_link(fs, fs->fs_sysdir_blkno, fname, blkno,
			 OCFS2_FT_REG_FILE);
	if (ret) {
		tcom_err(ret, "while linking file \"%s\" in the system "
			 "directory", fname);
		return ret;
	}
	return 0;
}
Ejemplo n.º 15
0
static errcode_t add_revoke_records(struct journal_info *ji, char *buf,
				    size_t max, uint32_t seq)
{
	journal_revoke_header_t jr;
	uint32_t *blkno;  /* XXX 640k ought to be enough for everybody */
	size_t i, num;
	errcode_t err = 0;

	memcpy(&jr, buf, sizeof(jr));
	jr.r_count = be32_to_cpu(jr.r_count);

	if (jr.r_count < sizeof(jr) || jr.r_count > max) {
		verbosef("corrupt r_count: %X", jr.r_count);
		return OCFS2_ET_BAD_JOURNAL_REVOKE;
	}

	num = (jr.r_count - sizeof(jr)) / sizeof(blkno);
	blkno = (uint32_t *)(buf + sizeof(jr));

	for (i = 0; i < num; i++, blkno++) {
		err = revoke_insert(&ji->ji_revoke, be32_to_cpu(*blkno), seq);
		if (err)
			break;
	}

	return err;
}
Ejemplo n.º 16
0
errcode_t o2cbtool_init_cluster_stack(void)
{
	errcode_t ret;
	const char *stack = NULL;

	verbosef(VL_DEBUG, "Initializing cluster stack\n");

	ret = o2cb_init();
	if (ret) {
		tcom_err(ret, "while initializing the cluster");
		goto bail;
	}

	ret = o2cb_get_stack_name(&stack);
	if (ret) {
		tcom_err(ret, "while determining the current cluster stack");
		goto bail;
	}

	if (strcmp(stack, stackname)) {
		ret = -1;
		errorf("This tool supports the '%s' stack, but the '%s' "
		       "stack is in use.\n", stackname, stack);
	}

bail:
	return ret;
}
Ejemplo n.º 17
0
void o2fsck_mark_cluster_allocated(o2fsck_state *ost, uint32_t cluster)
{
    int was_set = 0;
    errcode_t ret;
    const char *whoami = __FUNCTION__;

    o2fsck_bitmap_set(ost->ost_allocated_clusters, cluster, &was_set);

    if (!was_set)
        return;

    if (!ost->ost_duplicate_clusters) {
        fprintf(stderr,
                "Duplicate clusters detected.  Pass 1b will be run\n");

        ret = ocfs2_cluster_bitmap_new(ost->ost_fs,
                                       "duplicate clusters",
                                       &ost->ost_duplicate_clusters);
        if (ret) {
            com_err(whoami, ret,
                    "while allocating duplicate cluster bitmap");
            o2fsck_abort();
        }
    }

    verbosef("Cluster %"PRIu32" is allocated to more than one object\n",
             cluster);
    ocfs2_bitmap_set(ost->ost_duplicate_clusters, cluster, NULL);
}
Ejemplo n.º 18
0
/* handle the command line options */
static void process_cmdline(int argc, char **argv) {
  for (;;) {
    int result = getopt_long(argc, argv, "v", long_options, 0);
    if (result == -1) break;

    switch (result) {
      case 'd': use_def_pal = 1; break;
      case 'v': verbosity++; break;
      case OPT_VERSION: printf("%d.%d.%d\n", SHPTOOL_MAJOR, SHPTOOL_MINOR, SHPTOOL_PATCHLVL); exit(0);
    }
  }

  if (show_help) {
    syntax(argc, argv);
    exit(1);
  }
  
  /* first parameter is input file */
  if (optind >= argc) abortf("Input file missing\n");
  input_file = argv[optind++];
  
  /* second parameter is output file */  
  if (optind >= argc) abortf("Output file missing\n");
  output_file = argv[optind++];
  
  if (optind < argc) abortf("Excess parameters: %s\n", argv[optind]);
  
  verbosef(2, "use_def_pal:\t\t%d\n"
  		"verbosity:\t\t%d\n"
  	, use_def_pal, verbosity);
}
Ejemplo n.º 19
0
static errcode_t check_backup_offsets(ocfs2_filesys *fs)
{

	errcode_t ret;
	int i, num, val, failed = 0;
	ocfs2_cached_inode *chain_alloc = NULL;
	uint64_t blocks[OCFS2_MAX_BACKUP_SUPERBLOCKS];

	num = ocfs2_get_backup_super_offsets(fs, blocks,
					     ARRAY_SIZE(blocks));
	if (!num) {
		ret = 1;
		errorf("Volume on device \"%s\" is too small to contain "
		       "backup superblocks\n",
		       fs->fs_devname);
		goto bail;
	}

	ret = load_global_bitmap(fs, &chain_alloc);
	if (ret) {
		tcom_err(ret, "while loading the global bitmap");
		goto bail;
	}

	for (i = 0; i < num; i++) {
		ret = ocfs2_bitmap_test(chain_alloc->ci_chains,
					ocfs2_blocks_to_clusters(fs, blocks[i]),
					&val);
		if (ret) {
			tcom_err(ret,
				 "looking up backup superblock locations "
				 "in the global bitmap");
			goto bail;
		}

		if (val) {
			verbosef(VL_APP,
				 "Backup superblock location %d at block "
				 "%"PRIu64" is in use\n", i, blocks[i]);
			/* in order to verify all the block in the 'blocks',
			 * we don't stop the loop here.
			 */
			failed = 1;
		}
	}

	if (failed) {
		ret = 1;
		errorf("One or more backup superblock locations are "
		       "already in use\n");
	} else
		ret = 0;

	if (chain_alloc)
		ocfs2_free_cached_inode(fs, chain_alloc);

bail:
	return ret;
}
Ejemplo n.º 20
0
/* this could certainly be more clever to issue reads in groups */
static unsigned pass2_dir_block_iterate(o2fsck_dirblock_entry *dbe, 
					void *priv_data) 
{
	struct dirblock_data *dd = priv_data;
	struct ocfs2_dir_entry *dirent, *prev = NULL;
	unsigned int offset = 0, ret_flags = 0, end = dd->fs->fs_blocksize;
	struct ocfs2_dinode *di = (struct ocfs2_dinode *)dd->inoblock_buf; 
	errcode_t ret = 0;

	if (!o2fsck_test_inode_allocated(dd->ost, dbe->e_ino)) {
		printf("Directory block %"PRIu64" belongs to directory inode "
		       "%"PRIu64" which isn't allocated.  Ignoring this "
		       "block.", dbe->e_blkno, dbe->e_ino);
		goto out;
	}

	if (dbe->e_ino != dd->last_ino) {
		o2fsck_strings_free(&dd->strings);
		dd->last_ino = dbe->e_ino;

		ret = ocfs2_read_inode(dd->ost->ost_fs, dbe->e_ino,
				       dd->inoblock_buf);
		if (ret) {
			com_err(whoami, ret, "while reading dir inode %"PRIu64,
				dbe->e_ino);
			ret_flags |= OCFS2_DIRENT_ABORT;
			goto out;
		}

		verbosef("dir inode %"PRIu64" i_size %"PRIu64"\n",
			 dbe->e_ino, (uint64_t)di->i_size);

	}

	verbosef("dir block %"PRIu64" block offs %"PRIu64" in ino\n",
		 dbe->e_blkno, dbe->e_blkcount);

	if (di->i_dyn_features & OCFS2_INLINE_DATA_FL) {
		if (dbe->e_ino != dbe->e_blkno)
			goto out;

		memcpy(dd->dirblock_buf, dd->inoblock_buf,
		       dd->fs->fs_blocksize);
		offset = offsetof(struct ocfs2_dinode, id2.i_data.id_data);
	} else {
		if (dbe->e_blkcount >= ocfs2_blocks_in_bytes(dd->fs,
Ejemplo n.º 21
0
static void warn_backwards(const char *name,
                           const struct timespec * const t0,
                           const struct timespec * const t1) {
   verbosef("%s clock went backwards from %lld.%09lld to %lld.%09lld",
            name,
            (lld)t0->tv_sec,
            (lld)t0->tv_nsec,
            (lld)t1->tv_sec,
            (lld)t1->tv_nsec);
}
Ejemplo n.º 22
0
static int decode_null(DECODER_ARGS) {
   uint32_t family;

   if (pheader->caplen < NULL_HDR_LEN) {
      verbosef("null: packet too short (%u bytes)", pheader->caplen);
      return 0;
   }
   family = *(const uint32_t *)pdata;
   if (family == AF_INET)
      return helper_ip(pdata + NULL_HDR_LEN,
                       pheader->caplen - NULL_HDR_LEN,
                       sm);
   if (family == AF_INET6)
      return helper_ipv6(pdata + NULL_HDR_LEN,
                         pheader->caplen - NULL_HDR_LEN,
                         sm);
   verbosef("null: unknown family (0x%04x)", family);
   return 0;
}
Ejemplo n.º 23
0
static int remove_quota_files_iterate(struct ocfs2_dir_entry *dirent,
				      uint64_t blocknr, int offset,
				      int blocksize, char *buf,
				      void *priv_data)
{
	struct remove_quota_files_ctxt *ctxt = priv_data;
	char dname[OCFS2_MAX_FILENAME_LEN];
	char wname[OCFS2_MAX_FILENAME_LEN];
	errcode_t ret;
	int tail, i;
	int ret_flags = 0;

	strncpy(dname, dirent->name, dirent->name_len);
	dname[dirent->name_len] = 0;

	/* Check whether entry is quota file of type we want - i.e. matching
	 * aquota.user:[0-9][0-9][0-9][0-9] or aquota.user for type == USRQUOTA
	 * and similarly for type == GRPQUOTA */
	strcpy(wname, "aquota.");
	strcat(wname, type2name(ctxt->type));
	tail = strlen(wname);
	if (strncmp(dname, wname, tail))
		return 0;
	if (dname[tail] == ':') {	/* May be local file? */
		tail++;
		for (i = 0; i < 4; i++)
			if (dname[tail + i] < '0' || dname[tail + i] > '9')
				return 0;
		if (dname[tail + i])
			return 0;
	} else if (dname[tail])		/* May be global file? */
		return 0;

	verbosef(VL_APP, "Deleting quota file %s\n",
		 dname);
	ret = ocfs2_truncate(ctxt->fs, dirent->inode, 0);
	if (ret) {
		tcom_err(ret, "while truncating quota file \"%s\"", dname);
		ret_flags |= OCFS2_DIRENT_ERROR;
		ctxt->err = ret;
		goto out;
	}
	ret = ocfs2_delete_inode(ctxt->fs, dirent->inode);
	if (ret) {
		tcom_err(ret, "while deleting quota file \"%s\"", dname);
		ret_flags |= OCFS2_DIRENT_ERROR;
		ctxt->err = ret;
	} else {
		dirent->inode = 0;
		ret_flags |= OCFS2_DIRENT_CHANGED;
	}
out:
	return ret_flags;
}
Ejemplo n.º 24
0
/* Very similar to decode_null, except on OpenBSD we need to think
 * about family endianness.
 */
static int decode_loop(DECODER_ARGS) {
   uint32_t family;

   if (pheader->caplen < NULL_HDR_LEN) {
      verbosef("loop: packet too short (%u bytes)", pheader->caplen);
      return 0;
   }
   family = *(const uint32_t *)pdata;
#ifdef __OpenBSD__
   family = ntohl(family);
#endif
   if (family == AF_INET)
      return helper_ip(pdata + NULL_HDR_LEN,
                       pheader->caplen - NULL_HDR_LEN, sm);
   if (family == AF_INET6)
      return helper_ipv6(pdata + NULL_HDR_LEN,
                         pheader->caplen - NULL_HDR_LEN, sm);
   verbosef("loop: unknown family (0x%04x)", family);
   return 0;
}
Ejemplo n.º 25
0
static int helper_pppoe(HELPER_ARGS) {
   if (len < PPPOE_HDR_LEN) {
      verbosef("pppoe: packet too short (%u bytes)", len);
      return 0;
   }

   if (pdata[1] != 0x00) {
      verbosef("pppoe: code = 0x%02x, expecting 0; ignoring.", pdata[1]);
      return 0;
   }

   if ((pdata[6] == 0xc0) && (pdata[7] == 0x21)) return 0; /* LCP */
   if ((pdata[6] == 0xc0) && (pdata[7] == 0x25)) return 0; /* LQR */

   if ((pdata[6] == 0x00) && (pdata[7] == 0x21))
      return helper_ip(pdata + PPPOE_HDR_LEN, len - PPPOE_HDR_LEN, sm);

   verbosef("pppoe: ignoring non-IP PPPoE packet (0x%02x%02x)",
            pdata[6], pdata[7]);
   return 0;
}
Ejemplo n.º 26
0
static int decode_ether(DECODER_ARGS) {
   u_short type;
   const struct ether_header *hdr = (const struct ether_header *)pdata;

   if (pheader->caplen < ETHER_HDR_LEN) {
      verbosef("ether: packet too short (%u bytes)", pheader->caplen);
      return 0;
   }
#ifdef __sun
   memcpy(sm->src_mac, hdr->ether_shost.ether_addr_octet, sizeof(sm->src_mac));
   memcpy(sm->dst_mac, hdr->ether_dhost.ether_addr_octet, sizeof(sm->dst_mac));
#else
   memcpy(sm->src_mac, hdr->ether_shost, sizeof(sm->src_mac));
   memcpy(sm->dst_mac, hdr->ether_dhost, sizeof(sm->dst_mac));
#endif
   type = ntohs(hdr->ether_type);
   switch (type) {
      case ETHERTYPE_IP:
      case ETHERTYPE_IPV6:
         if (!opt_want_pppoe)
            return helper_ip(pdata + ETHER_HDR_LEN,
                             pheader->caplen - ETHER_HDR_LEN,
                             sm);
         verbosef("ether: discarded IP packet, expecting PPPoE instead");
         return 0;
      case ETHERTYPE_PPPOE:
         if (opt_want_pppoe)
            return helper_pppoe(pdata + ETHER_HDR_LEN,
                                pheader->caplen - ETHER_HDR_LEN,
                                sm);
         verbosef("ether: got PPPoE frame: maybe you want --pppoe");
         return 0;
      case ETHERTYPE_ARP:
         /* known protocol, don't complain about it. */
         return 0;
      default:
         verbosef("ether: unknown protocol (0x%04x)", type);
         return 0;
   }
}
Ejemplo n.º 27
0
static errcode_t prep_journal_info(ocfs2_filesys *fs, int slot,
			           struct journal_info *ji)
{
	errcode_t err;


	err = ocfs2_malloc_blocks(fs->fs_io, 1, &ji->ji_jsb);
	if (err)
		com_err(whoami, err, "while allocating space for slot %d's "
			    "journal superblock", slot);

	err = ocfs2_lookup_system_inode(fs, JOURNAL_SYSTEM_INODE,
					slot, &ji->ji_ino);
	if (err) {
		com_err(whoami, err, "while looking up the journal inode for "
			"slot %d", slot);
		goto out;
	}

	err = ocfs2_read_cached_inode(fs, ji->ji_ino, &ji->ji_cinode);
	if (err) {
		com_err(whoami, err, "while reading cached inode %"PRIu64" "
			"for slot %d's journal", ji->ji_ino, slot);
		goto out;
	}

	if (!(ji->ji_cinode->ci_inode->id1.journal1.ij_flags &
	      OCFS2_JOURNAL_DIRTY_FL))
		goto out;

	err = lookup_journal_block(fs, ji, 0, &ji->ji_jsb_block, 1);
	if (err)
		goto out;

	/* XXX be smarter about reading in the whole super block if it
	 * spans multiple blocks */
	err = ocfs2_read_journal_superblock(fs, ji->ji_jsb_block, 
					    (char *)ji->ji_jsb);
	if (err) {
		com_err(whoami, err, "while reading block %"PRIu64" as slot "
			"%d's journal super block", ji->ji_jsb_block,
			ji->ji_slot);
		goto out;
	}

	ji->ji_replay = 1;

	verbosef("slot: %d jsb start %u maxlen %u\n", slot,
		 ji->ji_jsb->s_start, ji->ji_jsb->s_maxlen);
out:
	return err;
}
Ejemplo n.º 28
0
static int remove_slot_iterate(struct ocfs2_dir_entry *dirent, int offset,
			       int blocksize, char *buf, void *priv_data)
{
	struct remove_slot_ctxt *ctxt =
		(struct remove_slot_ctxt *)priv_data;
	int taillen, ret_flags = 0;
	errcode_t ret;
	char dname[OCFS2_MAX_FILENAME_LEN];
	char tail[OCFS2_MAX_FILENAME_LEN];

	sprintf(tail, ":%04d", ctxt->removed_slot);
	taillen = strlen(tail);

	strncpy(dname, dirent->name, dirent->name_len);
	dname[dirent->name_len] = '\0';

	if (!strcmp(dname + (dirent->name_len - taillen), tail)) {
		verbosef(VL_APP, "Unlinking system file \"%s\"\n",
			 dname);
		ret = ocfs2_delete_inode(ctxt->fs, dirent->inode);
		if (ret) {
			verbosef(VL_APP,
				 "%s while unlinking system file \"%s\"\n",
				 error_message(ret), dname);
			ret_flags |= OCFS2_DIRENT_ERROR;
			ctxt->errcode = ret;
		} else {
			verbosef(VL_APP,
				 "Successfully unlinked system file "
				 "\"%s\"\n",
				 dname);
			dirent->inode = 0;
			ret_flags |= OCFS2_DIRENT_CHANGED;
		}
	}

	return ret_flags;
}
Ejemplo n.º 29
0
static int enable_backup_super(ocfs2_filesys *fs, int flags)
{
	errcode_t err = 0;
	struct ocfs2_super_block *super = OCFS2_RAW_SB(fs->fs_super);
	struct tools_progress *prog;

	if (OCFS2_HAS_COMPAT_FEATURE(super,
				     OCFS2_FEATURE_COMPAT_BACKUP_SB)) {
		verbosef(VL_APP,
			 "Backup superblock feature is already enabled; "
			 "nothing to enable\n");
		goto out;
	}

	if (!tools_interact("Enable the backup superblock feature on "
			    "device \"%s\"? ",
			    fs->fs_devname))
		goto out;

	prog = tools_progress_start("Enable backup-super", "backup-super",
				    2);
	if (!prog) {
		err = TUNEFS_ET_NO_MEMORY;
		tcom_err(err, "while initializing the progress display");
		goto out;
	}

	tunefs_block_signals();
	err = check_backup_offsets(fs);
	tools_progress_step(prog, 1);
	if (!err)
		err = fill_backup_supers(fs);
	if (!err) {
		super->s_feature_compat |= OCFS2_FEATURE_COMPAT_BACKUP_SB;
		err = ocfs2_write_super(fs);
		if (err)
			tcom_err(err, "while writing out the superblock\n");
	}
	tunefs_unblock_signals();

	tools_progress_step(prog, 1);
	tools_progress_stop(prog);

	if (err)
		errorf("Unable to enable the backup superblock feature on "
		       "device \"%s\"\n",
		       fs->fs_devname);
out:
	return err;
}
Ejemplo n.º 30
0
static int corrupt_dirent_lengths(struct ocfs2_dir_entry *dirent, int left)
{
	if ((dirent->rec_len >= OCFS2_DIR_REC_LEN(1)) &&
	    ((dirent->rec_len & OCFS2_DIR_ROUND) == 0) &&
	    (dirent->rec_len <= left) &&
	    (OCFS2_DIR_REC_LEN(dirent->name_len) <= dirent->rec_len) &&
	    !dirent_leaves_partial(dirent, left))
		return 0;

	verbosef("corrupt dirent: %"PRIu64" rec_len %u name_len %u\n",
		 (uint64_t)dirent->inode, dirent->rec_len, dirent->name_len);

	return 1;
}